]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Refactor virDomainDiskDefMirrorParse
authorPeter Krempa <pkrempa@redhat.com>
Wed, 20 Mar 2019 16:33:29 +0000 (17:33 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 3 Apr 2019 09:58:09 +0000 (11:58 +0200)
Use virDomainStorageSourceParseBase and other tricks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c

index 62a46f57ecb4c3f0dfe43117b23a4ce559cf75fc..cde19a8a52d767732ef58a702cb4a67531df4f5f 100644 (file)
@@ -9306,13 +9306,13 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def,
                             virDomainXMLOptionPtr xmlopt)
 {
     xmlNodePtr mirrorNode;
+    VIR_XPATH_NODE_AUTORESTORE(ctxt);
     VIR_AUTOFREE(char *) mirrorFormat = NULL;
     VIR_AUTOFREE(char *) mirrorType = NULL;
     VIR_AUTOFREE(char *) ready = NULL;
     VIR_AUTOFREE(char *) blockJob = NULL;
 
-    if (!(def->mirror = virStorageSourceNew()))
-        return -1;
+    ctxt->node = cur;
 
     if ((blockJob = virXMLPropString(cur, "job"))) {
         if ((def->mirrorJob = virDomainBlockJobTypeFromString(blockJob)) <= 0) {
@@ -9325,51 +9325,39 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def,
     }
 
     if ((mirrorType = virXMLPropString(cur, "type"))) {
-        if ((def->mirror->type = virStorageTypeFromString(mirrorType)) <= 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown mirror backing store type '%s'"),
-                           mirrorType);
+        mirrorFormat = virXPathString("string(./format/@type)", ctxt);
+    } else {
+        if (def->mirrorJob != VIR_DOMAIN_BLOCK_JOB_TYPE_COPY) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("mirror without type only supported "
+                             "by copy job"));
             return -1;
         }
+        mirrorFormat = virXMLPropString(cur, "format");
+    }
 
-        mirrorFormat = virXPathString("string(./mirror/format/@type)", ctxt);
+    if (!(def->mirror = virDomainStorageSourceParseBase(mirrorType, mirrorFormat, NULL)))
+        return -1;
 
-        if (!(mirrorNode = virXPathNode("./mirror/source", ctxt))) {
+    if (mirrorType) {
+        if (!(mirrorNode = virXPathNode("./source", ctxt))) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("mirror requires source element"));
             return -1;
         }
 
-        if (virDomainStorageSourceParse(mirrorNode, ctxt, def->mirror,
-                                        flags, xmlopt) < 0)
+        if (virDomainStorageSourceParse(mirrorNode, ctxt, def->mirror, flags,
+                                        xmlopt) < 0)
             return -1;
     } else {
-        /* For back-compat reasons, we handle a file name
-         * encoded as attributes, even though we prefer
-         * modern output in the style of backingStore */
-        def->mirror->type = VIR_STORAGE_TYPE_FILE;
-        def->mirror->path = virXMLPropString(cur, "file");
-        if (!def->mirror->path) {
+        /* For back-compat reasons, we handle a file name encoded as
+         * attributes, even though we prefer modern output in the style of
+         * backingStore */
+        if (!(def->mirror->path = virXMLPropString(cur, "file"))) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("mirror requires file name"));
             return -1;
         }
-        if (def->mirrorJob != VIR_DOMAIN_BLOCK_JOB_TYPE_COPY) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("mirror without type only supported "
-                             "by copy job"));
-            return -1;
-        }
-        mirrorFormat = virXMLPropString(cur, "format");
-    }
-
-    if (mirrorFormat) {
-        def->mirror->format = virStorageFileFormatTypeFromString(mirrorFormat);
-        if (def->mirror->format <= 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown mirror format value '%s'"), mirrorFormat);
-            return -1;
-        }
     }
 
     if ((ready = virXMLPropString(cur, "ready")) &&