fstests.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] common/renameat2: Make _rename_tests_source_dest take flags as 4th arguement
@ 2021-08-30 12:23 Nikolay Borisov
  2021-08-30 12:23 ` [PATCH V2 2/2] btrfs: Add test for rename/exchange behavior between subvolumes Nikolay Borisov
  0 siblings, 1 reply; 7+ messages in thread
From: Nikolay Borisov @ 2021-08-30 12:23 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Nikolay Borisov

Currently this function takes the flags parameter to be passed to the
renameat program by assuming there exists a 'flags' variable. Instead,
make the flags being passed as 4th argument to the function.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 common/renameat2 | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/common/renameat2 b/common/renameat2
index 4b64eea7824b..4d25d7cebf94 100644
--- a/common/renameat2
+++ b/common/renameat2
@@ -61,6 +61,7 @@ _rename_tests_source_dest()
 	local source=$1
 	local dest=$2
 	local options=$3
+	local flags=$4
 
 	for stype in none regu symb dire tree; do
 		for dtype in none regu symb dire tree; do
@@ -90,11 +91,11 @@ _rename_tests()
 	local flags=$2
 
 	#same directory renames
-	_rename_tests_source_dest $testdir/src $testdir/dst     "samedir "
+	_rename_tests_source_dest $testdir/src $testdir/dst     "samedir " $flags
 
 	#cross directory renames
 	mkdir $testdir/x $testdir/y
-	_rename_tests_source_dest $testdir/x/src $testdir/y/dst "crossdir"
+	_rename_tests_source_dest $testdir/x/src $testdir/y/dst "crossdir" $flags
 	rmdir $testdir/x $testdir/y
 }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH V2 2/2] btrfs: Add test for rename/exchange behavior between subvolumes
  2021-08-30 12:23 [PATCH 1/2] common/renameat2: Make _rename_tests_source_dest take flags as 4th arguement Nikolay Borisov
@ 2021-08-30 12:23 ` Nikolay Borisov
  2021-08-30 15:01   ` Filipe Manana
  2021-08-30 15:36   ` [PATCH v2] " Nikolay Borisov
  0 siblings, 2 replies; 7+ messages in thread
From: Nikolay Borisov @ 2021-08-30 12:23 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Nikolay Borisov

This tests ensures that renames/exchanges across subvolumes work only
for other subvolumes and are otherwise forbidden and fail.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
Changes in V2:
 * Added cross-subvol rename tests
 * Added cross-subvol subvolume rename test
 * Added ordinary volume rename test
 * Removed explicit sync

 tests/btrfs/246     | 43 +++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/246.out | 27 +++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)
 create mode 100755 tests/btrfs/246
 create mode 100644 tests/btrfs/246.out

