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