Module Name: src Committed By: christos Date: Sun May 27 20:05:05 UTC 2012
Modified Files: src/sbin/iscsid: Makefile iscsid.8 iscsid.h iscsid_driverif.c iscsid_lists.c iscsid_main.c Log Message: use -n for nothreads. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sbin/iscsid/Makefile src/sbin/iscsid/iscsid.h cvs rdiff -u -r1.3 -r1.4 src/sbin/iscsid/iscsid.8 cvs rdiff -u -r1.4 -r1.5 src/sbin/iscsid/iscsid_driverif.c \ src/sbin/iscsid/iscsid_lists.c src/sbin/iscsid/iscsid_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/sbin/iscsid/Makefile diff -u src/sbin/iscsid/Makefile:1.2 src/sbin/iscsid/Makefile:1.3 --- src/sbin/iscsid/Makefile:1.2 Sun May 27 15:52:51 2012 +++ src/sbin/iscsid/Makefile Sun May 27 16:05:04 2012 @@ -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 @@ SRCS= iscsid_main.c iscsid_lists.c iscsi CPPFLAGS+= -I${DESTDIR}/usr/include/dev/iscsi CPPFLAGS+= -I${DESTDIR}/usr/include CPPFLAGS+= -D_THREAD_SAFE -CPPFLAGS+= -DISCSI_NOTHREAD -DBG=-g MAN= iscsid.8 Index: src/sbin/iscsid/iscsid.h diff -u src/sbin/iscsid/iscsid.h:1.2 src/sbin/iscsid/iscsid.h:1.3 --- src/sbin/iscsid/iscsid.h:1.2 Sat Oct 29 12:54:49 2011 +++ src/sbin/iscsid/iscsid.h Sun May 27 16:05:04 2012 @@ -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 @@ typedef struct { Corresponding version information for driver. */ +extern int nothreads; + __END_DECLS #endif /* !_ISCSID_H_ */ Index: src/sbin/iscsid/iscsid.8 diff -u src/sbin/iscsid/iscsid.8:1.3 src/sbin/iscsid/iscsid.8:1.4 --- src/sbin/iscsid/iscsid.8:1.3 Sun May 27 15:52:51 2012 +++ src/sbin/iscsid/iscsid.8 Sun May 27 16:05:04 2012 @@ -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 <a...@netbsd.org> .\" 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 @@ 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 -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 Index: src/sbin/iscsid/iscsid_driverif.c diff -u src/sbin/iscsid/iscsid_driverif.c:1.4 src/sbin/iscsid/iscsid_driverif.c:1.5 --- src/sbin/iscsid/iscsid_driverif.c:1.4 Sun May 27 12:50:32 2012 +++ src/sbin/iscsid/iscsid_driverif.c Sun May 27 16:05:04 2012 @@ -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 @@ 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.4 src/sbin/iscsid/iscsid_lists.c:1.5 --- src/sbin/iscsid/iscsid_lists.c:1.4 Sun May 27 12:50:32 2012 +++ src/sbin/iscsid/iscsid_lists.c Sun May 27 16:05:04 2012 @@ -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 @@ static uint32_t initiator_id = 0; /* -------------------------------------------------------------------------- */ -/*#ifdef ISCSI_NOTHREAD */ #if 0 /* Index: src/sbin/iscsid/iscsid_main.c diff -u src/sbin/iscsid/iscsid_main.c:1.4 src/sbin/iscsid/iscsid_main.c:1.5 --- src/sbin/iscsid/iscsid_main.c:1.4 Sun May 27 15:52:51 2012 +++ src/sbin/iscsid/iscsid_main.c Sun May 27 16:05:04 2012 @@ -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 @@ int client_sock; /* the client commun #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 @@ 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; } @@ -481,9 +477,9 @@ process_message(iscsid_request_t *req, i void exit_daemon(void) { -#ifndef ISCSI_NOTHREAD - LOCK_SESSIONS; -#endif + if (nothreads) { + LOCK_SESSIONS; + } deregister_event_handler(); #ifndef ISCSI_MINIMAL @@ -516,9 +512,7 @@ main(int argc, char **argv) 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 @@ main(int argc, char **argv) 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 @@ main(int argc, char **argv) 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 @@ 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) { + 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");