From 93d1fdba4bccab746ce8670a0f38f88a80df7c31 Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Fri, 11 Sep 2009 15:56:06 +0000 Subject: [PATCH] Check that udev is running and set internal state appropriately. --- WHATS_NEW | 1 + libdm/libdm-common.c | 50 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/WHATS_NEW b/WHATS_NEW index f9a263b9f..535bdcb79 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.52 - ================================= + Check that udev is running and set internal state appropriately. Add libudev configuration check. Add lvm2app.sh to nightly tests conditional upon configure --enable-applib. Update lvm_vg_remove to require lvm_vg_write to commit remove to disk. diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c index 554c1a490..141180a85 100644 --- a/libdm/libdm-common.c +++ b/libdm/libdm-common.c @@ -28,6 +28,9 @@ # include # include # include +#ifdef HAVE_UDEV_QUEUE_GET_UDEV_IS_ACTIVE +# include +#endif #endif #ifdef linux @@ -45,6 +48,7 @@ static char _dm_dir[PATH_MAX] = DEV_DIR DM_DIR; static int _verbose = 0; #ifdef UDEV_SYNC_SUPPORT +static int _udev_running = -1; static int _sync_with_udev = 1; #endif @@ -825,14 +829,58 @@ int dm_udev_wait(uint32_t cookie) #else /* UDEV_SYNC_SUPPORT */ + +static int _check_udev_is_running(void) +{ + #ifndef HAVE_UDEV_QUEUE_GET_UDEV_IS_ACTIVE + log_debug("Could not get udev state because libudev library " + "was not found and it was not compiled in. " + "Assuming udev is not running."); + return 0; + #else /* HAVE_UDEV_QUEUE_GET_UDEV_IS_ACTIVE */ + struct udev *udev; + struct udev_queue *udev_queue; + int r; + + if (!(udev = udev_new())) + goto error; + + if (!(udev_queue = udev_queue_new(udev))) { + udev_unref(udev); + goto error; + } + + r = udev_queue_get_udev_is_active(udev_queue); + + if (!r) + log_debug("Udev is not running. " + "Not using udev synchronisation code."); + + udev_queue_unref(udev_queue); + udev_unref(udev); + + return r; + +error: + log_debug("Could not get udev state. Assuming udev is not running."); + return 0; + #endif /* HAVE_UDEV_QUEUE_GET_UDEV_IS_ACTIVE */ +} + void dm_udev_set_sync_support(int sync_with_udev) { + if (_udev_running < 0) + _udev_running = _check_udev_is_running(); + _sync_with_udev = sync_with_udev; } int dm_udev_get_sync_support(void) { - return _sync_with_udev; + if (_udev_running < 0) + _udev_running = _check_udev_is_running(); + + return _udev_running && _sync_with_udev; } static int _get_cookie_sem(uint32_t cookie, int *semid)