btrfs-progs: tests: misc/046: fix false alerts on write detection

[BUG]
Test case misc/046-seed-multi-mount would always fail with the following
error:

    [TEST]   misc-tests.sh
    [TEST/misc]   046-seed-multi-mount
unexpected success: writable file despite read-only mount
test failed for case 046-seed-multi-mount

[CAUSE]
Although mounting seed device is indeed read-only, sprouting it with a
new device would always make it read-write by itself.

The behavior is already there for a long time, thus expecting a new
behavior (not changing the read-only flag) is a little weird.

[FIX]
Instead of doing the write check after the sprout, do it before the
sprout.

This looks more correct, and would not rely on the kernel behavior
change (if we determine to go that path).

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Qu Wenruo 2023-08-09 06:40:43 +08:00 committed by David Sterba
parent e6b412b359
commit cb19235991

View File

@ -42,9 +42,11 @@ nextdevice() {
run_check mkdir -p "$mnt"
TEST_MNT="$mnt"
run_check_mount_test_dev
run_check $SUDO_HELPER "$TOP/btrfs" device add ${loopdevs[$nextdev]} "$TEST_MNT"
run_mustfail "writable file despite read-only mount" \
$SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file$nextdevice" bs=1M count=1 status=none
run_check $SUDO_HELPER "$TOP/btrfs" device add ${loopdevs[$nextdev]} "$TEST_MNT"
# Although seed sprout would make the fs RW, explicitly remount it RW
# just in case of future behavior change.
run_check $SUDO_HELPER mount -o remount,rw "$TEST_MNT"
# Rewrite the file
md5sum=$(run_check_stdout md5sum "$TEST_MNT/file$nextdev" | awk '{print $1}')