Date: Wed, 08 Apr 2026 12:50:10 +0000 From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: bf0881060ecd - main - lualoader: allow the local module to filter out the BE list Message-ID: <69d64f02.32959.4abb16e1@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=bf0881060ecd75ce79683b82ebcd4809eadf7cf5 commit bf0881060ecd75ce79683b82ebcd4809eadf7cf5 Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2026-04-08 12:49:18 +0000 Commit: Kyle Evans <kevans@FreeBSD.org> CommitDate: 2026-04-08 12:49:58 +0000 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 Differential Revision: https://reviews.freebsd.org/D55359 --- stand/lua/core.lua | 20 ++++++++++++++++++-- stand/lua/core.lua.8 | 13 ++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/stand/lua/core.lua b/stand/lua/core.lua index 92cbd20b25a0..471e579619c7 100644 --- a/stand/lua/core.lua +++ b/stand/lua/core.lua @@ -305,6 +305,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 = {} @@ -332,11 +341,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 diff --git a/stand/lua/core.lua.8 b/stand/lua/core.lua.8 index de43d3e2b220..325320b2fce8 100644 --- a/stand/lua/core.lua.8 +++ b/stand/lua/core.lua.8 @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd March 29, 2025 +.Dd April 8, 2026 .Dt CORE.LUA 8 .Os .Sh NAME @@ -164,6 +164,17 @@ is set in kernels will be autodetected from the current system. .It Fn core.bootenvDefault Returns the default boot environment, nil if unset. +.It Fn core.bootenvFilter func +Installs a filter +.Fa func +into +.Fn core.bootenvList . +If the +.Fa func +returns true, then the boot environment is retained in the list. +Otherwise, the boot environment is hidden. +The old filter, if any, is returned to allow the caller to compose a filter on +top of another filter. .It Fn core.bootenvList Returns a table of boot environments, or an empty table. These will be picked up using thehome | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69d64f02.32959.4abb16e1>
