A tag of a target_core_uring device belongs to the server from the moment it fetches a command until it commits the result. If the server exits or crashes in between, the command never completes and the tag stays owned, so a new server cannot fetch on it. Fail the commands the server was working on when it closes the character device, and give the tags back. Commands that were not fetched yet stay on the pending lists for the next server. Signed-off-by: Qiliang Yuan --- drivers/target/target_core_uring.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/target/target_core_uring.c b/drivers/target/target_core_uring.c index 3a6f8d25d28e5..2978dd08c99cf 100644 --- a/drivers/target/target_core_uring.c +++ b/drivers/target/target_core_uring.c @@ -153,6 +153,16 @@ static void tcmur_cmd_end(struct tcmur_cmd *tcmd, u8 status) tcmur_cmd_put(tcmd); } +static void tcmur_end_cmds(struct list_head *cmds, u8 status) +{ + struct tcmur_cmd *tcmd, *tmp; + + list_for_each_entry_safe(tcmd, tmp, cmds, node) { + list_del(&tcmd->node); + tcmur_cmd_end(tcmd, status); + } +} + /* Hand @tcmd to the server through the tag @io */ static void tcmur_io_start(struct tcmur_queue *q, struct tcmur_io *io, struct tcmur_cmd *tcmd) @@ -509,6 +519,27 @@ static int tcmur_ch_open(struct inode *inode, struct file *filp) static int tcmur_ch_release(struct inode *inode, struct file *filp) { struct tcmur_dev *udev = filp->private_data; + struct tcmur_queue *q; + struct tcmur_io *io; + LIST_HEAD(failed); + unsigned int i, j; + + /* Fail the commands that the server did not commit */ + for (i = 0; i < udev->nr_queues; i++) { + q = &udev->queues[i]; + + spin_lock(&q->lock); + for (j = 0; j < udev->queue_depth; j++) { + io = &q->ios[j]; + io->owned = false; + if (!io->cmd) + continue; + list_add_tail(&io->cmd->node, &failed); + io->cmd = NULL; + } + spin_unlock(&q->lock); + } + tcmur_end_cmds(&failed, SAM_STAT_CHECK_CONDITION); clear_bit(TCMUR_DEV_OPEN, &udev->flags); return 0; -- 2.43.0