Quoting Danny Braniss <danny_at_cs.huji.ac.il>: > Quoting John Nielsen <lists_at_jnielsen.net>: >> 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. > JNReceived on Wed Jun 06 2007 - 14:30:09 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:11 UTC