Source-Changes-HG archive

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

[src/trunk]: src/sbin/iscsid Several improvents to iscsid



details:   https://anonhg.NetBSD.org/src/rev/eb81107e3101
branches:  trunk
changeset: 815593:eb81107e3101
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sun May 29 13:35:45 2016 +0000

description:
Several improvents to iscsid

- debug log is now using syslog
- seperate options for log level and foreground mode
- writes a pidfile so that /etc/rc.d/iscsid works
  Now links with libutil for pidfile(), the functions login() and logout()
  needed to be renamed to avoid a conflict.
- drops the nothreads option
- handles signals to shut down gracefully
- the driver may also shut down the daemon when it terminates
  Currently this cannot work as the driver can only terminate when
  the daemon has closed the driver file handle.

diffstat:

 sbin/iscsid/Makefile          |    4 +-
 sbin/iscsid/iscsid.8          |   16 ++--
 sbin/iscsid/iscsid.h          |    4 +-
 sbin/iscsid/iscsid_discover.c |  128 +++++++++++++++++++-------------------
 sbin/iscsid/iscsid_driverif.c |   69 ++++++++++----------
 sbin/iscsid/iscsid_globals.h  |   25 +++----
 sbin/iscsid/iscsid_lists.c    |   28 ++++----
 sbin/iscsid/iscsid_main.c     |  139 +++++++++++++++++++++++------------------
 sbin/iscsid/iscsid_targets.c  |   40 ++++++------
 9 files changed, 232 insertions(+), 221 deletions(-)

diffs (truncated from 1468 to 300 lines):

diff -r f6f3297762a4 -r eb81107e3101 sbin/iscsid/Makefile
--- a/sbin/iscsid/Makefile      Sun May 29 13:11:21 2016 +0000
+++ b/sbin/iscsid/Makefile      Sun May 29 13:35:45 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.5 2013/08/11 06:04:38 dholland Exp $
+#      $NetBSD: Makefile,v 1.6 2016/05/29 13:35:45 mlelstv Exp $
 
 PROG=  iscsid
 
@@ -11,7 +11,7 @@
 
 MAN=   iscsid.8
 
-LDADD = -lpthread -lisns
+LDADD = -lpthread -lisns -lutil
 
 INCSDIR= /usr/include
 
diff -r f6f3297762a4 -r eb81107e3101 sbin/iscsid/iscsid.8
--- a/sbin/iscsid/iscsid.8      Sun May 29 13:11:21 2016 +0000
+++ b/sbin/iscsid/iscsid.8      Sun May 29 13:35:45 2016 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: iscsid.8,v 1.12 2015/11/10 12:41:18 tnn Exp $
+.\" $NetBSD: iscsid.8,v 1.13 2016/05/29 13:35:45 mlelstv 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 Fl n
+.Op Fl D
 .Op Fl d Ar lvl
 .Sh DESCRIPTION
 The iSCSI initiator runs as a kernel driver, and provides access
@@ -60,14 +60,14 @@
 .Pp
 The
 .Fl d
-flag increases the debug level to
+flag increases the log level to
 .Ar lvl .
-Any level above 0 causes
+At level 0 only start and stop messages are logged.
+The
+.Fl D
+flag causes
 .Nm
-to remain in the foreground, and increases the amount of debug output.
-The
-.Fl n
-flag makes the daemon single-threaded.
+to remain in the foreground and to write log output to stdout.
 .Pp
 It is envisaged that user-level communication take place with
 .Nm
diff -r f6f3297762a4 -r eb81107e3101 sbin/iscsid/iscsid.h
--- a/sbin/iscsid/iscsid.h      Sun May 29 13:11:21 2016 +0000
+++ b/sbin/iscsid/iscsid.h      Sun May 29 13:35:45 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsid.h,v 1.4 2015/02/21 20:33:44 joerg Exp $ */
+/*     $NetBSD: iscsid.h,v 1.5 2016/05/29 13:35:45 mlelstv Exp $       */
 
 /*-
  * Copyright (c) 2004,2006,2011 The NetBSD Foundation, Inc.
@@ -908,8 +908,6 @@
       Corresponding version information for driver.
 */
 
-extern int nothreads;
-
 __END_DECLS
 
 #endif /* !_ISCSID_H_ */
