Skip to content

Commit 8d456c1

Browse files
committed
return module name when processing module, in case an alias was resolved
Signed-off-by: Zen <[email protected]>
1 parent cfb8d98 commit 8d456c1

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/ugrd/kmod/kmod.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "desultory"
2-
__version__ = "4.0.0"
2+
__version__ = "4.1.0"
33

44
from pathlib import Path
55
from platform import uname
@@ -52,7 +52,7 @@ def _resolve_kmod_alias(self, module: str) -> str:
5252
module = module.replace("_", "[_-]") # Allow for both _ and - in the module name
5353
for alias, kmod in _KMOD_ALIASES.items():
5454
if search(module, alias):
55-
self.logger.debug(f"Resolved kernel module alias: {c_(alias, 'green')} -> {c_(kmod, 'cyan')}")
55+
self.logger.info(f"Resolved kernel module alias: {c_(alias, 'blue')} -> {c_(kmod, 'cyan')}")
5656
return kmod
5757

5858
raise MissingModuleError(f"Failed to resolve kernel module alias: {module}")
@@ -120,7 +120,7 @@ def _get_kmod_info(self, module: str) -> dict:
120120
"""
121121
module = _normalize_kmod_name(self, module)
122122
if module in self["_kmod_modinfo"]:
123-
return self["_kmod_modinfo"][module]
123+
return module, self["_kmod_modinfo"][module]
124124
args = ["modinfo", module, "--set-version", self["kernel_version"]]
125125

126126
try:
@@ -163,7 +163,7 @@ def _get_kmod_info(self, module: str) -> dict:
163163

164164
self.logger.debug("[%s] Module info: %s" % (module, module_info))
165165
self["_kmod_modinfo"][module] = module_info
166-
return module_info
166+
return module, module_info
167167

168168

169169
@unset("no_kmod", "no_kmod is enabled, skipping module alias enumeration.", log_level=30)
@@ -395,7 +395,7 @@ def _add_kmod_firmware(self, kmod: str) -> None:
395395
Attempts to run even if no_kmod is set; this will not work if there are no kmods/no kernel version set
396396
"""
397397
try:
398-
modinfo = _get_kmod_info(self, kmod)
398+
kmod, modinfo = _get_kmod_info(self, kmod)
399399
except DependencyResolutionError as e:
400400
if self["no_kmod"]:
401401
return self.logger.warning(
@@ -441,9 +441,11 @@ def _process_kmod_dependencies(self, kmod: str, mod_tree=None) -> None:
441441
442442
Iterate over dependencies, adding them to kernel_mdules if they (or sub-dependencies) are not in the ignore list.
443443
If the dependency is already in the module tree, skip it to prevent infinite recursion.
444+
445+
returns the name of the kernel module (in case it was an alias) and the list of dependencies.
444446
"""
445447
mod_tree = mod_tree or set()
446-
modinfo = _get_kmod_info(self, kmod)
448+
kmod, modinfo = _get_kmod_info(self, kmod)
447449

448450
# Get kernel module dependencies, softedeps if not ignored
449451
dependencies = []
@@ -462,7 +464,7 @@ def _process_kmod_dependencies(self, kmod: str, mod_tree=None) -> None:
462464
if dependency in mod_tree:
463465
self.logger.debug("[%s] Dependency is already in mod_tree: %s" % (kmod, dependency))
464466
continue
465-
dep_modinfo = _get_kmod_info(self, dependency) # Get modinfo for the dependency
467+
dependency, dep_modinfo = _get_kmod_info(self, dependency) # Get modinfo for the dependency
466468
if dependency in self["kmod_ignore"]: # Don't add modules with ignored dependencies
467469
if dep_modinfo["filename"] == "(builtin)":
468470
self.logger.debug("[%s] Ignored dependency is a built-in module: %s" % (kmod, dependency))
@@ -485,6 +487,8 @@ def _process_kmod_dependencies(self, kmod: str, mod_tree=None) -> None:
485487
_add_kmod_firmware(self, kmod)
486488
raise BuiltinModuleError("Not adding built-in module to dependencies: %s" % kmod)
487489

490+
return kmod, dependencies
491+
488492

489493
def add_kmod_deps(self):
490494
"""Adds all kernel modules to the initramfs dependencies.
@@ -503,7 +507,7 @@ def add_kmod_deps(self):
503507
continue
504508

505509
# Add the kmod file to the initramfs dependenceis
506-
modinfo = _get_kmod_info(self, kmod)
510+
kmod, modinfo = _get_kmod_info(self, kmod)
507511
filename = modinfo["filename"]
508512
if filename.endswith(".ko"):
509513
self["dependencies"] = filename
@@ -525,7 +529,7 @@ def process_ignored_module(self, module: str) -> None:
525529
if module in self[key]:
526530
if key == "kmod_init":
527531
try:
528-
modinfo = _get_kmod_info(self, module)
532+
module, modinfo = _get_kmod_info(self, module)
529533
if modinfo["filename"] == "(builtin)":
530534
self.logger.debug("Removing built-in module from kmod_init: %s" % module)
531535
except DependencyResolutionError:
@@ -556,7 +560,7 @@ def _process_optional_modules(self) -> None:
556560
self.logger.debug(f"Optional kmod_init module is already in kmod_init: {c_(kmod, 'yellow', bold=True)}")
557561
continue
558562
try:
559-
_process_kmod_dependencies(self, kmod)
563+
kmod, dependencies = _process_kmod_dependencies(self, kmod)
560564
self["kmod_init"] = kmod # add to kmod_init so it will be loaded
561565
except IgnoredModuleError as e:
562566
self.logger.warning(e)
@@ -607,8 +611,8 @@ def process_modules(self) -> None:
607611
continue
608612
self.logger.debug("Processing autodetected kernel module: %s" % kmod)
609613
try:
610-
_process_kmod_dependencies(self, kmod)
611-
self["kmod_init"] = kmod
614+
kmod_name, dependencies = _process_kmod_dependencies(self, kmod)
615+
self["kmod_init"] = kmod_name
612616
continue
613617
except BuiltinModuleError:
614618
continue # Don't add built-in modules to the ignore list

0 commit comments

Comments
 (0)