multipathd: function return value tweaks
[multipath-tools/.git] / multipath / multipath.rules
1 # Set DM_MULTIPATH_DEVICE_PATH if the device should be handled by multipath
2 SUBSYSTEM!="block", GOTO="end_mpath"
3 KERNEL!="sd*|dasd*|nvme*", GOTO="end_mpath"
4 ACTION=="remove", TEST=="/dev/shm/multipath/find_multipaths/$major:$minor", \
5         RUN+="/usr/bin/rm -f /dev/shm/multipath/find_multipaths/$major:$minor"
6 ACTION!="add|change", GOTO="end_mpath"
7
8 IMPORT{cmdline}="nompath"
9 ENV{nompath}=="?*", GOTO="end_mpath"
10 IMPORT{cmdline}="multipath"
11 ENV{multipath}=="off", GOTO="end_mpath"
12
13 ENV{DEVTYPE}!="partition", GOTO="test_dev"
14 IMPORT{parent}="DM_MULTIPATH_DEVICE_PATH"
15 ENV{DM_MULTIPATH_DEVICE_PATH}=="1", ENV{ID_FS_TYPE}="none", \
16         ENV{SYSTEMD_READY}="0"
17 GOTO="end_mpath"
18
19 LABEL="test_dev"
20
21 ENV{MPATH_SBIN_PATH}="/sbin"
22 TEST!="$env{MPATH_SBIN_PATH}/multipath", ENV{MPATH_SBIN_PATH}="/usr/sbin"
23
24 # FIND_MULTIPATHS_WAIT_UNTIL is the timeout (in seconds after the
25 # epoch).
26 IMPORT{db}="FIND_MULTIPATHS_WAIT_UNTIL"
27 ENV{.SAVED_FM_WAIT_UNTIL}="$env{FIND_MULTIPATHS_WAIT_UNTIL}"
28
29 # multipath -u needs to know if this device has ever been exported
30 IMPORT{db}="DM_MULTIPATH_DEVICE_PATH"
31
32 # multipath -u sets DM_MULTIPATH_DEVICE_PATH and,
33 # if "find_multipaths smart", also FIND_MULTIPATHS_WAIT_UNTIL.
34 IMPORT{program}="$env{MPATH_SBIN_PATH}/multipath -u %k"
35
36 # case 1: this is definitely multipath
37 ENV{DM_MULTIPATH_DEVICE_PATH}=="1", \
38         ENV{ID_FS_TYPE}="mpath_member", ENV{SYSTEMD_READY}="0", \
39         GOTO="stop_wait"
40
41 # case 2: this is definitely not multipath, or timeout has expired
42 ENV{DM_MULTIPATH_DEVICE_PATH}!="2", \
43         GOTO="stop_wait"
44
45 # Code below here is only run in "smart" mode.
46 # multipath -u has indicated this is "maybe" multipath.
47
48 # This shouldn't happen, just in case.
49 ENV{FIND_MULTIPATHS_WAIT_UNTIL}!="?*", GOTO="end_mpath"
50
51 # Be careful not to start the timer twice.
52 ACTION!="add", GOTO="pretend_mpath"
53 ENV{.SAVED_FM_WAIT_UNTIL}=="?*", GOTO="pretend_mpath"
54
55 # At this point, we are seeing this path for the first time, and it's "maybe" multipath.
56
57 # The actual start command for the timer.
58 #
59 # The purpose of this command is only to make sure we will receive another
60 # uevent eventually. *Any* uevent may cause waiting to finish if it either ends
61 # in case 1-3 above, or if it arrives after FIND_MULTIPATHS_WAIT_UNTIL.
62 #
63 # Note that this will try to activate multipathd if it isn't running yet.
64 # If that fails, the unit starts and expires nonetheless. If multipathd
65 # startup needs to wait for other services, this wait time will add up with
66 # the --on-active timeout.
67 #
68 # We must trigger an "add" event because LVM2 will only act on those.
69
70 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"
71
72 LABEL="pretend_mpath"
73 ENV{DM_MULTIPATH_DEVICE_PATH}="1"
74 ENV{SYSTEMD_READY}="0"
75 GOTO="end_mpath"
76
77 LABEL="stop_wait"
78 # If timeout hasn't expired but we're not in "maybe" state any more, stop timer
79 # Do this only once, and only if the timer has been started before
80 IMPORT{db}="FIND_MULTIPATHS_WAIT_CANCELLED"
81 ENV{FIND_MULTIPATHS_WAIT_CANCELLED}!="?*", \
82         ENV{FIND_MULTIPATHS_WAIT_UNTIL}=="?*", \
83         ENV{FIND_MULTIPATHS_WAIT_UNTIL}!="0", \
84         ENV{FIND_MULTIPATHS_WAIT_CANCELLED}="1", \
85         RUN+="/usr/bin/systemctl stop cancel-multipath-wait-$kernel.timer"
86
87 LABEL="end_mpath"