|
| 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 | +} |
0 commit comments