Skip to contentSkip to conversation

btrfs/220: make it compatible with older kernels

PATCH New Anand Jain 1 participant 5 messages Aug 13, 2021 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

cover btrfs/220: make it compatible with older kernels

I found this test case fails on older kernels such as 5.4.17 as the patches that brought the mount options changes aren't the candidate for the backport because of ABI compliance.

So make this test case to check if the newer options such as [1] are supported and tests the mount options along with the expected output in /proc/self/mounts accordingly.

[1]
mount options changes:

  new                   old
  discard=sync          discard
  rescue=nologreplay    nologreplay

/proc/self/mounts output changes:
new old
"" clear_cache

Patch 1 improves the debug log provided by the _fail() for the scratch_mount.

Patch 2,3,4 fixes discard, nologreplay and clear_cache, respectively and, they are separated into the individual patch to show the diff. These may merge at the time of integration. I am ok.

This patchset is on top of Boris's patch [2]
[2]
[PATCH] btrfs/220: fix clear_cache and inode_cache option tests
https://patchwork.kernel.org/project/fstests/patch/409e4c73fefce666d151b043d6b2a0d821f8ef85.1610485406.git.boris@bur.io/

Anand Jain (4):
rc: debug add _scratch_mount_options to the _scratch_mount btrfs/220: discard=sync support older kernel btrfs/220: nologreplay support older kernel btrfs/220: clear_cache fix for older kernel

 common/rc       |  2 +-
 tests/btrfs/220 | 59 +++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 48 insertions(+), 13 deletions(-)
Signature · 1 line
2.27.0
author
#1 lore raw

PATCH 1/4 rc: debug add _scratch_mount_options to the _scratch_mount

When the _scratch_mount fails, there isn't any clue on why it failed as of now, change this and add the $(_scratch_mount_options $*) to the _fail.

---
 common/rc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/rc +1 -1
index e04d9365d902..4e939da37010 100644
@@ -339,7 +339,7 @@ _try_scratch_mount()
 # mount scratch device with given options and _fail if mount fails
 _scratch_mount()
 {
-	_try_scratch_mount $* || _fail "mount failed"
+	_try_scratch_mount $* || _fail "mount $(_scratch_mount_options $*) failed"
 }
 
 _scratch_mount_idmapped()
Signature · 1 line
2.27.0
author
#2 lore raw

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

In reply to Anand Jain

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.

---
 tests/btrfs/220 | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
tests/btrfs/220 +15 -3
index 7207c6967793..a01b28a6e42f 100755
@@ -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
 
Signature · 1 line
2.27.0
author
#3 lore raw

PATCH 3/4 btrfs/220: nologreplay support older kernel

In reply to Anand Jain

mount option -o rescue=nologreplay isn't supported on the older kernel, make this test case older kernel compatible by checking if the mount option is supported.

---
 tests/btrfs/220 | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
tests/btrfs/220 +20 -8
index a01b28a6e42f..9f2f07d723c4 100755
@@ -209,22 +209,30 @@ test_non_revertible_options()
 {
 	test_mount_opt "degraded" "degraded"
 
-	# nologreplay should be used only with
+	# nologreplay should be used only with readonly
 	test_should_fail "nologreplay"
-	test_mount_opt "nologreplay,ro" "ro,rescue=nologreplay"
 
-	# norecovery should be used only with. This options is an alias to nologreplay
+	# norecovery should be used only with readonly.
+	# This options is an alias to nologreplay
 	test_should_fail "norecovery"
-	test_mount_opt "norecovery,ro" "ro,rescue=nologreplay"
+
+	if [ "$enable_rescue_nologreplay" = true ]; then
+		#rescue=nologreplay should be used only with readonly
+		test_should_fail "rescue=nologreplay"
+
+		test_mount_opt "nologreplay,ro" "ro,rescue=nologreplay"
+		test_mount_opt "norecovery,ro" "ro,rescue=nologreplay"
+		test_mount_opt "rescue=nologreplay,ro" "ro,rescue=nologreplay"
+	else
+		test_mount_opt "nologreplay,ro" "ro,nologreplay"
+		test_mount_opt "norecovery,ro" "ro,nologreplay"
+	fi
+
 	test_mount_opt "rescan_uuid_tree" "rescan_uuid_tree"
 	test_mount_opt "skip_balance" "skip_balance"
 	test_mount_opt "user_subvol_rm_allowed" "user_subvol_rm_allowed"
 
 	test_should_fail "rescue=invalid"
-
-	# nologreplay requires readonly
-	test_should_fail "rescue=nologreplay"
-	test_mount_opt "rescue=nologreplay,ro" "ro,rescue=nologreplay"
 }
 
 test_one_shot_options()
@@ -304,6 +312,10 @@ enable_discard_sync=false
 _try_scratch_mount "-o discard=sync" > /dev/null 2>&1 && \
 	{ enable_discard_sync=true; _scratch_unmount; }
 
+enable_rescue_nologreplay=false
+_try_scratch_mount "-o ro,rescue=nologreplay" > /dev/null 2>&1 && \
+	{ enable_rescue_nologreplay=true; _scratch_unmount; }
+
 # real QA test starts here
 _scratch_mkfs >/dev/null
 
Signature · 1 line
2.27.0
author
#4 lore raw

PATCH 4/4 btrfs/220: clear_cache fix for older kernel

In reply to Anand Jain

mount option -o clear_cache shown in /proc/self/mounts isn't supported in the newer kernel, make this test case older kernel compatible by checking if clear_cache is shown in the /proc/self/mounts.

---
 tests/btrfs/220 | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
tests/btrfs/220 +12 -1
index 9f2f07d723c4..fa91a38493af 100755
@@ -237,7 +237,11 @@ test_non_revertible_options()
 
 test_one_shot_options()
 {
-	test_mount_opt "clear_cache" ""
+	if [ "$enable_clear_cache_shown" = true ]; then
+		test_mount_opt "clear_cache" "clear_cache"
+	else
+		test_mount_opt "clear_cache" ""
+	fi
 }
 
 # All these options can be reverted (with their "no" counterpart), or can have
@@ -316,6 +320,13 @@ enable_rescue_nologreplay=false
 _try_scratch_mount "-o ro,rescue=nologreplay" > /dev/null 2>&1 && \
 	{ enable_rescue_nologreplay=true; _scratch_unmount; }
 
+enable_clear_cache_shown=false
+_try_scratch_mount "-o clear_cache" > /dev/null 2>&1 && \
+	{ shown_opts=$(cat /proc/self/mounts | grep $SCRATCH_MNT | \
+		       $AWK_PROG '{ print $4 }')
+	  echo $shown_opts | grep -q clear_cache && enable_clear_cache_shown=true
+	  _scratch_unmount; }
+
 # real QA test starts here
 _scratch_mkfs >/dev/null
 
Signature · 1 line
2.27.0