Blame 0132-dracut-install-fallback-to-non-hostonly-mode-if-lsmo.patch

Harald Hoyer 53404a
From bb47ec54994e9fbac2117b8133cd328a2bb3b28f Mon Sep 17 00:00:00 2001
Harald Hoyer 53404a
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 53404a
Date: Thu, 8 Sep 2016 15:55:21 +0200
Harald Hoyer 53404a
Subject: [PATCH] dracut-install: fallback to non-hostonly mode if lsmod fails
Harald Hoyer 53404a
Harald Hoyer 53404a
if libkmod fails to get the list of loaded modules, fallback
Harald Hoyer 53404a
to non-hostonly mode, to at least try to assemble a working initrd.
Harald Hoyer 53404a
---
Harald Hoyer 53404a
 install/dracut-install.c | 58 +++++++++++++++++++++++++-----------------------
Harald Hoyer 53404a
 1 file changed, 30 insertions(+), 28 deletions(-)
Harald Hoyer 53404a
Harald Hoyer 53404a
diff --git a/install/dracut-install.c b/install/dracut-install.c
Harald Hoyer 53404a
index 0cffa39..fe30bba 100644
Harald Hoyer 53404a
--- a/install/dracut-install.c
Harald Hoyer 53404a
+++ b/install/dracut-install.c
Harald Hoyer 53404a
@@ -1288,38 +1288,40 @@ static int install_modules(int argc, char **argv)
Harald Hoyer 53404a
 
Harald Hoyer 53404a
         ctx = kmod_new(kerneldir, NULL);
Harald Hoyer 53404a
 
Harald Hoyer 53404a
-        err = kmod_module_new_from_loaded(ctx, &loaded_list);
Harald Hoyer 53404a
-        if (err < 0) {
Harald Hoyer 53404a
-                errno = err;
Harald Hoyer 53404a
-                log_error("Could not get list of loaded modules: %m");
Harald Hoyer 53404a
-                return err;
Harald Hoyer 53404a
-        }
Harald Hoyer 53404a
-
Harald Hoyer 53404a
-        kmod_list_foreach(itr, loaded_list) {
Harald Hoyer 53404a
-                _cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
Harald Hoyer 53404a
+        if (arg_hostonly) {
Harald Hoyer 53404a
+                err = kmod_module_new_from_loaded(ctx, &loaded_list);
Harald Hoyer 53404a
+                if (err < 0) {
Harald Hoyer 53404a
+                        errno = err;
Harald Hoyer 53404a
+                        log_error("Could not get list of loaded modules: %m. Switching to non-hostonly mode.");
Harald Hoyer 53404a
+                        arg_hostonly = false;
Harald Hoyer 53404a
+                } else {
Harald Hoyer 53404a
+                        kmod_list_foreach(itr, loaded_list) {
Harald Hoyer 53404a
+                                _cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
Harald Hoyer 53404a
 
Harald Hoyer 53404a
-                struct kmod_module *mod = kmod_module_get_module(itr);
Harald Hoyer 53404a
-                char *name = strdup(kmod_module_get_name(mod));
Harald Hoyer 53404a
-                hashmap_put(modules_loaded, name, name);
Harald Hoyer 53404a
-                kmod_module_unref(mod);
Harald Hoyer 53404a
+                                struct kmod_module *mod = kmod_module_get_module(itr);
Harald Hoyer 53404a
+                                char *name = strdup(kmod_module_get_name(mod));
Harald Hoyer 53404a
+                                hashmap_put(modules_loaded, name, name);
Harald Hoyer 53404a
+                                kmod_module_unref(mod);
Harald Hoyer 53404a
 
Harald Hoyer 53404a
-                /* also put the modules from the new kernel in the hashmap,
Harald Hoyer 53404a
-                 * which resolve the name as an alias, in case a kernel module is
Harald Hoyer 53404a
-                 * renamed.
Harald Hoyer 53404a
-                 */
Harald Hoyer 53404a
-                err = kmod_module_new_from_lookup(ctx, name, &modlist);
Harald Hoyer 53404a
-                if (err < 0)
Harald Hoyer 53404a
-                        continue;
Harald Hoyer 53404a
-                if (!modlist)
Harald Hoyer 53404a
-                        continue;
Harald Hoyer 53404a
-                kmod_list_foreach(l, modlist) {
Harald Hoyer 53404a
-                        mod = kmod_module_get_module(l);
Harald Hoyer 53404a
-                        char *name = strdup(kmod_module_get_name(mod));
Harald Hoyer 53404a
-                        hashmap_put(modules_loaded, name, name);
Harald Hoyer 53404a
-                        kmod_module_unref(mod);
Harald Hoyer 53404a
+                                /* also put the modules from the new kernel in the hashmap,
Harald Hoyer 53404a
+                                 * which resolve the name as an alias, in case a kernel module is
Harald Hoyer 53404a
+                                 * renamed.
Harald Hoyer 53404a
+                                 */
Harald Hoyer 53404a
+                                err = kmod_module_new_from_lookup(ctx, name, &modlist);
Harald Hoyer 53404a
+                                if (err < 0)
Harald Hoyer 53404a
+                                        continue;
Harald Hoyer 53404a
+                                if (!modlist)
Harald Hoyer 53404a
+                                        continue;
Harald Hoyer 53404a
+                                kmod_list_foreach(l, modlist) {
Harald Hoyer 53404a
+                                        mod = kmod_module_get_module(l);
Harald Hoyer 53404a
+                                        char *name = strdup(kmod_module_get_name(mod));
Harald Hoyer 53404a
+                                        hashmap_put(modules_loaded, name, name);
Harald Hoyer 53404a
+                                        kmod_module_unref(mod);
Harald Hoyer 53404a
+                                }
Harald Hoyer 53404a
+                        }
Harald Hoyer 53404a
+                        kmod_module_unref_list(loaded_list);
Harald Hoyer 53404a
                 }
Harald Hoyer 53404a
         }
Harald Hoyer 53404a
-        kmod_module_unref_list(loaded_list);
Harald Hoyer 53404a
 
Harald Hoyer 53404a
         for (i = 0; i < argc; i++) {
Harald Hoyer 53404a
                 int r = 0;