Module Name: src
Committed By: sborrill
Date: Wed May 30 08:06:26 UTC 2012
Modified Files:
src/etc [netbsd-6]: MAKEDEV.tmpl
src/sbin/iscsictl [netbsd-6]: iscsictl.8
src/sbin/iscsid [netbsd-6]: Makefile iscsid.8 iscsid.h
iscsid_driverif.c iscsid_globals.h iscsid_lists.c iscsid_main.c
iscsid_targets.c
src/sys/dev/iscsi [netbsd-6]: iscsi_main.c
Log Message:
Pull up the following revisions(s) (requested by riz in ticket #291):
etc/MAKEDEV.tmpl: revision 1.155
sbin/iscsictl/iscsictl.8: revision 1.2-1.4
sbin/iscsid/iscsid_driverif.c: revision 1.4-1.5
sbin/iscsid/iscsid_lists.c: revision 1.4-1.7
sbin/iscsid/iscsid_targets.c: revision 1.4
sbin/iscsid/iscsid_globals.h: revision 1.5-1.7
sbin/iscsid/iscsid_main.c: revision 1.4-1.7
sbin/iscsid/Makefile: revision 1.2-1.4
sbin/iscsid/iscsid.8: revision 1.3-1.8
sbin/iscsid/iscsid.h: revision 1.3
sys/dev/iscsi/iscsi_main.c: revision 1.2-1.3
Fix bugs in iscsid target list handling, and improve documentation
somewhat for the in-kernel iSCSI initiator.
To generate a diff of this commit:
cvs rdiff -u -r1.151.2.1 -r1.151.2.2 src/etc/MAKEDEV.tmpl
cvs rdiff -u -r1.1 -r1.1.4.1 src/sbin/iscsictl/iscsictl.8
cvs rdiff -u -r1.1 -r1.1.4.1 src/sbin/iscsid/Makefile
cvs rdiff -u -r1.2 -r1.2.2.1 src/sbin/iscsid/iscsid.8
cvs rdiff -u -r1.2 -r1.2.4.1 src/sbin/iscsid/iscsid.h
cvs rdiff -u -r1.3 -r1.3.2.1 src/sbin/iscsid/iscsid_driverif.c \
src/sbin/iscsid/iscsid_lists.c src/sbin/iscsid/iscsid_main.c \
src/sbin/iscsid/iscsid_targets.c
cvs rdiff -u -r1.4 -r1.4.2.1 src/sbin/iscsid/iscsid_globals.h
cvs rdiff -u -r1.1 -r1.1.8.1 src/sys/dev/iscsi/iscsi_main.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/etc/MAKEDEV.tmpl
diff -u src/etc/MAKEDEV.tmpl:1.151.2.1 src/etc/MAKEDEV.tmpl:1.151.2.2
--- src/etc/MAKEDEV.tmpl:1.151.2.1 Sat Feb 25 14:48:12 2012
+++ src/etc/MAKEDEV.tmpl Wed May 30 08:06:26 2012
@@ -1,5 +1,5 @@
#!/bin/sh -
-# $NetBSD: MAKEDEV.tmpl,v 1.151.2.1 2012/02/25 14:48:12 sborrill Exp $
+# $NetBSD: MAKEDEV.tmpl,v 1.151.2.2 2012/05/30 08:06:26 sborrill Exp $
#
# Copyright (c) 2003,2007,2008 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -810,6 +810,7 @@ all)
makedev md0 md1
makedev raid0 raid1 raid2 raid3 raid4 raid5 raid6 raid7
makedev vnd0 vnd1 vnd2 vnd3
+ makedev iscsi0
makedev bpf npf
makedev tun0 tun1 tun2 tun3
makedev ipl pf crypto random
Index: src/sbin/iscsictl/iscsictl.8
diff -u src/sbin/iscsictl/iscsictl.8:1.1 src/sbin/iscsictl/iscsictl.8:1.1.4.1
--- src/sbin/iscsictl/iscsictl.8:1.1 Sun Oct 23 21:11:23 2011
+++ src/sbin/iscsictl/iscsictl.8 Wed May 30 08:06:26 2012
@@ -1,4 +1,4 @@
-.\" $NetBSD: iscsictl.8,v 1.1 2011/10/23 21:11:23 agc Exp $
+.\" $NetBSD: iscsictl.8,v 1.1.4.1 2012/05/30 08:06:26 sborrill Exp $
.\"
.\" Copyright (c) 2011 Alistair Crooks <[email protected]>
.\" All rights reserved.
@@ -23,7 +23,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd August 8, 2011
+.Dd May 26, 2012
.Dt ISCSICTL 8
.Os
.Sh NAME
@@ -31,8 +31,7 @@
.Nd program to manage iSCSI instances
.Sh SYNOPSIS
.Nm
-.Op Fl v
-.Op Fl d Ar directory
+.Op Fl d Ar sockdir
.Ar command
.Op Ar arguments ...
.Sh DESCRIPTION
@@ -75,20 +74,112 @@ command is used; this creates a session
The sessions can be listed by using the
.Dv list_sessions
command.
-.Pp
+.Ss Global Options
+.Bl -tag width xdxsockdirx
+.It Fl d Ar sockdir
+Specify the directory where the socket for
+.Xr iscsid 8
+lives.
+.El
+.Ss Target Address Specification
+The target address specification for the
+.Ic add_target
+and
+.Ic add_send_target
+commands may include a target name, target address (IP or FQDN),
+TCP port, and group tag.
+Either the target address or target name is required.
+(For add_send_target, a target address is required).
+The address, port, and group tag may optionally be repeated.
+.Bl -tag -width xaxtarget-addressx
+.It Fl a Ar target-address
+Specify the target address by IP or FQDN.
+.It Fl n Ar target-name
+Specify the target by name.
+.It Fl p Ar port-num
+The TCP port to connect to the target on.
+(Default port is 3260)
+.It Fl g Ar group-tag
+The group tag, a 16-bit integer.
+.El
+.Ss Portal Address Specification
+The portal address specification for the
+.Ic add_portal
+command may include an address (IP or FQDN), port, and group tag, plus
+portal options.
+.Bl -tag -width xaxtarget-addressx
+.It Fl a Ar target-address
+Specify the target address by IP or FQDN.
+.It Fl p Ar port-num
+The TCP port to connect to the target on.
+(Default port is 3260)
+.It Fl g Ar group-tag
+The group tag, a 16-bit integer.
+.It Fl h
+Use a CRC32 header digest.
+.It Fl d
+Use a CRC32 data digest.
+.It Fl l Ar segment-length
+Specify the max received data segment length.
+.El
+.Ss Target Options
+Target options are as follows:
+.Bl -tag -width xlxsegment-lengthx
+.It Fl h
+Use a CRC32 header digest.
+.It Fl d
+Use a CRC32 data digest.
+.It Fl w Ar time
+Time to wait.
+.It Fl r Ar time
+Time to retain.
+.It Fl e Ar level
+Error recovery level.
+.It Fl l Ar segment-length
+Specify the max received data segment length.
+.El
+.Ss Authentication Options
+Authentication options are as follows:
+.Bl -tag width 5n
+.It Fl t Ar type
+Specify authentication type.
+.Ar n
+indicates no authentication, while
+.Ar c
+indicates CHAP authentication, and
+.Ar C
+indicates Mutual CHAP authentication.
+.It Fl u Ar name
+User name.
+.It Fl s Ar secret
+Initiator secret.
+.It Fl S Ar secret
+Target secret.
+.El
+.Ss Nm Commands
The
.Nm
command argument is taken from one of the following options:
-.Bl -tag -width XCXremove_send_targetXX
-.It version
-return the version number of the
-.Nm
-utility
-.It add_target
-.It add_portal
-.It remove_target
-.It slp_find_targets
-.It refresh_targets
+.Bl -tag -width 5n
+.It Cm version
+return version information from the
+.Nm
+utility and the
+.Xr iscsid 8
+daemon.
+.It Cm add_target Ar target-address-spec Oo Ar target-opts Oc Oo Ar auth-opts Oc Oo Fl N Ar symbolic-name Oc
+A
+.Ar target-address-spec
+may include name, address, port, and group tag, with address/port/tag
+possibly repeated.
+.It Cm add_portal Ar portal-address-spec Oo Fl I target-id Oc Oo Fl N symbolic-name Oc
+Add a portal to the list of portals.
+.It Cm remove_target Fl I Ar target-id
+.It Cm remove_target Fl n Ar target-name
+Remove a target by name or ID.
+.It Cm slp_find_targets
+Not implemented.
+.It Cm refresh_targets Op Fl I Ar target-id
this command causes the iSCSI initiator to refresh its view of the
iSCSI targets to which it is connected.
If this command completes successfully, an
@@ -96,8 +187,9 @@ If this command completes successfully,
value is printed.
For more context on the exact usage of this
command, please see the example below.
-.It list_targets
-.It add_send_target
+.It Cm list_targets
+Display a list of targets the iSCSI initiator knows about.
+.It Cm add_send_target Fl a Ar target-address Oo Ar target-address-spec Oc Oo Ar target-opts Oc Oo Ar auth-opts Oc Oo Fl N Ar symbolic-name Oc
this command allows the iSCSI initiator to connect to an iSCSI
target.
The subsequent
@@ -107,14 +199,22 @@ This can be provided as a numerical IP a
or as a textual FQDN.
For more context on the exact usage of this
command, please see the example below.
-.It remove_send_target
-.It list_send_targets
-.It add_isns_server
-.It remove_isns_server
-.It find_isns_servers
-.It list_isns_servers
-.It refresh_isns
-.It login
+.It Cm remove_send_target Fl I Ar target-id
+.It Cm remove_send_target Fl n Ar target-name
+Remove a send target from the list by name or
+.Ar target-id
+.It Cm list_send_targets
+Display the list of send targets configured.
+.It Cm add_isns_server Ar iSNS-address-spec
+Add an iSNS server using an address specification that may include name,
+address, and port.
+.It Cm remove_isns_server Fl I Ar isns-server-id
+.It Cm remove_isns_server Fl a Ar isns-server-address
+.It Cm find_isns_servers
+Not Implemented.
+.It Cm list_isns_servers
+.It Cm refresh_isns Op Fl I Ar id
+.It Cm login Oo Fl m Oc Oo Ar target-opts Oc Oo Ar auth-opts Oc Oo Fl P Ar portal-id Oc
To be able to communicate with the iSCSI target, the initiator
must login.
This command allows this login to take place.
@@ -127,30 +227,42 @@ session which has been created will be d
number.
For more context on the exact usage of this
command, please see the example below.
-.It logout
-.It add_connection
-.It remove_connection
-.It inquiry
-.It read_capacity
-.It report_luns
-.It test_unit_ready
-.It add_initiator
-.It remove_initiator
-.It list_initiators
-.It list_sessions
+.It Cm logout Op Fl I Ar session-id
+.It Cm add_connection Oo Fl m Oc Oo Ar target-opts Oc Oo Ar auth-opts Oc Oo Fl P Ar portal-id Oc
+.It Cm remove_connection Fl I Ar session-id Fl C Ar connection-id
+.It Cm inquiry Oo Fl l Ar lun Oc Oo Fl d Ar detail Oc Oo Fl p Ar pag Oc
+.It Cm read_capacity Op Fl I Ar session-id Op Fl l Ar lun
+.It Cm report_luns Op Fl I Ar session-id
+.It Cm test_unit_ready Op Fl I Ar session-id
+.It Cm add_initiator Fl a Ar interface-address Op Fl N Ar symbolic-name
+.It Cm remove_initiator Fl I Ar portal-id
+.It Cm list_initiators
+.It Cm list_sessions Op Fl c
Once login to the target has taken place, a session will have been created.
To list the session information, this command is used.
The session number and target information for each of the targets are displayed.
+If the
+.Fl c
+flag is used, connection information is displayed as well.
For more context on the exact usage of this
command, please see the example below.
-.It set_node_name
+.It Cm set_node_name Fl n Ar initiator-name Oo Fl A alias Oc Oo Fl i Ar isid Oc
+Set the initiator name.
+The default initiator name is
+iqn.1994-04.org.netbsd:iscsi.<hostname>:<hostid> .
+An
+.Ar alias
+can be specified as well as an
+.Ar isid
.El
.Sh EXAMPLES
.Nm
is intended to be used as follows:
.Pp
The initiator itself can be loaded as a kernel module, and works successfully
-on 2.0 (the host called "burner"), running against the NetBSD target on a 5.99 host.
+on 2.0 (the host called "burner"), running against the
+.Nx
+target on a 5.99 host.
.Pp
.Bd -literal
burner# modload -v -s -p /usr/lkm/iscsi_post.sh /usr/lkm/iscsidrv.o
Index: src/sbin/iscsid/Makefile
diff -u src/sbin/iscsid/Makefile:1.1 src/sbin/iscsid/Makefile:1.1.4.1
--- src/sbin/iscsid/Makefile:1.1 Sun Oct 23 21:11:23 2011
+++ src/sbin/iscsid/Makefile Wed May 30 08:06:26 2012
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2011/10/23 21:11:23 agc Exp $
+# $NetBSD: Makefile,v 1.1.4.1 2012/05/30 08:06:26 sborrill Exp $
PROG= iscsid
@@ -13,8 +13,6 @@ MAN= iscsid.8
WARNS= 4
-# CPPFLAGS+= -DISCSI_DEBUG
-
LDADD = -lpthread -lisns
INCSDIR= /usr/include
Index: src/sbin/iscsid/iscsid.8
diff -u src/sbin/iscsid/iscsid.8:1.2 src/sbin/iscsid/iscsid.8:1.2.2.1
--- src/sbin/iscsid/iscsid.8:1.2 Mon Nov 21 08:23:20 2011
+++ src/sbin/iscsid/iscsid.8 Wed May 30 08:06:26 2012
@@ -1,4 +1,4 @@
-.\" $NetBSD: iscsid.8,v 1.2 2011/11/21 08:23:20 njoly Exp $
+.\" $NetBSD: iscsid.8,v 1.2.2.1 2012/05/30 08:06:26 sborrill Exp $
.\"
.\" Copyright (c) 2011 Alistair Crooks <[email protected]>
.\" All rights reserved.
@@ -23,7 +23,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd August 8, 2011
+.Dd May 27, 2012
.Dt ISCSID 8
.Os
.Sh NAME
@@ -31,6 +31,8 @@
.Nd interface to kernel iSCSI driver
.Sh SYNOPSIS
.Nm
+.Op Fl n
+.Op Fl d Ar lvl
.Sh DESCRIPTION
The iSCSI initiator runs as a kernel driver, and provides access
to iSCSI targets running across a network using the iSCSI protocol,
@@ -56,8 +58,16 @@ exits on receiving a terminate message,
(no response to one that is sent to the kernel),
or when an error occurs reading from or writing to the socket.
.Pp
-There are no command line arguments to
-.Nm .
+The
+.Fl d
+flag increases the debug level to
+.Ar lvl .
+Any level above 0 causes
+.Nm
+to remain in the foreground, and increases the amount of debug output.
+The
+.Fl n
+flag makes the daemon single-threaded.
.Pp
It is envisaged that user-level communication take place with
.Nm
Index: src/sbin/iscsid/iscsid.h
diff -u src/sbin/iscsid/iscsid.h:1.2 src/sbin/iscsid/iscsid.h:1.2.4.1
--- src/sbin/iscsid/iscsid.h:1.2 Sat Oct 29 16:54:49 2011
+++ src/sbin/iscsid/iscsid.h Wed May 30 08:06:26 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: iscsid.h,v 1.2 2011/10/29 16:54:49 christos Exp $ */
+/* $NetBSD: iscsid.h,v 1.2.4.1 2012/05/30 08:06:26 sborrill Exp $ */
/*-
* Copyright (c) 2004,2006,2011 The NetBSD Foundation, Inc.
@@ -908,6 +908,8 @@ typedef struct {
Corresponding version information for driver.
*/
+extern int nothreads;
+
__END_DECLS
#endif /* !_ISCSID_H_ */
Index: src/sbin/iscsid/iscsid_driverif.c
diff -u src/sbin/iscsid/iscsid_driverif.c:1.3 src/sbin/iscsid/iscsid_driverif.c:1.3.2.1
--- src/sbin/iscsid/iscsid_driverif.c:1.3 Sun Nov 20 01:23:57 2011
+++ src/sbin/iscsid/iscsid_driverif.c Wed May 30 08:06:26 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: iscsid_driverif.c,v 1.3 2011/11/20 01:23:57 agc Exp $ */
+/* $NetBSD: iscsid_driverif.c,v 1.3.2.1 2012/05/30 08:06:26 sborrill Exp $ */
/*-
* Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -192,8 +192,8 @@ make_connection(session_t * sess, iscsid
struct hostent *host;
initiator_t *init;
- DEB(9, ("Make Connection sess=%x, req=%x, res=%x, stid=%x\n",
- (int) sess, (int) req, (int) res, (int) stid));
+ DEB(9, ("Make Connection sess=%p, req=%p, res=%p, stid=%p\n",
+ sess, req, res, stid));
(void) memset(&loginp, 0x0, sizeof(loginp));
(void) memset(&serverAddress, 0x0, sizeof(serverAddress));
@@ -923,11 +923,10 @@ event_handler(void *par)
evtp.event_id = event_reg.event_id;
do {
-#ifndef ISCSI_NOTHREAD
- rc = ioctl(driver, ISCSI_WAIT_EVENT, &evtp);
-#else
- rc = ioctl(driver, ISCSI_POLL_EVENT, &evtp);
-#endif
+ if (nothreads)
+ rc = ioctl(driver, ISCSI_POLL_EVENT, &evtp);
+ else
+ rc = ioctl(driver, ISCSI_WAIT_EVENT, &evtp);
if (rc || evtp.status)
break;
@@ -953,9 +952,7 @@ event_handler(void *par)
}
} while (evtp.event_kind != ISCSI_DRIVER_TERMINATING);
-#ifdef ISCSI_NOTHREAD
- if (evtp.event_kind == ISCSI_DRIVER_TERMINATING)
-#endif
+ if (nothreads && evtp.event_kind == ISCSI_DRIVER_TERMINATING)
exit_daemon();
return NULL;
Index: src/sbin/iscsid/iscsid_lists.c
diff -u src/sbin/iscsid/iscsid_lists.c:1.3 src/sbin/iscsid/iscsid_lists.c:1.3.2.1
--- src/sbin/iscsid/iscsid_lists.c:1.3 Sun Nov 20 01:23:57 2011
+++ src/sbin/iscsid/iscsid_lists.c Wed May 30 08:06:26 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: iscsid_lists.c,v 1.3 2011/11/20 01:23:57 agc Exp $ */
+/* $NetBSD: iscsid_lists.c,v 1.3.2.1 2012/05/30 08:06:26 sborrill Exp $ */
/*-
* Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,6 @@ static uint32_t initiator_id = 0;
/* -------------------------------------------------------------------------- */
-/*#ifdef ISCSI_NOTHREAD */
#if 0
/*
@@ -233,9 +232,9 @@ find_TargetName(iscsid_list_kind_t lst,
break;
}
- DEB(10, ("Find_TagetName returns %p\n", curr));
-
- return t;
+ /* return curr instead of t because curr==NULL if name not found */
+ DEB(10, ("Find_TargetName returns %p\n", curr));
+ return (target_t *)curr;
}
@@ -256,10 +255,10 @@ find_portal_by_addr(target_t * target, i
TAILQ_FOREACH(curr, &list[PORTAL_LIST].list, link) {
p = (void *)curr;
- DEB(10, ("Find_portal_by_addr - addr %s port %d target %x\n",
+ DEB(10, ("Find_portal_by_addr - addr %s port %d target %p\n",
p->addr.address,
p->addr.port,
- (int) p->target));
+ p->target));
if (strcmp((char *)p->addr.address, (char *)addr->address) == 0 &&
(!addr->port || p->addr.port == addr->port) &&
@@ -267,8 +266,9 @@ find_portal_by_addr(target_t * target, i
break;
}
+ /* return curr instead of p because curr==NULL if not found */
DEB(10, ("Find_portal_by_addr returns %p\n", curr));
- return p;
+ return (portal_t *)curr;
}
@@ -294,8 +294,9 @@ find_send_target_by_addr(iscsi_portal_ad
break;
}
+ /* return curr instead of p because curr==NULL if not found */
DEB(10, ("Find_send_target_by_addr returns %p\n", curr));
- return t;
+ return (send_target_t *)curr;
}
@@ -695,8 +696,9 @@ find_initiator_by_addr(uint8_t * addr)
break;
}
+ /* return curr instead of i because if not found, curr==NULL */
DEB(9, ("Find_initiator_by_addr returns %p\n", curr));
- return i;
+ return (initiator_t *)curr;
}
Index: src/sbin/iscsid/iscsid_main.c
diff -u src/sbin/iscsid/iscsid_main.c:1.3 src/sbin/iscsid/iscsid_main.c:1.3.2.1
--- src/sbin/iscsid/iscsid_main.c:1.3 Sun Nov 20 01:23:57 2011
+++ src/sbin/iscsid/iscsid_main.c Wed May 30 08:06:26 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: iscsid_main.c,v 1.3 2011/11/20 01:23:57 agc Exp $ */
+/* $NetBSD: iscsid_main.c,v 1.3.2.1 2012/05/30 08:06:26 sborrill Exp $ */
/*-
* Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -37,6 +37,7 @@
#include <sys/sysctl.h>
#include <ctype.h>
+#include <err.h>
#include <fcntl.h>
#define DEVICE "/dev/iscsi0"
@@ -45,17 +46,17 @@
list_head_t list[NUM_DAEMON_LISTS]; /* the lists this daemon keeps */
-#ifndef ISCSI_NOTHREAD
pthread_mutex_t sesslist_lock; /* session list lock */
pthread_t event_thread; /* event thread handle */
-#endif
int driver = -1; /* the driver's file desc */
int client_sock; /* the client communication socket */
-#ifdef ISCSI_DEBUG
-int debug_level = ISCSI_DEBUG; /* How much info to display */
+#ifndef ISCSI_DEBUG
+#define ISCSI_DEBUG 0
#endif
+int debug_level = ISCSI_DEBUG; /* How much info to display */
+int nothreads;
/*
To avoid memory fragmentation (and speed things up a bit), we use the
@@ -68,6 +69,13 @@ static uint8_t rsp_buf[RSP_BUFFER_SIZE];
/* -------------------------------------------------------------------------- */
+static void __dead
+usage(void)
+{
+ fprintf(stderr, "Usage: %s [-d <lvl>] [-n]\n", getprogname());
+ exit(EXIT_FAILURE);
+}
+
/*
* create_node_name:
@@ -162,21 +170,18 @@ init_daemon(void)
list[i].num_entries = 0;
}
-#ifndef ISCSI_NOTHREAD
- if ((i = pthread_mutex_init(&sesslist_lock, NULL)) != 0) {
+ if (!nothreads && (i = pthread_mutex_init(&sesslist_lock, NULL)) != 0) {
printf("Mutex init failed (%d)\n", i);
close(sock);
return -1;
}
-#endif
if (!register_event_handler()) {
printf("Couldn't register event handler\n");
close(sock);
unlink(ISCSID_SOCK_NAME);
-#ifndef ISCSI_NOTHREAD
- pthread_mutex_destroy(&sesslist_lock);
-#endif
+ if (!nothreads)
+ pthread_mutex_destroy(&sesslist_lock);
return -1;
}
@@ -473,9 +478,7 @@ process_message(iscsid_request_t *req, i
void
exit_daemon(void)
{
-#ifndef ISCSI_NOTHREAD
LOCK_SESSIONS;
-#endif
deregister_event_handler();
#ifndef ISCSI_MINIMAL
@@ -501,16 +504,30 @@ int
/*ARGSUSED*/
main(int argc, char **argv)
{
- int req_temp, rsp_temp;
+ int req_temp, rsp_temp, c;
ssize_t ret;
size_t len;
struct sockaddr_un from;
socklen_t fromlen;
iscsid_request_t *req;
iscsid_response_t *rsp;
-#ifdef ISCSI_NOTHREAD
struct timeval seltout = { 2, 0 }; /* 2 second poll interval */
-#endif
+ char *p;
+
+ while ((c = getopt(argc, argv, "d:n")) != -1)
+ switch (c) {
+ case 'n':
+ nothreads++;
+ break;
+ case 'd':
+ debug_level=(int)strtol(optarg, &p, 10);
+ if (*p)
+ errx(EXIT_FAILURE, "illegal debug level -- %s",
+ optarg);
+ break;
+ default:
+ usage();
+ }
client_sock = init_daemon();
if (client_sock < 0)
@@ -518,21 +535,23 @@ main(int argc, char **argv)
printf("iSCSI Daemon loaded\n");
- daemon(0, 1);
+ if (!debug_level)
+ daemon(0, 1);
-#ifndef ISCSI_NOTHREAD
- ret = pthread_create(&event_thread, NULL, event_handler, NULL);
- if (ret) {
- printf("Thread creation failed (%zd)\n", ret);
- close(client_sock);
- unlink(ISCSID_SOCK_NAME);
- deregister_event_handler();
- pthread_mutex_destroy(&sesslist_lock);
- return -1;
+ if (nothreads)
+ setsockopt(client_sock, SOL_SOCKET, SO_RCVTIMEO, &seltout,
+ sizeof(seltout));
+ else {
+ ret = pthread_create(&event_thread, NULL, event_handler, NULL);
+ if (ret) {
+ printf("Thread creation failed (%zd)\n", ret);
+ close(client_sock);
+ unlink(ISCSID_SOCK_NAME);
+ deregister_event_handler();
+ pthread_mutex_destroy(&sesslist_lock);
+ return -1;
+ }
}
-#else
- setsockopt(client_sock, SOL_SOCKET, SO_RCVTIMEO, &seltout, sizeof(seltout));
-#endif
/* ---------------------------------------------------------------------- */
@@ -542,23 +561,29 @@ main(int argc, char **argv)
fromlen = sizeof(from);
len = sizeof(iscsid_request_t);
-#ifdef ISCSI_NOTHREAD
- do {
- ret = recvfrom(client_sock, req, len, MSG_PEEK | MSG_WAITALL,
- (struct sockaddr *) &from, &fromlen);
- if (ret == -1)
- event_handler(NULL);
- } while (ret == -1 && errno == EAGAIN);
-#else
- ret = recvfrom(client_sock, req, len, MSG_PEEK | MSG_WAITALL,
- (struct sockaddr *)(void *)&from, &fromlen);
-#endif
+ if (nothreads) {
+ do {
+ ret = recvfrom(client_sock, req, len, MSG_PEEK |
+ MSG_WAITALL, (struct sockaddr *)(void *)&from,
+ &fromlen);
+ if (ret == -1)
+ event_handler(NULL);
+ } while (ret == -1 && errno == EAGAIN);
+ } else {
+ do {
+ ret = recvfrom(client_sock, req, len, MSG_PEEK |
+ MSG_WAITALL, (struct sockaddr *) &from,
+ &fromlen);
+ if (ret == -1)
+ event_handler(NULL);
+ } while (ret == -1 && errno == EAGAIN);
+ }
if ((size_t)ret != len) {
perror("Receiving from socket");
break;
}
- DEB(99, ("Request %d, parlen %d\n",
+ DEB(98, ("Request %d, parlen %d\n",
req->request, req->parameter_length));
len += req->parameter_length;
@@ -604,7 +629,7 @@ main(int argc, char **argv)
if (rsp == NULL)
break;
- DEB(99, ("Sending reply: status %d, len %d\n",
+ DEB(98, ("Sending reply: status %d, len %d\n",
rsp->status, rsp->parameter_length));
/* send the response */
Index: src/sbin/iscsid/iscsid_targets.c
diff -u src/sbin/iscsid/iscsid_targets.c:1.3 src/sbin/iscsid/iscsid_targets.c:1.3.2.1
--- src/sbin/iscsid/iscsid_targets.c:1.3 Sun Nov 20 01:23:57 2011
+++ src/sbin/iscsid/iscsid_targets.c Wed May 30 08:06:26 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: iscsid_targets.c,v 1.3 2011/11/20 01:23:57 agc Exp $ */
+/* $NetBSD: iscsid_targets.c,v 1.3.2.1 2012/05/30 08:06:26 sborrill Exp $ */
/*-
* Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -114,7 +114,7 @@ create_portal(target_t *target, iscsi_po
TAILQ_INSERT_TAIL(&list[PORTAL_LIST].list, &portal->entry, link);
list[PORTAL_LIST].num_entries++;
- DEB(9, ("create_portal returns %x\n", (int) portal));
+ DEB(9, ("create_portal returns %p\n", portal));
return portal;
}
Index: src/sbin/iscsid/iscsid_globals.h
diff -u src/sbin/iscsid/iscsid_globals.h:1.4 src/sbin/iscsid/iscsid_globals.h:1.4.2.1
--- src/sbin/iscsid/iscsid_globals.h:1.4 Sun Nov 20 01:23:57 2011
+++ src/sbin/iscsid/iscsid_globals.h Wed May 30 08:06:26 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: iscsid_globals.h,v 1.4 2011/11/20 01:23:57 agc Exp $ */
+/* $NetBSD: iscsid_globals.h,v 1.4.2.1 2012/05/30 08:06:26 sborrill Exp $ */
/*-
* Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -379,33 +379,20 @@ iscsid_set_node_name_req_t node_name;
/* Debugging stuff */
-#ifdef ISCSI_DEBUG
-int debug_level; /* How much info to display */
+extern int debug_level; /* How much info to display */
#define DEBOUT(x) printf x
#define DEB(lev,x) {if (debug_level >= lev) printf x ;}
-#else
-
-#define DEBOUT(x)
-#define DEB(lev,x)
-
-#endif
-
/* Session list protection shortcuts */
#if 0
#define LOCK_SESSIONS verify_sessions()
#define UNLOCK_SESSIONS
#endif
-#ifdef ISCSI_NOTHREAD
-#define LOCK_SESSIONS event_handler(NULL)
-#define UNLOCK_SESSIONS
-#else
-#define LOCK_SESSIONS pthread_mutex_lock(&sesslist_lock)
-#define UNLOCK_SESSIONS pthread_mutex_unlock(&sesslist_lock)
-#endif
+#define LOCK_SESSIONS if (nothreads) event_handler(NULL); else pthread_mutex_lock(&sesslist_lock)
+#define UNLOCK_SESSIONS if (!nothreads) pthread_mutex_unlock(&sesslist_lock)
/* Check whether ID is present */
Index: src/sys/dev/iscsi/iscsi_main.c
diff -u src/sys/dev/iscsi/iscsi_main.c:1.1 src/sys/dev/iscsi/iscsi_main.c:1.1.8.1
--- src/sys/dev/iscsi/iscsi_main.c:1.1 Sun Oct 23 21:15:02 2011
+++ src/sys/dev/iscsi/iscsi_main.c Wed May 30 08:06:26 2012
@@ -483,7 +483,6 @@ iscsi_done(ccb_t *ccb)
}
/* Kernel Module support */
-#ifdef _MODULE
#include <sys/module.h>
@@ -493,6 +492,7 @@ static const struct cfiattrdata ibescsi_
};
static const struct cfiattrdata *const iscsi_attrs[] = { &ibescsi_info, NULL };
+#ifdef _MODULE
CFDRIVER_DECL(iscsi, DV_DULL, iscsi_attrs);
static struct cfdata iscsi_cfdata[] = {
@@ -507,15 +507,19 @@ static struct cfdata iscsi_cfdata[] = {
},
{ NULL, NULL, 0, 0, NULL, 0, NULL }
};
+#endif
static int
iscsi_modcmd(modcmd_t cmd, void *arg)
{
+#ifdef _MODULE
devmajor_t cmajor = NODEVMAJOR, bmajor = NODEVMAJOR;
int error;
+#endif
switch (cmd) {
case MODULE_CMD_INIT:
+#ifdef _MODULE
error = config_cfdriver_attach(&iscsi_cd);
if (error) {
return error;
@@ -556,11 +560,12 @@ iscsi_modcmd(modcmd_t cmd, void *arg)
config_cfdriver_detach(&iscsi_cd);
return ENXIO;
}
-
+#endif
return 0;
break;
case MODULE_CMD_FINI:
+#ifdef _MODULE
error = config_cfdata_detach(iscsi_cfdata);
if (error)
return error;
@@ -568,13 +573,16 @@ iscsi_modcmd(modcmd_t cmd, void *arg)
config_cfattach_detach(iscsi_cd.cd_name, &iscsi_ca);
config_cfdriver_detach(&iscsi_cd);
devsw_detach(NULL, &iscsi_cdevsw);
-
+#endif
return 0;
break;
+ case MODULE_CMD_AUTOUNLOAD:
+ return EBUSY;
+ break;
+
default:
return ENOTTY;
break;
}
}
-#endif /* _MODULE */