[PATCH 03/17] virDomainBackupDefParse: Switch to virXMLPropEnumDefault()

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

 



The virDomainBackupDefParse() function uses old style of parsing
XML (virXMLPropString + str2enum conversion). Use
virXMLPropEnumDefault() which encapsulates those steps.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/conf/backup_conf.c | 16 ++++++----------
 src/conf/backup_conf.h |  2 +-
 2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c
index 2a7fa95e0c..11d533a905 100644
--- a/src/conf/backup_conf.c
+++ b/src/conf/backup_conf.c
@@ -201,22 +201,18 @@ virDomainBackupDefParse(xmlXPathContextPtr ctxt,
     g_autoptr(virDomainBackupDef) def = NULL;
     g_autofree xmlNodePtr *nodes = NULL;
     xmlNodePtr node = NULL;
-    g_autofree char *mode = NULL;
     bool push;
     size_t i;
     int n;
 
     def = g_new0(virDomainBackupDef, 1);
 
-    def->type = VIR_DOMAIN_BACKUP_TYPE_PUSH;
-
-    if ((mode = virXMLPropString(ctxt->node, "mode"))) {
-        if ((def->type = virDomainBackupTypeFromString(mode)) <= 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown backup mode '%s'"), mode);
-            return NULL;
-        }
-    }
+    if (virXMLPropEnumDefault(ctxt->node, "mode",
+                              virDomainBackupTypeFromString,
+                              VIR_XML_PROP_NONZERO,
+                              &def->type,
+                              VIR_DOMAIN_BACKUP_TYPE_PUSH) < 0)
+        return NULL;
 
     push = def->type == VIR_DOMAIN_BACKUP_TYPE_PUSH;
 
diff --git a/src/conf/backup_conf.h b/src/conf/backup_conf.h
index dc66b75892..413488e123 100644
--- a/src/conf/backup_conf.h
+++ b/src/conf/backup_conf.h
@@ -76,7 +76,7 @@ struct _virDomainBackupDiskDef {
 typedef struct _virDomainBackupDef virDomainBackupDef;
 struct _virDomainBackupDef {
     /* Public XML.  */
-    int type; /* virDomainBackupType */
+    virDomainBackupType type;
     char *incremental;
     virStorageNetHostDef *server; /* only when type == PULL */
     virTristateBool tls; /* use TLS for NBD */
-- 
2.35.1




[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