fstests: btrfs: new test case for leaking BTRFS_FS_STATE_REMOUNTING flag
PATCH 1/1 fstests: btrfs: new test case for leaking BTRFS_FS_STATE_REMOUNTING flag
This is a regression test for the patch "btrfs: fix leaking BTRFS_FS_STATE_REMOUNTING flag", where conflicting mount options can cause btrfs leave BTRFS_FS_STATE_REMOUNTING set.
Such set BTRFS_FS_STATE_REMOUNTING will interrupt several features, and the test case will use "btrfs qgroup rescan" to catch the BTRFS_FS_STATE_REMOUNTING flag.
--- tests/btrfs/352 | 53 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/352.out | 2 ++ 2 files changed, 55 insertions(+) create mode 100755 tests/btrfs/352 create mode 100644 tests/btrfs/352.out
tests/btrfs/352 new file +53 -0
@@ -0,0 +1,53 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2026 SUSE S.A. All Rights Reserved. +# +# FS QA Test 352 +# +# A regression test to make sure failed remount won't leave +# BTRFS_FS_STATE_REMOUNTING flag set, which can interrupt several features, +# one of them is btrfs qgroup rescan. +# +. ./common/preamble +_begin_fstest auto quick remount + +_fixed_by_kernel_commit XXXXXXXXXXXX \ + "btrfs: fix leaking BTRFS_FS_STATE_REMOUNTING flag" + +rescue_opts="/sys/fs/btrfs/features/supported_rescue_options" +if [ ! -f "$rescue_opts" ]; then + _notrun "No supported_rescue_options sysfs interface" +fi + +if ! grep -q "ignorebadroots" "$rescue_opts"; then + _notrun "\"rescue=ignorebadroots\" mount option not supported" +fi + +_require_btrfs_command quota rescan -w +_require_scratch +_scratch_mkfs >> $seqres.full +_scratch_mount + +# Enable regular quota mode, and do a rescan. +# Although the regression is affecting multiple features, qgroup rescan is the +# easiest to verify. +_btrfs quota enable $SCRATCH_MNT +_btrfs quota rescan -w $SCRATCH_MNT + +# The following mount must fail, as the following rescue mount option requires +# a full RO mount, thus it can not be set for the existing RW mount. +_scratch_remount "rescue=ignorebadroots" >> $seqres.full 2>&1 +if [ $? -eq 0 ]; then + _fail "\"rescue=ignorebadroots\" is applied to RW mount unexpectedly" +fi + +# For unpatched kernel, qgroup rescan will be interrupted immediately. +_btrfs quota rescan -w $SCRATCH_MNT + +# We want capture the stderr output, so use $BTRFS_UTIL_PROG instead of _btrfs +$BTRFS_UTIL_PROG qgroup show $SCRATCH_MNT >> $seqres.full + +echo "Silence is golden" + +# success, all done +_exit 0
tests/btrfs/352.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 352 +Silence is golden
Signature · 1 line
2.51.2
Quoted 28 lines · Qu Wenruo
This is a regression test for the patch "btrfs: fix leaking
BTRFS_FS_STATE_REMOUNTINGflag", where conflicting mount options can cause btrfs leaveBTRFS_FS_STATE_REMOUNTINGset.Such set
BTRFS_FS_STATE_REMOUNTINGwill interrupt several features, and the test case will use "btrfs qgroup rescan" to catch theBTRFS_FS_STATE_REMOUNTINGflag.Signed-off-by Qu Wenruo <[email protected]>--- tests/btrfs/352 | 53 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/352.out | 2 ++ 2 files changed, 55 insertions(+) create mode 100755 tests/btrfs/352 create mode 100644 tests/btrfs/352.outtests/btrfs/352 new file +6
-0@@ -0,0 +1,53 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2026 SUSE S.A. All Rights Reserved. +# +# FS QA Test 352 +#
tests/btrfs/352 line 16
Quoted 10 lines
tests/btrfs/352 new file +10
-0+# A regression test to make sure failed remount won't leave +# BTRFS_FS_STATE_REMOUNTING flag set, which can interrupt several features, +# one of them is btrfs qgroup rescan. +# +. ./common/preamble +_begin_fstest auto quick remount + +_fixed_by_kernel_commit XXXXXXXXXXXX \ + "btrfs: fix leaking BTRFS_FS_STATE_REMOUNTING flag" +
We can replace this section with the existing helpers or, even better, with a new one as shown below. I am not too particular about creating a new helper, that is up to you. However, the use of existing helpers such as _require_btrfs_fs_sysfs and _require_btrfs_fs_feature will be better. Thanks
tests/btrfs/352 line 25
Quoted 9 lines
tests/btrfs/352 new file +9
-0+rescue_opts="/sys/fs/btrfs/features/supported_rescue_options" +if [ ! -f "$rescue_opts" ]; then + _notrun "No supported_rescue_options sysfs interface" +fi + +if ! grep -q "ignorebadroots" "$rescue_opts"; then + _notrun "\"rescue=ignorebadroots\" mount option not supported" +fi +
common/btrfs +1 -0
@@ -100,6 +100,29 @@ _require_btrfs_mkfs_uuid_option() fi } +# Check for the availability of a specific option within a btrfs
feature set
+# Arguments:
+# $1 - Feature attribute of /sys/fs/btrfs/features/
+# $2 - Option string to verify inside that file
+_require_btrfs_fs_feature_option()
+{
+ local feat=$1
+ local feat_type=$2
+
+ if [ -z "$feat" ] || [ -z "$feat_type" ]; then
+ echo "Missing argument(s) for _require_btrfs_fs_feature_type"
+ _exit 1
+ fi
+
+ modprobe btrfs > /dev/null 2>&1
+
+ _require_btrfs_fs_feature "$feat"
+
+ if ! grep -qw "$feat_type" "/sys/fs/btrfs/features/$feat"; then
+ _notrun "Feature type '$feat_type' not supported by the available
btrfs version"
+ fi
+}
+
_require_btrfs_fs_feature()
{
if [ -z $1 ]; then
tests/btrfs/352 +2 -9
@@ -14,15 +14,8 @@ _begin_fstest auto quick remount _fixed_by_kernel_commit XXXXXXXXXXXX \ "btrfs: fix leaking BTRFS_FS_STATE_REMOUNTING flag" -rescue_opts="/sys/fs/btrfs/features/supported_rescue_options" -if [ ! -f "$rescue_opts" ]; then - _notrun "No supported_rescue_options sysfs interface" -fi - -if ! grep -q "ignorebadroots" "$rescue_opts"; then - _notrun "\"rescue=ignorebadroots\" mount option not supported" -fi - +_require_btrfs_fs_sysfs +_require_btrfs_fs_feature_option "supported_rescue_options"
"ignorebadroots"
_require_btrfs_command quota rescan -w
_require_scratch
_scratch_mkfs >> $seqres.full
Quoted 71 lines · Anand Suveer Jain
Quoted 28 lines · Qu Wenruo
This is a regression test for the patch "btrfs: fix leaking
BTRFS_FS_STATE_REMOUNTINGflag", where conflicting mount options can cause btrfs leaveBTRFS_FS_STATE_REMOUNTINGset.Such set
BTRFS_FS_STATE_REMOUNTINGwill interrupt several features, and the test case will use "btrfs qgroup rescan" to catch theBTRFS_FS_STATE_REMOUNTINGflag.Signed-off-by Qu Wenruo <[email protected]>--- tests/btrfs/352 | 53 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/352.out | 2 ++ 2 files changed, 55 insertions(+)create mode 100755 tests/btrfs/352
create mode 100644 tests/btrfs/352.outtests/btrfs/352 new file +6
-0@@ -0,0 +1,53 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2026 SUSE S.A. All Rights Reserved. +# +# FS QA Test 352 +#tests/btrfs/352 line 16
Quoted 10 lines
tests/btrfs/352 new file +10
-0+# A regression test to make sure failed remount won't leave +# BTRFS_FS_STATE_REMOUNTING flag set, which can interrupt several features, +# one of them is btrfs qgroup rescan. +# +. ./common/preamble +_begin_fstest auto quick remount + +_fixed_by_kernel_commit XXXXXXXXXXXX \ + "btrfs: fix leaking BTRFS_FS_STATE_REMOUNTING flag" +We can replace this section with the existing helpers or, even better, with a new one as shown below. I am not too particular about creating a new helper, that is up to you. However, the use of existing helpers such as
_require_btrfs_fs_sysfsand_require_btrfs_fs_featurewill be better. ThanksQuoted 9 lines
tests/btrfs/352 new file +9
-0+rescue_opts="/sys/fs/btrfs/features/supported_rescue_options" +if [ ! -f "$rescue_opts" ]; then + _notrun "No supported_rescue_options sysfs interface" +fi + +if ! grep -q "ignorebadroots" "$rescue_opts"; then + _notrun "\"rescue=ignorebadroots\" mount option not supported" +fi +common/btrfs +1
-0@@ -100,6 +100,29 @@ _require_btrfs_mkfs_uuid_option() fi } +# Check for the availability of a specific option within a btrfsfeature set
common/btrfs
Quoted 5 lines
common/btrfs +5
-0+# Arguments: +# $1 - Feature attribute of /sys/fs/btrfs/features/ +# $2 - Option string to verify inside that file +_require_btrfs_fs_feature_option() +{
I'm fine to use the existing _require_btrfs_fs_feature() to detect that file.
But I'm not fine of a new _require_btrfs_fs_feature_option().
You have already mentioned the second parameter is optional, then why not merge it into the existing _require_btrfs_fs_feature().
Furthermore adding the second option can cause weird situations for the existing features.
E.g. just check /sys/fs/btrfs/features/rmdir_subvol, I believe it will be 0 on your environment too.
So if we use the optional parameter, there will be something like "_require_btrfs_fs_feature_option acl 0", which doesn't looks sane at all.
I'll convert to use _require_btrfs_fs_feature() for supported_rescue_options, but still manually test the content for the ibadroots option.
Thanks,
Qu
Quoted 47 lines
common/btrfs +14
-0+ local feat=$1 + local feat_type=$2 + + if [ -z "$feat" ] || [ -z "$feat_type" ]; then + echo "Missing argument(s) for _require_btrfs_fs_feature_type" + _exit 1 + fi + + modprobe btrfs > /dev/null 2>&1 + + _require_btrfs_fs_feature "$feat" + + if ! grep -qw "$feat_type" "/sys/fs/btrfs/features/$feat"; then + _notrun "Feature type '$feat_type' not supported by the availablebtrfs version"
common/btrfs +3
-0+ fi +} + _require_btrfs_fs_feature() { if [ -z $1 ]; thentests/btrfs/352 +2
-9@@ -14,15 +14,8 @@ _begin_fstest auto quick remount _fixed_by_kernel_commit XXXXXXXXXXXX \ "btrfs: fix leaking BTRFS_FS_STATE_REMOUNTING flag" -rescue_opts="/sys/fs/btrfs/features/supported_rescue_options" -if [ ! -f "$rescue_opts" ]; then - _notrun "No supported_rescue_options sysfs interface" -fi - -if ! grep -q "ignorebadroots" "$rescue_opts"; then - _notrun "\"rescue=ignorebadroots\" mount option not supported" -fi - +_require_btrfs_fs_sysfs +_require_btrfs_fs_feature_option "supported_rescue_options""ignorebadroots"
_require_btrfs_commandquota rescan -w
_require_scratch
_scratch_mkfs>> $seqres.full