Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


request_module

Prepare environment for modprobe

Too many simultaneous calls of request_module? return

call_usermodehelper

Figure 7-7: Code flow diagram forrequest_module.

The default value formodprobe_pathis/sbin/modprobe. However, this value can be changed via the
procfilesystem (/proc/sys/kernel/modprobe) or the corresponding Sysctl. The name of the required
module is passed as a command-line argument.

Ifmodprobeitself builds on a service implemented in a module,^20 the kernel goes into a recursive endless
loop becausemodprobeinstances are started repeatedly. To prevent this, the kernel uses the global vari-
ablekmod_concurrent, which is incremented by 1 each timemodprobeis called. The operation is termi-
nated when the lesser of the two valuesMAX_KMOD_CONCURRENT—thedefaultis50—ormax_threads/2
is exceeded.

call_usermodehelperis then called to start the utility in userspace. Via some detours over functions
that are not described in further detail here, the function declares a new work queue entry (see
Chapter 14) and adds it to the work queue of thekhelperkernel thread. When the queue entry is
processed,____call_usermodehelperis called. This function is, in turn, responsible to run themodprobe
application, which inserts the desired module into the kernel using the method described above.

7.4.2 Hotplugging


When a new device is connected (or removed) at a hotpluggable bus, the kernel, again with the help of a
userspace application, ensures that the correct driver is loaded. In contrast to normal module insertion,
it is necessary to perform several additional tasks (e.g., the right driver must be found by reference to
a device identification string, or configuration workmust be carried out). For this reason, another tool
(usually/sbin/udevd^21 ) is used in place ofmodprobe.

Note that the kernel provides messages to userspace not only when devices are inserted and removed,
but also for a much more generic set of events. When, for instance, a new hard disk is connected to the
system, the kernel does not just provide informationabout this event, but also sends notifications about
partitions that have been found on the device. Everycomponent of the device model can send registration
and unregistration events to the userland. Since this results in a rather large and comprehensive set of
messages that can be potentially passed on from the kernel, I do not want to describe them all in detail.

(^20) In other words,modprobeis dependent on a service in a module; accordingly, the kernel issues an instruction tomodprobeto
load the module — and this, in turn, causesmodprobeto instruct the kernel to startmodprobeto load the module.
(^21) For former versions of the kernel,/sbin/hotplugwas used as the only hotplug agent. With the introduction of the device
model and its maturation during the development of 2.6,udevdis now the method of choice for most distributions. Neverthe-
less, the kernel does provide generic messages and is not tied to aparticular mechanism in userspace. In some places, the ker-
nel still calls the program registered inuevent_helper, which can be set to/sbin/hotplug— the setting is accessible via
/proc/sys/kernel/hotplug. Setting the value to an empty string disables the mechanism. Since it is only needed during early
boot or for some very specific configurations (mostly systems where networking is completely disabled), I will not consider it any
further.

Free download pdf