Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/etc/rc.d Add start script to attach iscsi volumes at boot.



details:   https://anonhg.NetBSD.org/src/rev/dc09c6079382
branches:  trunk
changeset: 373332:dc09c6079382
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Fri Feb 03 13:53:40 2023 +0000

description:
Add start script to attach iscsi volumes at boot.

The default is to execute the script (iscsid_volumes=YES), so if you have
any volumes defined, you should also start iscsid (iscsid=YES) to avoid
error messages.

diffstat:

 distrib/sets/lists/etc/mi |    4 +-
 etc/defaults/rc.conf      |    4 +-
 etc/rc.d/Makefile         |    4 +-
 etc/rc.d/iscsid_volumes   |  110 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 118 insertions(+), 4 deletions(-)

diffs (175 lines):

diff -r 823155a9b2ae -r dc09c6079382 distrib/sets/lists/etc/mi
--- a/distrib/sets/lists/etc/mi Fri Feb 03 09:21:58 2023 +0000
+++ b/distrib/sets/lists/etc/mi Fri Feb 03 13:53:40 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.270 2022/06/06 10:56:27 nia Exp $
+# $NetBSD: mi,v 1.271 2023/02/03 13:53:40 mlelstv Exp $
 #
 # Note: end-user configuration files that are moved to another location
 #      should not be marked "obsolete"; they should just be removed from
@@ -83,6 +83,7 @@
 ./etc/inetd.conf                               etc-netutil-etc
 ./etc/iscsi/auths                              etc-iscsi-etc           iscsi
 ./etc/iscsi/targets                            etc-iscsi-etc           iscsi
+./etc/iscsi/volumes                            etc-iscsi-etc
 ./etc/kyua/kyua.conf                           etc-kyua-etc            kyua
 ./etc/lkm.conf                                 etc-obsolete            obsolete
 ./etc/localtime                                        etc-sys-etc
@@ -238,6 +239,7 @@
 ./etc/rc.d/irdaattach                          etc-sys-rc
 ./etc/rc.d/iscsi_target                                etc-iscsi-rc
 ./etc/rc.d/iscsid                              etc-iscsi-rc
+./etc/rc.d/iscsid_volumes                      etc-iscsi-rc
 ./etc/rc.d/isdnd                               etc-obsolete            obsolete
 ./etc/rc.d/isibootd                            etc-bootserver-rc
 ./etc/rc.d/kdc                                 etc-krb5-rc
diff -r 823155a9b2ae -r dc09c6079382 etc/defaults/rc.conf
--- a/etc/defaults/rc.conf      Fri Feb 03 09:21:58 2023 +0000
+++ b/etc/defaults/rc.conf      Fri Feb 03 13:53:40 2023 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: rc.conf,v 1.162 2022/02/20 14:42:07 alnsn Exp $
+#      $NetBSD: rc.conf,v 1.163 2023/02/03 13:53:40 mlelstv Exp $
 #
 # /etc/defaults/rc.conf --
 #      default configuration of /etc/rc.conf
@@ -317,6 +317,8 @@
 iscsi_target=NO                iscsi_target_flags=""
 # iSCSI kernel initiator
 iscsid=NO
+# iSCSI attach from /etc/iscsi/volumes
+iscsid_volumes=YES
 
 # WPA daemons.
 hostapd=NO             hostapd_flags="-Bs /etc/hostapd.conf"
diff -r 823155a9b2ae -r dc09c6079382 etc/rc.d/Makefile
--- a/etc/rc.d/Makefile Fri Feb 03 09:21:58 2023 +0000
+++ b/etc/rc.d/Makefile Fri Feb 03 13:53:40 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.116 2022/06/06 10:56:28 nia Exp $
+# $NetBSD: Makefile,v 1.117 2023/02/03 13:53:40 mlelstv Exp $
 
 .include <bsd.own.mk>
 
