Skip to contentSkip to conversation

master - udev: recognize DM_DISABLE_UDEV environment variable

PATCH Peter Rajnoha 1 participant 1 message Nov 29, 2012

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=4891a735d343db26460f1b6218169c458d59f2a1
Commit:        4891a735d343db26460f1b6218169c458d59f2a1
Parent:        fb8cc7c63f7f5ab9e0d6d2d38f29169346a54087
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Thu Nov 29 14:03:48 2012 +0100
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Thu Nov 29 14:03:48 2012 +0100

udev: recognize DM_DISABLE_UDEV environment variable

Setting this environment variable will cause a full fallback to old direct node and symlink management in libdevmapper and lvm2.

It means:

- disabling udev synchronization
(--noudevsync in dmsetup and --noudevsync + activation/udev_sync=0
lvm2 config)
- disabling dm and any subsystem related udev rules (--noudevrules in dmsetup and activation/udev_rules=0 lvm2 config)
- management of nodes/symlinks under /dev directly by libdevmapper/lvm2 (--verifyudev in dmsetup and activation/verify_udev_operations=1 lvm2 config)
- not obtaining any device list from udev database (devices/obtain_device_list_from_udev=0 lvm2 config)

Note: we could set all of these before - there's no functional change! However the DM_DISABLE_UDEV environment variable is a nice shortcut to make it easier for libdevmapper users so that one can switch off all of the udev management off at one go directly on the command line, without a need to modify any source or add any extra switches.

---
 WHATS_NEW                  |    1 +
 WHATS_NEW_DM               |    1 +
 lib/commands/toolcontext.c |   55 +++++++++++++++++++++++++++++++------------
 libdm/libdm-common.c       |   34 ++++++++++++++++++++++++---
 4 files changed, 71 insertions(+), 20 deletions(-)
WHATS_NEW +1 -0
index 657b3a4..ca1b539 100644
@@ -1,5 +1,6 @@
 Version 2.02.99 - 
 ===================================
+  Recognize DM_DISABLE_UDEV environment variable for a complete fallback.
   Do not verify udev operations if --noudevsync command option is used.
   Fix lvm2api and return lvseg discards property as string.
   Allow forced vgcfgrestore of lvm2 metadata with thin volumes.
WHATS_NEW_DM +1 -0
index 3f8d9c9..3ea0502 100644
@@ -1,5 +1,6 @@
 Version 1.02.78 - 
 ===================================
+  Add DM_DISABLE_UDEV environment variable to manage dev nodes by libdm only.
   Fix dm_task_set_cookie to properly process udev flags if udev_sync disabled.
 
 Version 1.02.77 - 15th October 2012
lib/commands/toolcontext.c +39 -16

81 lines not on this page · raw message

libdm/libdm-common.c +30 -4
index afdac89..2d79efa 100644
@@ -75,6 +75,7 @@ static struct selabel_handle *_selabel_handle = NULL;
 #endif
 
 #ifdef UDEV_SYNC_SUPPORT
+static int _udev_disabled = 0;
 static int _semaphore_supported = -1;
 static int _udev_running = -1;
 static int _sync_with_udev = 1;
@@ -85,6 +86,9 @@ void dm_lib_init(void)
 {
 	const char *env;
 
+	if ((env = getenv("DM_DISABLE_UDEV")))
+		_udev_disabled = 1;
+
 	env = getenv(DM_DEFAULT_NAME_MANGLING_MODE_ENV_VAR_NAME);
 	if (env && *env) {
 		if (!strcasecmp(env, "none"))
@@ -1814,6 +1818,26 @@ out:
 	return r;
 }
 
+static void _set_cookie_flags(struct dm_task *dmt, uint16_t flags)
+{
+	if (!dm_cookie_supported())
+		return;
+
+	if (_udev_disabled) {
+		/*
+		 * If udev is disabled, hardcode this functionality:
+		 *   - we want libdm to create the nodes
+		 *   - we don't want the /dev/mapper and any subsystem
+		 *     related content to be created by udev if udev
+		 *     rules are installed
+		 */
+		flags &= ~DM_UDEV_DISABLE_LIBRARY_FALLBACK;
+		flags |= DM_UDEV_DISABLE_DM_RULES_FLAG | DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG;
+	}
+
+	dmt->event_nr = flags << DM_UDEV_FLAGS_SHIFT;
+}
+
 #ifndef UDEV_SYNC_SUPPORT
 void dm_udev_set_sync_support(int sync_with_udev)
 {
@@ -1835,8 +1859,8 @@ int dm_udev_get_checking(void)
 
 int dm_task_set_cookie(struct dm_task *dmt, uint32_t *cookie, uint16_t flags)
 {
-	if (dm_cookie_supported())
-		dmt->event_nr = flags << DM_UDEV_FLAGS_SHIFT;
+	_set_cookie_flags(dmt, flags);
+
 	*cookie = 0;
 	dmt->cookie_set = 1;
 
@@ -1920,6 +1944,9 @@ void dm_udev_set_sync_support(int sync_with_udev)
 
 int dm_udev_get_sync_support(void)
 {
+	if (_udev_disabled)
+		return 0;
+
 	_check_udev_sync_requirements_once();
 
 	return _semaphore_supported && dm_cookie_supported() &&
@@ -2203,8 +2230,7 @@ int dm_task_set_cookie(struct dm_task *dmt, uint32_t *cookie, uint16_t flags)
 {
 	int semid;
 
-	if (dm_cookie_supported())
-		dmt->event_nr = flags << DM_UDEV_FLAGS_SHIFT;
+	_set_cookie_flags(dmt, flags);
 
 	if (!dm_udev_get_sync_support()) {
 		*cookie = 0;