From: Qiliang Yuan <qiliang.yuan@linux.dev>
To: "Martin K. Petersen" <mkp@kernel.org>,
Shuah Khan <shuah@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>
Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org,
target-devel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-doc@vger.kernel.org, Jens Axboe <axboe@kernel.dk>,
io-uring@vger.kernel.org,
Mike Christie <michael.christie@oracle.com>,
Bodo Stroesser <bostroesser@gmail.com>,
Ming Lei <tom.leiming@gmail.com>,
Qiliang Yuan <qiliang.yuan@linux.dev>
Subject: [PATCH RFC 07/18] scsi: target: uring: Complete commands with TCMUR_IO_COMMIT_AND_FETCH
Date: Sun, 15 Nov 2026 19:18:00 -0500 [thread overview]
Message-ID: <20261115-feat-target-core-uring-v1-7-28cdc137eac6@linux.dev> (raw)
In-Reply-To: <20261115-feat-target-core-uring-v1-0-28cdc137eac6@linux.dev>
The server of a target_core_uring device can fetch a command for each
tag.
It cannot report the result, so the command never completes and the tag
is never used again.
Add the TCMUR_IO_COMMIT_AND_FETCH io_uring command, which completes the
command of a tag with GOOD or CHECK CONDITION status and fetches the
next one in the same call. Count references on struct tcmur_cmd and
complete the target command when the last one goes, as later patches
add users that can outlive the commit.
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
drivers/target/target_core_uring.c | 47 ++++++++++++++++++++++++++++++++++
include/uapi/linux/target_core_uring.h | 9 +++++--
2 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/drivers/target/target_core_uring.c b/drivers/target/target_core_uring.c
index 85c9a1ae84433..770bb665fbe00 100644
--- a/drivers/target/target_core_uring.c
+++ b/drivers/target/target_core_uring.c
@@ -20,6 +20,7 @@
#include <linux/scatterlist.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
+#include <scsi/scsi_proto.h>
#include <target/target_core_base.h>
#include <target/target_core_backend.h>
#include <uapi/linux/target_core_uring.h>
@@ -42,6 +43,8 @@ struct tcmur_dev;
* @sgl: Data pages of the command
* @sgl_nents: Number of entries in @sgl
* @desc: What the server is asked to do
+ * @ref: Held by the tag or the pending list
+ * @status: SAM status to complete @se_cmd with
*/
struct tcmur_cmd {
struct list_head node;
@@ -49,6 +52,8 @@ struct tcmur_cmd {
struct scatterlist *sgl;
u32 sgl_nents;
struct tcmur_io_desc desc;
+ refcount_t ref;
+ u8 status;
};
/**
@@ -130,6 +135,22 @@ static struct tcmur_queue *tcmur_cmd_queue(struct tcmur_dev *udev,
return &udev->queues[(unsigned int)se_cmd->cpuid % udev->nr_queues];
}
+static void tcmur_cmd_put(struct tcmur_cmd *tcmd)
+{
+ if (!refcount_dec_and_test(&tcmd->ref))
+ return;
+
+ target_complete_cmd(tcmd->se_cmd, tcmd->status);
+ kmem_cache_free(tcmur_cmd_cache, tcmd);
+}
+
+/* Drop the reference of the tag or of the pending list and set the result */
+static void tcmur_cmd_end(struct tcmur_cmd *tcmd, u8 status)
+{
+ tcmd->status = status;
+ tcmur_cmd_put(tcmd);
+}
+
/* 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)
@@ -156,6 +177,8 @@ static void tcmur_queue_cmd(struct tcmur_dev *udev, struct tcmur_cmd *tcmd)
struct io_uring_cmd *ucmd = NULL;
struct tcmur_io *io;
+ refcount_set(&tcmd->ref, 1);
+
spin_lock(&q->lock);
io = list_first_entry_or_null(&q->idle, struct tcmur_io, node);
if (io) {
@@ -262,6 +285,24 @@ static int tcmur_fetch(struct tcmur_queue *q, struct tcmur_io *io,
return ret;
}
+static int tcmur_commit(struct tcmur_queue *q, struct tcmur_io *io, int result)
+{
+ struct tcmur_cmd *tcmd;
+
+ spin_lock(&q->lock);
+ if (!io->owned) {
+ spin_unlock(&q->lock);
+ return -EINVAL;
+ }
+ tcmd = io->cmd;
+ io->cmd = NULL;
+ io->owned = false;
+ spin_unlock(&q->lock);
+
+ tcmur_cmd_end(tcmd, result ? SAM_STAT_CHECK_CONDITION : SAM_STAT_GOOD);
+ return 0;
+}
+
static int tcmur_ch_uring_cmd_local(struct io_uring_cmd *ucmd,
unsigned int issue_flags)
{
@@ -272,6 +313,7 @@ static int tcmur_ch_uring_cmd_local(struct io_uring_cmd *ucmd,
u16 tag = READ_ONCE(ioc->tag);
struct tcmur_queue *q;
struct tcmur_io *io;
+ int ret;
if (q_id >= udev->nr_queues || tag >= udev->queue_depth)
return -EINVAL;
@@ -282,6 +324,11 @@ static int tcmur_ch_uring_cmd_local(struct io_uring_cmd *ucmd,
switch (ucmd->cmd_op) {
case TCMUR_IO_FETCH:
return tcmur_fetch(q, io, ucmd, issue_flags);
+ case TCMUR_IO_COMMIT_AND_FETCH:
+ ret = tcmur_commit(q, io, READ_ONCE(ioc->result));
+ if (ret)
+ return ret;
+ return tcmur_fetch(q, io, ucmd, issue_flags);
default:
return -EOPNOTSUPP;
}
diff --git a/include/uapi/linux/target_core_uring.h b/include/uapi/linux/target_core_uring.h
index 9ce871d2e2087..a662a23fca9ab 100644
--- a/include/uapi/linux/target_core_uring.h
+++ b/include/uapi/linux/target_core_uring.h
@@ -43,21 +43,26 @@ struct tcmur_dev_info {
* struct tcmur_io_cmd - Payload of the io_uring commands, placed in sqe->cmd
* @q_id: Queue of the tag
* @tag: Tag the command is for
- * @reserved: Zero
+ * @result: TCMUR_IO_COMMIT_AND_FETCH: 0, or a negative errno if the
+ * command failed
* @reserved1: Zero
*/
struct tcmur_io_cmd {
__u16 q_id;
__u16 tag;
- __s32 reserved;
+ __s32 result;
__u64 reserved1;
};
/*
* TCMUR_IO_FETCH: wait for a command on (q_id, tag). The CQE result is 0
* once the descriptor of the tag holds a command.
+ *
+ * TCMUR_IO_COMMIT_AND_FETCH: complete the command of (q_id, tag) with
+ * @result, then wait for the next one.
*/
#define TCMUR_IO_FETCH _IOWR(0xBB, 0x08, struct tcmur_io_cmd)
+#define TCMUR_IO_COMMIT_AND_FETCH _IOWR(0xBB, 0x09, struct tcmur_io_cmd)
enum tcmur_io_op {
TCMUR_OP_READ,
--
2.43.0
next prev parent reply other threads:[~2026-11-16 0:19 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 0:17 [PATCH RFC 00/18] scsi: target: Add target_core_uring, an io_uring based user backstore Qiliang Yuan
2026-11-16 0:17 ` [PATCH RFC 01/18] scsi: target: uring: Introduce " Qiliang Yuan
2026-11-16 0:38 ` sashiko-bot
2026-11-16 0:17 ` [PATCH RFC 02/18] scsi: target: uring: Allocate per-queue command descriptors Qiliang Yuan
2026-11-16 0:17 ` [PATCH RFC 03/18] scsi: target: uring: Create a character device per backstore device Qiliang Yuan
2026-11-16 0:33 ` sashiko-bot
2026-11-16 0:17 ` [PATCH RFC 04/18] scsi: target: uring: Map the command descriptors into the server Qiliang Yuan
2026-11-16 0:17 ` [PATCH RFC 05/18] scsi: target: uring: Queue commands until a server fetches them Qiliang Yuan
2026-11-16 0:46 ` sashiko-bot
2026-11-16 0:17 ` [PATCH RFC 06/18] scsi: target: uring: Hand commands out through TCMUR_IO_FETCH Qiliang Yuan
2026-11-16 0:18 ` Qiliang Yuan [this message]
2026-11-16 0:18 ` [PATCH RFC 08/18] scsi: target: uring: Copy command data with pread() and pwrite() Qiliang Yuan
2026-11-16 0:18 ` [PATCH RFC 09/18] scsi: target: uring: Fail in-flight commands when the server exits Qiliang Yuan
2026-11-16 0:18 ` [PATCH RFC 10/18] scsi: target: uring: Time out commands the server does not complete Qiliang Yuan
2026-11-16 0:41 ` sashiko-bot
2026-11-16 0:18 ` [PATCH RFC 11/18] scsi: target: uring: Drop aborted commands that are still queued Qiliang Yuan
2026-11-16 0:37 ` sashiko-bot
2026-11-16 0:18 ` [PATCH RFC 12/18] scsi: target: uring: Support SYNCHRONIZE CACHE Qiliang Yuan
2026-11-16 0:40 ` sashiko-bot
2026-11-16 0:18 ` [PATCH RFC 13/18] scsi: target: uring: Implement UNMAP Qiliang Yuan
2026-11-16 0:45 ` sashiko-bot
2026-11-16 0:18 ` [PATCH RFC 14/18] scsi: target: uring: Handle WRITE SAME Qiliang Yuan
2026-11-16 0:44 ` sashiko-bot
2026-11-16 0:18 ` [PATCH RFC 15/18] scsi: target: uring: Register command data as io_uring fixed buffers Qiliang Yuan
2026-11-16 0:18 ` [PATCH RFC 16/18] selftests: target_core_uring: Add a minimal server Qiliang Yuan
2026-11-16 1:03 ` sashiko-bot
2026-11-16 0:18 ` [PATCH RFC 17/18] selftests: target_core_uring: Test a device exported through tcm_loop Qiliang Yuan
2026-11-16 0:49 ` sashiko-bot
2026-11-16 0:18 ` [PATCH RFC 18/18] Documentation: target: Describe the uring backstore Qiliang Yuan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261115-feat-target-core-uring-v1-7-28cdc137eac6@linux.dev \
--to=qiliang.yuan@linux.dev \
--cc=axboe@kernel.dk \
--cc=bostroesser@gmail.com \
--cc=corbet@lwn.net \
--cc=io-uring@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=michael.christie@oracle.com \
--cc=mkp@kernel.org \
--cc=rdunlap@infradead.org \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=target-devel@vger.kernel.org \
--cc=tom.leiming@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox