Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 07 May 2013 10:55:30 +0300
From:      Daniel Braniss <danny@cs.huji.ac.il>
To:        freebsd-scsi@freebsd.org
Subject:   Re: running iscontrol at boot time
Message-ID:  <E1UZckE-000Lcs-Bf@kabab.cs.huji.ac.il>
In-Reply-To: Your message of Sun, 05 May 2013 09:31:46 -0700.

Next in thread | Raw E-Mail | Index | Archive | Help
> How to configure FreeBSD so that iscontrol runs at boot time, so that an
> iSCSI initiator will mount a filesystem on an iSCSI target?
> 
> In this case the FreeBSD system is an iSCSI initiator. The
> /boot/loader.conf file has 'iscsi_initiator_load="YES"' but iscontrol
> does not run at boot time.
> 
> I believe iscontrol needs to run after the kernel module is loaded but
> before a filesystem in /etc/fstab is mounted.
> 
> This works fine manually, but a reboot fails because the FreeBSD box
> doesn't run iscontrol at boot time, and thus can't mount the filesystem
> on the iSCSI target.
> 
> Pardon me if this has been asked before, as it seems like a standard
> problem, but I couldn't find anything in recent archives or in the man
> pages.
> 
> The initiator runs a generic FreeBSD 8.3-RELEASE/amd64 kernel.
> 
> Thanks!
> 
> dn

This is a script that was lst tested in 2009, but should work :-)
also, should be renamed 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: <http://docs.FreeBSD.org/cgi/mid.cgi?E1UZckE-000Lcs-Bf>