[PATCH RFC 12/18] scsi: target: uring: Support SYNCHRONIZE CACHE

From: Qiliang Yuan

Date: Sun Nov 15 2026 - 19:20:04 EST


target_core_uring only passes reads and writes to the server.

A server that caches writes has no way to learn that the initiator
wants them on stable storage.

Add TCMUR_OP_FLUSH and send it for SYNCHRONIZE CACHE. The descriptor
carries the range to flush; a zero length means up to the end of the
device.

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

diff --git a/drivers/target/target_core_uring.c b/drivers/target/target_core_uring.c
index 629419a4c8f46..f39bf7bf36d0f 100644
--- a/drivers/target/target_core_uring.c
+++ b/drivers/target/target_core_uring.c
@@ -237,7 +237,8 @@ static sense_reason_t tcmur_submit(struct se_cmd *se_cmd, u32 op, u64 offset,
tcmd->desc.op = op;
tcmd->desc.offset = offset;
tcmd->desc.len = len;
- tcmd->desc.data_len = se_cmd->data_length;
+ if (sgl)
+ tcmd->desc.data_len = se_cmd->data_length;
if (op == TCMUR_OP_WRITE && (se_cmd->se_cmd_flags & SCF_FUA))
tcmd->desc.flags |= TCMUR_IO_F_FUA;

@@ -257,6 +258,16 @@ static sense_reason_t tcmur_execute_rw(struct se_cmd *se_cmd,
se_cmd->data_length, sgl, sgl_nents);
}

+static sense_reason_t tcmur_execute_sync_cache(struct se_cmd *se_cmd)
+{
+ u32 block_size = se_cmd->se_dev->dev_attrib.block_size;
+
+ /* Pass a zero length to flush up to the end of the device */
+ return tcmur_submit(se_cmd, TCMUR_OP_FLUSH,
+ se_cmd->t_task_lba * block_size,
+ se_cmd->data_length, NULL, 0);
+}
+
static void tcmur_tmr_notify(struct se_device *dev, enum tcm_tmreq_table tmf,
struct list_head *aborted_cmds)
{
@@ -929,6 +940,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,
};

static sense_reason_t tcmur_parse_cdb(struct se_cmd *se_cmd)
diff --git a/include/uapi/linux/target_core_uring.h b/include/uapi/linux/target_core_uring.h
index 8b95be853753c..a1d8ae47ebf7d 100644
--- a/include/uapi/linux/target_core_uring.h
+++ b/include/uapi/linux/target_core_uring.h
@@ -67,6 +67,7 @@ struct tcmur_io_cmd {
enum tcmur_io_op {
TCMUR_OP_READ,
TCMUR_OP_WRITE,
+ TCMUR_OP_FLUSH,
};

/* Put the write on stable storage before completing it */

--
2.43.0