diff mbox series

[2/2] btrfs: require discard functionality from scratch device

Message ID 20210302091305.27828-3-johannes.thumshirn@wdc.com (mailing list archive)
State New, archived
Headers show
Series fstests: two preperation patches for zoned device support | expand

Commit Message

Johannes Thumshirn March 2, 2021, 9:13 a.m. UTC
Some test cases for btrfs require the scratch device to support discard.
Check if the scratch device does support discard before trying to execute
the test.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 common/rc       | 8 ++++++++
 tests/btrfs/116 | 1 +
 tests/btrfs/156 | 1 +
 3 files changed, 10 insertions(+)

Comments

Josef Bacik March 2, 2021, 7:01 p.m. UTC | #1
On 3/2/21 4:13 AM, Johannes Thumshirn wrote:
> Some test cases for btrfs require the scratch device to support discard.
> Check if the scratch device does support discard before trying to execute
> the test.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index 7254130ffe22..9fca7f31d6a2 100644
--- a/common/rc
+++ b/common/rc
@@ -3513,6 +3513,14 @@  _require_batched_discard()
 	$FSTRIM_PROG $1 > /dev/null 2>&1 || _notrun "FITRIM not supported on $1"
 }
 
+_require_scratch_discard()
+{
+	local sdev="$(_short_dev $SCRATCH_DEV)"
+	local discard=$(cat /sys/block/$sdev/queue/discard_granularity)
+
+	[ $discard -gt 0 ] || _notrun "discard not supported"
+}
+
 _require_dumpe2fs()
 {
 	if [ -z "$DUMPE2FS_PROG" ]; then
diff --git a/tests/btrfs/116 b/tests/btrfs/116
index 3ed097eccf03..f4db439caef8 100755
--- a/tests/btrfs/116
+++ b/tests/btrfs/116
@@ -29,6 +29,7 @@  _cleanup()
 # real QA test starts here
 _supported_fs btrfs
 _require_scratch
+_require_scratch_discard
 
 rm -f $seqres.full
 
diff --git a/tests/btrfs/156 b/tests/btrfs/156
index 89c80e7161e2..56206d99c801 100755
--- a/tests/btrfs/156
+++ b/tests/btrfs/156
@@ -42,6 +42,7 @@  rm -f $seqres.full
 _supported_fs btrfs
 _require_scratch
 _require_fstrim
+_require_scratch_discard
 
 # 1024fs size
 fs_size=$((1024 * 1024 * 1024))