[stgt] [PATCH 2/2] Add MaxQueueCmd iscsi local parameter

Shlomo Pongratz shlomop at mellanox.com
Thu Aug 8 15:03:36 CEST 2013


Make iscsi max queue commannd configurable. This parameter is local like "MaxXmitDataSegmentLength"
i.e. it is not sent to the initiator. The dynamic range of the parmater is [1..512] and the default value is 128,
to keep backward compatibility. The following tgtadm command should be used in order to modify it for a certain target

$ tgtadm --op update --mode target --tid <target-id> --name=MaxQueueCmd --value=<new-value>

Note that the new value will be applicable only to new sessions. So in that respect, after modifying the value,
if the new value need to be used the initiator needs to logout and login again.

Signed-off-by: Shlomo Pongratz <shlomop at mellanox.com>
---
 usr/iscsi/iscsi_if.h |    1 +
 usr/iscsi/iscsid.c   |   20 ++++++++++++--------
 usr/iscsi/iscsid.h   |    5 +++++
 usr/iscsi/iser.c     |   15 ++++++++-------
 usr/iscsi/param.c    |    3 +++
 usr/iscsi/session.c  |    2 ++
 usr/iscsi/target.c   |    1 +
 7 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/usr/iscsi/iscsi_if.h b/usr/iscsi/iscsi_if.h
index cee91c3..012a5ab 100644
--- a/usr/iscsi/iscsi_if.h
+++ b/usr/iscsi/iscsi_if.h
@@ -222,6 +222,7 @@ enum iscsi_param {
 	/* "local" parmas, never sent to the initiator */
 	ISCSI_PARAM_FIRST_LOCAL,
 	ISCSI_PARAM_MAX_XMIT_DLENGTH = ISCSI_PARAM_FIRST_LOCAL,
+	ISCSI_PARAM_MAX_QUEUE_CMD,
 	/* must always be last */
 	ISCSI_PARAM_MAX,
 };
diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c
index ec011dd..1f7ef07 100644
--- a/usr/iscsi/iscsid.c
+++ b/usr/iscsi/iscsid.c
@@ -41,8 +41,6 @@
 #include "tgtadm.h"
 #include "crc32c.h"
 
-#define MAX_QUEUE_CMD	128
-
 int default_nop_interval;
 int default_nop_count;
 
@@ -1092,7 +1090,8 @@ static int iscsi_cmd_rsp_build(struct iscsi_task *task)
 	rsp->cmd_status = scsi_get_result(&task->scmd);
 	rsp->statsn = cpu_to_be32(conn->stat_sn++);
 	rsp->exp_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn);
-	rsp->max_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn + MAX_QUEUE_CMD);
+	rsp->max_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn +
+				     conn->session->max_queue_cmd);
 
 	iscsi_rsp_set_residual(rsp, &task->scmd);
 
@@ -1152,7 +1151,8 @@ static int iscsi_data_rsp_build(struct iscsi_task *task)
 		datalen = maxdatalen;
 
 	rsp->exp_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn);
-	rsp->max_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn + MAX_QUEUE_CMD);
+	rsp->max_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn +
+				     conn->session->max_queue_cmd);
 
 	conn->rsp.datasize = datalen;
 	hton24(rsp->dlength, datalen);
@@ -1831,7 +1831,8 @@ static int iscsi_logout_tx_start(struct iscsi_task *task)
 	rsp->itt = task->req.itt;
 	rsp->statsn = cpu_to_be32(conn->stat_sn++);
 	rsp->exp_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn);
-	rsp->max_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn + MAX_QUEUE_CMD);
+	rsp->max_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn +
+				     conn->session->max_queue_cmd);
 
 	return 0;
 }
@@ -1848,7 +1849,8 @@ static int iscsi_noop_in_tx_start(struct iscsi_task *task)
 	rsp->ttt = task->req.ttt;
 	rsp->statsn = cpu_to_be32(conn->stat_sn);
 	rsp->exp_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn);
