From: Nikolay Borisov Date: Mon, 30 Aug 2021 15:36:41 +0000 (+0300) Subject: btrfs: test for rename/exchange behavior between subvolumes X-Git-Tag: v2022.05.01~248 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=281b2bd374e22a1dd49644dec48b1b50ee0da654;p=xfstests-dev.git btrfs: test for rename/exchange behavior between subvolumes This tests ensures that renames/exchanges across subvolumes work only for other subvolumes and are otherwise forbidden and fail. Signed-off-by: Nikolay Borisov Reviewed-by: Filipe Manana Signed-off-by: Eryu Guan --- diff --git a/tests/btrfs/247 b/tests/btrfs/247 new file mode 100755 index 00000000..ca0f41a1 --- /dev/null +++ b/tests/btrfs/247 @@ -0,0 +1,60 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2021 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 247 +# +# Tests rename/exchange behavior when subvolumes are involved. Rename/exchanges +# across subvolumes are forbidden. This is also a regression test for +# 3f79f6f6247c ("btrfs: prevent rename2 from exchanging a subvol with a +# directory from different parents"). +# +. ./common/preamble +_begin_fstest auto quick rename subvol + +# Import common functions. + . ./common/renameat2 + +# real QA test starts here + +# Modify as appropriate. +_supported_fs btrfs +_require_renameat2 exchange +_require_scratch + +_scratch_mkfs >> $seqres.full 2>&1 +_scratch_mount + +# Create 2 subvols to use as parents for the rename ops +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol1 1>/dev/null +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol2 1>/dev/null + +# Ensure cross subvol ops are forbidden +_rename_tests_source_dest $SCRATCH_MNT/subvol1/src $SCRATCH_MNT/subvol2/dst "cross-subvol" "-x" + +# Prepare a subvolume and a directory whose parents are different subvolumes +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol1/sub-subvol 1>/dev/null +mkdir $SCRATCH_MNT/subvol2/dir + +# Ensure exchanging a subvol with a dir when both parents are different fails +$here/src/renameat2 -x $SCRATCH_MNT/subvol1/sub-subvol $SCRATCH_MNT/subvol2/dir + +echo "ordinary rename" +# Test also ordinary renames +_rename_tests_source_dest $SCRATCH_MNT/subvol1/src $SCRATCH_MNT/subvol2/dst "cross-subvol" + +echo "subvolumes rename" +# Rename subvol1/sub-subvol -> subvol2/sub-subvol +$here/src/renameat2 $SCRATCH_MNT/subvol1/sub-subvol $SCRATCH_MNT/subvol2/sub-subvol +# Now create another subvol under subvol1/ +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol1/sub-subvol 1>/dev/null +# and exchange the two +$here/src/renameat2 -x $SCRATCH_MNT/subvol2/sub-subvol $SCRATCH_MNT/subvol1/sub-subvol + +# simple rename of a subvolume in the same directory, should catch +# 4871c1588f92 ("Btrfs: use right root when checking for hash collision") +mv $SCRATCH_MNT/subvol2/ $SCRATCH_MNT/subvol2. + +# success, all done +status=0 +exit diff --git a/tests/btrfs/247.out b/tests/btrfs/247.out new file mode 100644 index 00000000..89755b2f --- /dev/null +++ b/tests/btrfs/247.out @@ -0,0 +1,54 @@ +QA output created by 247 +cross-subvol none/none -> No such file or directory +cross-subvol none/regu -> No such file or directory +cross-subvol none/symb -> No such file or directory +cross-subvol none/dire -> No such file or directory +cross-subvol none/tree -> No such file or directory +cross-subvol regu/none -> No such file or directory +cross-subvol regu/regu -> Invalid cross-device link +cross-subvol regu/symb -> Invalid cross-device link +cross-subvol regu/dire -> Invalid cross-device link +cross-subvol regu/tree -> Invalid cross-device link +cross-subvol symb/none -> No such file or directory +cross-subvol symb/regu -> Invalid cross-device link +cross-subvol symb/symb -> Invalid cross-device link +cross-subvol symb/dire -> Invalid cross-device link +cross-subvol symb/tree -> Invalid cross-device link +cross-subvol dire/none -> No such file or directory +cross-subvol dire/regu -> Invalid cross-device link +cross-subvol dire/symb -> Invalid cross-device link +cross-subvol dire/dire -> Invalid cross-device link +cross-subvol dire/tree -> Invalid cross-device link +cross-subvol tree/none -> No such file or directory +cross-subvol tree/regu -> Invalid cross-device link +cross-subvol tree/symb -> Invalid cross-device link +cross-subvol tree/dire -> Invalid cross-device link +cross-subvol tree/tree -> Invalid cross-device link +Invalid cross-device link +ordinary rename +cross-subvol none/none -> No such file or directory +cross-subvol none/regu -> No such file or directory +cross-subvol none/symb -> No such file or directory +cross-subvol none/dire -> No such file or directory +cross-subvol none/tree -> No such file or directory +cross-subvol regu/none -> Invalid cross-device link +cross-subvol regu/regu -> Invalid cross-device link +cross-subvol regu/symb -> Invalid cross-device link +cross-subvol regu/dire -> Is a directory +cross-subvol regu/tree -> Is a directory +cross-subvol symb/none -> Invalid cross-device link +cross-subvol symb/regu -> Invalid cross-device link +cross-subvol symb/symb -> Invalid cross-device link +cross-subvol symb/dire -> Is a directory +cross-subvol symb/tree -> Is a directory +cross-subvol dire/none -> Invalid cross-device link +cross-subvol dire/regu -> Not a directory +cross-subvol dire/symb -> Not a directory +cross-subvol dire/dire -> Invalid cross-device link +cross-subvol dire/tree -> Invalid cross-device link +cross-subvol tree/none -> Invalid cross-device link +cross-subvol tree/regu -> Not a directory +cross-subvol tree/symb -> Not a directory +cross-subvol tree/dire -> Invalid cross-device link +cross-subvol tree/tree -> Invalid cross-device link +subvolumes rename