2 # Copyright (c) 2005 SuSE GmbH Nuernberg, Germany.
4 # Author: Hannes Reinecke <feedback@suse.de>
6 # init.d/boot.multipath
9 # Provides: boot.multipath
10 # Required-Start: boot.device-mapper boot.udev
11 # Required-Stop: boot.device-mapper boot.udev
12 # Should-Start: boot.xdrsetsite
13 # Should-Stop: boot.xdrsetsite
16 # Short-Description: Create multipath device targets
17 # Description: Setup initial multipath device-mapper targets
20 PATH=/bin:/usr/bin:/sbin:/usr/sbin
21 PROGRAM=/sbin/multipath
23 # Set the maximum number of open files
26 # Number of seconds to wait for disks and partitions
27 MPATH_DEVICE_TIMEOUT=30
29 test -x $PROGRAM || exit 5
31 # Shell functions sourced from /etc/rc.status:
32 # rc_check check and set local and overall rc status
33 # rc_status check and set local and overall rc status
34 # rc_status -v ditto but be verbose in local rc status
35 # rc_status -v -r ditto and clear the local rc status
36 # rc_failed set local and overall rc status to failed
37 # rc_reset clear local rc status (overall remains)
38 # rc_exit exit appropriate to overall rc status
41 # First reset status of this service
44 # Return values acc. to LSB for all commands but status:
47 # 2 - invalid or excess args
48 # 3 - unimplemented feature (e.g. reload)
49 # 4 - insufficient privilege
50 # 5 - program not installed
51 # 6 - program not configured
52 # 7 - program is not running
54 # Note that starting an already running service, stopping
55 # or restarting a not-running service as well as the restart
56 # with force-reload (in case signalling is not supported) are
57 # considered a success.
61 # Check for existing multipath mappings
62 if dmsetup table --target multipath | grep -q multipath ; then
63 # Multipath active, start daemon
64 exec /etc/init.d/multipathd $1
67 echo -n "Creating multipath targets:"
68 # Check whether multipath daemon is already running
69 if /sbin/multipathd -k"list paths" > /dev/null 2>&1 ; then
70 echo -n " (multipathd running)"
74 # Load prerequisite module
77 # Set the maximum number of open files
78 if [ -n "$MAX_OPEN_FDS" ] ; then
79 ulimit -n $MAX_OPEN_FDS
82 # Start the program directly as checkproc doesn't work here
84 echo -n " (waiting for udev)"
85 # Wait for all multipathed devices to appear
86 maplist=$(/sbin/dmsetup ls --target multipath | sed '/No devices/d' | sed -n 's/\(^[^ ()]*\)[\t ]*.*/\1/p')
87 wait=$MPATH_DEVICE_TIMEOUT
88 while [ $wait -gt 0 ] ; do
90 for map in $maplist; do
91 [ -e /dev/disk/by-id/dm-name-$map ] && continue
94 [ $num -eq 0 ] && break
98 if [ $wait -le 0 ] ; then
99 echo -n " timeout: $num devices left"
102 # Reset to wait for partitions
103 wait=$MPATH_DEVICE_TIMEOUT
105 # Wait for all partitions on multipathed devices
106 while [ $wait -gt 0 ] ; do
108 for map in $maplist ; do
109 [ -e /dev/disk/by-id/dm-name-$map ] || continue
110 partlist=$(/sbin/kpartx -l -p _part /dev/disk/by-id/dm-name-$map | sed 's/\([^ ]*\) :.*/\1/p')
111 for part in $partlist; do
112 [ -e /dev/disk/by-id/dm-name-$part ] && continue
116 [ $num -eq 0 ] && break
120 if [ $wait -le 0 ] ; then
121 echo -n "timeout: $num partitions left"
125 # Remember status and be verbose
129 echo -n "Removing multipath targets:"
131 # Flush all existing maps
138 echo -n "Checking multipath targets: "
139 # Display active multipath tables
140 tblnum=$(/sbin/dmsetup ls --target multipath | sed '/No devices/d' | wc --lines)
141 if [ "$tblnum" ] && [ $tblnum -gt 0 ] ; then
142 echo -n "($tblnum multipath devices) "
154 echo "Usage: $0 {start|stop|status}"