[PATCH blktests 2/2] nvme: add test for writing to file-ns just after disabling it

Nilay Shroff
2024-11-29T08:03:00Z

This is a regression test for commit 505363957fad ("nvmet: fix nvme
status code when namespace is disabled")[1].

This test creates a regular file backed loop target namespace and
then write to that namespace just after disabling it in a loop.

[1] https://lore.kernel.org/linux-nvme/tqcy3sveity7p56v7ywp7ssyviwcb3w4623cnxj3knoobfcanq@yxgt2mjkbkam/

Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
tests/nvme/055 | 74 ++++++++++++++++++++++++++++++++++++++++++++++
tests/nvme/055.out | 2 ++
2 files changed, 76 insertions(+)
create mode 100755 tests/nvme/055
create mode 100644 tests/nvme/055.out

diff --git a/tests/nvme/055 b/tests/nvme/055
new file mode 100755
index 0000000..0dbba74
--- /dev/null
+++ b/tests/nvme/055
@@ -0,0 +1,74 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Nilay Shroff
+#
+# Regression test for commit 505363957fad ("nvmet: fix nvme
+# status code when namespace is disabled").
+
+. tests/nvme/rc
+
+DESCRIPTION="Test nvme write to a loop target ns just after ns is disabled"
+
+QUICK=1
+
+requires() {
+ _nvme_requires
+ _have_loop
+ _require_nvme_trtype_is_loop
+}
+
+set_conditions() {
+ _set_nvme_trtype "$@"
+}
+
+test() {
+ echo "Running ${TEST_NAME}"
+
+ local iterations=10
+
+ _setup_nvmet
+
+ _nvmet_target_setup
+
+ _nvme_connect_subsys
+
+ img="$(mktemp /tmp/blk_img_XXXXXX)"
+ dd if=/dev/urandom of="$img" bs=512 count=1 status=none
+
+ subsys_path="${NVMET_CFS}/subsystems/${def_subsysnqn}"
+ ns_path="${subsys_path}/namespaces/${def_nsid}"
+
+ for ((i = 0; i < iterations; i++)); do
+
+ # wait until async request is processed and ns is created
+ if ! _nvmf_wait_for_ns "${def_subsys_uuid}" created; then
+ echo "FAIL"
+ break
+ fi
+
+ disk="/dev/$(_find_nvme_ns "${def_subsys_uuid}")"
+
+ # disable target namespace and write to it
+ echo 0 > ${ns_path}/enable
+ nvme write --start-block=1 --block-count=0 \
+ --data-size=512 --data="$img" "$disk" 2>>"$FULL"
+
+ # wait until async request is processed and ns is removed
+ if ! _nvmf_wait_for_ns "${def_subsys_uuid}" removed; then
+ echo "FAIL"
+ break
+ fi
+
+ # enable target namespace
+ echo 1 > ${ns_path}/enable
+ done
+
+ rm "$img"
+
+ _nvme_disconnect_subsys >> "$FULL" 2>&1
+
+ _nvmet_target_cleanup
+
+
+ echo "Test complete"
+}
diff --git a/tests/nvme/055.out b/tests/nvme/055.out
new file mode 100644
index 0000000..bbefc28
--- /dev/null
+++ b/tests/nvme/055.out
@@ -0,0 +1,2 @@
+Running nvme/055
+Test complete
--
2.45.2