When the first path to a device appears, we don't know if more paths are going
to follow. find_multipath "smart" logic attempts to solve this dilemma by
waiting for additional paths for a configurable time before giving up
and releasing single paths to upper layers.

These rules apply only if both find_multipaths is set to "smart" in
multipath.conf. In this mode, multipath -u sets DM_MULTIPATH_DEVICE_PATH=2 if
there's no clear evidence wheteher a given device should be a multipath member
(not blacklisted, not listed as "failed", not in WWIDs file, not member of an
existing map, only one path seen yet). In this case, "multipath -u" also sets 
variable FIND_MULTIPATHS_WAIT_UNIL to a relative time stamp (we need to use
relative "monotonic" time stamps because this may be triggered early during
boot, before system "calendar" time is correctly initialized).

In the DM_MULTIPATH_DEVICE_PATH=2 case, pretend that the path is multipath
member, disallow further processing by systemd (allowing multipathd some time
to grab the path), and set a systemd timer to check again after the given
timeout. If the path is still not multipathed by then, pass it on to systemd
for further processing.

Signed-off-by: Martin Wilck <mwi...@suse.com>
Reviewed-by: Benjamin Marzinski <bmarz...@redhat.com>
 multipath/multipath.rules | 61 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 58 insertions(+), 3 deletions(-)

diff --git a/multipath/multipath.rules b/multipath/multipath.rules
index ef857271..d658073f 100644
--- a/multipath/multipath.rules
+++ b/multipath/multipath.rules
@@ -21,12 +21,67 @@ LABEL="test_dev"
 TEST!="$env{MPATH_SBIN_PATH}/multipath", ENV{MPATH_SBIN_PATH}="/usr/sbin"
+# FIND_MULTIPATHS_WAIT_UNTIL is the timeout (in seconds after the
+# epoch).
 # multipath -u needs to know if this device has ever been exported
-# multipath -u sets DM_MULTIPATH_DEVICE_PATH
+# multipath -u sets DM_MULTIPATH_DEVICE_PATH and,
+# if "find_multipaths smart", also FIND_MULTIPATHS_WAIT_UNTIL.
 IMPORT{program}="$env{MPATH_SBIN_PATH}/multipath -u %k"
-ENV{DM_MULTIPATH_DEVICE_PATH}=="1", ENV{ID_FS_TYPE}="mpath_member", \
-       ENV{SYSTEMD_READY}="0"
+# case 1: this is definitely multipath
+       ENV{ID_FS_TYPE}="mpath_member", ENV{SYSTEMD_READY}="0", \
+       GOTO="stop_wait"
+# case 2: this is definitely not multipath, or timeout has expired
+       GOTO="stop_wait"
+# Code below here is only run in "smart" mode.
+# multipath -u has indicated this is "maybe" multipath.
+# This shouldn't happen, just in case.
+# Be careful not to start the timer twice.
+ACTION!="add", GOTO="pretend_mpath"
+ENV{.SAVED_FM_WAIT_UNTIL}=="?*", GOTO="pretend_mpath"
+# At this point, we are seeing this path for the first time, and it's "maybe" 
+# The actual start command for the timer.
+# The purpose of this command is only to make sure we will receive another
+# uevent eventually. *Any* uevent may cause waiting to finish if it either ends
+# in case 1-3 above, or if it arrives after FIND_MULTIPATHS_WAIT_UNTIL.
+# Note that this will try to activate multipathd if it isn't running yet.
+# If that fails, the unit starts and expires nonetheless. If multipathd
+# startup needs to wait for other services, this wait time will add up with
+# the --on-active timeout.
+# We must trigger an "add" event because LVM2 will only act on those.
+RUN+="/usr/bin/systemd-run --unit=cancel-multipath-wait-$kernel --description 
'cancel waiting for multipath siblings of $kernel' --no-block --timer-property 
DefaultDependencies=no --timer-property Conflicts=shutdown.target 
--timer-property Before=shutdown.target --timer-property AccuracySec=500ms 
--property DefaultDependencies=no --property Conflicts=shutdown.target 
--property Before=shutdown.target --property Wants=multipathd.service 
--property After=multipathd.service 
--on-active=$env{FIND_MULTIPATHS_WAIT_UNTIL} /usr/bin/udevadm trigger 
--action=add $sys$devpath"
+# If timeout hasn't expired but we're not in "maybe" state any more, stop timer
+# Do this only once, and only if the timer has been started before
+       RUN+="/usr/bin/systemctl stop cancel-multipath-wait-$kernel.timer"

dm-devel mailing list

Reply via email to