Skip to content

Commit

Permalink
dracut-install: add weak dependencies support
Browse files Browse the repository at this point in the history
It has been seen that for some network mac drivers (i.e. lan78xx) the
related module for the phy is loaded dynamically depending on the current
hardware. In this case, the associated phy is read using mdio bus and then
the associated phy module is loaded during runtime (kernel function
phy_request_driver_module). However, no software dependency is defined, so
the user tools will no be able to get this dependency. For example, if
dracut is used and the hardware is present, lan78xx will be included but no
phy module will be added, and in the next restart the device will not work
from boot because no related phy will be found during initramfs stage.

In order to solve this, we could define a normal 'pre' software dependency
in lan78xx module with all the possible phy modules (there may be some),
but proceeding in that way, all the possible phy modules would be loaded
while only one is necessary.

So, a new type of dependency has been created, that we are going to call
'weak' to be used only by the user tools that need to detect this situation.
In that way, for example, dracut could check the 'weak' dependency of the
modules involved in order to install these dependencies in initramfs too.
That is, for the commented lan78xx module, defining the 'weak' dependency
with the possible phy modules list, only the necessary phy would be loaded
on demand keeping the same behavior, but all the possible phy modules would
be available from initramfs.

The 'weak' dependency support has been already included in kmod:
kmod-project/kmod@05828b4
And in kernel:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/commit/?h=modules-next&id=1f3dacc0dcef6681c2acf5890e018012f6b53085
After these, 'weak' dependencies for modules will start to appear.
Read the possible weak dependencies from dracut in order to take them into
account.

Signed-off-by: Jose Ignacio Tornos Martinez <[email protected]>
  • Loading branch information
jtornosm committed Jun 28, 2024
1 parent 5d2bda4 commit 4a59f9f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/install/dracut-install.c
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,7 @@ static int install_dependent_module(struct kmod_ctx *ctx, struct kmod_module *mo
_cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
_cleanup_kmod_module_unref_list_ struct kmod_list *modpre = NULL;
_cleanup_kmod_module_unref_list_ struct kmod_list *modpost = NULL;
_cleanup_kmod_module_unref_list_ struct kmod_list *modweak = NULL;
log_debug("dracut_install '%s' '%s' OK", path, &path[kerneldirlen]);
install_firmware(mod);
modlist = kmod_module_get_dependencies(mod);
Expand All @@ -1651,6 +1652,9 @@ static int install_dependent_module(struct kmod_ctx *ctx, struct kmod_module *mo
r = install_dependent_modules(ctx, modpost, NULL);
*err = *err ? : r;
}
*err = kmod_module_get_weakdeps(mod, &modweak);
if (*err == 0)
*err = install_dependent_modules(ctx, modweak, NULL);
}
} else {
log_error("dracut_install '%s' '%s' ERROR", path, &path[kerneldirlen]);
Expand Down Expand Up @@ -1710,6 +1714,7 @@ static int install_module(struct kmod_ctx *ctx, struct kmod_module *mod)
_cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
_cleanup_kmod_module_unref_list_ struct kmod_list *modpre = NULL;
_cleanup_kmod_module_unref_list_ struct kmod_list *modpost = NULL;
_cleanup_kmod_module_unref_list_ struct kmod_list *modweak = NULL;
const char *path = NULL;
const char *name = NULL;

Expand Down Expand Up @@ -1766,6 +1771,9 @@ static int install_module(struct kmod_ctx *ctx, struct kmod_module *mod)
r = install_dependent_modules(ctx, modpost, NULL);
ret = ret ? : r;
}
ret = kmod_module_get_weakdeps(mod, &modweak);
if (ret == 0)
ret = install_dependent_modules(ctx, modweak, NULL);
}

return ret;
Expand Down

0 comments on commit 4a59f9f

Please sign in to comment.