Skip to contentSkip to conversation

target/tcm_qla2xxx: Add TMR_ABORT_TASK support

PATCH In review Nicholas A. Bellinger 2 participants 7 messages Feb 13, 2012 – Feb 17, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover target/tcm_qla2xxx: Add TMR_ABORT_TASK support

From: Nicholas Bellinger <[email protected]>

Hi folks,

The following series adds explict TMR_ABORT_TASK support using session command list descriptors for target_submit_cmd() fabric module users.

The logic performs explict abort using tmr->ref_task_tag for outstanding descriptors have not been set CMD_T_COMPLETE in transport_complete_task() during backend I/O completion. It also cancels se_cmd->work and wait for backing I/O to complete before attempting to send SAM_STAT_TASK_ABORTED and perform necessary target_put_sess_cmd() to drop outstanding cmd_kref references.

So far this has been tested with tcm_qla2xxx using target-core debug code to simulate delayed execution of a referenced tag descriptor in the following locations:

- Before execution of tasks in transport_generic_new_cmd()
- Before completion of tasks in transport_complete_task()
- After completion of tasks in transport_complete_task()

The code can use some more testing and review, but so far these changes with simulated I/O delays are generating SAM_STAT_TASK_ABORTED status for the aborted tag, or failing with TMR_TASK_DOES_NOT_EXIST as expected..

Please have a look,

--nab

Nicholas Bellinger (4):
target: Add SCF_ACK_KREF flag for acknowledgement kref
target: Make target_release_cmd_kref release on empty list
target: Add TMR_ABORT_TASK task management support qla_target/tcm_qla2xxx: Fix TMR_ABORT_TASK with target mode usage

 drivers/scsi/qla2xxx/qla_target.c      |   15 +++----
 drivers/scsi/qla2xxx/qla_target.h      |    2 +-
 drivers/scsi/qla2xxx/tcm_qla2xxx.c     |    6 ++-
 drivers/scsi/qla2xxx/tcm_qla2xxx.h     |    3 +-
 drivers/target/target_core_internal.h  |    2 +
 drivers/target/target_core_tmr.c       |   64 ++++++++++++++++++++++++++++++++
 drivers/target/target_core_transport.c |   26 ++++++++----
 include/target/target_core_base.h      |    3 +-
 8 files changed, 100 insertions(+), 21 deletions(-)
Signature · 1 line
1.7.2.5
#1 lore raw

PATCH 1/4 target: Add SCF_ACK_KREF flag for acknowledgement kref

From: Nicholas Bellinger <[email protected]>

When TARGET_SCF_ACK_KREF is in use with target_submit_cmd() for setting the extra acknowledgement reference to se_cmd->cmd_kref, go ahead and set SCF_ACK_KREF in order to be used later by abort task.

---
 drivers/target/target_core_transport.c |    4 +++-
 include/target/target_core_base.h      |    3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/target/target_core_transport.c +3 -1
