[PATCH 10/10] conf: extract disk geometry parsing code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/conf/domain_conf.c | 75 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 46 insertions(+), 29 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e64471d..b5f2b91 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6838,6 +6838,51 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def,
 }


+static int
+virDomainDiskDefGeometryParse(virDomainDiskDefPtr def,
+                              xmlNodePtr cur,
+                              xmlXPathContextPtr ctxt)
+{
+    char *trans;
+
+    if (virXPathUInt("string(./geometry/@cyls)",
+                     ctxt, &def->geometry.cylinders) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("invalid geometry settings (cyls)"));
+        return -1;
+    }
+
+    if (virXPathUInt("string(./geometry/@heads)",
+                     ctxt, &def->geometry.heads) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("invalid geometry settings (heads)"));
+        return -1;
+    }
+
+    if (virXPathUInt("string(./geometry/@secs)",
+                     ctxt, &def->geometry.sectors) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("invalid geometry settings (secs)"));
+        return -1;
+    }
+
+    trans = virXMLPropString(cur, "trans");
+    if (trans) {
+        def->geometry.trans = virDomainDiskGeometryTransTypeFromString(trans);
+        if (def->geometry.trans <= 0) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("invalid translation value '%s'"),
+                           trans);
+            VIR_FREE(trans);
+            return -1;
+        }
+        VIR_FREE(trans);
+    }
+
+    return 0;
+}
+
+
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16

@@ -6866,7 +6911,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
     char *driverType = NULL;
     bool source = false;
     char *target = NULL;
-    char *trans = NULL;
     char *bus = NULL;
     char *cachetag = NULL;
     char *error_policy = NULL;
@@ -6951,34 +6995,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
                    xmlStrEqual(cur->name, BAD_CAST "backenddomain")) {
             domain_name = virXMLPropString(cur, "name");
         } else if (xmlStrEqual(cur->name, BAD_CAST "geometry")) {
-            if (virXPathUInt("string(./geometry/@cyls)",
-                             ctxt, &def->geometry.cylinders) < 0) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("invalid geometry settings (cyls)"));
+            if (virDomainDiskDefGeometryParse(def, cur, ctxt) < 0)
                 goto error;
-            }
-            if (virXPathUInt("string(./geometry/@heads)",
-                             ctxt, &def->geometry.heads) < 0) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("invalid geometry settings (heads)"));
-                goto error;
-            }
-            if (virXPathUInt("string(./geometry/@secs)",
-                             ctxt, &def->geometry.sectors) < 0) {
-                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                               _("invalid geometry settings (secs)"));
-                goto error;
-            }
-            trans = virXMLPropString(cur, "trans");
-            if (trans) {
-                def->geometry.trans = virDomainDiskGeometryTransTypeFromString(trans);
-                if (def->geometry.trans <= 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("invalid translation value '%s'"),
-                                   trans);
-                    goto error;
-                }
-            }
         } else if (xmlStrEqual(cur->name, BAD_CAST "blockio")) {
             logical_block_size =
                 virXMLPropString(cur, "logical_block_size");
@@ -7486,7 +7504,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
     VIR_FREE(target);
     VIR_FREE(tray);
     VIR_FREE(removable);
-    VIR_FREE(trans);
     VIR_FREE(device);
     virStorageAuthDefFree(authdef);
     VIR_FREE(driverType);
-- 
2.8.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]