Remove last_rule from udev rules and support udev flags even when udev_sync

is disabled.
This commit is contained in:
Peter Rajnoha 2009-11-13 14:47:51 +00:00
parent b874f54f67
commit 0f14aac7de
4 changed files with 288 additions and 1 deletions

View File

@ -9,7 +9,7 @@
Summary: Userland logical volume management tools Summary: Userland logical volume management tools
Name: lvm2 Name: lvm2
Version: 2.02.54 Version: 2.02.54
Release: 2%{?dist} Release: 3%{?dist}
License: GPLv2 License: GPLv2
Group: System Environment/Base Group: System Environment/Base
URL: http://sources.redhat.com/lvm2 URL: http://sources.redhat.com/lvm2
@ -17,6 +17,9 @@ Source0: ftp://sources.redhat.com/pub/lvm2/LVM2.%{version}.tgz
# Customise lvmconf.sh for built-in clustered locking in Fedora # Customise lvmconf.sh for built-in clustered locking in Fedora
Patch0: cluster-locking-built-in.patch Patch0: cluster-locking-built-in.patch
Patch1: udev-rules-cleanup-v55.patch
Patch2: udev-rules-remove-last_rule-v55.patch
Patch3: udev-flags-support-while-noudevsync-v55.patch
BuildRequires: libselinux-devel >= 1.30.19-4, libsepol-devel BuildRequires: libselinux-devel >= 1.30.19-4, libsepol-devel
BuildRequires: ncurses-devel BuildRequires: ncurses-devel
@ -47,6 +50,9 @@ or more physical volumes and creating one or more logical volumes
%prep %prep
%setup -q -n LVM2.%{version} %setup -q -n LVM2.%{version}
%patch0 -p1 -b .locking %patch0 -p1 -b .locking
%patch1 -p1 -b .cleanup-v55
%patch2 -p1 -b .last_rule-v55
%patch3 -p1 -b .noudevsync-v55
%build %build
%define _exec_prefix / %define _exec_prefix /
@ -396,6 +402,11 @@ the device-mapper event library.
%changelog %changelog
* Fri Nov 13 2009 Peter Rajnoha <prajnoha@redhat.com> - 2.02.54-3
- Support udev flags even when udev_sync is disabled.
- Remove last_rule from udev_rules.
- Udev rules cleanup.
* Tue Nov 3 2009 Peter Rajnoha <prajnoha@redhat.com> - 2.02.54-2 * Tue Nov 3 2009 Peter Rajnoha <prajnoha@redhat.com> - 2.02.54-2
- Enable udev synchronisation code. - Enable udev synchronisation code.
- Install default udev rules for device-mapper and LVM2. - Install default udev rules for device-mapper and LVM2.

View File

