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.thumsh...@wdc.com>
---
 common/rc       | 8 ++++++++
 tests/btrfs/116 | 1 +
 tests/btrfs/156 | 1 +
 3 files changed, 10 insertions(+)

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))
-- 
2.30.0

Reply via email to