Skip to content

Commit ee4bcd0

Browse files
zhangyi089kawasaki
authored andcommitted
nvme/065: add unmap write zeroes tests
Test block device unmap write zeroes sysfs interface with NVMeT devices which are based on various SCSI debug devices. The NVMe device's /sys/block/<disk>/queue/write_zeroes_unmap_max_hw_bytes should equal to the write_zeroes_max_bytes if the SCSI debug device enable the WRITE SAME command with unmap functionality, and it should return 0 otherwise. /sys/block/<disk>/queue/write_zeroes_unmap_max_bytes should be equal to write_zeroes_unmap_max_hw_bytes by default, and we can disable write zeroes support by setting it to zero. Signed-off-by: Zhang Yi <[email protected]> [Shin'ichiro: fixed a shellcheck warning] Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent e7c6123 commit ee4bcd0

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

tests/nvme/065

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-3.0+
3+
# Copyright (C) 2025 Huawei.
4+
#
5+
# Test block device unmap write zeroes sysfs interface with nvmet scsi
6+
# debug devices.
7+
8+
. tests/nvme/rc
9+
. common/scsi_debug
10+
11+
DESCRIPTION="test unmap write zeroes sysfs interface with nvmet devices"
12+
QUICK=1
13+
14+
nvme_trtype=loop
15+
nvmet_blkdev_type="device"
16+
17+
requires() {
18+
_have_scsi_debug
19+
_nvme_requires
20+
_require_nvme_trtype_is_loop
21+
}
22+
23+
readonly TO_SKIP=255
24+
25+
setup_test_device() {
26+
local port
27+
28+
if ! _configure_scsi_debug "$@"; then
29+
return 1
30+
fi
31+
32+
if [[ ! -f /sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_unmap_max_hw_bytes ]]; then
33+
_exit_scsi_debug
34+
return $TO_SKIP
35+
fi
36+
37+
port="$(_create_nvmet_port)"
38+
_create_nvmet_subsystem --blkdev "/dev/${SCSI_DEBUG_DEVICES[0]}"
39+
_add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"
40+
41+
_create_nvmet_host "${def_subsysnqn}" "${def_hostnqn}"
42+
_nvme_connect_subsys
43+
44+
_find_nvme_ns "${def_subsys_uuid}"
45+
}
46+
47+
cleanup_test_device() {
48+
_nvme_disconnect_subsys
49+
_nvmet_target_cleanup --subsysnqn "${def_subsysnqn}"
50+
_exit_scsi_debug
51+
}
52+
53+
test() {
54+
echo "Running ${TEST_NAME}"
55+
56+
_setup_nvmet
57+
58+
# disable WRITE SAME with unmap
59+
local dname
60+
dname=$(setup_test_device lbprz=0)
61+
ret=$?
62+
if ((ret)); then
63+
if ((ret == TO_SKIP)); then
64+
SKIP_REASONS+=("kernel does not support unmap write zeroes sysfs interface")
65+
fi
66+
return 1
67+
fi
68+
69+
umap_hw_bytes="$(cat "/sys/block/$dname/queue/write_zeroes_unmap_max_hw_bytes")"
70+
umap_bytes="$(cat "/sys/block/$dname/queue/write_zeroes_unmap_max_bytes")"
71+
if [[ $umap_hw_bytes -ne 0 || $umap_bytes -ne 0 ]]; then
72+
echo "Test disable WRITE SAME with unmap failed."
73+
fi
74+
cleanup_test_device
75+
76+
# enable WRITE SAME with unmap
77+
if ! dname=$(setup_test_device lbprz=1 lbpws=1); then
78+
return 1
79+
fi
80+
81+
zero_bytes="$(cat "/sys/block/$dname/queue/write_zeroes_max_bytes")"
82+
umap_hw_bytes="$(cat "/sys/block/$dname/queue/write_zeroes_unmap_max_hw_bytes")"
83+
umap_bytes="$(cat "/sys/block/$dname/queue/write_zeroes_unmap_max_bytes")"
84+
if [[ $umap_hw_bytes -ne $zero_bytes || $umap_bytes -ne $zero_bytes ]]; then
85+
echo "Test enable WRITE SAME with unmap failed."
86+
fi
87+
88+
echo 0 > "/sys/block/$dname/queue/write_zeroes_unmap_max_bytes"
89+
umap_bytes="$(cat "/sys/block/$dname/queue/write_zeroes_unmap_max_bytes")"
90+
if [[ $umap_bytes -ne 0 ]]; then
91+
echo "Test manually disable WRITE SAME with unmap failed."
92+
fi
93+
cleanup_test_device
94+
95+
echo "Test complete"
96+
}

tests/nvme/065.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Running nvme/065
2+
disconnected 1 controller(s)
3+
disconnected 1 controller(s)
4+
Test complete

0 commit comments

Comments
 (0)