index 1fe946c..4a6ece1 100644
@@ -4035,8 +4035,10 @@ void target_get_sess_cmd(struct se_session *se_sess, struct se_cmd *se_cmd,
 	 * fabric acknowledgement that requires two target_put_sess_cmd()
 	 * invocations before se_cmd descriptor release.
 	 */
-	if (ack_kref == true)
+	if (ack_kref == true) {
 		kref_get(&se_cmd->cmd_kref);
+		se_cmd->se_cmd_flags |= SCF_ACK_KREF;
+	}
 
 	spin_lock_irqsave(&se_sess->sess_cmd_lock, flags);
 	list_add_tail(&se_cmd->se_cmd_list, &se_sess->sess_cmd_list);
include/target/target_core_base.h +2 -1
index 870768c..2d3d79a 100644
@@ -183,7 +183,8 @@ enum se_cmd_flags_table {
 	SCF_ALUA_NON_OPTIMIZED		= 0x00040000,
 	SCF_DELAYED_CMD_FROM_SAM_ATTR	= 0x00080000,
 	SCF_UNUSED			= 0x00100000,
-	SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00400000,
+	SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00200000,
+	SCF_ACK_KREF			= 0x00400000,
 };
 
 /* struct se_dev_entry->lun_flags and struct se_lun->lun_access */
Signature · 1 line
1.7.2.5
#2 lore raw

PATCH 2/4 target: Make target_release_cmd_kref release on empty list

In reply to Nicholas A. Bellinger

From: Nicholas Bellinger <[email protected]>

This patch changes target_release_cmd_kref() to make TFO->release_cmd() call when list_empty(&se_cmd->se_cmd_list) is TRUE. This is required for TMR_ABORT_TASK operation where the referenced tag descriptor may have already been pulled of the session command list.

---
 drivers/target/target_core_transport.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/target/target_core_transport.c +1 -1
index 4a6ece1..17183da 100644
@@ -4056,7 +4056,7 @@ static void target_release_cmd_kref(struct kref *kref)
 	spin_lock_irqsave(&se_sess->sess_cmd_lock, flags);
 	if (list_empty(&se_cmd->se_cmd_list)) {
 		spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags);
-		WARN_ON(1);
+		se_cmd->se_tfo->release_cmd(se_cmd);
 		return;
 	}
 	if (se_sess->sess_tearing_down && se_cmd->cmd_wait_set) {
Signature · 1 line
1.7.2.5
#3 lore raw

PATCH 3/4 target: Add TMR_ABORT_TASK task management support

In reply to Nicholas A. Bellinger

From: Nicholas Bellinger <[email protected]>

This patch adds initial support for TMR_ABORT_TASK ops for se_cmd descriptors using se_sess->sess_cmd_list and se_cmd->cmd_kref counting.

It will perform an explict abort for all outstanding se_cmd ops based upon tmr->ref_task_tag that have not been set CMD_T_COMPLETE. It will cancel se_cmd->work and wait for backing I/O to complete before attempting to send SAM_STAT_TASK_ABORTED and perform target_put_sess_cmd() to release the referenced descriptor.

It also adds a CMD_T_ABORTED check into transport_complete_task() to catch the completion from backend I/O that has been aborted, and updates transport_wait_for_tasks() to allow CMD_T_ABORTED usage with core_tmr_abort_task() context.

---
 drivers/target/target_core_internal.h  |    2 +
 drivers/target/target_core_tmr.c       |   64 ++++++++++++++++++++++++++++++++
 drivers/target/target_core_transport.c |   20 ++++++---
 3 files changed, 79 insertions(+), 7 deletions(-)
drivers/target/target_core_internal.h +2 -0
index e414c90..88bdb57 100644
@@ -75,6 +75,8 @@ struct se_hba *core_alloc_hba(const char *, u32, u32);
 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 *);
 
drivers/target/target_core_tmr.c +64 -0

70 lines not on this page · raw message

drivers/target/target_core_transport.c +13 -7
index 17183da..bba671a 100644
@@ -701,17 +701,24 @@ void transport_complete_task(struct se_task *task, int success)
 		spin_unlock_irqrestore(&cmd->t_state_lock, flags);
 		return;
 	}
-
-	if (cmd->transport_state & CMD_T_FAILED) {
+	/*
+	 * Check for case where an explict ABORT_TASK has been received
+	 * and transport_wait_for_tasks() will be waiting for completion..
+	 */
+	if (cmd->transport_state & CMD_T_ABORTED &&
+	    cmd->transport_state & CMD_T_STOP) {
+		spin_unlock_irqrestore(&cmd->t_state_lock, flags);
+		complete(&cmd->t_transport_stop_comp);
+		return;
+	} else if (cmd->transport_state & CMD_T_FAILED) {
 		cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
 		INIT_WORK(&cmd->work, target_complete_failure_work);
 	} else {
-		cmd->transport_state |= CMD_T_COMPLETE;
 		INIT_WORK(&cmd->work, target_complete_ok_work);
 	}
 
 	cmd->t_state = TRANSPORT_COMPLETE;
-	cmd->transport_state |= CMD_T_ACTIVE;
+	cmd->transport_state |= (CMD_T_COMPLETE | CMD_T_ACTIVE);
 	spin_unlock_irqrestore(&cmd->t_state_lock, flags);
 
 	queue_work(target_completion_wq, &cmd->work);
@@ -4379,8 +4386,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
 		cmd->transport_state &= ~CMD_T_LUN_STOP;
 	}
 