-	rsp->max_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn + MAX_QUEUE_CMD);
+	rsp->max_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn +
+				     conn->session->max_queue_cmd);
 
 	/* TODO: honor max_burst */
 	conn->rsp.datasize = task->len;
@@ -1880,7 +1882,8 @@ static int iscsi_noop_out_tx_start(struct iscsi_task *task, int *is_rsp)
 		rsp->ttt = cpu_to_be32(ISCSI_RESERVED_TAG);
 		rsp->statsn = cpu_to_be32(conn->stat_sn++);
 		rsp->exp_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn);
-		rsp->max_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn + MAX_QUEUE_CMD);
+		rsp->max_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn +
+					     conn->session->max_queue_cmd);
 
 		/* TODO: honor max_burst */
 		conn->rsp.datasize = task->len;
@@ -1904,7 +1907,8 @@ static int iscsi_tm_tx_start(struct iscsi_task *task)
 
 	rsp->statsn = cpu_to_be32(conn->stat_sn++);
 	rsp->exp_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn);
-	rsp->max_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn + MAX_QUEUE_CMD);
+	rsp->max_cmdsn = cpu_to_be32(conn->session->exp_cmd_sn +
+				     conn->session->max_queue_cmd);
 
 	return 0;
 }
diff --git a/usr/iscsi/iscsid.h b/usr/iscsi/iscsid.h
index 0710ccb..1b4065c 100644
--- a/usr/iscsi/iscsid.h
+++ b/usr/iscsi/iscsid.h
@@ -40,6 +40,10 @@
 #define be32_to_cpu(x)	__be32_to_cpu(x)
 #define be64_to_cpu(x)	__be64_to_cpu(x)
 
+#define MAX_QUEUE_CMD_MIN	1
+#define MAX_QUEUE_CMD_DEF	128
+#define MAX_QUEUE_CMD_MAX	512
+
 #define ISCSI_NAME_LEN 256
 
 #define DIGEST_ALL		(DIGEST_NONE | DIGEST_CRC32C)
@@ -90,6 +94,7 @@ struct iscsi_session {
 	struct list_head pending_cmd_list;
 
 	uint32_t exp_cmd_sn;
+	uint32_t max_queue_cmd;
 
 	struct param session_param[ISCSI_PARAM_MAX];
 
diff --git a/usr/iscsi/iser.c b/usr/iscsi/iser.c
index 3c07276..01c0cd9 100644
--- a/usr/iscsi/iser.c
+++ b/usr/iscsi/iser.c
@@ -83,8 +83,7 @@ char *iser_portal_addr;
 #define MAX_POLL_WC 32
 
 #define DEFAULT_POOL_SIZE_MB    1024
-#define ISER_MAX_QUEUE_CMD      128     /* iSCSI cmd window size */
-#define MAX_CQ_ENTRIES          (128 * 1024)
+#define MAX_CQ_ENTRIES          (MAX_QUEUE_CMD_MAX * DEFAULT_POOL_SIZE_MB)
 
 #define MASK_BY_BIT(b)  	((1UL << b) - 1)
 #define ALIGN_TO_BIT(x, b)      ((((unsigned long)x) + MASK_BY_BIT(b)) & \
@@ -556,7 +555,7 @@ static inline void iser_set_rsp_stat_sn(struct iscsi_session *session,
 	if (session) {
 		rsp->exp_statsn = cpu_to_be32(session->exp_cmd_sn);
 		rsp->max_statsn = cpu_to_be32(session->exp_cmd_sn +
-					      ISER_MAX_QUEUE_CMD);
+					      session->max_queue_cmd);
 	}
 }
 
@@ -1121,6 +1120,7 @@ int iser_login_complete(struct iscsi_connection *iscsi_conn)
 	unsigned int trdsl;
 	/* unsigned int irdsl; */
 	unsigned int outst_pdu, hdrsz;
+	uint32_t max_q_cmd;
 	int err = -1;
 
 	dprintf("entry\n");
