Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


The implementation of this feature is interesting because, in both cases, the kernel relies on utilities
in userspace. On the basis of the information provided by the kernel, the utilities find the appropriate
module and insert it into the kernel in the usual way.

7.4.1 Automatic Loading with kmod


request_moduleinkernel/kmod.cis the main function for automatic kernel-initiated module loading.
The name of a module (or a generic placeholder^19 ) is passed to this function.

Module requests must be built into the kernel explicitly — logically at points where attempts are made
to reserve a particular resource but fail because no driver is available. At the moment, there are about 100
such points in the kernel. The IDE driver, for example, attempts to load required drivers when probing
for existing devices. The module name of the desired driver must be specified directly to do this:

drivers/ide/ide-probe.c
if (drive->media == ide_disk)
request_module("ide-disk");
...
if (drive->media == ide_floppy)
request_module("ide-floppy");

If a particular protocol family is not available,the kernel must make do with a general request:

net/socket.c
if (net_families[family]==NULL)
{
request_module("net-pf-%d",family);
}

Whereas automatic module loading in earlier kernel versions (up to 2.0) was the responsibility of a
separate daemon that had to be started explicitly in userspace, loading is now implemented by kernel
means — but the kernel still requires a utility in userspace to insert modules./sbin/modprobeis used by
default. The tool was mentioned above when discussing how the manual insertion of modules is used
by default. It is not my intention to consider with the numerous tool control options available when
automatically inserting modules. Instead, see the comprehensive system administration literature on on
this subject.

Figure 7-7 shows the code flow diagram forrequest_module.

The function requires a minimal environment in which themodprobeprocess executes (with full root
permissions):

kernel/kmod.c
char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
static char *envp[] = { "HOME=/",
"TERM=linux",
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
NULL };

(^19) This is a service name that is not associated with a particular hardware. For example, the kernel determines that a network mod-
ule for a certain protocol family is needed, but not linked into the kernel. Because it only knows the number of the protocol family,
but not the name of the module that provides support for this family number, the kernel usesnet-pf-Xas the module name —X
denotes the family number. Themodules.aliasfileassignstheappropriatemodule name for the particular family.net-pf-24,
for instance, resolves topppoe.

Free download pdf