mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
node_device_udev: 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
86f048c85e
commit
dd057af7ae
@ -1688,10 +1688,10 @@ nodeStateCleanup(void)
|
|||||||
|
|
||||||
priv = driver->privateData;
|
priv = driver->privateData;
|
||||||
if (priv) {
|
if (priv) {
|
||||||
virObjectLock(priv);
|
VIR_WITH_OBJECT_LOCK_GUARD(priv) {
|
||||||
priv->threadQuit = true;
|
priv->threadQuit = true;
|
||||||
virCondSignal(&priv->threadCond);
|
virCondSignal(&priv->threadCond);
|
||||||
virObjectUnlock(priv);
|
}
|
||||||
if (priv->initThread) {
|
if (priv->initThread) {
|
||||||
virThreadJoin(priv->initThread);
|
virThreadJoin(priv->initThread);
|
||||||
g_clear_pointer(&priv->initThread, g_free);
|
g_clear_pointer(&priv->initThread, g_free);
|
||||||
@ -1807,24 +1807,21 @@ udevEventHandleThread(void *opaque G_GNUC_UNUSED)
|
|||||||
|
|
||||||
/* continue rather than break from the loop on non-fatal errors */
|
/* continue rather than break from the loop on non-fatal errors */
|
||||||
while (1) {
|
while (1) {
|
||||||
virObjectLock(priv);
|
VIR_WITH_OBJECT_LOCK_GUARD(priv) {
|
||||||
while (!priv->dataReady && !priv->threadQuit) {
|
while (!priv->dataReady && !priv->threadQuit) {
|
||||||
if (virCondWait(&priv->threadCond, &priv->parent.lock)) {
|
if (virCondWait(&priv->threadCond, &priv->parent.lock)) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("handler failed to wait on condition"));
|
_("handler failed to wait on condition"));
|
||||||
virObjectUnlock(priv);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (priv->threadQuit) {
|
if (priv->threadQuit)
|
||||||
virObjectUnlock(priv);
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
device = udev_monitor_receive_device(priv->udev_monitor);
|
device = udev_monitor_receive_device(priv->udev_monitor);
|
||||||
virObjectUnlock(priv);
|
}
|
||||||
|
|
||||||
if (!device) {
|
if (!device) {
|
||||||
if (errno == 0) {
|
if (errno == 0) {
|
||||||
@ -1848,9 +1845,9 @@ udevEventHandleThread(void *opaque G_GNUC_UNUSED)
|
|||||||
/* Trying to move the reset of the @priv->dataReady flag to
|
/* Trying to move the reset of the @priv->dataReady flag to
|
||||||
* after the udev_monitor_receive_device wouldn't help much
|
* after the udev_monitor_receive_device wouldn't help much
|
||||||
* due to event mgmt and scheduler timing. */
|
* due to event mgmt and scheduler timing. */
|
||||||
virObjectLock(priv);
|
VIR_WITH_OBJECT_LOCK_GUARD(priv) {
|
||||||
priv->dataReady = false;
|
priv->dataReady = false;
|
||||||
virObjectUnlock(priv);
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1873,8 +1870,7 @@ udevEventHandleCallback(int watch G_GNUC_UNUSED,
|
|||||||
void *data G_GNUC_UNUSED)
|
void *data G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
udevEventData *priv = driver->privateData;
|
udevEventData *priv = driver->privateData;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
|
||||||
virObjectLock(priv);
|
|
||||||
|
|
||||||
if (!udevEventMonitorSanityCheck(priv, fd))
|
if (!udevEventMonitorSanityCheck(priv, fd))
|
||||||
priv->threadQuit = true;
|
priv->threadQuit = true;
|
||||||
@ -1882,7 +1878,6 @@ udevEventHandleCallback(int watch G_GNUC_UNUSED,
|
|||||||
priv->dataReady = true;
|
priv->dataReady = true;
|
||||||
|
|
||||||
virCondSignal(&priv->threadCond);
|
virCondSignal(&priv->threadCond);
|
||||||
virObjectUnlock(priv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1897,18 +1892,17 @@ udevGetDMIData(virNodeDevCapSystem *syscap)
|
|||||||
virNodeDevCapSystemHardware *hardware = &syscap->hardware;
|
virNodeDevCapSystemHardware *hardware = &syscap->hardware;
|
||||||
virNodeDevCapSystemFirmware *firmware = &syscap->firmware;
|
virNodeDevCapSystemFirmware *firmware = &syscap->firmware;
|
||||||
|
|
||||||
virObjectLock(priv);
|
VIR_WITH_OBJECT_LOCK_GUARD(priv) {
|
||||||
udev = udev_monitor_get_udev(priv->udev_monitor);
|
udev = udev_monitor_get_udev(priv->udev_monitor);
|
||||||
|
|
||||||
device = udev_device_new_from_syspath(udev, DMI_DEVPATH);
|
device = udev_device_new_from_syspath(udev, DMI_DEVPATH);
|
||||||
if (device == NULL) {
|
if (device == NULL) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to get udev device for syspath '%s'"),
|
_("Failed to get udev device for syspath '%s'"),
|
||||||
DMI_DEVPATH);
|
DMI_DEVPATH);
|
||||||
virObjectUnlock(priv);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
virObjectUnlock(priv);
|
|
||||||
|
|
||||||
if (udevGetStringSysfsAttr(device, "product_name",
|
if (udevGetStringSysfsAttr(device, "product_name",
|
||||||
&syscap->product_name) < 0)
|
&syscap->product_name) < 0)
|
||||||
@ -2002,12 +1996,12 @@ nodeStateInitializeEnumerate(void *opaque)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virObjectLock(priv);
|
VIR_WITH_OBJECT_LOCK_GUARD(priv) {
|
||||||
ignore_value(virEventRemoveHandle(priv->watch));
|
ignore_value(virEventRemoveHandle(priv->watch));
|
||||||
priv->watch = -1;
|
priv->watch = -1;
|
||||||
priv->threadQuit = true;
|
priv->threadQuit = true;
|
||||||
virCondSignal(&priv->threadCond);
|
virCondSignal(&priv->threadCond);
|
||||||
virObjectUnlock(priv);
|
}
|
||||||
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user