From: Adrien Thierry Date: Mon, 14 Nov 2022 16:13:57 +0000 (-0500) Subject: refactor(dracut-install): add function to install one dependent module X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=8ea8cf5f56df2e2808863188450488835c17e59d;p=thirdparty%2Fdracut.git refactor(dracut-install): add function to install one dependent module This is prep work for adding support for fw_devlink suppliers dependencies. Signed-off-by: Adrien Thierry --- diff --git a/src/install/dracut-install.c b/src/install/dracut-install.c index 7d145f3d7..b008614f9 100644 --- a/src/install/dracut-install.c +++ b/src/install/dracut-install.c @@ -94,6 +94,7 @@ static bool arg_mod_filter_nosymbol = false; static bool arg_mod_filter_noname = false; static int dracut_install(const char *src, const char *dst, bool isdir, bool resolvedeps, bool hashdst); +static int install_dependent_modules(struct kmod_list *modlist); static inline void kmod_module_unrefp(struct kmod_module **p) { @@ -1486,55 +1487,64 @@ static bool check_module_path(const char *path) return true; } -static int install_dependent_modules(struct kmod_list *modlist) +static int install_dependent_module(struct kmod_module *mod, int *err) { - struct kmod_list *itr = NULL; const char *path = NULL; const char *name = NULL; - int ret = 0; - kmod_list_foreach(itr, modlist) { - _cleanup_kmod_module_unref_ struct kmod_module *mod = NULL; - mod = kmod_module_get_module(itr); - path = kmod_module_get_path(mod); + path = kmod_module_get_path(mod); - if (path == NULL) - continue; + if (path == NULL) + return 0; - if (check_hashmap(items_failed, path)) - return -1; + if (check_hashmap(items_failed, path)) + return -1; - if (check_hashmap(items, &path[kerneldirlen])) { - continue; - } + if (check_hashmap(items, &path[kerneldirlen])) { + return 0; + } - name = kmod_module_get_name(mod); + name = kmod_module_get_name(mod); - if (arg_mod_filter_noname && (regexec(&mod_filter_noname, name, 0, NULL, 0) == 0)) { - continue; - } + if (arg_mod_filter_noname && (regexec(&mod_filter_noname, name, 0, NULL, 0) == 0)) { + return 0; + } - ret = dracut_install(path, &path[kerneldirlen], false, false, true); - if (ret == 0) { - _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; - log_debug("dracut_install '%s' '%s' OK", path, &path[kerneldirlen]); - install_firmware(mod); - modlist = kmod_module_get_dependencies(mod); - ret = install_dependent_modules(modlist); - if (ret == 0) { - ret = kmod_module_get_softdeps(mod, &modpre, &modpost); - if (ret == 0) { - int r; - ret = install_dependent_modules(modpre); - r = install_dependent_modules(modpost); - ret = ret ? : r; - } + *err = dracut_install(path, &path[kerneldirlen], false, false, true); + if (*err == 0) { + _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; + log_debug("dracut_install '%s' '%s' OK", path, &path[kerneldirlen]); + install_firmware(mod); + modlist = kmod_module_get_dependencies(mod); + *err = install_dependent_modules(modlist); + if (*err == 0) { + *err = kmod_module_get_softdeps(mod, &modpre, &modpost); + if (*err == 0) { + int r; + *err = install_dependent_modules(modpre); + r = install_dependent_modules(modpost); + *err = *err ? : r; } - } else { - log_error("dracut_install '%s' '%s' ERROR", path, &path[kerneldirlen]); } + } else { + log_error("dracut_install '%s' '%s' ERROR", path, &path[kerneldirlen]); + } + + return 0; +} + +static int install_dependent_modules(struct kmod_list *modlist) +{ + struct kmod_list *itr = NULL; + int ret = 0; + + kmod_list_foreach(itr, modlist) { + _cleanup_kmod_module_unref_ struct kmod_module *mod = NULL; + mod = kmod_module_get_module(itr); + if (install_dependent_module(mod, &ret)) + return -1; } return ret;