Skip to content

Commit e7c6123

Browse files
zhangyi089kawasaki
authored andcommitted
dm/003: add unmap write zeroes tests
Test block device unmap write zeroes sysfs interface with device-mapper stacked devices. The sysfs parameters should inherit from the underlying SCSI device. We can disable write zeroes support by setting /sys/block/dm-<X>/queue/write_zeroes_unmap_max_bytes 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 653c713 commit e7c6123

3 files changed

Lines changed: 98 additions & 0 deletions

File tree

common/rc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,3 +668,13 @@ _io_uring_restore()
668668
echo "$IO_URING_DISABLED" > /proc/sys/kernel/io_uring_disabled
669669
fi
670670
}
671+
672+
# get real device path name by following link
673+
_real_dev()
674+
{
675+
local dev=$1
676+
if [ -b "$dev" ] && [ -L "$dev" ]; then
677+
dev=$(readlink -f "$dev")
678+
fi
679+
echo "$dev"
680+
}

tests/dm/003

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

tests/dm/003.out

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

0 commit comments

Comments
 (0)