[PATCH v14 43/49] improve virHostdevUpdate* parameters to make it more widely used

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

 



Changes parameter from vm def to specific hostdevs info and name info, so that
it could be used more widely, e.g, could be used without full vm def info.

Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx>
---
 src/qemu/qemu_hostdev.c |  9 ++++++---
 src/util/virhostdev.c   | 34 ++++++++++++++++++++--------------
 src/util/virhostdev.h   | 12 +++++++++---
 3 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 6648b71..88907b1 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -50,7 +50,8 @@ qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
     if (!def->nhostdevs)
         return 0;
 
-    return virHostdevUpdateActivePciHostdevs(mgr, QEMU_DRIVER_NAME, def);
+    return virHostdevUpdateActivePciHostdevs(mgr, def->hostdevs, def->nhostdevs,
+                                             QEMU_DRIVER_NAME, def->name);
 }
 
 int
@@ -62,7 +63,8 @@ qemuUpdateActiveUsbHostdevs(virQEMUDriverPtr driver,
     if (!def->nhostdevs)
         return 0;
 
-    return virHostdevUpdateActiveUsbHostdevs(mgr, QEMU_DRIVER_NAME, def);
+    return virHostdevUpdateActiveUsbHostdevs(mgr, def->hostdevs, def->nhostdevs,
+                                             QEMU_DRIVER_NAME, def->name);
 }
 
 int
@@ -74,7 +76,8 @@ qemuUpdateActiveScsiHostdevs(virQEMUDriverPtr driver,
     if (!def->nhostdevs)
         return 0;
 
-    return virHostdevUpdateActiveScsiHostdevs(mgr, QEMU_DRIVER_NAME, def);
+    return virHostdevUpdateActiveScsiHostdevs(mgr, def->hostdevs, def->nhostdevs,
+                                              QEMU_DRIVER_NAME, def->name);
 }
 
 
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index ab36e1f..5fddd8a 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -779,8 +779,10 @@ cleanup:
 
 int
 virHostdevUpdateActivePciHostdevs(virHostdevManagerPtr mgr,
+                                  virDomainHostdevDefPtr *hostdevs,
+                                  int nhostdevs,
                                   const char *drv_name,
-                                  virDomainDefPtr def)
+                                  const char *dom_name)
 {
     virDomainHostdevDefPtr hostdev = NULL;
     virPCIDevicePtr dev = NULL;
@@ -790,8 +792,8 @@ virHostdevUpdateActivePciHostdevs(virHostdevManagerPtr mgr,
     virObjectLock(mgr->activePciHostdevs);
     virObjectLock(mgr->inactivePciHostdevs);
 
-    for (i = 0; i < def->nhostdevs; i++) {
-        hostdev = def->hostdevs[i];
+    for (i = 0; i < nhostdevs; i++) {
+        hostdev = hostdevs[i];
 
         if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
             continue;
@@ -816,7 +818,7 @@ virHostdevUpdateActivePciHostdevs(virHostdevManagerPtr mgr,
                 goto cleanup;
 
         }
-        virPCIDeviceSetUsedBy(dev, drv_name, def->name);
+        virPCIDeviceSetUsedBy(dev, drv_name, dom_name);
 
         /* Setup the original states for the PCI device */
         virPCIDeviceSetUnbindFromStub(dev, hostdev->origstates.states.pci.unbind_from_stub);
@@ -838,17 +840,19 @@ cleanup:
 
 int
 virHostdevUpdateActiveUsbHostdevs(virHostdevManagerPtr mgr,
+                                  virDomainHostdevDefPtr *hostdevs,
+                                  int nhostdevs,
                                   const char *drv_name,
-                                  virDomainDefPtr def)
+                                  const char *dom_name)
 {
     virDomainHostdevDefPtr hostdev = NULL;
     size_t i;
     int ret = -1;
 
     virObjectLock(mgr->activeUsbHostdevs);
-    for (i = 0; i < def->nhostdevs; i++) {
+    for (i = 0; i < nhostdevs; i++) {
         virUSBDevicePtr usb = NULL;
-        hostdev = def->hostdevs[i];
+        hostdev = hostdevs[i];
 
         if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
             continue;
@@ -862,11 +866,11 @@ virHostdevUpdateActiveUsbHostdevs(virHostdevManagerPtr mgr,
             VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s",
                      hostdev->source.subsys.u.usb.bus,
                      hostdev->source.subsys.u.usb.device,
-                     def->name);
+                     dom_name);
             continue;
         }
 
-        virUSBDeviceSetUsedBy(usb, drv_name, def->name);
+        virUSBDeviceSetUsedBy(usb, drv_name, dom_name);
 
         if (virUSBDeviceListAdd(mgr->activeUsbHostdevs, usb) < 0) {
             virUSBDeviceFree(usb);
@@ -881,8 +885,10 @@ cleanup:
 
 int
 virHostdevUpdateActiveScsiHostdevs(virHostdevManagerPtr mgr,
+                                   virDomainHostdevDefPtr *hostdevs,
+                                   int nhostdevs,
                                    const char *drv_name,
-                                   virDomainDefPtr def)
+                                   const char *dom_name)
 {
     virDomainHostdevDefPtr hostdev = NULL;
     size_t i;
@@ -891,8 +897,8 @@ virHostdevUpdateActiveScsiHostdevs(virHostdevManagerPtr mgr,
     virSCSIDevicePtr tmp = NULL;
 
     virObjectLock(mgr->activeScsiHostdevs);
-    for (i = 0; i < def->nhostdevs; i++) {
-        hostdev = def->hostdevs[i];
+    for (i = 0; i < nhostdevs; i++) {
+        hostdev = hostdevs[i];
 
         if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
             hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
@@ -908,13 +914,13 @@ virHostdevUpdateActiveScsiHostdevs(virHostdevManagerPtr mgr,
             goto cleanup;
 
         if ((tmp = virSCSIDeviceListFind(mgr->activeScsiHostdevs, scsi))) {
-            if (virSCSIDeviceSetUsedBy(tmp, drv_name, def->name) < 0) {
+            if (virSCSIDeviceSetUsedBy(tmp, drv_name, dom_name) < 0) {
                 virSCSIDeviceFree(scsi);
                 goto cleanup;
             }
             virSCSIDeviceFree(scsi);
         } else {
-            if (virSCSIDeviceSetUsedBy(scsi, drv_name, def->name) < 0 ||
+            if (virSCSIDeviceSetUsedBy(scsi, drv_name, dom_name) < 0 ||
                 virSCSIDeviceListAdd(mgr->activeScsiHostdevs, scsi) < 0) {
                 virSCSIDeviceFree(scsi);
                 goto cleanup;
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index 3fd38b5..8680e5d 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -92,16 +92,22 @@ virHostdevReAttachScsiHostdevs(virHostdevManagerPtr hostdev_mgr,
                                int nhostdevs);
 int
 virHostdevUpdateActivePciHostdevs(virHostdevManagerPtr mgr,
+                                  virDomainHostdevDefPtr *hostdevs,
+                                  int nhostdevs,
                                   const char *drv_name,
-                                  virDomainDefPtr def);
+                                  const char *dom_name);
 int
 virHostdevUpdateActiveUsbHostdevs(virHostdevManagerPtr mgr,
+                                  virDomainHostdevDefPtr *hostdevs,
+                                  int nhostdevs,
                                   const char *drv_name,
-                                  virDomainDefPtr def);
+                                  const char *dom_name);
 int
 virHostdevUpdateActiveScsiHostdevs(virHostdevManagerPtr mgr,
+                                   virDomainHostdevDefPtr *hostdevs,
+                                   int nhostdevs,
                                    const char *drv_name,
-                                   virDomainDefPtr def);
+                                   const char *dom_name);
 
 /* functions used by NodeDevDetach/Reattach/Reset */
 int virHostdevPciNodeDeviceDetach(virHostdevManagerPtr mgr,
-- 
1.9.0

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