]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: domain: Extract parsing of NBD status XML
authorPeter Krempa <pkrempa@redhat.com>
Mon, 12 Mar 2018 14:33:39 +0000 (15:33 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 23 May 2018 11:18:25 +0000 (13:18 +0200)
Extract the NBD portion of the 'job' status XML element parser into a
separate function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/qemu/qemu_domain.c

index 0bca80f3c6d82c6733c307e1bb1c8c3a056b9845..83e6f1a216b00e5293d8e0de5429f615c5169572 100644 (file)
@@ -2367,16 +2367,50 @@ qemuDomainObjPrivateXMLParsePR(xmlXPathContextPtr ctxt,
 }
 
 
+static int
+qemuDomainObjPrivateXMLParseJobNBD(virDomainObjPtr vm,
+                                   qemuDomainObjPrivatePtr priv,
+                                   xmlXPathContextPtr ctxt)
+{
+    xmlNodePtr *nodes = NULL;
+    size_t i;
+    int n;
+    int ret = -1;
+
+    if ((n = virXPathNodeSet("./disk[@migrating='yes']", ctxt, &nodes)) < 0)
+        goto cleanup;
+
+    if (n > 0) {
+        if (priv->job.asyncJob != QEMU_ASYNC_JOB_MIGRATION_OUT) {
+            VIR_WARN("Found disks marked for migration but we were not "
+                     "migrating");
+            n = 0;
+        }
+        for (i = 0; i < n; i++) {
+            char *dst = virXMLPropString(nodes[i], "dev");
+            virDomainDiskDefPtr disk;
+
+            if (dst && (disk = virDomainDiskByName(vm->def, dst, false)))
+                QEMU_DOMAIN_DISK_PRIVATE(disk)->migrating = true;
+            VIR_FREE(dst);
+        }
+    }
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(nodes);
+    return ret;
+}
+
+
 static int
 qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
                                 qemuDomainObjPrivatePtr priv,
                                 xmlXPathContextPtr ctxt)
 {
-    xmlNodePtr *nodes = NULL;
     xmlNodePtr savedNode = ctxt->node;
     char *tmp = NULL;
-    size_t i;
-    int n;
     int ret = -1;
 
     if (!(ctxt->node = virXPathNode("./job[1]", ctxt))) {
@@ -2423,26 +2457,9 @@ qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
         goto cleanup;
     }
 
-    if ((n = virXPathNodeSet("./disk[@migrating='yes']", ctxt, &nodes)) < 0)
+    if (qemuDomainObjPrivateXMLParseJobNBD(vm, priv, ctxt) < 0)
         goto cleanup;
 
-    if (n > 0) {
-        if (priv->job.asyncJob != QEMU_ASYNC_JOB_MIGRATION_OUT) {
-            VIR_WARN("Found disks marked for migration but we were not "
-                     "migrating");
-            n = 0;
-        }
-        for (i = 0; i < n; i++) {
-            char *dst = virXMLPropString(nodes[i], "dev");
-            virDomainDiskDefPtr disk;
-
-            if (dst && (disk = virDomainDiskByName(vm->def, dst, false)))
-                QEMU_DOMAIN_DISK_PRIVATE(disk)->migrating = true;
-            VIR_FREE(dst);
-        }
-    }
-    VIR_FREE(nodes);
-
     if (qemuMigrationParamsParse(ctxt, &priv->job.migParams) < 0)
         goto cleanup;
 
@@ -2451,7 +2468,6 @@ qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
  cleanup:
     ctxt->node = savedNode;
     VIR_FREE(tmp);
-    VIR_FREE(nodes);
     return ret;
 }