Linux Kernel Selftest development
 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 17/18] selftests: target_core_uring: Test a device exported through tcm_loop
Date: Sun, 15 Nov 2026 19:18:10 -0500	[thread overview]
Message-ID: <20261115-feat-target-core-uring-v1-17-28cdc137eac6@linux.dev> (raw)
In-Reply-To: <20261115-feat-target-core-uring-v1-0-28cdc137eac6@linux.dev>

tcmur_server can serve a target_core_uring device from a backing file.

Nothing checks that the backstore and the server work together.

Add a test that exports a device through tcm_loop and compares the SCSI
disk with the backing file after writes, reads, flushes, UNMAP and
WRITE SAME, with and without zero copy. Also check that a new server
takes over after the first one is killed, and that commands time out
without a server.

Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
 tools/testing/selftests/Makefile                   |   1 +
 tools/testing/selftests/target_core_uring/Makefile |   1 +
 tools/testing/selftests/target_core_uring/config   |   5 +
 .../selftests/target_core_uring/tcmur_test.sh      | 137 +++++++++++++++++++++
 4 files changed, 144 insertions(+)

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 07c3719f8b04b..8e97d4b374a09 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -131,6 +131,7 @@ TARGETS += static_keys
 TARGETS += sync
 TARGETS += syscall_user_dispatch
 TARGETS += sysctl
+TARGETS += target_core_uring
 TARGETS += tc-testing
 TARGETS += tdx
 TARGETS += thermal/intel/power_floor
diff --git a/tools/testing/selftests/target_core_uring/Makefile b/tools/testing/selftests/target_core_uring/Makefile
index 438628fd1606b..202f174a17e08 100644
--- a/tools/testing/selftests/target_core_uring/Makefile
+++ b/tools/testing/selftests/target_core_uring/Makefile
@@ -2,6 +2,7 @@
 CFLAGS += -O2 -Wall -D_GNU_SOURCE $(KHDR_INCLUDES)
 LDLIBS += -luring -lpthread
 
+TEST_PROGS := tcmur_test.sh
 TEST_GEN_PROGS_EXTENDED := tcmur_server
 
 include ../lib.mk
