[PATCH] Move "nousbstorage" and "nousb" handling into init.c.

Chris Lumens clumens at redhat.com
Fri Aug 9 13:48:12 UTC 2013


This is required because it must happen before udev starts and auto-loads
certain modules.  In order to reuse the modules.c code, I had to move
loadKickstartModule into kickstart.c so it won't try to link newt into init.

Based on a patch from Masahiro Matsuya.

Resolves: rhbz#947704
---
 loader/Makefile.am |  2 +-
 loader/init.c      |  7 +++++++
 loader/kickstart.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++
 loader/loader.c    |  8 +-------
 loader/modules.c   | 57 ++++++------------------------------------------------
 loader/modules.h   |  1 -
 6 files changed, 68 insertions(+), 60 deletions(-)

diff --git a/loader/Makefile.am b/loader/Makefile.am
index 4d063bb..ebefd53 100644
--- a/loader/Makefile.am
+++ b/loader/Makefile.am
@@ -56,7 +56,7 @@ loader_SOURCES     = loader.c copy.c log.c moduleinfo.c loadermisc.c \
 
 init_CFLAGS        = $(COMMON_CFLAGS) $(GLIB_CFLAGS)
 init_LDADD	   = $(GLIB_LIBS)
-init_SOURCES       = init.c undomounts.c shutdown.c copy.c
+init_SOURCES       = init.c undomounts.c shutdown.c copy.c modules.c log.c
 
 shutdown_CFLAGS    = $(COMMON_CFLAGS) -DAS_SHUTDOWN=1
 shutdown_SOURCES   = shutdown.c undomounts.c
diff --git a/loader/init.c b/loader/init.c
index a54d86d..7c5bcc8 100644
--- a/loader/init.c
+++ b/loader/init.c
@@ -62,6 +62,8 @@
 #include "copy.h"
 #include "devt.h"
 #include "devices.h"
+#include "modules.h"
+#include "log.h"
 
 #endif
 
