|
| 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 MD devices. This is |
| 6 | +# the regression test for the kernel commit f0bd03832f5c ("md: init |
| 7 | +# queue_limits->max_hw_wzeroes_unmap_sectors parameter"). |
| 8 | + |
| 9 | +. tests/md/rc |
| 10 | +. common/scsi_debug |
| 11 | + |
| 12 | +DESCRIPTION="test unmap write zeroes sysfs interface with MD devices" |
| 13 | +QUICK=1 |
| 14 | + |
| 15 | +requires() { |
| 16 | + _have_scsi_debug |
| 17 | + _have_driver linear |
| 18 | + _have_driver raid0 |
| 19 | +} |
| 20 | + |
| 21 | +setup_test_device() { |
| 22 | + local dev_0 dev_1 dpath |
| 23 | + local raid_level=$1 |
| 24 | + local scsi_debug_params=( |
| 25 | + num_tgts=1 |
| 26 | + add_host=2 |
| 27 | + per_host_store=true |
| 28 | + "${@:2}" |
| 29 | + ) |
| 30 | + |
| 31 | + if ! _configure_scsi_debug "${scsi_debug_params[@]}"; then |
| 32 | + return 1 |
| 33 | + fi |
| 34 | + |
| 35 | + if [[ ! -f /sys/block/${SCSI_DEBUG_DEVICES[0]}/queue/write_zeroes_unmap_max_hw_bytes ]]; then |
| 36 | + _exit_scsi_debug |
| 37 | + return $TO_SKIP |
| 38 | + fi |
| 39 | + |
| 40 | + dev_0="/dev/${SCSI_DEBUG_DEVICES[0]}" |
| 41 | + dev_1="/dev/${SCSI_DEBUG_DEVICES[1]}" |
| 42 | + mdadm --create /dev/md/blktests_md --level="$raid_level" --raid-devices=2 \ |
| 43 | + --force --run "${dev_0}" "${dev_1}" 2> /dev/null 1>&2 |
| 44 | + |
| 45 | + dpath=$(_real_dev /dev/md/blktests_md) |
| 46 | + echo "${dpath##*/}" |
| 47 | +} |
| 48 | + |
| 49 | +cleanup_test_device() { |
| 50 | + mdadm --stop /dev/md/blktests_md 2> /dev/null 1>&2 |
| 51 | + _exit_scsi_debug |
| 52 | +} |
| 53 | + |
| 54 | +test() { |
| 55 | + echo "Running ${TEST_NAME}" |
| 56 | + |
| 57 | + local dname |
| 58 | + |
| 59 | + for raid_level in linear raid0; do |
| 60 | + # disable WRITE SAME with unmap |
| 61 | + dname=$(setup_test_device $raid_level lbprz=0) |
| 62 | + ret=$? |
| 63 | + if ((ret)); then |
| 64 | + if ((ret == TO_SKIP)); then |
| 65 | + SKIP_REASONS+=("kernel does not support unmap write zeroes sysfs interface") |
| 66 | + fi |
| 67 | + return 1 |
| 68 | + fi |
| 69 | + |
| 70 | + umap_hw_bytes="$(cat "/sys/block/$dname/queue/write_zeroes_unmap_max_hw_bytes")" |
| 71 | + umap_bytes="$(cat "/sys/block/$dname/queue/write_zeroes_unmap_max_bytes")" |
| 72 | + if [[ $umap_hw_bytes -ne 0 || $umap_bytes -ne 0 ]]; then |
| 73 | + echo "$raid_level: Test disable WRITE SAME with unmap failed." |
| 74 | + fi |
| 75 | + cleanup_test_device |
| 76 | + |
| 77 | + # enable WRITE SAME with unmap |
| 78 | + if ! dname=$(setup_test_device $raid_level lbprz=1 lbpws=1); then |
| 79 | + return 1 |
| 80 | + fi |
| 81 | + |
| 82 | + zero_bytes="$(cat "/sys/block/$dname/queue/write_zeroes_max_bytes")" |
| 83 | + umap_hw_bytes="$(cat "/sys/block/$dname/queue/write_zeroes_unmap_max_hw_bytes")" |
| 84 | + umap_bytes="$(cat "/sys/block/$dname/queue/write_zeroes_unmap_max_bytes")" |
| 85 | + if [[ $umap_hw_bytes -ne $zero_bytes || $umap_bytes -ne $zero_bytes ]]; then |
| 86 | + echo "$raid_level: Test enable WRITE SAME with unmap failed." |
| 87 | + fi |
| 88 | + |
| 89 | + echo 0 > "/sys/block/$dname/queue/write_zeroes_unmap_max_bytes" |
| 90 | + umap_bytes="$(cat "/sys/block/$dname/queue/write_zeroes_unmap_max_bytes")" |
| 91 | + if [[ $umap_bytes -ne 0 ]]; then |
| 92 | + echo "$raid_level: Test manually disable WRITE SAME with unmap failed." |
| 93 | + fi |
| 94 | + cleanup_test_device |
| 95 | + done |
| 96 | + |
| 97 | + echo "Test complete" |
| 98 | +} |
0 commit comments