mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 19:32:19 +00:00
node_device: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
fb48d87765
commit
a99d876a0f
@ -156,33 +156,18 @@ nodeDeviceUpdateDriverName(virNodeDeviceDef *def G_GNUC_UNUSED)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
nodeDeviceLock(void)
|
|
||||||
{
|
|
||||||
virMutexLock(&driver->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
nodeDeviceUnlock(void)
|
|
||||||
{
|
|
||||||
virMutexUnlock(&driver->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
nodeDeviceInitWait(void)
|
nodeDeviceInitWait(void)
|
||||||
{
|
{
|
||||||
nodeDeviceLock();
|
VIR_LOCK_GUARD lock = virLockGuardLock(&driver->lock);
|
||||||
|
|
||||||
while (!driver->initialized) {
|
while (!driver->initialized) {
|
||||||
if (virCondWait(&driver->initCond, &driver->lock) < 0) {
|
if (virCondWait(&driver->initCond, &driver->lock) < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s", _("failed to wait on condition"));
|
||||||
_("failed to wait on condition"));
|
|
||||||
nodeDeviceUnlock();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nodeDeviceUnlock();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,9 +93,9 @@ udevEventDataDispose(void *obj)
|
|||||||
udev_monitor_unref(priv->udev_monitor);
|
udev_monitor_unref(priv->udev_monitor);
|
||||||
udev_unref(udev);
|
udev_unref(udev);
|
||||||
|
|
||||||
virMutexLock(&priv->mdevctlLock);
|
VIR_WITH_MUTEX_LOCK_GUARD(&priv->mdevctlLock) {
|
||||||
g_list_free_full(priv->mdevctlMonitors, g_object_unref);
|
g_list_free_full(priv->mdevctlMonitors, g_object_unref);
|
||||||
virMutexUnlock(&priv->mdevctlLock);
|
}
|
||||||
virMutexDestroy(&priv->mdevctlLock);
|
virMutexDestroy(&priv->mdevctlLock);
|
||||||
|
|
||||||
virCondDestroy(&priv->threadCond);
|
virCondDestroy(&priv->threadCond);
|
||||||
@ -348,13 +348,9 @@ udevTranslatePCIIds(unsigned int vendor,
|
|||||||
m.match_data = 0;
|
m.match_data = 0;
|
||||||
|
|
||||||
/* pci_get_strings returns void and unfortunately is not thread safe. */
|
/* pci_get_strings returns void and unfortunately is not thread safe. */
|
||||||
virMutexLock(&pciaccessMutex);
|
VIR_WITH_MUTEX_LOCK_GUARD(&pciaccessMutex) {
|
||||||
pci_get_strings(&m,
|
pci_get_strings(&m, &device_name, &vendor_name, NULL, NULL);
|
||||||
&device_name,
|
}
|
||||||
&vendor_name,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
virMutexUnlock(&pciaccessMutex);
|
|
||||||
|
|
||||||
*vendor_string = g_strdup(vendor_name);
|
*vendor_string = g_strdup(vendor_name);
|
||||||
*product_string = g_strdup(device_name);
|
*product_string = g_strdup(device_name);
|
||||||
@ -373,11 +369,11 @@ udevProcessPCI(struct udev_device *device,
|
|||||||
virPCIDeviceAddress devAddr;
|
virPCIDeviceAddress devAddr;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *p;
|
char *p;
|
||||||
bool privileged;
|
bool privileged = false;
|
||||||
|
|
||||||
nodeDeviceLock();
|
VIR_WITH_MUTEX_LOCK_GUARD(&driver->lock) {
|
||||||
privileged = driver->privileged;
|
privileged = driver->privileged;
|
||||||
nodeDeviceUnlock();
|
}
|
||||||
|
|
||||||
pci_dev->klass = -1;
|
pci_dev->klass = -1;
|
||||||
if (udevGetIntProperty(device, "PCI_CLASS", &pci_dev->klass, 16) < 0)
|
if (udevGetIntProperty(device, "PCI_CLASS", &pci_dev->klass, 16) < 0)
|
||||||
@ -1989,10 +1985,10 @@ nodeStateInitializeEnumerate(void *opaque)
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
nodeDeviceLock();
|
VIR_WITH_MUTEX_LOCK_GUARD(&driver->lock) {
|
||||||
driver->initialized = true;
|
driver->initialized = true;
|
||||||
virCondBroadcast(&driver->initCond);
|
virCondBroadcast(&driver->initCond);
|
||||||
nodeDeviceUnlock();
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -2036,12 +2032,10 @@ static void
|
|||||||
mdevctlHandlerThread(void *opaque G_GNUC_UNUSED)
|
mdevctlHandlerThread(void *opaque G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
udevEventData *priv = driver->privateData;
|
udevEventData *priv = driver->privateData;
|
||||||
|
VIR_LOCK_GUARD lock = virLockGuardLock(&priv->mdevctlLock);
|
||||||
|
|
||||||
/* ensure only a single thread can query mdevctl at a time */
|
|
||||||
virMutexLock(&priv->mdevctlLock);
|
|
||||||
if (nodeDeviceUpdateMediatedDevices() < 0)
|
if (nodeDeviceUpdateMediatedDevices() < 0)
|
||||||
VIR_WARN("mdevctl failed to updated mediated devices");
|
VIR_WARN("mdevctl failed to updated mediated devices");
|
||||||
virMutexUnlock(&priv->mdevctlLock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2143,13 +2137,10 @@ mdevctlEnableMonitor(udevEventData *priv)
|
|||||||
* mdevctl configuration is stored in a directory tree within
|
* mdevctl configuration is stored in a directory tree within
|
||||||
* /etc/mdevctl.d/. There is a directory for each parent device, which
|
* /etc/mdevctl.d/. There is a directory for each parent device, which
|
||||||
* contains a file defining each mediated device */
|
* contains a file defining each mediated device */
|
||||||
virMutexLock(&priv->mdevctlLock);
|
VIR_WITH_MUTEX_LOCK_GUARD(&priv->mdevctlLock) {
|
||||||
if (!(priv->mdevctlMonitors = monitorFileRecursively(priv,
|
if (!(priv->mdevctlMonitors = monitorFileRecursively(priv, mdevctlConfigDir)))
|
||||||
mdevctlConfigDir))) {
|
return -1;
|
||||||
virMutexUnlock(&priv->mdevctlLock);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
virMutexUnlock(&priv->mdevctlLock);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2171,9 +2162,10 @@ mdevctlEventHandleCallback(GFileMonitor *monitor G_GNUC_UNUSED,
|
|||||||
if (file_type == G_FILE_TYPE_DIRECTORY) {
|
if (file_type == G_FILE_TYPE_DIRECTORY) {
|
||||||
GList *newmonitors = monitorFileRecursively(priv, file);
|
GList *newmonitors = monitorFileRecursively(priv, file);
|
||||||
|
|
||||||
virMutexLock(&priv->mdevctlLock);
|
VIR_WITH_MUTEX_LOCK_GUARD(&priv->mdevctlLock) {
|
||||||
priv->mdevctlMonitors = g_list_concat(priv->mdevctlMonitors, newmonitors);
|
priv->mdevctlMonitors = g_list_concat(priv->mdevctlMonitors,
|
||||||
virMutexUnlock(&priv->mdevctlLock);
|
newmonitors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user