diff mbox series

[v2] btrfs: test that we can not delete a subvolume with an active swap file

Message ID 0bc9cd4abfbde3f76b981628942f94631cef7162.1662110839.git.fdmanana@suse.com (mailing list archive)
State New, archived
Headers show
Series [v2] btrfs: test that we can not delete a subvolume with an active swap file | expand

Commit Message

Filipe Manana Sept. 2, 2022, 9:30 a.m. UTC
From: Filipe Manana <fdmanana@suse.com>

Verify that we can not delete a subvolume that has an active swap file,
and that after disabling the swap file, we can delete it.

This tests a fix done by kernel commit 60021bd754c6ca ("btrfs: prevent
subvol with swapfile from being deleted"), which landed in kernel 5.18.

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

V2: Add _cleanup() override to make sure swapfile is disabled in case
    the test is interrupted.

 tests/btrfs/274     | 58 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/274.out |  6 +++++
 2 files changed, 64 insertions(+)
 create mode 100755 tests/btrfs/274
 create mode 100644 tests/btrfs/274.out

Comments

Qu Wenruo Sept. 2, 2022, 9:42 a.m. UTC | #1
On 2022/9/2 17:30, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> Verify that we can not delete a subvolume that has an active swap file,
> and that after disabling the swap file, we can delete it.
>
> This tests a fix done by kernel commit 60021bd754c6ca ("btrfs: prevent
> subvol with swapfile from being deleted"), which landed in kernel 5.18.
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Pretty straightforward.

Reivewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>
> V2: Add _cleanup() override to make sure swapfile is disabled in case
>      the test is interrupted.
>
>   tests/btrfs/274     | 58 +++++++++++++++++++++++++++++++++++++++++++++
>   tests/btrfs/274.out |  6 +++++
>   2 files changed, 64 insertions(+)
>   create mode 100755 tests/btrfs/274
>   create mode 100644 tests/btrfs/274.out
>
> diff --git a/tests/btrfs/274 b/tests/btrfs/274
> new file mode 100755
> index 00000000..c0594e25
> --- /dev/null
> +++ b/tests/btrfs/274
> @@ -0,0 +1,58 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2022 SUSE Linux Products GmbH. All Rights Reserved.
> +#
> +# FS QA Test 274
> +#
> +# Test that we can not delete a subvolume that has an active swap file.
> +#
> +. ./common/preamble
> +_begin_fstest auto quick swap subvol
> +
> +_cleanup()
> +{
> +	cd /
> +	rm -f $tmp.*
> +	test -n "$swap_file" && swapoff $swap_file &> /dev/null
> +}
> +
> +. ./common/filter
> +
> +_supported_fs btrfs
> +_fixed_by_kernel_commit 60021bd754c6ca \
> +    "btrfs: prevent subvol with swapfile from being deleted"
> +_require_scratch_swapfile
> +
> +_scratch_mkfs >> $seqres.full 2>&1
> +_scratch_mount
> +
> +swap_file="$SCRATCH_MNT/subvol/swap"
> +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol | _filter_scratch
> +
> +echo "Creating and activating swap file..."
> +_format_swapfile $swap_file $(($(get_page_size) * 32)) >> $seqres.full
> +_swapon_file $swap_file
> +
> +echo "Attempting to delete subvolume with swap file enabled..."
> +# Output differs with different btrfs-progs versions and some display multiple
> +# lines on failure like this for example:
> +#
> +#   ERROR: Could not destroy subvolume/snapshot: Operation not permitted
> +#   WARNING: deletion failed with EPERM, send may be in progress
> +#   Delete subvolume (no-commit): '/home/fdmanana/btrfs-tests/scratch_1/subvol'
> +#
> +# So just redirect all output to the .full file and check the command's exit
> +# status instead.
> +$BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/subvol >> $seqres.full 2>&1 && \
> +    echo "subvolume deletion successful, expected failure!"
> +
> +echo "Disabling swap file..."
> +swapoff $swap_file
> +
> +echo "Attempting to delete subvolume after disabling swap file..."
> +$BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/subvol >> $seqres.full 2>&1 || \
> +   echo "subvolume deletion failure, expected success!"
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/btrfs/274.out b/tests/btrfs/274.out
> new file mode 100644
> index 00000000..66e0de25
> --- /dev/null
> +++ b/tests/btrfs/274.out
> @@ -0,0 +1,6 @@
> +QA output created by 274
> +Create subvolume 'SCRATCH_MNT/subvol'
> +Creating and activating swap file...
> +Attempting to delete subvolume with swap file enabled...
> +Disabling swap file...
> +Attempting to delete subvolume after disabling swap file...
Zorro Lang Sept. 3, 2022, 12:44 a.m. UTC | #2
On Fri, Sep 02, 2022 at 10:30:32AM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> Verify that we can not delete a subvolume that has an active swap file,
> and that after disabling the swap file, we can delete it.
> 
> This tests a fix done by kernel commit 60021bd754c6ca ("btrfs: prevent
> subvol with swapfile from being deleted"), which landed in kernel 5.18.
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
> ---
> 
> V2: Add _cleanup() override to make sure swapfile is disabled in case
>     the test is interrupted.

Thanks for doing this cleanup, now it's good to me.

Reviewed-by: Zorro Lang <zlang@redhat.com>

> 
>  tests/btrfs/274     | 58 +++++++++++++++++++++++++++++++++++++++++++++
>  tests/btrfs/274.out |  6 +++++
>  2 files changed, 64 insertions(+)
>  create mode 100755 tests/btrfs/274
>  create mode 100644 tests/btrfs/274.out
> 
> diff --git a/tests/btrfs/274 b/tests/btrfs/274
> new file mode 100755
> index 00000000..c0594e25
> --- /dev/null
> +++ b/tests/btrfs/274
> @@ -0,0 +1,58 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2022 SUSE Linux Products GmbH. All Rights Reserved.
> +#
> +# FS QA Test 274
> +#
> +# Test that we can not delete a subvolume that has an active swap file.
> +#
> +. ./common/preamble
> +_begin_fstest auto quick swap subvol
> +
> +_cleanup()
> +{
> +	cd /
> +	rm -f $tmp.*
> +	test -n "$swap_file" && swapoff $swap_file &> /dev/null
> +}
> +
> +. ./common/filter
> +
> +_supported_fs btrfs
> +_fixed_by_kernel_commit 60021bd754c6ca \
> +    "btrfs: prevent subvol with swapfile from being deleted"
> +_require_scratch_swapfile
> +
> +_scratch_mkfs >> $seqres.full 2>&1
> +_scratch_mount
> +
> +swap_file="$SCRATCH_MNT/subvol/swap"
> +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol | _filter_scratch
> +
> +echo "Creating and activating swap file..."
> +_format_swapfile $swap_file $(($(get_page_size) * 32)) >> $seqres.full
> +_swapon_file $swap_file
> +
> +echo "Attempting to delete subvolume with swap file enabled..."
> +# Output differs with different btrfs-progs versions and some display multiple
> +# lines on failure like this for example:
> +#
> +#   ERROR: Could not destroy subvolume/snapshot: Operation not permitted
> +#   WARNING: deletion failed with EPERM, send may be in progress
> +#   Delete subvolume (no-commit): '/home/fdmanana/btrfs-tests/scratch_1/subvol'
> +#
> +# So just redirect all output to the .full file and check the command's exit
> +# status instead.
> +$BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/subvol >> $seqres.full 2>&1 && \
> +    echo "subvolume deletion successful, expected failure!"
> +
> +echo "Disabling swap file..."
> +swapoff $swap_file
> +
> +echo "Attempting to delete subvolume after disabling swap file..."
> +$BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/subvol >> $seqres.full 2>&1 || \
> +   echo "subvolume deletion failure, expected success!"
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/btrfs/274.out b/tests/btrfs/274.out
> new file mode 100644
> index 00000000..66e0de25
> --- /dev/null
> +++ b/tests/btrfs/274.out
> @@ -0,0 +1,6 @@
> +QA output created by 274
> +Create subvolume 'SCRATCH_MNT/subvol'
> +Creating and activating swap file...
> +Attempting to delete subvolume with swap file enabled...
> +Disabling swap file...
> +Attempting to delete subvolume after disabling swap file...
> -- 
> 2.35.1
>
Filipe Manana Sept. 5, 2022, 9:21 a.m. UTC | #3
On Sat, Sep 3, 2022 at 1:44 AM Zorro Lang <zlang@redhat.com> wrote:
>
> On Fri, Sep 02, 2022 at 10:30:32AM +0100, fdmanana@kernel.org wrote:
> > From: Filipe Manana <fdmanana@suse.com>
> >
> > Verify that we can not delete a subvolume that has an active swap file,
> > and that after disabling the swap file, we can delete it.
> >
> > This tests a fix done by kernel commit 60021bd754c6ca ("btrfs: prevent
> > subvol with swapfile from being deleted"), which landed in kernel 5.18.
> >
> > Signed-off-by: Filipe Manana <fdmanana@suse.com>
> > ---
> >
> > V2: Add _cleanup() override to make sure swapfile is disabled in case
> >     the test is interrupted.
>
> Thanks for doing this cleanup, now it's good to me.

Great.
Is there any reason why the test wasn't merged in yesterday's update?

Thanks.

>
> Reviewed-by: Zorro Lang <zlang@redhat.com>
>
> >
> >  tests/btrfs/274     | 58 +++++++++++++++++++++++++++++++++++++++++++++
> >  tests/btrfs/274.out |  6 +++++
> >  2 files changed, 64 insertions(+)
> >  create mode 100755 tests/btrfs/274
> >  create mode 100644 tests/btrfs/274.out
> >
> > diff --git a/tests/btrfs/274 b/tests/btrfs/274
> > new file mode 100755
> > index 00000000..c0594e25
> > --- /dev/null
> > +++ b/tests/btrfs/274
> > @@ -0,0 +1,58 @@
> > +#! /bin/bash
> > +# SPDX-License-Identifier: GPL-2.0
> > +# Copyright (C) 2022 SUSE Linux Products GmbH. All Rights Reserved.
> > +#
> > +# FS QA Test 274
> > +#
> > +# Test that we can not delete a subvolume that has an active swap file.
> > +#
> > +. ./common/preamble
> > +_begin_fstest auto quick swap subvol
> > +
> > +_cleanup()
> > +{
> > +     cd /
> > +     rm -f $tmp.*
> > +     test -n "$swap_file" && swapoff $swap_file &> /dev/null
> > +}
> > +
> > +. ./common/filter
> > +
> > +_supported_fs btrfs
> > +_fixed_by_kernel_commit 60021bd754c6ca \
> > +    "btrfs: prevent subvol with swapfile from being deleted"
> > +_require_scratch_swapfile
> > +
> > +_scratch_mkfs >> $seqres.full 2>&1
> > +_scratch_mount
> > +
> > +swap_file="$SCRATCH_MNT/subvol/swap"
> > +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol | _filter_scratch
> > +
> > +echo "Creating and activating swap file..."
> > +_format_swapfile $swap_file $(($(get_page_size) * 32)) >> $seqres.full
> > +_swapon_file $swap_file
> > +
> > +echo "Attempting to delete subvolume with swap file enabled..."
> > +# Output differs with different btrfs-progs versions and some display multiple
> > +# lines on failure like this for example:
> > +#
> > +#   ERROR: Could not destroy subvolume/snapshot: Operation not permitted
> > +#   WARNING: deletion failed with EPERM, send may be in progress
> > +#   Delete subvolume (no-commit): '/home/fdmanana/btrfs-tests/scratch_1/subvol'
> > +#
> > +# So just redirect all output to the .full file and check the command's exit
> > +# status instead.
> > +$BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/subvol >> $seqres.full 2>&1 && \
> > +    echo "subvolume deletion successful, expected failure!"
> > +
> > +echo "Disabling swap file..."
> > +swapoff $swap_file
> > +
> > +echo "Attempting to delete subvolume after disabling swap file..."
> > +$BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/subvol >> $seqres.full 2>&1 || \
> > +   echo "subvolume deletion failure, expected success!"
> > +
> > +# success, all done
> > +status=0
> > +exit
> > diff --git a/tests/btrfs/274.out b/tests/btrfs/274.out
> > new file mode 100644
> > index 00000000..66e0de25
> > --- /dev/null
> > +++ b/tests/btrfs/274.out
> > @@ -0,0 +1,6 @@
> > +QA output created by 274
> > +Create subvolume 'SCRATCH_MNT/subvol'
> > +Creating and activating swap file...
> > +Attempting to delete subvolume with swap file enabled...
> > +Disabling swap file...
> > +Attempting to delete subvolume after disabling swap file...
> > --
> > 2.35.1
> >
>
Zorro Lang Sept. 5, 2022, 6:38 p.m. UTC | #4
On Mon, Sep 05, 2022 at 10:21:24AM +0100, Filipe Manana wrote:
> On Sat, Sep 3, 2022 at 1:44 AM Zorro Lang <zlang@redhat.com> wrote:
> >
> > On Fri, Sep 02, 2022 at 10:30:32AM +0100, fdmanana@kernel.org wrote:
> > > From: Filipe Manana <fdmanana@suse.com>
> > >
> > > Verify that we can not delete a subvolume that has an active swap file,
> > > and that after disabling the swap file, we can delete it.
> > >
> > > This tests a fix done by kernel commit 60021bd754c6ca ("btrfs: prevent
> > > subvol with swapfile from being deleted"), which landed in kernel 5.18.
> > >
> > > Signed-off-by: Filipe Manana <fdmanana@suse.com>
> > > ---
> > >
> > > V2: Add _cleanup() override to make sure swapfile is disabled in case
> > >     the test is interrupted.
> >
> > Thanks for doing this cleanup, now it's good to me.
> 
> Great.
> Is there any reason why the test wasn't merged in yesterday's update?

Sorry, I forgot to add an 'acked' tag to this patch, after I gave it a RVB. That
caused I missed this patch in last release. It'll be in next release.

Thanks,
Zorro

> 
> Thanks.
> 
> >
> > Reviewed-by: Zorro Lang <zlang@redhat.com>
> >
> > >
> > >  tests/btrfs/274     | 58 +++++++++++++++++++++++++++++++++++++++++++++
> > >  tests/btrfs/274.out |  6 +++++
> > >  2 files changed, 64 insertions(+)
> > >  create mode 100755 tests/btrfs/274
> > >  create mode 100644 tests/btrfs/274.out
> > >
> > > diff --git a/tests/btrfs/274 b/tests/btrfs/274
> > > new file mode 100755
> > > index 00000000..c0594e25
> > > --- /dev/null
> > > +++ b/tests/btrfs/274
> > > @@ -0,0 +1,58 @@
> > > +#! /bin/bash
> > > +# SPDX-License-Identifier: GPL-2.0
> > > +# Copyright (C) 2022 SUSE Linux Products GmbH. All Rights Reserved.
> > > +#
> > > +# FS QA Test 274
> > > +#
> > > +# Test that we can not delete a subvolume that has an active swap file.
> > > +#
> > > +. ./common/preamble
> > > +_begin_fstest auto quick swap subvol
> > > +
> > > +_cleanup()
> > > +{
> > > +     cd /
> > > +     rm -f $tmp.*
> > > +     test -n "$swap_file" && swapoff $swap_file &> /dev/null
> > > +}
> > > +
> > > +. ./common/filter
> > > +
> > > +_supported_fs btrfs
> > > +_fixed_by_kernel_commit 60021bd754c6ca \
> > > +    "btrfs: prevent subvol with swapfile from being deleted"
> > > +_require_scratch_swapfile
> > > +
> > > +_scratch_mkfs >> $seqres.full 2>&1
> > > +_scratch_mount
> > > +
> > > +swap_file="$SCRATCH_MNT/subvol/swap"
> > > +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol | _filter_scratch
> > > +
> > > +echo "Creating and activating swap file..."
> > > +_format_swapfile $swap_file $(($(get_page_size) * 32)) >> $seqres.full
> > > +_swapon_file $swap_file
> > > +
> > > +echo "Attempting to delete subvolume with swap file enabled..."
> > > +# Output differs with different btrfs-progs versions and some display multiple
> > > +# lines on failure like this for example:
> > > +#
> > > +#   ERROR: Could not destroy subvolume/snapshot: Operation not permitted
> > > +#   WARNING: deletion failed with EPERM, send may be in progress
> > > +#   Delete subvolume (no-commit): '/home/fdmanana/btrfs-tests/scratch_1/subvol'
> > > +#
> > > +# So just redirect all output to the .full file and check the command's exit
> > > +# status instead.
> > > +$BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/subvol >> $seqres.full 2>&1 && \
> > > +    echo "subvolume deletion successful, expected failure!"
> > > +
> > > +echo "Disabling swap file..."
> > > +swapoff $swap_file
> > > +
> > > +echo "Attempting to delete subvolume after disabling swap file..."
> > > +$BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/subvol >> $seqres.full 2>&1 || \
> > > +   echo "subvolume deletion failure, expected success!"
> > > +
> > > +# success, all done
> > > +status=0
> > > +exit
> > > diff --git a/tests/btrfs/274.out b/tests/btrfs/274.out
> > > new file mode 100644
> > > index 00000000..66e0de25
> > > --- /dev/null
> > > +++ b/tests/btrfs/274.out
> > > @@ -0,0 +1,6 @@
> > > +QA output created by 274
> > > +Create subvolume 'SCRATCH_MNT/subvol'
> > > +Creating and activating swap file...
> > > +Attempting to delete subvolume with swap file enabled...
> > > +Disabling swap file...
> > > +Attempting to delete subvolume after disabling swap file...
> > > --
> > > 2.35.1
> > >
> >
>
diff mbox series

Patch

diff --git a/tests/btrfs/274 b/tests/btrfs/274
new file mode 100755
index 00000000..c0594e25
--- /dev/null
+++ b/tests/btrfs/274
@@ -0,0 +1,58 @@ 
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2022 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FS QA Test 274
+#
+# Test that we can not delete a subvolume that has an active swap file.
+#
+. ./common/preamble
+_begin_fstest auto quick swap subvol
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+	test -n "$swap_file" && swapoff $swap_file &> /dev/null
+}
+
+. ./common/filter
+
+_supported_fs btrfs
+_fixed_by_kernel_commit 60021bd754c6ca \
+    "btrfs: prevent subvol with swapfile from being deleted"
+_require_scratch_swapfile
+
+_scratch_mkfs >> $seqres.full 2>&1
+_scratch_mount
+
+swap_file="$SCRATCH_MNT/subvol/swap"
+$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol | _filter_scratch
+
+echo "Creating and activating swap file..."
+_format_swapfile $swap_file $(($(get_page_size) * 32)) >> $seqres.full
+_swapon_file $swap_file
+
+echo "Attempting to delete subvolume with swap file enabled..."
+# Output differs with different btrfs-progs versions and some display multiple
+# lines on failure like this for example:
+#
+#   ERROR: Could not destroy subvolume/snapshot: Operation not permitted
+#   WARNING: deletion failed with EPERM, send may be in progress
+#   Delete subvolume (no-commit): '/home/fdmanana/btrfs-tests/scratch_1/subvol'
+#
+# So just redirect all output to the .full file and check the command's exit
+# status instead.
+$BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/subvol >> $seqres.full 2>&1 && \
+    echo "subvolume deletion successful, expected failure!"
+
+echo "Disabling swap file..."
+swapoff $swap_file
+
+echo "Attempting to delete subvolume after disabling swap file..."
+$BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/subvol >> $seqres.full 2>&1 || \
+   echo "subvolume deletion failure, expected success!"
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/274.out b/tests/btrfs/274.out
new file mode 100644
index 00000000..66e0de25
--- /dev/null
+++ b/tests/btrfs/274.out
@@ -0,0 +1,6 @@ 
+QA output created by 274
+Create subvolume 'SCRATCH_MNT/subvol'
+Creating and activating swap file...
+Attempting to delete subvolume with swap file enabled...
+Disabling swap file...
+Attempting to delete subvolume after disabling swap file...