From owner-freebsd-stable@FreeBSD.ORG Wed Jun 6 16:30:09 2007 Return-Path: X-Original-To: freebsd-stable@freebsd.org Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 18CA616A46C; Wed, 6 Jun 2007 16:30:09 +0000 (UTC) (envelope-from lists@jnielsen.net) Received: from ns1.jnielsen.net (ns1.jnielsen.net [69.55.238.237]) by mx1.freebsd.org (Postfix) with ESMTP id E4C1C13C45D; Wed, 6 Jun 2007 16:30:06 +0000 (UTC) (envelope-from lists@jnielsen.net) Received: from ns1.jnielsen.net (jn@ns1 [69.55.238.237]) by ns1.jnielsen.net (8.12.9p2/8.12.9) with ESMTP id l56GTsLR059554; Wed, 6 Jun 2007 12:29:54 -0400 (EDT) (envelope-from lists@jnielsen.net) Received: (from www@localhost) by ns1.jnielsen.net (8.12.9p2/8.12.9/Submit) id l56GTs81059553; Wed, 6 Jun 2007 12:29:54 -0400 (EDT) (envelope-from lists@jnielsen.net) X-Authentication-Warning: ns1.jnielsen.net: www set sender to lists@jnielsen.net using -f Received: from 70.150.196.243 ([70.150.196.243]) by newwebmail.jnielsen.net (Horde MIME library) with HTTP; Wed, 06 Jun 2007 12:29:53 -0400 Message-ID: <20070606122953.mnndzgmvkcc0s8c8@newwebmail.jnielsen.net> Date: Wed, 06 Jun 2007 12:29:53 -0400 From: John Nielsen To: Danny Braniss References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: 7bit User-Agent: Internet Messaging Program (IMP) H3 (4.0.4) / FreeBSD-4.9 X-Virus-Scanned: ClamAV version 0.88.4, clamav-milter version 0.88.4 on ns1.jnielsen.net X-Virus-Status: Clean Cc: freebsd-current@freebsd.org, freebsd-stable@freebsd.org Subject: Re: iSCSI initiator tester wanted X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Jun 2007 16:30:09 -0000 Quoting Danny Braniss : > Quoting John Nielsen : >> Do you have any suggestions on startup integration (rc script, fstab >> magic, etc)? I know you said once before that that was hopefully coming >> soon.. >> > this is an attempt: A couple comments just from reading through this, see below. > #!/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" The iscsi_exports knob should also be documented here. > . /etc/rc.subr > > name=iscsi > rcvar=`set_rcvar` > > command=/usr/local/sbin/iscontrol Assuming this gets commited this will want to be /sbin/iscontrol. > iscsi_enable=${iscsi_enable:-"NO"} > iscsi_fstab=${iscsi_fstab:-"/etc/fstab.iscsi"} > iscsi_exports=${iscsi_exports:-"/etc/exports.iscsi"} > > start_cmd="iscsi_start" > faststop_cmp="iscsi_stop" > stop_cmd="iscsi_stop" > > 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' > return 0 > break > fi > echo -n '.' > sleep 5; > done > echo '.' > return 1 > } > > iscsi_start() > { > # > # load needed modules > for m in iscsi_initiator geom_label; do > kldstat -qm $m || kldload $m > done Good thinking making geom_label a pseudo-requirement. Examples and documentation for fstab.iscsi should strongly recommend its use, since device names will vary. > sysctl debug.iscsi=2 Maybe make this another rc variable that could be set in /etc/rc.conf. You'll probably also want to change the module's default verbosity level once it becomes more official. > # > # 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} && mount ${spec} ${file} > ;; > esac > done < ${iscsi_fstab} > fi > > if [ -f "${iscsi_exports}" ]; then > cat ${iscsi_exports} >> /etc/exports > #/etc/rc.d/mountd reload does not work, why? > kill -1 `cat /var/run/mountd.pid` > fi > } Look at how Pawel handled this with ZFS (mostly in the zfs and mountd rc.d scripts), and use the fact that mountd can take multiple exports files on its command line to your advantage. i.e. appending to the normal exports file is not really what you want to do. > iscsi_stop() > { > echo 'iscsi stopping' > while read spec file type opt t1 t2 > do > case ${spec} in > \#*|'') > ;; > *) > echo iscsi: umount $spec > umount -fv $spec > # and remove from the exports ... See above; this could be a no-op. > ;; > esac > done < ${iscsi_fstab} > } > > load_rc_config $name > run_rc_command "$1" > ------ > problems with the above script: > - no background fsck It would be nice not to re-invent the wheel here, and there are other reasons it would be nice to just use /etc/fstab instead of adding a new file -- a number of utilities use /etc/fstab to map between mountpoints and device names even if the device isn't mounted. Did you try this approach, and if so what obstacles did you encounter? I will play around with this if I have time. The "late" fstab/mount option will probably be useful here. > - restart will mess the exports file > - the wait loop should be replaced by something more deterministic. > JN