2002-02-24 12:38:38

by Jaroslav Kysela

[permalink] [raw]
Subject: KMOD error messages - proposal and patch

Hello,

there are very bad-looking messages during the boot process for
ALSA and other code using request_module() when a real root filesystem is
not mounted:

kmod: failed to exec /sbin/modprobe -s -k snd-card-0, errno = 2

I propose to add a new function can_request_module() allowing a
check, if request_module() function is useable. Implementation follows.

Jaroslav

# This is a BitKeeper generated patch for the following project:
# Project Name: Perex's Linux 2.5 Tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.4 -> 1.5
# kernel/kmod.c 1.2 -> 1.4
# include/linux/kmod.h 1.1 -> 1.2
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/02/24 [email protected] 1.5
# kmod.c:
# Exported function can_request_module()
# kmod.c, kmod.h:
# Added can_request_module() function.
# --------------------------------------------
#
diff -Nru a/include/linux/kmod.h b/include/linux/kmod.h
--- a/include/linux/kmod.h Sun Feb 24 13:20:44 2002
+++ b/include/linux/kmod.h Sun Feb 24 13:20:44 2002
@@ -23,8 +23,10 @@
#include <linux/errno.h>

#ifdef CONFIG_KMOD
+extern int can_request_module(void);
extern int request_module(const char * name);
#else
+static inline int can_request_module(void) { return 0; }
static inline int request_module(const char * name) { return -ENOSYS; }
#endif

diff -Nru a/kernel/kmod.c b/kernel/kmod.c
--- a/kernel/kmod.c Sun Feb 24 13:20:44 2002
+++ b/kernel/kmod.c Sun Feb 24 13:20:44 2002
@@ -167,6 +167,27 @@
}

/**
+ * can_request_module - test if request_module() function can be used
+ *
+ * If no root filesystem is mounted, request_module() will fail.
+ * This test ensures, that everything is prepared to load on demand
+ * kernel modules.
+ */
+int can_request_module(void)
+{
+ /* Don't allow request_module() before the root fs is mounted! */
+ if ( ! current->fs->root )
+ return 0;
+
+ /* Don't allow request_module() when ramfs based rootfs is mounted! */
+ if ( ! strcmp("rootfs", current->fs->pwdmnt->mnt_sb->s_type->name) )
+ return 0;
+
+ /* Everything is ok */
+ return 1;
+}
+
+/**
* request_module - try to load a kernel module
* @module_name: Name of module
*
@@ -189,13 +210,20 @@
#define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
static int kmod_loop_msg;

- /* Don't allow request_module() before the root fs is mounted! */
+ /* Don't allow request_module() before the root fs is mounted! */
if ( ! current->fs->root ) {
printk(KERN_ERR "request_module[%s]: Root fs not mounted\n",
module_name);
return -EPERM;
}

+ /* Don't allow request_module() when ramfs based rootfs is mounted! */
+ if ( ! strcmp("rootfs", current->fs->pwdmnt->mnt_sb->s_type->name) ) {
+ printk(KERN_ERR "request_module[%s]: Real root fs not mounted\n",
+ module_name);
+ return -EPERM;
+ }
+
/* If modprobe needs a service that is in a module, we get a recursive
* loop. Limit the number of running kmod threads to max_threads/2 or
* MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
@@ -377,6 +405,7 @@
EXPORT_SYMBOL(call_usermodehelper);

#ifdef CONFIG_KMOD
+EXPORT_SYMBOL(can_request_module);
EXPORT_SYMBOL(request_module);
#endif


-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project http://www.alsa-project.org
SuSE Linux http://www.suse.com


2002-02-24 12:58:24

by Alan

[permalink] [raw]
Subject: Re: KMOD error messages - proposal and patch

> + /* Don't allow request_module() when ramfs based rootfs is mounted! */
> + if ( ! strcmp("rootfs", current->fs->pwdmnt->mnt_sb->s_type->name) ) {
> + printk(KERN_ERR "request_module[%s]: Real root fs not mounted\n",
> + module_name);
> + return -EPERM;
> + }

The ramfs based root file system once the load ramfs from tar stuff is
working may have a completely valid modprobe on it.

Perhaps request_module() needs a 'quiet' flag

2002-02-24 17:18:42

by Jaroslav Kysela

[permalink] [raw]
Subject: Re: KMOD error messages - proposal and patch

On Sun, 24 Feb 2002, Alan Cox wrote:

> > + /* Don't allow request_module() when ramfs based rootfs is mounted! */
> > + if ( ! strcmp("rootfs", current->fs->pwdmnt->mnt_sb->s_type->name) ) {
> > + printk(KERN_ERR "request_module[%s]: Real root fs not mounted\n",
> > + module_name);
> > + return -EPERM;
> > + }
>
> The ramfs based root file system once the load ramfs from tar stuff is
> working may have a completely valid modprobe on it.
>
> Perhaps request_module() needs a 'quiet' flag

Well, I though about this, but we can suppress with this way important
informative error messages as well. I think that the condition in kmod
might be exteded in future when the ramfs initialization will be
implemented.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project http://www.alsa-project.org
SuSE Linux http://www.suse.com