提交 94410ded 编写于 作者: D Daniel Henrique Barboza 提交者: Ján Tomko

qemu: move qemuDomainDeviceDefValidateHostdev() to qemu_validate.c

This function alone requires other 3 static functions to be
moved as well, thus let's move it in its own patch.
Signed-off-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
Signed-off-by: NJán Tomko <jtomko@redhat.com>
上级 f38cfe72
......@@ -5245,194 +5245,6 @@ qemuDomainValidateActualNetDef(const virDomainNetDef *net,
}
static int
qemuDomainMdevDefVFIOPCIValidate(const virDomainHostdevDef *hostdev,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
const virDomainHostdevSubsysMediatedDev *dev;
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("VFIO PCI device assignment is not "
"supported by this version of QEMU"));
return -1;
}
/* VFIO-PCI does not support boot */
if (hostdev->info->bootIndex) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("booting from assigned devices is not "
"supported by mediated devices of "
"model vfio-pci"));
return -1;
}
dev = &hostdev->source.subsys.u.mdev;
if (dev->display == VIR_TRISTATE_SWITCH_ABSENT)
return 0;
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VFIO_PCI_DISPLAY)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("display property of device vfio-pci is "
"not supported by this version of QEMU"));
return -1;
}
if (dev->model != VIR_MDEV_MODEL_TYPE_VFIO_PCI) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("<hostdev> attribute 'display' is only supported"
" with model='vfio-pci'"));
return -1;
}
if (dev->display == VIR_TRISTATE_SWITCH_ON) {
if (def->ngraphics == 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("graphics device is needed for attribute value "
"'display=on' in <hostdev>"));
return -1;
}
}
return 0;
}
static int
qemuDomainMdevDefVFIOAPValidate(const virDomainHostdevDef *hostdev,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
size_t i;
bool vfioap_found = false;
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_AP)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("VFIO AP device assignment is not "
"supported by this version of QEMU"));
return -1;
}
/* VFIO-AP does not support boot */
if (hostdev->info->bootIndex) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("booting from assigned devices is not "
"supported by mediated devices of "
"model vfio-ap"));
return -1;
}
/* VFIO-AP is restricted to a single mediated device only */
for (i = 0; i < def->nhostdevs; i++) {
virDomainHostdevDefPtr hdev = def->hostdevs[i];
if (virHostdevIsMdevDevice(hdev) &&
hdev->source.subsys.u.mdev.model == VIR_MDEV_MODEL_TYPE_VFIO_AP) {
if (vfioap_found) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Only one hostdev of model vfio-ap is "
"supported"));
return -1;
}
vfioap_found = true;
}
}
return 0;
}
static int
qemuDomainMdevDefValidate(const virDomainHostdevDef *hostdev,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
const virDomainHostdevSubsysMediatedDev *mdevsrc;
mdevsrc = &hostdev->source.subsys.u.mdev;
switch ((virMediatedDeviceModelType) mdevsrc->model) {
case VIR_MDEV_MODEL_TYPE_VFIO_PCI:
return qemuDomainMdevDefVFIOPCIValidate(hostdev, def, qemuCaps);
case VIR_MDEV_MODEL_TYPE_VFIO_AP:
return qemuDomainMdevDefVFIOAPValidate(hostdev, def, qemuCaps);
case VIR_MDEV_MODEL_TYPE_VFIO_CCW:
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_CCW)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("VFIO CCW device assignment is not "
"supported by this version of QEMU"));
return -1;
}
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,
virQEMUCapsPtr qemuCaps)
{
int backend;
/* forbid capabilities mode hostdev in this kind of hypervisor */
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("hostdev mode 'capabilities' is not "
"supported in %s"),
virDomainVirtTypeToString(def->virtType));
return -1;
}
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
backend = hostdev->source.subsys.u.pci.backend;
if (backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("VFIO PCI device assignment is not "
"supported by this version of qemu"));
return -1;
}
}
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
if (hostdev->info->bootIndex) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("booting from assigned devices is not "
"supported by vhost SCSI devices"));
return -1;
}
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
return qemuDomainMdevDefValidate(hostdev, def, qemuCaps);
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
default:
virReportEnumRangeError(virDomainHostdevSubsysType,
hostdev->source.subsys.type);
return -1;
}
}
return 0;
}
static int
qemuDomainDeviceDefValidateVideo(const virDomainVideoDef *video,
virQEMUCapsPtr qemuCaps)
......@@ -7265,7 +7077,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
break;
case VIR_DOMAIN_DEVICE_HOSTDEV:
ret = qemuDomainDeviceDefValidateHostdev(dev->data.hostdev, def,
ret = qemuValidateDomainDeviceDefHostdev(dev->data.hostdev, def,
qemuCaps);
break;
......
......@@ -1532,3 +1532,191 @@ qemuValidateDomainWatchdogDef(const virDomainWatchdogDef *dev,
return 0;
}
static int
qemuValidateDomainMdevDefVFIOPCI(const virDomainHostdevDef *hostdev,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
const virDomainHostdevSubsysMediatedDev *dev;
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("VFIO PCI device assignment is not "
"supported by this version of QEMU"));
return -1;
}
/* VFIO-PCI does not support boot */
if (hostdev->info->bootIndex) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("booting from assigned devices is not "
"supported by mediated devices of "
"model vfio-pci"));
return -1;
}
dev = &hostdev->source.subsys.u.mdev;
if (dev->display == VIR_TRISTATE_SWITCH_ABSENT)
return 0;
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VFIO_PCI_DISPLAY)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("display property of device vfio-pci is "
"not supported by this version of QEMU"));
return -1;
}
if (dev->model != VIR_MDEV_MODEL_TYPE_VFIO_PCI) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("<hostdev> attribute 'display' is only supported"
" with model='vfio-pci'"));
return -1;
}
if (dev->display == VIR_TRISTATE_SWITCH_ON) {
if (def->ngraphics == 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("graphics device is needed for attribute value "
"'display=on' in <hostdev>"));
return -1;
}
}
return 0;
}
static int
qemuValidateDomainMdevDefVFIOAP(const virDomainHostdevDef *hostdev,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
size_t i;
bool vfioap_found = false;
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_AP)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("VFIO AP device assignment is not "
"supported by this version of QEMU"));
return -1;
}
/* VFIO-AP does not support boot */
if (hostdev->info->bootIndex) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("booting from assigned devices is not "
"supported by mediated devices of "
"model vfio-ap"));
return -1;
}
/* VFIO-AP is restricted to a single mediated device only */
for (i = 0; i < def->nhostdevs; i++) {
virDomainHostdevDefPtr hdev = def->hostdevs[i];
if (virHostdevIsMdevDevice(hdev) &&
hdev->source.subsys.u.mdev.model == VIR_MDEV_MODEL_TYPE_VFIO_AP) {
if (vfioap_found) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Only one hostdev of model vfio-ap is "
"supported"));
return -1;
}
vfioap_found = true;
}
}
return 0;
}
static int
qemuValidateDomainMdevDef(const virDomainHostdevDef *hostdev,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
const virDomainHostdevSubsysMediatedDev *mdevsrc;
mdevsrc = &hostdev->source.subsys.u.mdev;
switch ((virMediatedDeviceModelType) mdevsrc->model) {
case VIR_MDEV_MODEL_TYPE_VFIO_PCI:
return qemuValidateDomainMdevDefVFIOPCI(hostdev, def, qemuCaps);
case VIR_MDEV_MODEL_TYPE_VFIO_AP:
return qemuValidateDomainMdevDefVFIOAP(hostdev, def, qemuCaps);
case VIR_MDEV_MODEL_TYPE_VFIO_CCW:
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_CCW)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("VFIO CCW device assignment is not "
"supported by this version of QEMU"));
return -1;
}
break;
case VIR_MDEV_MODEL_TYPE_LAST:
default:
virReportEnumRangeError(virMediatedDeviceModelType,
mdevsrc->model);
return -1;
}
return 0;
}
int
qemuValidateDomainDeviceDefHostdev(const virDomainHostdevDef *hostdev,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
int backend;
/* forbid capabilities mode hostdev in this kind of hypervisor */
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("hostdev mode 'capabilities' is not "
"supported in %s"),
virDomainVirtTypeToString(def->virtType));
return -1;
}
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
backend = hostdev->source.subsys.u.pci.backend;
if (backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("VFIO PCI device assignment is not "
"supported by this version of qemu"));
return -1;
}
}
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
if (hostdev->info->bootIndex) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("booting from assigned devices is not "
"supported by vhost SCSI devices"));
return -1;
}
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
return qemuValidateDomainMdevDef(hostdev, def, qemuCaps);
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
default:
virReportEnumRangeError(virDomainHostdevSubsysType,
hostdev->source.subsys.type);
return -1;
}
}
return 0;
}
......@@ -41,3 +41,6 @@ int qemuValidateDomainRedirdevDef(const virDomainRedirdevDef *def,
virQEMUCapsPtr qemuCaps);
int qemuValidateDomainWatchdogDef(const virDomainWatchdogDef *dev,
const virDomainDef *def);
int qemuValidateDomainDeviceDefHostdev(const virDomainHostdevDef *hostdev,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册