Linux Documentation
 help / color / mirror / Atom feed
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 13/18] scsi: target: uring: Implement UNMAP
Date: Sun, 15 Nov 2026 19:18:06 -0500	[thread overview]
Message-ID: <20261115-feat-target-core-uring-v1-13-28cdc137eac6@linux.dev> (raw)
In-Reply-To: <20261115-feat-target-core-uring-v1-0-28cdc137eac6@linux.dev>

target_core_uring passes reads, writes and flushes to the server.

Thin provisioned storage also needs to know which blocks the initiator
no longer uses.

Add TCMUR_OP_UNMAP and send one for each range of an UNMAP command or of
a WRITE SAME with the UNMAP bit. The core expects execute_unmap() to
return once the range is unmapped, so queue a struct tcmur_cmd that
lives on the stack and wait for the server to commit it.

Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
 drivers/target/target_core_uring.c     | 39 ++++++++++++++++++++++++++++++++++
 include/uapi/linux/target_core_uring.h |  1 +
 2 files changed, 40 insertions(+)

diff --git a/drivers/target/target_core_uring.c b/drivers/target/target_core_uring.c
index f39bf7bf36d0f..366c5e9820956 100644
--- a/drivers/target/target_core_uring.c
+++ b/drivers/target/target_core_uring.c
@@ -49,6 +49,7 @@ struct tcmur_dev;
  * @ref:	Held by the tag or the pending list and by data copies in
  *		progress
  * @deadline:	When to give up waiting for the server
+ * @done:	Complete this instead of @se_cmd when the last reference goes
  * @status:	SAM status to complete @se_cmd with
  */
 struct tcmur_cmd {
@@ -59,6 +60,7 @@ struct tcmur_cmd {
 	struct tcmur_io_desc	desc;
 	refcount_t		ref;
 	unsigned long		deadline;
+	struct completion	*done;
 	u8			status;
 };
 
@@ -148,6 +150,11 @@ static void tcmur_cmd_put(struct tcmur_cmd *tcmd)
 	if (!refcount_dec_and_test(&tcmd->ref))
 		return;
 
+	if (tcmd->done) {
+		complete(tcmd->done);
+		return;
+	}
+
 	target_complete_cmd(tcmd->se_cmd, tcmd->status);
 	kmem_cache_free(tcmur_cmd_cache, tcmd);
 }
@@ -268,6 +275,36 @@ static sense_reason_t tcmur_execute_sync_cache(struct se_cmd *se_cmd)
 			    se_cmd->data_length, NULL, 0);
 }
 
+static sense_reason_t tcmur_execute_unmap(struct se_cmd *se_cmd, sector_t lba,
+					  sector_t nolb)
+{
+	u32 block_size = se_cmd->se_dev->dev_attrib.block_size;
+	DECLARE_COMPLETION_ONSTACK(done);
+	struct tcmur_cmd tcmd = {
+		.se_cmd		= se_cmd,
+		.done		= &done,
+		.desc.op	= TCMUR_OP_UNMAP,
+		.desc.offset	= lba * block_size,
+		.desc.len	= nolb * block_size,
+	};
+
+	/* Wait here, as the core completes the command after all ranges */
+	tcmur_queue_cmd(TCMUR_DEV(se_cmd->se_dev), &tcmd);
+	wait_for_completion(&done);
+
+	return tcmd.status ? TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE : 0;
+}
+
+static bool tcmur_configure_unmap(struct se_device *dev)
+{
+	dev->dev_attrib.max_unmap_lba_count = UINT_MAX /
+					      dev->dev_attrib.hw_block_size;
+	dev->dev_attrib.max_unmap_block_desc_count = 1;
+	dev->dev_attrib.unmap_granularity = 1;
+	dev->dev_attrib.unmap_granularity_alignment = 0;
+	return true;
+}
+
 static void tcmur_tmr_notify(struct se_device *dev, enum tcm_tmreq_table tmf,
 			     struct list_head *aborted_cmds)
 {
@@ -941,6 +978,7 @@ static sector_t tcmur_get_blocks(struct se_device *dev)
 static struct exec_cmd_ops tcmur_exec_cmd_ops = {
 	.execute_rw		= tcmur_execute_rw,
 	.execute_sync_cache	= tcmur_execute_sync_cache,
+	.execute_unmap		= tcmur_execute_unmap,
 };
 
 static sense_reason_t tcmur_parse_cdb(struct se_cmd *se_cmd)
@@ -959,6 +997,7 @@ static const struct target_backend_ops tcmur_ops = {
 	.configure_device	= tcmur_configure_device,
 	.destroy_device		= tcmur_destroy_device,
 	.free_device		= tcmur_free_device,
+	.configure_unmap	= tcmur_configure_unmap,
 	.parse_cdb		= tcmur_parse_cdb,
 	.tmr_notify		= tcmur_tmr_notify,
 	.set_configfs_dev_params = tcmur_set_configfs_dev_params,
diff --git a/include/uapi/linux/target_core_uring.h b/include/uapi/linux/target_core_uring.h
index a1d8ae47ebf7d..9df10558cfa9e 100644
--- a/include/uapi/linux/target_core_uring.h
+++ b/include/uapi/linux/target_core_uring.h
@@ -68,6 +68,7 @@ enum tcmur_io_op {
 	TCMUR_OP_READ,
 	TCMUR_OP_WRITE,
 	TCMUR_OP_FLUSH,
+	TCMUR_OP_UNMAP,
 };
 
 /* Put the write on stable storage before completing it */

-- 
2.43.0


  parent reply	other threads:[~2026-11-16  0:19 UTC|newest]

Thread overview: 19+ 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: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: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:17 ` [PATCH RFC 06/18] scsi: target: uring: Hand commands out through TCMUR_IO_FETCH Qiliang Yuan
2026-11-16  0:18 ` [PATCH RFC 07/18] scsi: target: uring: Complete commands with TCMUR_IO_COMMIT_AND_FETCH Qiliang Yuan
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:18 ` [PATCH RFC 11/18] scsi: target: uring: Drop aborted commands that are still queued Qiliang Yuan
2026-11-16  0:18 ` [PATCH RFC 12/18] scsi: target: uring: Support SYNCHRONIZE CACHE Qiliang Yuan
2026-11-16  0:18 ` Qiliang Yuan [this message]
2026-11-16  0:18 ` [PATCH RFC 14/18] scsi: target: uring: Handle WRITE SAME Qiliang Yuan
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  0:18 ` [PATCH RFC 17/18] selftests: target_core_uring: Test a device exported through tcm_loop Qiliang Yuan
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-13-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