lualoader: Cache kernel list

With autodetection turned on, hitting the filesystem everytime we need to
calculate choices for the kernel carousel is kind of slow. Cache once on the
first listing and reload it anytime the config is reloaded in case any of
the loader.conf(5) changes that affect this (kernel, kernels,
kernels_autodetect) have changed. This also picks up the case where we've
changed currdev and the autodetected kernels could change.
This commit is contained in:
Kyle Evans 2018-03-09 19:04:06 +00:00
parent 7fe5130df9
commit 35b0c718d3
2 changed files with 16 additions and 2 deletions

View File

@ -497,6 +497,7 @@ function config.reload(file)
modules = {}
config.restoreEnv()
config.load(file)
core.configReloaded()
end
function config.loadelf()

View File

@ -138,7 +138,18 @@ function core.setSafeMode(safe_mode)
core.sm = safe_mode
end
function core.configReloaded()
-- Clear the kernel cache on config changes, autodetect might have
-- changed or if we've switched boot environments then we could have
-- a new kernel set.
core.cached_kernels = nil
end
function core.kernelList()
if core.cached_kernels ~= nil then
return core.cached_kernels
end
local k = loader.getenv("kernel")
local v = loader.getenv("kernels")
local autodetect = loader.getenv("kernels_autodetect") or ""
@ -166,7 +177,8 @@ function core.kernelList()
-- setting, kernels_autodetect. If it's set to 'yes', we'll add
-- any kernels we detect based on the criteria described.
if autodetect:lower() ~= "yes" then
return kernels
core.cached_kernels = kernels
return core.cached_kernels
end
-- Automatically detect other bootable kernel directories using a
@ -195,7 +207,8 @@ function core.kernelList()
::continue::
end
return kernels
core.cached_kernels = kernels
return core.cached_kernels
end
function core.bootenvDefault()