@@ -548,6 +550,11 @@ int main(int argc, char **argv) {
     createDevices();
     printf("done\n");
 
+    if (!mlInitModuleConfig()) {
+        logMessage(ERROR, "unable to initialize kernel module loading");
+        abort();
+    }
+
     printf("starting udev...");
     fflush(stdout);
     if ((childpid = fork()) == 0) {
diff --git a/loader/kickstart.c b/loader/kickstart.c
index 27f5f66..7e6b052 100644
--- a/loader/kickstart.c
+++ b/loader/kickstart.c
@@ -91,6 +91,8 @@ static void setVnc(struct loaderData_s * loaderData, int argc,
                        char ** argv);
 static void setUnsupportedHw(struct loaderData_s * loaderData, int argc,
                        char ** argv);
+static void loadKickstartModule(struct loaderData_s * loaderData, int argc,
+                                char **argv);
 
 struct ksCommandNames ksTable[] = {
     { KS_CMD_NFS, "nfs", setKickstartNfs },
@@ -547,6 +549,57 @@ static void setMediaCheck(struct loaderData_s * loaderData, int argc,
     return;
 }
 
+static void loadKickstartModule(struct loaderData_s * loaderData,
+                                int argc, char **argv) {
+    gchar *opts = NULL;
+    gchar *module = NULL;
+    gchar **args = NULL, **remaining = NULL;
+    gboolean rc;
+    GOptionContext *optCon = g_option_context_new(NULL);
+    GError *optErr = NULL;
+    GOptionEntry ksDeviceOptions[] = {
+        { "opts", 0, 0, G_OPTION_ARG_STRING, &opts, NULL, NULL },
+        { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining,
+          NULL, NULL },
+        { NULL },
+    };
+
+    g_option_context_set_help_enabled(optCon, FALSE);
+    g_option_context_add_main_entries(optCon, ksDeviceOptions, NULL);
+
+    if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
+        startNewt();
+        newtWinMessage(_("Kickstart Error"), _("OK"),
+                       _("Bad argument to device kickstart method "
+                         "command: %s"), optErr->message);
+        g_error_free(optErr);
+        g_option_context_free(optCon);
+        return;
+    }
+
+    g_option_context_free(optCon);
+
+    if ((remaining != NULL) && (g_strv_length(remaining) == 1)) {
+        module = remaining[0];
+    }
+
+    if (!module) {
+        startNewt();
+        newtWinMessage(_("Kickstart Error"), _("OK"),
+                       _("A module name must be specified for "
+                         "the kickstart device command."));
+        return;
+    }
+
+    if (opts) {
+        args = g_strsplit(opts, " ", 0);
+    }
+
+    rc = mlLoadModule(module, args);
+    g_strfreev(args);
+    return;
+}
+
 void markFirstKsNetworkCommand() {
     int i = 0;
 
diff --git a/loader/loader.c b/loader/loader.c
index 4ae9a56..1bc9c8f 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -1027,13 +1027,7 @@ static void parseCmdLineFlags(struct loaderData_s * loaderData,
         else if (!strcasecmp(argv[i], "kssendsn"))
             flags |= LOADER_FLAGS_KICKSTART_SEND_SERIAL;
         /* deprecated hardware bits */
-        else if (!strcasecmp(argv[i], "nousbstorage"))
-            mlAddBlacklist("usb-storage");
-        else if (!strcasecmp(argv[i], "nousb")) {
-            mlAddBlacklist("ehci-hcd");
-            mlAddBlacklist("ohci-hcd");
-            mlAddBlacklist("uhci-hcd");
-        } else if (!strcasecmp(argv[i], "nofirewire"))
+        else if (!strcasecmp(argv[i], "nofirewire"))
             mlAddBlacklist("firewire-ohci");
         else if (!strcasecmp(argv[i], "noeject"))
             flags |= LOADER_FLAGS_NOEJECT;
diff --git a/loader/modules.c b/loader/modules.c
index 8c852e5..e824dd9 100644
--- a/loader/modules.c
+++ b/loader/modules.c
@@ -291,6 +291,12 @@ gboolean mlInitModuleConfig(void) {
                     g_strfreev(blmods);
                 }
             }
+        } else if (!strncmp(options[i], "nousbstorage", 12)) {
+            blacklist = g_slist_append(blacklist, "usb-storage");
+        } else if (!strcasecmp(options[i], "nousb")) {
+            blacklist = g_slist_append(blacklist, "ehci-hcd");
+            blacklist = g_slist_append(blacklist, "ohci-hcd");
+            blacklist = g_slist_append(blacklist, "uhci-hcd");
         } else if ((fields = g_strsplit(options[i], ".", 0)) != NULL) {
             if (g_strv_length(fields) == 2) {
                 if (_isValidModule(fields[0])) {
@@ -373,57 +379,6 @@ gboolean mlRemoveBlacklist(gchar *module) {
     return TRUE;
 }
 
-void loadKickstartModule(struct loaderData_s * loaderData,
-                         int argc, char **argv) {
-    gchar *opts = NULL;
-    gchar *module = NULL;
-    gchar **args = NULL, **remaining = NULL;
-    gboolean rc;
-    GOptionContext *optCon = g_option_context_new(NULL);
-    GError *optErr = NULL;
-    GOptionEntry ksDeviceOptions[] = {
-        { "opts", 0, 0, G_OPTION_ARG_STRING, &opts, NULL, NULL },
-        { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining,
-          NULL, NULL },
-        { NULL },
-    };
-
-    g_option_context_set_help_enabled(optCon, FALSE);
-    g_option_context_add_main_entries(optCon, ksDeviceOptions, NULL);
-
-    if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
-        startNewt();
-        newtWinMessage(_("Kickstart Error"), _("OK"),
-                       _("Bad argument to device kickstart method "
-                         "command: %s"), optErr->message);
-        g_error_free(optErr);
-        g_option_context_free(optCon);
-        return;
-    }
-
-    g_option_context_free(optCon);
-
-    if ((remaining != NULL) && (g_strv_length(remaining) == 1)) {
-        module = remaining[0];
-    }
-
-    if (!module) {
-        startNewt();
-        newtWinMessage(_("Kickstart Error"), _("OK"),
-                       _("A module name must be specified for "
-                         "the kickstart device command."));
-        return;
-    }
-
-    if (opts) {
-        args = g_strsplit(opts, " ", 0);
-    }
-
-    rc = mlLoadModule(module, args);
-    g_strfreev(args);
-    return;
-}
-
 inline gint gcmp(gconstpointer a, gconstpointer b, gpointer userptr)
 {
     return g_strcmp0(a, b);
diff --git a/loader/modules.h b/loader/modules.h
index 675dffc..e10382b 100644
--- a/loader/modules.h
+++ b/loader/modules.h
@@ -38,7 +38,6 @@ gboolean mlLoadModule(const gchar *, gchar **);
 gboolean mlLoadModuleSet(const gchar *);
 gboolean mlAddBlacklist(gchar *);
 gboolean mlRemoveBlacklist(gchar *);
-void loadKickstartModule(struct loaderData_s *, int, char **);
 
 GTree* mlSaveModuleState();
 void mlRestoreModuleState(GTree *state);
-- 
1.8.1.2



More information about the anaconda-patches mailing list