diff mbox series

[RFC,23/48] target: core: refactor LUN_RESET code

Message ID 20220803162857.27770-24-d.bogdanov@yadro.com
State New
Headers show
Series Target cluster implementation over DLM | expand

Commit Message

Dmitry Bogdanov March 11, 2022, 8:33 a.m. UTC
No function change, just extract a code of aborting all active commands
on the device. To make it possible to call TMF LUN_RESET code without
cluster related things - SCSI2 reservation or ACA condition.

Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
---
 drivers/target/target_core_internal.h  |  5 +++--
 drivers/target/target_core_pr.c        |  4 ++--
 drivers/target/target_core_tmr.c       | 27 +++++++++++++++++++-------
 drivers/target/target_core_transport.c |  6 +-----
 4 files changed, 26 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h
index eeb405908987..b32ac78a26b0 100644
--- a/drivers/target/target_core_internal.h
+++ b/drivers/target/target_core_internal.h
@@ -112,8 +112,9 @@  int	core_delete_hba(struct se_hba *);
 /* target_core_tmr.c */
 void	core_tmr_abort_task(struct se_device *, struct se_tmr_req *,
 			struct se_session *);
-int	core_tmr_lun_reset(struct se_device *, struct se_tmr_req *,
-		struct list_head *, struct se_cmd *);
+int	core_tmr_lun_reset(struct se_device *dev, struct se_tmr_req *tmr);
+void	core_local_lun_reset(struct se_device *swc, struct se_tmr_req *tmr,
+		struct list_head *preempt_and_abort_list, struct se_cmd *prout_cmd);
 
 /* target_core_tpg.c */
 extern struct spinlock g_tpg_lock;
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index c4329f639323..dfecb155bf88 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -2936,7 +2936,7 @@  core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
 		 * registered I_T nexuses.
 		 */
 		if (preempt_type == PREEMPT_AND_ABORT) {
-			core_tmr_lun_reset(dev, NULL, &preempt_and_abort_list,
+			core_local_lun_reset(dev, NULL, &preempt_and_abort_list,
 					   cmd);
 			core_scsi3_release_preempt_and_abort(
 				&preempt_and_abort_list, pr_reg_n);
@@ -3067,7 +3067,7 @@  core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
 	 * new persistent reservation holder, the calling Initiator Port.
 	 */
 	if (preempt_type == PREEMPT_AND_ABORT) {
-		core_tmr_lun_reset(dev, NULL, &preempt_and_abort_list, cmd);
+		core_local_lun_reset(dev, NULL, &preempt_and_abort_list, cmd);
 		core_scsi3_release_preempt_and_abort(&preempt_and_abort_list,
 						pr_reg_n);
 	}
diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
index 51d95e0b8885..2db45efedd97 100644
--- a/drivers/target/target_core_tmr.c
+++ b/drivers/target/target_core_tmr.c
@@ -22,6 +22,7 @@ 
 #include "target_core_internal.h"
 #include "target_core_alua.h"
 #include "target_core_pr.h"
+#include "target_core_ua.h"
 
 int core_tmr_alloc_req(
 	struct se_cmd *se_cmd,
@@ -342,7 +343,8 @@  static void core_tmr_drain_state_list(
 	}
 }
 
-int core_tmr_lun_reset(
+
+void core_local_lun_reset(
         struct se_device *dev,
         struct se_tmr_req *tmr,
         struct list_head *preempt_and_abort_list,
@@ -352,7 +354,8 @@  int core_tmr_lun_reset(
 	struct se_portal_group *tmr_tpg = NULL;
 	struct se_session *tmr_sess = NULL;
 	bool tas;
-        /*
+
+	/*
 	 * TASK_ABORTED status bit, this is configurable via ConfigFS
 	 * struct se_device attributes.  spc4r17 section 7.4.6 Control mode page
 	 *
@@ -387,23 +390,33 @@  int core_tmr_lun_reset(
 	core_tmr_drain_state_list(dev, prout_cmd, tmr_sess, tas,
 				preempt_and_abort_list);
 
+	pr_debug("LUN_RESET: %s for [%s] Complete\n",
+			(preempt_and_abort_list) ? "Preempt" : "TMR",
+			dev->transport->name);
+}
+
+int core_tmr_lun_reset(
+	struct se_device *dev,
+	struct se_tmr_req *tmr)
+{
+	core_local_lun_reset(dev, tmr, NULL, NULL);
+
 	/*
 	 * Clear any legacy SPC-2 reservation when called during
 	 * LOGICAL UNIT RESET
 	 */
-	if (!preempt_and_abort_list &&
-	     (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS)) {
+	if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) {
 		spin_lock(&dev->dev_reservation_lock);
 		target_release_reservation(dev);
 		spin_unlock(&dev->dev_reservation_lock);
 		pr_debug("LUN_RESET: SCSI-2 Released reservation\n");
 	}
 
+	target_dev_ua_allocate(dev, 0x29,
+			ASCQ_29H_BUS_DEVICE_RESET_FUNCTION_OCCURRED);
+
 	atomic_long_inc(&dev->num_resets);
 
-	pr_debug("LUN_RESET: %s for [%s] Complete\n",
-			(preempt_and_abort_list) ? "Preempt" : "TMR",
-			dev->transport->name);
 	return 0;
 }
 
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 5926316252eb..d3cbba294510 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -3527,13 +3527,9 @@  static void target_tmr_work(struct work_struct *work)
 		tmr->response = TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED;
 		break;
 	case TMR_LUN_RESET:
-		ret = core_tmr_lun_reset(dev, tmr, NULL, NULL);
+		ret = core_tmr_lun_reset(dev, tmr);
 		tmr->response = (!ret) ? TMR_FUNCTION_COMPLETE :
 					 TMR_FUNCTION_REJECTED;
-		if (tmr->response == TMR_FUNCTION_COMPLETE) {
-			target_dev_ua_allocate(dev, 0x29,
-					       ASCQ_29H_BUS_DEVICE_RESET_FUNCTION_OCCURRED);
-		}
 		break;
 	case TMR_TARGET_WARM_RESET:
 		tmr->response = TMR_FUNCTION_REJECTED;