[stgt] [PATCH 1/1] iscsi: Initial iscsi statistics for stgt.

Daniel Henrique Debonzi debonzi at linux.vnet.ibm.com
Wed Oct 13 18:02:14 CEST 2010


Hi Ronnie,

I will be looking for it soon.

regards,
Daniel Debonzi

ronnie sahlberg wrote:
> Hi Daniel,
> 
> Very nice!
> 
> Can you add something to the manpage for this too?
> 
> 
> regards
> ronnie sahlberg
> 
> On Sat, Oct 9, 2010 at 1:40 AM, Daniel Henrique Debonzi
> <debonzi at linux.vnet.ibm.com> wrote:
>> 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.c |   27 ++++++++++++++++++
>>  usr/iscsi/iscsid.h |    2 +
>>  usr/iscsi/target.c |   79 +++++++++++++++++++++++++++++++++++++++++++--------
>>  usr/tgtadm.c       |    2 +
>>  usr/tgtadm.h       |    1 +
>>  5 files changed, 98 insertions(+), 13 deletions(-)
>>
>> diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c
>> index 5b13d90..3a79d93 100644
>> --- a/usr/iscsi/iscsid.c
>> +++ b/usr/iscsi/iscsid.c
>> @@ -1917,8 +1917,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;
>>
>> @@ -1930,6 +1943,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,8 +2099,21 @@ 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/iscsid.h b/usr/iscsi/iscsid.h
>> index 469a9d2..2a7a3f8 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/iscsi/target.c b/usr/iscsi/target.c
>> index b097a58..f4842c9 100644
>> --- a/usr/iscsi/target.c
>> +++ b/usr/iscsi/target.c
>> @@ -532,29 +532,78 @@ 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: %" PRIu64 "\n"
>> +                                      "txdata_octets: %" PRIu64 "\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)
>>  {
>> @@ -605,6 +654,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 c2ed6b4..149767e 100644
>> --- a/usr/tgtadm.c
>> +++ b/usr/tgtadm.c
>> @@ -372,6 +372,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);
>> 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 {
>> --
>> 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
>>
> --
> 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

--
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