Linux XFS filesystem development
 help / color / mirror / Atom feed
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 2/6] fstests: consolidate _require_fs_sysfs and _require_fs_sysfs_dev_attr
Date: Sat, 24 Oct 2026 04:31:10 +0800	[thread overview]
Message-ID: <20261023203114.1655019-3-zlang@kernel.org> (raw)
In-Reply-To: <20261023203114.1655019-1-zlang@kernel.org>

There is heavy overlap between _require_fs_sysfs and
_require_fs_sysfs_dev_attr, and their ambiguous names make it
difficult to tell them apart.

Teach _require_fs_sysfs_dev_attr to default to $TEST_DEV when only
an attribute is given, remove _has_fs_sysfs and _require_fs_sysfs,
and update their callers.

Signed-off-by: Zorro Lang <zlang@kernel.org>
---
 common/rc       | 44 +++++++++++++++-----------------------------
 common/xfs      |  4 ++--
 tests/btrfs/253 |  4 ++--
 tests/btrfs/285 |  2 +-
 tests/xfs/006   |  2 +-
 tests/xfs/177   |  2 +-
 tests/xfs/264   |  6 +++---
 7 files changed, 25 insertions(+), 39 deletions(-)

diff --git a/common/rc b/common/rc
index 43c95930..bcecaaeb 100644
--- a/common/rc
+++ b/common/rc
@@ -5545,43 +5545,29 @@ _has_fs_sysfs_dev_attr()
 }
 
 # Require the existence of a sysfs entry at /sys/fs/$FSTYP/$DEV/$ATTR
-# All arguments are necessary, and in this order:
+#
+# If only one argument is given, it is taken as the attribute under
+# $TEST_DEV.  Otherwise the arguments are, in this order:
 #  - dev: device name, e.g. $SCRATCH_DEV
 #  - attr: path name under /sys/fs/$FSTYP/$dev
 #
-# Usage example:
+# Usage examples:
+#   _require_fs_sysfs_dev_attr error/fail_at_unmount
 #   _require_fs_sysfs_dev_attr /dev/mapper/scratch-dev error/fail_at_unmount
 _require_fs_sysfs_dev_attr()
 {
-	_has_fs_sysfs_dev_attr "$@" && return
-
-	local dev=$1
-	local attr=$2
-	local dname=$(_fs_sysfs_dname $dev)
-
-	_notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}"
-}
+	local dev attr
 
-# Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR
-#
-# Only one argument is needed:
-#  - attr: path name under /sys/fs/$FSTYP/DEV
-#
-# Usage example:
-#   _has_fs_sysfs error/fail_at_unmount
-_has_fs_sysfs()
-{
-	_has_fs_sysfs_dev_attr $TEST_DEV "$@"
-}
-
-# Require the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR
-_require_fs_sysfs()
-{
-	_has_fs_sysfs "$@" && return
-
-	local attr=$1
-	local dname=$(_short_dev $TEST_DEV)
+	if [ $# -eq 1 ];then
+		dev=$TEST_DEV
+		attr=$1
+	else
+		dev=$1
+		attr=$2
+	fi
+	_has_fs_sysfs_dev_attr "$dev" "$attr" && return
 
+	local dname=$(_fs_sysfs_dname $dev)
 	_notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}"
 }
 
diff --git a/common/xfs b/common/xfs
index 8bd144e3..cb0f6e0b 100644
--- a/common/xfs
+++ b/common/xfs
@@ -1226,13 +1226,13 @@ _xfs_prepare_for_eio_shutdown()
 	_add_dmesg_filter "Internal error"
 
 	# Don't retry any writes during the (presumably) post-shutdown unmount
-	_has_fs_sysfs "$ctlfile" && _set_fs_sysfs_dev_attr $dev "$ctlfile" 1
+	_has_fs_sysfs_dev_attr $dev "$ctlfile" && _set_fs_sysfs_dev_attr $dev "$ctlfile" 1
 
 	# Disable retry of metadata writes that fail with EIO
 	for ctl in max_retries retry_timeout_seconds; do
 		ctlfile="error/metadata/EIO/$ctl"
 
-		_has_fs_sysfs "$ctlfile" && _set_fs_sysfs_dev_attr $dev "$ctlfile" 0
+		_has_fs_sysfs_dev_attr $dev "$ctlfile" && _set_fs_sysfs_dev_attr $dev "$ctlfile" 0
 	done
 }
 
