Skip to content

Commit 131e6ab

Browse files
author
Nicholas Bellinger
committed
target: Add TFO->abort_task for aborted task resources release
Now that TASK_ABORTED status is not generated for all cases by TMR ABORT_TASK + LUN_RESET, a new TFO->abort_task() caller is necessary in order to give fabric drivers a chance to unmap hardware / software resources before the se_cmd descriptor is released via the normal TFO->release_cmd() codepath. This patch adds TFO->aborted_task() in core_tmr_abort_task() in place of the original transport_send_task_abort(), and also updates all fabric drivers to implement this caller. The fabric drivers that include changes to perform cleanup via ->aborted_task() are: - iscsi-target - iser-target - srpt - tcm_qla2xxx The fabric drivers that currently set ->aborted_task() to NOPs are: - loopback - tcm_fc - usb-gadget - sbp-target - vhost-scsi For the latter five, there appears to be no additional cleanup required before invoking TFO->release_cmd() to release the se_cmd descriptor. v2 changes: - Move ->aborted_task() call into transport_cmd_finish_abort (Alex) Cc: Alex Leung <[email protected]> Cc: Mark Rustad <[email protected]> Cc: Roland Dreier <[email protected]> Cc: Vu Pham <[email protected]> Cc: Chris Boot <[email protected]> Cc: Sebastian Andrzej Siewior <[email protected]> Cc: Michael S. Tsirkin <[email protected]> Cc: Giridhar Malavali <[email protected]> Cc: Saurav Kashyap <[email protected]> Cc: Quinn Tran <[email protected]> Cc: Sagi Grimberg <[email protected]> Cc: Or Gerlitz <[email protected]> Signed-off-by: Nicholas Bellinger <[email protected]>
1 parent 68259b5 commit 131e6ab

File tree

18 files changed

+111
-2
lines changed

18 files changed

+111
-2
lines changed

drivers/infiniband/ulp/isert/ib_isert.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,6 +2162,24 @@ isert_put_response(struct iscsi_conn *conn, struct iscsi_cmd *cmd)
21622162
return isert_post_response(isert_conn, isert_cmd);
21632163
}
21642164

2165+
static void
2166+
isert_aborted_task(struct iscsi_conn *conn, struct iscsi_cmd *cmd)
2167+
{
2168+
struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd);
2169+
struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
2170+
struct isert_device *device = isert_conn->conn_device;
2171+
2172+
spin_lock_bh(&conn->cmd_lock);
2173+
if (!list_empty(&cmd->i_conn_node))
2174+
list_del_init(&cmd->i_conn_node);
2175+
spin_unlock_bh(&conn->cmd_lock);
2176+
2177+
if (cmd->data_direction == DMA_TO_DEVICE)
2178+
iscsit_stop_dataout_timer(cmd);
2179+
2180+
device->unreg_rdma_mem(isert_cmd, isert_conn);
2181+
}
2182+
21652183
static int
21662184
isert_put_nopin(struct iscsi_cmd *cmd, struct iscsi_conn *conn,
21672185
bool nopout_response)
@@ -3217,6 +3235,7 @@ static struct iscsit_transport iser_target_transport = {
32173235
.iscsit_get_dataout = isert_get_dataout,
32183236
.iscsit_queue_data_in = isert_put_datain,
32193237
.iscsit_queue_status = isert_put_response,
3238+
.iscsit_aborted_task = isert_aborted_task,
32203239
};
32213240

32223241
static int __init isert_init(void)

drivers/infiniband/ulp/srpt/ib_srpt.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3081,6 +3081,14 @@ static void srpt_queue_tm_rsp(struct se_cmd *cmd)
30813081
srpt_queue_response(cmd);
30823082
}
30833083

