[PATCH v13 07/49] qemu_hostdev: move cfg->relaxedACS as a flag

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

 



For extracting hostdev codes from qemu_hostdev.c to common library, change qemu
specific cfg->relaxedACS handling to be a flag, and pass it to hostdev
functions.

Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx>
---
 src/qemu/qemu_hostdev.c |   11 +++++++----
 src/qemu/qemu_hostdev.h |   10 ++++++++--
 src/qemu/qemu_hotplug.c |   11 +++++++++--
 src/qemu/qemu_process.c |    5 ++++-
 4 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 54ac973..5f2dc44 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -659,7 +659,8 @@ qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
                              const unsigned char *uuid,
                              virDomainHostdevDefPtr *hostdevs,
                              int nhostdevs,
-                             virQEMUCapsPtr qemuCaps)
+                             virQEMUCapsPtr qemuCaps,
+                             unsigned int flags)
 {
     virPCIDeviceListPtr pcidevs = NULL;
     int last_processed_hostdev_vf = -1;
@@ -695,8 +696,9 @@ qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
     for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
         virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
         virPCIDevicePtr other;
+        bool strict_acs_check = !!(flags & VIR_STRICT_ACS_CHECK);
 
-        if (!virPCIDeviceIsAssignable(dev, !cfg->relaxedACS)) {
+        if (!virPCIDeviceIsAssignable(dev, strict_acs_check)) {
             virReportError(VIR_ERR_OPERATION_INVALID,
                            _("PCI device %s is not assignable"),
                            virPCIDeviceGetName(dev));
@@ -1214,14 +1216,15 @@ int
 qemuPrepareHostDevices(virQEMUDriverPtr driver,
                        virDomainDefPtr def,
                        virQEMUCapsPtr qemuCaps,
-                       bool coldBoot)
+                       bool coldBoot,
+                       unsigned int flags)
 {
     if (!def->nhostdevs)
         return 0;
 
     if (qemuPrepareHostdevPCIDevices(driver, def->name, def->uuid,
                                      def->hostdevs, def->nhostdevs,
-                                     qemuCaps) < 0)
+                                     qemuCaps, flags) < 0)
         return -1;
 
     if (qemuPrepareHostUSBDevices(driver, def, coldBoot) < 0)
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 5b34245..48ca610 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -27,6 +27,10 @@
 # include "qemu_conf.h"
 # include "domain_conf.h"
 
+typedef enum {
+     VIR_STRICT_ACS_CHECK     = (1 << 0), /* strict acs check */
+} virHostdevFlag;
+
 int qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
                                 virDomainDefPtr def);
 int qemuUpdateActiveUsbHostdevs(virQEMUDriverPtr driver,
@@ -40,7 +44,8 @@ int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
                                  const unsigned char *uuid,
                                  virDomainHostdevDefPtr *hostdevs,
                                  int nhostdevs,
-                                 virQEMUCapsPtr qemuCaps);
+                                 virQEMUCapsPtr qemuCaps,
+                                 unsigned int flags);
 int
 qemuPrepareHostUSBDevices(virQEMUDriverPtr driver,
                           virDomainDefPtr def,
@@ -52,7 +57,8 @@ int qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
 int qemuPrepareHostDevices(virQEMUDriverPtr driver,
                            virDomainDefPtr def,
                            virQEMUCapsPtr qemuCaps,
-                           bool coldBoot);
+                           bool coldBoot,
+                           unsigned int flags);
 void
 qemuDomainReAttachHostUsbDevices(virQEMUDriverPtr driver,
                                  const char *name,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index eeb1f24..a213929 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1155,13 +1155,17 @@ qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
     bool teardownlabel = false;
     int backend;
     unsigned long long memKB;
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    unsigned int flags = 0;
 
     if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
         return -1;
 
+    if (!cfg->relaxedACS)
+        flags |= VIR_STRICT_ACS_CHECK;
     if (qemuPrepareHostdevPCIDevices(driver, vm->def->name, vm->def->uuid,
-                                     &hostdev, 1, priv->qemuCaps) < 0)
-        return -1;
+                                     &hostdev, 1, priv->qemuCaps, flags) < 0)
+        goto cleanup;
 
     /* this could have been changed by qemuPrepareHostdevPCIDevices */
     backend = hostdev->source.subsys.u.pci.backend;
@@ -1255,6 +1259,7 @@ qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
     VIR_FREE(devstr);
     VIR_FREE(configfd_name);
     VIR_FORCE_CLOSE(configfd);
+    virObjectUnref(cfg);
 
     return 0;
 
@@ -1275,6 +1280,8 @@ error:
     VIR_FREE(configfd_name);
     VIR_FORCE_CLOSE(configfd);
 
+cleanup:
+    virObjectUnref(cfg);
     return -1;
 }
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index ffa939a..47ecfe4 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3596,6 +3596,7 @@ int qemuProcessStart(virConnectPtr conn,
     unsigned int stop_flags;
     virQEMUDriverConfigPtr cfg;
     virCapsPtr caps = NULL;
+    unsigned int hostdev_flags = 0;
 
     VIR_DEBUG("vm=%p name=%s id=%d pid=%llu",
               vm, vm->def->name, vm->def->id,
@@ -3685,8 +3686,10 @@ int qemuProcessStart(virConnectPtr conn,
 
     /* Must be run before security labelling */
     VIR_DEBUG("Preparing host devices");
+    if (!cfg->relaxedACS)
+        hostdev_flags |= VIR_STRICT_ACS_CHECK;
     if (qemuPrepareHostDevices(driver, vm->def, priv->qemuCaps,
-                               !migrateFrom) < 0)
+                               !migrateFrom, hostdev_flags) < 0)
         goto cleanup;
 
     VIR_DEBUG("Preparing chr devices");
-- 
1.6.0.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[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]