Source-Changes-HG archive

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

[src/netbsd-6]: src Pull up revisions:



details:   https://anonhg.NetBSD.org/src/rev/cb86a5f030d2
branches:  netbsd-6
changeset: 774286:cb86a5f030d2
user:      jdc <jdc%NetBSD.org@localhost>
date:      Tue Jul 03 20:48:40 2012 +0000

description:
Pull up revisions:
  src/sys/dev/iscsi/iscsi_globals.h revisions 1.3,1.4
  src/sys/dev/iscsi/iscsi_main.c revisions 1.4,1.5
  src/sys/dev/iscsi/iscsi_text.c revisions 1.4,1.5
  src/sys/dev/iscsi/iscsi_ioctl.c revisions 1.3,1.4
  src/sys/dev/iscsi/iscsi_send.c revisions 1.3,1.4,1.5
  src/sys/dev/iscsi/iscsi_utils.c revisions 1.2,1.3,1.4
  src/sbin/iscsid/iscsid_discover.c revision 1.4
  src/sys/dev/iscsi/iscsi_rcv.c revision 1.3
  src/sbin/iscsictl/iscsic_driverif.c revisions 1.5,1.6
(requested by martin in ticket #357, with updates from mhitch and mlelstv).

avoid namespace pollution when debugging
don't panic when printing data for a dead (NULL) connection

Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.

assemble_login_parameters() has a strange error reporting convention:
errors are positive numbers, so <= 0 is good, not >= ...
This makes CHAP authenticated iscsi logins work.

use first successful connection to a ISNS server

Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.

report luns returns a 32bit list length.

Make digests work also on big endian machines.

it's really 32bit

diffstat:

 sbin/iscsictl/iscsic_driverif.c |   7 +-
 sbin/iscsid/iscsid_discover.c   |   4 +-
 sys/dev/iscsi/iscsi_globals.h   |  21 +++++----
 sys/dev/iscsi/iscsi_ioctl.c     |  56 ++++++++++++++++++------
 sys/dev/iscsi/iscsi_main.c      |   5 +-
 sys/dev/iscsi/iscsi_rcv.c       |  46 +++++++++++---------
 sys/dev/iscsi/iscsi_send.c      |  85 +++++++++++++++++++++-----------------
 sys/dev/iscsi/iscsi_text.c      |  89 ++++++++++++++++++++++++++++++++--------
 sys/dev/iscsi/iscsi_utils.c     |  19 +++++--
 9 files changed, 215 insertions(+), 117 deletions(-)

diffs (truncated from 869 to 300 lines):

diff -r 839fc59fa45f -r cb86a5f030d2 sbin/iscsictl/iscsic_driverif.c
--- a/sbin/iscsictl/iscsic_driverif.c   Mon Jul 02 21:42:47 2012 +0000
+++ b/sbin/iscsictl/iscsic_driverif.c   Tue Jul 03 20:48:40 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsic_driverif.c,v 1.2.4.1 2012/07/02 18:50:11 jdc Exp $      */
+/*     $NetBSD: iscsic_driverif.c,v 1.2.4.2 2012/07/03 20:48:40 jdc Exp $      */
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -590,7 +590,6 @@
        int rc;
        size_t llen;
        uint32_t n;
-       uint16_t n2;
        uint64_t *lp;
 
        (void) memset(&io, 0x0, sizeof(io));
@@ -609,8 +608,8 @@
        if ((rc = do_ioctl(&io, TRUE)) != 0) {
                return rc;
        }
-       (void) memcpy(&n2, buf, sizeof(n2));
-       llen = ntohs(n2);
+       (void) memcpy(&n, buf, sizeof(n));
+       llen = ntohl(n);
        if (!llen) {
                printf("No LUNs!\n");
                return 1;
diff -r 839fc59fa45f -r cb86a5f030d2 sbin/iscsid/iscsid_discover.c
--- a/sbin/iscsid/iscsid_discover.c     Mon Jul 02 21:42:47 2012 +0000
+++ b/sbin/iscsid/iscsid_discover.c     Tue Jul 03 20:48:40 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsid_discover.c,v 1.3 2011/11/20 01:23:57 agc Exp $  */
+/*     $NetBSD: iscsid_discover.c,v 1.3.2.1 2012/07/03 20:48:40 jdc Exp $      */
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -522,7 +522,7 @@
                        return (uint32_t)-1;
                }
 
-               if (connect(sock, addr->ai_addr, addr->ai_addrlen) == -1)
+               if (connect(sock, addr->ai_addr, addr->ai_addrlen) != -1)
                        break;
 
                DEB(1, ("%s: connect call FAILED!\n", __func__));
diff -r 839fc59fa45f -r cb86a5f030d2 sys/dev/iscsi/iscsi_globals.h
--- a/sys/dev/iscsi/iscsi_globals.h     Mon Jul 02 21:42:47 2012 +0000
+++ b/sys/dev/iscsi/iscsi_globals.h     Tue Jul 03 20:48:40 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_globals.h,v 1.2 2011/11/29 03:50:31 tls Exp $    */
+/*     $NetBSD: iscsi_globals.h,v 1.2.4.1 2012/07/03 20:48:40 jdc Exp $        */
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -387,6 +387,7 @@
                                        /* if closing down: status */
        int                             recover; /* recovery count */
                /* (reset on first successful data transfer) */
+       int                             usecount; /* number of active CCBs */
 
        bool                            destroy; /* conn will be destroyed */
        bool                            in_session;
@@ -564,12 +565,13 @@
 
 #if defined(ISCSI_PERFTEST)
 
-int perf_level;                                /* How much info to display */
+int iscsi_perf_level;                          /* How much info to display */
 
 #define PDEBOUT(x) printf x
-#define PDEB(lev,x) { if (perf_level >= lev) printf x ;}
-#define PDEBC(conn,lev,x) { { if (perf_level >= lev) printf("S%dC%d: ", \
-                               conn->session->id, conn->id); printf x ;}}
+#define PDEB(lev,x) { if (iscsi_perf_level >= lev) printf x ;}
+#define PDEBC(conn,lev,x) { if (iscsi_perf_level >= lev) { printf("S%dC%d: ", \
+                               conn ? conn->session->id : -1, \
+                               conn ? conn->id : -1); printf x ;}}
 #else
 #define PDEBOUT(x)
 #define PDEB(lev,x)