-	if (!(cmd->transport_state & CMD_T_ACTIVE) ||
-	     (cmd->transport_state & CMD_T_ABORTED)) {
+	if (!(cmd->transport_state & CMD_T_ACTIVE)) {
 		spin_unlock_irqrestore(&cmd->t_state_lock, flags);
 		return false;
 	}
@@ -4686,7 +4692,7 @@ static int transport_generic_do_tmr(struct se_cmd *cmd)
 
 	switch (tmr->function) {
 	case TMR_ABORT_TASK:
-		tmr->response = TMR_FUNCTION_REJECTED;
+		core_tmr_abort_task(dev, tmr, cmd->se_sess);
 		break;
 	case TMR_ABORT_TASK_SET:
 	case TMR_CLEAR_ACA:
Signature · 1 line
1.7.2.5
#4 lore raw

PATCH 4/4 qla_target/tcm_qla2xxx: Fix TMR_ABORT_TASK with target mode usage

In reply to Nicholas A. Bellinger

From: Nicholas Bellinger <[email protected]>

This patch fixes qla_target.c code use the proper TMR_ABORT_TASK that target-core is expecting, instead of the incorrect ABORT_TASK message code usage from include/scsi/scsi.h.

It also changes tgt_ops->handle_tmr() -> tcm_qla2xxx_handle_tmr() to accept referenced tag for TMR_ABORT_TASK that is setup to se_tmr_req->ref_task_tag.

---
 drivers/scsi/qla2xxx/qla_target.c  |   15 +++++++--------
 drivers/scsi/qla2xxx/qla_target.h  |    2 +-
 drivers/scsi/qla2xxx/tcm_qla2xxx.c |    6 +++++-
 drivers/scsi/qla2xxx/tcm_qla2xxx.h |    3 ++-
 4 files changed, 15 insertions(+), 11 deletions(-)
drivers/scsi/qla2xxx/qla_target.c +7 -8
index 4b24457..ac203ef 100644
@@ -1304,7 +1304,8 @@ static int __qla_tgt_24xx_handle_abts(struct scsi_qla_host *vha,
 	mcmd->sess = sess;
 	memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts));
 
-	rc = ha->tgt_ops->handle_tmr(mcmd, 0, ABORT_TASK);
+	rc = ha->tgt_ops->handle_tmr(mcmd, 0, TMR_ABORT_TASK,
+				abts->exchange_addr_to_abort);
 	if (rc != 0) {
 		printk(KERN_ERR "qla_target(%d):  tgt_ops->handle_tmr()"
 				" failed: %d", vha->vp_idx, rc);
@@ -1428,7 +1429,7 @@ void qla_tgt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd)
 	unsigned long flags;
 
 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xe116, "TM response mcmd"
-		" (%p) status %#x state %#x", mcmd, mcmd->se_tmr_req->response,
+		" (%p) status %#x state %#x", mcmd, mcmd->fc_tm_rsp,
 		mcmd->flags);
 
 	spin_lock_irqsave(&ha->hardware_lock, flags);
