[PATCH RFC 11/18] scsi: target: uring: Drop aborted commands that are still queued

From: Qiliang Yuan

Date: Sun Nov 15 2026 - 19:19:47 EST


When a command is aborted, the core waits for the backstore to complete
it.

A target_core_uring command that no server has fetched only completes
when it times out, which delays the abort by up to cmd_time_out.

Implement tmr_notify() and complete the aborted commands that are still
on a pending list with TASK ABORTED status. Track them through
se_cmd->priv, which is set only while a command is pending.

Signed-off-by: Qiliang Yuan <qiliang.yuan@xxxxxxxxx>
---
drivers/target/target_core_uring.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)

diff --git a/drivers/target/target_core_uring.c b/drivers/target/target_core_uring.c
index 0f83bdc55e06a..629419a4c8f46 100644
--- a/drivers/target/target_core_uring.c
+++ b/drivers/target/target_core_uring.c
@@ -175,6 +175,7 @@ static void tcmur_io_start(struct tcmur_queue *q, struct tcmur_io *io,
{
lockdep_assert_held(&q->lock);

+ tcmd->se_cmd->priv = NULL;
io->cmd = tcmd;
io->owned = true;
q->descs[io - q->ios] = tcmd->desc;
@@ -207,6 +208,7 @@ static void tcmur_queue_cmd(struct tcmur_dev *udev, struct tcmur_cmd *tcmd)
io->ucmd = NULL;
tcmur_io_start(q, io, tcmd);
} else {
+ tcmd->se_cmd->priv = tcmd;
list_add_tail(&tcmd->node, &q->pending);
}
spin_unlock(&q->lock);
@@ -255,6 +257,31 @@ static sense_reason_t tcmur_execute_rw(struct se_cmd *se_cmd,
se_cmd->data_length, sgl, sgl_nents);
}

+static void tcmur_tmr_notify(struct se_device *dev, enum tcm_tmreq_table tmf,
+ struct list_head *aborted_cmds)
+{
+ struct tcmur_dev *udev = TCMUR_DEV(dev);
+ struct tcmur_cmd *tcmd;
+ struct tcmur_queue *q;
+ struct se_cmd *se_cmd;
+
+ /* Drop the aborted commands that no server has picked up yet */
+ list_for_each_entry(se_cmd, aborted_cmds, state_list) {
+ q = tcmur_cmd_queue(udev, se_cmd);
+
+ spin_lock(&q->lock);
+ tcmd = se_cmd->priv;
+ if (tcmd) {
+ se_cmd->priv = NULL;
+ list_del(&tcmd->node);
+ }
+ spin_unlock(&q->lock);
+
+ if (tcmd)
+ tcmur_cmd_end(tcmd, SAM_STAT_TASK_ABORTED);
+ }
+}
+
static void tcmur_timeout_work(struct work_struct *work)
{
struct tcmur_dev *udev = container_of(work, struct tcmur_dev,
@@ -278,6 +305,7 @@ static void tcmur_timeout_work(struct work_struct *work)
rearm = true;
break;
}
+ tcmd->se_cmd->priv = NULL;
list_move_tail(&tcmd->node, &expired);
}
for (j = 0; j < udev->queue_depth; j++) {
@@ -920,6 +948,7 @@ static const struct target_backend_ops tcmur_ops = {
.destroy_device = tcmur_destroy_device,
.free_device = tcmur_free_device,
.parse_cdb = tcmur_parse_cdb,
+ .tmr_notify = tcmur_tmr_notify,
.set_configfs_dev_params = tcmur_set_configfs_dev_params,
.show_configfs_dev_params = tcmur_show_configfs_dev_params,
.get_device_type = sbc_get_device_type,

--
2.43.0