f_device_get_all probes every DEV geom. Each probe calls f_geom_find_by to turn a provider ref into a struct, and f_geom_find for the gpt, geli, and nop parent names. Those walks cover every class and geom, so a machine with a large disk set spends its time in sh at "Probing devices". Record each struct by id, and each geom by name, while f_geom_get_all parses kern.geom.confxml. f_geom_find_by resolves property id from the id map. f_geom_find resolves a non-empty name from the name map. The same name can appear in more than one class, so the name map stores a list of structs. A name that is still not a shell identifier after rewriting is left for the linear scan. f_geom_reset drops both maps. Add an ATF test that times id and name lookups at 100 and 200 disks, and checks names that are not shell identifiers. PR: 269150 Reviewed by: kfv Differential Revision: https://reviews.freebsd.org/D61818
@@ -31,4 +31,7 @@ SCRIPTS= bsdconfig
MAN= bsdconfig.8
+HAS_TESTS=
+SUBDIR.${MK_TESTS}+= tests
+
.include <bsd.prog.mk>
@@ -1,6 +1,6 @@
if [ ! "$_GEOM_SUBR" ]; then _GEOM_SUBR=1
#
-# Copyright (c) 2012-2014 Devin Teske
+# Copyright (c) 2012-2026 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -87,6 +87,204 @@ f_struct_define GEOM_PROVIDER_CONFIG \
############################################################ FUNCTIONS
+# f_geom_clear_maps
+#
+# Drop the id and name maps built by f_geom_get_all
+#
+f_geom_clear_maps()
+{
+ f_geom_id_clear
+ f_geom_name_clear
+}
+
+# f_geom_id_clear
+#
+# Drop the id-to-struct index built by f_geom_get_all
+#
+f_geom_id_clear()
+{
+ local id
+
+ for id in $GEOM_IDS; do
+ unset GEOM_ID_$id
+ done
+ GEOM_IDS=
+ GEOM_ID_INDEX=
+}
+
+# f_geom_name_clear
+#
+# Drop the name-to-struct index built by f_geom_get_all
+#
+f_geom_name_clear()
+{
+ local key
+
+ for key in $GEOM_NAME_KEYS; do
+ unset GEOM_NM_$key
+ done
+ GEOM_NAME_KEYS=
+ GEOM_NAME_INDEX=
+}
+
+# f_geom_name_key $name $var_to_set
+#
+# Store the cache key for $name. A shell identifier is n_$name.
+# g_label_mangle_name keeps every printable byte other than a
+# space, a double quote, and percent. Those three become %XX.
+# The bytes it keeps, percent, and a space from gjournal are
+# rewritten with f_replaceall(). Underscore is doubled first, so
+# a literal _w cannot collide with a space encoded as _w. A name
+# that is still not an identifier is left for the scan.
+#
+f_geom_name_key()
+{
+ local __gnk_name="$1" __gnk_var="$2"
+ local __gnk_key="$__gnk_name"
+
+ # NB: Underscore first, so results are injective.
+ case "$__gnk_key" in
+ *_*) f_replaceall "$__gnk_key" _ __ __gnk_key ;;
+ esac
+
+ # Fast path for performance
+ case "$__gnk_key" in
+ *[!$VALID_VARNAME_CHARS]*) : fall-through ;;
+ *)
+ setvar "$__gnk_var" "$__gnk_key"
+ return
+ esac
+
+ #
+ # Encode based on kernel survey of possibilities
+ # NB: case matching improves performance
+ #
+ case "$__gnk_key" in
+ */*) f_replaceall "$__gnk_key" / _s __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *.*) f_replaceall "$__gnk_key" . _d __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *-*) f_replaceall "$__gnk_key" - _h __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *" "*) f_replaceall "$__gnk_key" " " _w __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\!*) f_replaceall "$__gnk_key" \! _b __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\#*) f_replaceall "$__gnk_key" \# _N __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\$*) f_replaceall "$__gnk_key" $ _o __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *%*) f_replaceall "$__gnk_key" % _r __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\&*) f_replaceall "$__gnk_key" \& _n __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\'*) f_replaceall "$__gnk_key" \' _S __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\(*) f_replaceall "$__gnk_key" "[(]" _l __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\)*) f_replaceall "$__gnk_key" \) _R __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\**) f_replaceall "$__gnk_key" "[*]" _A __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *+*) f_replaceall "$__gnk_key" + _p __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *,*) f_replaceall "$__gnk_key" , _m __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *:*) f_replaceall "$__gnk_key" : _c __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\;*) f_replaceall "$__gnk_key" \; _i __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\<*) f_replaceall "$__gnk_key" \< _k __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *=*) f_replaceall "$__gnk_key" = _q __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\>*) f_replaceall "$__gnk_key" \> _g __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\?*) f_replaceall "$__gnk_key" "[?]" _B __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *@*) f_replaceall "$__gnk_key" @ _a __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *'['*) f_replaceall "$__gnk_key" [[] _C __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\\*) f_replaceall "$__gnk_key" '[\]' _E __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *']'*) f_replaceall "$__gnk_key" ] _D __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *^*) f_replaceall "$__gnk_key" ^ _e __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\`*) f_replaceall "$__gnk_key" \` _F __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\{*) f_replaceall "$__gnk_key" { _L __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *\|*) f_replaceall "$__gnk_key" \| _v __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *}*) f_replaceall "$__gnk_key" } _G __gnk_key ;;
+ esac
+ case "$__gnk_key" in
+ *~*) f_replaceall "$__gnk_key" \~ _t __gnk_key ;;
+ esac
+
+ # Check/set results
+ case "$__gnk_key" in
+ *[!$VALID_VARNAME_CHARS]*) return $FAILURE ;;
+ *) setvar "$__gnk_var" "$__gnk_key"
+ esac
+}
+
+# f_geom_name_add $name $struct
+#
+# Append $struct to the name map. f_geom_get_all evals one call per geom.
+#
+# NB: A single name in GEOM can exist in multiple class entries (hence why
+# we maintain a name-to-list map instead of one-to-one name-to-struct).
+# For example, nda0 can exist in PART, DISK, and DEV classes.
+#
+f_geom_name_add()
+{
+ local name="$1" struct="$2"
+ local key old
+
+ f_geom_name_key "$name" key || return
+ eval old=\${GEOM_NM_$key:-}
+ if [ ! "$old" ]; then
+ GEOM_NAME_KEYS="$GEOM_NAME_KEYS${GEOM_NAME_KEYS:+ }$key"
+ fi
+ if [ "$old" ]; then
+ eval GEOM_NM_$key=\"\$old $struct\"
+ else
+ eval GEOM_NM_$key=\$struct
+ fi
+}
+
# f_geom_get_all
#
# Parse sysctl(8) `kern.geom.confxml' data into a series of structs. GEOM
@@ -99,10 +297,23 @@ f_struct_define GEOM_PROVIDER_CONFIG \
# Use the function f_geom_find() to get a list of geoms (execute without
# arguments) or find specific geoms by class or name.
#
+# Each struct id is also stored in $GEOM_ID_<id>. $GEOM_ID_INDEX is set when
+# that map is complete, and $GEOM_IDS lists the ids so f_geom_id_clear() can
+# drop them. f_geom_find_by() uses the map for property `id'.
+#
+# Each GEOM name is also stored in $GEOM_NM_<key>. $GEOM_NAME_INDEX is set when
+# the map is complete and $GEOM_NAME_KEYS lists the keys so f_geom_name_clear()
+# can drop them. f_geom_find() uses the map for a non-empty name. <key> is the
+# GEOM name with underscore doubled and any other non-identifier character
+# rewritten by f_replaceall(). In the unlikely edge-case that a name cannot map
+# cleanly to <key>, it is still found with a full walk.
+#
f_geom_get_all()
{
+ f_geom_clear_maps
eval "$( sysctl -n kern.geom.confxml | awk '
BEGIN {
+ sq = "\047" # single-quote
struct_count["class"] = 0
struct_count["geom"] = 0
struct_count["consumer"] = 0
@@ -158,6 +369,11 @@ f_geom_get_all()
sub("</" type ">.*$", "", data)
return data
}
+ function shell_escape(s)
+ {
+ gsub(sq, sq "\\" sq sq, s)
+ return sq s sq
+ }
############################################### OPENING PATTERNS
$1 == "<mesh>" { mesh = 1 }
$1 ~ /^<(class|geom)$/ && mesh {
@@ -184,7 +400,16 @@ f_geom_get_all()
$1 ~ /^<[[:alnum:]]+>/ {
prop = $1
sub(/^</, "", prop); sub(/>.*/, "", prop)
- set_value(prop, extract_data(prop))
+ pval = extract_data(prop)
+ set_value(prop, pval)
+ if (prop == "name" && type_stack[cur_struct] == "geom") {
+ struct = struct_stack[cur_struct]
+ if (!(struct in geom_named)) {
+ geom_named[struct] = 1
+ geom_order[++ngeom_order] = struct
+ }
+ geom_names[struct] = pval
+ }
}
############################################### CLOSING PATTERNS
$1 ~ "^</(consumer|provider|config)>$" { cur_struct-- }
@@ -203,6 +428,26 @@ f_geom_get_all()
struct_count["geom"] = 0
}
$1 == "</mesh>" {
+ for (key in created) {
+ id = key
+ sub(/^(class|geom|consumer|provider)_/, "", id)
+ if (id ~ /^0x[[:xdigit:]]+$/) {
+ printf "GEOM_ID_%s=%s\n", id, created[key]
+ idlist = idlist " " id
+ nindex++
+ }
+ }
+ if (nindex)
+ print "GEOM_ID_INDEX=1"
+ printf "GEOM_IDS=\"%s\"\n", substr(idlist, 2)
+ for (i = 1; i <= ngeom_order; i++) {
+ struct = geom_order[i]
+ if (geom_names[struct] == "")
+ continue
+ printf "f_geom_name_add %s %s\n", \
+ shell_escape(geom_names[struct]), struct
+ }
+ print "GEOM_NAME_INDEX=1"
printf "NGEOM_CLASSES=%u\n", struct_count["class"]
delete struct_count
mesh = 0
@@ -216,6 +461,8 @@ f_geom_get_all()
f_geom_reset()
{
local classn=1 class ngeoms geomn geom
+
+ f_geom_clear_maps
while [ $classn -le ${NGEOM_CLASSES:-0} ]; do
class=geom_class_$classn
$class get ngeoms ngeoms
@@ -249,11 +496,43 @@ f_geom_rescan()
# out for capturing in a sub-shell (which is less-recommended because of
# performance degredation; for example, when called in a loop).
#
+# A non-empty name is taken from the f_geom_get_all() index when
+# $GEOM_NAME_INDEX is set, including a miss. Unset $GEOM_NAME_INDEX to
+# force the linear scan. An empty name still scans.
+#
f_geom_find()
{
local __name="$1" __type="${2:-$GEOM_CLASS_ANY}" __var_to_set="$3"
local __classn=1 __class __class_name __ngeoms
local __geomn __geom __geom_name __found=
+ local __key __list
+
+ #
+ # Indexed name. An empty name still walks the class.
+ # A miss does not scan
+ #
+ if [ "$__name" ] && [ "$GEOM_NAME_INDEX" ] &&
+ f_geom_name_key "$__name" __key
+ then
+ eval __list=\${GEOM_NM_$__key:-}
+ for __geom in $__list; do
+ if [ "$__type" != "$GEOM_CLASS_ANY" ]; then
+ __class="${__geom%_geom_*}"
+ __class_name=
+ $__class get name __class_name || continue
+ [ "$__class_name" = "$__type" ] || continue
+ fi
+ __found="$__found $__geom"
+ done
+ if [ "$__var_to_set" ]; then
+ setvar "$__var_to_set" "${__found# }"
+ else
+ echo $__found
+ fi
+ [ "$__found" ]
+ return
+ fi
+
while [ $__classn -le ${NGEOM_CLASSES:-0} ]; do
__class=geom_class_$__classn
$__class get name __class_name
@@ -303,13 +582,17 @@ f_geom_find()
# standard out for capturing in a sub-shell (which is less-recommended because
# of performance degredation; for example when called in a loop).
#
+# Property `id' is taken from the f_geom_get_all() index when
+# $GEOM_ID_INDEX is set, including a miss. Unset $GEOM_ID_INDEX to force
+# the linear scan. A value that is not a hex id still scans.
+#
f_geom_find_by()
{
local __prop="$1" __find="$2" __type="$3" __var_to_set="$4"
local __classn=1 __class __ngeoms
local __geomn __geom __nitems
local __itype __itemn __item
- local __value __found=
+ local __value __found= __kind=
if [ ! "$__prop" ]; then
[ "$__var_to_set" ] && setvar "$__var_to_set" ""
@@ -327,6 +610,36 @@ f_geom_find_by()
return $FAILURE
esac
+ #
+ # Indexed id. A non-hex id falls through to the scan
+ #
+ if [ "$__prop" = "id" ] && [ "$GEOM_ID_INDEX" ]; then
+ case "$__find" in
+ 0x*[![:xdigit:]]*) : scan ;;
+ 0x[[:xdigit:]]*)
+ eval __found=\${GEOM_ID_$__find:-}
+ if [ "$__found" -a "$__type" ]; then
+ __kind=
+ case "$__found" in
+ *_config) __kind=config ;;
+ *_consumer_[0-9]*) __kind=consumer ;;
+ *_provider_[0-9]*) __kind=provider ;;
+ *_geom_[0-9]*) __kind=geom ;;
+ geom_class_[0-9]*) __kind=class ;;
+ *) __kind=
+ esac
+ [ "$__kind" = "$__type" ] || __found=
+ fi
+ if [ "$__var_to_set" ]; then
+ setvar "$__var_to_set" "$__found"
+ else
+ [ "$__found" ] && echo "$__found"
+ fi
+ [ "$__found" ]
+ return
+ esac
+ fi
+
while [ $__classn -le ${NGEOM_CLASSES:-0} ]; do
__class=geom_class_$__classn
diff --git a/usr.sbin/bsdconfig/tests/Makefile b/usr.sbin/bsdconfig/tests/Makefile
new file mode 100644
index 000000000000..2bc8e9704231
--- /dev/null
+++ b/usr.sbin/bsdconfig/tests/Makefile
@@ -0,0 +1,3 @@
+ATF_TESTS_SH+= geom_subr_test
+
+.include <bsd.test.mk>
diff --git a/usr.sbin/bsdconfig/tests/geom_subr_test.sh b/usr.sbin/bsdconfig/tests/geom_subr_test.sh
new file mode 100644
index 000000000000..39fa88cb557f
--- /dev/null
+++ b/usr.sbin/bsdconfig/tests/geom_subr_test.sh
@@ -0,0 +1,324 @@
+#
+# Copyright (c) 2026 Devin Teske <dteske@FreeBSD.org>
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+#
+# Time geom lookups against /usr/share/bsdconfig/geom.subr.
+# A sysctl(8) shim serves the mesh, so an old geom.subr and the
+# indexed one see the same input. Replace geom.subr and run the
+# test again. The lookup seconds are on stdout. kyua test also
+# prints each case's wall time, which tracks the lookups.
+#
+# lookups_* times f_geom_find_by id. name_lookups_* times
+# f_geom_find by DEV name. The name map makes that a cache hit.
+# Without the map it is the walk f_device_probe_geom makes for
+# gpt/*, gptid/*, .eli, and .nop. name_chars checks names that
+# are not shell identifiers.
+#
+
+SHARE=/usr/share/bsdconfig
+
+#
+# Id bases. Decimal values of the hex bases in the mesh:
+# 65536 DEV geom, 131072 consumer, 196608 DISK geom, 262144 provider
+#
+DEV_GEOM_BASE=65536
+CONSUMER_BASE=131072
+DISK_GEOM_BASE=196608
+PROVIDER_BASE=262144
+
+# xid $base $n
+#
+# Print 0x-prefixed hex for $base + $n
+#
+xid()
+{
+ printf "0x%x\n" $(( $1 + $2 ))
+}
+
+# mesh_write $file $n
+#
+# Write N disks, DEV class first, so provider refs point forward
+#
+mesh_write()
+{
+ local file="$1" n="$2"
+ local i id_devgeom id_cons id_diskgeom id_prov
+
+ : > "$file"
+ provider_ids=
+ printf "%s\n" "<mesh>" "<class id=\"0x10\">" \
+ "<name>DEV</name>" >> "$file"
+ i=1
+ while [ "$i" -le "$n" ]; do
+ id_devgeom=$( xid $DEV_GEOM_BASE "$i" )
+ id_cons=$( xid $CONSUMER_BASE "$i" )
+ id_prov=$( xid $PROVIDER_BASE "$i" )
+ provider_ids="$provider_ids $id_prov"
+ printf "%s\n" \
+ "<geom id=\"$id_devgeom\">" \
+ "<name>ada$(( $i - 1 ))</name>" \
+ "<consumer id=\"$id_cons\">" \
+ "<provider ref=\"$id_prov\"/>" \
+ "</consumer>" \
+ "</geom>" >> "$file"
+ i=$(( $i + 1 ))
+ done
+ printf "%s\n" "</class>" "<class id=\"0x20\">" \
+ "<name>DISK</name>" >> "$file"
+ i=1
+ while [ "$i" -le "$n" ]; do
+ id_diskgeom=$( xid $DISK_GEOM_BASE "$i" )
+ id_prov=$( xid $PROVIDER_BASE "$i" )
+ printf "%s\n" \
+ "<geom id=\"$id_diskgeom\">" \
+ "<name>ada$(( $i - 1 ))</name>" \
+ "<provider id=\"$id_prov\">" \
+ "<name>ada$(( $i - 1 ))</name>" \
+ "<mediasize>512</mediasize>" \
+ "</provider>" \
+ "</geom>" >> "$file"
+ i=$(( $i + 1 ))
+ done
+ printf "%s\n" "</class>" "</mesh>" >> "$file"
+ provider_ids=${provider_ids# }
+}
+
+install_sysctl_shim()
+{
+ mkdir -p bin || exit
+ cat > bin/sysctl <<'EOF' || exit
+#!/bin/sh
+if [ "$1" = -n ] && [ "$2" = kern.geom.confxml ]; then
+ cat "$GEOM_MESH" || exit
+ exit 0
+fi
+exec /sbin/sysctl "$@"
+EOF
+ chmod +x bin/sysctl || exit
+ PATH=$( pwd )/bin:$PATH
+ export PATH
+}
+
+prepare()
+{
+ [ -f "$SHARE/geom.subr" ] || atf_skip "no $SHARE/geom.subr"
+ DEBUG_SELF_INITIALIZE=0
+ GEOM_SELF_SCAN_ALL=0
+ nonInteractive=1
+ install_sysctl_shim
+ . "$SHARE/geom.subr" || atf_fail "load geom.subr"
+}
+
+check_providers()
+{
+ local id struct got
+
+ for id in $provider_ids; do
+ struct=
+ f_geom_find_by id "$id" provider struct ||
+ atf_fail "provider $id not found"
+ got=
+ $struct get id got || atf_fail "$struct has no id"
+ [ "$got" = "$id" ] ||
+ atf_fail "provider $id is [$got]"
+ done
+}
+
+# check_names $n
+#
+# Resolve every DEV geom by name
+#
+check_names()
+{
+ local n="$1"
+ local i name id struct got
+
+ i=1
+ while [ "$i" -le "$n" ]; do
+ name=ada$(( $i - 1 ))
+ id=$( xid $DEV_GEOM_BASE "$i" )
+ struct=
+ f_geom_find "$name" $GEOM_CLASS_DEV struct ||
+ atf_fail "geom $name not found"
+ got=
+ $struct get id got || atf_fail "$struct has no id"
+ [ "$got" = "$id" ] ||
+ atf_fail "geom $name id is [$got]"
+ i=$(( $i + 1 ))
+ done
+}
+
+# time_lookups $n $kind
+#
+# Print seconds spent resolving every provider id ($kind = id) or
+# every DEV geom by name ($kind = name)
+#
+time_lookups()
+{
+ local n="$1" kind="$2"
+ local start end
+
+ mesh_write mesh.xml "$n"
+ GEOM_MESH=$PWD/mesh.xml
+ export GEOM_MESH
+ f_geom_get_all || atf_fail "f_geom_get_all"
+ start=$( date "+%s.%N" )
+ case "$kind" in
+ id) check_providers ;;
+ name) check_names "$n" ;;
+ *) atf_fail "kind $kind"
+ esac
+ end=$( date "+%s.%N" )
+ awk -v a="$start" -v b="$end" 'BEGIN { printf "%.4f\n", b - a }'
+}
+
+run_size()
+{
+ local n="$1" kind="$2"
+ local seconds label
+
+ prepare
+ seconds=$( time_lookups "$n" "$kind" ) || atf_fail "time"
+ case "$kind" in
+ id) label=lookups ;;
+ name) label=name_lookups ;;
+ *) atf_fail "kind $kind"
+ esac
+ printf "n=%s %s=%s\n" "$n" "$label" "$seconds"
+}
+
+# mesh_write_special $file
+#
+# Names that are not shell identifiers, plus one shared name
+#
+mesh_write_special()
+{
+ local file="$1"
+
+ printf "%s\n" \
+ "<mesh>" \
+ "<class id=\"0x10\">" \
+ "<name>DEV</name>" \
+ "<geom id=\"0x10001\">" \
+ "<name>ada0.eli</name>" \
+ "</geom>" \
+ "<geom id=\"0x10002\">" \
+ "<name>gpt/root</name>" \
+ "</geom>" \
+ "<geom id=\"0x10003\">" \
+ "<name>gptid/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee</name>" \
+ "</geom>" \
+ "</class>" \
+ "<class id=\"0x20\">" \
+ "<name>DISK</name>" \
+ "<geom id=\"0x30001\">" \
+ "<name>gpt/root</name>" \
+ "</geom>" \
+ "</class>" \
+ "</mesh>" > "$file"
+}
+
+# expect_name $name $class $id
+#
+# The DEV or DISK geom of this name has this id
+#
+expect_name()
+{
+ local name="$1" class="$2" id="$3"
+ local struct got
+
+ struct=
+ f_geom_find "$name" "$class" struct ||
+ atf_fail "geom $name not found"
+ got=
+ $struct get id got || atf_fail "$struct has no id"
+ [ "$got" = "$id" ] || atf_fail "geom $name id is [$got]"
+}
+
+atf_test_case lookups_100
+lookups_100_head()
+{
+ atf_set "descr" "Time f_geom_find_by id for 100 disks"
+}
+lookups_100_body()
+{
+ run_size 100 id
+}
+
+atf_test_case lookups_200
+lookups_200_head()
+{
+ atf_set "descr" "Time f_geom_find_by id for 200 disks"
+}
+lookups_200_body()
+{
+ run_size 200 id
+}
+
+atf_test_case name_lookups_100
+name_lookups_100_head()
+{
+ atf_set "descr" "Time f_geom_find name for 100 disks"
+}
+name_lookups_100_body()
+{
+ run_size 100 name
+}
+
+atf_test_case name_lookups_200
+name_lookups_200_head()
+{
+ atf_set "descr" "Time f_geom_find name for 200 disks"
+}
+name_lookups_200_body()
+{
+ run_size 200 name
+}
+
+atf_test_case name_chars
+name_chars_head()
+{
+ atf_set "descr" "Resolve geom names that are not shell identifiers"
+}
+name_chars_body()
+{
+ local struct n
+
+ prepare
+ mesh_write_special mesh.xml
+ GEOM_MESH=$PWD/mesh.xml
+ export GEOM_MESH
+ f_geom_get_all || atf_fail "f_geom_get_all"
+ expect_name "ada0.eli" "$GEOM_CLASS_DEV" 0x10001
+ expect_name "gpt/root" "$GEOM_CLASS_DEV" 0x10002
+ expect_name "gpt/root" "$GEOM_CLASS_DISK" 0x30001
+ expect_name "gptid/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" \
+ "$GEOM_CLASS_DEV" 0x10003
+ struct=
+ f_geom_find "gpt/root" "$GEOM_CLASS_ANY" struct ||
+ atf_fail "gpt/root any"
+ [ "$struct" = "geom_class_1_geom_2 geom_class_2_geom_1" ] ||
+ atf_fail "gpt/root any is [$struct]"
+ struct=sentinel
+ f_geom_find "no/such" $GEOM_CLASS_DEV struct &&
+ atf_fail "no/such found"
+ [ ! "$struct" ] || atf_fail "no/such is [$struct]"
+ f_geom_find "" $GEOM_CLASS_DEV struct || atf_fail "list"
+ n=0
+ for struct in $struct; do
+ n=$(( $n + 1 ))
+ done
+ [ "$n" -eq 3 ] || atf_fail "DEV list count $n"
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case lookups_100
+ atf_add_test_case lookups_200
+ atf_add_test_case name_lookups_100
+ atf_add_test_case name_lookups_200
+ atf_add_test_case name_chars
+}