[Devel] [PATCH RH8 1/3] target: add extra counters for LUN statistics

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Mon Apr 26 10:18:11 MSK 2021


From: Konstantin Khorenko <khorenko at virtuozzo.com>

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 6af064c3e24e4481ad55785a6018eb8398f84e71)
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 b64d822..3871bee 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -91,6 +91,8 @@
 		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 8d9ceed..844d076 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 @@ static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item,
 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 ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item,
 	&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 076c167..fc2343c 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 2617bb3..f5afe9f 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 6d4a694..1d1f3a9 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 {
-- 
1.8.3.1



More information about the Devel mailing list