[Devel] [PATCH] target: add extra counters for LUN statistics - test1
Konstantin Khorenko
khorenko at gmail.com
Thu Dec 21 15:29:58 MSK 2017
Signed-off-by: Andrey Grafin <Andrey.Grafin at acronis.com>
Signed-off-by: Andrei Vagin <avagin at openvz.org>
---
drivers/target/target_core_device.c | 2 ++
drivers/target/target_core_stat.c | 57 ++++++++++++++++++++++++++++++++++
drivers/target/target_core_tmr.c | 4 +++
drivers/target/target_core_tpg.c | 8 +++++
drivers/target/target_core_transport.c | 23 ++++++++++++++
include/target/target_core_base.h | 8 +++++
6 files changed, 102 insertions(+)
diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index c928bd18ec1b..bf7631824aeb 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -95,6 +95,8 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun)
percpu_ref_get(&se_lun->lun_ref);
se_cmd->lun_ref_active = true;
+
+ atomic_long_inc(&se_cmd->se_lun->lun_stats.queue_cmds);
}
spin_unlock_irqrestore(&se_sess->se_node_acl->device_list_lock, flags);
diff --git a/drivers/target/target_core_stat.c b/drivers/target/target_core_stat.c
index 8dacf57620f9..e88e29612db9 100644
--- a/drivers/target/target_core_stat.c
+++ b/drivers/target/target_core_stat.c
@@ -682,6 +682,53 @@ static struct target_stat_scsi_tgt_port_attribute \
__CONFIGFS_EATTR_RO(_name, \
target_stat_scsi_tgt_port_show_attr_##_name);
+#define DEV_STAT_SCSI_TGT_PORT_STATS_SHOW_SIMPLE(_name, _value) \
+static ssize_t target_stat_scsi_tgt_port_show_attr_##_name( \
+ struct se_port_stat_grps *pgrps, char *page) \
+{ \
+ struct se_lun *lun = container_of(pgrps, \
+ struct se_lun, port_stat_grps); \
+ ssize_t ret = -ENODEV; \
+ \
+ spin_lock(&lun->lun_sep_lock); \
+ if (lun->lun_sep) { \
+ ret = snprintf(page, PAGE_SIZE, "%lu\n", \
+ atomic_long_read(&lun->lun_stats._value)); \
+ } \
+ spin_unlock(&lun->lun_sep_lock); \
+ return ret; \
+}
+
+DEV_STAT_SCSI_TGT_PORT_STATS_SHOW_SIMPLE(read_bytes, tx_data_octets);
+DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_bytes);
+
+DEV_STAT_SCSI_TGT_PORT_STATS_SHOW_SIMPLE(write_bytes, rx_data_octets);
+DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_bytes);
+
+DEV_STAT_SCSI_TGT_PORT_STATS_SHOW_SIMPLE(read_cmds, read_cmds);
+DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_cmds);
+
+DEV_STAT_SCSI_TGT_PORT_STATS_SHOW_SIMPLE(write_cmds, write_cmds);
+DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_cmds);
+
+DEV_STAT_SCSI_TGT_PORT_STATS_SHOW_SIMPLE(bidi_cmds, bidi_cmds);
+DEV_STAT_SCSI_TGT_PORT_ATTR_RO(bidi_cmds);
+
+DEV_STAT_SCSI_TGT_PORT_STATS_SHOW_SIMPLE(read_errors, read_errors);
+DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_errors);
+
+DEV_STAT_SCSI_TGT_PORT_STATS_SHOW_SIMPLE(write_errors, write_errors);
+DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_errors);
+
+DEV_STAT_SCSI_TGT_PORT_STATS_SHOW_SIMPLE(bidi_errors, bidi_errors);
+DEV_STAT_SCSI_TGT_PORT_ATTR_RO(bidi_errors);
+
+DEV_STAT_SCSI_TGT_PORT_STATS_SHOW_SIMPLE(aborts, aborts);
+DEV_STAT_SCSI_TGT_PORT_ATTR_RO(aborts);
+
+DEV_STAT_SCSI_TGT_PORT_STATS_SHOW_SIMPLE(queue_cmds, queue_cmds);
+DEV_STAT_SCSI_TGT_PORT_ATTR_RO(queue_cmds);
+
static ssize_t target_stat_scsi_tgt_port_show_attr_inst(
struct se_port_stat_grps *pgrps, char *page)
{
@@ -869,6 +916,16 @@ static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
&target_stat_scsi_tgt_port_write_mbytes.attr,
&target_stat_scsi_tgt_port_read_mbytes.attr,
&target_stat_scsi_tgt_port_hs_in_cmds.attr,
+ &target_stat_scsi_tgt_port_read_bytes.attr,
+ &target_stat_scsi_tgt_port_write_bytes.attr,
+ &target_stat_scsi_tgt_port_read_cmds.attr,
+ &target_stat_scsi_tgt_port_write_cmds.attr,
+ &target_stat_scsi_tgt_port_bidi_cmds.attr,
+ &target_stat_scsi_tgt_port_read_errors.attr,
+ &target_stat_scsi_tgt_port_write_errors.attr,
+ &target_stat_scsi_tgt_port_bidi_errors.attr,
+ &target_stat_scsi_tgt_port_aborts.attr,
+ &target_stat_scsi_tgt_port_queue_cmds.attr,
NULL,
};
diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
index 67a0ef38c740..7723d11df01b 100644
--- a/drivers/target/target_core_tmr.c
+++ b/drivers/target/target_core_tmr.c
@@ -154,6 +154,10 @@ void core_tmr_abort_task(
transport_wait_for_tasks(se_cmd);
target_put_sess_cmd(se_cmd);
+
+ if (se_cmd->se_cmd_flags & SCF_SE_LUN_CMD)
+ atomic_long_inc(&se_cmd->se_lun->lun_stats.aborts);
+
transport_cmd_finish_abort(se_cmd, true);
printk("ABORT_TASK: Sending TMR_FUNCTION_COMPLETE for"
diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c
index 7ee2a94463b3..17442d5b6865 100644
--- a/drivers/target/target_core_tpg.c
+++ b/drivers/target/target_core_tpg.c
@@ -835,6 +835,14 @@ int core_tpg_add_lun(
atomic_long_set(&lun->lun_stats.cmd_pdus, 0);
atomic_long_set(&lun->lun_stats.rx_data_octets, 0);
atomic_long_set(&lun->lun_stats.tx_data_octets, 0);
+ atomic_long_set(&lun->lun_stats.write_cmds, 0);
+ atomic_long_set(&lun->lun_stats.read_cmds, 0);
+ atomic_long_set(&lun->lun_stats.bidi_cmds, 0);
+ atomic_long_set(&lun->lun_stats.write_errors, 0);
+ atomic_long_set(&lun->lun_stats.read_errors, 0);
+ atomic_long_set(&lun->lun_stats.bidi_errors, 0);
+ atomic_long_set(&lun->lun_stats.queue_cmds, 0);
+ atomic_long_set(&lun->lun_stats.aborts, 0);
lun->lun_access = lun_access;
lun->lun_status = TRANSPORT_LUN_STATUS_ACTIVE;
spin_unlock(&tpg->tpg_lun_lock);
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 4675bcc70cb0..f9d1491b08f4 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -603,6 +603,9 @@ static void transport_lun_remove_cmd(struct se_cmd *cmd)
if (!lun)
return;
+ if (cmd->se_cmd_flags & SCF_SE_LUN_CMD)
+ atomic_long_dec(&cmd->se_lun->lun_stats.queue_cmds);
+
if (cmpxchg(&cmd->lun_ref_active, true, false))
percpu_ref_put(&lun->lun_ref);
}
@@ -628,6 +631,19 @@ static void target_complete_failure_work(struct work_struct *work)
{
struct se_cmd *cmd = container_of(work, struct se_cmd, work);
+ switch (cmd->data_direction) {
+ case DMA_FROM_DEVICE:
+ atomic_long_inc(&cmd->se_lun->lun_stats.read_errors);
+ break;
+ case DMA_TO_DEVICE:
+ (cmd->se_cmd_flags & SCF_BIDI) ?
+ atomic_long_inc(&cmd->se_lun->lun_stats.bidi_errors) :
+ atomic_long_inc(&cmd->se_lun->lun_stats.write_errors);
+ break;
+ default:
+ break;
+ }
+
transport_generic_request_failure(cmd,
TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE);
}
@@ -2028,6 +2044,8 @@ queue_rsp:
atomic_long_add(cmd->data_length,
&cmd->se_lun->lun_stats.tx_data_octets);
+ atomic_long_inc(&cmd->se_lun->lun_stats.read_cmds);
+
/*
* Perform READ_STRIP of PI using software emulation when
* backend had PI enabled, if the transport will not be
@@ -2053,6 +2071,11 @@ queue_rsp:
case DMA_TO_DEVICE:
atomic_long_add(cmd->data_length,
&cmd->se_lun->lun_stats.rx_data_octets);
+
+ (cmd->se_cmd_flags & SCF_BIDI) ?
+ atomic_long_inc(&cmd->se_lun->lun_stats.bidi_cmds) :
+ atomic_long_inc(&cmd->se_lun->lun_stats.write_cmds);
+
/*
* Check if we need to send READ payload for BIDI-COMMAND
*/
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index 3010f63e0858..83538ca9f7cb 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -714,6 +714,14 @@ struct scsi_port_stats {
atomic_long_t cmd_pdus;
atomic_long_t tx_data_octets;
atomic_long_t rx_data_octets;
+ atomic_long_t write_cmds;
+ atomic_long_t read_cmds;
+ atomic_long_t bidi_cmds;
+ atomic_long_t write_errors;
+ atomic_long_t read_errors;
+ atomic_long_t bidi_errors;
+ atomic_long_t queue_cmds;
+ atomic_long_t aborts;
};
struct se_lun {
--
2.13.6
_______________________________________________
Devel mailing list
Devel at openvz.org
https://lists.openvz.org/mailman/listinfo/devel
.
More information about the Devel
mailing list