[PATCH 09/17] virDomainDiskDefMirrorParse: Switch to virXMLPropEnumDefault()

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

 



The virDomainDiskDefMirrorParse() 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/domain_conf.c  | 26 ++++++++++----------------
 src/conf/domain_conf.h  |  4 ++--
 src/qemu/qemu_process.c |  6 ++++--
 3 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index bf9db38340..4e1835fd34 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8804,21 +8804,16 @@ virDomainDiskDefMirrorParse(virDomainDiskDef *def,
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     g_autofree char *mirrorFormat = NULL;
     g_autofree char *mirrorType = NULL;
-    g_autofree char *ready = NULL;
-    g_autofree char *blockJob = NULL;
     g_autofree char *index = NULL;
 
     ctxt->node = cur;
 
-    if ((blockJob = virXMLPropString(cur, "job"))) {
-        if ((def->mirrorJob = virDomainBlockJobTypeFromString(blockJob)) <= 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown mirror job type '%s'"), blockJob);
-            return -1;
-        }
-    } else {
-        def->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_COPY;
-    }
+    if (virXMLPropEnumDefault(cur, "job",
+                              virDomainBlockJobTypeFromString,
+                              VIR_XML_PROP_NONZERO,
+                              &def->mirrorJob,
+                              VIR_DOMAIN_BLOCK_JOB_TYPE_COPY) < 0)
+        return -1;
 
     if ((mirrorType = virXMLPropString(cur, "type"))) {
         mirrorFormat = virXPathString("string(./format/@type)", ctxt);
@@ -8860,12 +8855,11 @@ virDomainDiskDefMirrorParse(virDomainDiskDef *def,
         }
     }
 
-    if ((ready = virXMLPropString(cur, "ready")) &&
-        (def->mirrorState = virDomainDiskMirrorStateTypeFromString(ready)) < 0) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("unknown mirror ready state %s"), ready);
+    if (virXMLPropEnum(cur, "ready",
+                       virDomainDiskMirrorStateTypeFromString,
+                       VIR_XML_PROP_NONE,
+                       &def->mirrorState) < 0)
         return -1;
-    }
 
     if (virParseScaledValue("./format/metadata_cache/max_size", NULL,
                             ctxt,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 2f00cc7f79..30aa0ed8d3 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -564,8 +564,8 @@ struct _virDomainDiskDef {
     unsigned int rotation_rate;
 
     virStorageSource *mirror;
-    int mirrorState; /* enum virDomainDiskMirrorState */
-    int mirrorJob; /* virDomainBlockJobType */
+    virDomainDiskMirrorState mirrorState;
+    virDomainBlockJobType mirrorJob;
 
     struct {
         unsigned int cylinders;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 929986745e..85bf452a59 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8660,8 +8660,10 @@ qemuProcessRefreshLegacyBlockjob(void *payload,
     }
 
     if (jobtype == QEMU_BLOCKJOB_TYPE_COMMIT &&
-        disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
-        jobtype = disk->mirrorJob;
+        disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT) {
+        /* This typecast is safe because of how the enum is declared. */
+        jobtype = (qemuBlockJobType) disk->mirrorJob;
+    }
 
     if (!(job = qemuBlockJobDiskNew(vm, disk, jobtype, jobname)))
         return -1;
-- 
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