aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Burkov <boris@bur.io>2023-09-28 16:16:43 -0700
committerZorro Lang <zlang@kernel.org>2023-10-05 22:32:01 +0800
commitc0cafb48a892e0d9e414478df5d5f818d6c101dd (patch)
tree4c5e59055eac75fb8344f8d45a9aaf0e3e141950
parent2fddeb5c79ff16bf37e1f1d809bd94b360c27801 (diff)
downloadxfstests-dev-c0cafb48a892e0d9e414478df5d5f818d6c101dd.tar.gz
common: refactor sysfs_attr functions
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> Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: Zorro Lang <zlang@kernel.org>
-rw-r--r--common/rc127
1 files changed, 82 insertions, 45 deletions
diff --git a/common/rc b/common/rc
index 76a7e77403..5fd2d66a83 100644
--- a/common/rc
+++ b/common/rc
@@ -4705,47 +4705,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
@@ -4769,13 +4755,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}
}
@@ -4797,17 +4777,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: _has_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()