[PATCH 5/8] virDomainBackupDiskDefParseXML: Use virDomainStorageSourceParseBase

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

 



Don't duplicate code to parse the virStorageSource basics.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/backup_conf.c | 35 ++++++++++-------------------------
 1 file changed, 10 insertions(+), 25 deletions(-)

diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c
index 47e3bc1d60..11d419ce2b 100644
--- a/src/conf/backup_conf.c
+++ b/src/conf/backup_conf.c
@@ -104,7 +104,7 @@ virDomainBackupDiskDefParseXML(xmlNodePtr node,
 {
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     g_autofree char *type = NULL;
-    g_autofree char *driver = NULL;
+    g_autofree char *format = NULL;
     g_autofree char *backup = NULL;
     g_autofree char *state = NULL;
     g_autofree char *backupmode = NULL;
@@ -169,23 +169,17 @@ virDomainBackupDiskDefParseXML(xmlNodePtr node,
         def->state = tmp;
     }

-    def->store = virStorageSourceNew();
+    type = virXMLPropString(node, "type");
+    format = virXPathString("string(./driver/@type)", ctxt);

-    if ((type = virXMLPropString(node, "type"))) {
-        if ((def->store->type = virStorageTypeFromString(type)) <= 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("unknown disk backup type '%s'"), type);
-            return -1;
-        }
+    if (!(def->store = virDomainStorageSourceParseBase(type, format, NULL)))
+          return -1;

-        if (def->store->type != VIR_STORAGE_TYPE_FILE &&
-            def->store->type != VIR_STORAGE_TYPE_BLOCK) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("unsupported disk backup type '%s'"), type);
-            return -1;
-        }
-    } else {
-        def->store->type = VIR_STORAGE_TYPE_FILE;
+    if (def->store->type != VIR_STORAGE_TYPE_FILE &&
+        def->store->type != VIR_STORAGE_TYPE_BLOCK) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("unsupported disk backup type '%s'"), type);
+        return -1;
     }

     if (push)
@@ -198,15 +192,6 @@ virDomainBackupDiskDefParseXML(xmlNodePtr node,
                                     storageSourceParseFlags, xmlopt) < 0)
         return -1;

-    if ((driver = virXPathString("string(./driver/@type)", ctxt))) {
-        def->store->format = virStorageFileFormatTypeFromString(driver);
-        if (def->store->format <= 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown disk backup driver '%s'"), driver);
-            return -1;
-        }
-    }
-
     return 0;
 }

-- 
2.28.0




[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]

  Powered by Linux