@@ -1142,9 +1142,10 @@ int iser_login_complete(struct iscsi_connection *iscsi_conn)
 #define ISER_MAX_RX_MISC_PDUS   4
 #define ISER_MAX_TX_MISC_PDUS   6
 
+	max_q_cmd = iscsi_conn->session_param[ISCSI_PARAM_MAX_QUEUE_CMD].val;
 	/* if (outst_pdu == 0) // ToDo: outstanding pdus num */
 	outst_pdu =
-		3 * ISER_MAX_QUEUE_CMD * (1 + ISER_INFLIGHT_DATAOUTS) +
+		3 * max_q_cmd * (1 + ISER_INFLIGHT_DATAOUTS) +
 		ISER_MAX_RX_MISC_PDUS + ISER_MAX_TX_MISC_PDUS;
 
 	/* RDSLs do not include headers. */
@@ -2656,10 +2657,10 @@ static int iser_queue_task(struct iscsi_session *session,
 		cmd_sn = be32_to_cpu(task->pdu.bhs->statsn);
 	}
 
-	/* cmd_sn > (exp_cmd_sn+ISER_MAX_QUEUE_CMD), i.e. beyond allowed window */
-	if (cmdsn_cmp(cmd_sn, session->exp_cmd_sn+ISER_MAX_QUEUE_CMD) == 1) {
+	/* cmd_sn > (exp_cmd_sn+max_queue_cmd), i.e. beyond allowed window */
+	if (cmdsn_cmp(cmd_sn, session->exp_cmd_sn+session->max_queue_cmd) == 1) {
 		eprintf("unexpected cmd_sn:0x%x, max:0x%x\n",
-			cmd_sn, session->exp_cmd_sn+ISER_MAX_QUEUE_CMD);
+			cmd_sn, session->exp_cmd_sn+session->max_queue_cmd);
 		return -EINVAL;
 	}
 
diff --git a/usr/iscsi/param.c b/usr/iscsi/param.c
index 0d9788b..5fcedd1 100644
--- a/usr/iscsi/param.c
+++ b/usr/iscsi/param.c
@@ -368,6 +368,9 @@ struct iscsi_key session_keys[] = {
 	/* "local" parmas, never sent to the initiator */
 	[ISCSI_PARAM_MAX_XMIT_DLENGTH] =
 	{"MaxXmitDataSegmentLength", 8192, 512, 16777215, &minimum_ops},
+	[ISCSI_PARAM_MAX_QUEUE_CMD] =
+	{"MaxQueueCmd", MAX_QUEUE_CMD_DEF, MAX_QUEUE_CMD_MIN,
+			MAX_QUEUE_CMD_MAX, &minimum_ops},
 	[ISCSI_PARAM_MAX] =
 	{NULL,},
 };
diff --git a/usr/iscsi/session.c b/usr/iscsi/session.c
index 2c675b8..057d014 100644
--- a/usr/iscsi/session.c
+++ b/usr/iscsi/session.c
@@ -152,6 +152,8 @@ int session_create(struct iscsi_connection *conn)
 	memcpy(session->session_param, conn->session_param,
 	       sizeof(session->session_param));
 
+	session->max_queue_cmd = session->session_param[ISCSI_PARAM_MAX_QUEUE_CMD].val;
+
 	return 0;
 }
 
diff --git a/usr/iscsi/target.c b/usr/iscsi/target.c
index 4797b4c..5a3bd1e 100644
--- a/usr/iscsi/target.c
+++ b/usr/iscsi/target.c
@@ -456,6 +456,7 @@ int iscsi_target_create(struct target *t)
 		[ISCSI_PARAM_MAX_OUTST_PDU] =  {0, 0},  /* not in open-iscsi */
 		/* "local" parmas, never sent to the initiator */
 		[ISCSI_PARAM_MAX_XMIT_DLENGTH] = {0, 8192},  /* do not edit */
+ 		[ISCSI_PARAM_MAX_QUEUE_CMD] = {0, MAX_QUEUE_CMD_DEF},
 	};
 
 	target = malloc(sizeof(*target));
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list