Skip to content

Commit 653c713

Browse files
zhangyi089kawasaki
authored andcommitted
scsi/010: add unmap write zeroes tests
Test block device unmap write zeroes sysfs interface with various SCSI debug devices. /sys/block/<disk>/queue/write_zeroes_unmap_max_hw_bytes should equal to the write_zeroes_max_bytes if the SCSI 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]> Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent a08678c commit 653c713

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

tests/scsi/010

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 various scsi
6+
# devices.
7+
8+
. tests/scsi/rc
9+
. common/scsi_debug
10+
11+
DESCRIPTION="test unmap write zeroes sysfs interface with scsi devices"
12+
QUICK=1
13+
14+
requires() {
15+
_have_scsi_debug
16+
}
17+
18+
setup_test_device() {
19+
if ! _configure_scsi_debug "$@"; then
20+
return 1
21+
fi
22+
23+
if [[ ! -f /sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_unmap_max_hw_bytes ]]; then
24+
_exit_scsi_debug
25+
SKIP_REASONS+=("kernel does not support unmap write zeroes sysfs interface")
26+
return 1
27+
fi
28+
}
29+
30+
test() {
31+
echo "Running ${TEST_NAME}"
32+
33+
# disable WRITE SAME with unmap
34+
if ! setup_test_device lbprz=0; then
35+
return 1
36+
fi
37+
38+
umap_hw_bytes="$(cat "/sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_unmap_max_hw_bytes")"
39+
umap_bytes="$(cat "/sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_unmap_max_bytes")"
40+
if [[ $umap_hw_bytes -ne 0 || $umap_bytes -ne 0 ]]; then
41+
echo "Test disable WRITE SAME with unmap failed."
42+
fi
43+
_exit_scsi_debug
44+
45+
# enable WRITE SAME(16) with unmap
46+
if ! setup_test_device lbprz=1 lbpws=1; then
47+
return 1
48+
fi
49+
50+
zero_bytes="$(cat "/sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_max_bytes")"
51+
umap_hw_bytes="$(cat "/sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_unmap_max_hw_bytes")"
52+
umap_bytes="$(cat "/sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_unmap_max_bytes")"
53+
if [[ $umap_hw_bytes -ne $zero_bytes || $umap_bytes -ne $zero_bytes ]]; then
54+
echo "Test enable WRITE SAME(16) with unmap failed."
55+
fi
56+
57+
echo 0 > "/sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_unmap_max_bytes"
58+
umap_bytes="$(cat "/sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_unmap_max_bytes")"
59+
if [[ $umap_bytes -ne 0 ]]; then
60+
echo "Test manually disable WRITE SAME(16) with unmap failed."
61+
fi
62+
_exit_scsi_debug
63+
64+
# enable WRITE SAME(10) with unmap
65+
if ! setup_test_device lbprz=1 lbpws10=1; then
66+
return 1
67+
fi
68+
69+
zero_bytes="$(cat "/sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_max_bytes")"
70+
umap_hw_bytes="$(cat "/sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_unmap_max_hw_bytes")"
71+
umap_bytes="$(cat "/sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_unmap_max_bytes")"
72+
if [[ $umap_hw_bytes -ne $zero_bytes || $umap_bytes -ne $zero_bytes ]]; then
73+
echo "Test enable WRITE SAME(10) with unmap failed."
74+
fi
75+
76+
echo 0 > "/sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_unmap_max_bytes"
77+
umap_bytes="$(cat "/sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_unmap_max_bytes")"
78+
if [[ $umap_bytes -ne 0 ]]; then
79+
echo "Test manually disable WRITE SAME(10) with unmap failed."
80+
fi
81+
_exit_scsi_debug
82+
83+
echo "Test complete"
84+
}

tests/scsi/010.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Running scsi/010
2+
Test complete

0 commit comments

Comments
 (0)