debian/0000755000000000000000000000000011772433573007202 5ustar debian/README.source0000644000000000000000000000353111615420745011354 0ustar istgt (0.4~20110529-1) unstable; urgency=low Unfortunately the upstream author of istgt does not provide any location for his upstream tarballs, uscan(1) could examine to learn about new versions. All you can do is to have look to his blog [1], where he announces new versions (e.g. [2]). The tarball itself is reachable through a Wordpress plugin which does not allow browsing through releases (e.g. [3]). The announcement page also contains corresponding hash check sums. Finally please note, tarballs are not versioned, but have a timestamp in it. The version of istgt itself can be determined by having a look to `src/istgt_ver.h'. To (re-)build the source package from the subversion repository, please consider using svn-buildpackage [4], although this is not required. Do as follows: *) $ mkdir ~/tarballs *) Put whatever orig.tar.gz tarball you want to build into ~/tarballs *) $ svn checkout svn://anonscm.debian.org/svn/glibc-bsd/trunk/istgt *) svn-buildpackage This will produce source and binary packages in ~/build-area. If you want to work in a full source directory, use the following command instead: *) svn-buildpackage --svn-export This will produce a source directory in ~/build-area where you can work. If you don't want to use svn-buildpackage at all, you have to merge directories manually. For example do: *) $ tar zxfv istgt_0.4~20110529.orig.tar.gz *) $ cd istgt-20110529 *) $ svn export svn://anonscm.debian.org/svn/glibc-bsd/trunk/istgt/debian \ debian/ *) $ dpkg-buildpackage [1] http://shell.peach.ne.jp/aoyama/ [2] http://shell.peach.ne.jp/aoyama/archives/1542 [3] http://shell.peach.ne.jp/~aoyama/wordpress/download/istgt-20110717.tar.gz [4] http://packages.debian.org/search?keywords=svn-buildpackage -- Arno Töll Sun, 31 Jul 2011 13:33:15 -0400 debian/rules0000755000000000000000000000123411650601135010244 0ustar #!/usr/bin/make -f # -*- makefile -*- # Uncomment this to turn on verbose mode. export DH_VERBOSE=1 %: dh $@ override_dh_auto_configure: dh_auto_configure -- --with-configdir=/etc/istgt \ --with-logfacility=daemon \ --localstatedir=/var/run/istgt \ $(shell dpkg-buildflags --export=configure) override_dh_install: dh_install rm -f debian/istgt/etc/rc.d/istgt rmdir debian/istgt/etc/rc.d rm -f debian/istgt/usr/man/man1/istgt*.gz rmdir debian/istgt/usr/man/man1 debian/istgt/usr/man rm -f debian/istgt/etc/istgt/*.conf.sample install -m 0644 -t debian/istgt/etc/istgt debian/README.configuration override_dh_installinit: dh_installinit --no-start debian/compat0000644000000000000000000000000211615305462010367 0ustar 8 debian/docs0000644000000000000000000000000711615305462010041 0ustar README debian/init0000644000000000000000000000764211772432713010074 0ustar #! /bin/sh ### BEGIN INIT INFO # Provides: istgt # Required-Start: $network $local_fs $remote_fs # Required-Stop: $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: iSCSI userspace target for kFreeBSD systems # Description: iSCSI userspace target for kFreeBSD systems ### END INIT INFO # Author: Arno Töll PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="istgt iSCSI target" NAME=istgt DAEMON=/usr/sbin/istgt ISTGTCONTROL=/usr/sbin/istgtcontrol PIDFILE=/var/run/$NAME.pid DAEMON_ARGS="-c /etc/istgt/istgt.conf -p $PIDFILE" SCRIPTNAME=/etc/init.d/$NAME CONFIG=/etc/istgt/istgt.conf # Exit if the package is not installed [ -x $DAEMON ] || exit 0 # Read configuration variable file if it is present [ -r /etc/default/$NAME ] && . /etc/default/$NAME # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh # Define LSB log_* functions. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. . /lib/lsb/init-functions if [ ! -r $CONFIG ] ; then [ "$VERBOSE" != no ] && log_warning_msg "Not Starting $DESC: $CONFIG does not exit" exit 0 fi # # Function that starts the daemon/service # do_start() { # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ || return 1 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ $DAEMON_ARGS 2>&1 | logger -p daemon.info \ || return 2 RETVAL=0 for i in 1 2 3 4 5 ; do sleep 1 pidofproc -p $PIDFILE "$DAEMON" "$NAME" > /dev/null || RETVAL=$? [ "$RETVAL" = 0 ] && return 0 done [ "$RETVAL" != 0 ] && return 2 } # # Function that stops the daemon/service # do_stop() { # Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME RETVAL="$?" [ "$RETVAL" = 2 ] && return 2 # Wait for children to finish too if this is a daemon that forks # and if the daemon is only ever run from this initscript. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON [ "$?" = 2 ] && return 2 # Many daemons don't delete their pidfiles when they exit. rm -f $PIDFILE return "$RETVAL" } # # Function that sends a SIGHUP to the daemon/service # do_reload() { [ -x $ISTGTCONTROL ] || return 127 pidofproc -p $PIDFILE $NAME > /dev/null || return 2 $ISTGTCONTROL refresh > /dev/null 2>&1 return $? } case "$1" in start) [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME" do_start case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; stop) [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" do_stop case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; reload) [ "$VERBOSE" != no ] && log_daemon_msg "Reloading $DESC " "$NAME" do_reload case "$?" in 0) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 [ "$VERBOSE" != no ] && log_warning_msg "$NAME is not running" ;; 127) [ "$VERBOSE" != no ] && log_end_msg 1 [ "$VERBOSE" != no ] && log_warning_msg "$ISTGTCONTROL not found" ;; *) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; status) status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? ;; restart) log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; *) echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 exit 3 ;; esac : debian/patches/0000755000000000000000000000000011772433573010631 5ustar debian/patches/fix-installdir.patch0000644000000000000000000000132511633460464014577 0ustar Description: Install binaries to $PREFIX/sbin instead of $PREFIX/bin . * src/Makefile.in: Fix paths hardcoded to the install target * doc/istgt.1.in: Reflect change in resulting man page Forwarded: not-needed Author: Arno Töll --- a/src/Makefile.in +++ b/src/Makefile.in @@ -83,11 +83,11 @@ $(CC) $(LDFLAGS) $(LIBS) -o $@ $(ISTGTCONTROL) install: install-dirs - install -c -m 0755 istgt $(DESTDIR)$(bindir) - install -c -m 0755 istgtcontrol $(DESTDIR)$(bindir) + install -c -m 0755 istgt $(DESTDIR)$(sbindir) + install -c -m 0755 istgtcontrol $(DESTDIR)$(sbindir) install-dirs: - mkdir -p $(DESTDIR)$(bindir) + mkdir -p $(DESTDIR)$(sbindir) dist: $(DISTFILES) mkdir $(DISTDIR)/$(subdir) debian/patches/add-istgtcontrol-manpage0000644000000000000000000001410311652102552015425 0ustar Description: Add istgtcontrol manpage Add the manpages for the istgtcontrol.1 command. Modified files: . * doc/istgtcontrol.1.in - new file * doc/Makefile.in - change Makefile to make use of the Makefile Forwarded: Yes Author: Arno Töll Applied-Upstream: not yet Last-Update: 2010-10-07 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -19,22 +19,24 @@ source = header = -document = QUICKSTART QUICKSTART.jp istgt.1.in +document = QUICKSTART QUICKSTART.jp sample = +MANPAGES = $(patsubst %.1.in, %.1, $(wildcard *.1.in)) DISTDIR = $(top_srcdir)/`cat $(top_srcdir)/distdir` DISTFILES = Makefile.in \ $(header) $(source) \ $(document) $(sample) +DISTFILES += $(MANPAGES) ######################################################################### -all: istgt.1 +all: $(MANPAGES) -istgt.1: +$(MANPAGES): $(SED) -e 's:%%PREFIX%%:$(prefix):g' \ -e 's:%%CONFIGDIR%%:$(configdir):g' \ - -e 's:%%MEDIADIR%%:$(mediadir):g' < istgt.1.in > $@ + -e 's:%%MEDIADIR%%:$(mediadir):g' < $(patsubst %.1, %.1.in, $@) > $@ dist: $(DISTFILES) mkdir $(DISTDIR)/$(subdir) @@ -44,9 +46,13 @@ done install: install-dirs - install -c -m 0644 istgt.1 $(DESTDIR)$(mandir)/man1/ - -rm -f $(DESTDIR)$(mandir)/man1/istgt.1.gz - gzip -9 $(DESTDIR)$(mandir)/man1/istgt.1 + set -e + for file in $(MANPAGES) ; \ + do \ + install -c -m 0644 $$file $(DESTDIR)$(mandir)/man1/ ; \ + rm -f $(DESTDIR)$(mandir)/man1/$$file.gz ; \ + gzip -9 $(DESTDIR)$(mandir)/man1/$$file ; \ + done install-doc: install-doc-dirs install -c -m 0644 $(top_srcdir)/README $(DESTDIR)$(datadir)/doc/istgt/ @@ -61,7 +67,7 @@ mkdir -p $(DESTDIR)$(datadir)/doc/istgt clean: - -rm -f istgt.1 + -rm -f $(MANPAGES) -rm -f a.out *.o *.core -rm -f *~ --- /dev/null +++ b/doc/istgtcontrol.1.in @@ -0,0 +1,140 @@ +.TH istgtcontrol 1 "Oct 07, 2011" "istgtcontrol" +.SH NAME +istgtcontrol \- istgt iSCSI target command utility +.SH SYNOPSIS +.B istgtcontrol +[options] [] +.SH DESCRIPTION +\fBistgtcontrol\fP is a command and control utility for \fBistgt\fP(1). +It can be used to query and change the status of a local or remote +\fBistgt\fP instance. +.PP +\fBistgtcontrol\fP supports the commands denoted below to interact with +the \fBistgt\fP instance. By default it connects and authenticates to +the iSCSI target portal specified in the \fBistgtcontrol.conf\fP +configuration file and uses CHAP credentials denoted there, if any. +Both can be overridden by using the respecitve command line arguments. +.SH COMMANDS + +\fBistgtcontrol\fP understands the following commands which can be +forwarded to \fBistgt\fP: + +.TP +.BI "noop" +Do not actually do anything, but test responsiveness of the portal and +test CHAP credentials only. +.TP +.BI "version" +Retrieve the \fBistgt\fP version number providing the iSCSI +portal \fBistgtcontrol\fP connected to. +.TP +.BI "list" +List all, or the specified targets only, which shared by the portal. +.TP +.BI "load" +Load a new media to the specified unit. This command issues the same +command as if a drive tray had been closed on a SCSI device. + +.TP +.BI "unload" +Unload a media from the specified unit. This command issues the same +command as if the drive tray had been opened from a SCSI device. + +.TP +.BI "change" " \fIfile\fP" +Change the loaded media by the specified unit. This command is +equivalent as if a new media (for example a DVD-ROM or tape cartridge) had +been inserted in the SCSI drive. The "\fIfile\fP" argument is interpreted +as filename to be loaded. + +.TP +.BI "reset" +Reset the specified LUN of the portal. +.TP +.BI "info" +Display all connections of the portal + +.SH OPTIONS +.TP +.BI \-c " \fIconfig\fP" +Use specified file as configuration file instead of the default file. +.TP + +.BI -h " \fIhost\fP" +Override the target portal by the specified host name or IP address. This +defaults to "localhost" if no other host was specified in the +configuration file. +.TP +.BI -p " \fIport\fP" +Override the target portal port by the specified port number. This defaults +to "3261" if no other port was specified in the configuration file. +.TP +.BI -t " \fItarget\fP" +Specifies the target IQN which should be affected by the command given. +There may be a default given in the configuration file. The keyword +"\fIall\fP" is accepted by some commands and matches all exported volumes. +.TP +.BI -l " \fIlun\fP" +Specifies the target LUN which should be affected by the command given. +This defaults to "0" unless another default was provided in the configuration +file. +.TP +.BI -f " \fIflags\fP" +Specifies flags passed to the portal when loading a new media. This +defaults to "ro". Supported \fIflags\fP are: "ro", "rw", "extend" and +"dynamic". +.TP +.BI -s " \fIsize\fP" +Specifies the size of the meda to be loaded. The default is to auto-detect the +media size. +.TP +.BI -q +Quiet mode, supress non-critical outputs. +.TP +.BI -v +Verbose mode, gives more output during operations. +.TP +.BI -A " \fImethod\fP" +Sets the preferred authentication method for logging in to the portal. This +overrides any method specified in the configuration file. Supported +methods are either CHAP/Mutual or CHAP/Auto. +.TP +.BI -U " \fIuser\fP" +Sets the user to authenticate on the portal. This overrides any username +specified in the configuration file. +.TP +.BI -S " \fIsecret\fP" +Set the secret used to authenticate on the portal. This overrides any +secret specified in the configuration file. +.TP +.BI -M " \fImuser\fP" +Set the mutual authentication user. This overrides any user specified in +the configuration file. +.TP +.BI -R " \fImsecret\fP" +Set the mutual authentication secret. This overrides any secret +specified in the configuration file. +.TP +.BI -H +Display a brief usage summary and exit. +.TP +.BI -V +Display the \fBistgtcontrol\fP version number and exit. +.TP + + +.SH FILES +.PD 0 +.TP +.I %%CONFIGDIR%%/istgtcontrol.conf +Configuration file + +.PD +.SH SEE ALSO +\fBistgt\fP(1) +.PD +.SH AUTHORS +Daisuke Aoyama + +This manual page was written by Arno Töll () for the Debian +GNU/kFreeBSD system (but may be used by others). debian/patches/add-reload.patch0000644000000000000000000002731511772422007013644 0ustar Description: Add a reload target to istgt Currently istgt does not support on-the-fly reloading of its configurations, which means the administrator has to restart the daemon to make new settings in effect. . This is quite inconvenient when istgt is used in conjection with some "sensitive" initiators, for instance, Xen. . This patch which implements the underlying functionality was written by Kun Huang, sponsored by Applied Operations, LLC. . It was taken from the FreeBSD patch tracking sustem. Author: Andrew Ruthven Origin: other, http://www.freebsd.org/cgi/query-pr.cgi?pr=165844 Forwarded: no Last-Update: 2012-06-26 --- a/src/istgt_lu.h +++ b/src/istgt_lu.h @@ -236,6 +236,9 @@ ISTGT_LU_TSIH tsih[MAX_LU_TSIH]; int maxmap; ISTGT_LU_MAP map[MAX_LU_MAP]; + + int to_add; + int to_remove; } ISTGT_LU; typedef ISTGT_LU *ISTGT_LU_Ptr; --- a/src/istgt_proto.h +++ b/src/istgt_proto.h @@ -85,10 +85,10 @@ uint64_t istgt_lu_parse_media_size(const char *file, const char *size, int *flags); PORTAL *istgt_lu_find_portalgroup(ISTGT_Ptr istgt, int tag); INITIATOR_GROUP *istgt_lu_find_initiatorgroup(ISTGT_Ptr istgt, int tag); -int istgt_lu_init(ISTGT_Ptr istgt); +int istgt_lu_init(ISTGT_Ptr istgt, int ignore_dup); int istgt_lu_set_all_state(ISTGT_Ptr istgt, ISTGT_STATE state); -int istgt_lu_create_threads(ISTGT_Ptr istgt); -int istgt_lu_shutdown(ISTGT_Ptr istgt); +int istgt_lu_create_threads(ISTGT_Ptr istgt, int new_only); +int istgt_lu_shutdown(ISTGT_Ptr istgt, int removed_only); int istgt_lu_islun2lun(uint64_t islun); uint64_t istgt_lu_lun2islun(int lun, int maxlun); int istgt_lu_reset(ISTGT_LU_Ptr lu, uint64_t lun); --- a/src/istgt_lu_disk.c +++ b/src/istgt_lu_disk.c @@ -794,6 +794,7 @@ xfree(spec); lu->lun[i].spec = NULL; } + lu->maxlun = 0; return 0; } --- a/src/istgt_lu_ctl.c +++ b/src/istgt_lu_ctl.c @@ -965,6 +965,113 @@ return UCTL_CMD_OK; } +extern const char *g_config_file; +extern ISTGT g_istgt; + +static int +istgt_uctl_cmd_refresh(UCTL_Ptr uctl) +{ + char *arg; + int rc, i, j; + CONFIG *config; + ISTGT_Ptr istgt; + + arg = uctl->arg; + istgt = &g_istgt; + + /* reload config, might add/remove LUNs */ + /* step 1: re-read config files */ + config = istgt_allocate_config(); + rc = istgt_read_config(config, g_config_file); + if (rc < 0) { + fprintf(stderr, "refresh config error\n"); + return UCTL_CMD_ERR; + } + if (config->section == NULL) { + fprintf(stderr, "empty config\n"); + istgt_free_config(config); + return UCTL_CMD_ERR; + } + istgt_free_config(istgt->config); + istgt->config = config; + + /* step 2: add new units, init new LUNs, tag to-add/remove LUNs */ + rc = istgt_lu_init(istgt, 1); + if (rc < 0) { + ISTGT_ERRLOG("istgt_lu_init() failed\n"); + istgt_free_config(config); + return UCTL_CMD_ERR; + } + + for (i = 0; i < MAX_LOGICAL_UNIT; i++) { + ISTGT_LU_Ptr lu = istgt->logical_unit[i]; + if (lu == NULL) + continue; + if (lu->to_add) + ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "newly added LUN %s\n", lu->name); + if (lu->to_remove) + ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "newly removed LUN %s\n", lu->name); + } + + /* creat new threads for new LUNs, do work in luworker() */ + /* create LUN threads for command queuing */ + rc = istgt_lu_create_threads(istgt, 1); + if (rc < 0) { + ISTGT_ERRLOG("lu_create_threads() failed\n"); + istgt_free_config(config); + return UCTL_CMD_ERR; + } + /* start taking IOs */ + for (i = 0; i < MAX_LOGICAL_UNIT; i++) { + ISTGT_LU_Ptr lu = istgt->logical_unit[i]; + if (lu == NULL) + continue; + if (lu->to_add) { + istgt_lu_set_state(lu, ISTGT_STATE_RUNNING); + ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "set newly added LUN as running %s\n", lu->name); + } + } + + /* step 3: shutdown removed LUNs */ + /* clear outstanding IOs */ + for (i = 0; i < MAX_LOGICAL_UNIT; i++) { + ISTGT_LU_Ptr lu = istgt->logical_unit[i]; + if (lu == NULL) + continue; + if (lu->to_remove) { + for (j = 0; jmaxlun; j++) + istgt_lu_clear_all_task(lu, j); + ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "clear newly removed LUN queue %s\n", lu +->name); + } + } + + /* sync and close LUNs */ + istgt_lu_shutdown(istgt, 1); + + /* clear tag of to_add/to_remove, get ready for next refresh */ + for (i = 0; i < MAX_LOGICAL_UNIT; i++) { + ISTGT_LU_Ptr lu = istgt->logical_unit[i]; + if (lu == NULL) + continue; + if (lu->to_add) + lu->to_add = 0; + if (lu->to_remove) + lu->to_remove = 0; + } + + /* logging event */ + ISTGT_NOTICELOG("Configuration refresh requested from %s\n", + uctl->caddr); + + /* refresh succeeded */ + istgt_uctl_snprintf(uctl, "OK %s\n", uctl->cmd); + rc = istgt_uctl_writeline(uctl); + if (rc != UCTL_CMD_OK) + return rc; + return UCTL_CMD_OK; +} + static int istgt_uctl_cmd_reset(UCTL_Ptr uctl) { @@ -1183,6 +1290,7 @@ { "UNLOAD", istgt_uctl_cmd_unload }, { "LOAD", istgt_uctl_cmd_load }, { "CHANGE", istgt_uctl_cmd_change }, + { "REFRESH", istgt_uctl_cmd_refresh }, { "RESET", istgt_uctl_cmd_reset }, { "INFO", istgt_uctl_cmd_info }, { NULL, NULL }, --- a/src/istgtcontrol.c +++ b/src/istgtcontrol.c @@ -494,6 +494,36 @@ } static int +exec_refresh(UCTL_Ptr uctl) +{ + const char *delim = ARGS_DELIM; + char *arg; + char *result; + int rc; + + /* send command */ + uctl_snprintf(uctl, "REFRESH \n"); + rc = uctl_writeline(uctl); + if (rc != UCTL_CMD_OK) + return rc; + + /* receive result */ + rc = uctl_readline(uctl); + if (rc != UCTL_CMD_OK) + return rc; + arg = trim_string(uctl->recvbuf); + result = strsepq(&arg, delim); + strupr(result); + if (strcmp(result, "OK") != 0) { + if (is_err_req_auth(uctl, arg)) + return UCTL_CMD_REQAUTH; + fprintf(stderr, "ERROR %s\n", arg); + return UCTL_CMD_ERR; + } + return UCTL_CMD_OK; +} + +static int exec_reset(UCTL_Ptr uctl) { const char *delim = ARGS_DELIM; @@ -591,6 +621,7 @@ { "UNLOAD", exec_unload, 0, 1 }, { "LOAD", exec_load, 0, 1 }, { "CHANGE", exec_change, 1, 1 }, + { "REFRESH", exec_refresh, 0, 0 }, { "RESET", exec_reset, 0, 1 }, { "INFO", exec_info, 0, 0 }, { NULL, NULL, 0, 0 }, @@ -1054,6 +1085,7 @@ printf(" load load media to specified unit\n"); printf(" unload unload media from specified unit\n"); printf(" change change media with at specified unit\n"); + printf(" refresh refresh to reload target and lun configuration\n"); printf(" reset reset specified lun of target\n"); printf(" info show connections of target\n"); } --- a/src/istgt_lu.c +++ b/src/istgt_lu.c @@ -1200,7 +1200,7 @@ } static int -istgt_lu_add_unit(ISTGT_Ptr istgt, CF_SECTION *sp) +istgt_lu_add_unit(ISTGT_Ptr istgt, CF_SECTION *sp, int ignore_dup) { char buf[MAX_TMPBUF], buf2[MAX_TMPBUF]; ISTGT_LU_Ptr lu; @@ -1220,21 +1220,40 @@ int i, j, k; int rc; - ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "add unit %d\n", sp->num); + ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "add unit %d (ignore dup = %d)\n", sp->num, ignore_dup); if (sp->num >= MAX_LOGICAL_UNIT) { ISTGT_ERRLOG("LU%d: over maximum unit number\n", sp->num); return -1; } - if (istgt->logical_unit[sp->num] != NULL) { + if (istgt->logical_unit[sp->num] != NULL && !ignore_dup) { ISTGT_ERRLOG("LU%d: duplicate unit\n", sp->num); return -1; } + /* existing LUNs */ + if (istgt->logical_unit[sp->num] != NULL && ignore_dup) { + istgt->logical_unit[sp->num]->to_add = 0; + istgt->logical_unit[sp->num]->to_remove = 0; + ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "skip existing unit %d\n", sp->num); + return 0; + } + + /* new LUNs */ + if (istgt->logical_unit[sp->num] == NULL && ignore_dup) { + ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "add NEW unit %d\n", sp->num); + } lu = xmalloc(sizeof *lu); memset(lu, 0, sizeof *lu); lu->num = sp->num; lu->istgt = istgt; + + /* tag new LUNs */ + if (ignore_dup) { + lu->to_add = 1; + lu->to_remove = 0; + } + istgt_lu_set_state(lu, ISTGT_STATE_INVALID); nbs64 = istgt_lu_get_nbserial(istgt->nodebase); #if 0 @@ -1942,12 +1961,15 @@ static void *luworker(void *arg); int -istgt_lu_init(ISTGT_Ptr istgt) +istgt_lu_init(ISTGT_Ptr istgt, int ignore_dup) { ISTGT_LU_Ptr lu; CF_SECTION *sp; int rc; int i; + int lun_map[MAX_LOGICAL_UNIT]; + + memset(lun_map, 0, sizeof(int) * MAX_LOGICAL_UNIT); ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "istgt_lu_init\n"); sp = istgt_find_cf_section(istgt->config, "Global"); @@ -1967,11 +1989,12 @@ ISTGT_ERRLOG("tag %d is invalid\n", sp->num); return -1; } - rc = istgt_lu_add_unit(istgt, sp); + rc = istgt_lu_add_unit(istgt, sp, ignore_dup); if (rc < 0) { ISTGT_ERRLOG("lu_add_unit() failed\n"); return -1; } + lun_map[sp->num] = 1; /* in new LUN list */ } sp = sp->next; } @@ -1980,6 +2003,22 @@ lu = istgt->logical_unit[i]; if (lu == NULL) continue; + /* tag to be removed LUNs */ + if (lun_map[i] == 0) { + istgt->logical_unit[i]->to_add = 0; + istgt->logical_unit[i]->to_remove = 1; + continue; + } + /* only process newly added LUNs here beyond in loop */ + if (ignore_dup && + (istgt->logical_unit[i]->to_add == 1 && + istgt->logical_unit[i]->to_remove == 0)) { + ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "adding unit %d\n", i); + } else if (ignore_dup && + !(istgt->logical_unit[i]->to_add == 1 && + istgt->logical_unit[i]->to_remove == 0)) { + continue; + } rc = pthread_mutex_init(&lu->mutex, NULL); if (rc != 0) { @@ -2067,7 +2106,7 @@ } int -istgt_lu_create_threads(ISTGT_Ptr istgt) +istgt_lu_create_threads(ISTGT_Ptr istgt, int new_only) { #ifdef HAVE_PTHREAD_SET_NAME_NP char buf[MAX_TMPBUF]; @@ -2082,6 +2121,10 @@ lu = istgt->logical_unit[i]; if (lu == NULL) continue; + if (new_only && !lu->to_add) { + ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "skip existing LUN %d\n", i); + continue; + } if (lu->queue_depth != 0) { /* create LU thread */ @@ -2112,18 +2155,22 @@ } int -istgt_lu_shutdown(ISTGT_Ptr istgt) +istgt_lu_shutdown(ISTGT_Ptr istgt, int removed_only) { ISTGT_LU_Ptr lu; int rc; int i; - ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "istgt_lu_shutdown\n"); + ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "istgt_lu_shutdown (removed_only = %d\n", removed_only); for (i = 0; i < MAX_LOGICAL_UNIT; i++) { lu = istgt->logical_unit[i]; if (lu == NULL) continue; + if (removed_only && !lu->to_remove) { + ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "skip existing LUNs %d\n", i); + continue; + } istgt_lu_set_state(lu, ISTGT_STATE_SHUTDOWN); switch (lu->type) { --- a/src/istgt.c +++ b/src/istgt.c @@ -71,6 +71,7 @@ #define PORTNUMLEN 32 ISTGT g_istgt; +const char *g_config_file; #if 0 void @@ -1598,6 +1599,7 @@ /* read config files */ config = istgt_allocate_config(); + g_config_file = config_file; rc = istgt_read_config(config, config_file); if (rc < 0) { fprintf(stderr, "config error\n"); @@ -1662,7 +1664,7 @@ istgt_free_config(config); exit(EXIT_FAILURE); } - rc = istgt_lu_init(istgt); + rc = istgt_lu_init(istgt, 0); if (rc < 0) { ISTGT_ERRLOG("istgt_lu_init() failed\n"); goto initialize_error; @@ -1772,7 +1774,7 @@ #endif /* create LUN threads for command queuing */ - rc = istgt_lu_create_threads(istgt); + rc = istgt_lu_create_threads(istgt, 0); if (rc < 0) { ISTGT_ERRLOG("lu_create_threads() failed\n"); goto initialize_error; @@ -1809,7 +1811,7 @@ istgt_close_portal(istgt); istgt_close_uctl_portal(istgt); istgt_iscsi_shutdown(istgt); - istgt_lu_shutdown(istgt); + istgt_lu_shutdown(istgt, 0); istgt_destory_initiator_group_array(istgt); istgt_destroy_portal_array(istgt); istgt_destroy_uctl_portal(istgt); @@ -1837,7 +1839,7 @@ istgt_close_portal(istgt); istgt_close_uctl_portal(istgt); istgt_iscsi_shutdown(istgt); - istgt_lu_shutdown(istgt); + istgt_lu_shutdown(istgt, 0); istgt_destory_initiator_group_array(istgt); istgt_destroy_portal_array(istgt); istgt_destroy_uctl_portal(istgt); debian/patches/fix-autosize.patch0000644000000000000000000000256611772423733014307 0ustar Description: support symlinks as device names This patch adds support for symlinks as device store in the backend. . This patch was rejected upstream. Upstream was worried about security implications when following symlinks to logical devices. This is an opinion I do not share, as I consider existing file permission layers as sufficient. . Neither do several people asked for advise. . -- Arno Töll Author: Michal Suchanek Forwarded: yes Index: istgt-0.4~20111008/src/istgt_lu.c =================================================================== --- istgt-0.4~20111008.orig/src/istgt_lu.c 2011-11-27 21:48:45.000000000 +0100 +++ istgt-0.4~20111008/src/istgt_lu.c 2011-11-27 22:14:12.000000000 +0100 @@ -606,7 +606,7 @@ int rc; val = 0ULL; - rc = lstat(file, &st); + rc = stat(file, &st); if (rc != 0) return val; if (!S_ISCHR(st.st_mode) && !S_ISBLK(st.st_mode)) @@ -689,11 +689,9 @@ int rc; val = 0ULL; - rc = lstat(file, &st); + rc = stat(file, &st); if (rc < 0) return val; - if (S_ISLNK(st.st_mode)) - return val; if (S_ISCHR(st.st_mode)) { val = istgt_lu_get_devsize(file); @@ -702,7 +700,7 @@ } else if (S_ISREG(st.st_mode)) { val = st.st_size; } else { - ISTGT_ERRLOG("lstat is neither REG, CHR nor BLK\n"); + ISTGT_ERRLOG("stat is neither REG, CHR nor BLK\n"); val = 0ULL; } return val; debian/patches/fix-as-needed-build.patch0000644000000000000000000000121111665477037015357 0ustar Description: fix build with ld --as-needed With the linker flag --as-needed libraries must be placed behind objects needing their symbols on the commandline. Author: Julian Taylor Forwarded: yes --- a/src/Makefile.in +++ b/src/Makefile.in @@ -77,10 +77,10 @@ all: stamp-depend config.h istgt istgtcontrol istgt: $(ISTGT) - $(CC) $(LDFLAGS) $(LIBS) -o $@ $(ISTGT) + $(CC) $(LDFLAGS) -o $@ $(ISTGT) $(LIBS) istgtcontrol: $(ISTGTCONTROL) - $(CC) $(LDFLAGS) $(LIBS) -o $@ $(ISTGTCONTROL) + $(CC) $(LDFLAGS) -o $@ $(ISTGTCONTROL) $(LIBS) install: install-dirs install -c -m 0755 istgt $(DESTDIR)$(sbindir) debian/patches/series0000644000000000000000000000015411772421752012042 0ustar fix-installdir.patch add-istgtcontrol-manpage fix-as-needed-build.patch fix-autosize.patch add-reload.patch debian/watch0000644000000000000000000000022611615421130010211 0ustar version=3 # Sorry, upstream does not provide any browsable location for tarballs. # Have a look to README.source to learn how to fetch new versions debian/manpages0000644000000000000000000000003711650601135010702 0ustar doc/istgt.1 doc/istgtcontrol.1 debian/examples0000644000000000000000000000001311615361513010723 0ustar etc/*.conf debian/copyright0000644000000000000000000000336511615421723011132 0ustar Format: http://anonscm.debian.org/viewvc/dep/web/deps/dep5.mdwn?revision=174 Upstream-Name: istgt Upstream-Contact: Daisuke Aoyama Source: http://www.peach.ne.jp/archives/istgt/ Files: debian/* Copyright: 2011 Arno Toell License: BSD-2-clause Comment: Packaging for Debian was done by Arno Töll, and I hereby grant distribution of it under the same terms as istgt itself. Files: * Copyright: Copyright (C) 2008-2011 Daisuke Aoyama License: BSD-2-clause License: BSD-2-clause All rights reserved. . Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. debian/source/0000755000000000000000000000000011772433573010502 5ustar debian/source/format0000644000000000000000000000001411615305462011677 0ustar 3.0 (quilt) debian/control0000644000000000000000000000202411770661506010600 0ustar Source: istgt Section: admin Priority: extra Maintainer: GNU/kFreeBSD Maintainers Uploaders: Arno Töll , Robert Millan Build-Depends: debhelper (>= 8.0), autotools-dev, libssl-dev, libcam-dev [kfreebsd-any], dpkg-dev (>= 1.16.1~) Standards-Version: 3.9.3.1 Homepage: http://www.peach.ne.jp/archives/istgt/ Vcs-Svn: svn://svn.debian.org/svn/glibc-bsd/trunk/istgt Vcs-Browser: https://alioth.debian.org/scm/viewvc.php/trunk/istgt/?root=glibc-bsd Package: istgt Architecture: any Depends: lsb-base (>= 3.0-6), ${shlibs:Depends}, ${misc:Depends} Description: iSCSI userspace target daemon for Unix-like operating systems istgt is a iSCSI target for Unix-like operating systems (including those with Linux and kFreeBSD kernels) running as daemon process in user space. . It supports: . * Multipath I/O * 64bit LBA for volumes over 2 TiB size * Header/Data digest by CRC32C * Mutual authentication with CHAP * Multiple LUNs and ACLs for portals * IPv6/IPv4 support debian/changelog0000644000000000000000000000641511772433275011061 0ustar istgt (0.4~20111008-3) unstable; urgency=low * Fix "cannot determine device size from symlink" Apply patch to use stat() instead of lstat(). Thanks Michal Suchanek (Closes: #650212). I apologize for the delay, but I was postponing this decision for a long time, given it was rejected by upstream for security concerns. I do not share these. * Fix "Add support to reload the istgt.conf file." by merging the excellent patch Andrew Ruthven . Much appreciated (Closes: #679055) * Improve init script: + Better support fancy outputs + Improve failure toleance of the reload handler + Log istgt start output to syslog -- Arno Töll Wed, 27 Jun 2012 00:23:23 +0200 istgt (0.4~20111008-2) unstable; urgency=low * Fix "istgt: ftbs with ld --as-needed" - apply patch which shifts libraries in the compiler line after object files. Thanks Julian Taylor (Closes: #646272) * Fix "ftbfs on squeeze" Add missing build-dependency to dpkg-dev 1.16.1 which is required to build the package because we're using dpkg-buildflags to generate configure flags. That's guaranteed for Testing, but might be helpful to know for backporters. (Closes: #650217) * Push standards version to 3.9.3.1 - no further changes required * Drop the DMUA field - I don't need it anymore, update my maintainer address -- Arno Töll Sat, 31 Mar 2012 17:13:43 +0200 istgt (0.4~20111008-1) unstable; urgency=low * New upstream release * Add patch `add-istgtcontrol-manpage' which adds a manpage for the istgtcontrol command. * Check whether istgt is actually running after starting up the daemon in its init script. That's required because istgt may fail for the socket setup after forking into the background. -- Arno Töll Thu, 27 Oct 2011 01:40:23 +0200 istgt (0.4~20110928-1) unstable; urgency=low * New upstream release * Adapt to dpkg 1.16.1 API changes regarding build flags. This enables hardening build flags. This means, istgt is now being built with -fstack-protector and other security related build flags. -- Arno Töll Fri, 07 Oct 2011 10:54:47 -0400 istgt (0.4~20110907-1) unstable; urgency=low * New upstream release * Make debian/copyright more readable * Provide a non-functional watch file to follow glibc-bsd conventions to denote the problem with it in a comment * Fix a not detected build failure due to a problem in upstream's Makefile for the GNU/Hurd architecture (`make-build-failures-fatal.patch'). This patch has been forwarded and merged upstream * Remove `handle-destdir.patch' - it has been merged upstream * Refresh `fix-installdir.patch' -- Arno Töll Wed, 14 Sep 2011 22:40:25 +0200 istgt (0.4~20110717-1) unstable; urgency=low [ Arno Töll ] * Make upstream Makefile honor $(DESTDIR) (`handle-destdir.patch') * Install binaries to /sbin instead of /bin (`fix-installdir.patch') * Initial release. (Closes: #636139: ITP: istgt -- iSCSI userspace target daemon for Unix-like operating systems) [ Robert Millan ] * Require libcam-dev on kfreebsd-any. * Set Dm-Upload-Allowed: yes. * Add myself to Uploaders. -- Robert Millan Mon, 01 Aug 2011 00:12:35 +0200 debian/README.configuration0000644000000000000000000000032211615362650012716 0ustar istgt (0.4~20110717-1) unstable; urgency=low Please have a look to `/usr/share/doc/istgt/examples/' for examples how to configure istgt. -- Arno Töll Sun, 31 Jul 2011 19:23:09 -0400