aboutsummaryrefslogtreecommitdiff
path: root/stand/lua/core.lua
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2026-04-08 12:49:18 +0000
committerKyle Evans <kevans@FreeBSD.org>2026-04-13 14:43:16 +0000
commit9ef671ef0c6c50e85a35d867ef1c7890f9de91af (patch)
tree3a903e9b224938450b47ac8ada4deda406826144 /stand/lua/core.lua
parent42a8f973cb90fa40025586f083e7b13db7f81926 (diff)
lualoader: allow the local module to filter out the BE list
This allows something like the following local.lua to install a filter to implement its own notion of hidden BEs using a naming convention of a leading dot to hide them: -- file: /boot/lua/local.lua local core = require("core") local function be_hide(be) if core.isSingleUserBoot() then -- All BEs are accepted for single-user return true end local name = be:match("/([^/]+)$") if not name then -- Accept malformed BEs, for whatever reason return true end return name:match("^%.") == nil end if core.bootenvFilter then -- Just in case we need to be compatible with older versions of -- core.lua without the filtering functionality. core.bootenvFilter(be_hide) end -- EOF Requested by: Marek Zarychta Reviewed by: imp (cherry picked from commit bf0881060ecd75ce79683b82ebcd4809eadf7cf5)
Diffstat (limited to 'stand/lua/core.lua')
-rw-r--r--stand/lua/core.lua20
1 files changed, 18 insertions, 2 deletions
diff --git a/stand/lua/core.lua b/stand/lua/core.lua
index ccd8213a718d..4091f446e1f1 100644
--- a/stand/lua/core.lua
+++ b/stand/lua/core.lua
@@ -303,6 +303,15 @@ function core.bootenvDefault()
return loader.getenv("zfs_be_active")
end
+function core.bootenvFilter(func)
+ local oldf = core.bootenv_filter
+
+ -- Filter contract: returns true if the BE should be kept, false if it
+ -- should be hidden.
+ core.bootenv_filter = func
+ return oldf
+end
+
function core.bootenvList()
local bootenv_count = tonumber(loader.getenv(bootenv_list .. "_count"))
local bootenvs = {}
@@ -330,11 +339,18 @@ function core.bootenvList()
for curenv_idx = 0, bootenv_count - 1 do
curenv = loader.getenv(bootenv_list .. "[" .. curenv_idx .. "]")
if curenv ~= nil and unique[curenv] == nil then
- envcount = envcount + 1
- bootenvs[envcount] = curenv
unique[curenv] = true
+
+ -- If we have a filter installed (by a local module), we
+ -- give it a chance to veto the BE.
+ if not core.bootenv_filter or
+ core.bootenv_filter(curenv) then
+ envcount = envcount + 1
+ bootenvs[envcount] = curenv
+ end
end
end
+
return bootenvs
end