diff -r f6f3297762a4 -r eb81107e3101 sbin/iscsid/iscsid_discover.c
--- a/sbin/iscsid/iscsid_discover.c     Sun May 29 13:11:21 2016 +0000
+++ b/sbin/iscsid/iscsid_discover.c     Sun May 29 13:35:45 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsid_discover.c,v 1.4 2012/06/24 13:08:38 mlelstv Exp $      */
+/*     $NetBSD: iscsid_discover.c,v 1.5 2016/05/29 13:35:45 mlelstv Exp $      */
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -116,7 +116,7 @@
 
        t = isns_new_trans(isns_handle, isnsp_DevAttrQry, MY_FLAGS);
        if (ISNS_INVALID_TRANS == t) {
-               DEBOUT(("%s: get_targets iscsi_new_trans failed\n", __func__));
+               DEB(10,("%s: get_targets iscsi_new_trans failed", __func__));
                return ISCSID_STATUS_NO_RESOURCES;
        }
        isns_add_string(t, isnst_iSCSIName, (char *)isns->reg_iscsi_name);
@@ -132,20 +132,20 @@
        /*tag=27: security bitmap */
 
        retval = isns_send_trans(t, &tout, &status);
-       DEB(9, ("isns_send_trans called, returns %d, status %d\n", retval, status));
+       DEB(9, ("isns_send_trans called, returns %d, status %d", retval, status));
        if (retval) {
-               DEBOUT(("iSNS Attribute Query failed, rc = %d\n", retval));
+               DEB(10,("iSNS Attribute Query failed, rc = %d", retval));
                isns_free_trans(t);
                return ISCSID_STATUS_ISNS_SERVER_ERROR;
        }
        /* First is target name (the one we put in), ignore */
        if (isns_get_tlv(t, ISNS_TLV_FIRST, &tag, &data_len, &data_p)) {
-               DEBOUT(("iSNS Attribute Query returned nothing\n"));
+               DEB(10,("iSNS Attribute Query returned nothing"));
                isns_free_trans(t);
                return ISCSID_STATUS_ISNS_SERVER_ERROR;
        }
        if (tag != isnst_iSCSIName) {
-               DEBOUT(("iSNS Query returned bad type (tag = %d, length = %d)\n",
+               DEB(10,("iSNS Query returned bad type (tag = %d, length = %d)",
                                tag, data_len));
                isns_free_trans(t);
                return ISCSID_STATUS_ISNS_SERVER_ERROR;
@@ -153,7 +153,7 @@
 
        isns_get_tlv(t, ISNS_TLV_NEXT, &tag, &data_len, &data_p);
        if (tag != isnst_Delimiter) {
-               DEBOUT(("Attr Query Missing Delimiter (tag = %d, length = %d)\n",
+               DEB(10,("Attr Query Missing Delimiter (tag = %d, length = %d)",
                                tag, data_len));
                isns_free_trans(t);
                return ISCSID_STATUS_ISNS_SERVER_ERROR;
@@ -161,8 +161,8 @@
 
        isns_get_tlv(t, ISNS_TLV_NEXT, &tag, &data_len, &data_p);
        if (tag != isnst_iSCSIName || !data_len || data_len >= ISCSI_STRING_LENGTH) {
-               DEBOUT(("iSNS Query returned no or invalid name (tag = %d, "
-                               "length = %d)\n", tag, data_len));
+               DEB(10,("iSNS Query returned no or invalid name (tag = %d, "
+                               "length = %d)", tag, data_len));
                isns_free_trans(t);
                return ISCSID_STATUS_ISNS_SERVER_ERROR;
        }
@@ -170,14 +170,14 @@
 
        isns_get_tlv(t, ISNS_TLV_NEXT, &tag, &data_len, &data_p);
        if (tag != isnst_iSCSINodeType || data_len != 4) {
-               DEBOUT(("iSNS Query returned no or invalid node type (tag = %d, "
-                               "length = %d)\n", tag, data_len));
+               DEB(10,("iSNS Query returned no or invalid node type (tag = %d, "
+                               "length = %d)", tag, data_len));
                isns_free_trans(t);
                return ISCSID_STATUS_ISNS_SERVER_ERROR;
        }
        u32 = ntohl(*((uint32_t *) data_p));
        if (!(u32 & 1)) {
-               DEBOUT(("iSNS Query returned bad type (type=%x, should be 1)\n", u32));
+               DEB(10,("iSNS Query returned bad type (type=%x, should be 1)", u32));
                isns_free_trans(t);
                return ISCSID_STATUS_ISNS_SERVER_ERROR;
        }
@@ -185,7 +185,7 @@
        isns_get_tlv(t, ISNS_TLV_NEXT, &tag, &data_len, &data_p);
        if (tag == isnst_iSCSIAlias) {
                if (data_len >= ISCSI_STRING_LENGTH) {
-                       DEBOUT(("iSNS Query returned invalid alias (tag=%d, length=%d)\n",
+                       DEB(10,("iSNS Query returned invalid alias (tag=%d, length=%d)",
                                        tag, data_len));
                        isns_free_trans(t);
                        return ISCSID_STATUS_ISNS_SERVER_ERROR;
@@ -199,7 +199,7 @@
 
        if (ISNS_INVALID_TRANS ==
                (t = isns_new_trans(isns_handle, isnsp_DevAttrQry, MY_FLAGS))) {
-               DEBOUT(("get_targets iscsi_new_trans failed\n"));
+               DEB(10,("get_targets iscsi_new_trans failed"));
                return ISCSID_STATUS_NO_RESOURCES;
        }
        isns_add_string(t, isnst_iSCSIName, (char *)isns->reg_iscsi_name);
@@ -213,20 +213,20 @@
        isns_add_tlv(t, isnst_PGTag, 0, NULL);  /* 51: group tag */
 
        retval = isns_send_trans(t, &tout, &status);
-       DEB(9, ("isns_send_trans called, returns %d, status %d\n", retval, status));
+       DEB(9, ("isns_send_trans called, returns %d, status %d", retval, status));
        if (retval) {
-               DEBOUT(("iSNS Attribute Query failed, rc = %d\n", retval));
+               DEB(10,("iSNS Attribute Query failed, rc = %d", retval));
                isns_free_trans(t);
                return ISCSID_STATUS_ISNS_SERVER_ERROR;
        }
        /* First is target name (the one we put in), ignore */
        if (isns_get_tlv(t, ISNS_TLV_FIRST, &tag, &data_len, &data_p)) {
-               DEBOUT(("iSNS Attribute Query returned nothing\n"));
+               DEB(10,("iSNS Attribute Query returned nothing"));
                isns_free_trans(t);
                return ISCSID_STATUS_ISNS_SERVER_ERROR;
        }
        if (tag != isnst_iSCSIName) {
-               DEBOUT(("iSNS Query2 returned bad name (tag = %d, length = %d)\n",
+               DEB(10,("iSNS Query2 returned bad name (tag = %d, length = %d)",
                                tag, data_len));
                isns_free_trans(t);
                return ISCSID_STATUS_ISNS_SERVER_ERROR;
@@ -234,7 +234,7 @@
 
        isns_get_tlv(t, ISNS_TLV_NEXT, &tag, &data_len, &data_p);
        if (tag != isnst_Delimiter) {
-               DEBOUT(("Attr Query2 Missing Delimiter (tag = %d, length = %d)\n",
+               DEB(10,("Attr Query2 Missing Delimiter (tag = %d, length = %d)",
                                tag, data_len));
                isns_free_trans(t);
                return ISCSID_STATUS_ISNS_SERVER_ERROR;
@@ -243,8 +243,8 @@
        while (!isns_get_tlv(t, ISNS_TLV_NEXT, &tag, &data_len, &data_p)) {
                if (tag != isnst_PGiSCSIName || !data_len ||
                        data_len >= ISCSI_STRING_LENGTH) {
-                       DEBOUT(("iSNS Query2 returned no or invalid name (tag=%d, "
-                                       "length=%d)\n", tag, data_len));
+                       DEB(10,("iSNS Query2 returned no or invalid name (tag=%d, "
+                                       "length=%d)", tag, data_len));
                        isns_free_trans(t);
                        return ISCSID_STATUS_ISNS_SERVER_ERROR;
                }
@@ -252,8 +252,8 @@
 
                isns_get_tlv(t, ISNS_TLV_NEXT, &tag, &data_len, &data_p);
                if (tag != isnst_PGPortIPAddr || data_len != 16) {
-                       DEBOUT(("iSNS Query returned no or invalid address (tag=%d, "
-                                       "length=%d)\n", tag, data_len));
+                       DEB(10,("iSNS Query returned no or invalid address (tag=%d, "
+                                       "length=%d)", tag, data_len));
                        isns_free_trans(t);
                        return ISCSID_STATUS_ISNS_SERVER_ERROR;
                }
@@ -262,15 +262,15 @@
                /* Now comes the port */
                isns_get_tlv(t, ISNS_TLV_NEXT, &tag, &data_len, &data_p);
                if (tag != isnst_PGPortIPPort || data_len != 4) {
-                       DEBOUT(("iSNS Query returned no or invalid port (tag=%d, "
-                                       "length=%d)\n", tag, data_len));
+                       DEB(10,("iSNS Query returned no or invalid port (tag=%d, "
+                                       "length=%d)", tag, data_len));
                        isns_free_trans(t);
                        return ISCSID_STATUS_ISNS_SERVER_ERROR;
                }
                u32 = ntohl(*((uint32_t *) data_p));
                if (u32 & 0xffff0000) {
-                       DEBOUT(("iSNS Query returned invalid port (flags=%x, "
-                                       "should be 0)\n", u32 >> 16));
+                       DEB(10,("iSNS Query returned invalid port (flags=%x, "
+                                       "should be 0)", u32 >> 16));
                        isns_free_trans(t);
                        return ISCSID_STATUS_ISNS_SERVER_ERROR;
                }
@@ -279,8 +279,8 @@
                /* And each target must have a group tag */
                isns_get_tlv(t, ISNS_TLV_NEXT, &tag, &data_len, &data_p);
                if (tag != isnst_PGTag || (data_len && data_len != 4)) {
-                       DEBOUT(("iSNS Query returned no or invalid group tag (tag=%d, "
-                                       "length=%d)\n", tag, data_len));
+                       DEB(10,("iSNS Query returned no or invalid group tag (tag=%d, "
+                                       "length=%d)", tag, data_len));
                        isns_free_trans(t);
                        return ISCSID_STATUS_ISNS_SERVER_ERROR;
                }
@@ -292,7 +292,7 @@
 
                /* we have everything necessary to describe the target, add it. */
 
-               DEB(1, ("Adding <%s>, IP <%s>, Port %d, Tag %d\n",
+               DEB(2, ("Adding <%s>, IP <%s>, Port %d, Tag %d",
                                name, addr.address, addr.port, addr.group_tag));
 
                if ((targ = add_discovered_target((unsigned char *)name, &addr, PORTAL_TYPE_ISNS,
@@ -335,7 +335,7 @@
 
        if (ISNS_INVALID_TRANS == (t = isns_new_trans(isns_handle, isnsp_DevDereg,
                                                                                                  MY_FLAGS))) {
-               DEBOUT(("dereg_isns_server iscsi_new_trans failed\n"));
+               DEB(10,("dereg_isns_server iscsi_new_trans failed"));
                return ISCSID_STATUS_NO_RESOURCES;
        }
 
@@ -349,7 +349,7 @@
        isns_add_string(t, isnst_iSCSIName, (char *)isns->reg_iscsi_name);
 
        retval = isns_send_trans(t, &tout, &status);
-       DEB(9, ("DevAttrReg request returns %d, status %d\n", retval, status));
+       DEB(9, ("DevAttrReg request returns %d, status %d", retval, status));
 
        isns_free_trans(t);
        return ISCSID_STATUS_SUCCESS;
@@ -375,7 +375,7 @@
 
        if (ISNS_INVALID_TRANS == (t = isns_new_trans(isns_handle, isnsp_DevAttrReg,
                                                                                                  MY_FLAGS))) {
-               DEBOUT(("iscsi_new_trans failed\n"));
+               DEB(10,("iscsi_new_trans failed"));
                return ISCSID_STATUS_NO_RESOURCES;
        }
 
@@ -394,7 +394,7 @@
                /*tag=33 (node type = intiator) */
 



Home | Main Index | Thread Index | Old Index