The virDomainDiskDefMirrorParse() function uses old style of
parsing XML (virXMLPropString + str2enum conversion). Use
virXMLPropEnumDefault() which encapsulates those steps.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
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 e348748062..cb4b43ea23 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8808,21 +8808,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);
@@ -8864,12 +8859,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 9173c98d42..f23444d768 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 8c19b812da..bb754ff8d6 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8625,8 +8625,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