The virDomainInputDefParseXML() 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_audit.c | 2 +-
src/conf/domain_conf.c | 86 +++++++++++++-------------------
src/conf/domain_conf.h | 6 +--
src/conf/domain_validate.c | 2 +-
src/libxl/libxl_conf.c | 4 ++
src/libxl/xen_xl.c | 3 ++
src/libxl/xen_xm.c | 3 ++
src/qemu/qemu_cgroup.c | 12 +++++
src/qemu/qemu_command.c | 10 ++--
src/qemu/qemu_domain_address.c | 4 +-
src/qemu/qemu_hotplug.c | 4 +-
src/qemu/qemu_validate.c | 4 +-
src/security/security_apparmor.c | 2 +-
src/security/security_dac.c | 4 +-
src/security/security_selinux.c | 4 +-
15 files changed, 80 insertions(+), 70 deletions(-)
diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index 17a01c51ba..9ce14de80b 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -949,7 +949,7 @@ virDomainAuditInput(virDomainObj *vm,
if (!(vmname = virAuditEncode("vm", vm->def->name)))
return;
- switch ((virDomainInputType) input->type) {
+ switch (input->type) {
case VIR_DOMAIN_INPUT_TYPE_MOUSE:
case VIR_DOMAIN_INPUT_TYPE_TABLET:
case VIR_DOMAIN_INPUT_TYPE_KBD:
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 85aae73873..44ab79c1f0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1942,7 +1942,7 @@ void virDomainGraphicsDefFree(virDomainGraphicsDef *def)
const char *virDomainInputDefGetPath(virDomainInputDef *input)
{
- switch ((virDomainInputType) input->type) {
+ switch (input->type) {
case VIR_DOMAIN_INPUT_TYPE_MOUSE:
case VIR_DOMAIN_INPUT_TYPE_TABLET:
case VIR_DOMAIN_INPUT_TYPE_KBD:
@@ -11818,70 +11818,54 @@ virDomainInputDefParseXML(virDomainXMLOption *xmlopt,
{
VIR_XPATH_NODE_AUTORESTORE(ctxt)
virDomainInputDef *def;
- g_autofree char *type = NULL;
- g_autofree char *bus = NULL;
- g_autofree char *model = NULL;
+ virDomainInputBus bus = VIR_DOMAIN_INPUT_BUS_PS2;
xmlNodePtr source = NULL;
def = g_new0(virDomainInputDef, 1);
ctxt->node = node;
- type = virXMLPropString(node, "type");
- bus = virXMLPropString(node, "bus");
- model = virXMLPropString(node, "model");
-
- if (!type) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("missing input device type"));
- goto error;
- }
-
- if ((def->type = virDomainInputTypeFromString(type)) < 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown input device type '%s'"), type);
+ if (virXMLPropEnum(node, "type",
+ virDomainInputTypeFromString,
+ VIR_XML_PROP_REQUIRED,
+ &def->type) < 0)
goto error;
- }
- if (model &&
- ((def->model = virDomainInputModelTypeFromString(model)) < 0 ||
- def->model == VIR_DOMAIN_INPUT_MODEL_DEFAULT)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown input model '%s'"), model);
+ if (virXMLPropEnum(node, "model",
+ virDomainInputModelTypeFromString,
+ VIR_XML_PROP_NONZERO,
+ &def->model) < 0)
goto error;
- }
-
- if (bus) {
- if ((def->bus = virDomainInputBusTypeFromString(bus)) < 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown input bus type '%s'"), bus);
- goto error;
- }
- } else {
- if (dom->os.type == VIR_DOMAIN_OSTYPE_HVM) {
- if ((def->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ||
- def->type == VIR_DOMAIN_INPUT_TYPE_KBD) &&
- (ARCH_IS_X86(dom->os.arch) || dom->os.arch == VIR_ARCH_NONE)) {
- def->bus = VIR_DOMAIN_INPUT_BUS_PS2;
- } else if (ARCH_IS_S390(dom->os.arch) ||
- def->type == VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH) {
- def->bus = VIR_DOMAIN_INPUT_BUS_VIRTIO;
- } else if (def->type == VIR_DOMAIN_INPUT_TYPE_EVDEV) {
- def->bus = VIR_DOMAIN_INPUT_BUS_NONE;
- } else {
- def->bus = VIR_DOMAIN_INPUT_BUS_USB;
- }
- } else if (dom->os.type == VIR_DOMAIN_OSTYPE_XEN ||
- dom->os.type == VIR_DOMAIN_OSTYPE_XENPVH) {
- def->bus = VIR_DOMAIN_INPUT_BUS_XEN;
+ if (dom->os.type == VIR_DOMAIN_OSTYPE_HVM) {
+ if ((def->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ||
+ def->type == VIR_DOMAIN_INPUT_TYPE_KBD) &&
+ (ARCH_IS_X86(dom->os.arch) || dom->os.arch == VIR_ARCH_NONE)) {
+ bus = VIR_DOMAIN_INPUT_BUS_PS2;
+ } else if (ARCH_IS_S390(dom->os.arch) ||
+ def->type == VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH) {
+ bus = VIR_DOMAIN_INPUT_BUS_VIRTIO;
+ } else if (def->type == VIR_DOMAIN_INPUT_TYPE_EVDEV) {
+ bus = VIR_DOMAIN_INPUT_BUS_NONE;
} else {
- if ((dom->virtType == VIR_DOMAIN_VIRT_VZ ||
- dom->virtType == VIR_DOMAIN_VIRT_PARALLELS))
- def->bus = VIR_DOMAIN_INPUT_BUS_PARALLELS;
+ bus = VIR_DOMAIN_INPUT_BUS_USB;
}
+ } else if (dom->os.type == VIR_DOMAIN_OSTYPE_XEN ||
+ dom->os.type == VIR_DOMAIN_OSTYPE_XENPVH) {
+ bus = VIR_DOMAIN_INPUT_BUS_XEN;
+ } else {
+ if ((dom->virtType == VIR_DOMAIN_VIRT_VZ ||
+ dom->virtType == VIR_DOMAIN_VIRT_PARALLELS))
+ bus = VIR_DOMAIN_INPUT_BUS_PARALLELS;
}
+ if (virXMLPropEnumDefault(node, "bus",
+ virDomainInputBusTypeFromString,
+ VIR_XML_PROP_NONE,
+ &def->bus, bus) < 0)
+ goto error;
+
+
if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &def->info, flags) <
0)
goto error;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 3abc1dba36..b3d51565e3 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1493,9 +1493,9 @@ typedef enum {
} virDomainInputSourceGrabToggle;
struct _virDomainInputDef {
- int type;
- int bus;
- int model; /* virDomainInputModel */
+ virDomainInputType type;
+ virDomainInputBus bus;
+ virDomainInputModel model;
struct {
char *evdev;
virDomainInputSourceGrab grab;
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 4fce7059dc..5205834d12 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2276,7 +2276,7 @@ virDomainInputDefValidate(const virDomainInputDef *input,
}
}
- switch ((virDomainInputType) input->type) {
+ switch (input->type) {
case VIR_DOMAIN_INPUT_TYPE_MOUSE:
case VIR_DOMAIN_INPUT_TYPE_TABLET:
case VIR_DOMAIN_INPUT_TYPE_KBD:
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 0cfd49ebcf..82af406e2d 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -725,6 +725,10 @@ libxlMakeDomBuildInfo(virDomainDef *def,
VIR_FREE(*usbdevice);
*usbdevice = g_strdup("tablet");
break;
+ case VIR_DOMAIN_INPUT_TYPE_KBD:
+ case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
+ case VIR_DOMAIN_INPUT_TYPE_EVDEV:
+ case VIR_DOMAIN_INPUT_TYPE_LAST:
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Unknown input device type"));
diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c
index eb3b0b3718..76237dfa25 100644
--- a/src/libxl/xen_xl.c
+++ b/src/libxl/xen_xl.c
@@ -1757,6 +1757,9 @@ xenFormatXLInputDevs(virConf *conf, virDomainDef *def)
case VIR_DOMAIN_INPUT_TYPE_KBD:
devtype = "keyboard";
break;
+ case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
+ case VIR_DOMAIN_INPUT_TYPE_EVDEV:
+ case VIR_DOMAIN_INPUT_TYPE_LAST:
default:
continue;
}
diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c
index a962da9cad..31d2d2e6a1 100644
--- a/src/libxl/xen_xm.c
+++ b/src/libxl/xen_xm.c
@@ -521,6 +521,9 @@ xenFormatXMInputDevs(virConf *conf, virDomainDef *def)
case VIR_DOMAIN_INPUT_TYPE_KBD:
devtype = "keyboard";
break;
+ case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
+ case VIR_DOMAIN_INPUT_TYPE_EVDEV:
+ case VIR_DOMAIN_INPUT_TYPE_LAST:
default:
continue;
}
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index aa0c927578..7c24e187c9 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -384,6 +384,12 @@ qemuSetupInputCgroup(virDomainObj *vm,
return qemuCgroupAllowDevicePath(vm, dev->source.evdev,
VIR_CGROUP_DEVICE_RW, false);
break;
+
+ case VIR_DOMAIN_INPUT_TYPE_MOUSE:
+ case VIR_DOMAIN_INPUT_TYPE_TABLET:
+ case VIR_DOMAIN_INPUT_TYPE_KBD:
+ case VIR_DOMAIN_INPUT_TYPE_LAST:
+ break;
}
return ret;
@@ -405,6 +411,12 @@ qemuTeardownInputCgroup(virDomainObj *vm,
return qemuCgroupDenyDevicePath(vm, dev->source.evdev,
VIR_CGROUP_DEVICE_RWM, false);
break;
+
+ case VIR_DOMAIN_INPUT_TYPE_MOUSE:
+ case VIR_DOMAIN_INPUT_TYPE_TABLET:
+ case VIR_DOMAIN_INPUT_TYPE_KBD:
+ case VIR_DOMAIN_INPUT_TYPE_LAST:
+ break;
}
return 0;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d3d69fed4f..b863fd1c32 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -873,7 +873,7 @@ qemuBuildVirtioDevGetConfigDev(const virDomainDeviceDef *device,
case VIR_DOMAIN_DEVICE_INPUT:
*virtioOptions = device->data.input->virtio;
- switch ((virDomainInputType) device->data.input->type) {
+ switch (device->data.input->type) {
case VIR_DOMAIN_INPUT_TYPE_MOUSE:
*baseName = "virtio-mouse";
break;
@@ -4510,7 +4510,7 @@ qemuBuildInputVirtioDevProps(const virDomainDef *def,
g_autoptr(virJSONValue) props = NULL;
const char *evdev = NULL;
- switch ((virDomainInputType)dev->type) {
+ switch (dev->type) {
case VIR_DOMAIN_INPUT_TYPE_MOUSE:
case VIR_DOMAIN_INPUT_TYPE_TABLET:
case VIR_DOMAIN_INPUT_TYPE_KBD:
@@ -4559,6 +4559,10 @@ qemuBuildInputUSBDevProps(const virDomainDef *def,
case VIR_DOMAIN_INPUT_TYPE_KBD:
driver = "usb-kbd";
break;
+ case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
+ case VIR_DOMAIN_INPUT_TYPE_EVDEV:
+ case VIR_DOMAIN_INPUT_TYPE_LAST:
+ break;
}
if (virJSONValueObjectAdd(&props,
@@ -4623,7 +4627,7 @@ qemuBuildInputCommandLine(virCommand *cmd,
} else {
g_autoptr(virJSONValue) props = NULL;
- switch ((virDomainInputBus) input->bus) {
+ switch (input->bus) {
case VIR_DOMAIN_INPUT_BUS_USB:
if (!(props = qemuBuildInputUSBDevProps(def, input)))
return -1;
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 753733d1b9..3b1139d975 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -960,9 +960,9 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef *dev,
return pciFlags;
case VIR_DOMAIN_DEVICE_INPUT:
- switch ((virDomainInputBus) dev->data.input->bus) {
+ switch (dev->data.input->bus) {
case VIR_DOMAIN_INPUT_BUS_VIRTIO:
- switch ((virDomainInputModel) dev->data.input->model) {
+ switch (dev->data.input->model) {
case VIR_DOMAIN_INPUT_MODEL_VIRTIO_TRANSITIONAL:
/* Transitional devices only work in conventional PCI slots */
return pciFlags;
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 24df66cc9f..48dfac3f07 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3139,7 +3139,7 @@ qemuDomainAttachInputDevice(virQEMUDriver *driver,
qemuAssignDeviceInputAlias(vm->def, input, -1);
- switch ((virDomainInputBus) input->bus) {
+ switch (input->bus) {
case VIR_DOMAIN_INPUT_BUS_USB:
if (virDomainUSBAddressEnsure(priv->usbaddrs, &input->info) < 0)
return -1;
@@ -5882,7 +5882,7 @@ qemuDomainDetachPrepInput(virDomainObj *vm,
}
*detach = input = vm->def->inputs[idx];
- switch ((virDomainInputBus) input->bus) {
+ switch (input->bus) {
case VIR_DOMAIN_INPUT_BUS_PS2:
case VIR_DOMAIN_INPUT_BUS_XEN:
case VIR_DOMAIN_INPUT_BUS_PARALLELS:
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 3a82a2adfa..f54b4587c0 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -4786,7 +4786,7 @@ qemuValidateDomainDeviceDefInput(const virDomainInputDef *input,
return 0;
/* model=virtio-(non-)transitional is unsupported */
- switch ((virDomainInputModel)input->model) {
+ switch (input->model) {
case VIR_DOMAIN_INPUT_MODEL_VIRTIO_TRANSITIONAL:
case VIR_DOMAIN_INPUT_MODEL_VIRTIO_NON_TRANSITIONAL:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -4804,7 +4804,7 @@ qemuValidateDomainDeviceDefInput(const virDomainInputDef *input,
return -1;
}
- switch ((virDomainInputType)input->type) {
+ switch (input->type) {
case VIR_DOMAIN_INPUT_TYPE_MOUSE:
baseName = "virtio-mouse";
cap = QEMU_CAPS_VIRTIO_MOUSE;
diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
index c05a2fbaac..7160ef99b8 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -712,7 +712,7 @@ AppArmorSetInputLabel(virSecurityManager *mgr,
if (input == NULL)
return 0;
- switch ((virDomainInputType)input->type) {
+ switch (input->type) {
case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
case VIR_DOMAIN_INPUT_TYPE_EVDEV:
if (input->source.evdev == NULL) {
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index 211f5cf9a2..a74337fcf7 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -1792,7 +1792,7 @@ virSecurityDACSetInputLabel(virSecurityManager *mgr,
if (seclabel && !seclabel->relabel)
return 0;
- switch ((virDomainInputType)input->type) {
+ switch (input->type) {
case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
case VIR_DOMAIN_INPUT_TYPE_EVDEV:
if (virSecurityDACGetIds(seclabel, priv, &user, &group, NULL, NULL) <
0)
@@ -1821,7 +1821,7 @@ virSecurityDACRestoreInputLabel(virSecurityManager *mgr,
{
int ret = -1;
- switch ((virDomainInputType)input->type) {
+ switch (input->type) {
case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
case VIR_DOMAIN_INPUT_TYPE_EVDEV:
ret = virSecurityDACRestoreFileLabel(mgr, input->source.evdev);
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 9d9e308a38..22747b667a 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -1512,7 +1512,7 @@ virSecuritySELinuxSetInputLabel(virSecurityManager *mgr,
if (seclabel == NULL)
return 0;
- switch ((virDomainInputType)input->type) {
+ switch (input->type) {
case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
case VIR_DOMAIN_INPUT_TYPE_EVDEV:
if (virSecuritySELinuxSetFilecon(mgr, input->source.evdev,
@@ -1543,7 +1543,7 @@ virSecuritySELinuxRestoreInputLabel(virSecurityManager *mgr,
if (seclabel == NULL)
return 0;
- switch ((virDomainInputType)input->type) {
+ switch (input->type) {
case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
case VIR_DOMAIN_INPUT_TYPE_EVDEV:
rc = virSecuritySELinuxRestoreFileLabel(mgr, input->source.evdev, true);
--
2.35.1