From: Josef Bacik Date: Tue, 19 Mar 2024 18:12:05 +0000 (+0100) Subject: btrfs/330: add test to validate ro/rw subvol mounting X-Git-Tag: v2024.03.31~14 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=af82dc0ed2039df3116be239d95b0b17eea6a859;p=xfstests-dev.git btrfs/330: add test to validate ro/rw subvol mounting Btrfs has had the ability for almost a decade to allow ro and rw mounting of subvols. This behavior specifically mount -o subvol=foo,ro /some/dir mount -o subvol=bar,rw /some/other/dir This seems simple, but because of the limitations of how we did mounting in ye olde days we would mark the super block as RO and the mount if we mounted RO first. In the case above /some/dir would instantiate the super block as read only and the mount point. So the second mount command under the covers would convert the super block to RW, and then allow the mount to continue. The results were still consistent, /some/dir was still read only because the mount was marked read only, but /some/other/dir could be written to. This is a test to make sure we maintain this behavior, as I almost regressed this behavior while converting us to the new mount API. Reviewed-by: Anand Jain Signed-off-by: Josef Bacik Signed-off-by: Anand Jain [ Fixed mkfs.btrfs redirect. Removed common/filter. ] --- diff --git a/tests/btrfs/330 b/tests/btrfs/330 new file mode 100755 index 00000000..095f6b36 --- /dev/null +++ b/tests/btrfs/330 @@ -0,0 +1,53 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2023 Meta Platforms, Inc. All Rights Reserved. +# +# FS QA Test No. btrfs/330 +# +# Test mounting one subvolume as ro and another as rw +# +. ./common/preamble +_begin_fstest auto quick subvol + +_cleanup() +{ + rm -rf $TEST_DIR/$seq +} + +# Import common functions. +. ./common/filter.btrfs + +# real QA test starts here +_supported_fs btrfs +_require_scratch + +$MOUNT_PROG -V | grep -q 'fd-based-mount' +[ "$?" -eq 0 ] && _notrun "mount uses the new mount api" + +_scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed" +_scratch_mount + +# Create our subvolumes to mount +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/foo | _filter_scratch +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/bar | _filter_scratch + +_scratch_unmount + +mkdir -p $TEST_DIR/$seq/foo +mkdir -p $TEST_DIR/$seq/bar + +_mount -t btrfs -o subvol=foo,ro $SCRATCH_DEV $TEST_DIR/$seq/foo +_mount -t btrfs -o subvol=bar,rw $SCRATCH_DEV $TEST_DIR/$seq/bar + +echo "making sure foo is read only" +touch $TEST_DIR/$seq/foo/baz > /dev/null 2&>1 +ls $TEST_DIR/$seq/foo + +echo "making sure bar allows writes" +touch $TEST_DIR/$seq/bar/qux +ls $TEST_DIR/$seq/bar + +$UMOUNT_PROG $TEST_DIR/$seq/foo +$UMOUNT_PROG $TEST_DIR/$seq/bar + +status=0 ; exit diff --git a/tests/btrfs/330.out b/tests/btrfs/330.out new file mode 100644 index 00000000..4795a2cc --- /dev/null +++ b/tests/btrfs/330.out @@ -0,0 +1,6 @@ +QA output created by 330 +Create subvolume 'SCRATCH_MNT/foo' +Create subvolume 'SCRATCH_MNT/bar' +making sure foo is read only +making sure bar allows writes +qux