Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/iscsid use -n for nothreads.



details:   https://anonhg.NetBSD.org/src/rev/4b01ad35b4f5
branches:  trunk
changeset: 779429:4b01ad35b4f5
user:      christos <christos%NetBSD.org@localhost>
date:      Sun May 27 20:05:04 2012 +0000

description:
use -n for nothreads.

diffstat:

 sbin/iscsid/Makefile          |   4 +-
 sbin/iscsid/iscsid.8          |  10 +++--
 sbin/iscsid/iscsid.h          |   4 +-
 sbin/iscsid/iscsid_driverif.c |  15 +++-----
 sbin/iscsid/iscsid_lists.c    |   3 +-
 sbin/iscsid/iscsid_main.c     |  76 +++++++++++++++++++++---------------------
 6 files changed, 55 insertions(+), 57 deletions(-)

diffs (275 lines):

diff -r fb823a35490b -r 4b01ad35b4f5 sbin/iscsid/Makefile
--- a/sbin/iscsid/Makefile      Sun May 27 19:52:51 2012 +0000
+++ b/sbin/iscsid/Makefile      Sun May 27 20:05:04 2012 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.2 2012/05/27 19:52:51 christos Exp $
+#      $NetBSD: Makefile,v 1.3 2012/05/27 20:05:04 christos Exp $
 
 PROG=  iscsid
 
@@ -8,8 +8,6 @@
 CPPFLAGS+= -I${DESTDIR}/usr/include/dev/iscsi
 CPPFLAGS+= -I${DESTDIR}/usr/include
 CPPFLAGS+= -D_THREAD_SAFE
-CPPFLAGS+= -DISCSI_NOTHREAD
-DBG=-g
 
 MAN=   iscsid.8
 
diff -r fb823a35490b -r 4b01ad35b4f5 sbin/iscsid/iscsid.8
--- a/sbin/iscsid/iscsid.8      Sun May 27 19:52:51 2012 +0000
+++ b/sbin/iscsid/iscsid.8      Sun May 27 20:05:04 2012 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: iscsid.8,v 1.3 2012/05/27 19:52:51 christos Exp $
+.\" $NetBSD: iscsid.8,v 1.4 2012/05/27 20:05:04 christos Exp $
 .\"
 .\" Copyright (c) 2011 Alistair Crooks <agc%NetBSD.org@localhost>
 .\" All rights reserved.
@@ -31,7 +31,7 @@
 .Nd interface to kernel iSCSI driver
 .Sh SYNOPSIS
 .Nm
-.Op Ar d
+.Op Ar dn
 .Sh DESCRIPTION
 The iSCSI initiator runs as a kernel driver, and provides access
 to iSCSI targets running across a network using the iSCSI protocol,
@@ -57,10 +57,12 @@
 (no response to one that is sent to the kernel),
 or when an error occurs reading from or writing to the socket.
 .Pp
-The only command line argument
+The argument
 .Ar d
 increases the debug level.
-.Nm .
+The argument
+.Ar n
+makes the daemon single-threaded.
 .Pp
 It is envisaged that user-level communication take place with
 .Nm
diff -r fb823a35490b -r 4b01ad35b4f5 sbin/iscsid/iscsid.h
--- a/sbin/iscsid/iscsid.h      Sun May 27 19:52:51 2012 +0000
+++ b/sbin/iscsid/iscsid.h      Sun May 27 20:05:04 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsid.h,v 1.2 2011/10/29 16:54:49 christos Exp $      */
+/*     $NetBSD: iscsid.h,v 1.3 2012/05/27 20:05:04 christos Exp $      */
 
 /*-
  * Copyright (c) 2004,2006,2011 The NetBSD Foundation, Inc.
@@ -908,6 +908,8 @@
       Corresponding version information for driver.
 */
 
+extern int nothreads;
+
 __END_DECLS
 
 #endif /* !_ISCSID_H_ */
diff -r fb823a35490b -r 4b01ad35b4f5 sbin/iscsid/iscsid_driverif.c
--- a/sbin/iscsid/iscsid_driverif.c     Sun May 27 19:52:51 2012 +0000
+++ b/sbin/iscsid/iscsid_driverif.c     Sun May 27 20:05:04 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsid_driverif.c,v 1.4 2012/05/27 16:50:32 riz Exp $  */
+/*     $NetBSD: iscsid_driverif.c,v 1.5 2012/05/27 20:05:04 christos Exp $     */
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -923,11 +923,10 @@
        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 @@
                }
        } 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;
diff -r fb823a35490b -r 4b01ad35b4f5 sbin/iscsid/iscsid_lists.c
--- a/sbin/iscsid/iscsid_lists.c        Sun May 27 19:52:51 2012 +0000
+++ b/sbin/iscsid/iscsid_lists.c        Sun May 27 20:05:04 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsid_lists.c,v 1.4 2012/05/27 16:50:32 riz Exp $     */
+/*     $NetBSD: iscsid_lists.c,v 1.5 2012/05/27 20:05:04 christos Exp $        */
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -37,7 +37,6 @@
 
 /* -------------------------------------------------------------------------- */
 
-/*#ifdef ISCSI_NOTHREAD */
 #if 0
 
 /*
diff -r fb823a35490b -r 4b01ad35b4f5 sbin/iscsid/iscsid_main.c
--- a/sbin/iscsid/iscsid_main.c Sun May 27 19:52:51 2012 +0000
+++ b/sbin/iscsid/iscsid_main.c Sun May 27 20:05:04 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsid_main.c,v 1.4 2012/05/27 19:52:51 christos Exp $ */
+/*     $NetBSD: iscsid_main.c,v 1.5 2012/05/27 20:05:04 christos Exp $ */
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -45,10 +45,8 @@
 
 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 */
@@ -57,6 +55,7 @@
 #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
@@ -170,21 +169,18 @@
                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;
        }
 
@@ -481,9 +477,9 @@
 void
 exit_daemon(void)
 {
-#ifndef ISCSI_NOTHREAD
-       LOCK_SESSIONS;
-#endif
+       if (nothreads) {
+               LOCK_SESSIONS;
+       }
        deregister_event_handler();
 
 #ifndef ISCSI_MINIMAL
@@ -516,9 +512,7 @@
        socklen_t fromlen;
        iscsid_request_t *req;
        iscsid_response_t *rsp;
-#ifdef ISCSI_NOTHREAD
        struct timeval seltout = { 2, 0 };      /* 2 second poll interval */
-#endif
 
        client_sock = init_daemon();
        if (client_sock < 0)
@@ -526,8 +520,11 @@
 
        printf("iSCSI Daemon loaded\n");
 
-       while ((c = getopt(argc, argv, "d")) != -1)
+       while ((c = getopt(argc, argv, "dn")) != -1)
                switch (c) {
+               case 'n':
+                       nothreads++;
+                       break;
                case 'd':
                        debug_level++;
                        break;
@@ -538,19 +535,20 @@
        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
 
     /* ---------------------------------------------------------------------- */
 
@@ -560,17 +558,19 @@
                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) {
+                       ret = recvfrom(client_sock, req, len, MSG_PEEK |
+                           MSG_WAITALL, (struct sockaddr *)(void *)&from,
+                           &fromlen);
+               } 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");



Home | Main Index | Thread Index | Old Index