Skip to contentSkip to conversation

multipath-tools: fixes for kpartx.rules and skip_kpartx

PATCH In review [email protected] 2 participants 5 messages Apr 3, 2020 Device mapper

lore
Share & tools
lore
#0 lore raw

v2 cover multipath-tools: fixes for kpartx.rules and skip_kpartx

From: Martin Wilck <[email protected]>

Hi Christophe, Ben,

The "skip_kpartx" option serves to prevent creation of partitions on top of multipath devices where that's undesired, e.g. on VM hosts which are supposed to provide the unpartitioned dm devices to guests. This is broken with our current udev rules, because partition creation is only suppressed on "primary" uevents, and not on "sporadic" ones.

This series fixes the issue. It replaces my previous patch "kpartx.rules:
check for skip_kpartx if DM_ACTIVATION is unset", which turned out to be insufficient.

Regards,
Martin

Martin Wilck (2):
kpartx.rules: honor DM_UDEV_DISABLE_OTHER_RULES_FLAG kpartx.rules: check for skip_kpartx on synthetic uevents

 kpartx/kpartx.rules | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/2 kpartx.rules: honor DM_UDEV_DISABLE_OTHER_RULES_FLAG

From: Martin Wilck <[email protected]>

10-dm.rules sets DM_UDEV_DISABLE_OTHER_RULES_FLAG for spurious events that should be ignored by other layers. This means devices with DISK_RO set, and devices that have never been set up properly by device-mapper before. This flag should be respected by kpartx.

---
 kpartx/kpartx.rules | 1 +
 1 file changed, 1 insertion(+)
kpartx/kpartx.rules +1 -0
index 8f990494..f1bf31ca 100644
@@ -7,6 +7,7 @@
 KERNEL!="dm-*", GOTO="kpartx_end"
 ACTION!="add|change", GOTO="kpartx_end"
 ENV{DM_UUID}!="?*", GOTO="kpartx_end"
+ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", GOTO="kpartx_end"
 
 # Create dm tables for partitions on multipath devices.
 ENV{DM_UUID}!="mpath-?*", GOTO="mpath_kpartx_end"
Signature · 1 line
2.25.1
maintainer Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] kpartx.rules: honor DM_UDEV_DISABLE_OTHER_RULES_FLAG

Quoted 7 lines · On Fri, Apr 03, 2020 at 01:19:13PM +0200, [email protected] wrote:

From: Martin Wilck <[email protected]>

10-dm.rules sets DM_UDEV_DISABLE_OTHER_RULES_FLAG for spurious events that should be ignored by other layers. This means devices with DISK_RO set, and devices that have never been set up properly by device-mapper before. This flag should be respected by kpartx.

Quoted 19 lines
---
 kpartx/kpartx.rules | 1 +
 1 file changed, 1 insertion(+)
kpartx/kpartx.rules +1 -0
index 8f990494..f1bf31ca 100644
@@ -7,6 +7,7 @@
 KERNEL!="dm-*", GOTO="kpartx_end"
 ACTION!="add|change", GOTO="kpartx_end"
 ENV{DM_UUID}!="?*", GOTO="kpartx_end"
+ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", GOTO="kpartx_end"
 
 # Create dm tables for partitions on multipath devices.
 ENV{DM_UUID}!="mpath-?*", GOTO="mpath_kpartx_end"
Signature · 1 line
2.25.1
#3 lore raw

PATCH v2 2/2 kpartx.rules: check for skip_kpartx on synthetic uevents

In reply to [email protected]

From: Martin Wilck <[email protected]>

The current test to detect "spurious" uevents, and thus whether to import DM_SUBSYSTEM_UDEV_FLAG1 (the flag for the "skip_kpartx" option) from the udev db is wrong. In 10-dm.rules, DM_UDEV_PRIMARY_SOURCE_FLAG is imported from the db if it isn't set, meaning that it's always 1 for active maps. The only events for which DM_SUBSYSTEM_UDEV_FLAG1 must not be loaded from the db are the real "primary" events, which are "change" events with DM_ACTIVATION=="1".

11-dm-mpath.rules resets DM_ACTIVATION to 0 if nothing should change in upper layers. In this case importing DM_SUBSYSTEM_UDEV_FLAG1 is correct, too. kpartx will not be called anyway, because 11-dm-mpath.rules also sets MPATH_UNCHANGED=1.

---
 kpartx/kpartx.rules | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
kpartx/kpartx.rules +5 -2
index f1bf31ca..d7527d7d 100644
@@ -13,8 +13,11 @@ ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", GOTO="kpartx_end"
 ENV{DM_UUID}!="mpath-?*", GOTO="mpath_kpartx_end"
 
 # DM_SUBSYSTEM_UDEV_FLAG1 is the "skip_kpartx" flag.
-# For events not generated by libdevmapper, we need to fetch it from db.
-ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}!="1", IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG1"
+# For events not generated by libdevmapper, we need to fetch it from db:
+# - "change" events with DM_ACTIVATION!="1" (e.g. partition table changes)
+# - "add" events for which rules are not disabled ("coldplug" case)
+ENV{DM_ACTIVATION}!="1", IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG1"
+ACTION=="add", IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG1"
 ENV{DM_SUBSYSTEM_UDEV_FLAG1}=="1", GOTO="mpath_kpartx_end"
 
 # 11-dm-mpath.rules sets MPATH_UNCHANGED for events that can be ignored.
Signature · 1 line
2.25.1
maintainer Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] kpartx.rules: check for skip_kpartx on synthetic uevents

Quoted 10 lines · On Fri, Apr 03, 2020 at 01:19:14PM +0200, [email protected] wrote:

From: Martin Wilck <[email protected]>

The current test to detect "spurious" uevents, and thus whether to import DM_SUBSYSTEM_UDEV_FLAG1 (the flag for the "skip_kpartx" option) from the udev db is wrong. In 10-dm.rules, DM_UDEV_PRIMARY_SOURCE_FLAG is imported from the db if it isn't set, meaning that it's always 1 for active maps. The only events for which DM_SUBSYSTEM_UDEV_FLAG1 must not be loaded from the db are the real "primary" events, which are "change" events with DM_ACTIVATION=="1".

Quoted 4 lines

11-dm-mpath.rules resets DM_ACTIVATION to 0 if nothing should change in upper layers. In this case importing DM_SUBSYSTEM_UDEV_FLAG1 is correct, too. kpartx will not be called anyway, because 11-dm-mpath.rules also sets MPATH_UNCHANGED=1.

Quoted 25 lines
---
 kpartx/kpartx.rules | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
kpartx/kpartx.rules +5 -2
index f1bf31ca..d7527d7d 100644
@@ -13,8 +13,11 @@ ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", GOTO="kpartx_end"
 ENV{DM_UUID}!="mpath-?*", GOTO="mpath_kpartx_end"
 
 # DM_SUBSYSTEM_UDEV_FLAG1 is the "skip_kpartx" flag.
-# For events not generated by libdevmapper, we need to fetch it from db.
-ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}!="1", IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG1"
+# For events not generated by libdevmapper, we need to fetch it from db:
+# - "change" events with DM_ACTIVATION!="1" (e.g. partition table changes)
+# - "add" events for which rules are not disabled ("coldplug" case)
+ENV{DM_ACTIVATION}!="1", IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG1"
+ACTION=="add", IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG1"
 ENV{DM_SUBSYSTEM_UDEV_FLAG1}=="1", GOTO="mpath_kpartx_end"
 
 # 11-dm-mpath.rules sets MPATH_UNCHANGED for events that can be ignored.
Signature · 1 line
2.25.1