@@ -25,7 +25,7 @@
                gpio \
                hostapd httpd \
                identd ifwatchd inetd ip6addrctl ipfilter ipfs ipmon ipnat \
-               ipsec irdaattach iscsi_target iscsid isibootd \
+               ipsec irdaattach iscsi_target iscsid iscsid_volumes isibootd \
                kdc \
                ldconfig ldpd lvmlockdir local lpd lvm \
                makemandb mdnsd mixerctl modules mopd motd mountall \
diff -r 823155a9b2ae -r dc09c6079382 etc/rc.d/iscsid_volumes
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/etc/rc.d/iscsid_volumes   Fri Feb 03 13:53:40 2023 +0000
@@ -0,0 +1,110 @@
+#!/bin/sh
+#
+# $NetBSD: iscsid_volumes,v 1.1 2023/02/03 13:53:40 mlelstv Exp $
+#
+
+# PROVIDE: iscsid_volumes
+# REQUIRE: iscsid
+# BEFORE:  securelevel mountcritremote
+
+$_rc_subr_loaded . /etc/rc.subr
+
+name="iscsid_volumes"
+rcvar=$name
+start_cmd="iscsid_volumes_start"
+stop_cmd="iscsid_volumes_stop"
+
+iscsid_volumes_start()
+{
+       test -f /etc/iscsi/volumes || return
+
+       while read host target digest auth user alias; do
+               case $host in
+               \#*) ;;
+               *)
+                       topts=''
+                       case $digest in
+                       *d*) topts="$topts -d";;
+                       esac
+                       case $digest in
+                       *h*) topts="$topts -h";;
+                       esac
+
+                       pass="-"
+                       mpass="-"
+
+                       while read entry dummy; do
+                               case $entry in
+                               \#*) ;;
+                               "$user":*) pass=${entry#*:} ;;
+                               "$target":*) mpass=${entry#*:} ;;
+                               esac
+                       done < /etc/iscsi/auths
+
+                       case $host in
+                       *:*)
+                               port=${host#*:}
+                               host=${host%%:*}
+                               ;;
+                       *)
+                               port=3260
+                               ;;
+                       esac
+
+                       echo "Add target ${alias:-$target}"
+
+                       out=$(/sbin/iscsictl add_target$topts \
+                               -a "$host" \
+                               -p "$port" \
+                               -n "$target" \
+                               -t "$auth" \
+                               -u "$user" \
+                               -s "$pass" \
+                               -S "$mpass" \
+                               -N "${alias:--}")
+                       echo "$out"
+
+                       case $out in
+                       Added\ Target\ [1-9]*,\ Portal\ [1-9]*\ )
+                               out=${out% }
+                               portal=${out##* }
+                               echo "Login $target via Portal $portal"
+                               /sbin/iscsictl login -P "$portal"
+                               ;;
+                       esac
+               esac
+       done < /etc/iscsi/volumes
+}
+
+iscsid_volumes_stop()
+{
+       test -f /etc/iscsi/volumes || return
+
+       while read host target digest auth user alias; do
+               case $host in
+               \#*) ;;
+               *)
+                       echo "Remove target ${alias:-$target}"
+
+                       /sbin/iscsictl list_sessions \
+                       | while read key1 num key2 sesstarget; do
+                               if [ x"$key1" = x"Session" -a \
+                                    x"$key2" = x"Target" -a \
+                                    x"$sesstarget" = x"$target" ]; then
+                                       /sbin/iscsictl logout -I "$num" | grep -v '^OK$'
+                               fi
+                       done
+
+                       /sbin/iscsictl list_targets \
+                       | while read num talias ttarget; do
+                               if [ x"$ttarget" = x"$target" ]; then
+                                       /sbin/iscsictl remove_target -I "$num"
+                               fi
+                       done
+                       ;;
+               esac
+       done < /etc/iscsi/volumes
+}
+
+load_rc_config $name
+run_rc_command "$1"



Home | Main Index | Thread Index | Old Index