Module Name: src
Committed By: mlelstv
Date: Wed Jun 1 04:19:08 UTC 2016
Modified Files:
src/sys/dev/iscsi: iscsi_globals.h iscsi_send.c iscsi_utils.c
Log Message:
factor out sernum handling.
make incrementing sernum atomic.
declare variables for atomic operations as volatile.
To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/iscsi/iscsi_globals.h
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/iscsi/iscsi_send.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/iscsi/iscsi_utils.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/iscsi/iscsi_globals.h
diff -u src/sys/dev/iscsi/iscsi_globals.h:1.14 src/sys/dev/iscsi/iscsi_globals.h:1.15
--- src/sys/dev/iscsi/iscsi_globals.h:1.14 Sun May 29 13:51:16 2016
+++ src/sys/dev/iscsi/iscsi_globals.h Wed Jun 1 04:19:08 2016
@@ -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 @@ struct ccb_s {
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 @@ struct connection_s {
/* 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 @@ void init_sernum(sernum_buffer_t *);
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 *);
Index: src/sys/dev/iscsi/iscsi_send.c
diff -u src/sys/dev/iscsi/iscsi_send.c:1.16 src/sys/dev/iscsi/iscsi_send.c:1.17
--- src/sys/dev/iscsi/iscsi_send.c:1.16 Sun May 29 13:51:16 2016
+++ src/sys/dev/iscsi/iscsi_send.c Wed Jun 1 04:19:08 2016
@@ -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 @@ reassign_tasks(connection_t *oldconn)
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 @@ reassign_tasks(connection_t *oldconn)
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 @@ send_command(ccb_t *ccb, ccb_disp_t disp
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 @@ send_command(ccb_t *ccb, ccb_disp_t disp
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);
Index: src/sys/dev/iscsi/iscsi_utils.c
diff -u src/sys/dev/iscsi/iscsi_utils.c:1.9 src/sys/dev/iscsi/iscsi_utils.c:1.10
--- src/sys/dev/iscsi/iscsi_utils.c:1.9 Sun May 29 13:51:16 2016
+++ src/sys/dev/iscsi/iscsi_utils.c Wed Jun 1 04:19:08 2016
@@ -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 @@ ack_sernum(sernum_buffer_t *buff, uint32
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);
+}
+