diff --git a/tests/btrfs/246 b/tests/btrfs/246
new file mode 100755
index 000000000000..eeb12bb457a8
--- /dev/null
+++ b/tests/btrfs/246
@@ -0,0 +1,43 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2021 SUSE Linux Products GmbH.  All Rights Reserved.
+#
+# FS QA Test 246
+#
+# Tests rename exchange behavior when subvolumes are involved. 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
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/246.out b/tests/btrfs/246.out
new file mode 100644
index 000000000000..d50dc28b1b40
--- /dev/null
+++ b/tests/btrfs/246.out
@@ -0,0 +1,27 @@
+QA output created by 246
+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
--
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH V2 2/2] btrfs: Add test for rename/exchange behavior between subvolumes
  2021-08-30 12:23 ` [PATCH V2 2/2] btrfs: Add test for rename/exchange behavior between subvolumes Nikolay Borisov
@ 2021-08-30 15:01   ` Filipe Manana
  2021-08-30 15:03     ` Filipe Manana
  2021-08-30 15:34     ` Nikolay Borisov
  2021-08-30 15:36   ` [PATCH v2] " Nikolay Borisov
  1 sibling, 2 replies; 7+ messages in thread
From: Filipe Manana @ 2021-08-30 15:01 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: fstests, linux-btrfs

On Mon, Aug 30, 2021 at 1:23 PM Nikolay Borisov <nborisov@suse.com> wrote:
>
> This tests ensures that renames/exchanges across subvolumes work only
> for other subvolumes and are otherwise forbidden and fail.
>
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
> Changes in V2:
>  * Added cross-subvol rename tests
>  * Added cross-subvol subvolume rename test
>  * Added ordinary volume rename test
>  * Removed explicit sync
>
>  tests/btrfs/246     | 43 +++++++++++++++++++++++++++++++++++++++++++
>  tests/btrfs/246.out | 27 +++++++++++++++++++++++++++
>  2 files changed, 70 insertions(+)
>  create mode 100755 tests/btrfs/246
>  create mode 100644 tests/btrfs/246.out
>
> diff --git a/tests/btrfs/246 b/tests/btrfs/246
> new file mode 100755
> index 000000000000..eeb12bb457a8
> --- /dev/null
> +++ b/tests/btrfs/246
> @@ -0,0 +1,43 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2021 SUSE Linux Products GmbH.  All Rights Reserved.
> +#
> +# FS QA Test 246
> +#
> +# Tests rename exchange behavior when subvolumes are involved. This is also a
> +# regression test for 3f79f6f6247c ("btrfs: prevent rename2 from exchanging a
> +# subvol with a directory from different parents").

And it's also a regression test for commit 3f79f6f6247c83 ("btrfs:
prevent rename2 from exchanging a subvol with a directory from
different parents"),
which is actually the fix that motivated v1 of this test case.

> +#
> +. ./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

Where is the test for renaming a subvolume and the test(s) for regular renames?
The v2 changelog mentions those tests were added, but all the tests I
see here are doing rename exchanges only.

I must have missed something subtle.

Thanks.

> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/btrfs/246.out b/tests/btrfs/246.out
> new file mode 100644
> index 000000000000..d50dc28b1b40
> --- /dev/null
> +++ b/tests/btrfs/246.out
> @@ -0,0 +1,27 @@
> +QA output created by 246
> +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
> --
> 2.17.1
>


-- 
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V2 2/2] btrfs: Add test for rename/exchange behavior between subvolumes
  2021-08-30 15:01   ` Filipe Manana
@ 2021-08-30 15:03     ` Filipe Manana
  2021-08-30 15:34     ` Nikolay Borisov
  1 sibling, 0 replies; 7+ messages in thread
From: Filipe Manana @ 2021-08-30 15:03 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: fstests, linux-btrfs

On Mon, Aug 30, 2021 at 4:01 PM Filipe Manana <fdmanana@gmail.com> wrote:
>
> On Mon, Aug 30, 2021 at 1:23 PM Nikolay Borisov <nborisov@suse.com> wrote:
> >
> > This tests ensures that renames/exchanges across subvolumes work only
> > for other subvolumes and are otherwise forbidden and fail.
> >
> > Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> > ---
> > Changes in V2:
> >  * Added cross-subvol rename tests
> >  * Added cross-subvol subvolume rename test
> >  * Added ordinary volume rename test
> >  * Removed explicit sync
> >
> >  tests/btrfs/246     | 43 +++++++++++++++++++++++++++++++++++++++++++
> >  tests/btrfs/246.out | 27 +++++++++++++++++++++++++++
> >  2 files changed, 70 insertions(+)
> >  create mode 100755 tests/btrfs/246
> >  create mode 100644 tests/btrfs/246.out
> >
> > diff --git a/tests/btrfs/246 b/tests/btrfs/246
> > new file mode 100755
> > index 000000000000..eeb12bb457a8
> > --- /dev/null
> > +++ b/tests/btrfs/246
> > @@ -0,0 +1,43 @@
> > +#! /bin/bash
> > +# SPDX-License-Identifier: GPL-2.0
> > +# Copyright (c) 2021 SUSE Linux Products GmbH.  All Rights Reserved.
> > +#
> > +# FS QA Test 246
> > +#
> > +# Tests rename exchange behavior when subvolumes are involved. This is also a
> > +# regression test for 3f79f6f6247c ("btrfs: prevent rename2 from exchanging a
> > +# subvol with a directory from different parents").
>
> And it's also a regression test for commit 3f79f6f6247c83 ("btrfs:
> prevent rename2 from exchanging a subvol with a directory from
> different parents"),

