[stgt] [PATCH 1/1] iscsi: Initial iscsi statistics for stgt.
Daniel Henrique Debonzi
debonzi at linux.vnet.ibm.com
Mon Oct 4 19:08:46 CEST 2010
From: Daniel Henrique Debonzi <debonzi at linux.vnet.ibm.com>
This patch implements some statistics information for the iscsi.
Signed-off-by: Daniel Henrique Debonzi <debonzi at linux.vnet.ibm.com>
---
usr/iscsi/iscsid.h | 2 +
usr/tgtadm.h | 1 +
usr/iscsi/iscsid.c | 29 ++++++++++++++++++-
usr/iscsi/target.c | 78 +++++++++++++++++++++++++++++++++++++++++++--------
usr/tgtadm.c | 2 +
5 files changed, 98 insertions(+), 14 deletions(-)
diff --git a/usr/iscsi/iscsid.h b/usr/iscsi/iscsid.h
index 35bb068..f82366a 100644
--- a/usr/iscsi/iscsid.h
+++ b/usr/iscsi/iscsid.h
@@ -197,6 +197,8 @@ struct iscsi_connection {
} auth;
struct iscsi_transport *tp;
+
+ struct iscsi_stats stats;
};
#define STATE_FREE 0
diff --git a/usr/tgtadm.h b/usr/tgtadm.h
index 8e04a3c..53a9608 100644
--- a/usr/tgtadm.h
+++ b/usr/tgtadm.h
@@ -25,6 +25,7 @@ enum tgtadm_mode {
MODE_SESSION,
MODE_CONNECTION,
MODE_ACCOUNT,
+ MODE_STATS,
};
enum tgtadm_account_dir {
diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c
index facc999..e5be01d 100644
--- a/usr/iscsi/iscsid.c
+++ b/usr/iscsi/iscsid.c
@@ -1918,8 +1918,21 @@ 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++;
+ }
+ }
+
+
if (!conn->rx_size)
conn->rx_iostate = next_state;
@@ -1931,6 +1944,7 @@ void iscsi_rx_handler(struct iscsi_connection *conn)
int ret = 0, hdigest, ddigest;
uint32_t crc;
+
if (conn->state == STATE_SCSI) {
struct param *p = conn->session_param;
hdigest = p[ISCSI_PARAM_HDRDGST_EN].val & DIGEST_CRC32C;
@@ -2085,9 +2099,22 @@ 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;
+ }
+ }
+
if (conn->tx_size)
goto again;
conn->tx_iostate = next_state;
diff --git a/usr/iscsi/target.c b/usr/iscsi/target.c
index f3b1edd..7732898 100644
--- a/usr/iscsi/target.c
+++ b/usr/iscsi/target.c
@@ -453,29 +453,77 @@ static int show_iscsi_param(char *buf, struct param *param, int rest)
return total;
}
-static int iscsi_target_show_session(struct iscsi_target* target, uint64_t sid,
- char *buf, int rest)
+#define __buffer_check(buf, total, len, rest) \
+({ \
+ buf += len; \
+ total += len; \
+ rest -= len; \
+ if (!rest) \
+ return total; \
+})
+
+static struct iscsi_session *iscsi_target_find_session(struct iscsi_target* target,
+ uint64_t sid)
{
- int len = 0, total = 0;
struct iscsi_session *session;
list_for_each_entry(session, &target->sessions_list, slist) {
if (session->tsih == sid)
- len = show_iscsi_param(buf, session->session_param, rest);
- buffer_check(buf, total, len, rest);
+ return session;
}
+ return NULL;
+
+}
+
+static int iscsi_target_show_session(struct iscsi_target* target, uint64_t sid,
+ char *buf, int rest)
+{
+ int len = 0, total = 0;
+ struct iscsi_session *session;
+
+ session = iscsi_target_find_session(target, sid);
+
+ if (session) {
+ len = show_iscsi_param(buf, session->session_param, rest);
+ __buffer_check(buf, total, len, rest);
+
+ }
+
return total;
}
-#define __buffer_check(buf, total, len, rest) \
-({ \
- buf += len; \
- total += len; \
- rest -= len; \
- if (!rest) \
- return total; \
-})
+static int iscsi_target_show_stats(struct iscsi_target* target, uint64_t sid,
+ char *buf, int rest)
+{
+ int len = 0, total = 0;
+ struct iscsi_session *session;
+ struct iscsi_connection *conn;
+
+ session = iscsi_target_find_session(target, sid);
+
+ if (session) {
+ list_for_each_entry(conn, &session->conn_list, clist) {
+ len = snprintf(buf, rest,
+ "rxdata_octets: %lld\n"
+ "txdata_octets: %lld\n"
+ "dataout_pdus: %d\n"
+ "datain_pdus: %d\n"
+ "scsicmd_pdus: %d\n"
+ "scsirsp_pdus: %d\n",
+ conn->stats.rxdata_octets,
+ conn->stats.txdata_octets,
+ conn->stats.dataout_pdus,
+ conn->stats.datain_pdus,
+ conn->stats.scsicmd_pdus,
+ conn->stats.scsirsp_pdus);
+ __buffer_check(buf, total, len, rest);
+ }
+ }
+
+ return total;
+
+}
static int show_redirect_info(struct iscsi_target* target, char *buf, int rest)
{
@@ -526,6 +574,10 @@ int iscsi_target_show(int mode, int tid, uint64_t sid, uint32_t cid, uint64_t lu
len = iscsi_target_show_session(target, sid, buf, rest);
total += len;
break;
+ case MODE_STATS:
+ len = iscsi_target_show_stats(target, sid, buf, rest);
+ total += len;
+ break;
default:
break;
}
diff --git a/usr/tgtadm.c b/usr/tgtadm.c
index fc93ad9..8d7b18a 100644
--- a/usr/tgtadm.c
+++ b/usr/tgtadm.c
@@ -383,7 +383,8 @@ static int str_to_mode(char *str)
return MODE_CONNECTION;
else if (!strcmp("account", str))
return MODE_ACCOUNT;
+ else if (!strcmp("stats", str))
+ return MODE_STATS;
else {
eprintf("unknown mode: %s\n", str);
exit(1);
--
1.6.3.3
--
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