Use struct udev_device instead of sysdev
[platform/upstream/multipath-tools.git] / multipath / multipath.init.suse
1 #! /bin/sh
2 # Copyright (c) 2005 SuSE GmbH Nuernberg, Germany.
3 #
4 # Author: Hannes Reinecke <feedback@suse.de>
5 #
6 # init.d/boot.multipath
7 #
8 ### BEGIN INIT INFO
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
14 # Default-Start:     B
15 # Default-Stop:
16 # Short-Description:       Create multipath device targets
17 # Description:       Setup initial multipath device-mapper targets
18 ### END INIT INFO
19
20 PATH=/bin:/usr/bin:/sbin:/usr/sbin
21 PROGRAM=/sbin/multipath
22
23 # Set the maximum number of open files
24 MAX_OPEN_FDS=4096
25
26 # Number of seconds to wait for disks and partitions
27 MPATH_DEVICE_TIMEOUT=30
28
29 test -x $PROGRAM || exit 5
30
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
39 . /etc/rc.status
40
41 # First reset status of this service
42 rc_reset
43
44 # Return values acc. to LSB for all commands but status:
45 # 0 - success
46 # 1 - misc error
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
53
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.
58
59 case "$1" in
60     start)
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
65         fi
66
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)"
71             rc_status -v
72             rc_exit
73         fi
74         # Load prerequisite module
75         modprobe dm-multipath
76         
77         # Set the maximum number of open files
78         if [ -n "$MAX_OPEN_FDS" ] ; then
79             ulimit -n $MAX_OPEN_FDS
80         fi
81
82         # Start the program directly as checkproc doesn't work here
83         $PROGRAM -v 0
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
89             num=0
90             for map in $maplist; do
91                 [ -e /dev/disk/by-id/dm-name-$map ] && continue
92                 num=$((num + 1))
93             done
94             [ $num -eq 0 ] && break
95             wait=$((wait - 1))
96             sleep 1;
97         done
98         if [ $wait -le 0 ] ; then
99             echo -n " timeout: $num devices left"
100             rc_failed 1
101         else
102             # Reset to wait for partitions
103             wait=$MPATH_DEVICE_TIMEOUT
104         fi
105         # Wait for all partitions on multipathed devices
106         while [ $wait -gt 0 ] ; do
107             num=0
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
113                     num$((num + 1))
114                 done
115             done
116             [ $num -eq 0 ] && break
117             wait=$((wait - 1))
118             sleep 1;
119         done
120         if [ $wait -le 0 ] ; then
121             echo -n "timeout: $num partitions left"
122             rc_failed 1
123         fi
124
125         # Remember status and be verbose
126         rc_status -v
127         ;;
128     stop)
129         echo -n "Removing multipath targets:"
130
131         # Flush all existing maps
132         $PROGRAM -F
133
134         rc_failed 0
135         rc_status -v
136         ;;
137     status)
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) "
143             rc_failed 0
144         else
145             rc_failed 3
146         fi
147         rc_status -v
148         ;;
149     reload)
150         $0 stop
151         $0 start
152         ;;
153     *)
154         echo "Usage: $0 {start|stop|status}"
155         exit 1
156         ;;
157 esac
158 rc_exit