From 46dc4f557546c024c273e0e21110698cdfffe8ae Mon Sep 17 00:00:00 2001 Message-Id: <46dc4f557546c024c273e0e21110698cdfffe8ae@dist-git> From: Erik Skultety Date: Fri, 30 Nov 2018 15:49:25 +0100 Subject: [PATCH] qemu: Extract MDEV VFIO PCI validation code into a separate helper Since we'll need to validate other models apart from VFIO PCI too, having a helper for each model should keep the code base cleaner. Signed-off-by: Erik Skultety Reviewed-by: Boris Fiuczynski (cherry picked from commit 208d6e6f5aafa102d04ce300c6338b0736bb52df) https://bugzilla.redhat.com/show_bug.cgi?id=1508146 Signed-off-by: Pino Toscano Reviewed-by: Jiri Denemark --- src/qemu/qemu_domain.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d80f9b393e..4898d58733 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4451,11 +4451,11 @@ qemuDomainDeviceDefValidateNetwork(const virDomainNetDef *net) static int -qemuDomainMdevDefValidate(const virDomainHostdevSubsysMediatedDev *mdevsrc, - const virDomainDef *def, - virQEMUCapsPtr qemuCaps) +qemuDomainMdevDefVFIOPCIValidate(const virDomainHostdevSubsysMediatedDev *dev, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) { - if (mdevsrc->display == VIR_TRISTATE_SWITCH_ABSENT) + if (dev->display == VIR_TRISTATE_SWITCH_ABSENT) return 0; if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VFIO_PCI_DISPLAY)) { @@ -4465,7 +4465,7 @@ qemuDomainMdevDefValidate(const virDomainHostdevSubsysMediatedDev *mdevsrc, return -1; } - if (mdevsrc->model != VIR_MDEV_MODEL_TYPE_VFIO_PCI) { + if (dev->model != VIR_MDEV_MODEL_TYPE_VFIO_PCI) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _(" attribute 'display' is only supported" " with model='vfio-pci'")); @@ -4473,7 +4473,7 @@ qemuDomainMdevDefValidate(const virDomainHostdevSubsysMediatedDev *mdevsrc, return -1; } - if (mdevsrc->display == VIR_TRISTATE_SWITCH_ON) { + if (dev->display == VIR_TRISTATE_SWITCH_ON) { if (def->ngraphics == 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("graphics device is needed for attribute value " @@ -4486,6 +4486,29 @@ qemuDomainMdevDefValidate(const virDomainHostdevSubsysMediatedDev *mdevsrc, } +static int +qemuDomainMdevDefValidate(const virDomainHostdevSubsysMediatedDev *mdevsrc, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) +{ + switch ((virMediatedDeviceModelType) mdevsrc->model) { + case VIR_MDEV_MODEL_TYPE_VFIO_PCI: + return qemuDomainMdevDefVFIOPCIValidate(mdevsrc, def, qemuCaps); + case VIR_MDEV_MODEL_TYPE_VFIO_AP: + break; + case VIR_MDEV_MODEL_TYPE_VFIO_CCW: + break; + case VIR_MDEV_MODEL_TYPE_LAST: + default: + virReportEnumRangeError(virMediatedDeviceModelType, + mdevsrc->model); + return -1; + } + + return 0; +} + + static int qemuDomainDeviceDefValidateHostdev(const virDomainHostdevDef *hostdev, const virDomainDef *def, -- 2.19.2