Page MenuHomeFreeBSD

D61933.1795486225.diff
No OneTemporary

Authored By
Unknown
Size
12 KB
Referenced Files
None
Subscribers
None

D61933.1795486225.diff

diff --git a/tests/sys/vfs/abi_root_symlink.sh b/tests/sys/vfs/abi_root_symlink.sh
--- a/tests/sys/vfs/abi_root_symlink.sh
+++ b/tests/sys/vfs/abi_root_symlink.sh
@@ -2,53 +2,39 @@
#
# Copyright (c) 2026 Devin Teske <dteske@FreeBSD.org>
#
-# Regression tests for absolute symlink resolution under an ABI root
-# (compat.linux.emul_path). namei(9) resolves paths for Linux ABI
-# processes by trying the ABI root first and falling back to the
-# native root. Absolute symlink targets receive the same treatment:
-# a target is first resolved under the ABI root (so self-contained
-# Linux userlands keep working, PR 289739); when the target itself
-# does not resolve there, the walk restarts once from the native
-# root using the expansion (so symlinks pointing at host paths, and
-# linprocfs' /proc/<pid>/exe, keep working, PR 297426). An ENOENT
-# past a target that did resolve under the ABI root falls back to
-# the original path like any other lookup.
+# Regression tests for absolute symlink resolution under an
+# alternative root. namei(9) resolves absolute paths by trying
+# the alternative root first and falling back to the native root.
+# Absolute symlink targets receive the same treatment: a target
+# is first resolved under the alternative root (so self-contained
+# Linux userlands keep working, PR 289739); when the target
+# itself does not resolve there, the walk restarts once from the
+# native root using the expansion (so symlinks pointing at host
+# paths, and linprocfs' /proc/<pid>/exe, keep working, PR 297426).
+# An ENOENT past a target that did resolve under the alternative
+# root falls back to the original path like any other lookup.
+#
+# The Linux ABI sets this root from compat.linux.emul_path when
+# it activates a branded image. These tests set the same root
+# with chaltroot(2), through chroot -a, and do not need a Linux
+# userland.
#
-# These tests require the Linux ABI (linux_enable=YES) and a Linux
-# userland (e.g. emulators/linux_base-rl9) providing ${emul_path}/bin/sh.
-# Without that, they skip, so CI jobs that lack a Linux base do not
-# fail.
# Each case comments the fixture so it can be rebuilt by hand.
# $wd is any empty directory (the ATF work directory when kyua
-# runs). $emul is compat.linux.emul_path, usually /compat/linux.
-# $emul$wd means the same path names created under that ABI root.
+# runs). $abi is the alternative root, created at $wd/abi.
+# $abi$wd means the same path names created under that root.
#
-require_linux()
+setup_abi()
{
- emul=$(sysctl -n compat.linux.emul_path 2>/dev/null)
- [ "$emul" ] || atf_skip "Linux ABI not present (compat.linux.emul_path)"
- kldstat -q -n linux64 || kldstat -q -n linux ||
- atf_skip "linux(4) not loaded"
- lsh="$emul/bin/sh"
- [ -x "$lsh" ] || atf_skip "Linux userland not installed ($lsh)"
- # Mirror of the ATF work directory under the ABI root.
+ # Private alternative root for chroot -a
wd=$(pwd)
- abiwd="$emul$wd"
+ abi="$wd/abi"
+ abiwd="$abi$wd"
atf_check mkdir -p "$abiwd"
}
-cleanup_linux()
-{
- emul=$(sysctl -n compat.linux.emul_path 2>/dev/null)
- [ "$emul" ] || return 0
- rm -rf "$emul$(pwd)" 2>/dev/null
- # Remove now-empty parents mirrored under the ABI root.
- rmdir -p "$emul$(dirname "$(pwd)")" 2>/dev/null
- return 0
-}
-
-atf_test_case symlink_target_in_abi_root cleanup
+atf_test_case symlink_target_in_abi_root
symlink_target_in_abi_root_head()
{
atf_set "descr" "Absolute symlink target under the ABI root wins" \
@@ -58,38 +44,36 @@
symlink_target_in_abi_root_body()
{
#
- # Recreate by hand. $wd is any empty directory. $emul is
- # compat.linux.emul_path (usually /compat/linux).
+ # Recreate by hand. $wd is any empty directory. $abi is
+ # the alternative root ($wd/abi).
#
# Native:
# $wd/f-both
# Regular file containing the word "native".
#
- # ABI (the same path names created under $emul):
- # $emul$wd/f-both
+ # Alternative root (the same path names created under $abi):
+ # $abi$wd/f-both
# Regular file containing the word "abi".
- # $emul$wd/link-both
+ # $abi$wd/link-both
# Absolute symlink whose target is $wd/f-both.
#
- # A Linux process opens $wd/link-both. namei tries that path
- # under the ABI root first ($emul$wd/link-both), follows the
- # symlink to $wd/f-both, and stays on the ABI pass, so the
- # file that is read is $emul$wd/f-both.
+ # chroot -a $abi /bin/cat opens $wd/link-both. namei tries
+ # that path under the alternative root first
+ # ($abi$wd/link-both), follows the symlink to $wd/f-both,
+ # and stays on the ABI pass, so the file that is read is
+ # $abi$wd/f-both.
#
# Expected result: the read returns "abi".
#
- require_linux
+ setup_abi
printf native > "$wd/f-both"
printf abi > "$abiwd/f-both"
atf_check ln -s "$wd/f-both" "$abiwd/link-both"
- atf_check -o inline:"abi" "$lsh" -c "cat $wd/link-both"
-}
-symlink_target_in_abi_root_cleanup()
-{
- cleanup_linux
+ atf_check -o inline:"abi" \
+ chroot -a "$abi" /bin/cat "$wd/link-both"
}
-atf_test_case symlink_target_native_only cleanup
+atf_test_case symlink_target_native_only
symlink_target_native_only_head()
{
atf_set "descr" "Absolute symlink under the ABI root pointing at" \
@@ -99,38 +83,36 @@
symlink_target_native_only_body()
{
#
- # Recreate by hand. $wd is any empty directory. $emul is
- # compat.linux.emul_path (usually /compat/linux).
+ # Recreate by hand. $wd is any empty directory. $abi is
+ # the alternative root ($wd/abi).
#
# Native:
# $wd/f-native
# Regular file containing the word "native".
#
- # ABI (the same path names created under $emul):
- # $emul$wd/link-native
+ # Alternative root (the same path names created under $abi):
+ # $abi$wd/link-native
# Absolute symlink whose target is $wd/f-native.
- # There is no $emul$wd/f-native.
- #
- # A Linux process opens $wd/link-native. namei tries that
- # path under the ABI root first ($emul$wd/link-native) and
- # follows the symlink to $wd/f-native. That target does not
- # exist under the ABI root, so the walk should restart once
- # from the native root using the expansion and read
+ # There is no $abi$wd/f-native.
+ #
+ # chroot -a $abi /bin/cat opens $wd/link-native. namei tries
+ # that path under the alternative root first
+ # ($abi$wd/link-native) and follows the symlink to
+ # $wd/f-native. That target does not exist under the
+ # alternative root, so the walk should restart once from
+ # the native root using the expansion and read
# $wd/f-native.
#
# Expected result: the read returns "native".
#
- require_linux
+ setup_abi
printf native > "$wd/f-native"
atf_check ln -s "$wd/f-native" "$abiwd/link-native"
- atf_check -o inline:"native" "$lsh" -c "cat $wd/link-native"
-}
-symlink_target_native_only_cleanup()
-{
- cleanup_linux
+ atf_check -o inline:"native" \
+ chroot -a "$abi" /bin/cat "$wd/link-native"
}
-atf_test_case symlink_target_native_only_midpath cleanup
+atf_test_case symlink_target_native_only_midpath
symlink_target_native_only_midpath_head()
{
atf_set "descr" "Absolute directory symlink under the ABI root" \
@@ -142,8 +124,8 @@
symlink_target_native_only_midpath_body()
{
#
- # Recreate by hand. $wd is any empty directory. $emul is
- # compat.linux.emul_path (usually /compat/linux).
+ # Recreate by hand. $wd is any empty directory. $abi is
+ # the alternative root ($wd/abi).
#
# Native:
# $wd/ndir/
@@ -151,34 +133,31 @@
# $wd/ndir/f
# Regular file containing the word "native".
#
- # ABI (the same path names created under $emul):
- # $emul$wd/dirlink
+ # Alternative root (the same path names created under $abi):
+ # $abi$wd/dirlink
# Absolute symlink whose target is $wd/ndir.
- # There is no $emul$wd/ndir.
- #
- # A Linux process opens $wd/dirlink/f. namei tries that path
- # under the ABI root first ($emul$wd/dirlink/f), follows
- # dirlink to $wd/ndir, and then wants $wd/ndir/f. The
- # directory does not exist under the ABI root, so the walk
- # should restart once from the native root using the
- # expansion and read $wd/ndir/f. This is the
- # linux-rl9-fontconfig case (/etc/fonts ->
+ # There is no $abi$wd/ndir.
+ #
+ # chroot -a $abi /bin/cat opens $wd/dirlink/f. namei tries
+ # that path under the alternative root first
+ # ($abi$wd/dirlink/f), follows dirlink to $wd/ndir, and then
+ # wants $wd/ndir/f. The directory does not exist under the
+ # alternative root, so the walk should restart once from
+ # the native root using the expansion and read $wd/ndir/f.
+ # This is the linux-rl9-fontconfig case (/etc/fonts ->
# /usr/local/etc/fonts).
#
# Expected result: the read returns "native".
#
- require_linux
+ setup_abi
atf_check mkdir "$wd/ndir"
printf native > "$wd/ndir/f"
atf_check ln -s "$wd/ndir" "$abiwd/dirlink"
- atf_check -o inline:"native" "$lsh" -c "cat $wd/dirlink/f"
-}
-symlink_target_native_only_midpath_cleanup()
-{
- cleanup_linux
+ atf_check -o inline:"native" \
+ chroot -a "$abi" /bin/cat "$wd/dirlink/f"
}
-atf_test_case symlink_target_resolved_suffix cleanup
+atf_test_case symlink_target_resolved_suffix
symlink_target_resolved_suffix_head()
{
atf_set "descr" "ENOENT past an absolute symlink target that" \
@@ -189,8 +168,8 @@
symlink_target_resolved_suffix_body()
{
#
- # Recreate by hand. $wd is any empty directory. $emul is
- # compat.linux.emul_path (usually /compat/linux).
+ # Recreate by hand. $wd is any empty directory. $abi is
+ # the alternative root ($wd/abi).
#
# Native:
# $wd/tdir/
@@ -198,36 +177,34 @@
# $wd/tdir/f
# Regular file containing the word "native".
#
- # ABI (the same path names created under $emul):
- # $emul$wd/tdir/
+ # Alternative root (the same path names created under $abi):
+ # $abi$wd/tdir/
# Empty directory (no file named f).
- # $emul$wd/reslink
+ # $abi$wd/reslink
# Absolute symlink whose target is $wd/tdir.
#
- # A Linux process opens $wd/reslink/f. namei tries that path
- # under the ABI root first ($emul$wd/reslink/f), follows
- # reslink to $wd/tdir, and finds $emul$wd/tdir on the ABI
- # pass. The leftover component f is missing there. Because
- # the symlink target already resolved under the ABI root,
- # the native restart must not walk the expansion (that would
+ # chroot -a $abi /bin/cat opens $wd/reslink/f. namei tries
+ # that path under the alternative root first
+ # ($abi$wd/reslink/f), follows reslink to $wd/tdir, and
+ # finds $abi$wd/tdir on the ABI pass. The leftover
+ # component f is missing there. Because the symlink target
+ # already resolved under the alternative root, the native
+ # restart must not walk the expansion (that would
# incorrectly find $wd/tdir/f). It restarts the original
# path and still gets ENOENT.
#
# Expected result: ENOENT.
#
- require_linux
+ setup_abi
atf_check mkdir "$abiwd/tdir"
atf_check mkdir "$wd/tdir"
printf native > "$wd/tdir/f"
atf_check ln -s "$wd/tdir" "$abiwd/reslink"
- atf_check -s not-exit:0 -e ignore "$lsh" -c "cat $wd/reslink/f"
-}
-symlink_target_resolved_suffix_cleanup()
-{
- cleanup_linux
+ atf_check -s not-exit:0 -e ignore \
+ chroot -a "$abi" /bin/cat "$wd/reslink/f"
}
-atf_test_case plain_native_fallback cleanup
+atf_test_case plain_native_fallback
plain_native_fallback_head()
{
atf_set "descr" "Plain path (no symlink) absent under the ABI root" \
@@ -237,29 +214,26 @@
plain_native_fallback_body()
{
#
- # Recreate by hand. $wd is any empty directory. $emul is
- # compat.linux.emul_path (usually /compat/linux).
+ # Recreate by hand. $wd is any empty directory. $abi is
+ # the alternative root ($wd/abi).
#
# Native:
# $wd/f-plain
# Regular file containing the word "native".
#
- # ABI (the same path names created under $emul):
- # There is no $emul$wd/f-plain, and no symlink.
+ # Alternative root (the same path names created under $abi):
+ # There is no $abi$wd/f-plain, and no symlink.
#
- # A Linux process opens $wd/f-plain. namei tries that path
- # under the ABI root first, gets ENOENT, and restarts the
- # original path from the native root.
+ # chroot -a $abi /bin/cat opens $wd/f-plain. namei tries
+ # that path under the alternative root first, gets ENOENT,
+ # and restarts the original path from the native root.
#
# Expected result: the read returns "native".
#
- require_linux
+ setup_abi
printf native > "$wd/f-plain"
- atf_check -o inline:"native" "$lsh" -c "cat $wd/f-plain"
-}
-plain_native_fallback_cleanup()
-{
- cleanup_linux
+ atf_check -o inline:"native" \
+ chroot -a "$abi" /bin/cat "$wd/f-plain"
}
atf_init_test_cases()

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 24, 2:10 AM (23 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41943315
Default Alt Text
D61933.1795486225.diff (12 KB)

Event Timeline