Actually, it's 4871c1588f92c6c13f4713a7009f25f217055807 ("Btrfs: use right
root when checking for hash collision"), mentioned in the reply for v1. My bad.

> which is actually the fix that motivated v1 of this test case.
>
> > +#
> > +. ./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
>
> Where is the test for renaming a subvolume and the test(s) for regular renames?
> The v2 changelog mentions those tests were added, but all the tests I
> see here are doing rename exchanges only.
>
> I must have missed something subtle.
>
> Thanks.
>
> > +
> > +# success, all done
> > +status=0
> > +exit
> > diff --git a/tests/btrfs/246.out b/tests/btrfs/246.out
> > new file mode 100644
> > index 000000000000..d50dc28b1b40
> > --- /dev/null
> > +++ b/tests/btrfs/246.out
> > @@ -0,0 +1,27 @@
> > +QA output created by 246
> > +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
> > --
> > 2.17.1
> >
>
>
> --
> Filipe David Manana,
>
> “Whether you think you can, or you think you can't — you're right.”



-- 
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V2 2/2] btrfs: Add test for rename/exchange behavior between subvolumes
  2021-08-30 15:01   ` Filipe Manana
  2021-08-30 15:03     ` Filipe Manana
@ 2021-08-30 15:34     ` Nikolay Borisov
  1 sibling, 0 replies; 7+ messages in thread
From: Nikolay Borisov @ 2021-08-30 15:34 UTC (permalink / raw)
  To: fdmanana; +Cc: fstests, linux-btrfs



On 30.08.21 г. 18:01, Filipe Manana wrote:
> On Mon, Aug 30, 2021 at 1:23 PM Nikolay Borisov <nborisov@suse.com> wrote:
>>
>> This tests ensures that renames/exchanges across subvolumes work only
>> for other subvolumes and are otherwise forbidden and fail.
>>
>> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
>> ---
>> Changes in V2:
>>  * Added cross-subvol rename tests
>>  * Added cross-subvol subvolume rename test
>>  * Added ordinary volume rename test
>>  * Removed explicit sync
>>
>>  tests/btrfs/246     | 43 +++++++++++++++++++++++++++++++++++++++++++
>>  tests/btrfs/246.out | 27 +++++++++++++++++++++++++++
>>  2 files changed, 70 insertions(+)
>>  create mode 100755 tests/btrfs/246
>>  create mode 100644 tests/btrfs/246.out
>>
>> diff --git a/tests/btrfs/246 b/tests/btrfs/246
>> new file mode 100755
>> index 000000000000..eeb12bb457a8
>> --- /dev/null
>> +++ b/tests/btrfs/246
>> @@ -0,0 +1,43 @@
>> +#! /bin/bash
>> +# SPDX-License-Identifier: GPL-2.0
>> +# Copyright (c) 2021 SUSE Linux Products GmbH.  All Rights Reserved.
>> +#
>> +# FS QA Test 246
>> +#
>> +# Tests rename exchange behavior when subvolumes are involved. This is also a
>> +# regression test for 3f79f6f6247c ("btrfs: prevent rename2 from exchanging a
>> +# subvol with a directory from different parents").
> 
> And it's also a regression test for commit 3f79f6f6247c83 ("btrfs:
> prevent rename2 from exchanging a subvol with a directory from
> different parents"),
> which is actually the fix that motivated v1 of this test case.
> 
>> +#
>> +. ./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
> 
> Where is the test for renaming a subvolume and the test(s) for regular renames?
> The v2 changelog mentions those tests were added, but all the tests I
> see here are doing rename exchanges only.
> 
> I must have missed something subtle.

Nope, I missed committing my changes...

> 
> Thanks.
> 
>> +
>> +# success, all done
>> +status=0
>> +exit
>> diff --git a/tests/btrfs/246.out b/tests/btrfs/246.out
>> new file mode 100644
>> index 000000000000..d50dc28b1b40
>> --- /dev/null
>> +++ b/tests/btrfs/246.out
>> @@ -0,0 +1,27 @@
>> +QA output created by 246
>> +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
>> --
>> 2.17.1
>>
> 
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] btrfs: Add test for rename/exchange behavior between subvolumes
  2021-08-30 12:23 ` [PATCH V2 2/2] btrfs: Add test for rename/exchange behavior between subvolumes Nikolay Borisov
  2021-08-30 15:01   ` Filipe Manana
@ 2021-08-30 15:36   ` Nikolay Borisov
  2021-09-03 16:23     ` Filipe Manana
  1 sibling, 1 reply; 7+ messages in thread
From: Nikolay Borisov @ 2021-08-30 15:36 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Nikolay Borisov

This tests ensures that renames/exchanges across subvolumes work only
for other subvolumes and are otherwise forbidden and fail.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
This is the real v2.

Changes in V2:
 * Added cross-subvol rename tests
 * Added cross-subvol subvolume rename test
 * Added ordinary volume rename test
 * Removed explicit sync


 tests/btrfs/246     | 60 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/246.out | 54 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+)
 create mode 100755 tests/btrfs/246
 create mode 100644 tests/btrfs/246.out

diff --git a/tests/btrfs/246 b/tests/btrfs/246
new file mode 100755
index 000000000000..53039df38993
--- /dev/null
+++ b/tests/btrfs/246
@@ -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 246
+#
+# 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/246.out b/tests/btrfs/246.out
new file mode 100644
index 000000000000..5db90cf2bd9a
--- /dev/null
+++ b/tests/btrfs/246.out
@@ -0,0 +1,54 @@
+QA output created by 246
+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
--
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] btrfs: Add test for rename/exchange behavior between subvolumes
  2021-08-30 15:36   ` [PATCH v2] " Nikolay Borisov
