mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 12:35:17 +00: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
|
||||
udevEventHandleCallback(int watch ATTRIBUTE_UNUSED,
|
||||
int fd,
|
||||
int events ATTRIBUTE_UNUSED,
|
||||
void *data ATTRIBUTE_UNUSED)
|
||||
static bool
|
||||
udevEventMonitorSanityCheck(struct udev_monitor *udev_monitor,
|
||||
int fd)
|
||||
{
|
||||
struct udev_device *device = NULL;
|
||||
struct udev_monitor *udev_monitor = DRV_STATE_UDEV_MONITOR(driver);
|
||||
int udev_fd = -1;
|
||||
int rc = -1;
|
||||
|
||||
udev_fd = udev_monitor_get_fd(udev_monitor);
|
||||
if (fd != udev_fd) {
|
||||
rc = udev_monitor_get_fd(udev_monitor);
|
||||
if (fd != rc) {
|
||||
udevPrivate *priv = driver->privateData;
|
||||
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("File descriptor returned by udev %d does not "
|
||||
"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
|
||||
* 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);
|
||||
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);
|
||||
if (device == NULL) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("udev_monitor_receive_device returned NULL"));
|
||||
goto cleanup;
|
||||
return;
|
||||
}
|
||||
|
||||
udevHandleOneDevice(device);
|
||||
|
||||
cleanup:
|
||||
udev_device_unref(device);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user