From: Zorro Lang <zlang@kernel.org>
To: fstests@vger.kernel.org
Cc: linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org,
Anand Suveer Jain <asj@kernel.org>, Chao Yu <chao@kernel.org>,
Christoph Hellwig <hch@infradead.org>
Subject: [PATCH v2 3/6] common: move btrfs-only sysfs policy helpers out of common/sysfs
Date: Sat, 24 Oct 2026 04:31:11 +0800 [thread overview]
Message-ID: <20261023203114.1655019-4-zlang@kernel.org> (raw)
In-Reply-To: <20261023203114.1655019-1-zlang@kernel.org>
The sysfs policy helpers in common/sysfs are only usable for btrfs.
The only filesystem supported by them is btrfs and the only callers
are btrfs tests. So rename them with a _btrfs_ infix and move them to
common/btrfs, then remove empty common/sysfs and its references.
Signed-off-by: Zorro Lang <zlang@kernel.org>
---
common/btrfs | 135 ++++++++++++++++++++++++++++++++++++++++++++
common/sysfs | 145 ------------------------------------------------
tests/btrfs/253 | 3 +-
tests/btrfs/329 | 5 +-
tests/btrfs/334 | 3 +-
5 files changed, 139 insertions(+), 152 deletions(-)
delete mode 100644 common/sysfs
diff --git a/common/btrfs b/common/btrfs
index b52b4b11..38658a11 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -1084,3 +1084,138 @@ _require_btrfs_iouring_encoded_read()
_notrun "btrfs io_uring encoded read failed with -EOPNOTSUPP"
fi
}
+
+# Btrfs-only sysfs policy helpers. They operate on per-device sysfs
+# attributes that accept a "policy" value, e.g. read_policy.
+
+# Test for the existence of a policy at /sys/fs/$FSTYP/$DEV/$ATTR
+#
+# All arguments are necessary, and in this order:
+# - dev: device name, e.g. $SCRATCH_DEV
+# - attr: path name under /sys/fs/$FSTYP/$dev
+# - policy: policy within /sys/fs/$FSTYP/$dev
+#
+# Usage example:
+# _has_btrfs_sysfs_dev_policy /dev/mapper/scratch-dev read_policy round-robin
+_has_btrfs_sysfs_dev_policy()
+{
+ local dev=$1
+ local attr=$2
+ local policy=$3
+
+ if [ ! -b "$dev" -o -z "$attr" -o -z "$policy" ]; then
+ _fail \
+ "Usage: _has_btrfs_sysfs_dev_policy <mounted_device> <attr> <policy>"
+ fi
+
+ local dname=$(_fs_sysfs_dname $dev)
+ if ! test -e /sys/fs/${FSTYP}/${dname}/${attr}; then
+ return 1
+ fi
+
+ cat /sys/fs/${FSTYP}/${dname}/${attr} | grep -q ${policy}
+}
+
+# Require the existence of a sysfs entry at /sys/fs/$FSTYP/$DEV/$ATTR
+# and value in it contains $policy
+# All arguments are necessary, and in this order:
+# - dev: device name, e.g. $SCRATCH_DEV
+# - attr: path name under /sys/fs/$FSTYP/$dev
+# - policy: mentioned in /sys/fs/$FSTYP/$dev/$attr
+#
+# Usage example:
+# _require_btrfs_sysfs_dev_policy /dev/mapper/scratch-dev read_policy round-robin
+_require_btrfs_sysfs_dev_policy()
+{
+ _has_btrfs_sysfs_dev_policy "$@" && return
+
+ local dev=$1
+ local attr=$2
+ local policy=$3
+ local dname=$(_fs_sysfs_dname $dev)
+
+ _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr} ${policy}"
+}
+
+_set_btrfs_sysfs_dev_policy()
+{
+ local dev=$1
+ local attr=$2
+ shift
+ shift
+ local policy=$@
+
+ _set_fs_sysfs_dev_attr $dev $attr ${policy}
+
+ _get_fs_sysfs_dev_attr $dev $attr | grep -q "[${policy}]"
+ if [[ $? != 0 ]]; then
+ echo "Setting sysfs $attr $policy failed"
+ fi
+}
+
+_set_btrfs_sysfs_dev_policy_must_fail()
+{
+ local dev=$1
+ local attr=$2
+ shift
+ shift
+ local policy=$@
+
+ _set_fs_sysfs_dev_attr $dev $attr ${policy} | _filter_sysfs_error \
+ | tee -a $seqres.full
+}
+
+# Verify sysfs attribute rejects invalid input.
+# Usage syntax:
+# _verify_btrfs_sysfs_dev_syntax <$dev> <$attr> <$policy> [$value]
+# Examples:
+# _verify_btrfs_sysfs_dev_syntax $TEST_DEV read_policy pid
+# _verify_btrfs_sysfs_dev_syntax $TEST_DEV read_policy round-robin 4k
+# Note:
+# Testcase must include
+# . ./common/filter
+# Prerequisite checks are kept outside this function
+# to make them clear to the test case, rather than hiding
+# them deep inside another function.
+# _require_btrfs_sysfs_dev_policy $TEST_DEV $attr $policy
+_verify_btrfs_sysfs_dev_syntax()
+{
+ local dev=$1
+ local attr=$2
+ local policy=$3
+ local value=$4
+
+ # Test policy specified wrongly. Must fail.
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr "'$policy $policy'"
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr "'$policy t'"
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr "' '"
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr "'${policy} n'"
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr "'n ${policy}'"
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr "' ${policy}'"
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr "' ${policy} '"
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr "'${policy} '"
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr _${policy}
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr ${policy}_
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr _${policy}_
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr ${policy}:
+ # Test policy longer than 32 chars fails stable.
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr 'jfdkkkkjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjffjfjfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
+
+ # Test policy specified correctly. Must pass.
+ _set_btrfs_sysfs_dev_policy $dev $attr $policy
+
+ # If the policy has no value return
+ if [[ -z $value ]]; then
+ return
+ fi
+
+ # Test value specified wrongly. Must fail.
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr "'$policy: $value'"
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr "'$policy:$value '"
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr "'$policy:$value typo'"
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr "'$policy:${value}typo'"
+ _set_btrfs_sysfs_dev_policy_must_fail $dev $attr "'$policy :$value'"
+
+ # Test policy and value all specified correctly. Must pass.
+ _set_btrfs_sysfs_dev_policy $dev $attr $policy:$value
+}
diff --git a/common/sysfs b/common/sysfs
deleted file mode 100644
index c36ab426..00000000
--- a/common/sysfs
+++ /dev/null
@@ -1,145 +0,0 @@
-##/bin/bash
-# SPDX-License-Identifier: GPL-2.0+
-# Copyright (c) 2025 Oracle. All Rights Reserved.
-#
-# Common/sysfs file for the sysfs related helper functions.
-
-# Test for the existence of a policy at /sys/fs/$FSTYP/$DEV/$ATTR
-#
-# All arguments are necessary, and in this order:
-# - dev: device name, e.g. $SCRATCH_DEV
-# - attr: path name under /sys/fs/$FSTYP/$dev
-# - policy: policy within /sys/fs/$FSTYP/$dev
-#
-# Usage example:
-# _has_fs_sysfs_attr_policy /dev/mapper/scratch-dev read_policy round-robin
-_has_fs_sysfs_attr_policy()
-{
- local dev=$1
- local attr=$2
- local policy=$3
-
- if [ ! -b "$dev" -o -z "$attr" -o -z "$policy" ]; then
- _fail \
- "Usage: _has_fs_sysfs_attr_policy <mounted_device> <attr> <policy>"
- fi
-
- local dname=$(_fs_sysfs_dname $dev)
- if ! test -e /sys/fs/${FSTYP}/${dname}/${attr}; then
- return 1
- fi
-
- cat /sys/fs/${FSTYP}/${dname}/${attr} | grep -q ${policy}
-}
-
-# Require the existence of a sysfs entry at /sys/fs/$FSTYP/$DEV/$ATTR
-# and value in it contains $policy
-# All arguments are necessary, and in this order:
-# - dev: device name, e.g. $SCRATCH_DEV
-# - attr: path name under /sys/fs/$FSTYP/$dev
-# - policy: mentioned in /sys/fs/$FSTYP/$dev/$attr
-#
-# Usage example:
-# _require_fs_sysfs_attr_policy /dev/mapper/scratch-dev read_policy round-robin
-_require_fs_sysfs_attr_policy()
-{
- _has_fs_sysfs_attr_policy "$@" && return
-
- local dev=$1
- local attr=$2
- local policy=$3
- local dname=$(_fs_sysfs_dname $dev)
-
- _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr} ${policy}"
-}
-
-_set_sysfs_policy()
-{
- local dev=$1
- local attr=$2
- shift
- shift
- local policy=$@
-
- _set_fs_sysfs_dev_attr $dev $attr ${policy}
-
- case "$FSTYP" in
- btrfs)
- _get_fs_sysfs_dev_attr $dev $attr | grep -q "[${policy}]"
- if [[ $? != 0 ]]; then
- echo "Setting sysfs $attr $policy failed"
- fi
- ;;
- *)
- _fail \
-"sysfs syntax verification for '${attr}' '${policy}' for '${FSTYP}' is not implemented"
- ;;
- esac
-}
-
-_set_sysfs_policy_must_fail()
-{
- local dev=$1
- local attr=$2
- shift
- shift
- local policy=$@
-
- _set_fs_sysfs_dev_attr $dev $attr ${policy} | _filter_sysfs_error \
- | tee -a $seqres.full
-}
-
-# Verify sysfs attribute rejects invalid input.
-# Usage syntax:
-# _verify_sysfs_syntax <$dev> <$attr> <$policy> [$value]
-# Examples:
-# _verify_sysfs_syntax $TEST_DEV read_policy pid
-# _verify_sysfs_syntax $TEST_DEV read_policy round-robin 4k
-# Note:
-# Testcase must include
-# . ./common/filter
-# Prerequisite checks are kept outside this function
-# to make them clear to the test case, rather than hiding
-# them deep inside another function.
-# _require_fs_sysfs_attr_policy $TEST_DEV $attr $policy
-_verify_sysfs_syntax()
-{
- local dev=$1
- local attr=$2
- local policy=$3
- local value=$4
-
- # Test policy specified wrongly. Must fail.
- _set_sysfs_policy_must_fail $dev $attr "'$policy $policy'"
- _set_sysfs_policy_must_fail $dev $attr "'$policy t'"
- _set_sysfs_policy_must_fail $dev $attr "' '"
- _set_sysfs_policy_must_fail $dev $attr "'${policy} n'"
- _set_sysfs_policy_must_fail $dev $attr "'n ${policy}'"
- _set_sysfs_policy_must_fail $dev $attr "' ${policy}'"
- _set_sysfs_policy_must_fail $dev $attr "' ${policy} '"
- _set_sysfs_policy_must_fail $dev $attr "'${policy} '"
- _set_sysfs_policy_must_fail $dev $attr _${policy}
- _set_sysfs_policy_must_fail $dev $attr ${policy}_
- _set_sysfs_policy_must_fail $dev $attr _${policy}_
- _set_sysfs_policy_must_fail $dev $attr ${policy}:
- # Test policy longer than 32 chars fails stable.
- _set_sysfs_policy_must_fail $dev $attr 'jfdkkkkjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjffjfjfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
-
- # Test policy specified correctly. Must pass.
- _set_sysfs_policy $dev $attr $policy
-
- # If the policy has no value return
- if [[ -z $value ]]; then
- return
- fi
-
- # Test value specified wrongly. Must fail.
- _set_sysfs_policy_must_fail $dev $attr "'$policy: $value'"
- _set_sysfs_policy_must_fail $dev $attr "'$policy:$value '"
- _set_sysfs_policy_must_fail $dev $attr "'$policy:$value typo'"
- _set_sysfs_policy_must_fail $dev $attr "'$policy:${value}typo'"
- _set_sysfs_policy_must_fail $dev $attr "'$policy :$value'"
-
- # Test policy and value all specified correctly. Must pass.
- _set_sysfs_policy $dev $attr $policy:$value
-}
diff --git a/tests/btrfs/253 b/tests/btrfs/253
index 5843643d..27c35dc9 100755
--- a/tests/btrfs/253
+++ b/tests/btrfs/253
@@ -25,7 +25,6 @@
# value is in megabytes.
#
. ./common/preamble
-. ./common/sysfs
_begin_fstest auto
# Parse a size string which is in the format "XX.XXMib".
@@ -226,7 +225,7 @@ alloc_size "Data" FOURTH_DATA_SIZE_MB
# Force chunk allocation of system block type must fail.
#
echo "Force allocation of system block type must fail."
-_set_sysfs_policy_must_fail ${SCRATCH_BDEV} allocation/system/force_chunk_alloc 1
+_set_btrfs_sysfs_dev_policy_must_fail ${SCRATCH_BDEV} allocation/system/force_chunk_alloc 1
#
# Verification of initial allocation.
diff --git a/tests/btrfs/329 b/tests/btrfs/329
index f4fadded..9d6ccce9 100755
--- a/tests/btrfs/329
+++ b/tests/btrfs/329
@@ -9,13 +9,12 @@
. ./common/preamble
_begin_fstest auto quick
-. ./common/sysfs
. ./common/filter
_require_test
-_require_fs_sysfs_attr_policy $TEST_DEV read_policy round-robin
+_require_btrfs_sysfs_dev_policy $TEST_DEV read_policy round-robin
-_verify_sysfs_syntax $TEST_DEV read_policy round-robin 4096
+_verify_btrfs_sysfs_dev_syntax $TEST_DEV read_policy round-robin 4096
status=0
exit
diff --git a/tests/btrfs/334 b/tests/btrfs/334
index 08b66dc7..8c0f226e 100755
--- a/tests/btrfs/334
+++ b/tests/btrfs/334
@@ -9,13 +9,12 @@
. ./common/preamble
_begin_fstest auto quick
-. ./common/sysfs
. ./common/filter
_require_test
_require_fs_sysfs_dev_attr $TEST_DEV allocation/data/chunk_size
-_verify_sysfs_syntax $TEST_DEV allocation/data/chunk_size 256m
+_verify_btrfs_sysfs_dev_syntax $TEST_DEV allocation/data/chunk_size 256m
status=0
exit
--
2.55.0
next prev parent reply other threads:[~2026-10-23 20:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 20:31 [PATCH v2 0/6] Refactor *_fs_sysfs_* helpers Zorro Lang
2026-10-23 20:31 ` [PATCH v2 1/6] fstests: rename _*_fs_sysfs_attr helpers to _*_fs_sysfs_dev_attr Zorro Lang
2026-10-23 20:31 ` [PATCH v2 2/6] fstests: consolidate _require_fs_sysfs and _require_fs_sysfs_dev_attr Zorro Lang
2026-10-23 20:31 ` Zorro Lang [this message]
2026-10-23 20:31 ` [PATCH v2 4/6] common/rc: add helpers for /sys/fs/$FSTYP/features/ Zorro Lang
2026-10-23 20:31 ` [PATCH v2 5/6] common/rc: use common helper in _require_fanotify_ioerrors for f2fs Zorro Lang
2026-10-23 20:31 ` [PATCH v2 6/6] fstests: replace btrfs specific helpers with common sysfs helpers Zorro Lang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261023203114.1655019-4-zlang@kernel.org \
--to=zlang@kernel.org \
--cc=asj@kernel.org \
--cc=chao@kernel.org \
--cc=fstests@vger.kernel.org \
--cc=hch@infradead.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox