Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/iscsi factor out sernum handling.



details:   https://anonhg.NetBSD.org/src/rev/0b84d1626422
branches:  trunk
changeset: 345574:0b84d1626422
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Wed Jun 01 04:19:08 2016 +0000

description:
factor out sernum handling.
make incrementing sernum atomic.
declare variables for atomic operations as volatile.

diffstat:

 sys/dev/iscsi/iscsi_globals.h |   9 ++++++---
 sys/dev/iscsi/iscsi_send.c    |  15 ++++++---------
 sys/dev/iscsi/iscsi_utils.c   |  34 +++++++++++++++++++++++++++++++++-
 3 files changed, 45 insertions(+), 13 deletions(-)

diffs (136 lines):

diff -r a019d3c03317 -r 0b84d1626422 sys/dev/iscsi/iscsi_globals.h
--- a/sys/dev/iscsi/iscsi_globals.h     Wed Jun 01 04:15:54 2016 +0000
+++ b/sys/dev/iscsi/iscsi_globals.h     Wed Jun 01 04:19:08 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_globals.h,v 1.14 2016/05/29 13:51:16 mlelstv Exp $       */
+/*     $NetBSD: iscsi_globals.h,v 1.15 2016/06/01 04:19:08 mlelstv Exp $       */
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -289,7 +289,7 @@
        int                     sense_len_got; /* actual sense data length */
 
        pdu_t                   *pdu_waiting; /* PDU waiting to be ack'ed */
-       uint32_t                CmdSN; /* CmdSN associated with waiting PDU */
+       volatile uint32_t       CmdSN; /* CmdSN associated with waiting PDU */
 
        int                     flags;
        connection_t            *connection; /* connection for CCB */
@@ -363,7 +363,7 @@
                                        /* if closing down: status */
        int                             recover; /* recovery count */
                /* (reset on first successful data transfer) */
-       unsigned                        usecount; /* number of active CCBs */
+       volatile unsigned               usecount; /* number of active CCBs */
 
        bool                            destroy; /* conn will be destroyed */
        bool                            in_session;
@@ -724,6 +724,9 @@
 int add_sernum(sernum_buffer_t *, uint32_t);
 uint32_t ack_sernum(sernum_buffer_t *, uint32_t);
 
+uint32_t get_sernum(session_t *, bool);
+int sernum_in_window(session_t *);
+
 /* in iscsi_text.c */
 
 int assemble_login_parameters(connection_t *, ccb_t *, pdu_t *);
diff -r a019d3c03317 -r 0b84d1626422 sys/dev/iscsi/iscsi_send.c
--- a/sys/dev/iscsi/iscsi_send.c        Wed Jun 01 04:15:54 2016 +0000
+++ b/sys/dev/iscsi/iscsi_send.c        Wed Jun 01 04:19:08 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_send.c,v 1.16 2016/05/29 13:51:16 mlelstv Exp $  */
+/*     $NetBSD: iscsi_send.c,v 1.17 2016/06/01 04:19:08 mlelstv Exp $  */
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -145,6 +145,7 @@
        pdu_t *opdu;
        int no_tm = 1;
        int rc = 1;
+       uint32_t sn;
 
        if ((conn = assign_connection(sess, FALSE)) == NULL) {
                DEB(1, ("Reassign_tasks of Session %d, connection %d failed, "
@@ -255,14 +256,12 @@
                        mutex_enter(&sess->lock);
                        if (ccb->CmdSN < sess->ExpCmdSN) {
                                pdu = ccb->pdu_waiting;
+                               sn = get_sernum(sess, !(pdu->pdu.Opcode & OP_IMMEDIATE));
 
                                /* update CmdSN */
                                DEBC(conn, 1, ("Resend Updating CmdSN - old %d, new %d\n",
                                           ccb->CmdSN, sess->CmdSN));
-                               ccb->CmdSN = sess->CmdSN;
-                               if (!(pdu->pdu.Opcode & OP_IMMEDIATE)) {
-                                       sess->CmdSN++;
-                               }
+                               ccb->CmdSN = sn;
                                pdu->pdu.p.command.CmdSN = htonl(ccb->CmdSN);
                        }
                        mutex_exit(&sess->lock);
@@ -1351,7 +1350,7 @@
        mutex_enter(&sess->lock);
        while (/*CONSTCOND*/ISCSI_THROTTLING_ENABLED &&
            /*CONSTCOND*/!ISCSI_SERVER_TRUSTED &&
-           !sn_a_le_b(sess->CmdSN, sess->MaxCmdSN)) {
+           !sernum_in_window(sess)) {
 
                ccb->disp = disp;
                if (waitok)
@@ -1419,9 +1418,7 @@
        ccb->flags |= CCBF_REASSIGN;
 
        mutex_enter(&sess->lock);
-       ccb->CmdSN = sess->CmdSN;
-       if (!immed)
-               sess->CmdSN++;
+       ccb->CmdSN = get_sernum(sess, !immed);
        mutex_exit(&sess->lock);
 
        pdu->p.command.CmdSN = htonl(ccb->CmdSN);
diff -r a019d3c03317 -r 0b84d1626422 sys/dev/iscsi/iscsi_utils.c
--- a/sys/dev/iscsi/iscsi_utils.c       Wed Jun 01 04:15:54 2016 +0000
+++ b/sys/dev/iscsi/iscsi_utils.c       Wed Jun 01 04:19:08 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_utils.c,v 1.9 2016/05/29 13:51:16 mlelstv Exp $  */
+/*     $NetBSD: iscsi_utils.c,v 1.10 2016/06/01 04:19:08 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2004,2005,2006,2008 The NetBSD Foundation, Inc.
@@ -678,3 +678,35 @@
 
        return buff->ExpSN;
 }
+
+/*
+ * next_sernum:
+ *   Return the current command serial number of the session
+ *   and optionally increment it for the next query
+ */
+uint32_t
+get_sernum(session_t *sess, bool bump)
+{
+       uint32_t sn;
+
+       KASSERT(mutex_owned(&sess->lock));
+
+       sn = sess->CmdSN;
+       if (bump)
+               atomic_inc_32(&sess->CmdSN);
+       return sn;
+}
+
+/*
+ * sernum_in_window:
+ *   Check wether serial number is in send window
+ *
+ */
+int
+sernum_in_window(session_t *sess)
+{
+
+       KASSERT(mutex_owned(&sess->lock));
+       return sn_a_le_b(sess->CmdSN, sess->MaxCmdSN);
+}
+



Home | Main Index | Thread Index | Old Index