@@ -578,12 +580,13 @@
 
 #ifdef ISCSI_DEBUG
 
-int debug_level;       /* How much debug info to display */
+int iscsi_debug_level; /* How much debug info to display */
 
 #define DEBOUT(x) printf x
-#define DEB(lev,x) { if (debug_level >= lev) printf x ;}
-#define DEBC(conn,lev,x) { if (debug_level >= lev) { printf("S%dC%d: ", \
-                               conn->session->id, conn->id); printf x ;}}
+#define DEB(lev,x) { if (iscsi_debug_level >= lev) printf x ;}
+#define DEBC(conn,lev,x) { if (iscsi_debug_level >= lev) { printf("S%dC%d: ", \
+                               conn ? conn->session->id : -1, \
+                               conn ? conn->id : -1); printf x ;}}
 void dump(void *buf, int len);
 
 #define STATIC static
diff -r 839fc59fa45f -r cb86a5f030d2 sys/dev/iscsi/iscsi_ioctl.c
--- a/sys/dev/iscsi/iscsi_ioctl.c       Mon Jul 02 21:42:47 2012 +0000
+++ b/sys/dev/iscsi/iscsi_ioctl.c       Tue Jul 03 20:48:40 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_ioctl.c,v 1.2 2012/01/27 19:48:39 para Exp $     */
+/*     $NetBSD: iscsi_ioctl.c,v 1.2.2.1 2012/07/03 20:48:40 jdc Exp $  */
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -207,7 +207,8 @@
                        }
                        handler->waiter = par;
                        splx(s);
-                       tsleep(par, PRIBIO, "iscsievtwait", 0);
+                       if (tsleep(par, PRIBIO | PCATCH, "iscsievtwait", 0))
+                               return;
                }
        } while (evt == NULL);
 
@@ -324,15 +325,34 @@
        if (fp->f_type != DTYPE_SOCKET) {
                return ENOTSOCK;
        }
+
        /* Add the reference */
+       mutex_enter(&fp->f_lock);
        fp->f_count++;
-
-       /*simple_unlock (&fp->f_slock); */
+       mutex_exit(&fp->f_lock);
 
        *fpp = fp;
        return 0;
 }
 
+/*
+ * release_socket:
+ *    Release the file pointer from the socket handle passed into login.
+ *
+ *    Parameter:
+ *          fp       IN: The pointer to the resulting file pointer
+ *
+ */
+
+STATIC void
+release_socket(struct file *fp)
+{
+       /* Add the reference */
+       mutex_enter(&fp->f_lock);
+       fp->f_count--;
+       mutex_exit(&fp->f_lock);
+}
+
 
 /*
  * find_session:
@@ -468,7 +488,6 @@
 
        conn->terminating = status;
        conn->state = ST_SETTLING;
-       callout_stop(&conn->timeout);
 
        /* let send thread take over next step of cleanup */
        wakeup(&conn->pdus_to_send);
@@ -614,6 +633,7 @@
        callout_setfunc(&connection->timeout, connection_timeout, connection);
        connection->idle_timeout_val = CONNECTION_IDLE_TIMEOUT;
 