3084+
static void srpt_aborted_task(struct se_cmd *cmd)
3085+
{
3086+
struct srpt_send_ioctx *ioctx = container_of(cmd,
3087+
struct srpt_send_ioctx, cmd);
3088+
3089+
srpt_unmap_sg_to_ib_sge(ioctx->ch, ioctx);
3090+
}
3091+
30843092
static int srpt_queue_status(struct se_cmd *cmd)
30853093
{
30863094
struct srpt_send_ioctx *ioctx;
@@ -3928,6 +3936,7 @@ static struct target_core_fabric_ops srpt_template = {
39283936
.queue_data_in = srpt_queue_data_in,
39293937
.queue_status = srpt_queue_status,
39303938
.queue_tm_rsp = srpt_queue_tm_rsp,
3939+
.aborted_task = srpt_aborted_task,
39313940
/*
39323941
* Setup function pointers for generic logic in
39333942
* target_core_fabric_configfs.c

drivers/scsi/qla2xxx/tcm_qla2xxx.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,20 @@ static void tcm_qla2xxx_queue_tm_rsp(struct se_cmd *se_cmd)
684684
qlt_xmit_tm_rsp(mcmd);
685685
}
686686

687+
static void tcm_qla2xxx_aborted_task(struct se_cmd *se_cmd)
688+
{
689+
struct qla_tgt_cmd *cmd = container_of(se_cmd,
690+
struct qla_tgt_cmd, se_cmd);
691+
struct scsi_qla_host *vha = cmd->vha;
692+
struct qla_hw_data *ha = vha->hw;
693+
694+
if (!cmd->sg_mapped)
695+
return;
696+
697+
pci_unmap_sg(ha->pdev, cmd->sg, cmd->sg_cnt, cmd->dma_data_direction);
698+
cmd->sg_mapped = 0;
699+
}
700+
687701
/* Local pointer to allocated TCM configfs fabric module */
688702
struct target_fabric_configfs *tcm_qla2xxx_fabric_configfs;
689703
struct target_fabric_configfs *tcm_qla2xxx_npiv_fabric_configfs;
@@ -1877,6 +1891,7 @@ static struct target_core_fabric_ops tcm_qla2xxx_ops = {
18771891
.queue_data_in = tcm_qla2xxx_queue_data_in,
18781892
.queue_status = tcm_qla2xxx_queue_status,
18791893
.queue_tm_rsp = tcm_qla2xxx_queue_tm_rsp,
1894+
.aborted_task = tcm_qla2xxx_aborted_task,
18801895
/*
18811896
* Setup function pointers for generic logic in
18821897
* target_core_fabric_configfs.c
@@ -1926,6 +1941,7 @@ static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = {
19261941
.queue_data_in = tcm_qla2xxx_queue_data_in,
19271942
.queue_status = tcm_qla2xxx_queue_status,
19281943
.queue_tm_rsp = tcm_qla2xxx_queue_tm_rsp,
1944+
.aborted_task = tcm_qla2xxx_aborted_task,
19291945
/*
19301946
* Setup function pointers for generic logic in
19311947
* target_core_fabric_configfs.c

drivers/target/iscsi/iscsi_target.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,18 @@ static int iscsit_queue_rsp(struct iscsi_conn *conn, struct iscsi_cmd *cmd)
499499
return 0;
500500
}
501501

502+
static void iscsit_aborted_task(struct iscsi_conn *conn, struct iscsi_cmd *cmd)
503+
{
504+
bool scsi_cmd = (cmd->iscsi_opcode == ISCSI_OP_SCSI_CMD);
505+
506+
spin_lock_bh(&conn->cmd_lock);
507+
if (!list_empty(&cmd->i_conn_node))
508+
list_del_init(&cmd->i_conn_node);
509+
spin_unlock_bh(&conn->cmd_lock);
510+
511+
__iscsit_free_cmd(cmd, scsi_cmd, true);
512+
}
513+
502514
static struct iscsit_transport iscsi_target_transport = {
503515
.name = "iSCSI/TCP",
504516
.transport_type = ISCSI_TCP,
@@ -513,6 +525,7 @@ static struct iscsit_transport iscsi_target_transport = {
513525
.iscsit_response_queue = iscsit_response_queue,
514526
.iscsit_queue_data_in = iscsit_queue_rsp,
515527
.iscsit_queue_status = iscsit_queue_rsp,
528+
.iscsit_aborted_task = iscsit_aborted_task,
516529
};
517530

518531
static int __init iscsi_target_init_module(void)

drivers/target/iscsi/iscsi_target_configfs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,13 @@ static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
18211821
iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
18221822
}
18231823

1824+
static void lio_aborted_task(struct se_cmd *se_cmd)
1825+
{
1826+
struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1827+
1828+
cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1829+
}
1830+
18241831
static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
18251832
{
18261833
struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
@@ -2005,6 +2012,7 @@ int iscsi_target_register_configfs(void)
20052012
fabric->tf_ops.queue_data_in = &lio_queue_data_in;
20062013
fabric->tf_ops.queue_status = &lio_queue_status;
20072014
fabric->tf_ops.queue_tm_rsp = &lio_queue_tm_rsp;
2015+
fabric->tf_ops.aborted_task = &lio_aborted_task;
20082016
/*
20092017
* Setup function pointers for generic logic in target_core_fabric_configfs.c
20102018
*/

drivers/target/iscsi/iscsi_target_util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,8 @@ void iscsit_release_cmd(struct iscsi_cmd *cmd)
705705
}
706706
EXPORT_SYMBOL(iscsit_release_cmd);
707707

708-
static void __iscsit_free_cmd(struct iscsi_cmd *cmd, bool scsi_cmd,
709-
bool check_queues)
708+
void __iscsit_free_cmd(struct iscsi_cmd *cmd, bool scsi_cmd,
709+
bool check_queues)
710710
{
711711
struct iscsi_conn *conn = cmd->conn;
712712

drivers/target/iscsi/iscsi_target_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern void iscsit_remove_cmd_from_tx_queues(struct iscsi_cmd *, struct iscsi_co
3030
extern bool iscsit_conn_all_queues_empty(struct iscsi_conn *);
3131
extern void iscsit_free_queue_reqs_for_conn(struct iscsi_conn *);
3232
extern void iscsit_release_cmd(struct iscsi_cmd *);
33+
extern void __iscsit_free_cmd(struct iscsi_cmd *, bool, bool);
3334
extern void iscsit_free_cmd(struct iscsi_cmd *, bool);
3435
extern int iscsit_check_session_usage_count(struct iscsi_session *);
3536
extern void iscsit_dec_session_usage_count(struct iscsi_session *);

drivers/target/loopback/tcm_loop.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,11 @@ static void tcm_loop_queue_tm_rsp(struct se_cmd *se_cmd)
919919
wake_up(&tl_tmr->tl_tmr_wait);
920920
}
921921

922+
static void tcm_loop_aborted_task(struct se_cmd *se_cmd)
923+
{
924+
return;
925+
}
926+
922927
static char *tcm_loop_dump_proto_id(struct tcm_loop_hba *tl_hba)
923928
{
924929
switch (tl_hba->tl_proto_id) {
@@ -1487,6 +1492,7 @@ static int tcm_loop_register_configfs(void)
14871492
fabric->tf_ops.queue_data_in = &tcm_loop_queue_data_in;
14881493
fabric->tf_ops.queue_status = &tcm_loop_queue_status;
14891494
fabric->tf_ops.queue_tm_rsp = &tcm_loop_queue_tm_rsp;
1495+
fabric->tf_ops.aborted_task = &tcm_loop_aborted_task;
14901496

14911497
/*
14921498
* Setup function pointers for generic logic in target_core_fabric_configfs.c

drivers/target/sbp/sbp_target.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,11 @@ static void sbp_queue_tm_rsp(struct se_cmd *se_cmd)
18461846
{
18471847
}
18481848

1849+
static void sbp_aborted_task(struct se_cmd *se_cmd)
1850+
{
1851+
return;
1852+
}
1853+
18491854
static int sbp_check_stop_free(struct se_cmd *se_cmd)
18501855
{
18511856
struct sbp_target_request *req = container_of(se_cmd,
@@ -2526,6 +2531,7 @@ static struct target_core_fabric_ops sbp_ops = {
25262531
.queue_data_in = sbp_queue_data_in,
25272532
.queue_status = sbp_queue_status,
25282533
.queue_tm_rsp = sbp_queue_tm_rsp,
2534+
.aborted_task = sbp_aborted_task,
25292535
.check_stop_free = sbp_check_stop_free,
25302536

25312537
.fabric_make_wwn = sbp_make_tport,

drivers/target/target_core_configfs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ static int target_fabric_tf_ops_check(
457457
pr_err("Missing tfo->queue_tm_rsp()\n");
458458
return -EINVAL;
459459
}
460+
if (!tfo->aborted_task) {
461+
pr_err("Missing tfo->aborted_task()\n");
462+
return -EINVAL;
463+
}
460464
/*
461465
* We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
462466
* tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in

drivers/target/target_core_transport.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,12 @@ void transport_cmd_finish_abort(struct se_cmd *cmd, int remove)
605605
{
606606
if (cmd->se_cmd_flags & SCF_SE_LUN_CMD)
607607
transport_lun_remove_cmd(cmd);
608+
/*
609+
* Allow the fabric driver to unmap any resources before
610+
* releasing the descriptor via TFO->release_cmd()
611+
*/
612+
if (remove)
613+
cmd->se_tfo->aborted_task(cmd);
608614

609615
if (transport_cmd_check_stop_to_fabric(cmd))
610616
return;

drivers/target/tcm_fc/tcm_fc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ int ft_write_pending_status(struct se_cmd *);
163163
u32 ft_get_task_tag(struct se_cmd *);
164164
int ft_get_cmd_state(struct se_cmd *);
165165
void ft_queue_tm_resp(struct se_cmd *);
166+
void ft_aborted_task(struct se_cmd *);
166167

167168
/*
168169
* other internal functions.

drivers/target/tcm_fc/tfc_cmd.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ void ft_queue_tm_resp(struct se_cmd *se_cmd)
426426
ft_send_resp_code(cmd, code);
427427
}
428428

429+
void ft_aborted_task(struct se_cmd *se_cmd)
430+
{
431+
return;
432+
}
433+
429434
static void ft_send_work(struct work_struct *work);
430435

431436
/*

drivers/target/tcm_fc/tfc_conf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ static struct target_core_fabric_ops ft_fabric_ops = {
536536
.queue_data_in = ft_queue_data_in,
537537
.queue_status = ft_queue_status,
538538
.queue_tm_rsp = ft_queue_tm_resp,
539+
.aborted_task = ft_aborted_task,
539540
/*
540541
* Setup function pointers for generic logic in
541542
* target_core_fabric_configfs.c

drivers/usb/gadget/tcm_usb_gadget.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,11 @@ static void usbg_queue_tm_rsp(struct se_cmd *se_cmd)
14711471
{
14721472
}
14731473

1474+
static void usbg_aborted_task(struct se_cmd *se_cmd)
1475+
{
1476+
return;
1477+
}
1478+
14741479
static const char *usbg_check_wwn(const char *name)
14751480
{
14761481
const char *n;
@@ -1897,6 +1902,7 @@ static struct target_core_fabric_ops usbg_ops = {
18971902
.queue_data_in = usbg_send_read_response,
18981903
.queue_status = usbg_send_status_response,
18991904
.queue_tm_rsp = usbg_queue_tm_rsp,
1905+
.aborted_task = usbg_aborted_task,
19001906
.check_stop_free = usbg_check_stop_free,
19011907

19021908
.fabric_make_wwn = usbg_make_tport,

drivers/vhost/scsi.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,11 @@ static void tcm_vhost_queue_tm_rsp(struct se_cmd *se_cmd)
539539
return;
540540
}
541541

542+
static void tcm_vhost_aborted_task(struct se_cmd *se_cmd)
543+
{
544+
return;
545+
}
546+
542547
static void tcm_vhost_free_evt(struct vhost_scsi *vs, struct tcm_vhost_evt *evt)
543548
{
544549
vs->vs_events_nr--;
@@ -2131,6 +2136,7 @@ static struct target_core_fabric_ops tcm_vhost_ops = {
21312136
.queue_data_in = tcm_vhost_queue_data_in,
21322137
.queue_status = tcm_vhost_queue_status,
21332138
.queue_tm_rsp = tcm_vhost_queue_tm_rsp,
2139+
.aborted_task = tcm_vhost_aborted_task,
21342140
/*
21352141
* Setup callers for generic logic in target_core_fabric_configfs.c
21362142
*/

include/target/iscsi/iscsi_transport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct iscsit_transport {
2121
int (*iscsit_get_dataout)(struct iscsi_conn *, struct iscsi_cmd *, bool);
2222
int (*iscsit_queue_data_in)(struct iscsi_conn *, struct iscsi_cmd *);
2323
int (*iscsit_queue_status)(struct iscsi_conn *, struct iscsi_cmd *);
24+
void (*iscsit_aborted_task)(struct iscsi_conn *, struct iscsi_cmd *);
2425
};
2526

2627
static inline void *iscsit_priv_cmd(struct iscsi_cmd *cmd)

include/target/target_core_fabric.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct target_core_fabric_ops {
6262
int (*queue_data_in)(struct se_cmd *);
6363
int (*queue_status)(struct se_cmd *);
6464
void (*queue_tm_rsp)(struct se_cmd *);
65+
void (*aborted_task)(struct se_cmd *);
6566
/*
6667
* fabric module calls for target_core_fabric_configfs.c
6768
*/

0 commit comments

Comments
 (0)