From: Boris Burkov <boris@bur.io>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, fstests@vger.kernel.org
Subject: [PATCH v4 1/6] common: refactor sysfs_attr functions
Date: Thu, 28 Sep 2023 16:16:43 -0700 [thread overview]
Message-ID: <0714f6b21000181ab43d3085903859b8ae1e1a32.1695942727.git.boris@bur.io> (raw)
In-Reply-To: <cover.1695942727.git.boris@bur.io>
Expand the has/get/require functions to allow passing a dev by
parameter, and implement the test_dev specific one in terms of the new
generic one.
Signed-off-by: Boris Burkov <boris@bur.io>
---
common/rc | 127 +++++++++++++++++++++++++++++++++++-------------------
1 file changed, 82 insertions(+), 45 deletions(-)
diff --git a/common/rc b/common/rc
index 1618ded54..c3cd53546 100644
--- a/common/rc
+++ b/common/rc
@@ -4689,47 +4689,33 @@ run_fsx()
rm -f $tmp.fsx
}
-# Test for the existence of a sysfs entry at /sys/fs/$FSTYP/DEV/$ATTR
+_require_statx()
+{
+ $here/src/stat_test --check-statx ||
+ _notrun "This test requires the statx system call"
+}
+
+# Get the path to the sysfs directory for the fs on a device
#
# Only one argument is needed:
-# - attr: path name under /sys/fs/$FSTYP/DEV
+# - dev: mounted block device for the fs
#
# Usage example:
-# _require_fs_sysfs error/fail_at_unmount
-_has_fs_sysfs()
+# _fs_sysfs_dname /dev/mapper/scratch-dev
+_fs_sysfs_dname()
{
- local attr=$1
- local dname
+ local dev=$1
+
+ if [ ! -b "$dev" ]; then
+ _fail "Usage: _fs_sysfs_dname <mounted_device>"
+ fi
case "$FSTYP" in
btrfs)
- dname=$(findmnt -n -o UUID $TEST_DEV) ;;
+ findmnt -n -o UUID ${dev} ;;
*)
- dname=$(_short_dev $TEST_DEV) ;;
+ _short_dev $dev ;;
esac
-
- if [ -z "$attr" -o -z "$dname" ];then
- _fail "Usage: _require_fs_sysfs <sysfs_attr_path>"
- fi
-
- test -e /sys/fs/${FSTYP}/${dname}/${attr}
-}
-
-# 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)
-
- _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}"
-}
-
-_require_statx()
-{
- $here/src/stat_test --check-statx ||
- _notrun "This test requires the statx system call"
}
# Write "content" into /sys/fs/$FSTYP/$DEV/$ATTR
@@ -4753,13 +4739,7 @@ _set_fs_sysfs_attr()
_fail "Usage: _set_fs_sysfs_attr <mounted_device> <attr> <content>"
fi
- local dname
- case "$FSTYP" in
- btrfs)
- dname=$(findmnt -n -o UUID ${dev}) ;;
- *)
- dname=$(_short_dev $dev) ;;
- esac
+ local dname=$(_fs_sysfs_dname $dev)
echo "$content" > /sys/fs/${FSTYP}/${dname}/${attr}
}
@@ -4781,17 +4761,74 @@ _get_fs_sysfs_attr()
_fail "Usage: _get_fs_sysfs_attr <mounted_device> <attr>"
fi
- local dname
- case "$FSTYP" in
- btrfs)
- dname=$(findmnt -n -o UUID ${dev}) ;;
- *)
- dname=$(_short_dev $dev) ;;
- esac
+ local dname=$(_fs_sysfs_dname $dev)
cat /sys/fs/${FSTYP}/${dname}/${attr}
}
+# Test for the existence of a sysfs entry 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
+#
+# Usage example:
+# _has_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount
+_has_fs_sysfs_attr()
+{
+ local dev=$1
+ local attr=$2
+
+ if [ ! -b "$dev" -o -z "$attr" ];then
+ _fail "Usage: _get_fs_sysfs_attr <mounted_device> <attr>"
+ fi
+
+ local dname=$(_fs_sysfs_dname $dev)
+
+ test -e /sys/fs/${FSTYP}/${dname}/${attr}
+}
+
+# Require the existence of a sysfs entry 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
+#
+# Usage example:
+# _require_fs_sysfs_attr /dev/mapper/scratch-dev error/fail_at_unmount
+_require_fs_sysfs_attr()
+{
+ _has_fs_sysfs_attr "$@" && return
+
+ local dev=$1
+ local attr=$2
+ local dname=$(_fs_sysfs_dname $dev)
+
+ _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${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_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)
+
+ _notrun "This test requires /sys/fs/${FSTYP}/${dname}/${attr}"
+}
+
# Generic test for specific filesystem feature.
# Currently only implemented to test overlayfs features.
_require_scratch_feature()
--
2.42.0
next prev parent reply other threads:[~2023-09-28 23:16 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-28 23:16 [PATCH v4 0/6] btrfs: simple quotas fstests Boris Burkov
2023-09-28 23:16 ` Boris Burkov [this message]
2023-09-29 8:23 ` [PATCH v4 1/6] common: refactor sysfs_attr functions Anand Jain
2023-09-28 23:16 ` [PATCH v4 2/6] btrfs: quota mode helpers Boris Burkov
2023-09-29 8:57 ` Anand Jain
2023-09-29 9:11 ` Anand Jain
2023-09-28 23:16 ` [PATCH v4 3/6] btrfs/301: new test for simple quotas Boris Burkov
2023-09-28 23:16 ` [PATCH v4 4/6] btrfs: quota rescan helpers Boris Burkov
2023-09-29 9:14 ` Anand Jain
2023-09-28 23:16 ` [PATCH v4 5/6] btrfs: use new rescan wrapper Boris Burkov
2023-09-29 9:28 ` Anand Jain
2023-09-28 23:16 ` [PATCH v4 6/6] btrfs: skip squota incompatible tests Boris Burkov
2023-09-29 9:37 ` Anand Jain
2023-09-29 9:42 ` Anand Jain
2023-09-29 16:57 ` Boris Burkov
2023-09-29 17:28 ` Boris Burkov
2023-09-29 17:43 ` [PATCH] btrfs: fix rescan helper Boris Burkov
2023-09-30 9:37 ` Anand Jain
2023-09-30 9:45 ` [PATCH v4 0/6] btrfs: simple quotas fstests Anand Jain
2023-10-05 8:08 ` Anand Jain
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=0714f6b21000181ab43d3085903859b8ae1e1a32.1695942727.git.boris@bur.io \
--to=boris@bur.io \
--cc=fstests@vger.kernel.org \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@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;
as well as URLs for NNTP newsgroup(s).