[PATCH 7/9] lxc: Make activeUsbHostdevs use locks

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

 



The activeUsbHostdevs item in LXCDriver are lockable, but the lock has
to be called explicitly. Call the virObject(Un)Lock() in order to
achieve mutual exclusion once lxcDriverLock is removed.
---
 src/lxc/lxc_driver.c  | 2 ++
 src/lxc/lxc_hostdev.c | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index df9fb92..1210e77 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -4139,7 +4139,9 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
         VIR_WARN("cannot deny device %s for domain %s",
                  dst, vm->def->name);
 
+    virObjectLock(driver->activeUsbHostdevs);
     virUSBDeviceListDel(driver->activeUsbHostdevs, usb);
+    virObjectUnlock(driver->activeUsbHostdevs);
 
     virDomainHostdevRemove(vm->def, idx);
     virDomainHostdevDefFree(def);
diff --git a/src/lxc/lxc_hostdev.c b/src/lxc/lxc_hostdev.c
index 257e93b..3b371fc 100644
--- a/src/lxc/lxc_hostdev.c
+++ b/src/lxc/lxc_hostdev.c
@@ -62,10 +62,13 @@ virLXCUpdateActiveUsbHostdevs(virLXCDriverPtr driver,
 
         virUSBDeviceSetUsedBy(usb, def->name);
 
+        virObjectLock(driver->activeUsbHostdevs);
         if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
+            virObjectUnlock(driver->activeUsbHostdevs);
             virUSBDeviceFree(usb);
             return -1;
         }
+        virObjectUnlock(driver->activeUsbHostdevs);
     }
 
     return 0;
@@ -83,6 +86,7 @@ virLXCPrepareHostdevUSBDevices(virLXCDriverPtr driver,
 
     count = virUSBDeviceListCount(list);
 
+    virObjectLock(driver->activeUsbHostdevs);
     for (i = 0; i < count; i++) {
         virUSBDevicePtr usb = virUSBDeviceListGet(list, i);
         if ((tmp = virUSBDeviceListFind(driver->activeUsbHostdevs, usb))) {
@@ -110,6 +114,7 @@ virLXCPrepareHostdevUSBDevices(virLXCDriverPtr driver,
         if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0)
             goto error;
     }
+    virObjectUnlock(driver->activeUsbHostdevs);
     return 0;
 
 error:
@@ -117,6 +122,7 @@ error:
         tmp = virUSBDeviceListGet(list, i);
         virUSBDeviceListSteal(driver->activeUsbHostdevs, tmp);
     }
+    virObjectUnlock(driver->activeUsbHostdevs);
     return -1;
 }
 
@@ -341,6 +347,7 @@ virLXCDomainReAttachHostUsbDevices(virLXCDriverPtr driver,
 {
     size_t i;
 
+    virObjectLock(driver->activeUsbHostdevs);
     for (i = 0; i < nhostdevs; i++) {
         virDomainHostdevDefPtr hostdev = hostdevs[i];
         virUSBDevicePtr usb, tmp;
@@ -392,6 +399,7 @@ virLXCDomainReAttachHostUsbDevices(virLXCDriverPtr driver,
             virUSBDeviceListDel(driver->activeUsbHostdevs, tmp);
         }
     }
+    virObjectUnlock(driver->activeUsbHostdevs);
 }
 
 void virLXCDomainReAttachHostDevices(virLXCDriverPtr driver,
-- 
1.8.1.5

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