[PATCH 09/10] conf: Refactor virDomainDiskDefMirrorParse

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

 



Now that the mirror parsing code is not crammed in the main disk parser
we can employ better coding style.
---
 src/conf/domain_conf.c | 75 +++++++++++++++++++++-----------------------------
 1 file changed, 31 insertions(+), 44 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 802a6fe..e64471d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6753,41 +6753,44 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def,
                             xmlNodePtr cur,
                             xmlXPathContextPtr ctxt)
 {
+    xmlNodePtr mirrorNode;
     char *mirrorFormat = NULL;
     char *mirrorType = NULL;
-    char *ready;
-    char *blockJob;
+    char *ready = NULL;
+    char *blockJob = NULL;
     int ret = -1;

     if (VIR_ALLOC(def->mirror) < 0)
         goto cleanup;

-    blockJob = virXMLPropString(cur, "job");
-    if (blockJob) {
-        def->mirrorJob = virDomainBlockJobTypeFromString(blockJob);
-        if (def->mirrorJob <= 0) {
+    if ((blockJob = virXMLPropString(cur, "job"))) {
+        if ((def->mirrorJob = virDomainBlockJobTypeFromString(blockJob)) <= 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown mirror job type '%s'"),
-                           blockJob);
-            VIR_FREE(blockJob);
+                           _("unknown mirror job type '%s'"), blockJob);
             goto cleanup;
         }
-        VIR_FREE(blockJob);
     } else {
         def->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_COPY;
     }

-    mirrorType = virXMLPropString(cur, "type");
-    if (mirrorType) {
-        def->mirror->type = virStorageTypeFromString(mirrorType);
-        if (def->mirror->type <= 0) {
+    if ((mirrorType = virXMLPropString(cur, "type"))) {
+        if ((def->mirror->type = virStorageTypeFromString(mirrorType)) <= 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown mirror backing store "
-                             "type '%s'"), mirrorType);
+                           _("unknown mirror backing store type '%s'"),
+                           mirrorType);
             goto cleanup;
         }
-        mirrorFormat = virXPathString("string(./mirror/format/@type)",
-                                      ctxt);
+
+        mirrorFormat = virXPathString("string(./mirror/format/@type)", ctxt);
+
+        if (!(mirrorNode = virXPathNode("./mirror/source", ctxt))) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("mirror requires source element"));
+            goto cleanup;
+        }
+
+        if (virDomainDiskSourceParse(mirrorNode, ctxt, def->mirror) < 0)
+            goto cleanup;
     } else {
         /* For back-compat reasons, we handle a file name
          * encoded as attributes, even though we prefer
@@ -6807,44 +6810,28 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def,
         }
         mirrorFormat = virXMLPropString(cur, "format");
     }
+
     if (mirrorFormat) {
-        def->mirror->format =
-            virStorageFileFormatTypeFromString(mirrorFormat);
+        def->mirror->format = virStorageFileFormatTypeFromString(mirrorFormat);
         if (def->mirror->format <= 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown mirror format value '%s'"),
-                           mirrorFormat);
+                           _("unknown mirror format value '%s'"), mirrorFormat);
             goto cleanup;
         }
     }
-    if (mirrorType) {
-        xmlNodePtr mirrorNode;

-        if (!(mirrorNode = virXPathNode("./mirror/source", ctxt))) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("mirror requires source element"));
-            goto cleanup;
-        }
-        if (virDomainDiskSourceParse(mirrorNode, ctxt,
-                                     def->mirror) < 0)
-            goto cleanup;
-    }
-    ready = virXMLPropString(cur, "ready");
-    if (ready) {
-        if ((def->mirrorState =
-             virDomainDiskMirrorStateTypeFromString(ready)) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("unknown mirror ready state %s"),
-                           ready);
-            VIR_FREE(ready);
-            goto cleanup;
-        }
-        VIR_FREE(ready);
+    if ((ready = virXMLPropString(cur, "ready")) &&
+        (def->mirrorState = virDomainDiskMirrorStateTypeFromString(ready)) < 0) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("unknown mirror ready state %s"), ready);
+        goto cleanup;
     }

     ret = 0;

  cleanup:
+    VIR_FREE(ready);
+    VIR_FREE(blockJob);
     VIR_FREE(mirrorType);
     VIR_FREE(mirrorFormat);
     return ret;
-- 
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]