+       init_sernum(&connection->StatSN_buf);
        create_pdus(connection);
 
        if ((rc = get_socket(par->socket, &connection->sock)) != 0) {
@@ -626,6 +646,9 @@
        DEBC(connection, 1, ("get_socket: par_sock=%d, fdesc=%p\n",
                        par->socket, connection->sock));
 
+       /* close the file descriptor */
+       fd_close(par->socket);
+
        connection->threadobj = p;
        connection->login_par = par;
 
@@ -635,6 +658,7 @@
                                "ConnRcv")) != 0) {
                DEBOUT(("Can't create rcv thread (rc %d)\n", rc));
 
+               release_socket(connection->sock);
                free(connection, M_DEVBUF);
                par->status = ISCSI_STATUS_NO_RESOURCES;
                return rc;
@@ -645,7 +669,7 @@
                                "ConnSend")) != 0) {
                DEBOUT(("Can't create send thread (rc %d)\n", rc));
 
-               connection->terminating = TRUE;
+               connection->terminating = ISCSI_STATUS_NO_RESOURCES;
 
                /*
                 * We must close the socket here to force the receive
@@ -653,18 +677,15 @@
                 */
                DEBC(connection, 1,
                        ("Closing Socket %p\n", connection->sock));
-#if __NetBSD_Version__ > 500000000
                mutex_enter(&connection->sock->f_lock);
                connection->sock->f_count += 1;
                mutex_exit(&connection->sock->f_lock);
-#else
-               FILE_USE(connection->sock);
-#endif
                closef(connection->sock);
 
                /* give receive thread time to exit */
                tsleep(connection, PWAIT, "settle", 20);
 
+               release_socket(connection->sock);
                free(connection, M_DEVBUF);
                par->status = ISCSI_STATUS_NO_RESOURCES;
                return rc;
@@ -743,9 +764,12 @@
                return rc;
        }
 
+       /* close the file descriptor */
+       fd_close(par->socket);
+
        connection->threadobj = p;
        connection->login_par = par;
-       connection->terminating = 0;
+       connection->terminating = ISCSI_STATUS_SUCCESS;
        connection->recover++;
        connection->num_timeouts = 0;
        connection->state = ST_SEC_NEG;
@@ -809,6 +833,7 @@
 
        DEBC(connection, 5, ("Connection ReCreated successfully - status %d\n",
                                                 par->status));
+
        return 0;
 }
 
@@ -881,7 +906,7 @@
                        return ISCSI_STATUS_PARAMETER_INVALID;
                }
        }
-       return ISCSI_STATUS_SUCCESS;
+       return 0;
 }
 
 
@@ -1463,10 +1488,11 @@
                        while (conn->sendproc || conn->rcvproc)
                                tsleep(conn, PWAIT, "termwait", 20);
 
-                       /* just in case any CCB is still being processed */
-                       /* that references this connection */
-                       tsleep(conn, PWAIT, "finalwait", 20);
+                       while (conn->usecount > 0)
+                               tsleep(conn, PWAIT, "finalwait", 20);
 
+                       callout_stop(&conn->timeout);
+                       closef(conn->sock);
                        free(conn, M_DEVBUF);
 
                        if (!(--sess->total_connections)) {
diff -r 839fc59fa45f -r cb86a5f030d2 sys/dev/iscsi/iscsi_main.c
--- a/sys/dev/iscsi/iscsi_main.c        Mon Jul 02 21:42:47 2012 +0000
+++ b/sys/dev/iscsi/iscsi_main.c        Tue Jul 03 20:48:40 2012 +0000
@@ -41,11 +41,11 @@
 extern struct cfdriver iscsi_cd;
 
 #if defined(ISCSI_DEBUG)
-int debug_level = ISCSI_DEBUG;
+int iscsi_debug_level = ISCSI_DEBUG;
 #endif
 
 #if defined(ISCSI_PERFTEST)
-int perf_level = 0;
+int iscsi_perf_level = 0;
 #endif
 
 /* Device Structure */
@@ -449,7 +449,6 @@
 
                case ISCSI_STATUS_CHECK_CONDITION:
                        xs->error = XS_SENSE;
-                       xs->error = XS_SENSE;
 #ifdef ISCSI_DEBUG
                        {
                                uint8_t *s = (uint8_t *) (&xs->sense);
diff -r 839fc59fa45f -r cb86a5f030d2 sys/dev/iscsi/iscsi_rcv.c
--- a/sys/dev/iscsi/iscsi_rcv.c Mon Jul 02 21:42:47 2012 +0000
+++ b/sys/dev/iscsi/iscsi_rcv.c Tue Jul 03 20:48:40 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_rcv.c,v 1.1.8.1 2012/06/12 19:41:25 riz Exp $    */
+/*     $NetBSD: iscsi_rcv.c,v 1.1.8.2 2012/07/03 20:48:40 jdc Exp $    */
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -163,6 +163,8 @@
        int i, pad;



Home | Main Index | Thread Index | Old Index