diff --git a/iscsi-scst/Makefile b/iscsi-scst/Makefile index 29532c64..83adbde3 100644 --- a/iscsi-scst/Makefile +++ b/iscsi-scst/Makefile @@ -48,17 +48,6 @@ include/iscsi_scst_itf_ver.h: include/iscsi_scst.h install: all @install -vD -m 755 usr/iscsi-scstd $(DESTDIR)$(SBINDIR)/iscsi-scstd @install -vD -m 755 usr/iscsi-scst-adm $(DESTDIR)$(SBINDIR)/iscsi-scst-adm - if [ -f /etc/debian_version ]; then \ - install -vD -m 755 etc/initd/initd.debian $(DESTDIR)$(INITDIR)/iscsi-scst; \ - elif [ -f /etc/redhat-release ]; then \ - install -vD -m 755 etc/initd/initd.redhat $(DESTDIR)$(INITDIR)/iscsi-scst; \ - elif [ -f /etc/gentoo-release ]; then \ - install -vD -m 755 etc/initd/initd.gentoo $(DESTDIR)$(INITDIR)/iscsi-scst; \ - elif [ -f /etc/slackware-version ]; then \ - install -vD -m 755 etc/initd/initd $(DESTDIR)$(RCDIR)/iscsi-scst; \ - else \ - install -vD -m 755 etc/initd/initd $(DESTDIR)$(INITDIR)/iscsi-scst; \ - fi @eval `sed -n 's/#define UTS_RELEASE /KERNELRELEASE=/p' $(KDIR)/include/linux/version.h $(KDIR)/include/linux/utsrelease.h 2>/dev/null`; \ install -vD -m 644 kernel/iscsi-scst.ko \ $(DESTDIR)$(INSTALL_MOD_PATH)/lib/modules/$(KVER)/extra/iscsi-scst.ko diff --git a/iscsi-scst/etc/initd/initd b/iscsi-scst/etc/initd/initd deleted file mode 100644 index 9126fcb2..00000000 --- a/iscsi-scst/etc/initd/initd +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/bash -# -# Start the iSCSI-SCST Target. -# - -PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin -MEM_SIZE=1048576 -SCST_CMD=/usr/local/sbin/scstadmin -SCST_CFG=/etc/scst.conf - -# Additional modules to load/unload -ADD_MODULES="scst_vdisk scst" - -configure_memsize() -{ - if [ -e /proc/sys/net/core/wmem_max ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/wmem_max - fi - - if [ -e /proc/sys/net/core/rmem_max ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/rmem_max - fi - - if [ -e /proc/sys/net/core/wmem_default ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/wmem_default - fi - - if [ -e /proc/sys/net/core/rmem_default ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/rmem_default - fi - - if [ -e /proc/sys/net/ipv4/tcp_mem ]; then - echo "${MEM_SIZE} ${MEM_SIZE} ${MEM_SIZE}" > /proc/sys/net/ipv4/tcp_mem - fi - - if [ -e /proc/sys/net/ipv4/tcp_rmem ]; then - echo "${MEM_SIZE} ${MEM_SIZE} ${MEM_SIZE}" > /proc/sys/net/ipv4/tcp_rmem - fi - - if [ -e /proc/sys/net/ipv4/tcp_wmem ]; then - echo "${MEM_SIZE} ${MEM_SIZE} ${MEM_SIZE}" > /proc/sys/net/ipv4/tcp_wmem - fi -} - -start_server() -{ -# configure_memsize - - modprobe -q crc32c 2>/dev/null - modprobe -q crc32c-intel 2>/dev/null - modprobe iscsi-scst || { exit $? ; } - for module in ${ADD_MODULES}; do - modprobe ${module} || { exit 1 ; } - done - - /usr/local/sbin/iscsi-scstd - - $SCST_CMD -config $SCST_CFG || { exit $? ; } -} - -stop_server() -{ - killall iscsi-scstd - rmmod -w iscsi-scst || { exit $? ; } - rmmod ${ADD_MODULES} || { exit $? ; } -} - -case "$1" in - start) - start_server - ;; - stop) - stop_server - ;; - restart) - stop_server - start_server - ;; - *) - echo "Usage: {start|stop}" >&2 - exit 1 - ;; -esac - -exit $? diff --git a/iscsi-scst/etc/initd/initd.debian b/iscsi-scst/etc/initd/initd.debian deleted file mode 100644 index aae3efec..00000000 --- a/iscsi-scst/etc/initd/initd.debian +++ /dev/null @@ -1,132 +0,0 @@ -#!/bin/sh -# -# chkconfig: - 39 35 -# description: Starts and stops the iSCSI target -# debianized start-stop script - -PID_FILE=/var/run/iscsi-scstd.pid -CONFIG_FILE=/etc/iscsi-scstd.conf -DAEMON=/usr/local/sbin/iscsi-scstd - -PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin - -# Don't touch this "memsize thingy" unless you are blessed -# with knowledge about it. -MEM_SIZE=1048576 - -ADD_MODULES="scst_vdisk scst" - -configure_memsize() -{ - if [ -e /proc/sys/net/core/wmem_max ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/wmem_max - fi - - if [ -e /proc/sys/net/core/rmem_max ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/rmem_max - fi - - if [ -e /proc/sys/net/core/wmem_default ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/wmem_default - fi - - if [ -e /proc/sys/net/core/rmem_default ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/rmem_default - fi - - if [ -e /proc/sys/net/ipv4/tcp_mem ]; then - echo "${MEM_SIZE} ${MEM_SIZE} ${MEM_SIZE}" > /proc/sys/net/ipv4/tcp_mem - fi - - if [ -e /proc/sys/net/ipv4/tcp_rmem ]; then - echo "${MEM_SIZE} ${MEM_SIZE} ${MEM_SIZE}" > /proc/sys/net/ipv4/tcp_rmem - fi - - if [ -e /proc/sys/net/ipv4/tcp_wmem ]; then - echo "${MEM_SIZE} ${MEM_SIZE} ${MEM_SIZE}" > /proc/sys/net/ipv4/tcp_wmem - fi -} - -RETVAL=0 - -iscsi_scstd_start() -{ - echo -n "Starting iSCSI-SCST target service: " -# configure_memsize - modprobe -q crc32c 2>/dev/null - modprobe -q crc32c-intel 2>/dev/null - modprobe iscsi-scst - for m in $ADD_MODULES; do - modprobe $m - done - start-stop-daemon --start --exec $DAEMON --quiet - /usr/local/sbin/scstadmin -config /etc/scst.conf - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - echo "succeeded." - else - echo "failed." - rmmod iscsi-scst - fi -} - -iscsi_scstd_stop() -{ - echo -n "Stopping iSCSI-SCST target service: " - start-stop-daemon --stop --quiet --exec $DAEMON --pidfile $PID_FILE - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - echo "succeeded." - else - echo "failed." - fi - # ugly, but pid file is not removed by iscsi-scstd - rm -f $PID_FILE - - echo -n "Removing iSCSI-SCST target modules: " - if [ -e /sys/module/iscsi_scst ]; then - rmmod -w iscsi-scst - fi - RETVAL=$? - for m in $ADD_MODULES; do - if [ -e /sys/module/$m ]; then - rmmod -w $m - fi - RETVAL=$? - done - modprobe -r crc32c 2>/dev/null - if [ $RETVAL -eq 0 ]; then - echo "succeeded." - else - echo "failed." - exit 1 - fi -} - -case "$1" in - start) - iscsi_scstd_start - ;; - stop) - iscsi_scstd_stop - ;; - restart) - iscsi_scstd_stop - sleep 1 - iscsi_scstd_start - ;; - status) - PID=`pidof iscsi-scstd` - if [ $PID ]; then - echo "iSCSI-SCST target is running at pid $PID" - else - echo "no iSCSI-SCST target found!" - exit 1 - fi - ;; - *) - echo $"Usage: $0 {start|stop|restart|status|dump}" - exit 1 -esac - -exit 0 diff --git a/iscsi-scst/etc/initd/initd.gentoo b/iscsi-scst/etc/initd/initd.gentoo deleted file mode 100644 index c5e9f714..00000000 --- a/iscsi-scst/etc/initd/initd.gentoo +++ /dev/null @@ -1,78 +0,0 @@ -#!/sbin/runscript -# -# System startup script for the SCST iSCSI functionality. -# -# Customized for gentoo linux by Scott Bowe. -# -# Note: on most Linux distributions /bin/sh is a soft link to /bin/bash, while -# on a default Ubuntu setup /bin/sh is a soft link to /bin/dash ! - -PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin -MEM_SIZE=1048576 - -depend() -{ - use net - need scst -} - -configure_memsize() -{ - if [ -e /proc/sys/net/core/wmem_max ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/wmem_max - fi - - if [ -e /proc/sys/net/core/rmem_max ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/rmem_max - fi - - if [ -e /proc/sys/net/core/wmem_default ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/wmem_default - fi - - if [ -e /proc/sys/net/core/rmem_default ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/rmem_default - fi - - if [ -e /proc/sys/net/ipv4/tcp_mem ]; then - echo "${MEM_SIZE} ${MEM_SIZE} ${MEM_SIZE}" > /proc/sys/net/ipv4/tcp_mem - fi - - if [ -e /proc/sys/net/ipv4/tcp_rmem ]; then - echo "${MEM_SIZE} ${MEM_SIZE} ${MEM_SIZE}" > /proc/sys/net/ipv4/tcp_rmem - fi - - if [ -e /proc/sys/net/ipv4/tcp_wmem ]; then - echo "${MEM_SIZE} ${MEM_SIZE} ${MEM_SIZE}" > /proc/sys/net/ipv4/tcp_wmem - fi -} - -start_server() -{ -# configure_memsize - modprobe -q crc32c 2>/dev/null - modprobe -q crc32c-intel 2>/dev/null - modprobe iscsi-scst - /usr/local/sbin/iscsi-scstd - /usr/local/sbin/scstadmin -config /etc/scst.conf -} - -stop_server() -{ - killall iscsi-scstd - rmmod -w iscsi-scst -} - -start() -{ - ebegin "Starting iscsi" - start_server - eend 0 -} - -stop() -{ - ebegin "Stopping iscsi" - stop_server - eend 0 -} diff --git a/iscsi-scst/etc/initd/initd.redhat b/iscsi-scst/etc/initd/initd.redhat deleted file mode 100644 index 3a1ed539..00000000 --- a/iscsi-scst/etc/initd/initd.redhat +++ /dev/null @@ -1,144 +0,0 @@ -#!/bin/sh -# -# chkconfig: - 39 35 -# description: Starts and stops the iSCSI target -# -# pidfile: /var/run/iscsi-scstd.pid -# config: /etc/iscsi-scstd.conf - -# Source function library. -if [ -f /etc/init.d/functions ] ; then - . /etc/init.d/functions -elif [ -f /etc/rc.d/init.d/functions ] ; then - . /etc/rc.d/init.d/functions -else - exit 0 -fi - -PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin -MEM_SIZE=1048576 -SCST_CMD=/usr/local/sbin/scstadmin -SCST_CFG=/etc/scst.conf - -# Additional modules to load/unload -ADD_MODULES="scst_vdisk scst" - -configure_memsize() -{ - if [ -e /proc/sys/net/core/wmem_max ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/wmem_max - fi - - if [ -e /proc/sys/net/core/rmem_max ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/rmem_max - fi - - if [ -e /proc/sys/net/core/wmem_default ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/wmem_default - fi - - if [ -e /proc/sys/net/core/rmem_default ]; then - echo ${MEM_SIZE} > /proc/sys/net/core/rmem_default - fi - - if [ -e /proc/sys/net/ipv4/tcp_mem ]; then - echo "${MEM_SIZE} ${MEM_SIZE} ${MEM_SIZE}" > /proc/sys/net/ipv4/tcp_mem - fi - - if [ -e /proc/sys/net/ipv4/tcp_rmem ]; then - echo "${MEM_SIZE} ${MEM_SIZE} ${MEM_SIZE}" > /proc/sys/net/ipv4/tcp_rmem - fi - - if [ -e /proc/sys/net/ipv4/tcp_wmem ]; then - echo "${MEM_SIZE} ${MEM_SIZE} ${MEM_SIZE}" > /proc/sys/net/ipv4/tcp_wmem - fi -} - -RETVAL=0 - -start() -{ - echo -n "Starting iSCSI target service: " -# configure_memsize - modprobe -q crc32c 2>/dev/null - modprobe -q crc32c-intel 2>/dev/null - modprobe iscsi-scst - for module in ${ADD_MODULES}; do - modprobe ${module} - done - daemon /usr/local/sbin/iscsi-scstd - # -d 0xFFFF - /usr/local/sbin/scstadmin -config /etc/scst.conf - RETVAL=$? - echo - return $RETVAL -} - -stop() -{ - echo -n "Stopping iSCSI target service: " - killall iscsi-scstd - rmmod -w iscsi-scst - RETVAL=$? - modprobe -r crc32c 2>/dev/null - for m in ${ADD_MODULES}; do - if [ -e /sys/module/$m ]; then - rmmod $m - fi - done - if [ $RETVAL -eq 0 ]; then - echo_success - else - echo_failure - fi - echo - return $RETVAL -} - -restart() -{ - stop - start -} - -condrestart() -{ - PID=`pidofproc iscsi-scstd` - if [ $PID ]; then - restart - fi -} - -status() -{ - PID=`pidofproc iscsi-scstd` - if [ ! $PID ]; then - echo "iSCSI target stopped" - exit 1 - else - echo "iscsi-scstd (pid $PID) is running..." - fi -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart) - restart - ;; - condrestart) - condrestart - ;; - status) - status - ;; - *) - echo $"Usage: $0 {start|stop|restart|status}" - exit 1 -esac - -exit $? diff --git a/scstadmin/Makefile b/scstadmin/Makefile index 8d79c25f..4331443b 100644 --- a/scstadmin/Makefile +++ b/scstadmin/Makefile @@ -1,6 +1,11 @@ SCSTADMIN_DIR = scstadmin -INITDIR := $(PREFIX)/etc/init.d +INITDIR := $(shell if [ -f /etc/slackware-version ]; then \ + echo $(PREFIX)/etc/rc.d; \ + else \ + echo $(PREFIX)/etc/init.d; \ + fi) +DEFAULTDIR := $(PREFIX)/etc/default all: cd $(SCSTADMIN_DIR) && $(MAKE) $@ @@ -9,20 +14,36 @@ install: @if ! perl -MExtUtils::MakeMaker -e '' >/dev/null 2>&1; then \ echo Error: the Perl module ExtUtils::MakeMaker must be installed \ first; false; fi - @if [ ! -e /usr/lib/lsb/install_initd ]; then \ - echo Error: the lsb-core package must be installed first; false; fi + @if [ ! -e /etc/slackware-version -a ! -e /lib/lsb/init-functions ]; \ + then \ + echo "Error: the lsb-core (Debian, Ubuntu), redhat-lsb (RHEL, Fedora) "\ + "or insserv (SLES, openSUSE) package must be installed first"; false; fi cd $(SCSTADMIN_DIR) && $(MAKE) $@ - -/usr/lib/lsb/install_initd scst - -/usr/lib/lsb/install_initd qla2x00t - mkdir -m 755 -p $(DESTDIR)$(INITDIR) + install -d $(DESTDIR)$(INITDIR) install -m 755 init.d/scst $(DESTDIR)$(INITDIR) - install -m 755 init.d/qla2x00t $(DESTDIR)$(INITDIR) + if [ ! -e $(DESTDIR)$(DEFAULTDIR)/scst ]; then \ + install -m 755 default/scst $(DESTDIR)$(DEFAULTDIR); \ + fi + @echo + @echo 'If you want SCST to start automatically at boot time, run' \ + 'the following command:' + @if [ ! -z "$(DESTDIR)" ]; then echo -n "chroot $(DESTDIR) "; fi + @echo '/usr/lib/lsb/install_initd scst' + @echo uninstall: - -/usr/lib/lsb/remove_initd qla2x00t - -/usr/lib/lsb/remove_initd scst - -rm -f $(DESTDIR)$(PATH_INITD)/qla2x00t - -rm -f $(DESTDIR)$(PATH_INITD)/scst + if [ -e $(DESTDIR)$(DEFAULTDIR)/scst ]; then \ + mv $(DESTDIR)$(DEFAULTDIR)/scst \ + $(DESTDIR)$(DEFAULTDIR)/scst.`date +%F,%T`; \ + fi + if [ -e $(DESTDIR)$(INITDIR)/scst ]; then \ + if [ -z "$(DESTDIR)" ]; then \ + /usr/lib/lsb/remove_initd scst; \ + else \ + chroot $(DESTDIR) /usr/lib/lsb/remove_initd scst; \ + fi; \ + rm -f $(DESTDIR)$(INITDIR)/scst; \ + fi cd $(SCSTADMIN_DIR) && $(MAKE) $@ perl-module: diff --git a/scstadmin/init.d/README.iscsi b/scstadmin/init.d/README.iscsi deleted file mode 100644 index c86eba1e..00000000 --- a/scstadmin/init.d/README.iscsi +++ /dev/null @@ -1,2 +0,0 @@ -These init scripts are intended for use with non-iscsi configurations. For -iscsi, please use one of the init scripts found in iscsi-scst/etc/initd. diff --git a/scstadmin/init.d/qla2x00t b/scstadmin/init.d/qla2x00t deleted file mode 100755 index 1b243233..00000000 --- a/scstadmin/init.d/qla2x00t +++ /dev/null @@ -1,122 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2008 Mark Buechler -# Copyright (C) 2009 Bart Van Assche -# This software is made available under the GPLv2 license. -# -# System startup script for the QLogic 22xx/23xx card target driver. -# -# Note: on most Linux distributions /bin/sh is a soft link to /bin/bash, while -# on a default Ubuntu setup /bin/sh is a soft link to /bin/dash ! -# -# See also: -# * http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html -# * http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html -# -### BEGIN INIT INFO -# Provides: qla2x00t -# Required-Start: $syslog $local_fs scst -# Required-Stop: $syslog $local_fs scst -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Description: QLogic 22xx/23xx card target driver -### END INIT INFO -### BEGIN CHKCONFIG INFO -# chkconfig: 2345 14 86 -# description: QLogic 22xx/23xx card target driver -### END CHKCONFIG IFO - -PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin - -# Modules to load/unload. -KERNEL_MODULES="qla2x00tgt" - -# Return values according to LSB for all commands but status: -# 0 - success -# 1 - generic or unspecified error -# 2 - invalid or excess argument(s) -# 3 - unimplemented feature (e.g. "reload") -# 4 - insufficient privilege -# 5 - program is not installed -# 6 - program is not configured -# 7 - program is not running -# - -. /lib/lsb/init-functions - -case "$1" in - start) - ## Start the service. - echo -n "Loading and configuring the QLogic target driver" - - for module in ${KERNEL_MODULES}; do - if ! modprobe "${module}"; then - log_failure_msg - exit 5 - fi - done - ;; - stop) - ## Stop the service. - echo -n "Stopping the QLogic target driver" - - reverse_list="" - for module in ${KERNEL_MODULES}; do - reverse_list="${module} ${reverse_list}" - done - for module in ${reverse_list}; do - if [ -e "/sys/module/${module}" ] && ! rmmod "${module}"; then - log_failure_msg FAILED - exit 1 - fi - done - - log_success_msg - ;; - restart) - ## Stop and restart the service if the service is already running, - ## otherwise start the service. - $0 stop - $0 start - ;; - try-restart) - ## Restart the service if the service is already running. - $0 status >/dev/null && $0 restart - ;; - reload) - ## Cause the configuration of the service to be reloaded without - ## actually stopping and restarting the service. - echo -n "Reloading QLogic target driver configuration" - log_success_msg - ;; - force-reload) - ## Cause the configuration to be reloaded if the service supports this, - ## otherwise restart the service if it is running. - echo -n "Reloading QLogic target driver configuration" - log_success_msg - ;; - status) - ## Print the current status of the service. - echo -n "QLogic target driver status: " - - # Status has a slightly different meaning for the status command: - # 0 - service running - # 1 - service dead, but /var/run/ pid file exists - # 2 - service dead, but /var/lock/ lock file exists - # 3 - service not running - - for module in ${KERNEL_MODULES}; do - if [ ! -e "/sys/module/${module}" ]; then - echo "Not loaded" - exit 3 - fi - done - echo "OK" - ;; - *) - echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}" - exit 2 - ;; -esac - -exit 0 diff --git a/scstadmin/init.d/qla2x00t.gentoo b/scstadmin/init.d/qla2x00t.gentoo deleted file mode 100755 index 42a1ca22..00000000 --- a/scstadmin/init.d/qla2x00t.gentoo +++ /dev/null @@ -1,104 +0,0 @@ -#!/sbin/runscript -# -# Copyright (C) 2008 Mark Buechler -# Copyright (C) 2009 Bart Van Assche -# Copyright (C) 2010 Scott Bowe -# This software is made available under the GPLv2 license. -# -# System startup script for the QLogic 22xx/23xx card target driver. -# -# Customized for Gentoo Linux by Scott Bowe -# -# Note: on most Linux distributions /bin/sh is a soft link to /bin/bash, while -# on a default Ubuntu setup /bin/sh is a soft link to /bin/dash ! -# - -opts="${opts} try-restart " -depend() { - use logger localmount - before scst -} -PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin - -# Modules to load/unload. -KERNEL_MODULES="qla2x00tgt" -MODPROBE="/sbin/modprobe" -RMMOD="/sbin/rmmod" - -# Return values according to LSB for all commands but status: -# 0 - success -# 1 - generic or unspecified error -# 2 - invalid or excess argument(s) -# 3 - unimplemented feature (e.g. "reload") -# 4 - insufficient privilege -# 5 - program is not installed -# 6 - program is not configured -# 7 - program is not running -# -start(){ - ## Start the service. - ebegin "Loading and configuring the QLogic target driver" - eindent - ret=0 - for module in ${KERNEL_MODULES}; do - einfo "Loading ${module}" - if ! modprobe "${module}"; then - ret=5 - eend $ret "Failed to load target driver" - return $ret - fi - done - einfo "Qlogic target driver loaded!!!" - eend $? - return $? -} - -stop() { - ## Stop the service. - ebegin "Stopping the QLogic target driver" - eindent - reverse_list="" - for module in ${KERNEL_MODULES}; do - reverse_list="${module} ${reverse_list}" - done - for module in ${reverse_list}; do - einfo "Unloading module" - if [ -e "/sys/module/${module}" ] && ! rmmod "${module}"; then - $eend $? "Failed to unload the target driver" - return $? - fi - done - einfo "Qlogic target driver unloaded!!!" - eend $? - return $? -} - -restart() { - ## Stop and restart the service if the service is already running, - ## otherwise start the service. - stop - start -} - -try-restart() { - ## Restart the service if the service is already running. - status >/dev/null 2>&1 && restart -} - -status() { - einfo "Qlogic target status: " - eindent - - for module in ${SCST_MODULES}; do - if [ ! -e "/sys/module/${module}" ]; then - einfo "${module} not loaded" - ret=3 - eend $ret - return $ret - fi - done - ret=0 - ebegin "Qlogic target loaded OK" - eend $ret - return $ret -} diff --git a/scstadmin/init.d/scst b/scstadmin/init.d/scst index bcde3f5a..3aa1db7e 100755 --- a/scstadmin/init.d/scst +++ b/scstadmin/init.d/scst @@ -1,43 +1,29 @@ #!/bin/sh # # Copyright (C) 2008 Mark Buechler -# Copyright (C) 2009 Bart Van Assche +# Copyright (C) 2009-2011 Bart Van Assche # This software is made available under the GPLv2 license. # -# System startup script for the SCST core functionality. -# -# Note: on most Linux distributions /bin/sh is a soft link to /bin/bash, while -# on a default Ubuntu setup /bin/sh is a soft link to /bin/dash ! +# System startup script for SCST. # # See also: -# * http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html +# * http://refspecs.freestandards.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html # * http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html # ### BEGIN INIT INFO # Provides: scst -# Required-Start: $syslog $local_fs -# Required-Stop: $syslog $local_fs +# Required-Start: $syslog $local_fs $network +# Required-Stop: $syslog $local_fs $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 -# Description: SCST core +# Description: SCST - A Generic SCSI Target Subsystem ### END INIT INFO ### BEGIN CHKCONFIG INFO # chkconfig: 2345 13 87 -# description: SCST core -### END CHKCONFIG IFO - -PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin -SCST_CFG=/etc/scst.conf - -# Modules to load/unload. -# -# !!! DON'T ADD HERE TARGET DRIVERS, WHICH IMMEDIATELLY START ACCEPTING -# !!! NEW CONNECTIONS, BECAUSE AT THIS POINT ACCESS CONTROL HASN'T CONFIGURED -# !!! YET! -# -SCST_MODULES="scst scst_disk scst_vdisk" +# description: SCST - A Generic SCSI Target Subsystem +### END CHKCONFIG INFO -# Return values according to LSB for all commands but status: +# Return values according to LSB for all commands except status: # 0 - success # 1 - generic or unspecified error # 2 - invalid or excess argument(s) @@ -48,27 +34,168 @@ SCST_MODULES="scst scst_disk scst_vdisk" # 7 - program is not running # +PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin +SCST_CFG=/etc/scst.conf +SCST_DFLT=/etc/default/scst + +if [ -e /lib/lsb/init-functions ]; then + . /lib/lsb/init-functions +else +start_daemon() { + "$@" >/dev/null 2>&1 & +} +killproc() { + local exe="`basename "$1"`" + /bin/killall $exe + rm -f "/var/run/$exe.pid" +} +log_success_msg() { + echo "$@" +} +log_failure_msg() { + echo "$@" +} +fi + [ -x "$(which scstadmin)" ] || exit 5 -. /lib/lsb/init-functions +if [ -f $SCST_DFLT ]; then + . $SCST_DFLT +fi + +# Whether or not there is a "TARGET_DRIVER iscsi" section in scst.conf. +using_iscsi() { + for m in $SCST_MODULES; do + if [ $m = "iscsi-scst" ]; then + return 0 + fi + done + return 1 +} + +# Parse scst.conf and assign the list of associated kernel modules to +# SCST_MODULES. +parse_scst_conf() { + if [ ! -e $SCST_CFG ]; then + return 1 + fi + SCST_MODULES="scst ` + sed -n -e 's/^HANDLER \(.*\) {$/\1/p' -e 's/^\[HANDLER \(.*\)\]$/\1/p' \ + $SCST_CFG \ + | while read h; do + case "$h" in + dev_cdrom) echo scst_cdrom;; + dev_changer) echo scst_changer;; + dev_disk*) echo scst_disk;; + dev_modisk*) echo scst_modisk;; + dev_processor) echo scst_processor;; + dev_raid) echo scst_raid;; + dev_tape*) echo scst_tape;; + dev_user) echo scst_user;; + vdisk*|vcdrom) echo scst_vdisk;; + *) echo "$h";; + esac + done | sort -u; + sed -n 's/^TARGET_DRIVER \(.*\) {$/\1/p' $SCST_CFG | while read d; do + case "$d" in + iscsi) echo iscsi-scst;; + qla2x00t) echo qla2x00tgt;; + *) echo "$d";; + esac + done | sort -u + ` $SCST_TARGET_MODULES" + if using_iscsi; then + case "`uname -m`" in + x86_64|i686) + SCST_OPT_MODULES="crc32c-intel $SCST_OPT_MODULES";; + esac + SCST_OPT_MODULES="crc32c $SCST_OPT_MODULES" + DAEMONS="/usr/local/sbin/iscsi-scstd $DAEMONS" + fi +} + +# Stop SCST. parse_scst_conf must already have been invoked. +stop() { + for d in $DAEMONS; do + killproc $d + done + + reverse_list="" + for m in $SCST_MODULES; do + reverse_list="$m $reverse_list" + done + for m in $reverse_list; do + # Although the file name of the iSCSI kernel module is + # "iscsi-scst.ko", pass the name "iscsi_scst" to rmmod. + if [ $m = "iscsi-scst" ]; then + m="iscsi_scst" + fi + refcnt="`cat /sys/module/$m/refcnt 2>/dev/null`" + if [ ! -z "$refcnt" ] && [ "$refcnt" -gt 0 ]; then + # Apparently it can happen that the iscsi_scst refcnt is only + # decremented a short time after killproc finished. If that + # occurs, sleep for a short time. + sleep 1 + fi + if [ -e "/sys/module/$m" ] && ! rmmod $m; then + return 1 + fi + done + for m in $SCST_OPT_MODULES; do + reverse_list="$m $reverse_list" + done + for m in $reverse_list; do + rmmod $m >/dev/null 2>&1 + done + return 0 +} case "$1" in start) ## Start the service. - echo -n "Loading and configuring the mid-level SCSI target SCST" + echo -n "Loading and configuring SCST" + + if [ -e /sys/module/scst ]; then + log_failure_msg + echo Already started + exit 1 + fi - for module in ${SCST_MODULES}; do - if ! modprobe "${module}"; then + parse_scst_conf + + for m in $SCST_OPT_MODULES; do + modprobe $m >/dev/null 2>&1 + done + + for m in $SCST_MODULES; do + module_params="`set|sed -n "s/${m}_parameters='\(.*\)'/\1/p"`" + if ! modprobe $m $module_params; then log_failure_msg + echo modprobe $m $module_params failed. + stop exit 5 fi done + for d in $DAEMONS; do + if ! start_daemon $d; then + log_failure_msg + echo "Starting $d failed" + stop + exit 1 + fi + done + if [ -f $SCST_CFG ]; then - if scstadmin -config $SCST_CFG >/dev/null 2>&1; then + tmpout=/tmp/scstadmin-output-$$ + if scstadmin -config $SCST_CFG >$tmpout 2>&1; then + rm -f $tmpout log_success_msg else log_failure_msg + cat $tmpout + rm -f $tmpout + stop exit 1 fi else @@ -78,26 +205,29 @@ case "$1" in ;; stop) ## Stop the service. - echo -n "Stopping the mid-level SCSI target SCST" + echo -n "Stopping SCST" - reverse_list="" - for module in ${SCST_MODULES}; do - reverse_list="${module} ${reverse_list}" - done - for module in ${reverse_list}; do - if [ -e "/sys/module/${module}" ] && ! rmmod "${module}"; then - log_failure_msg FAILED - exit 1 - fi - done + if ! parse_scst_conf; then + log_failure_msg "No $SCST_CFG found" + exit 1 + fi - log_success_msg + stop + + rc=$? + if [ $rc = 0 ]; then + log_success_msg + else + log_failure_msg + fi + exit $rc ;; restart) ## Stop and restart the service if the service is already running, ## otherwise start the service. - $0 stop - $0 start + if $0 stop; then + $0 start + fi ;; try-restart) ## Restart the service if the service is already running. @@ -134,9 +264,14 @@ case "$1" in # 2 - service dead, but /var/lock/ lock file exists # 3 - service not running - for module in ${SCST_MODULES}; do - if [ ! -e "/sys/module/${module}" ]; then - echo "Not loaded" + parse_scst_conf + + for m in $SCST_MODULES; do + if [ $m = "iscsi-scst" ]; then + m="iscsi_scst" + fi + if [ ! -e "/sys/module/$m" ]; then + echo "$m: not loaded" exit 3 fi done diff --git a/scstadmin/init.d/scst.gentoo b/scstadmin/init.d/scst.gentoo deleted file mode 100755 index 71216b81..00000000 --- a/scstadmin/init.d/scst.gentoo +++ /dev/null @@ -1,176 +0,0 @@ -#!/sbin/runscript -# -# Copyright (C) 2008 Mark Buechler -# Copyright (C) 2009 Bart Van Assche -# Copyright (C) 2010 Scott Bowe -# This software is made available under the GPLv2 license. -# -# System startup script for the SCST core functionality. -# -# Customized for gentoo linux by Scott Bowe. -# -# Note: on most Linux distributions /bin/sh is a soft link to /bin/bash, while -# on a default Ubuntu setup /bin/sh is a soft link to /bin/dash ! - -opts="${opts} try-restart reload force-reload" -depend() { - use logger -} - -PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin - -DEFAULTFILE="/etc/conf.d/scst" -SCST_CFG=/etc/scst.conf -MODPROBE="/sbin/modprobe" -RMMOD="/sbin/rmmod" - -if [ -f $DEFAULTFILE ]; then - . $DEFAULTFILE -fi - -# Modules to load/unload. -# -# !!! DON'T ADD HERE TARGET DRIVERS, WHICH IMMEDIATELLY START ACCEPTING -# !!! NEW CONNECTIONS, BECAUSE AT THIS POINT ACCESS CONTROL HASN'T CONFIGURED -# !!! YET! -# -SCST_MODULES="scst scst_disk scst_vdisk" - -# Return values according to LSB for all commands but status: -# 0 - success -# 1 - generic or unspecified error -# 2 - invalid or excess argument(s) -# 3 - unimplemented feature (e.g. "reload") -# 4 - insufficient privilege -# 5 - program is not installed -# 6 - program is not configured -# 7 - program is not running -# - -checkconfig() { - if [ ! -f $SCST_CFG ] ; then - eerror "Please create $SCST_CFG" - return 1 - fi - return 0 -} - -checkinstall() { - if [ ! -x `which scstadmin` ] ; then - eerror "scstadmin is not intalled" - return 1 - fi - return 0 -} - -start() { - ebegin "Loading and configuring the mid-level SCSI target SCST" - eindent - checkconfig - checkinstall || return $? - ret=0 - for module in ${SCST_MODULES}; do - einfo "Loading SCST module ${module}..." - if ! modprobe "${module}"; then - eerror "${module} failed to load" - eend $? "Failed to load SCST" - return $? - fi - done - einfo "Configuring SCST..." - eindent - if [ -f $SCST_CFG ]; then - if scstadmin -config $SCST_CFG >/dev/null 2>&1; then - einfo "SCST config was loaded" - else - eend $? "SCST config could not be loaded" - return $? - fi - else - einfo "SCST configuration file $SCST_CFG missing, skipping" - return 0 - fi - eoutdent - eoutdent - einfo "SCST loaded!!!" - eend $? -} - -stop() { - ## Stop the service. - ebegin "Stopping the mid-level SCSI target SCST" - eindent - reverse_list="" - for module in ${SCST_MODULES}; do - reverse_list="${module} ${reverse_list}" - done - for module in ${reverse_list}; do - einfo "Unloading ${module}" - if [ -e "/sys/module/${module}" ] && ! rmmod "${module}"; then - eindent - eend $? "Failed to unload ${module}" - return $? - fi - done - eoutdent - einfo "SCST unloaded!!!" - eend $? -} - -restart() { - ## Stop and restart the service if the service is already running, - ## otherwise start the service. - stop - sleep 3 - start -} - -try-restart() { - ## Restart the service if the service is already running. - status >/dev/null 2>&1 && restart -} - -reload() { - ## Cause the configuration of the service to be reloaded without - ## actually stopping and restarting the service. - einfo "Reloading SCST configuration" - eindent - if scstadmin -config $SCST_CFG >/dev/null 2>&1; then - ret=0 - ebegin "SCST config reloaded" - else - eend $? "SCST config could not be releaded" - exit 1 - fi -} - -force-reload() { - ## Cause the configuration to be reloaded if the service supports this, - ## otherwise restart the service if it is running. - einfo "Reloading SCST configuration" - eindent - if scstadmin -config $SCST_CFG >/dev/null 2>&1; then - ret=0 - ebegin "SCST config reloaded" - else - restart - fi -} - -status() { - ## Print the current status of the service. - einfo "SCST status: " - eindent - - for module in ${SCST_MODULES}; do - if [ ! -e "/sys/module/${module}" ]; then - einfo "${module} not loaded" - ret=3 - eend $ret - return $ret - fi - done - ret=0 - ebegin "SCST modules loaded OK" - eend $ret -}