@ -0,0 +1,132 @@
Support udev flags even when udev_sync is disabled or not compiled in.
This provides better support for environments where udev rules are installed
but udev_sync is not compiled in (however, using udev_sync is highly
recommended). It also provides consistent and expected functionality even
when '--noudevsync' option is used.
There is still requirement for kernel >= 2.6.31 for the flags to work though
(it uses DM cookies to pass the flags into the kernel and set them in udev
event environment that we can read in udev rules).
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 9751a03..50c59c2 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.40 -
===================================
+ Support udev flags even when udev_sync is disabled or not compiled in.
Remove 'last_rule' from udev rules: honor ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}.
Version 1.02.39 - 26th October 2009
diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
index e49ac71..df30adc 100644
--- a/libdm/ioctl/libdm-iface.c
+++ b/libdm/ioctl/libdm-iface.c
@@ -1535,6 +1535,7 @@ static int _create_and_load_v4(struct dm_task *dmt)
task->gid = dmt->gid;
task->mode = dmt->mode;
/* FIXME: Just for udev_check in dm_task_run. Can we avoid this? */
+ task->event_nr = dmt->event_nr & DM_UDEV_FLAGS_MASK;
task->cookie_set = dmt->cookie_set;
r = dm_task_run(task);
diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index b339683..fcafbee 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -1031,6 +1031,10 @@ void dm_report_field_set_value(struct dm_report_field *field, const void *value,
* of udev rules we use by decoding the cookie prefix. When doing the
* notification, we replace the cookie prefix with DM_COOKIE_MAGIC,
* so we notify the right semaphore.
+ * It is still possible to use cookies for passing the flags to udev
+ * rules even when udev_sync is disabled. The base part of the cookie
+ * will be zero (there's no notification semaphore) and prefix will be
+ * set then. However, having udev_sync enabled is highly recommended.
*/
#define DM_COOKIE_MAGIC 0x0D4D
#define DM_UDEV_FLAGS_MASK 0xFFFF0000
@@ -1075,7 +1079,7 @@ void dm_report_field_set_value(struct dm_report_field *field, const void *value,
int dm_cookie_supported(void);
/*
- * Udev notification functions.
+ * Udev synchronisation functions.
*/
void dm_udev_set_sync_support(int sync_with_udev);
int dm_udev_get_sync_support(void);
diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c
index ede17b2..adf450e 100644
--- a/libdm/libdm-common.c
+++ b/libdm/libdm-common.c
@@ -885,6 +885,8 @@ int dm_udev_get_sync_support(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;
*cookie = 0;
return 1;
@@ -1140,8 +1142,11 @@ 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;
+
if (!dm_udev_get_sync_support()) {
- dmt->event_nr = *cookie = 0;
+ *cookie = 0;
return 1;
}
@@ -1158,8 +1163,7 @@ int dm_task_set_cookie(struct dm_task *dmt, uint32_t *cookie, uint16_t flags)
goto bad;
}
- dmt->event_nr = (~DM_UDEV_FLAGS_MASK & *cookie) |
- (flags << DM_UDEV_FLAGS_SHIFT);
+ dmt->event_nr |= ~DM_UDEV_FLAGS_MASK & *cookie;
dmt->cookie_set = 1;
log_debug("Udev cookie 0x%" PRIx32 " (semid %d) assigned to dm_task "
diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c
index c98fb34..1465fd3 100644
--- a/libdm/libdm-deptree.c
+++ b/libdm/libdm-deptree.c
@@ -1039,7 +1039,7 @@ int dm_tree_deactivate_children(struct dm_tree_node *dnode,
continue;
if (!_deactivate_node(name, info.major, info.minor,
- &dnode->dtree->cookie, dnode->udev_flags)) {
+ &child->dtree->cookie, child->udev_flags)) {
log_error("Unable to deactivate %s (%" PRIu32
":%" PRIu32 ")", name, info.major,
info.minor);
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index a7f1d25..17548e4 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -821,9 +821,17 @@ static int _udevcomplete(int argc, char **argv, void *data __attribute((unused))
if (!(cookie = _get_cookie_value(argv[1])))
return 0;
- /* strip flags from the cookie and use cookie magic instead */
- cookie = (cookie & ~DM_UDEV_FLAGS_MASK) |
- (DM_COOKIE_MAGIC << DM_UDEV_FLAGS_SHIFT);
+ /*
+ * Strip flags from the cookie and use cookie magic instead.
+ * If the cookie has non-zero prefix and the base is zero then
+ * this one carries flags to control udev rules only and it is
+ * not meant to be for notification. Return with success in this
+ * situation.
+ */
+ if (!(cookie &= ~DM_UDEV_FLAGS_MASK))
+ return 1;
+
+ cookie |= DM_COOKIE_MAGIC << DM_UDEV_FLAGS_SHIFT;
return dm_udev_complete(cookie);
}

View File

@ -0,0 +1,72 @@
More cleanup in udev rules:
- add copyright notice for 10-dm.rules.in,
- set DM_UDEV_DISABLE_{DISK, OTHER}_RULES_FLAG in 11-dm-lvm.rules directly
for inappropriate and non-top-level subdevices in case we use older kernels
where DM_COOKIE is not used (and therefore there are no flags passed from
the LVM process itself). This applies for older kernels (version < 2.6.31),
- remove unnecessary filters in 95-dm-notify.rules - the DM_COOKIE env var
itself is set for change/remove udev events and for DM devices only so
there's no need to double-check this.
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 0314d98..84fe5ce 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,3 +1,6 @@
+Version 1.02.40 -
+===================================
+
Version 1.02.39 - 26th October 2009
===================================
Remove strict default permissions for DM devices from 95-dm-notify.rules.
diff --git a/udev/10-dm.rules.in b/udev/10-dm.rules.in
index 9c2e256..aba0bf4 100644
--- a/udev/10-dm.rules.in
+++ b/udev/10-dm.rules.in
@@ -1,3 +1,7 @@
+# Copyright (C) 2009 Red Hat, Inc. All rights reserved.
+#
+# This file is part of LVM2.
+
# Udev rules for device-mapper devices.
#
# These rules create a DM control node in /dev/(DM_DIR) directory.
diff --git a/udev/11-dm-lvm.rules b/udev/11-dm-lvm.rules
index 0dd6167..7d1dfcd 100644
--- a/udev/11-dm-lvm.rules
+++ b/udev/11-dm-lvm.rules
@@ -22,9 +22,14 @@ ENV{DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG}=="1", GOTO="lvm_end"
IMPORT{program}="$env{DM_SBIN_PATH}/dmsetup splitname --nameprefixes --noheadings --rows $env{DM_NAME}"
# Do not create symlinks for inappropriate subdevices.
-ENV{DM_LV_NAME}=="?*_mimage_[0-9]*|pvmove?*|?*_vorigin", GOTO="lvm_end"
+ENV{DM_LV_NAME}=="?*_mimage_[0-9]*|pvmove?*|?*_vorigin", GOTO="lvm_disable"
+ENV{DM_LV_LAYER}=="?*", GOTO="lvm_disable"
# Create symlinks for top-level devices only.
-ENV{DM_VG_NAME}=="?*", ENV{DM_LV_NAME}=="?*", ENV{DM_LV_LAYER}!="?*", SYMLINK+="$env{DM_VG_NAME}/$env{DM_LV_NAME}"
+ENV{DM_VG_NAME}=="?*", ENV{DM_LV_NAME}=="?*", SYMLINK+="$env{DM_VG_NAME}/$env{DM_LV_NAME}", GOTO="lvm_end"
+
+LABEL="lvm_disable"
+ENV{DM_UDEV_DISABLE_DISK_RULES_FLAG}="1"
+ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="1"
LABEL="lvm_end"
diff --git a/udev/95-dm-notify.rules b/udev/95-dm-notify.rules
index c6bf23b..72cc609 100644
--- a/udev/95-dm-notify.rules
+++ b/udev/95-dm-notify.rules
@@ -9,10 +9,4 @@
# a cookie value sent within "change" and "remove" events (the cookie
# value is set before by that process for every action requested).
-SUBSYSTEM!="block", GOTO="dm_end"
-KERNEL!="dm-[0-9]*", GOTO="dm_end"
-ACTION!="change|remove", GOTO="dm_end"
-
ENV{DM_COOKIE}=="?*", RUN+="$env{DM_SBIN_PATH}/dmsetup udevcomplete $env{DM_COOKIE}"
-
-LABEL="dm_end"

View File

@ -0,0 +1,72 @@
Remove 'last_rule' from udev rules.
'last_rule' option has been removed from udev (version >= 147).
From now on, we require foreign rules to check and honor
ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG} instead. Foreign
rules should be skipped totally when this flag is set.
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 84fe5ce..9751a03 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.40 -
===================================
+ Remove 'last_rule' from udev rules: honor ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}.
Version 1.02.39 - 26th October 2009
===================================
diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index 721e08a..b339683 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -1057,9 +1057,9 @@ void dm_report_field_set_value(struct dm_report_field *field, const void *value,
/*
* DM_UDEV_DISABLE_OTHER_RULES_FLAG is set in case we need to disable
* all the other rules that are not general device-mapper nor subsystem
- * related (the rules belong to other software or packages). Use this
- * flag with care since it will cutoff the rule processing after the
- * last device-mapper/subsytem rule is applied.
+ * related (the rules belong to other software or packages). All foreign
+ * rules should check this flag directly and they should ignore further
+ * rule processing for such event.
*/
#define DM_UDEV_DISABLE_OTHER_RULES_FLAG 0x0008
/*
diff --git a/udev/13-dm-disk.rules b/udev/13-dm-disk.rules
index 03d9cbc..271ca22 100644
--- a/udev/13-dm-disk.rules
+++ b/udev/13-dm-disk.rules
@@ -10,27 +10,18 @@
# suspended.
# "add" event is processed on coldplug only!
-ACTION!="add|change", GOTO="dm_other"
-ENV{DM_UDEV_RULES_VSN}!="?*", GOTO="dm_other"
-ENV{DM_UDEV_DISABLE_DISK_RULES_FLAG}=="1", GOTO="dm_other"
+ACTION!="add|change", GOTO="dm_end"
+ENV{DM_UDEV_RULES_VSN}!="?*", GOTO="dm_end"
+ENV{DM_UDEV_DISABLE_DISK_RULES_FLAG}=="1", GOTO="dm_end"
SYMLINK+="disk/by-id/dm-name-$env{DM_NAME}"
ENV{DM_UUID}=="?*", SYMLINK+="disk/by-id/dm-uuid-$env{DM_UUID}"
-ENV{DM_SUSPENDED}=="1", GOTO="dm_other"
+ENV{DM_SUSPENDED}=="1", GOTO="dm_end"
IMPORT{program}="$env{DM_SBIN_PATH}/blkid -o udev -p $tempnode"
ENV{DM_UDEV_LOW_PRIORITY_FLAG}=="1", OPTIONS="link_priority=-100"
ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}"
ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk/by-label/$env{ID_FS_LABEL_ENC}"
-# Cutoff all subsequent rules if instructed by a flag.
-# This flag should be used in well-founded situations only to prevent
-# any problems that could arise when processing this event further by
-# foreign rules (various temporary and hidden devices mostly).
-LABEL="dm_other"
-ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}!="1", GOTO="dm_end"
-ENV{DM_COOKIE}=="?*", RUN+="$env{DM_SBIN_PATH}/dmsetup udevcomplete $env{DM_COOKIE}"
-OPTIONS+="last_rule"
-
LABEL="dm_end"