Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/iscsi Add more debugging, fix filehandle usage, logi...



details:   https://anonhg.NetBSD.org/src/rev/cf9156a24887
branches:  trunk
changeset: 779879:cf9156a24887
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sun Jun 24 17:01:35 2012 +0000

description:
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.

diffstat:

 sys/dev/iscsi/iscsi_ioctl.c |  24 +++++++------
 sys/dev/iscsi/iscsi_rcv.c   |  46 ++++++++++++++----------
 sys/dev/iscsi/iscsi_send.c  |   7 ++-
 sys/dev/iscsi/iscsi_text.c  |  82 ++++++++++++++++++++++++++++++++++++--------
 sys/dev/iscsi/iscsi_utils.c |  10 +++--
 5 files changed, 115 insertions(+), 54 deletions(-)

diffs (truncated from 447 to 300 lines):

diff -r 125091cfa1cc -r cf9156a24887 sys/dev/iscsi/iscsi_ioctl.c
--- a/sys/dev/iscsi/iscsi_ioctl.c       Sun Jun 24 16:24:34 2012 +0000
+++ b/sys/dev/iscsi/iscsi_ioctl.c       Sun Jun 24 17:01:35 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_ioctl.c,v 1.3 2012/06/09 06:19:58 mlelstv Exp $  */
+/*     $NetBSD: iscsi_ioctl.c,v 1.4 2012/06/24 17:01:35 mlelstv Exp $  */
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -488,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);
@@ -634,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) {
@@ -646,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;
 
@@ -666,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
@@ -716,9 +719,6 @@
        session->mru_connection = connection;
        CS_END;
 
-       /* close the file descriptor */
-       fd_close(par->socket);
-
        DEBC(connection, 5, ("Connection created successfully!\n"));
        return 0;
 }
@@ -764,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;
@@ -831,9 +834,6 @@
        DEBC(connection, 5, ("Connection ReCreated successfully - status %d\n",
                                                 par->status));
 
-       /* close the file descriptor */
-       fd_close(par->socket);
-
        return 0;
 }
 
@@ -906,7 +906,7 @@
                        return ISCSI_STATUS_PARAMETER_INVALID;
                }
        }
-       return ISCSI_STATUS_SUCCESS;
+       return 0;
 }
 
 
@@ -1491,6 +1491,8 @@
                        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 125091cfa1cc -r cf9156a24887 sys/dev/iscsi/iscsi_rcv.c
--- a/sys/dev/iscsi/iscsi_rcv.c Sun Jun 24 16:24:34 2012 +0000
+++ b/sys/dev/iscsi/iscsi_rcv.c Sun Jun 24 17:01:35 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_rcv.c,v 1.2 2012/06/05 16:36:06 mhitch Exp $     */
+/*     $NetBSD: iscsi_rcv.c,v 1.3 2012/06/24 17:01:35 mlelstv Exp $    */
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -163,6 +163,8 @@
        int i, pad;
        connection_t *conn = pdu->connection;
 
+       DEBOUT(("read_pdu_data: data segment length = %d\n",
+               ntoh3(pdu->pdu.DataSegmentLength)));
        if (!(len = ntoh3(pdu->pdu.DataSegmentLength))) {
                return 0;
        }
