Skip to contentSkip to conversation

master - udev: fix pvscan --cache -aay to trigger on relevant events

PATCH Peter Rajnoha 1 participant 1 message Sep 10, 2013

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=8d1d83504dcf9c86ad42d34d3bd0b201d7bab8f6
Commit:        8d1d83504dcf9c86ad42d34d3bd0b201d7bab8f6
Parent:        9ba40da7ae908fb36cb9927cde60a1a45cacce80
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Tue Sep 10 15:49:05 2013 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Tue Sep 10 16:27:58 2013 +0200

udev: fix pvscan --cache -aay to trigger on relevant events

This patch fixes the way the special devices are handled (special in this context means that they're not usable after the usual ADD event like other generic devices):

- DM and MD devices are pvscanned only when they are just set up. This is the first CHANGE event that makes the device usable (the DM_UDEV_PRIMARY_SOURCE_FLAG is set for DM and the md/array_state sysfs attribute is present for MD). Whether the device is activated is remembered via DM_ACTIVATED (for DM) and LVM_MD_PV_ACTIVATED (for MD) udev environment variable. This is then used to decide whether we should fire the pvscan on ADD event to support coldplugging. For any (artificial) ADD event generated during coldplug, the device must be already set up properly to fire the pvscan on it.

- Similar for loop devices. For loop devices, only CHANGE events are relevant (so there's a CHANGE after the loop device is set up as well as detached). Whether the loop has just been activated is detected via loop/backing_file sysfs attribute presence. The activation state is remembered via LVM_LOOP_PV_ACTIVATED udev environment variable.

- Do not pvscan multipath device components (underlying paths).

- Do not pvscan RAID device components.

- Also, set LVM_SCANNED="1" udev environment variable for debug purposes (it's visible in the lvmdump -u that takes the current udev database). This variable is set once the pvscan is triggered.

The table below summarises when the pvscan is triggered (marked with X, X* means fire only if the special dev is properly set up):

| real ADD | real CHANGE | artificial ADD | artificial CHANGE | remove
=============================================================================

DM    |          |      X      |       X*       |                   |   X
MD    |          |      X      |       X*       |                   |
loop  |          |      X      |       X*       |                   |
other |    X     |             |       X        |                   |   X
---
 udev/10-dm.rules.in           |   20 +++++-------
 udev/13-dm-disk.rules.in      |    4 --
 udev/69-dm-lvm-metad.rules.in |   66 +++++++++++++++++++++++++++++++++++-----
 3 files changed, 65 insertions(+), 25 deletions(-)
udev/10-dm.rules.in +8 -12
index 3a157d5..f495103 100644
@@ -45,14 +45,13 @@ ENV{DISK_RO}=="1", GOTO="dm_disable"
 # in libdevmapper so we need to detect this and try to behave correctly.
 # For such spurious events, regenerate all flags from current udev database content
 # (this information would normally be inaccessible for spurious ADD and CHANGE events).
-ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", ENV{DM_ACTIVATION}="1", GOTO="dm_flags_done"
+ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", ENV{DM_ACTIVATED}="1", GOTO="dm_flags_done"
 IMPORT{db}="DM_UDEV_DISABLE_DM_RULES_FLAG"
 IMPORT{db}="DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG"
 IMPORT{db}="DM_UDEV_DISABLE_DISK_RULES_FLAG"
 IMPORT{db}="DM_UDEV_DISABLE_OTHER_RULES_FLAG"
 IMPORT{db}="DM_UDEV_LOW_PRIORITY_FLAG"
 IMPORT{db}="DM_UDEV_DISABLE_LIBRARY_FALLBACK_FLAG"
-IMPORT{db}="DM_UDEV_PRIMARY_SOURCE_FLAG"
 IMPORT{db}="DM_UDEV_FLAG7"
 IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG0"
 IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG1"
@@ -63,6 +62,7 @@ IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG5"
 IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG6"
 IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG7"
 IMPORT{db}="DM_UDEV_RULES_VSN"
+IMPORT{db}="DM_ACTIVATED"
 LABEL="dm_flags_done"
 
 # Normally, we operate on "change" events. But when coldplugging, there's an
@@ -77,28 +77,24 @@ LABEL="dm_flags_done"
 # before (e.g. in initrd). If udev is used in initrd, we require the udev init
 # script to not remove the existing udev database so we can reuse the information
 # stored at the time of device activation in the initrd.
-# The DM_ACTIVATION variable tells when any device stacked above should be
-# (re)activated as well.
-ACTION!="add", GOTO="dm_no_coldplug"
-ENV{DM_UDEV_RULES_VSN}!="1", ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}!="1", GOTO="dm_disable"
-ENV{DM_ACTIVATION}="1"
-LABEL="dm_no_coldplug"
+# The DM_ACTIVATED variable indicates that the device has already been activated.
+ACTION=="add", ENV{DM_UDEV_RULES_VSN}!="1", ENV{DM_ACTIVATED}!="1", GOTO="dm_disable"
 
 # Putting it together, following table is used to recognize genuine and spurious events.
 # N.B. Spurious events are generated based on use of the WATCH udev
 # rule or by triggering an event manually by "udevadm trigger" call
 # or by "echo <event_name> > /sys/block/dm-X/uevent".
 #
-#        EVENT              DM_UDEV_PRIMARY_SOURCE_FLAG   DM_ACTIVATION
-# ======================================================================
+#        EVENT              DM_UDEV_PRIMARY_SOURCE_FLAG   DM_ACTIVATED
+# ====================================================================
 # add event (genuine)                  0                        0
 # change event (genuine)               1                        1
 # add event (spurious)
 #   |_ dev still not active            0                        0
-#   \_ dev already active              1                        1
+#   \_ dev already active              0                        1
 # change event (spurious)
 #   |_ dev still not active            0                        0
-#   \_ dev already active              1                        0
+#   \_ dev already active              0                        1
 
 # "dm" sysfs subdirectory is available in newer versions of DM
 # only (kernels >= 2.6.29). We have to check for its existence
udev/13-dm-disk.rules.in +0 -4
index f8e4ac6..1920260 100644
@@ -17,10 +17,6 @@ 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}"
 
-# Save previously detected dev type.
-IMPORT{db}="ID_FS_TYPE"
-ENV{ID_FS_TYPE}=="?*", ENV{DM_ID_FS_TYPE_OLD}="$env{ID_FS_TYPE}", ENV{ID_FS_TYPE}=""
-
 ENV{DM_SUSPENDED}=="1", GOTO="dm_end"
 
 (BLKID_RULE)
udev/69-dm-lvm-metad.rules.in +57 -9

80 lines not on this page · raw message