
This patch provides userspace iSCSI target support. https://dev.openwrt.org/ticket/8798 Signed-off-by: Maxim Storchak <m.storchak@gmail.com> Signed-off-by: Florian Fainelli <florian@openwrt.org> git-svn-id: svn://svn.openwrt.org/openwrt/packages@40703 3c298f89-4303-0410-b956-a3cf2f4a3e73
108 lines
2.8 KiB
Bash
Executable File
108 lines
2.8 KiB
Bash
Executable File
#!/bin/sh /etc/rc.common
|
|
START=91
|
|
STOP=10
|
|
|
|
EXTRA_COMMANDS="show"
|
|
EXTRA_HELP=" show Show current configuration of tgtd"
|
|
|
|
NAME=tgt
|
|
PROG=/usr/sbin/tgtd
|
|
USE_PROCD=1
|
|
|
|
tgtadm="/usr/sbin/tgtadm --lld iscsi"
|
|
|
|
handle_lun() {
|
|
local tgt_lun=$1
|
|
local tgtid=$2
|
|
local ro device type bstype sync direct
|
|
local my_tgtid=${tgt_lun%_*}
|
|
local lun=${tgt_lun#*_}
|
|
[ $my_tgtid -eq $tgtid ] || return 0
|
|
|
|
config_get device $1 device ""
|
|
[ "$device" ] || return 1
|
|
|
|
config_get type $1 type disk
|
|
config_get bstype $1 bstype rdwr
|
|
config_get_bool readonly $1 readonly 0
|
|
config_get_bool sync $1 sync 0
|
|
config_get_bool direct $1 direct 0
|
|
if [ $sync -ne 0 -o $direct -ne 0 ]; then
|
|
local bsoflags
|
|
[ $sync -ne 0 ] && bsoflags="sync"
|
|
[ $direct -ne 0 ] && bsoflags="direct"
|
|
[ $sync -ne 0 -a $direct -ne 0 ] && bsoflags="sync:direct"
|
|
bsoflags="--bsoflags $bsoflags"
|
|
fi
|
|
|
|
local _tgtadm="$tgtadm --mode logicalunit --tid $tgtid --lun $lun"
|
|
$_tgtadm --op new --backing-store $device --device-type $type --bstype $bstype --bstype $bstype $bsoflags || return 1
|
|
$_tgtadm --op update --param readonly=$readonly || return 1
|
|
}
|
|
|
|
handle_account() {
|
|
local tgtid=$2
|
|
local _tgtadm="$tgtadm --mode account"
|
|
local target user password outgoing
|
|
|
|
config_get target $1 target ""
|
|
[ "$target" ] || return 1
|
|
[ $target -eq $tgtid ] || return 0
|
|
|
|
config_get user $1 user ""
|
|
[ "$user" ] || return 1
|
|
|
|
config_get password $1 password ""
|
|
config_get_bool outgoing $1 outgoing 0
|
|
[ "$outgoing" -ne 0 ] && outgoing=--outgoing || outgoing=""
|
|
|
|
$_tgtadm --op new --user "$user" --password "$password" || return 1
|
|
$_tgtadm --op bind --tid $tgtid --user "$user" $outgoing || return 1
|
|
}
|
|
|
|
handle_target() {
|
|
local tgtid=$1
|
|
local tgtname allow
|
|
local _tgtadm="$tgtadm --mode target"
|
|
|
|
[ $tgtid -ge 0 ] || return 1
|
|
|
|
config_get tgtname $1 name iqn.2012-06.org.openwrt
|
|
config_get allow $1 allow ALL
|
|
|
|
$_tgtadm --op new --tid $tgtid --targetname $tgtname || return 1
|
|
$_tgtadm --op bind --tid $tgtid -I $allow || return 1
|
|
|
|
config_foreach handle_lun lun $tgtid || return 1
|
|
config_foreach handle_account account $tgtid || return 1
|
|
}
|
|
|
|
configure() {
|
|
config_load $NAME
|
|
$tgtadm --mode sys --op update --name State -v offline || return 1
|
|
config_foreach handle_target target || return 1
|
|
$tgtadm --mode sys --op update --name State -v ready || return 1
|
|
return 0
|
|
}
|
|
|
|
start_service() {
|
|
procd_open_instance
|
|
procd_set_param command $PROG -f
|
|
procd_set_param respawn
|
|
procd_close_instance
|
|
logger -t $NAME -s "Configuration will be loaded in seconds"
|
|
( sleep 5; configure || { stop_service; exit 1; } ) &
|
|
}
|
|
|
|
stop_service() {
|
|
$tgtadm --mode sys --op update --name State -v offline
|
|
$tgtadm --mode target --op show \
|
|
| awk '$1 == "Target" {sub(/:/,"",$2); print $2}' \
|
|
| xargs -n1 $tgtadm --mode target --op delete --force --tid
|
|
$tgtadm --mode sys --op delete
|
|
}
|
|
|
|
show() {
|
|
$tgtadm --mode target --op show
|
|
}
|