lualoader: provide module-manipulation commands
Specifically, we have: - enable-module - disable-module - toggle-module These can be used to add/remove modules to be loaded or force modules to be loaded in spite of modules_blacklist. In the typical case, a user is expected to use them to recover an issue happening due to a module directive they've added to their loader.conf or because they discover that they've under-specified what to load. MFC after: 1 week
This commit is contained in:
parent
dd1ce6c7f1
commit
4634bb1f40
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=368575
@ -65,6 +65,14 @@ local function parseBootArgs(argv, with_kernel)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function setModule(module, loading)
|
||||||
|
if loading and config.enableModule(module) then
|
||||||
|
print(module .. " will be loaded")
|
||||||
|
elseif not loading and config.disableModule(module) then
|
||||||
|
print(module .. " will not be loaded")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Declares a global function cli_execute that attempts to dispatch the
|
-- Declares a global function cli_execute that attempts to dispatch the
|
||||||
-- arguments passed as a lua function. This gives lua a chance to intercept
|
-- arguments passed as a lua function. This gives lua a chance to intercept
|
||||||
-- builtin CLI commands like "boot"
|
-- builtin CLI commands like "boot"
|
||||||
@ -134,6 +142,37 @@ cli['reload-conf'] = function()
|
|||||||
config.reload()
|
config.reload()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
cli["enable-module"] = function(...)
|
||||||
|
local _, argv = cli.arguments(...)
|
||||||
|
if #argv == 0 then
|
||||||
|
print("usage error: enable-module module")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
setModule(argv[1], true)
|
||||||
|
end
|
||||||
|
|
||||||
|
cli["disable-module"] = function(...)
|
||||||
|
local _, argv = cli.arguments(...)
|
||||||
|
if #argv == 0 then
|
||||||
|
print("usage error: disable-module module")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
setModule(argv[1], false)
|
||||||
|
end
|
||||||
|
|
||||||
|
cli["toggle-module"] = function(...)
|
||||||
|
local _, argv = cli.arguments(...)
|
||||||
|
if #argv == 0 then
|
||||||
|
print("usage error: toggle-module module")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local module = argv[1]
|
||||||
|
setModule(module, not config.isModuleEnabled(module))
|
||||||
|
end
|
||||||
|
|
||||||
-- Used for splitting cli varargs into cmd_name and the rest of argv
|
-- Used for splitting cli varargs into cmd_name and the rest of argv
|
||||||
function cli.arguments(...)
|
function cli.arguments(...)
|
||||||
local argv = {...}
|
local argv = {...}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd September 13, 2019
|
.Dd December 12, 2020
|
||||||
.Dt CLI.LUA 8
|
.Dt CLI.LUA 8
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -77,14 +77,26 @@ This function may be invoked by a user at the loader prompt by simply typing
|
|||||||
.Ic foo .
|
.Ic foo .
|
||||||
Arguments may be passed to it as usual, space-delimited.
|
Arguments may be passed to it as usual, space-delimited.
|
||||||
.Ss Default Commands
|
.Ss Default Commands
|
||||||
As of present, the
|
The
|
||||||
.Nm
|
.Nm
|
||||||
module by default provides commands for
|
module provides the following default commands:
|
||||||
.Ic autoboot ,
|
.Bl -bullet
|
||||||
.Ic boot ,
|
.\"-width toggle-module -offset indent
|
||||||
.Ic boot-conf ,
|
.It
|
||||||
and
|
.Ic autoboot
|
||||||
.Ic reload-conf .
|
.It
|
||||||
|
.Ic boot
|
||||||
|
.It
|
||||||
|
.Ic boot-conf
|
||||||
|
.It
|
||||||
|
.Ic reload-conf
|
||||||
|
.It
|
||||||
|
.Ic enable-module
|
||||||
|
.It
|
||||||
|
.Ic disable-module
|
||||||
|
.It
|
||||||
|
.Ic toggle-module
|
||||||
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
For
|
For
|
||||||
.Ic autoboot ,
|
.Ic autoboot ,
|
||||||
@ -103,6 +115,16 @@ The
|
|||||||
command will reload the configuration from disk.
|
command will reload the configuration from disk.
|
||||||
This is useful if you have manually changed currdev and would like to easily
|
This is useful if you have manually changed currdev and would like to easily
|
||||||
reload the configuration from the new device.
|
reload the configuration from the new device.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Ic enable-module ,
|
||||||
|
.Ic disable-module ,
|
||||||
|
and
|
||||||
|
.Ic toggle-module
|
||||||
|
commands manipulate the list of modules to be loaded along with the kernel.
|
||||||
|
Modules blacklisted are considered disabled by
|
||||||
|
.Ic toggle-module .
|
||||||
|
These commands will override any such restriction as needed.
|
||||||
.Ss Exported Functions
|
.Ss Exported Functions
|
||||||
The following functions are exported from
|
The following functions are exported from
|
||||||
.Nm :
|
.Nm :
|
||||||
|
@ -312,7 +312,7 @@ local function loadModule(mod, silent)
|
|||||||
for k, v in pairs(mod) do
|
for k, v in pairs(mod) do
|
||||||
if v.load ~= nil and v.load:lower() == "yes" then
|
if v.load ~= nil and v.load:lower() == "yes" then
|
||||||
local module_name = v.name or k
|
local module_name = v.name or k
|
||||||
if blacklist[module_name] ~= nil then
|
if not v.force and blacklist[module_name] ~= nil then
|
||||||
if not silent then
|
if not silent then
|
||||||
print(MSG_MODBLACKLIST:format(module_name))
|
print(MSG_MODBLACKLIST:format(module_name))
|
||||||
end
|
end
|
||||||
@ -682,6 +682,45 @@ function config.loadelf()
|
|||||||
return status
|
return status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function config.enableModule(modname)
|
||||||
|
if modules[modname] == nil then
|
||||||
|
modules[modname] = {}
|
||||||
|
elseif modules[modname].load == "YES" then
|
||||||
|
modules[modname].force = true
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
modules[modname].load = "YES"
|
||||||
|
modules[modname].force = true
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function config.disableModule(modname)
|
||||||
|
if modules[modname] == nil then
|
||||||
|
return false
|
||||||
|
elseif modules[modname].load ~= "YES" then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
modules[modname].load = "NO"
|
||||||
|
modules[modname].force = nil
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function config.isModuleEnabled(modname)
|
||||||
|
local mod = modules[modname]
|
||||||
|
if not mod or mod.load ~= "YES" then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if mod.force then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local blacklist = getBlacklist()
|
||||||
|
return blacklist[modname]
|
||||||
|
end
|
||||||
|
|
||||||
hook.registerType("config.loaded")
|
hook.registerType("config.loaded")
|
||||||
hook.registerType("config.reloaded")
|
hook.registerType("config.reloaded")
|
||||||
hook.registerType("kernel.loaded")
|
hook.registerType("kernel.loaded")
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd April 30, 2020
|
.Dd December 12, 2020
|
||||||
.Dt CONFIG.LUA 8
|
.Dt CONFIG.LUA 8
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -184,6 +184,25 @@ This will be called by the Lua intercepted
|
|||||||
and
|
and
|
||||||
.Ic boot
|
.Ic boot
|
||||||
commands.
|
commands.
|
||||||
|
.It Fn config.enableModule modname
|
||||||
|
Marks a module named
|
||||||
|
.Fa modname
|
||||||
|
to be loaded during
|
||||||
|
.Fn config.loadelf .
|
||||||
|
If the module was previously blacklisted, then it will be forcefully allowed to
|
||||||
|
load.
|
||||||
|
.It Fn config.disableModule modname
|
||||||
|
Marks a module named
|
||||||
|
.Fa modname
|
||||||
|
to not be loaded during
|
||||||
|
.Fn config.loadelf .
|
||||||
|
.It Fn config.isModuleEnabled modname
|
||||||
|
Checks if the module named
|
||||||
|
.Fa modname
|
||||||
|
will be loaded during
|
||||||
|
.Fn config.loadelf .
|
||||||
|
It checks both that the module is marked for loading and that it is either
|
||||||
|
forced or not blacklisted.
|
||||||
.El
|
.El
|
||||||
.Ss Defined Hooks
|
.Ss Defined Hooks
|
||||||
The following hooks are defined in
|
The following hooks are defined in
|
||||||
|
Loading…
Reference in New Issue
Block a user