From owner-freebsd-scsi@FreeBSD.ORG Tue May 7 07:55:32 2013 Return-Path: Delivered-To: freebsd-scsi@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 79A6F8CB for ; Tue, 7 May 2013 07:55:32 +0000 (UTC) (envelope-from danny@cs.huji.ac.il) Received: from kabab.cs.huji.ac.il (kabab.cs.huji.ac.il [132.65.16.84]) by mx1.freebsd.org (Postfix) with ESMTP id 33E926AD for ; Tue, 7 May 2013 07:55:31 +0000 (UTC) Received: from pampa.cs.huji.ac.il ([132.65.80.32]) by kabab.cs.huji.ac.il with esmtp id 1UZckE-000Lcs-Bf for freebsd-scsi@freebsd.org; Tue, 07 May 2013 10:55:30 +0300 X-Mailer: exmh version 2.7.2 01/07/2005 with nmh-1.3 To: freebsd-scsi@freebsd.org Subject: Re: running iscontrol at boot time In-reply-to: Your message of Sun, 05 May 2013 09:31:46 -0700. Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 07 May 2013 10:55:30 +0300 From: Daniel Braniss Message-ID: X-BeenThere: freebsd-scsi@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SCSI subsystem List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 May 2013 07:55:32 -0000 > 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"