@ 2021-09-03 16:23     ` Filipe Manana
  0 siblings, 0 replies; 7+ messages in thread
From: Filipe Manana @ 2021-09-03 16:23 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: fstests, linux-btrfs

On Mon, Aug 30, 2021 at 4:38 PM Nikolay Borisov <nborisov@suse.com> wrote:
>
> This tests ensures that renames/exchanges across subvolumes work only
> for other subvolumes and are otherwise forbidden and fail.
>
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Reviewed-by: Filipe Manana <fdmanana@suse.com>

Looks good, thanks.

> ---
> This is the real v2.
>
> Changes in V2:
>  * Added cross-subvol rename tests
>  * Added cross-subvol subvolume rename test
>  * Added ordinary volume rename test
>  * Removed explicit sync
>
>
>  tests/btrfs/246     | 60 +++++++++++++++++++++++++++++++++++++++++++++
>  tests/btrfs/246.out | 54 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 114 insertions(+)
>  create mode 100755 tests/btrfs/246
>  create mode 100644 tests/btrfs/246.out
>
> diff --git a/tests/btrfs/246 b/tests/btrfs/246
> new file mode 100755
> index 000000000000..53039df38993
> --- /dev/null
> +++ b/tests/btrfs/246
> @@ -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 246
> +#
> +# 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/246.out b/tests/btrfs/246.out
> new file mode 100644
> index 000000000000..5db90cf2bd9a
> --- /dev/null
> +++ b/tests/btrfs/246.out
> @@ -0,0 +1,54 @@
> +QA output created by 246
> +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
> --
> 2.17.1
>


-- 
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-03 16:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-30 12:23 [PATCH 1/2] common/renameat2: Make _rename_tests_source_dest take flags as 4th arguement Nikolay Borisov
2021-08-30 12:23 ` [PATCH V2 2/2] btrfs: Add test for rename/exchange behavior between subvolumes Nikolay Borisov
2021-08-30 15:01   ` Filipe Manana
2021-08-30 15:03     ` Filipe Manana
2021-08-30 15:34     ` Nikolay Borisov
2021-08-30 15:36   ` [PATCH v2] " Nikolay Borisov
2021-09-03 16:23     ` Filipe Manana

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).