Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 07 May 2013 10:53:16 +0300
From:      Daniel Braniss <danny@cs.huji.ac.il>
To:        David Newman <dnewman@networktest.com>
Cc:        freebsd-scsi@freebsd.org
Subject:   Re: running iscontrol at boot time
Message-ID:  <E1UZci4-000LXF-MW@kabab.cs.huji.ac.il>
In-Reply-To: <51868972.804@networktest.com>
References:  <51868972.804@networktest.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi David,
I'm attaching a script, it was last tested on 8.2, but should work :-)

/etc/rc.d/iscsi (probably should be remnamed iscsi_initiator)
#!/bin/sh

# PROVIDE: iscsi
# REQUIRE: NETWORKING
# BEFORE:  DAEMON
# KEYWORD: nojail shutdown

#
# Add the following lines to /etc/rc.conf to enable iscsi:
#
# iscsi_enable="YES"
# iscsi_fstab="/etc/fstab.iscsi"

. /etc/rc.subr
. /cs/share/etc/rc.subr

name=iscsi
rcvar=`set_rcvar`

command=/sbin/iscontrol

iscsi_enable=${iscsi_enable:-"NO"}
iscsi_fstab=${iscsi_fstab:-"/etc/fstab.iscsi"}
iscsi_exports=${iscsi_exports:-"/etc/exports.iscsi"}
iscsi_debug=${iscsi_debug:-0}
start_cmd="iscsi_start"
faststop_cmp="iscsi_stop"
stop_cmd="iscsi_stop"

start_precmd="iscontrol_precmd"
iscontrol_prog=${iscontrol_prog:-"iscontrol"}
iscontrol_log=${iscontrol_log:-"/var/log/$iscontrol_prog"}
iscontrol_syslog=${iscontrol_syslog:-"644  3     100  *     JC"}

iscontrol_precmd()
{
    setup_syslog "$iscontrol_prog" "$iscontrol_log" "$iscontrol_syslog"
}

iscsi_wait()
{
    dev=$1
    trap "echo 'wait loop cancelled'; exit 1" 2
    count=0
    while true; do
	if [ -c $dev ]; then
	    break;
	fi
	if [ $count -eq 0 ]; then
	     echo -n Waiting for ${dev}': '
	fi
	count=$((${count} + 1))
	if [ $count -eq 6 ]; then
	    echo " Failed for dev=$dev"
	    return 0
	    break
	fi
	echo -n '.'
	sleep 5;
    done
    echo "$dev ok."
    return 1
}

iscsi_start()
{
    local file type opt t1 t2
    #
    # load needed modules
    for m in iscsi_initiator geom_label; do
	kldstat -qm $m || kldload $m
    done

    sysctl debug.iscsi_initiator=$iscsi_debug
    #
    # start iscontrol for each target
    if [ -n "${iscsi_targets}" ]; then
	for target in ${iscsi_targets}; do
	    ${command} ${rc_flags} -n ${target}
	done
    fi

    if [ -f "${iscsi_fstab}" ]; then
	while read spec file type opt t1 t2
	do
	  case ${spec} in
	  \#*|'')
		;;
	  *)
	  	if iscsi_wait ${spec}; then
		    break;
		fi
		echo type=$type spec=$spec file=$file
		fsck -p ${spec} && mkdir -p ${file} && mount ${spec} ${file}
		chmod 755 ${file} 
		;;
	  esac
	done < ${iscsi_fstab} 
    fi

    if [ -f "${iscsi_exports}" ]; then
	cat ${iscsi_exports} >> /etc/exports
	#/etc/rc.d/mountd reload
	kill -1 `cat /var/run/mountd.pid`
    fi
    if checkyesno zfs_enable; then
	if checkyesno iscsi_zfs; then
	    sleep 4
  	    zpool import -d /dev/label -a
# presumably we can ignore zfs mount -a share -a and swapon
# some zfs dataset may be exported "legacy", so hup mountd
	    kill -1 `cat /var/run/mountd.pid`
	fi
    fi
}

iscsi_stop()
{
    echo 'iscsi stopping'
    while read spec file type opt t1 t2
	do
	  case ${spec} in
	  \#*|'')
		;;
	  *)
	  	echo iscsi: umount $spec
	  	umount -fv $spec
		;;
	  esac
     done < ${iscsi_fstab} 
}

load_rc_config $name
run_rc_command "$1"





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E1UZci4-000LXF-MW>