diff mbox series

[2/4] btrfs/220: discard=sync support older kernel

Message ID 7f0731e5ed53fdd5b51ff1f2e51492415a46732a.1628818510.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series btrfs/220: make it compatible with older kernels | expand

Commit Message

Anand Jain Aug. 13, 2021, 1:59 a.m. UTC
mount option -o discard=sync isn't supported on the older kernel, make
this test case older kernel compatible by checking if the mount option
is supported.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 tests/btrfs/220 | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/tests/btrfs/220 b/tests/btrfs/220
index 7207c6967793..a01b28a6e42f 100755
--- a/tests/btrfs/220
+++ b/tests/btrfs/220
@@ -263,9 +263,14 @@  test_revertible_options()
 	test_roundtrip_mount "nodatasum" "nodatasum" "datasum" "$DEFAULT_OPTS"
 
 	test_should_fail "discard=invalid"
-	test_roundtrip_mount "discard" "discard" "discard=sync" "discard"
-	test_roundtrip_mount "discard=async" "discard=async" "discard=sync" "discard"
-	test_roundtrip_mount "discard=sync" "discard" "nodiscard" "$DEFAULT_OPTS"
+	if [ "$enable_discard_sync" = true ]; then
+		test_roundtrip_mount "discard" "discard" "discard=sync" "discard"
+		test_roundtrip_mount "discard=async" "discard=async" "discard=sync" "discard"
+		test_roundtrip_mount "discard=sync" "discard" "nodiscard" "$DEFAULT_OPTS"
+	else
+		test_roundtrip_mount "discard" "discard" "discard" "discard"
+		test_roundtrip_mount "discard" "discard" "nodiscard" "$DEFAULT_OPTS"
+	fi
 
 	test_roundtrip_mount "enospc_debug" "enospc_debug" "noenospc_debug" "$DEFAULT_OPTS"
 
@@ -292,6 +297,13 @@  test_revertible_options()
 	test_roundtrip_mount "notreelog" "notreelog" "treelog" "$DEFAULT_OPTS"
 }
 
+# Find out if the running kernel supports the -o discard=sync option.
+_scratch_mkfs >/dev/null
+MOUNT_OPTIONS=
+enable_discard_sync=false
+_try_scratch_mount "-o discard=sync" > /dev/null 2>&1 && \
+	{ enable_discard_sync=true; _scratch_unmount; }
+
 # real QA test starts here
 _scratch_mkfs >/dev/null