dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / iscsid / iscsi-initiator
blob48b97f0f35786f6124e449be87891f2a2e5655f4
1 #!/sbin/sh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
24 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
28 # Start/stop iscsi initiator service
30 . /lib/svc/share/smf_include.sh
32 # checkmessage "fsck_device | mount_point"
34 # Simple auxilary routine to the shell function checkfs. Prints out
35 # instructions for a manual file system check before entering the shell.
37 checkmessage() {
38 echo "" > /dev/console
39 if [ "$1" != "" ] ; then
40 echo "WARNING - Unable to repair one or more \c" \
41 > /dev/console
42 echo "of the following filesystem(s):" > /dev/console
43 echo "\t$1" > /dev/console
44 else
45 echo "WARNING - Unable to repair one or more filesystems." \
46 > /dev/console
48 echo "Run fsck manually (fsck filesystem...)." > /dev/console
49 echo "" > /dev/console
53 # checkfs raw_device fstype mountpoint
55 # Check the file system specified. The return codes from fsck have the
56 # following meanings.
57 # 0 - file system is unmounted and okay
58 # 32 - file system is unmounted and needs checking (fsck -m only)
59 # 33 - file system is already mounted
60 # 34 - cannot stat device
61 # 36 - uncorrectable errors detected - terminate normally (4.1 code 8)
62 # 37 - a signal was caught during processing (4.1 exit 12)
63 # 39 - uncorrectable errors detected - terminate rightaway (4.1 code 8)
64 # 40 - for root, same as 0 (used by rcS to remount root)
66 checkfs() {
67 /usr/sbin/fsck -F $2 -m $1 >/dev/null 2>&1
69 if [ $? -ne 0 ]
70 then
71 # Determine fsck options by file system type
72 case "$2" in
73 ufs) foptions="-o p"
75 *) foptions="-y"
77 esac
79 echo "The "$3" file system ("$1") is being checked."
80 /usr/sbin/fsck -F $2 ${foptions} $1
82 case $? in
83 0|40) # file system OK
86 *) # couldn't fix the file system
87 echo "/usr/sbin/fsck failed with exit code "$?"."
88 checkmessage "$1"
90 esac
95 mount_iscsi() {
96 err=0
97 iscsilist=""
98 exec < /etc/vfstab
99 while read special fsckdev mountp fstype fsckpass automnt mntopts; do
100 case $special in
101 '#'* | '' ) # Ignore comments, empty lines.
102 continue
104 '-') # Ignore "no-action" lines.
105 continue
107 esac
108 if [ "$automnt" != "iscsi" ]; then
109 continue
111 if [ "$fstype" = "-" ]; then
112 echo "iscsi-initiator: FSType of iscsi LUN \c" 1>&2
113 echo "$special cannot be identified" 1>&2
114 continue
118 # Ignore entries already mounted
120 /usr/bin/grep " $mountp " /etc/mnttab >/dev/null \
121 2>&1 && continue
124 # Can't fsck if no fsckdev is specified
126 if [ "$fsckdev" = "-" ]; then
127 iscsilist="$iscsilist $mountp"
128 continue
132 # fsck everything else:
134 # fsck -m simply returns true if the filesystem is
135 # suitable for mounting.
137 /usr/sbin/fsck -m -F $fstype $fsckdev >/dev/null 2>&1
138 case $? in
139 0|40) iscsilist="$iscsilist $mountp"
140 continue
142 32) checkfs $fsckdev $fstype $mountp
143 iscsilist="$iscsilist $mountp"
144 continue
146 33) # already mounted
147 echo "$special already mounted"
149 34) # bogus special device
150 echo "Cannot stat $fsckdev - ignoring"
151 err=1
153 *) # uncorrectable errors
154 echo "$fsckdev uncorrectable error"
155 err=1
157 esac
158 done
160 [ -z "$iscsilist" ] || /sbin/mount -a $iscsilist
161 for iscsilun in $iscsilist
163 /usr/bin/grep " $iscsilun " /etc/mnttab >/dev/null 2>&1
164 if [ $? -ne 0 ]; then
165 echo "Fail to mount $iscsilun"
166 err=1
168 done
169 return $err
172 umount_iscsi () {
174 # Generate iscsi mountp list from /etc/vfstab
175 exec < /etc/vfstab
176 while read special fsckdev mountp fstype fsckpass automnt mntopts; do
177 case $special in
178 '#'* | '') continue;; # Ignore comments,
179 # empty lines.
180 '-') continue;; # Ignore "no-action lines.
181 esac
182 if [ "$automnt" != "iscsi" ]; then
183 continue
185 /usr/bin/grep " $mountp " /etc/mnttab >/dev/null 2>&1
186 if [ $? -ne 0 ]; then
187 continue
189 iscsilist="$iscsilist $mountp"
190 done
192 if [ -n "$iscsilist" ]; then
193 umount -a $iscsilist 1>&2
194 rc=$?
195 else
196 rc=0;
198 return $rc
201 case "$1" in
202 'start')
203 /usr/bin/pgrep -P 1 -x iscsid
204 if [ $? -ne 0 ]; then
205 /lib/svc/method/iscsid
207 if [ $? -eq 0 ]; then
208 delay=60
209 while [ $delay -gt 0 ]; do
210 delay=`expr $delay - 1`
211 mount_iscsi
212 if [ $? -eq 1 ]; then
213 if [ $delay -gt 0 ]; then
214 sleep 1
215 continue
216 else
217 echo "iscsi-initiator: mount iscsi \c"
218 echo "lun in /etc/vfstab fail."
219 umount_iscsi
220 exit $SMF_EXIT_ERR_CONFIG
222 else
223 exit $SMF_EXIT_OK
225 done
226 else
227 exit $?
231 'stop')
232 umount_iscsi
233 /usr/bin/pkill -P 1 -x iscsid
234 exit 0
238 echo "Usage: $0 { start | stop }"
239 exit 1
241 esac
242 exit $SMF_EXIT_OK