NOT TO BE MERGED UPSTREAM This is just an example of usage of new EnumFromString() API. It's intentionally incomplete. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/conf/domain_conf.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6df1618..31b06b7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4904,11 +4904,10 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, type = virXMLPropString(address, "type"); if (type) { - if ((info->type = virDomainDeviceAddressTypeFromString(type)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown address type '%s'"), type); + if (virDomainDeviceAddressEnumFromString(type, &info->type, + _("unknown address type '%s'"), + type) < 0) goto cleanup; - } } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("No type specified for device address")); @@ -7430,8 +7429,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, } if (ioeventfd) { - int val; - if (def->bus != VIR_DOMAIN_DISK_BUS_VIRTIO) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("disk ioeventfd mode supported " @@ -7439,13 +7436,10 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; } - if ((val = virTristateSwitchTypeFromString(ioeventfd)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown disk ioeventfd mode '%s'"), - ioeventfd); + if (virTristateSwitchEnumFromString(ioeventfd, &def->ioeventfd, + _("unknown disk ioeventfd mode '%s'"), + ioeventfd) < 0) goto error; - } - def->ioeventfd = val; } if (event_idx) { @@ -7456,14 +7450,10 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; } - int idx; - if ((idx = virTristateSwitchTypeFromString(event_idx)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown disk event_idx mode '%s'"), - event_idx); + if (virTristateSwitchEnumFromString(event_idx, &def->event_idx, + _("unknown disk event_idx mode '%s'"), + event_idx) < 0) goto error; - } - def->event_idx = idx; } if (copy_on_read) { @@ -14754,11 +14744,9 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } - if ((def->virtType = virDomainVirtTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid domain type %s"), tmp); + if (virDomainVirtEnumFromString(tmp, &def->virtType, + _("invalid domain type %s"), tmp) < 0) goto error; - } VIR_FREE(tmp); def->os.bootloader = virXPathString("string(./bootloader)", ctxt); -- 2.4.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list