We have had several regressions wrt. read-only device handling. This is mainly caused by the fact that the device ro state can be set both by the user as well as the device. Add a series of tests that verify that all the intersections of user policy vs. device state changes are handled correctly in the block layer. Signed-off-by: Martin K. Petersen <martin.petersen@xxxxxxxxxx> --- v2: Hadn't verified the non-sdebug-wp parameter case after I changed output format. Fixed. --- tests/block/022 | 92 +++++++++++++++++++++++++++++++++++++++++++++ tests/block/022.out | 22 +++++++++++ 2 files changed, 114 insertions(+) create mode 100755 tests/block/022 create mode 100644 tests/block/022.out diff --git a/tests/block/022 b/tests/block/022 new file mode 100755 index 000000000000..2ce2cabc8ec9 --- /dev/null +++ b/tests/block/022 @@ -0,0 +1,92 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ +# Copyright (C) 2019 Martin K. Petersen <martin.petersen@xxxxxxxxxx> +# +# Test that device read-only state transitions are handled correctly. + +. tests/block/rc +. common/scsi_debug + +DESCRIPTION="test that device read-only state transitions are handled correctly" + +requires() { + _have_scsi_debug +} + +get_ro() { + local sys="/sys/block/${SCSI_DEBUG_DEVICES[0]}" + local ROSTATE=() + + for part in "${sys}"/ro "${sys}"/*/ro; do + ROSTATE+=("$(cat "${part}")") + done + + echo "${ROSTATE[*]}" +} + +test() { + echo "Running ${TEST_NAME}" + + if ! _init_scsi_debug dev_size_mb=128 num_parts=3; then + return 1 + fi + + local dev="/dev/${SCSI_DEBUG_DEVICES[0]}" + local sys="/sys/block/${SCSI_DEBUG_DEVICES[0]}" + local wp="/sys/module/scsi_debug/parameters/wp" + + echo "Verify that device comes up read-write" + get_ro + + echo "Verify that setting partition 2 read-only works" + blockdev --setro "${dev}2" + get_ro + + echo "Verify that setting whole disk read-only works" + blockdev --setro "${dev}" + get_ro + + echo "Verify that device revalidate works for whole disk policy" + echo 1 > "${sys}/device/rescan" + get_ro + + echo "Verify that setting whole disk device back to read-write works" + blockdev --setrw "${dev}" + get_ro + + echo "Verify that device revalidate works for partition policy" + echo 1 > "${sys}/device/rescan" + get_ro + + echo "Verify setting hardware device read-only" + if [[ -f "${wp}" ]]; then + echo 1 > "${wp}" + echo 1 > "${sys}/device/rescan" + get_ro + else + echo "1 1 1 1" + fi + + echo "Verify setting hardware device read-write" + if [[ -f "${wp}" ]]; then + echo 0 > "${wp}" + echo 1 > "${sys}/device/rescan" + get_ro + else + echo "0 0 1 0" + fi + + echo "Verify that partition read-only policy is lost after BLKRRPART" + blockdev --setro "${dev}2" + blockdev --rereadpt "${dev}" + get_ro + + echo "Verify that whole disk read-only policy persists after BLKRRPART" + blockdev --setro "${dev}" + blockdev --rereadpt "${dev}" + get_ro + + _exit_scsi_debug + + echo "Test complete" +} diff --git a/tests/block/022.out b/tests/block/022.out new file mode 100644 index 000000000000..c89d6d81903d --- /dev/null +++ b/tests/block/022.out @@ -0,0 +1,22 @@ +Running block/022 +Verify that device comes up read-write +0 0 0 0 +Verify that setting partition 2 read-only works +0 0 1 0 +Verify that setting whole disk read-only works +1 1 1 1 +Verify that device revalidate works for whole disk policy +1 1 1 1 +Verify that setting whole disk device back to read-write works +0 0 1 0 +Verify that device revalidate works for partition policy +0 0 1 0 +Verify setting hardware device read-only +1 1 1 1 +Verify setting hardware device read-write +0 0 1 0 +Verify that partition read-only policy is lost after BLKRRPART +0 0 0 0 +Verify that whole disk read-only policy persists after BLKRRPART +1 1 1 1 +Test complete -- 2.21.0