mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
nodedev: udev: Introduce udevEventMonitorSanityCheck helper function
We need to perform a sanity check on the udev monitor before every use so that we know nothing has changed in the meantime. The reason for moving the code to a separate helper is to enhance readability and shift the focus on the important stuff within the udevEventHandleCallback handler. Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
643c74abff
commit
c6a16d3c64
@ -1618,24 +1618,20 @@ udevHandleOneDevice(struct udev_device *device)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static bool
|
||||||
udevEventHandleCallback(int watch ATTRIBUTE_UNUSED,
|
udevEventMonitorSanityCheck(struct udev_monitor *udev_monitor,
|
||||||
int fd,
|
int fd)
|
||||||
int events ATTRIBUTE_UNUSED,
|
|
||||||
void *data ATTRIBUTE_UNUSED)
|
|
||||||
{
|
{
|
||||||
struct udev_device *device = NULL;
|
int rc = -1;
|
||||||
struct udev_monitor *udev_monitor = DRV_STATE_UDEV_MONITOR(driver);
|
|
||||||
int udev_fd = -1;
|
|
||||||
|
|
||||||
udev_fd = udev_monitor_get_fd(udev_monitor);
|
rc = udev_monitor_get_fd(udev_monitor);
|
||||||
if (fd != udev_fd) {
|
if (fd != rc) {
|
||||||
udevPrivate *priv = driver->privateData;
|
udevPrivate *priv = driver->privateData;
|
||||||
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("File descriptor returned by udev %d does not "
|
_("File descriptor returned by udev %d does not "
|
||||||
"match node device file descriptor %d"),
|
"match node device file descriptor %d"),
|
||||||
fd, udev_fd);
|
fd, rc);
|
||||||
|
|
||||||
/* this is a non-recoverable error, let's remove the handle, so that we
|
/* this is a non-recoverable error, let's remove the handle, so that we
|
||||||
* don't get in here again because of some spurious behaviour and report
|
* don't get in here again because of some spurious behaviour and report
|
||||||
@ -1644,21 +1640,36 @@ udevEventHandleCallback(int watch ATTRIBUTE_UNUSED,
|
|||||||
virEventRemoveHandle(priv->watch);
|
virEventRemoveHandle(priv->watch);
|
||||||
priv->watch = -1;
|
priv->watch = -1;
|
||||||
|
|
||||||
goto cleanup;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
udevEventHandleCallback(int watch ATTRIBUTE_UNUSED,
|
||||||
|
int fd,
|
||||||
|
int events ATTRIBUTE_UNUSED,
|
||||||
|
void *data ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
struct udev_device *device = NULL;
|
||||||
|
struct udev_monitor *udev_monitor = NULL;
|
||||||
|
|
||||||
|
udev_monitor = DRV_STATE_UDEV_MONITOR(driver);
|
||||||
|
|
||||||
|
if (!udevEventMonitorSanityCheck(udev_monitor, fd))
|
||||||
|
return;
|
||||||
|
|
||||||
device = udev_monitor_receive_device(udev_monitor);
|
device = udev_monitor_receive_device(udev_monitor);
|
||||||
if (device == NULL) {
|
if (device == NULL) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("udev_monitor_receive_device returned NULL"));
|
_("udev_monitor_receive_device returned NULL"));
|
||||||
goto cleanup;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
udevHandleOneDevice(device);
|
udevHandleOneDevice(device);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user