Rework module-list settings to use globs instead of regexps
"If you have a problem, and use a regexp, now you have two problems."
I don't think this quip applies in all cases, but the existing interface with
regexps was problematic for a few reasons:
- users usually want to match at a word boundary, but regexps apply anywhere in
the string, so to actually match correctly, the regexp has to be carefully
constructed with word boundary assertions.
Even our own config for initrds included some modules by mistake,
e.g. drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/ch_ipsec.ko.xz
was matched by crypto/.
- once the regexps include the word boundary assertions, they became quite
complex and hard to read.
- because of the separate evaluation of include and exlude patterns, we
need to have exclude patterns in the include patterns. The example given
in the review:
^drivers/net/(?!wireless/)
But this means that we can do exclusions in two places, making the whole
scheme very complex.
- the default to include all modules by default goes against the general
design of mkosi, where only things that are explicitly configured are
put in the image. That default is only useful when trying to build a
"maximal" image that matches the current machine. In most uses, the
default of including only requested modules makes more sense (initrd,
addons, any not-host-only images).
A new setting that takes glob patterns is added. There is only one setting
instead of a pair, exclusion patterns are prefixed by '-'. The last matching
glob wins. The details of how those globs are interpreted is crafted to
match our particular use cases.
For a single glob, the rules are:
- 'foo' matches the basename, /some/path/foo.ko
- 'bar/foo' matches the last component of the path, bar/foo.ko
- '/full/path/bar' only matches /full/path/bar.ko.
- crypto/* or crypto/ match all modules any crypto/ directory.
- /crypto/* matches the modules in the top-level directory.
This might seem complicated at first glance, but apart from the special
handling of the suffix, those rules mostly match how 'ls' would handle
a local path argument.
Suffixes are not specified in the globs. '-' and '_' are treated as equivalent,
except when part of special glob syntax with […].
New settings are added:
KernelModules=GLOB
KernelInitrdModules=GLOB
(KernelModulesInitrd=BOOL already exists and specifies whether to create a
separate initrd.)
I think the new syntax is more pleasant to read and write. Backward
compatibility is maintained by keeping the old options in place. The change to
exclude all modules by default is a breaking change, but in most uses both
options were used in combination anyway, so I think this should be fine.
The example given in the review:
KernelModulesInclude=
^drivers/net/(?!wireless/)
becomes
KernelModules=
/drivers/net/
-/drivers/net/wireless/