From owner-svn-src-all@freebsd.org Sat Dec 12 07:35:20 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5308C4ABDAD for ; Sat, 12 Dec 2020 07:35:20 +0000 (UTC) (envelope-from tsoome@me.com) Received: from pv50p00im-zteg10021301.me.com (pv50p00im-zteg10021301.me.com [17.58.6.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4CtKF415T7z4ZkL for ; Sat, 12 Dec 2020 07:35:19 +0000 (UTC) (envelope-from tsoome@me.com) Received: from nazgul.lan (148-52-235-80.sta.estpak.ee [80.235.52.148]) by pv50p00im-zteg10021301.me.com (Postfix) with ESMTPSA id B2EEECC02C1; Sat, 12 Dec 2020 07:35:11 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.20.0.2.21\)) Subject: Re: svn commit: r368575 - head/stand/lua From: Toomas Soome In-Reply-To: <202012120557.0BC5vgeL098066@repo.freebsd.org> Date: Sat, 12 Dec 2020 09:35:09 +0200 Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: <7FF23CBA-9BF0-4948-B967-0A2CD859A3BB@me.com> References: <202012120557.0BC5vgeL098066@repo.freebsd.org> To: Kyle Evans X-Mailer: Apple Mail (2.3654.20.0.2.21) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-12_02:2020-12-11, 2020-12-12 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2006250000 definitions=main-2012120058 X-Rspamd-Queue-Id: 4CtKF415T7z4ZkL X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Dec 2020 07:35:20 -0000 How about =E2=80=99show-module-options=E2=80=99?=20 rgds, toomas > On 12. Dec 2020, at 07:57, Kyle Evans wrote: >=20 > Author: kevans > Date: Sat Dec 12 05:57:42 2020 > New Revision: 368575 > URL: https://svnweb.freebsd.org/changeset/base/368575 >=20 > Log: > lualoader: provide module-manipulation commands >=20 > Specifically, we have: > - enable-module > - disable-module > - toggle-module >=20 > 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. >=20 > MFC after: 1 week >=20 > Modified: > head/stand/lua/cli.lua > head/stand/lua/cli.lua.8 > head/stand/lua/config.lua > head/stand/lua/config.lua.8 >=20 > Modified: head/stand/lua/cli.lua > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- head/stand/lua/cli.lua Sat Dec 12 02:26:43 2020 = (r368574) > +++ head/stand/lua/cli.lua Sat Dec 12 05:57:42 2020 = (r368575) > @@ -65,6 +65,14 @@ local function parseBootArgs(argv, with_kernel) > end > end >=20 > +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 > -- arguments passed as a lua function. This gives lua a chance to = intercept > -- builtin CLI commands like "boot" > @@ -132,6 +140,37 @@ end >=20 > cli['reload-conf'] =3D function() > config.reload() > +end > + > +cli["enable-module"] =3D function(...) > + local _, argv =3D cli.arguments(...) > + if #argv =3D=3D 0 then > + print("usage error: enable-module module") > + return > + end > + > + setModule(argv[1], true) > +end > + > +cli["disable-module"] =3D function(...) > + local _, argv =3D cli.arguments(...) > + if #argv =3D=3D 0 then > + print("usage error: disable-module module") > + return > + end > + > + setModule(argv[1], false) > +end > + > +cli["toggle-module"] =3D function(...) > + local _, argv =3D cli.arguments(...) > + if #argv =3D=3D 0 then > + print("usage error: toggle-module module") > + return > + end > + > + local module =3D argv[1] > + setModule(module, not config.isModuleEnabled(module)) > end >=20 > -- Used for splitting cli varargs into cmd_name and the rest of argv >=20 > Modified: head/stand/lua/cli.lua.8 > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- head/stand/lua/cli.lua.8 Sat Dec 12 02:26:43 2020 = (r368574) > +++ head/stand/lua/cli.lua.8 Sat Dec 12 05:57:42 2020 = (r368575) > @@ -26,7 +26,7 @@ > .\" > .\" $FreeBSD$ > .\" > -.Dd September 13, 2019 > +.Dd December 12, 2020 > .Dt CLI.LUA 8 > .Os > .Sh NAME > @@ -77,14 +77,26 @@ This function may be invoked by a user at the = loader p > .Ic foo . > Arguments may be passed to it as usual, space-delimited. > .Ss Default Commands > -As of present, the > +The > .Nm > -module by default provides commands for > -.Ic autoboot , > -.Ic boot , > -.Ic boot-conf , > -and > -.Ic reload-conf . > +module provides the following default commands: > +.Bl -bullet > +.\"-width toggle-module -offset indent > +.It > +.Ic autoboot > +.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 > For > .Ic autoboot , > @@ -103,6 +115,16 @@ The > command will reload the configuration from disk. > This is useful if you have manually changed currdev and would like to = easily > 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 > The following functions are exported from > .Nm : >=20 > Modified: head/stand/lua/config.lua > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- head/stand/lua/config.lua Sat Dec 12 02:26:43 2020 = (r368574) > +++ head/stand/lua/config.lua Sat Dec 12 05:57:42 2020 = (r368575) > @@ -312,7 +312,7 @@ local function loadModule(mod, silent) > for k, v in pairs(mod) do > if v.load ~=3D nil and v.load:lower() =3D=3D "yes" then > local module_name =3D v.name or k > - if blacklist[module_name] ~=3D nil then > + if not v.force and blacklist[module_name] ~=3D = nil then > if not silent then > = print(MSG_MODBLACKLIST:format(module_name)) > end > @@ -680,6 +680,45 @@ function config.loadelf() > status =3D loadModule(modules, not config.verbose) > hook.runAll("modules.loaded") > return status > +end > + > +function config.enableModule(modname) > + if modules[modname] =3D=3D nil then > + modules[modname] =3D {} > + elseif modules[modname].load =3D=3D "YES" then > + modules[modname].force =3D true > + return true > + end > + > + modules[modname].load =3D "YES" > + modules[modname].force =3D true > + return true > +end > + > +function config.disableModule(modname) > + if modules[modname] =3D=3D nil then > + return false > + elseif modules[modname].load ~=3D "YES" then > + return true > + end > + > + modules[modname].load =3D "NO" > + modules[modname].force =3D nil > + return true > +end > + > +function config.isModuleEnabled(modname) > + local mod =3D modules[modname] > + if not mod or mod.load ~=3D "YES" then > + return false > + end > + > + if mod.force then > + return true > + end > + > + local blacklist =3D getBlacklist() > + return blacklist[modname] > end >=20 > hook.registerType("config.loaded") >=20 > Modified: head/stand/lua/config.lua.8 > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- head/stand/lua/config.lua.8 Sat Dec 12 02:26:43 2020 = (r368574) > +++ head/stand/lua/config.lua.8 Sat Dec 12 05:57:42 2020 = (r368575) > @@ -26,7 +26,7 @@ > .\" > .\" $FreeBSD$ > .\" > -.Dd April 30, 2020 > +.Dd December 12, 2020 > .Dt CONFIG.LUA 8 > .Os > .Sh NAME > @@ -184,6 +184,25 @@ This will be called by the Lua intercepted > and > .Ic boot > 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 > .Ss Defined Hooks > The following hooks are defined in