@@ -1436,7 +1437,7 @@ void qla_tgt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd)
 		qla_tgt_send_notify_ack(vha, &mcmd->orig_iocb.imm_ntfy,
 			0, 0, 0, 0, 0, 0);
 	else {
-		if (mcmd->se_tmr_req->function == ABORT_TASK)
+		if (mcmd->se_tmr_req->function == TMR_ABORT_TASK)
 			qla_tgt_24xx_send_abts_resp(vha, &mcmd->orig_iocb.abts,
 				mcmd->fc_tm_rsp, false);
 		else
@@ -2804,7 +2805,7 @@ static int qla_tgt_issue_task_mgmt(struct qla_tgt_sess *sess, uint32_t lun,
 		return -ENOSYS;
 	}
 
-	res = ha->tgt_ops->handle_tmr(mcmd, lun, tmr_func);
+	res = ha->tgt_ops->handle_tmr(mcmd, lun, tmr_func, 0);
 	if (res != 0) {
 		printk(KERN_ERR "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
 			    sess->vha->vp_idx, res);
@@ -2857,7 +2858,6 @@ static int __qla_tgt_abort_task(struct scsi_qla_host *vha,
 	struct qla_tgt_mgmt_cmd *mcmd;
 	uint32_t lun, unpacked_lun;
 	int rc;
-	uint16_t tag;
 
 	mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
 	if (mcmd == NULL) {
@@ -2870,12 +2870,11 @@ static int __qla_tgt_abort_task(struct scsi_qla_host *vha,
 	mcmd->sess = sess;
 	memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, sizeof(mcmd->orig_iocb.imm_ntfy));
 
-	tag = le16_to_cpu(iocb->u.isp2x.seq_id);
-
 	lun = a->u.isp24.fcp_cmnd.lun;
 	unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun);
 
-	rc = ha->tgt_ops->handle_tmr(mcmd, unpacked_lun, ABORT_TASK);
+	rc = ha->tgt_ops->handle_tmr(mcmd, unpacked_lun, TMR_ABORT_TASK,
+				le16_to_cpu(iocb->u.isp2x.seq_id));
 	if (rc != 0) {
 		printk(KERN_ERR "qla_target(%d): tgt_ops->handle_tmr()"
 			" failed: %d\n", vha->vp_idx, rc);
drivers/scsi/qla2xxx/qla_target.h +1 -1
index b98b923..935ea32 100644
@@ -634,7 +634,7 @@ struct qla_tgt_func_tmpl {
 	int (*handle_cmd)(struct scsi_qla_host *, struct qla_tgt_cmd *,
 			unsigned char *, uint32_t, int, int, int);
 	int (*handle_data)(struct qla_tgt_cmd *);
-	int (*handle_tmr)(struct qla_tgt_mgmt_cmd *, uint32_t, uint8_t);
+	int (*handle_tmr)(struct qla_tgt_mgmt_cmd *, uint32_t, uint8_t, uint32_t);
 	void (*free_cmd)(struct qla_tgt_cmd *);
 	void (*free_session)(struct qla_tgt_sess *);
 
drivers/scsi/qla2xxx/tcm_qla2xxx.c +5 -1
index 71de7a6..5456af2 100644
@@ -668,7 +668,8 @@ int tcm_qla2xxx_handle_data(struct qla_tgt_cmd *cmd)
 /*
  * Called from qla_target.c:qla_tgt_issue_task_mgmt()
  */
-int tcm_qla2xxx_handle_tmr(struct qla_tgt_mgmt_cmd *mcmd, uint32_t lun, uint8_t tmr_func)
+int tcm_qla2xxx_handle_tmr(struct qla_tgt_mgmt_cmd *mcmd, uint32_t lun,
+			uint8_t tmr_func, uint32_t tag)
 {
 	struct qla_tgt_sess *sess = mcmd->sess;
 	struct se_session *se_sess = sess->se_sess;
@@ -688,6 +689,9 @@ int tcm_qla2xxx_handle_tmr(struct qla_tgt_mgmt_cmd *mcmd, uint32_t lun, uint8_t
 	 * Save the se_tmr_req for qla_tgt_xmit_tm_rsp() callback into LLD code
 	 */
 	mcmd->se_tmr_req = &se_cmd->se_tmr_req;
+
+	if (tmr_func == TMR_ABORT_TASK)
+		mcmd->se_tmr_req->ref_task_tag = tag;
 	/*
 	 * Locate the underlying TCM struct se_lun from sc->device->lun
 	 */
drivers/scsi/qla2xxx/tcm_qla2xxx.h +2 -1
index 9dbac00..e700c15 100644
@@ -139,7 +139,8 @@ extern int tcm_qla2xxx_handle_cmd(struct scsi_qla_host *, struct qla_tgt_cmd *,
 			unsigned char *, uint32_t, int, int, int);
 extern int tcm_qla2xxx_new_cmd_map(struct se_cmd *);
 extern int tcm_qla2xxx_handle_data(struct qla_tgt_cmd *);
-extern int tcm_qla2xxx_handle_tmr(struct qla_tgt_mgmt_cmd *, uint32_t, uint8_t);
+extern int tcm_qla2xxx_handle_tmr(struct qla_tgt_mgmt_cmd *, uint32_t,
+				uint8_t, uint32_t);
 extern int tcm_qla2xxx_queue_data_in(struct se_cmd *);
 extern int tcm_qla2xxx_queue_status(struct se_cmd *);
 extern int tcm_qla2xxx_queue_tm_rsp(struct se_cmd *);
Signature · 1 line
1.7.2.5
#5 lore raw
In reply to Nicholas A. Bellinger
Quoted 2 lines · Nicholas A. Bellinger

The following series adds explict TMR_ABORT_TASK support using session command list descriptors for target_submit_cmd() fabric module users.

<snip>

Quoted 5 lines

The code can use some more testing and review, but so far these changes with simulated I/O delays are generating SAM_STAT_TASK_ABORTED status for the aborted tag, or failing with TMR_TASK_DOES_NOT_EXIST as expected..

Please have a look,

Reviewed, looks good.

Do you have plans to implement ABORT_TASK_SET as well?

Regards -- Andy

#6 lore raw
Quoted 10 lines · Andy Grover
Quoted 2 lines · Nicholas A. Bellinger

The following series adds explict TMR_ABORT_TASK support using session command list descriptors for target_submit_cmd() fabric module users.

<snip>

Quoted 4 lines

The code can use some more testing and review, but so far these changes with simulated I/O delays are generating SAM_STAT_TASK_ABORTED status for the aborted tag, or failing with TMR_TASK_DOES_NOT_EXIST as expected..

Quoted 6 lines
Quoted 1 line

Please have a look,

Reviewed, looks good.

Do you have plans to implement ABORT_TASK_SET as well?

Hi Andy,

At some point, I'd like to add generic support for ABORT_TASK_SET into target-core.

The conversion of iscsi-target to use per session cmd list probably needs to happen so that ABORT_TASK + ABORT_TASK_SET can be properly supported there first.

Also, I'm not currently aware of a method to generate ABORT_TASK_SET for testing using simulated failures with qla2xxx (other than an FC jammer..?), and current libiscsi clients do not generate ABORT_TASK_SET.

I imagine it would be easier to test ABORT_TASK_SET if libscsi could generate this TMR for testing purposes (via SG ioctl perhaps..?)

--nab