[Devel] [PATCH RHEL8 COMMIT] target: add extra counters for LUN statistics

Konstantin Khorenko khorenko at virtuozzo.com
Fri Apr 30 14:33:44 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.24
------>
commit 72b685ef31750a8d03faaf8e3bbc209d50d34ff5
Author: Konstantin Khorenko <khorenko at virtuozzo.com>
Date:   Fri Apr 30 14:33:44 2021 +0300

    target: add extra counters for LUN statistics
    
    Signed-off-by: Andrey Grafin <Andrey.Grafin at acronis.com>
    Acked-by: Andrei Vagin <avagin at virtuozzo.com>
    
    ==============================
    Rebase to RHEL7.5 kernel-3.10.0-862.el7:
    dropped hunk
            --- a/drivers/target/target_core_tpg.c
            +++ b/drivers/target/target_core_tpg.c
            @@ -638,6 +638,14 @@ int core_tpg_add_lun(
                    mutex_lock(&tpg->tpg_lun_mutex);
    
                    spin_lock(&dev->se_port_lock);
            +       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_index = dev->dev_index;
                    rcu_assign_pointer(lun->lun_se_dev, dev);
                    dev->export_count++;
    
    Because core_tpg_alloc_lun() kzallocs whole lun struct, which zeroifies
    all stats.
    
    Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
    
    (cherry picked from vz7 commit 6af064c3e24e ("target: add extra counters for LUN
    statistics"))
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 drivers/target/target_core_device.c    |  2 ++
 drivers/target/target_core_stat.c      | 51 ++++++++++++++++++++++++++++++++++
 drivers/target/target_core_tmr.c       |  3 ++
 drivers/target/target_core_transport.c | 24 ++++++++++++++++
 include/target/target_core_base.h      |  8 ++++++
 5 files changed, 88 insertions(+)

diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index b64d82261824..3871bee50362 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -91,6 +91,8 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
 		se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD;
 		se_cmd->lun_ref_active = true;
 
+		atomic_long_inc(&se_cmd->se_lun->lun_stats.queue_cmds);
+
 		if ((se_cmd->data_direction == DMA_TO_DEVICE) &&
 		    deve->lun_access_ro) {
 			pr_err("TARGET_CORE[%s]: Detected WRITE_PROTECTED LUN"
diff --git a/drivers/target/target_core_stat.c b/drivers/target/target_core_stat.c
index 8d9ceedfd455..844d076b5c9f 100644
--- a/drivers/target/target_core_stat.c
+++ b/drivers/target/target_core_stat.c
@@ -683,6 +683,35 @@ static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item,
 	return ret;
 }
 
+#define DEV_STAT_TGT_PORT_STATS_SHOW_SIMPLE(_name, _value)		\
+static ssize_t  target_stat_tgt_port_##_name##_show(			\
+	struct config_item *item, char *page)				\
+{									\
+	struct se_lun *lun = to_stat_port(item);			\
+	struct se_device *dev;						\
+	ssize_t ret = -ENODEV;						\
+									\
+	rcu_read_lock();						\
+	dev = rcu_dereference(lun->lun_se_dev);				\
+	if (dev) {							\
+		ret = snprintf(page, PAGE_SIZE, "%lu\n",		\
+			atomic_long_read(&lun->lun_stats._value));	\
+	}								\
+	rcu_read_unlock();						\
+	return ret;							\
+}
+
+DEV_STAT_TGT_PORT_STATS_SHOW_SIMPLE(read_bytes, tx_data_octets);
+DEV_STAT_TGT_PORT_STATS_SHOW_SIMPLE(write_bytes, rx_data_octets);
+DEV_STAT_TGT_PORT_STATS_SHOW_SIMPLE(read_cmds, read_cmds);
+DEV_STAT_TGT_PORT_STATS_SHOW_SIMPLE(write_cmds, write_cmds);
+DEV_STAT_TGT_PORT_STATS_SHOW_SIMPLE(bidi_cmds, bidi_cmds);
+DEV_STAT_TGT_PORT_STATS_SHOW_SIMPLE(read_errors, read_errors);
+DEV_STAT_TGT_PORT_STATS_SHOW_SIMPLE(write_errors, write_errors);
+DEV_STAT_TGT_PORT_STATS_SHOW_SIMPLE(bidi_errors, bidi_errors);
+DEV_STAT_TGT_PORT_STATS_SHOW_SIMPLE(aborts, aborts);
+DEV_STAT_TGT_PORT_STATS_SHOW_SIMPLE(queue_cmds, queue_cmds);
+
 CONFIGFS_ATTR_RO(target_stat_tgt_port_, inst);
 CONFIGFS_ATTR_RO(target_stat_tgt_port_, dev);
 CONFIGFS_ATTR_RO(target_stat_tgt_port_, indx);
@@ -693,6 +722,17 @@ CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_mbytes);
 CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_mbytes);
 CONFIGFS_ATTR_RO(target_stat_tgt_port_, hs_in_cmds);
 
+CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_bytes);
+CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_bytes);
+CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_cmds);
+CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_cmds);
+CONFIGFS_ATTR_RO(target_stat_tgt_port_, bidi_cmds);
+CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_errors);
+CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_errors);
+CONFIGFS_ATTR_RO(target_stat_tgt_port_, bidi_errors);
+CONFIGFS_ATTR_RO(target_stat_tgt_port_, aborts);
+CONFIGFS_ATTR_RO(target_stat_tgt_port_, queue_cmds);
+
 static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
 	&target_stat_tgt_port_attr_inst,
 	&target_stat_tgt_port_attr_dev,
@@ -703,6 +743,17 @@ static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
 	&target_stat_tgt_port_attr_write_mbytes,
 	&target_stat_tgt_port_attr_read_mbytes,
 	&target_stat_tgt_port_attr_hs_in_cmds,
+
+	&target_stat_tgt_port_attr_read_bytes,
+	&target_stat_tgt_port_attr_write_bytes,
+	&target_stat_tgt_port_attr_read_cmds,
+	&target_stat_tgt_port_attr_write_cmds,
+	&target_stat_tgt_port_attr_bidi_cmds,
+	&target_stat_tgt_port_attr_read_errors,
+	&target_stat_tgt_port_attr_write_errors,
+	&target_stat_tgt_port_attr_bidi_errors,
+	&target_stat_tgt_port_attr_aborts,
+	&target_stat_tgt_port_attr_queue_cmds,
 	NULL,
 };
 
diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
index 076c167b8899..fc2343cb706a 100644
--- a/drivers/target/target_core_tmr.c
+++ b/drivers/target/target_core_tmr.c
@@ -166,6 +166,9 @@ void core_tmr_abort_task(
 
 		target_put_cmd_and_wait(se_cmd);
 
+		if (se_cmd->se_cmd_flags & SCF_SE_LUN_CMD)
+			atomic_long_inc(&se_cmd->se_lun->lun_stats.aborts);
+
 		printk("ABORT_TASK: Sending TMR_FUNCTION_COMPLETE for"
 				" ref_tag: %llu\n", ref_tag);
 		tmr->response = TMR_FUNCTION_COMPLETE;
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 2617bb3f7922..f5afe9f34d86 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -718,6 +718,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);
 }
@@ -726,6 +729,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);
 }
@@ -2375,6 +2391,9 @@ static void target_complete_ok_work(struct work_struct *work)
 
 		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
@@ -2399,6 +2418,11 @@ static void target_complete_ok_work(struct work_struct *work)
 	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 6d4a694f6ea7..1d1f3a91c5d0 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -715,6 +715,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 {


More information about the Devel mailing list