[PATCH RESEND 3/3] collect isci conn stats for iser connections

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

 



From: Alexander Nezhinsky <alexandern@xxxxxxxxxxxx>

implement iscsi stats update functions iscsi_update_conn_stats_{rx|tx}
common for iscsi and iser. In iser treat rdma-read as data-out pdu, and
rdma-write as data-out pdu for stat collection purposes.

Signed-off-by: Alexander Nezhinsky <alexandern@xxxxxxxxxxxx>
---
 usr/iscsi/conn.c   |   26 ++++++++++++++++++++++++++
 usr/iscsi/iscsid.c |   32 ++++++++------------------------
 usr/iscsi/iscsid.h |    2 ++
 usr/iscsi/iser.c   |   15 +++++++++++----
 4 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/usr/iscsi/conn.c b/usr/iscsi/conn.c
index 6111566..17aa3e3 100644
--- a/usr/iscsi/conn.c
+++ b/usr/iscsi/conn.c
@@ -244,3 +244,29 @@ tgtadm_err conn_close_admin(uint32_t tid, uint64_t sid, uint32_t cid)
 
 	return sess_found ? TGTADM_NO_CONNECTION : TGTADM_NO_SESSION;
 }
+
+void iscsi_update_conn_stats_rx(struct iscsi_connection *conn, int size, int opcode)
+{
+	conn->stats.rxdata_octets += (uint64_t)size;
+
+	if (unlikely(opcode < 0))
+		return;
+
+	if (opcode == ISCSI_OP_SCSI_CMD)
+		conn->stats.scsicmd_pdus++;
+	else if (opcode == ISCSI_OP_SCSI_DATA_OUT)
+		conn->stats.dataout_pdus++;
+}
+
+void iscsi_update_conn_stats_tx(struct iscsi_connection *conn, int size, int opcode)
+{
+	conn->stats.txdata_octets += (uint64_t)size;
+
+	if (unlikely(opcode < 0))
+		return;
+
+	if (opcode == ISCSI_OP_SCSI_DATA_IN)
+		conn->stats.datain_pdus++;
+	else if (opcode == ISCSI_OP_SCSI_CMD_RSP)
+		conn->stats.scsirsp_pdus++;
+}
diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c
index 4545018..96abbfc 100644
--- a/usr/iscsi/iscsid.c
+++ b/usr/iscsi/iscsid.c
@@ -1942,7 +1942,7 @@ nodata:
 
 static int do_recv(struct iscsi_connection *conn, int next_state)
 {
-	int ret;
+	int ret, opcode;
 
 	ret = conn->tp->ep_read(conn, conn->rx_buffer, conn->rx_size);
 	if (!ret) {
@@ -1955,20 +1955,12 @@ static int do_recv(struct iscsi_connection *conn, int next_state)
 			return -EIO;
 	}
 
-	conn->stats.rxdata_octets += ret;
 	conn->rx_size -= ret;
 	conn->rx_buffer += ret;
 
-	if (conn->rx_iostate == IOSTATE_RX_BHS) {
-		switch (conn->req.bhs.opcode & ISCSI_OPCODE_MASK) {
-		case ISCSI_OP_SCSI_CMD:
-			conn->stats.scsicmd_pdus++;
-			break;
-		case ISCSI_OP_SCSI_DATA_OUT:
-			conn->stats.dataout_pdus++;
-		}
-	}
-
+	opcode = (conn->rx_iostate == IOSTATE_RX_BHS) ?
+		(conn->req.bhs.opcode & ISCSI_OPCODE_MASK) : -1;
+	iscsi_update_conn_stats_rx(conn, ret, opcode);
 
 	if (!conn->rx_size)
 		conn->rx_iostate = next_state;
@@ -2140,7 +2132,7 @@ again:
 
 static int do_send(struct iscsi_connection *conn, int next_state)
 {
-	int ret;
+	int ret, opcode;
 again:
 	ret = conn->tp->ep_write_begin(conn, conn->tx_buffer, conn->tx_size);
 	if (ret < 0) {
@@ -2152,20 +2144,12 @@ again:
 		return -EIO;
 	}
 
-	conn->stats.txdata_octets += ret;
 	conn->tx_size -= ret;
 	conn->tx_buffer += ret;
 
-	if (conn->tx_iostate == IOSTATE_TX_BHS) {
-		switch (conn->rsp.bhs.opcode) {
-		case ISCSI_OP_SCSI_DATA_IN:
-			conn->stats.datain_pdus++;
-			break;
-		case ISCSI_OP_SCSI_CMD_RSP:
-			conn->stats.scsirsp_pdus++;
-			break;
-		}
-	}
+	opcode = (conn->tx_iostate == IOSTATE_TX_BHS) ?
+			(conn->req.bhs.opcode & ISCSI_OPCODE_MASK) : -1;
+	iscsi_update_conn_stats_tx(conn, ret, opcode);
 
 	if (conn->tx_size)
 		goto again;
diff --git a/usr/iscsi/iscsid.h b/usr/iscsi/iscsid.h
index f274857..444661b 100644
--- a/usr/iscsi/iscsid.h
+++ b/usr/iscsi/iscsid.h
@@ -317,6 +317,8 @@ extern int iscsi_transportid(int tid, uint64_t itn_id, char *buf, int size);
 extern int iscsi_add_portal(char *addr, int port, int tpgt);
 extern int iscsi_delete_portal(char *addr, int port);
 extern int iscsi_param_parse_portals(char *p, int do_add, int do_delete);
+extern void iscsi_update_conn_stats_rx(struct iscsi_connection *conn, int size, int opcode);
+extern void iscsi_update_conn_stats_tx(struct iscsi_connection *conn, int size, int opcode);
 
 /* iscsid.c iscsi_task */
 extern void iscsi_free_task(struct iscsi_task *task);
diff --git a/usr/iscsi/iser.c b/usr/iscsi/iser.c
index f864ff9..2c7679d 100644
--- a/usr/iscsi/iser.c
+++ b/usr/iscsi/iser.c
@@ -2406,7 +2406,6 @@ static int iser_scsi_cmd_rx(struct iser_task *task)
 			task->unsol_remains = 0;
 			task->rdma_rd_sz = 0;
 			task->rdma_rd_remains = 0;
-
 		} else {
 			scsi_set_data_dir(&task->scmd, DATA_NONE);
 			task->out_len = 0;
@@ -2717,6 +2716,8 @@ static int iser_parse_req_headers(struct iser_task *task)
 	struct iser_conn *conn = task->conn;
 	struct iser_hdr *iser_hdr = task->pdu.iser_hdr;
 	struct iscsi_hdr *iscsi_hdr = task->pdu.bhs;
+	unsigned pdu_dlength = ntoh24(iscsi_hdr->dlength);
+	unsigned pdu_len = pdu_dlength + sizeof(struct iscsi_hdr);
 	int err = -1;
 
 	switch (iser_hdr->flags & 0xF0) {
@@ -2754,12 +2755,14 @@ static int iser_parse_req_headers(struct iser_task *task)
 
 	task->pdu.ahssize = iscsi_hdr->hlength * 4;
 	task->pdu.membuf.addr += task->pdu.ahssize;
-	task->pdu.membuf.size = ntoh24(iscsi_hdr->dlength);
+	pdu_len += task->pdu.ahssize;
+	task->pdu.membuf.size = pdu_dlength;
 	task->pdu.membuf.rdma = 0;
 
 	task->tag = iscsi_hdr->itt;
 	task->cmd_sn = be32_to_cpu(iscsi_hdr->statsn);
 	conn->h.exp_stat_sn = be32_to_cpu(iscsi_hdr->exp_statsn);
+	iscsi_update_conn_stats_rx(&conn->h, pdu_len, task->opcode);
 
 	return err;
 }
@@ -2884,9 +2887,11 @@ static void iser_tx_complete_handler(struct iser_work_req *txd)
 {
 	struct iser_task *task = txd->task;
 	struct iser_conn *conn = task->conn;
+	int opcode = task->pdu.bhs->opcode & ISCSI_OPCODE_MASK;
 
-	dprintf("conn:%p task:%p tag:0x%04"PRIx64 "\n",
-		&conn->h, task, task->tag);
+	iscsi_update_conn_stats_tx(&conn->h, txd->sge.length, opcode);
+	dprintf("conn:%p task:%p tag:0x%04"PRIx64 " opcode:0x%x\n",
+		&conn->h, task, task->tag, opcode);
 	iser_conn_put(conn);
 
 	list_del(&task->tx_list); /* remove from conn->sent_list */
@@ -2909,6 +2914,7 @@ static void iser_rdma_wr_complete_handler(struct iser_work_req *rdmad)
 	struct iser_task *task = rdmad->task;
 	struct iser_conn *conn = task->conn;
 
+        iscsi_update_conn_stats_tx(&conn->h, rdmad->sge.length, ISCSI_OP_SCSI_DATA_IN);
 	dprintf("conn:%p task:%p tag:0x%04"PRIx64 "\n",
 		&conn->h, task, task->tag);
 	iser_conn_put(conn);
@@ -2922,6 +2928,7 @@ static void iser_rdma_rd_complete_handler(struct iser_work_req *rdmad)
 	struct iser_task *task = rdmad->task;
 	struct iser_conn *conn = task->conn;
 
+        iscsi_update_conn_stats_rx(&conn->h, rdmad->sge.length, ISCSI_OP_SCSI_DATA_OUT);
 	task->rdma_rd_remains -= rdmad->sge.length;
 	dprintf("conn:%p task:%p tag:0x%04"PRIx64 ", rems rdma:%d unsol:%d\n",
 		&conn->h, task, task->tag, task->rdma_rd_remains,
-- 
1.7.9.5

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


[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux