Blame 0051-dracut-install-simplify-error-logic.patch

Harald Hoyer b38677
From fe6e0c23adbdafc4fc371107534b3b2681c96393 Mon Sep 17 00:00:00 2001
Harald Hoyer b38677
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer b38677
Date: Wed, 13 Apr 2016 13:28:29 +0200
Harald Hoyer b38677
Subject: [PATCH] dracut-install: simplify error logic
Harald Hoyer b38677
Harald Hoyer b38677
error out early, if "--optional" is not set
Harald Hoyer b38677
---
Harald Hoyer b38677
 install/dracut-install.c | 64 +++++++++++++++++++++++++++++++++++-------------
Harald Hoyer b38677
 1 file changed, 47 insertions(+), 17 deletions(-)
Harald Hoyer b38677
Harald Hoyer b38677
diff --git a/install/dracut-install.c b/install/dracut-install.c
Harald Hoyer b38677
index c246201..f414f30 100644
Harald Hoyer b38677
--- a/install/dracut-install.c
Harald Hoyer b38677
+++ b/install/dracut-install.c
Harald Hoyer b38677
@@ -1181,8 +1181,10 @@ static int install_module(struct kmod_module *mod)
Harald Hoyer b38677
         state = kmod_module_get_initstate(mod);
Harald Hoyer b38677
 
Harald Hoyer b38677
         name = kmod_module_get_name(mod);
Harald Hoyer b38677
-        if (arg_mod_filter_noname && (regexec(&mod_filter_noname, name, 0, NULL, 0) == 0))
Harald Hoyer b38677
+        if (arg_mod_filter_noname && (regexec(&mod_filter_noname, name, 0, NULL, 0) == 0)) {
Harald Hoyer b38677
+                log_debug("dracut_install '%s' is excluded", name);
Harald Hoyer b38677
                 return 0;
Harald Hoyer b38677
+        }
Harald Hoyer b38677
 
Harald Hoyer b38677
         if (arg_hostonly && (state != KMOD_MODULE_BUILTIN) && (state != KMOD_MODULE_LIVE)) {
Harald Hoyer b38677
                 log_debug("dracut_install '%s' not hostonly", name);
Harald Hoyer b38677
@@ -1194,15 +1196,14 @@ static int install_module(struct kmod_module *mod)
Harald Hoyer b38677
                 return -ENOENT;
Harald Hoyer b38677
 
Harald Hoyer b38677
         if (check_hashmap(items_failed, path))
Harald Hoyer b38677
-                return 1;
Harald Hoyer b38677
+                return -1;
Harald Hoyer b38677
 
Harald Hoyer b38677
         if (check_hashmap(items, path))
Harald Hoyer b38677
                 return 0;
Harald Hoyer b38677
 
Harald Hoyer b38677
         if (!check_module_path(path) || !check_module_symbols(mod)) {
Harald Hoyer b38677
                 log_debug("No symbol or patch match for '%s'", path);
Harald Hoyer b38677
-                return 0;
Harald Hoyer b38677
-                //return -ENOENT;
Harald Hoyer b38677
+                return 1;
Harald Hoyer b38677
         }
Harald Hoyer b38677
 
Harald Hoyer b38677
         log_debug("dracut_install '%s'", path);
Harald Hoyer b38677
@@ -1252,7 +1253,7 @@ static int install_modules(int argc, char **argv)
Harald Hoyer b38677
 
Harald Hoyer b38677
         for (i = 0; i < argc; i++) {
Harald Hoyer b38677
                 int r = 0;
Harald Hoyer b38677
-                int ret = 0;
Harald Hoyer b38677
+                int ret = -1;
Harald Hoyer b38677
                 log_debug("Handle module '%s'", argv[i]);
Harald Hoyer b38677
 
Harald Hoyer b38677
                 if (argv[i][0] == '/') {
Harald Hoyer b38677
@@ -1296,7 +1297,14 @@ static int install_modules(int argc, char **argv)
Harald Hoyer b38677
                         }
Harald Hoyer b38677
                         kmod_list_foreach(itr, modlist) {
Harald Hoyer b38677
                                 mod = kmod_module_get_module(itr);
Harald Hoyer b38677
-                                ret += install_module(mod);
Harald Hoyer b38677
+                                r = install_module(mod);
Harald Hoyer b38677
+                                kmod_module_unref(mod);
Harald Hoyer b38677
+                                if ((r < 0) && !arg_optional) {
Harald Hoyer b38677
+                                        if (!arg_silent)
Harald Hoyer b38677
+                                                log_error("ERROR: installing module '%s'", modname);
Harald Hoyer b38677
+                                        return -ENOENT;
Harald Hoyer b38677
+                                };
Harald Hoyer b38677
+                                ret = ( ret == 0 ? 0 : r );
Harald Hoyer b38677
                         }
Harald Hoyer b38677
                         kmod_module_unref_list(modlist);
Harald Hoyer b38677
                         modlist = 0;
Harald Hoyer b38677
@@ -1341,40 +1349,55 @@ static int install_modules(int argc, char **argv)
Harald Hoyer b38677
                                 log_debug("Handling %s", ftsent->fts_accpath);
Harald Hoyer b38677
                                 r = kmod_module_new_from_path(ctx, ftsent->fts_accpath, &mod_o);
Harald Hoyer b38677
                                 if (r < 0) {
Harald Hoyer b38677
-                                        log_debug("Failed to lookup modules path '%s': %m", ftsent->fts_accpath);
Harald Hoyer b38677
+                                        log_debug("Failed to lookup modules path '%s': %m",
Harald Hoyer b38677
+                                                  ftsent->fts_accpath);
Harald Hoyer b38677
+                                        if (!arg_optional) {
Harald Hoyer b38677
+                                                return -ENOENT;
Harald Hoyer b38677
+                                        }
Harald Hoyer b38677
                                         continue;
Harald Hoyer b38677
                                 }
Harald Hoyer b38677
-#if 1
Harald Hoyer b38677
+
Harald Hoyer b38677
                                 /* Check, if we have to load another module with that name instead */
Harald Hoyer b38677
                                 modname = kmod_module_get_name(mod_o);
Harald Hoyer b38677
                                 if (!modname) {
Harald Hoyer b38677
                                         log_error("Failed to get name for module '%s'", ftsent->fts_accpath);
Harald Hoyer b38677
+                                        if (!arg_optional) {
Harald Hoyer b38677
+                                                return -ENOENT;
Harald Hoyer b38677
+                                        }
Harald Hoyer b38677
                                         continue;
Harald Hoyer b38677
                                 }
Harald Hoyer b38677
                                 r = kmod_module_new_from_lookup(ctx, modname, &modlist);
Harald Hoyer b38677
                                 kmod_module_unref(mod_o);
Harald Hoyer b38677
                                 if (r < 0) {
Harald Hoyer b38677
-                                        log_error("2 Failed to lookup alias '%s': %m", modname);
Harald Hoyer b38677
+                                        log_error("Failed to lookup alias '%s': %m", modname);
Harald Hoyer b38677
                                         kmod_module_unref_list(modlist);
Harald Hoyer b38677
+                                        if (!arg_optional) {
Harald Hoyer b38677
+                                                return -ENOENT;
Harald Hoyer b38677
+                                        }
Harald Hoyer b38677
                                         continue;
Harald Hoyer b38677
                                 }
Harald Hoyer b38677
                                 if (!modlist) {
Harald Hoyer b38677
-                                        log_error("Failed to find module '%s' %s", modname, ftsent->fts_accpath);
Harald Hoyer b38677
+                                        log_error("Failed to find module '%s' %s", modname,
Harald Hoyer b38677
+                                                  ftsent->fts_accpath);
Harald Hoyer b38677
                                         kmod_module_unref_list(modlist);
Harald Hoyer b38677
+                                        if (!arg_optional) {
Harald Hoyer b38677
+                                                return -ENOENT;
Harald Hoyer b38677
+                                        }
Harald Hoyer b38677
                                         continue;
Harald Hoyer b38677
                                 }
Harald Hoyer b38677
                                 kmod_list_foreach(itr, modlist) {
Harald Hoyer b38677
                                         mod = kmod_module_get_module(itr);
Harald Hoyer b38677
-                                        ret += install_module(mod);
Harald Hoyer b38677
+                                        r = install_module(mod);
Harald Hoyer b38677
                                         kmod_module_unref(mod);
Harald Hoyer b38677
+                                        if ((r < 0) && !arg_optional) {
Harald Hoyer b38677
+                                                if (!arg_silent)
Harald Hoyer b38677
+                                                        log_error("ERROR: installing module '%s'", modname);
Harald Hoyer b38677
+                                                return -ENOENT;
Harald Hoyer b38677
+                                        };
Harald Hoyer b38677
+                                        ret = ( ret == 0 ? 0 : r );
Harald Hoyer b38677
                                 }
Harald Hoyer b38677
                                 kmod_module_unref_list(modlist);
Harald Hoyer b38677
                                 modlist = 0;
Harald Hoyer b38677
-#else
Harald Hoyer b38677
-                                ret += install_module(mod_o);
Harald Hoyer b38677
-                                kmod_module_unref(mod_o);
Harald Hoyer b38677
-#endif
Harald Hoyer b38677
-
Harald Hoyer b38677
                         }
Harald Hoyer b38677
                         if (errno) {
Harald Hoyer b38677
                                 log_error("FTS ERROR: %m");
Harald Hoyer b38677
@@ -1414,8 +1437,14 @@ static int install_modules(int argc, char **argv)
Harald Hoyer b38677
                         }
Harald Hoyer b38677
                         kmod_list_foreach(itr, modlist) {
Harald Hoyer b38677
                                 mod = kmod_module_get_module(itr);
Harald Hoyer b38677
-                                ret += install_module(mod);
Harald Hoyer b38677
+                                r = install_module(mod);
Harald Hoyer b38677
                                 kmod_module_unref(mod);
Harald Hoyer b38677
+                                if ((r < 0) && !arg_optional) {
Harald Hoyer b38677
+                                        if (!arg_silent)
Harald Hoyer b38677
+                                                log_error("ERROR: installing '%s'", argv[i]);
Harald Hoyer b38677
+                                        return -ENOENT;
Harald Hoyer b38677
+                                };
Harald Hoyer b38677
+                                ret = ( ret == 0 ? 0 : r );
Harald Hoyer b38677
                         }
Harald Hoyer b38677
                         kmod_module_unref_list(modlist);
Harald Hoyer b38677
                         modlist = 0;
Harald Hoyer b38677
@@ -1427,6 +1456,7 @@ static int install_modules(int argc, char **argv)
Harald Hoyer b38677
                         return EXIT_FAILURE;
Harald Hoyer b38677
                 }
Harald Hoyer b38677
         }
Harald Hoyer b38677
+
Harald Hoyer b38677
         return EXIT_SUCCESS;
Harald Hoyer b38677
 }
Harald Hoyer b38677