diff options
| author | yi zhang - Sun Microsystems - Beijing China <Zhang.Yi@Sun.COM> | 2010-04-13 09:45:48 +0800 |
|---|---|---|
| committer | yi zhang - Sun Microsystems - Beijing China <Zhang.Yi@Sun.COM> | 2010-04-13 09:45:48 +0800 |
| commit | d30a1dc56ac8d5e7462b900c98440ba40daa3a46 (patch) | |
| tree | f75cceae17e1e2d4422e4658ff20857608173ecc /usr/src/cmd/iscsid | |
| parent | 8535923051a46cbc5d4842231151bbd31b9e6f4b (diff) | |
| download | illumos-joyent-d30a1dc56ac8d5e7462b900c98440ba40daa3a46.tar.gz | |
6918170 iscsi based target devices cannot be mounted automatically via /etc/vfstab during boot time
Diffstat (limited to 'usr/src/cmd/iscsid')
| -rw-r--r-- | usr/src/cmd/iscsid/Makefile | 14 | ||||
| -rw-r--r-- | usr/src/cmd/iscsid/iscsi-initiator | 243 | ||||
| -rw-r--r-- | usr/src/cmd/iscsid/iscsi-initiator.xml | 26 |
3 files changed, 267 insertions, 16 deletions
diff --git a/usr/src/cmd/iscsid/Makefile b/usr/src/cmd/iscsid/Makefile index 92383a476b..014dc9b90f 100644 --- a/usr/src/cmd/iscsid/Makefile +++ b/usr/src/cmd/iscsid/Makefile @@ -19,23 +19,21 @@ # CDDL HEADER END # # -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. +# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. # # # cmd/iscsid/Makefile # -PROG= iscsi-initiator +PROG= iscsid MANIFEST= iscsi-initiator.xml -SVCMETHOD= iscsi-initiator +SVCMETHOD= iscsi-initiator \ + iscsid PRODUCT= $(PROG) OBJS= iscsid.o SRCS= $(OBJS:%.o=./%.c) LLOBJS= $(OBJS:%.o=%.ll) -POFILES= $(OBJS:%.o=%.po) -POFILE= iscsi-initiator.po include ../Makefile.cmd @@ -63,10 +61,6 @@ clean: lint: lint_SRCS -$(POFILE): $(POFILES) - $(RM) $@ - cat $(POFILES) > $@ - install: all $(ROOTMANIFEST) $(ROOTSVCMETHOD) check: $(CHKMANIFEST) diff --git a/usr/src/cmd/iscsid/iscsi-initiator b/usr/src/cmd/iscsid/iscsi-initiator new file mode 100644 index 0000000000..48b97f0f35 --- /dev/null +++ b/usr/src/cmd/iscsid/iscsi-initiator @@ -0,0 +1,243 @@ +#!/sbin/sh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +# + +# +# Start/stop iscsi initiator service +# +. /lib/svc/share/smf_include.sh + +# checkmessage "fsck_device | mount_point" +# +# Simple auxilary routine to the shell function checkfs. Prints out +# instructions for a manual file system check before entering the shell. +# +checkmessage() { + echo "" > /dev/console + if [ "$1" != "" ] ; then + echo "WARNING - Unable to repair one or more \c" \ + > /dev/console + echo "of the following filesystem(s):" > /dev/console + echo "\t$1" > /dev/console + else + echo "WARNING - Unable to repair one or more filesystems." \ + > /dev/console + fi + echo "Run fsck manually (fsck filesystem...)." > /dev/console + echo "" > /dev/console +} + +# +# checkfs raw_device fstype mountpoint +# +# Check the file system specified. The return codes from fsck have the +# following meanings. +# 0 - file system is unmounted and okay +# 32 - file system is unmounted and needs checking (fsck -m only) +# 33 - file system is already mounted +# 34 - cannot stat device +# 36 - uncorrectable errors detected - terminate normally (4.1 code 8) +# 37 - a signal was caught during processing (4.1 exit 12) +# 39 - uncorrectable errors detected - terminate rightaway (4.1 code 8) +# 40 - for root, same as 0 (used by rcS to remount root) +# +checkfs() { + /usr/sbin/fsck -F $2 -m $1 >/dev/null 2>&1 + + if [ $? -ne 0 ] + then + # Determine fsck options by file system type + case "$2" in + ufs) foptions="-o p" + ;; + *) foptions="-y" + ;; + esac + + echo "The "$3" file system ("$1") is being checked." + /usr/sbin/fsck -F $2 ${foptions} $1 + + case $? in + 0|40) # file system OK + ;; + + *) # couldn't fix the file system + echo "/usr/sbin/fsck failed with exit code "$?"." + checkmessage "$1" + ;; + esac + fi +} + + +mount_iscsi() { + err=0 + iscsilist="" + exec < /etc/vfstab + while read special fsckdev mountp fstype fsckpass automnt mntopts; do + case $special in + '#'* | '' ) # Ignore comments, empty lines. + continue + ;; + '-') # Ignore "no-action" lines. + continue + ;; + esac + if [ "$automnt" != "iscsi" ]; then + continue + fi + if [ "$fstype" = "-" ]; then + echo "iscsi-initiator: FSType of iscsi LUN \c" 1>&2 + echo "$special cannot be identified" 1>&2 + continue + fi + + # + # Ignore entries already mounted + # + /usr/bin/grep " $mountp " /etc/mnttab >/dev/null \ + 2>&1 && continue + + # + # Can't fsck if no fsckdev is specified + # + if [ "$fsckdev" = "-" ]; then + iscsilist="$iscsilist $mountp" + continue + fi + + # + # fsck everything else: + # + # fsck -m simply returns true if the filesystem is + # suitable for mounting. + # + /usr/sbin/fsck -m -F $fstype $fsckdev >/dev/null 2>&1 + case $? in + 0|40) iscsilist="$iscsilist $mountp" + continue + ;; + 32) checkfs $fsckdev $fstype $mountp + iscsilist="$iscsilist $mountp" + continue + ;; + 33) # already mounted + echo "$special already mounted" + ;; + 34) # bogus special device + echo "Cannot stat $fsckdev - ignoring" + err=1 + ;; + *) # uncorrectable errors + echo "$fsckdev uncorrectable error" + err=1 + ;; + esac + done + + [ -z "$iscsilist" ] || /sbin/mount -a $iscsilist + for iscsilun in $iscsilist + do + /usr/bin/grep " $iscsilun " /etc/mnttab >/dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Fail to mount $iscsilun" + err=1 + fi + done + return $err +} + +umount_iscsi () { + # + # Generate iscsi mountp list from /etc/vfstab + exec < /etc/vfstab + while read special fsckdev mountp fstype fsckpass automnt mntopts; do + case $special in + '#'* | '') continue;; # Ignore comments, + # empty lines. + '-') continue;; # Ignore "no-action lines. + esac + if [ "$automnt" != "iscsi" ]; then + continue + fi + /usr/bin/grep " $mountp " /etc/mnttab >/dev/null 2>&1 + if [ $? -ne 0 ]; then + continue + fi + iscsilist="$iscsilist $mountp" + done + + if [ -n "$iscsilist" ]; then + umount -a $iscsilist 1>&2 + rc=$? + else + rc=0; + fi + return $rc +} + +case "$1" in +'start') + /usr/bin/pgrep -P 1 -x iscsid + if [ $? -ne 0 ]; then + /lib/svc/method/iscsid + fi + if [ $? -eq 0 ]; then + delay=60 + while [ $delay -gt 0 ]; do + delay=`expr $delay - 1` + mount_iscsi + if [ $? -eq 1 ]; then + if [ $delay -gt 0 ]; then + sleep 1 + continue + else + echo "iscsi-initiator: mount iscsi \c" + echo "lun in /etc/vfstab fail." + umount_iscsi + exit $SMF_EXIT_ERR_CONFIG + fi + else + exit $SMF_EXIT_OK + fi + done + else + exit $? + fi + ;; + +'stop') + umount_iscsi + /usr/bin/pkill -P 1 -x iscsid + exit 0 + ;; + +*) + echo "Usage: $0 { start | stop }" + exit 1 + ;; +esac +exit $SMF_EXIT_OK + diff --git a/usr/src/cmd/iscsid/iscsi-initiator.xml b/usr/src/cmd/iscsid/iscsi-initiator.xml index 32cc215e30..42e0f21384 100644 --- a/usr/src/cmd/iscsid/iscsi-initiator.xml +++ b/usr/src/cmd/iscsid/iscsi-initiator.xml @@ -22,8 +22,7 @@ CDDL HEADER END - Copyright 2009 Sun Microsystems, Inc. All rights reserved. - Use is subject to license terms. + Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. Service manifests for the iSCSI Initiator --> @@ -76,6 +75,14 @@ potential to specialize all the properties/methods. <single_instance/> <dependency + name='network' + grouping='require_any' + restart_on='error' + type='service'> + <service_fmri value='svc:/milestone/network' /> + </dependency> + + <dependency name='net' grouping='require_all' restart_on='none' @@ -91,6 +98,13 @@ potential to specialize all the properties/methods. <service_fmri value='svc:/network/loopback' /> </dependency> + <dependent + name='iscsi-initiator_multi-user' + grouping='optional_all' + restart_on='none'> + <service_fmri value='svc:/milestone/multi-user' /> + </dependent> + <!-- Set a timeout of -1 to signify to inetd that we don't want to timeout this service, since the forked process is the @@ -102,13 +116,13 @@ potential to specialize all the properties/methods. <exec_method type='method' name='start' - exec='/lib/svc/method/iscsi-initiator' + exec='/lib/svc/method/iscsi-initiator %m' timeout_seconds='600'> <method_context> <method_credential user='root' group='root' - privileges='basic,sys_devices' + privileges='basic,sys_devices,sys_mount' /> </method_context> </exec_method> @@ -116,13 +130,13 @@ potential to specialize all the properties/methods. <exec_method type='method' name='stop' - exec=':kill' + exec='/lib/svc/method/iscsi-initiator %m' timeout_seconds='600'> <method_context> <method_credential user='root' group='root' - privileges='basic,sys_devices' + privileges='basic,sys_devices,sys_mount' /> </method_context> </exec_method> |
