ab0e4d
From 73242b75af92bc86c26cfbe2954b7ecb9aaaf765 Mon Sep 17 00:00:00 2001
ab0e4d
From: Harald Hoyer <harald@redhat.com>
ab0e4d
Date: Tue, 4 Dec 2018 10:02:45 +0100
ab0e4d
Subject: [PATCH] install/dracut-install.c: install module dependencies of
ab0e4d
 dependencies
ab0e4d
ab0e4d
(cherry picked from commit c38f9e980c1ee03151dd1c6602907c6228b78d30)
ab0e4d
ab0e4d
Resolves: #1846343
ab0e4d
---
ab0e4d
 install/dracut-install.c | 28 +++++++++++++++++++++++++---
ab0e4d
 1 file changed, 25 insertions(+), 3 deletions(-)
ab0e4d
ab0e4d
diff --git a/install/dracut-install.c b/install/dracut-install.c
ab0e4d
index 88bca1d4..253ae194 100644
ab0e4d
--- a/install/dracut-install.c
ab0e4d
+++ b/install/dracut-install.c
ab0e4d
@@ -84,6 +84,11 @@ static bool arg_mod_filter_noname = false;
ab0e4d
 static int dracut_install(const char *src, const char *dst, bool isdir, bool resolvedeps, bool hashdst);
ab0e4d
 
ab0e4d
 
ab0e4d
+static inline void kmod_module_unrefp(struct kmod_module **p) {
ab0e4d
+        if (*p)
ab0e4d
+                kmod_module_unref(*p);
ab0e4d
+}
ab0e4d
+#define _cleanup_kmod_module_unref_ _cleanup_(kmod_module_unrefp)
ab0e4d
 
ab0e4d
 static inline void kmod_module_unref_listp(struct kmod_list **p) {
ab0e4d
         if (*p)
ab0e4d
@@ -1234,28 +1239,45 @@ static bool check_module_path(const char *path)
ab0e4d
 static int install_dependent_modules(struct kmod_list *modlist)
ab0e4d
 {
ab0e4d
         struct kmod_list *itr;
ab0e4d
-        struct kmod_module *mod;
ab0e4d
         const char *path = NULL;
ab0e4d
         const char *name = NULL;
ab0e4d
         int ret = 0;
ab0e4d
 
ab0e4d
         kmod_list_foreach(itr, modlist) {
ab0e4d
+		_cleanup_kmod_module_unref_ struct kmod_module *mod = NULL;
ab0e4d
                 mod = kmod_module_get_module(itr);
ab0e4d
                 path = kmod_module_get_path(mod);
ab0e4d
 
ab0e4d
+		if (check_hashmap(items_failed, path))
ab0e4d
+			return -1;
ab0e4d
+
ab0e4d
+		if (check_hashmap(items, path)) {
ab0e4d
+			continue;
ab0e4d
+		}
ab0e4d
+
ab0e4d
                 name = kmod_module_get_name(mod);
ab0e4d
+
ab0e4d
                 if ((path == NULL) || (arg_mod_filter_noname && (regexec(&mod_filter_noname, name, 0, NULL, 0) == 0))) {
ab0e4d
-                        kmod_module_unref(mod);
ab0e4d
                         continue;
ab0e4d
                 }
ab0e4d
+
ab0e4d
                 ret = dracut_install(path, &path[kerneldirlen], false, false, true);
ab0e4d
                 if (ret == 0) {
ab0e4d
+			_cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
ab0e4d
+			_cleanup_kmod_module_unref_list_ struct kmod_list *modpre = NULL;
ab0e4d
+			_cleanup_kmod_module_unref_list_ struct kmod_list *modpost = NULL;
ab0e4d
                         log_debug("dracut_install '%s' '%s' OK", path, &path[kerneldirlen]);
ab0e4d
                         install_firmware(mod);
ab0e4d
+			modlist = kmod_module_get_dependencies(mod);
ab0e4d
+			ret = install_dependent_modules(modlist);
ab0e4d
+			if (ret == 0) {
ab0e4d
+				ret = kmod_module_get_softdeps(mod, &modpre, &modpost);
ab0e4d
+				if (ret == 0)
ab0e4d
+					ret = install_dependent_modules(modpre);
ab0e4d
+			}
ab0e4d
                 } else {
ab0e4d
                         log_error("dracut_install '%s' '%s' ERROR", path, &path[kerneldirlen]);
ab0e4d
                 }
ab0e4d
-                kmod_module_unref(mod);
ab0e4d
         }
ab0e4d
 
ab0e4d
         return ret;
ab0e4d