diff --git a/tools/testing/selftests/target_core_uring/config b/tools/testing/selftests/target_core_uring/config
new file mode 100644
index 0000000000000..9115bf367c169
--- /dev/null
+++ b/tools/testing/selftests/target_core_uring/config
@@ -0,0 +1,5 @@
+CONFIG_IO_URING=y
+CONFIG_TARGET_CORE=m
+CONFIG_TCM_URING=m
+CONFIG_LOOPBACK_TARGET=m
+CONFIG_BLK_DEV_SD=m
diff --git a/tools/testing/selftests/target_core_uring/tcmur_test.sh b/tools/testing/selftests/target_core_uring/tcmur_test.sh
new file mode 100755
index 0000000000000..99f68e74c7cd0
--- /dev/null
+++ b/tools/testing/selftests/target_core_uring/tcmur_test.sh
@@ -0,0 +1,137 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Export a target_core_uring device through tcm_loop, serve it with
+# tcmur_server and check the resulting SCSI disk against the backing file.
+
+DIR=$(dirname "$(readlink -f "$0")")
+KSFT_SKIP=4
+T=/sys/kernel/config/target
+C=$T/core/uring_70/tcmur_test
+WWN=naa.5001405074636d75
+L=$T/loopback/$WWN/tpgt_1
+SIZE=$((256 << 20))
+IMG=$(mktemp /tmp/tcmur_test.XXXXXX)
+PAT=$(mktemp /tmp/tcmur_test.XXXXXX)
+server=
+dev=
+fail=0
+
+[ "$(id -u)" = 0 ] || { echo "SKIP: need root"; exit $KSFT_SKIP; }
+modprobe -q target_core_uring && modprobe -q tcm_loop ||
+	{ echo "SKIP: need target_core_uring and tcm_loop"; exit $KSFT_SKIP; }
+
+check() {	# <name> <command...>
+	local name=$1; shift
+
+	if "$@"; then
+		echo "ok $name"
+	else
+		echo "not ok $name"
+		fail=1
+	fi
+}
+
+# setup <control parameters> <serve|idle> [server arguments...]
+setup() {
+	local params=$1 serve=$2 before cdev; shift 2
+
+	truncate -s 0 "$IMG"; truncate -s $SIZE "$IMG"
+	mkdir -p $C
+	echo "dev_size=$SIZE,nr_queues=2,queue_depth=32$params" > $C/control
+	echo 1 > $C/enable
+	echo 1 > $C/attrib/emulate_tpu
+	echo 1 > $C/attrib/emulate_tpws
+	echo 1 > $C/attrib/emulate_write_cache
+	cdev=$(grep -o '/dev/tcmur[0-9]*' $C/info)
+	udevadm settle
+
+	if [ "$serve" = serve ]; then
+		"$DIR"/tcmur_server "$@" "$cdev" "$IMG" &
+		server=$!
+		sleep 1
+	fi
+
+	before=$(lsblk -dno NAME | sort)
+	mkdir -p $L
+	echo naa.5001405074636d76 > $L/nexus
+	mkdir $L/lun/lun_0
+	ln -s $C $L/lun/lun_0/tcmur_test
+	for _ in $(seq 40); do
+		dev=$(comm -13 <(echo "$before") <(lsblk -dno NAME | sort) | head -1)
+		[ -n "$dev" ] && break
+		sleep 0.5
+	done
+	udevadm settle
+	dev=/dev/$dev
+}
+
+teardown() {
+	rm $L/lun/lun_0/tcmur_test
+	rmdir $L/lun/lun_0 $L $T/loopback/$WWN
+	rmdir $C "$(dirname $C)"
+	# Wait for the server, which exits when the device goes
+	if [ -n "$server" ]; then
+		wait $server 2>/dev/null
+		server=
+	fi
+}
+
+same_as_image() {	# <offset MiB> <count MiB> <file>
+	cmp -s <(dd if="$IMG" bs=1M skip="$1" count="$2" status=none) "$3"
+}
+
+test_io() {	# <name> [server arguments...]
+	local name=$1 blocks; shift
+
+	setup "" serve "$@"
+	dd if=/dev/urandom of="$PAT" bs=1M count=8 status=none
+
+	dd if="$PAT" of=$dev bs=1M seek=16 oflag=direct status=none
+	check "$name write" same_as_image 16 8 "$PAT"
+	check "$name read" cmp -s \
+		<(dd if=$dev bs=1M skip=16 count=8 iflag=direct status=none) "$PAT"
+	check "$name flush" dd if="$PAT" of=$dev bs=1M seek=32 conv=fsync \
+		status=none
+
+	blocks=$(stat -c %b "$IMG")
+	blkdiscard -o $((16 << 20)) -l $((8 << 20)) $dev
+	check "$name unmap" [ "$(stat -c %b "$IMG")" -lt "$blocks" ]
+
+	if command -v sg_write_same > /dev/null; then
+		dd if=/dev/zero of="$PAT" bs=1M count=1 status=none
+		sg_write_same --in=/dev/zero --lba=$((32 << 11)) --num=2048 \
+			--xferlen=512 $dev > /dev/null 2>&1
+		check "$name write same" same_as_image 32 1 "$PAT"
+	else
+		echo "ok $name write same # SKIP no sg_write_same"
+	fi
+	teardown
+}
+
+test_io copy
+test_io "zero copy" -z
+
+# Check that a new server takes over after the first one is killed
+setup "" serve
+kill -9 $server; wait $server 2>/dev/null
+for _ in $(seq 20); do
+	"$DIR"/tcmur_server "$(grep -o '/dev/tcmur[0-9]*' $C/info)" "$IMG" \
+		2>/dev/null &
+	server=$!
+	sleep 0.5
+	kill -0 $server 2>/dev/null && break
+done
+check "server restart" dd if=$dev of=/dev/null bs=1M count=8 iflag=direct \
+	status=none
+teardown
+
+# Check that commands fail after cmd_time_out seconds without a server
+setup ",cmd_time_out=1" idle
+start=$(date +%s)
+dd if=$dev of=/dev/null bs=4k count=1 iflag=direct status=none 2>/dev/null
+check "command timeout" [ $? -ne 0 -a $(($(date +%s) - start)) -lt 30 ]
+teardown
+
+rm -f "$IMG" "$PAT"
+exit $fail

-- 
2.43.0


  parent reply	other threads:[~2026-11-16  0:20 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 ` [PATCH RFC 13/18] scsi: target: uring: Implement UNMAP Qiliang Yuan
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 ` Qiliang Yuan [this message]
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-17-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