[libvirt] [PATCH 21/34] qemu: Use virDomainStorageSourceParseFull when parsing NBD migration data

Peter Krempa pkrempa at redhat.com
Mon Mar 18 15:55:10 UTC 2019


The new helper allows to avoid hand-rolled code to parse a storage
source.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/qemu/qemu_domain.c | 62 ++++++++----------------------------------
 1 file changed, 12 insertions(+), 50 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 0a0a464dd2..e406647d8f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2681,65 +2681,27 @@ qemuDomainObjPrivateXMLParsePR(xmlXPathContextPtr ctxt,

 static int
 qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr node,
+                                         qemuDomainObjPrivatePtr priv,
                                          xmlXPathContextPtr ctxt,
                                          virDomainDiskDefPtr disk)
 {
     VIR_XPATH_NODE_AUTORESTORE(ctxt);
     qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
-    char *format = NULL;
-    char *type = NULL;
-    int ret = -1;
-    VIR_AUTOUNREF(virStorageSourcePtr) migrSource = NULL;

     ctxt->node = node;

-    if (!(ctxt->node = virXPathNode("./migrationSource", ctxt))) {
-        ret = 0;
-        goto cleanup;
-    }
-
-    if (!(migrSource = virStorageSourceNew()))
-        goto cleanup;
-
-    if (!(type = virXMLPropString(ctxt->node, "type"))) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("missing storage source type"));
-        goto cleanup;
-    }
-
-    if (!(format = virXMLPropString(ctxt->node, "format"))) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("missing storage source format"));
-        goto cleanup;
-    }
-
-    if ((migrSource->type = virStorageTypeFromString(type)) <= 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown storage source type '%s'"), type);
-        goto cleanup;
-    }
-
-    if ((migrSource->format = virStorageFileFormatTypeFromString(format)) <= 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown storage source format '%s'"), format);
-        goto cleanup;
-    }
-
-    if (virDomainStorageSourceParse(ctxt->node, ctxt, migrSource,
-                                    VIR_DOMAIN_DEF_PARSE_STATUS, NULL) < 0)
-        goto cleanup;
-
-    if ((ctxt->node = virXPathNode("./privateData", ctxt)) &&
-        qemuStorageSourcePrivateDataParse(ctxt, migrSource) < 0)
-        goto cleanup;
+    if (!(ctxt->node = virXPathNode("./migrationSource", ctxt)))
+        return 0;

-    VIR_STEAL_PTR(diskPriv->migrSource, migrSource);
-    ret = 0;
+    if (!(diskPriv->migrSource = virDomainStorageSourceParseFull("string(@type)",
+                                                                 "string(@format)",
+                                                                 ".", NULL,
+                                                                 false, ctxt,
+                                                                 VIR_DOMAIN_DEF_PARSE_STATUS,
+                                                                 priv->driver->xmlopt)))
+        return -1;

- cleanup:
-    VIR_FREE(format);
-    VIR_FREE(type);
-    return ret;
+    return 0;
 }


@@ -2770,7 +2732,7 @@ qemuDomainObjPrivateXMLParseJobNBD(virDomainObjPtr vm,
                 (disk = virDomainDiskByName(vm->def, dst, false))) {
                 QEMU_DOMAIN_DISK_PRIVATE(disk)->migrating = true;

-                if (qemuDomainObjPrivateXMLParseJobNBDSource(nodes[i], ctxt,
+                if (qemuDomainObjPrivateXMLParseJobNBDSource(nodes[i], priv, ctxt,
                                                              disk) < 0)
                     goto cleanup;
             }
-- 
2.20.1




More information about the libvir-list mailing list