Convert the field, adjust the XML parsers to use virXMLPropEnum() and fill in missing cases to switch() statements. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/conf/domain_audit.c | 2 ++ src/conf/domain_conf.c | 29 ++++++++++++++--------------- src/conf/domain_conf.h | 2 +- src/lxc/lxc_cgroup.c | 2 ++ src/lxc/lxc_controller.c | 1 + src/lxc/lxc_driver.c | 4 ++++ src/lxc/lxc_hostdev.c | 1 + src/security/security_selinux.c | 4 ++++ 8 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c index d4d303a214..0bf1768acd 100644 --- a/src/conf/domain_audit.c +++ b/src/conf/domain_audit.c @@ -428,6 +428,8 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef *hostdev, virt, reason, vmname, uuidstr, device); break; + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: VIR_WARN("Unexpected hostdev type while encoding audit message: %d", hostdev->source.caps.type); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c93f89ced6..cf1bd4df74 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2616,7 +2616,7 @@ virDomainHostdevDefClear(virDomainHostdevDef *def) switch (def->mode) { case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES: - switch ((virDomainHostdevCapsType) def->source.caps.type) { + switch (def->source.caps.type) { case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: VIR_FREE(def->source.caps.u.storage.block); break; @@ -6502,7 +6502,7 @@ virDomainNetDefCoalesceFormatXML(virBuffer *buf, static int virDomainHostdevDefParseXMLCaps(xmlNodePtr node G_GNUC_UNUSED, xmlXPathContextPtr ctxt, - const char *type, + virDomainHostdevCapsType type, virDomainHostdevDef *def) { /* @type is passed in from the caller rather than read from the @@ -6513,18 +6513,7 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node G_GNUC_UNUSED, * <hostdev>. (the functions we're going to call expect address * type to already be known). */ - if (!type) { - virReportError(VIR_ERR_XML_ERROR, - "%s", _("missing source address type")); - return -1; - } - - if ((def->source.caps.type = virDomainHostdevCapsTypeFromString(type)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host device source address type '%1$s'"), - type); - return -1; - } + def->source.caps.type = type; if (!virXPathNode("./source", ctxt)) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -6560,6 +6549,7 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node G_GNUC_UNUSED, ctxt, &def->source.caps.u.net.ip) < 0) return -1; break; + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("address type='%1$s' not supported in hostdev interfaces"), @@ -12920,6 +12910,7 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt, virDomainHostdevDef *def; VIR_XPATH_NODE_AUTORESTORE(ctxt) g_autofree char *type = virXMLPropString(node, "type"); + unsigned int typeU; ctxt->node = node; @@ -12940,7 +12931,12 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt, break; case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES: /* parse managed/mode/type, and the <source> element */ - if (virDomainHostdevDefParseXMLCaps(node, ctxt, type, def) < 0) + if (virXMLPropEnum(node, "type", + virDomainHostdevCapsTypeFromString, + VIR_XML_PROP_REQUIRED, &typeU) < 0) + goto error; + + if (virDomainHostdevDefParseXMLCaps(node, ctxt, typeU, def) < 0) goto error; break; default: @@ -14163,6 +14159,8 @@ virDomainHostdevMatchCaps(virDomainHostdevDef *a, return virDomainHostdevMatchCapsMisc(a, b); case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: return virDomainHostdevMatchCapsNet(a, b); + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: + break; } return 0; } @@ -23486,6 +23484,7 @@ virDomainHostdevDefFormatCaps(virBuffer *buf, virBufferEscapeString(buf, "<interface>%s</interface>\n", def->source.caps.u.net.ifname); break; + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected hostdev type %1$d"), diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 1f977ef1c8..0e76ff71ac 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -336,7 +336,7 @@ typedef enum { } virDomainHostdevCapsType; struct _virDomainHostdevCaps { - int type; /* enum virDOmainHostdevCapsType */ + virDomainHostdevCapsType type; union { struct { char *block; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 21d9b456e8..7c889667ba 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -309,6 +309,8 @@ static int virLXCCgroupSetupDeviceACL(virDomainDef *def, VIR_CGROUP_DEVICE_MKNOD, false) < 0) return -1; break; + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: break; } diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index e2d67d504d..7e486d0f78 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1804,6 +1804,7 @@ virLXCControllerSetupHostdevCaps(virDomainDef *vmDef, case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: return 0; /* case is handled in virLXCControllerMoveInterfaces */ + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported host device mode %1$s"), diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index fb0301b811..a9bdeba36d 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3869,6 +3869,8 @@ lxcDomainAttachDeviceHostdevCapsLive(virLXCDriver *driver, case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: return lxcDomainAttachDeviceHostdevMiscLive(driver, vm, dev); + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported host device type %1$s"), @@ -4299,6 +4301,8 @@ lxcDomainDetachDeviceHostdevCapsLive(virDomainObj *vm, case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: return lxcDomainDetachDeviceHostdevMiscLive(vm, dev); + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported host device type %1$s"), diff --git a/src/lxc/lxc_hostdev.c b/src/lxc/lxc_hostdev.c index af3ce3e0ac..2e06b516d4 100644 --- a/src/lxc/lxc_hostdev.c +++ b/src/lxc/lxc_hostdev.c @@ -90,6 +90,7 @@ int virLXCPrepareHostDevices(virLXCDriver *driver, case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: break; + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported hostdev type %1$s"), diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index c3c92f3538..1fa5303495 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2315,6 +2315,8 @@ virSecuritySELinuxSetHostdevCapsLabel(virSecurityManager *mgr, break; } + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: ret = 0; break; @@ -2538,6 +2540,8 @@ virSecuritySELinuxRestoreHostdevCapsLabel(virSecurityManager *mgr, break; } + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: ret = 0; break; -- 2.41.0