[PATCH 07/15] qemu: move qemuDomainDeviceDefValidateHostdev() to qemu_validate.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/qemu/qemu_domain.c   | 190 +--------------------------------------
 src/qemu/qemu_validate.c | 188 ++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_validate.h |   3 +
 3 files changed, 192 insertions(+), 189 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 4726fa015d..25b889b2d6 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -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)
@@ -7256,7 +7068,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;
 
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 9b67c753c2..62ecca3c84 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1531,3 +1531,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;
+}
diff --git a/src/qemu/qemu_validate.h b/src/qemu/qemu_validate.h
index d2238445be..ca1449c27f 100644
--- a/src/qemu/qemu_validate.h
+++ b/src/qemu/qemu_validate.h
@@ -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);
-- 
2.25.1






[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux