[PATCH v13 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   |   35 ++++++++++++++++++++---------------
 src/util/virhostdev.h   |   12 +++++++++---
 3 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 8b67b88..56afe0a 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -53,7 +53,8 @@ qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
     if (mgr == NULL)
         return -1;
 
-    return virHostdevUpdateActivePciHostdevs(mgr, QEMU_DRIVER_NAME, def);
+    return virHostdevUpdateActivePciHostdevs(mgr, def->hostdevs, def->nhostdevs,
+                                             QEMU_DRIVER_NAME, def->name);
 }
 
 int
@@ -68,7 +69,8 @@ qemuUpdateActiveUsbHostdevs(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
     if (mgr == NULL)
         return -1;
 
-    return virHostdevUpdateActiveUsbHostdevs(mgr, QEMU_DRIVER_NAME, def);
+    return virHostdevUpdateActiveUsbHostdevs(mgr, def->hostdevs, def->nhostdevs,
+                                             QEMU_DRIVER_NAME, def->name);
 }
 
 int
@@ -83,7 +85,8 @@ qemuUpdateActiveScsiHostdevs(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
     if (mgr == NULL)
         return -1;
 
-    return virHostdevUpdateActiveScsiHostdevs(mgr, QEMU_DRIVER_NAME, def);
+    return virHostdevUpdateActiveScsiHostdevs(mgr, def->hostdevs, def->nhostdevs,
+                                              QEMU_DRIVER_NAME, def->name);
 }
 
 bool
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 1ee44cf..3160bb6 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -753,9 +753,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;
@@ -765,8 +766,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;
@@ -791,7 +792,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);
@@ -813,17 +814,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;
@@ -837,11 +840,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);
@@ -856,8 +859,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;
@@ -866,8 +871,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)
@@ -883,13 +888,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 bdfc908..387c160 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.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]