diff --git a/tests/btrfs/253 b/tests/btrfs/253
index d8b58f49..5843643d 100755
--- a/tests/btrfs/253
+++ b/tests/btrfs/253
@@ -90,8 +90,8 @@ _scratch_mkfs_sized $((10 * 1024 * 1024 * 1024)) >> $seqres.full 2>&1
 _scratch_mount >> $seqres.full 2>&1
 
 # Check if there is sufficient sysfs support.
-_require_fs_sysfs allocation/metadata/chunk_size
-_require_fs_sysfs allocation/metadata/force_chunk_alloc
+_require_fs_sysfs_dev_attr allocation/metadata/chunk_size
+_require_fs_sysfs_dev_attr allocation/metadata/force_chunk_alloc
 
 # Get free space.
 free_space  FREE_SPACE_MB
diff --git a/tests/btrfs/285 b/tests/btrfs/285
index 5ceb69d4..6a1eb236 100755
--- a/tests/btrfs/285
+++ b/tests/btrfs/285
@@ -16,7 +16,7 @@ sysfs_size_classes() {
 
 _require_scratch
 _require_btrfs_fs_sysfs
-_require_fs_sysfs allocation/data/size_classes
+_require_fs_sysfs_dev_attr allocation/data/size_classes
 
 f="$SCRATCH_MNT/f"
 small=$((16 * 1024))
diff --git a/tests/xfs/006 b/tests/xfs/006
index e03ade1d..443e2db2 100755
--- a/tests/xfs/006
+++ b/tests/xfs/006
@@ -25,7 +25,7 @@ _cleanup()
 
 _require_scratch
 _require_dm_target error
-_require_fs_sysfs error/fail_at_unmount
+_require_fs_sysfs_dev_attr error/fail_at_unmount
 
 _scratch_mkfs > $seqres.full 2>&1
 _dmerror_init
diff --git a/tests/xfs/177 b/tests/xfs/177
index 38b68a7d..e9b4661d 100755
--- a/tests/xfs/177
+++ b/tests/xfs/177
@@ -48,7 +48,7 @@ _require_scratch
 
 # We require /sys/fs/xfs/$device/stats/stats to monitor per-filesystem inode
 # cache usage.
-_require_fs_sysfs stats/stats
+_require_fs_sysfs_dev_attr stats/stats
 
 count_xfs_inode_objs() {
 	_get_fs_sysfs_dev_attr $SCRATCH_DEV stats/stats | awk '/vnodes/ {print $2}'
diff --git a/tests/xfs/264 b/tests/xfs/264
index c8a2f714..0820eecd 100755
--- a/tests/xfs/264
+++ b/tests/xfs/264
@@ -24,9 +24,9 @@ _cleanup()
 
 _require_scratch
 _require_dm_target error
-_require_fs_sysfs error/fail_at_unmount
-_require_fs_sysfs error/metadata/EIO/max_retries
-_require_fs_sysfs error/metadata/EIO/retry_timeout_seconds
+_require_fs_sysfs_dev_attr error/fail_at_unmount
+_require_fs_sysfs_dev_attr error/metadata/EIO/max_retries
+_require_fs_sysfs_dev_attr error/metadata/EIO/retry_timeout_seconds
 
 _scratch_mkfs >> $seqres.full 2>&1
 _dmerror_init
-- 
2.55.0


  parent reply	other threads:[~2026-10-23 20:31 UTC|newest]

Thread overview: 13+ 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-28 15:55   ` Christoph Hellwig
2026-10-23 20:31 ` Zorro Lang [this message]
2026-10-28 15:57   ` [PATCH v2 2/6] fstests: consolidate _require_fs_sysfs and _require_fs_sysfs_dev_attr Christoph Hellwig
2026-10-23 20:31 ` [PATCH v2 3/6] common: move btrfs-only sysfs policy helpers out of common/sysfs Zorro Lang
2026-10-28 15:57   ` Christoph Hellwig
2026-10-23 20:31 ` [PATCH v2 4/6] common/rc: add helpers for /sys/fs/$FSTYP/features/ Zorro Lang
2026-10-28 15:58   ` Christoph Hellwig
2026-10-23 20:31 ` [PATCH v2 5/6] common/rc: use common helper in _require_fanotify_ioerrors for f2fs Zorro Lang
2026-10-28 15:58   ` Christoph Hellwig
2026-10-23 20:31 ` [PATCH v2 6/6] fstests: replace btrfs specific helpers with common sysfs helpers Zorro Lang
2026-10-28 15:58   ` Christoph Hellwig

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-3-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