From 2a82171affa266e4afe472ea7b79038e338aab52 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Wed, 17 Jul 2013 09:14:42 +0200 Subject: [PATCH] lxc: Make activeUsbHostdevs use locks 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 a79f620a39..7cfd450bbd 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -4167,7 +4167,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 257e93b343..3b371fc002 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, -- GitLab