From a23877b1506b2fc679006a05d134083e5ecd0afa Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Thu, 3 Feb 2022 14:05:32 -0800 Subject: [PATCH] Add fs test functions for mounted paths We have some fs functions which return info based on the test mount nr as the test has setup. This refactors those a bit to also provide some of the info when the caller has a path in a given mount. This will let tests work with scratch mounts a little more easily. Signed-off-by: Zach Brown Signed-off-by: Bryant G. Duffy-Ly --- tests/funcs/fs.sh | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/tests/funcs/fs.sh b/tests/funcs/fs.sh index 080b5c5f..78a8420b 100644 --- a/tests/funcs/fs.sh +++ b/tests/funcs/fs.sh @@ -29,13 +29,12 @@ t_mount_rid() } # -# Output the "f.$fsid.r.$rid" identifier string for the given mount -# number, 0 is used by default if none is specified. +# Output the "f.$fsid.r.$rid" identifier string for the given path +# in a mounted scoutfs volume. # -t_ident() +t_ident_from_mnt() { - local nr="${1:-0}" - local mnt="$(eval echo \$T_M$nr)" + local mnt="$1" local fsid local rid @@ -45,6 +44,38 @@ t_ident() echo "f.${fsid:0:6}.r.${rid:0:6}" } +# +# Output the "f.$fsid.r.$rid" identifier string for the given mount +# number, 0 is used by default if none is specified. +# +t_ident() +{ + local nr="${1:-0}" + local mnt="$(eval echo \$T_M$nr)" + + t_ident_from_mnt "$mnt" +} + +# +# Output the sysfs path for a path in a mounted fs. +# +t_sysfs_path_from_ident() +{ + local ident="$1" + + echo "/sys/fs/scoutfs/$ident" +} + +# +# Output the sysfs path for a path in a mounted fs. +# +t_sysfs_path_from_mnt() +{ + local mnt="$1" + + t_sysfs_path_from_ident $(t_ident_from_mnt $mnt) +} + # # Output the mount's sysfs path, defaulting to mount 0 if none is # specified. @@ -53,7 +84,7 @@ t_sysfs_path() { local nr="$1" - echo "/sys/fs/scoutfs/$(t_ident $nr)" + t_sysfs_path_from_ident $(t_ident $nr) } #