iSCSI target This patch adds a user space iscsi implementation. It provides a daemon tgtd, a control tool tgtadm, init script and an example uci config.
It has been tested with Scientific Linux 6 iscsi-initiator-utils-6.2.0.872-34.el6.x86_64, also worked with Microsoft iSCSI initiator and Global SAN 4 on Mac OS X. The best performance was observed with an image file located on a local filesystem. Raw device was much slower for some reason. Also, direct mode didn't work well for me - I could not mount filesystem after creating it. "Image indirect" mode worked perfectly. Signed-off-by: Maxim Storchak <[email protected]> net/tgt/Makefile | 57 +++++++++++++++++ net/tgt/files/etc/config/tgt | 38 +++++++++++ net/tgt/files/etc/init.d/tgt | 111 +++++++++++++++++++++++++++++++++ net/tgt/patches/010-fallocate.patch | 14 +++++ net/tgt/patches/020-usr_Makefile.patch | 26 ++++++++ net/tgt/patches/030-Makefile.patch | 11 ++++ 6 files changed, 257 insertions(+) diff --git a/net/tgt/Makefile b/net/tgt/Makefile new file mode 100644 index 0000000..1e87be2 --- /dev/null +++ b/net/tgt/Makefile @@ -0,0 +1,57 @@ +# +# Copyright (C) 2012 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. + +include $(TOPDIR)/rules.mk + +PKG_NAME:=tgt +PKG_VERSION:=1.0.30 +PKG_RELEASE:=2 +GIT_SHORT_REV:=9dc30be + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://github.com/fujita/tgt/tarball/v$(PKG_VERSION) + +#PKG_MD5SUM:= + +PKG_BUILD_DIR:=$(BUILD_DIR)/fujita-$(PKG_NAME)-$(GIT_SHORT_REV) + +include $(INCLUDE_DIR)/package.mk + +define Package/tgt + SECTION:=net + CATEGORY:=Network + URL:=http://stgt.sourceforge.net/ + TITLE:=userspace iSCSI target + DEPENDS:=+libpthread +endef + +define Package/tgt/description +Linux SCSI target framework (tgt) aims to simplify various SCSI target driver (iSCSI, Fibre Channel, SRP, etc) creation and maintenance. +Key goals of the project are the clean integration into the scsi-mid layer and implementing a great portion of tgt in user space. +Tgt consists of kernel-space and user-space code. The kernel-space component is included in upstream as of 2.6.20. +Note that if you are interested in only iSCSI (probably you are), you need only the user-space code (any kernel version is fine). +endef + +define Build/Compile + CC=$(TARGET_CC) $(MAKE) -C $(PKG_BUILD_DIR) \ + DESTDIR="$(PKG_INSTALL_DIR)" \ + LD="$(TARGET_CC)" \ + install-programs +endef + +define Package/tgt/conffiles + /etc/config/tgt +endef + +define Package/tgt/install + $(INSTALL_DIR) $(1)/ + $(INSTALL_DIR) $(1)/usr/sbin + $(CP) ./files/* $(1)/ + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/tgtd $(1)/usr/sbin/ + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/tgtadm $(1)/usr/sbin/ +endef + +$(eval $(call BuildPackage,tgt)) diff --git a/net/tgt/files/etc/config/tgt b/net/tgt/files/etc/config/tgt new file mode 100644 index 0000000..250d12d --- /dev/null +++ b/net/tgt/files/etc/config/tgt @@ -0,0 +1,38 @@ +config target 1 + option name 'iqn.2012-06.org.openwrt:target1' + option allow ALL + +#config target 2 +# option name 'iqn.2012-06.org.openwrt:t2' +# option allow 192.168.1.0/24 + + +# all options are set to default, except for the device +# for all type and bstype values see tgtd(8) +# lun "name" is constructed as TGTID_LUN +#config lun 1_1 +# option readonly 0 +# option device /dev/sda +# option type disk +# option bstype rdwr +# option sync 0 +# option direct 0 + + +#config lun 2_1 +# option readonly 0 +# option device /mnt/iscsi.img + +#config lun 2_2 +# option device /dev/sdc + +#config account +# option target 1 +# option user "username1" +# option password "pass1" + +#config account +# option target 2 +# option user "user2" +# option password "pwd2" +# option outgoing 1 diff --git a/net/tgt/files/etc/init.d/tgt b/net/tgt/files/etc/init.d/tgt new file mode 100644 index 0000000..06496b1 --- /dev/null +++ b/net/tgt/files/etc/init.d/tgt @@ -0,0 +1,111 @@ +#!/bin/sh /etc/rc.common +START=91 +STOP=10 + +SERVICE_SIG_STOP=INT + +EXTRA_COMMANDS="show status" +EXTRA_HELP=" show Show current configuration of tgtd + status Check of tgtd is running" + +NAME=tgt +EXEC=/usr/sbin/${NAME}d + +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 --op update --mode sys --name State -v offline || return 1 + config_foreach handle_target target || return 1 + $tgtadm --op update --mode sys --name State -v ready || return 1 + return 0 +} + +start() { + service_start $EXEC || return 1 + configure || { stop; exit 1; } +} + +stop() { + $tgtadm --op update --mode sys --name State -v offline + sleep 3 + service_stop $EXEC +} + +restart() { + stop; sleep 3; start +} + +show() { + $tgtadm --mode target --op show +} + +status() { + start-stop-daemon -x $EXEC -K -t -q && echo $NAME is running || echo $NAME is stopped +} diff --git a/net/tgt/patches/010-fallocate.patch b/net/tgt/patches/010-fallocate.patch new file mode 100644 index 0000000..5fe9ca5 --- /dev/null +++ b/net/tgt/patches/010-fallocate.patch @@ -0,0 +1,14 @@ +--- a/usr/util.h 2012-06-14 02:39:48.000000000 +0300 ++++ b/usr/util.h 2012-06-14 03:20:44.000000000 +0300 +@@ -209,11 +209,6 @@ + */ + static inline int unmap_file_region(int fd, off_t offset, off_t length) + { +-#ifdef FALLOC_FL_PUNCH_HOLE +- if (fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, +- offset, length) == 0) +- return 0; +-#endif + return -1; + } + diff --git a/net/tgt/patches/020-usr_Makefile.patch b/net/tgt/patches/020-usr_Makefile.patch new file mode 100644 index 0000000..b04ed51 --- /dev/null +++ b/net/tgt/patches/020-usr_Makefile.patch @@ -0,0 +1,26 @@ +--- a/usr/Makefile 2012-06-03 02:04:54.000000000 +0300 ++++ b/usr/Makefile 2012-06-14 03:22:27.000000000 +0300 +@@ -38,7 +38,7 @@ + + LIBS += -lpthread + +-PROGRAMS += tgtd tgtadm tgtimg ++PROGRAMS += tgtd tgtadm + TGTD_OBJS += tgtd.o mgmt.o target.o scsi.o log.o driver.o util.o work.o \ + concat_buf.o parser.o spc.o sbc.o mmc.o osd.o scc.o smc.o \ + ssc.o bs_ssc.o libssc.o \ +@@ -62,14 +62,8 @@ + + -include $(TGTADM_DEP) + +-TGTIMG_OBJS = tgtimg.o libssc.o libcrc32c.o + TGTIMG_DEP = $(TGTIMG_OBJS:.o=.d) + +-tgtimg: $(TGTIMG_OBJS) +- $(CC) $^ -o $@ +- +--include $(TGTIMG_DEP) +- + %.o: %.c + $(CC) -c $(CFLAGS) $*.c -o $*.o + @$(CC) -MM $(CFLAGS) -MF $*.d -MT $*.o $*.c diff --git a/net/tgt/patches/030-Makefile.patch b/net/tgt/patches/030-Makefile.patch new file mode 100644 index 0000000..b2410e9 --- /dev/null +++ b/net/tgt/patches/030-Makefile.patch @@ -0,0 +1,11 @@ +--- a/Makefile 2012-06-03 02:04:54.000000000 +0300 ++++ b/Makefile 2012-06-14 03:25:42.000000000 +0300 +@@ -61,7 +61,7 @@ + $(MAKE) -C conf clean + + .PHONY: install +-install: install-programs install-doc install-conf install-scripts ++install: install-programs + + .PHONY: clean + clean: clean-programs clean-doc clean-conf clean-scripts -- Best regards, Maxim Storchak mailto:[email protected] _______________________________________________ openwrt-devel mailing list [email protected] https://lists.openwrt.org/mailman/listinfo/openwrt-devel