@@ -324,8 +326,11 @@
                ack_sernum(&conn->StatSN_buf, sn);
 
        if (rc != 1) {
-               if (!rc)
+               if (rc == 0) {
+                       DEBOUT(("Duplicate PDU, ExpSN %d, Recvd: %d\n",
+                               conn->StatSN_buf.ExpSN, sn));
                        return -1;
+               }
 
                if (rc < 0) {
                        DEBOUT(("Excessive outstanding Status PDUs, ExpSN %d, Recvd: %d\n",
@@ -410,8 +415,9 @@
 {
        int rc;
 
-       DEBC(conn, 9, ("Received Login Response PDU, op=%x, flags=%x\n",
-                       pdu->pdu.Opcode, pdu->pdu.Flags));
+       DEBC(conn, 9, ("Received Login Response PDU, op=%x, flags=%x, sn=%u\n",
+                       pdu->pdu.Opcode, pdu->pdu.Flags,
+                       ntohl(pdu->pdu.p.login_rsp.StatSN)));
 
        if (req_ccb == NULL) {
                /* Duplicate?? */
@@ -419,31 +425,31 @@
                return -1;
        }
 
-       if (!conn->StatSN_buf.next_sn)
-               conn->StatSN_buf.next_sn = conn->StatSN_buf.ExpSN =
-                       ntohl(pdu->pdu.p.login_rsp.StatSN) + 1;
-       else if (check_StatSN(conn, pdu->pdu.p.login_rsp.StatSN, TRUE))
-               return -1;
-
-       if (pdu->temp_data_len) {
-               if ((rc = collect_text_data(pdu, req_ccb)) != 0) {
-                       return max(rc, 0);
-               }
-       }
-
        if (pdu->pdu.p.login_rsp.StatusClass) {
                DEBC(conn, 1, ("Login problem - Class = %x, Detail = %x\n",
                                pdu->pdu.p.login_rsp.StatusClass,
                                pdu->pdu.p.login_rsp.StatusDetail));
 
                req_ccb->status = ISCSI_STATUS_LOGIN_FAILED;
-       } else {
-               negotiate_login(conn, pdu, req_ccb);
-               /* negotiate_login will decide whether login is complete or not */
+               /* XXX */
+               wake_ccb(req_ccb);
                return 0;
        }
 
-       wake_ccb(req_ccb);
+       if (!conn->StatSN_buf.next_sn) {
+               conn->StatSN_buf.next_sn = conn->StatSN_buf.ExpSN =
+                       ntohl(pdu->pdu.p.login_rsp.StatSN) + 1;
+       } else if (check_StatSN(conn, pdu->pdu.p.login_rsp.StatSN, TRUE))
+               return -1;
+
+       if (pdu->temp_data_len) {
+               if ((rc = collect_text_data(pdu, req_ccb)) != 0)
+                       return max(rc, 0);
+       }
+
+       negotiate_login(conn, pdu, req_ccb);
+
+       /* negotiate_login will decide whether login is complete or not */
        return 0;
 }
 
diff -r 125091cfa1cc -r cf9156a24887 sys/dev/iscsi/iscsi_send.c
--- a/sys/dev/iscsi/iscsi_send.c        Sun Jun 24 16:24:34 2012 +0000
+++ b/sys/dev/iscsi/iscsi_send.c        Sun Jun 24 17:01:35 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_send.c,v 1.4 2012/06/19 14:19:46 martin Exp $    */
+/*     $NetBSD: iscsi_send.c,v 1.5 2012/06/24 17:01:35 mlelstv Exp $   */
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -344,19 +344,20 @@
                fp = conn->sock;
 
                /*
-                * We must close the socket here to force the receive
+                * We shutdown the socket here to force the receive
                 * thread to wake up
                 */
                DEBC(conn, 9, ("Closing Socket %p\n", conn->sock));
                solock((struct socket *) fp->f_data);
                soshutdown((struct socket *) fp->f_data, SHUT_RDWR);
                sounlock((struct socket *) fp->f_data);
-               closef(fp);
 
                /* wake up any non-reassignable waiting CCBs */
                for (ccb = TAILQ_FIRST(&conn->ccbs_waiting); ccb != NULL; ccb = nccb) {
                        nccb = TAILQ_NEXT(ccb, chain);
                        if (!(ccb->flags & CCBF_REASSIGN) || ccb->pdu_waiting == NULL) {
+                               DEBC(conn, 9, ("Terminating CCB %p (t=%p)\n",
+                                       ccb,&ccb->timeout));
                                ccb->status = conn->terminating;
                                wake_ccb(ccb);
                        } else {
diff -r 125091cfa1cc -r cf9156a24887 sys/dev/iscsi/iscsi_text.c
--- a/sys/dev/iscsi/iscsi_text.c        Sun Jun 24 16:24:34 2012 +0000
+++ b/sys/dev/iscsi/iscsi_text.c        Sun Jun 24 17:01:35 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_text.c,v 1.4 2012/06/09 06:19:58 mlelstv Exp $   */
+/*     $NetBSD: iscsi_text.c,v 1.5 2012/06/24 17:01:35 mlelstv Exp $   */
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -34,6 +34,9 @@
 #include <sys/md5.h>
 #include <sys/cprng.h>
 
+/* define to send T_BIGNUM in hex format instead of base64 */
+/* #define ISCSI_HEXBIGNUMS */
+
 #define isdigit(x) ((x) >= '0' && (x) <= '9')
 #define toupper(x) ((x) & ~0x20)
 
@@ -555,6 +558,10 @@
                return skiptozero(bp);
        }
 
+       DEB(10, ("get_par: key <%s>=%d, val=%d, ret %p\n",
+                       buf, i, entries[i].val, bp));
+       DEB(10, ("get_par: value '%s'\n",bp));
+
        switch (entries[i].val) {
        case T_NUM:
                bp = get_numval(bp, &par->val.nval[0]);
@@ -589,8 +596,6 @@
                bp = NULL;
                break;
        }
-       DEB(10, ("get_par: key <%s>=%d, val=%d, ret %p\n",
-                       buf, i, entries[i].val, bp));
        return bp;
 }
 
@@ -619,6 +624,38 @@
        return cc;
 }
 
+/*
+ * put_bignumval:
+ *    Write a large numeric value.
+ *    NOTE: Overwrites source string.
+ *
+ *    Parameter:
+ *          buf      The buffer pointer
+ *          par      The parameter
+ *
+ *    Returns:    The pointer to the next parameter, NULL on error.
+ */
+
+STATIC unsigned
+put_bignumval(negotiation_parameter_t *par, uint8_t *buf)
+{
+#ifdef ISCSI_HEXBIGNUMS
+       int k, c;
+
+       my_strcpy(buf, "0x");
+       for (k=0; k<par->list_num; ++k) {
+               c = par->val.sval[k] >> 4;
+               buf[2+2*k] = c < 10 ? '0' + c : 'a' + (c-10);
+               c = par->val.sval[k] & 0xf;
+               buf[2+2*k+1] = c < 10 ? '0' + c : 'a' + (c-10);
+       }
+       buf[2+2*k] = '\0';
+
+       return 2+2*par->list_num;
+#else
+       return base64_encode(par->val.sval, par->list_num, buf);
+#endif
+}
 
 /*
  * put_parameter:
@@ -635,9 +672,12 @@
 put_parameter(uint8_t *buf, unsigned len, negotiation_parameter_t *par)
 {



Home | Main Index | Thread Index | Old Index