]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
domain_conf: extract disk driver source bits to its own function
authorPavel Hrdina <phrdina@redhat.com>
Thu, 27 May 2021 13:25:51 +0000 (15:25 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 1 Jun 2021 13:29:03 +0000 (15:29 +0200)
Attribute `type` and sub-element `metadata_cache` are internally stored
in the `virStorageSource` structure. Sometimes we only care about the
disk source bits so we need a dedicated helper for that.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/conf/domain_conf.c

index 6d90041bf8a6d7538fe8dff4154a16e7138a176a..f7920bce2c666803d43992e58fe4e1348cc24e5f 100644 (file)
@@ -8849,7 +8849,6 @@ virDomainDiskDefDriverParseXML(virDomainDiskDef *def,
                                xmlNodePtr cur,
                                xmlXPathContextPtr ctxt)
 {
-    g_autofree char *tmp = NULL;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
 
     ctxt->node = cur;
@@ -8900,12 +8899,34 @@ virDomainDiskDefDriverParseXML(virDomainDiskDef *def,
     if (virXMLPropUInt(cur, "iothread", 10, VIR_XML_PROP_NONZERO, &def->iothread) < 0)
         return -1;
 
+    if (virXMLPropEnum(cur, "detect_zeroes",
+                       virDomainDiskDetectZeroesTypeFromString,
+                       VIR_XML_PROP_NONZERO, &def->detect_zeroes) < 0)
+        return -1;
+
+    if (virXMLPropUInt(cur, "queues", 10, VIR_XML_PROP_NONE, &def->queues) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+static int
+virDomainDiskDefDriverSourceParseXML(virStorageSource *src,
+                                     xmlNodePtr cur,
+                                     xmlXPathContextPtr ctxt)
+{
+    g_autofree char *tmp = NULL;
+    VIR_XPATH_NODE_AUTORESTORE(ctxt)
+
+    ctxt->node = cur;
+
     if ((tmp = virXMLPropString(cur, "type"))) {
         if (STREQ(tmp, "aio")) {
             /* Xen back-compat */
-            def->src->format = VIR_STORAGE_FILE_RAW;
+            src->format = VIR_STORAGE_FILE_RAW;
         } else {
-            if ((def->src->format = virStorageFileFormatTypeFromString(tmp)) <= 0) {
+            if ((src->format = virStorageFileFormatTypeFromString(tmp)) <= 0) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                _("unknown driver format value '%s'"), tmp);
                 return -1;
@@ -8913,17 +8934,9 @@ virDomainDiskDefDriverParseXML(virDomainDiskDef *def,
         }
     }
 
-    if (virXMLPropEnum(cur, "detect_zeroes",
-                       virDomainDiskDetectZeroesTypeFromString,
-                       VIR_XML_PROP_NONZERO, &def->detect_zeroes) < 0)
-        return -1;
-
-    if (virXMLPropUInt(cur, "queues", 10, VIR_XML_PROP_NONE, &def->queues) < 0)
-        return -1;
-
     if (virParseScaledValue("./metadata_cache/max_size", NULL,
                             ctxt,
-                            &def->src->metadataCacheMaxSize,
+                            &src->metadataCacheMaxSize,
                             1, ULLONG_MAX, false) < 0)
         return -1;
 
@@ -9129,6 +9142,9 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
 
         if (virDomainDiskDefDriverParseXML(def, driverNode, ctxt) < 0)
             return NULL;
+
+        if (virDomainDiskDefDriverSourceParseXML(def->src, driverNode, ctxt) < 0)
+            return NULL;
     }
 
     if ((mirrorNode = virXPathNode("./mirror", ctxt))) {