fstests.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fstests: btrfs/214: Add test to check if shrink works well with fstrim
@ 2020-07-30 12:17 Qu Wenruo
  2020-07-30 16:55 ` Filipe Manana
  0 siblings, 1 reply; 2+ messages in thread
From: Qu Wenruo @ 2020-07-30 12:17 UTC (permalink / raw)
  To: linux-btrfs, fstests

There is a bug in trim code which leads to fstrim accessing beyond
device boundary.

The test case will check if fstrim, then shrink, then fstrim, all of
them works without problem.

The fix is titled "btrfs: trim: fix underflow in trim length to prevent
access beyond device boundary".

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 tests/btrfs/214     | 62 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/214.out |  2 ++
 tests/btrfs/group   |  1 +
 3 files changed, 65 insertions(+)
 create mode 100755 tests/btrfs/214
 create mode 100644 tests/btrfs/214.out

diff --git a/tests/btrfs/214 b/tests/btrfs/214
new file mode 100755
index 00000000..6cd9f444
--- /dev/null
+++ b/tests/btrfs/214
@@ -0,0 +1,62 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FS QA Test 214
+#
+# Test if the following workload would cause problem:
+# - fstrim
+# - shrink device
+# - fstrim
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs btrfs 
+_supported_os Linux
+_require_scratch_size $((5 * 1024 * 1024)) #kB
+_require_fstrim
+
+# Create a 5G fs
+_scratch_mkfs_sized $((5 * 1024 * 1024 * 1024)) >> $seqres.full
+_scratch_mount
+
+# Fstrim to populate the device->alloc_status CHUNK_TRIMMED bits
+$FSTRIM_PROG -v $SCRATCH_MNT >> $seqres.full 2>&1 || \
+	_notrun "FSTRIM not supported"
+
+
+# Shrink the fs to 4G, so the existing CHUNK_TRIMMED bits are beyond
+# device boundary
+$BTRFS_UTIL_PROG filesystem resize 1:-1G "$SCRATCH_MNT" >> $seqres.full
+
+# Do fstrim again to trigger the bug
+$FSTRIM_PROG -v $SCRATCH_MNT >> $seqres.full
+
+echo "Silence is golden"
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/214.out b/tests/btrfs/214.out
new file mode 100644
index 00000000..dafb6086
--- /dev/null
+++ b/tests/btrfs/214.out
@@ -0,0 +1,2 @@
+QA output created by 214
+Silence is golden
diff --git a/tests/btrfs/group b/tests/btrfs/group
index 59e8ecce..e306fea5 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -216,3 +216,4 @@
 211 auto quick log prealloc
 212 auto balance dangerous
 213 auto quick balance dangerous
+214 auto quick trim dangerous
-- 
2.27.0


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

* Re: [PATCH] fstests: btrfs/214: Add test to check if shrink works well with fstrim
  2020-07-30 12:17 [PATCH] fstests: btrfs/214: Add test to check if shrink works well with fstrim Qu Wenruo
@ 2020-07-30 16:55 ` Filipe Manana
  0 siblings, 0 replies; 2+ messages in thread
From: Filipe Manana @ 2020-07-30 16:55 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, fstests

On Thu, Jul 30, 2020 at 1:18 PM Qu Wenruo <wqu@suse.com> wrote:
>
> There is a bug in trim code which leads to fstrim accessing beyond
> device boundary.
>
> The test case will check if fstrim, then shrink, then fstrim, all of
> them works without problem.
>
> The fix is titled "btrfs: trim: fix underflow in trim length to prevent
> access beyond device boundary".
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>

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

Looks good, thanks.

> ---
>  tests/btrfs/214     | 62 +++++++++++++++++++++++++++++++++++++++++++++
>  tests/btrfs/214.out |  2 ++
>  tests/btrfs/group   |  1 +
>  3 files changed, 65 insertions(+)
>  create mode 100755 tests/btrfs/214
>  create mode 100644 tests/btrfs/214.out
>
> diff --git a/tests/btrfs/214 b/tests/btrfs/214
> new file mode 100755
> index 00000000..6cd9f444
> --- /dev/null
> +++ b/tests/btrfs/214
> @@ -0,0 +1,62 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
> +#
> +# FS QA Test 214
> +#
> +# Test if the following workload would cause problem:
> +# - fstrim
> +# - shrink device
> +# - fstrim
> +#
> +seq=`basename $0`
> +seqres=$RESULT_DIR/$seq
> +echo "QA output created by $seq"
> +
> +here=`pwd`
> +tmp=/tmp/$$
> +status=1       # failure is the default!
> +trap "_cleanup; exit \$status" 0 1 2 3 15
> +
> +_cleanup()
> +{
> +       cd /
> +       rm -f $tmp.*
> +}
> +
> +# get standard environment, filters and checks
> +. ./common/rc
> +. ./common/filter
> +
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
> +
> +# real QA test starts here
> +
> +# Modify as appropriate.
> +_supported_fs btrfs
> +_supported_os Linux
> +_require_scratch_size $((5 * 1024 * 1024)) #kB
> +_require_fstrim
> +
> +# Create a 5G fs
> +_scratch_mkfs_sized $((5 * 1024 * 1024 * 1024)) >> $seqres.full
> +_scratch_mount
> +
> +# Fstrim to populate the device->alloc_status CHUNK_TRIMMED bits
> +$FSTRIM_PROG -v $SCRATCH_MNT >> $seqres.full 2>&1 || \
> +       _notrun "FSTRIM not supported"
> +
> +
> +# Shrink the fs to 4G, so the existing CHUNK_TRIMMED bits are beyond
> +# device boundary
> +$BTRFS_UTIL_PROG filesystem resize 1:-1G "$SCRATCH_MNT" >> $seqres.full
> +
> +# Do fstrim again to trigger the bug
> +$FSTRIM_PROG -v $SCRATCH_MNT >> $seqres.full
> +
> +echo "Silence is golden"
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/btrfs/214.out b/tests/btrfs/214.out
> new file mode 100644
> index 00000000..dafb6086
> --- /dev/null
> +++ b/tests/btrfs/214.out
> @@ -0,0 +1,2 @@
> +QA output created by 214
> +Silence is golden
> diff --git a/tests/btrfs/group b/tests/btrfs/group
> index 59e8ecce..e306fea5 100644
> --- a/tests/btrfs/group
> +++ b/tests/btrfs/group
> @@ -216,3 +216,4 @@
>  211 auto quick log prealloc
>  212 auto balance dangerous
>  213 auto quick balance dangerous
> +214 auto quick trim dangerous
> --
> 2.27.0
>


-- 
Filipe David Manana,

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

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

end of thread, other threads:[~2020-07-30 16:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-30 12:17 [PATCH] fstests: btrfs/214: Add test to check if shrink works well with fstrim Qu Wenruo
2020-07-30 16:55 ` 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).