Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


Request by kernel Load module

modprobe Find module request_module
Figure 7-2: Automatic module loading.

request_modulecalls are located at various points throughout the kernel sources; with their help, the
kernel attempts to make functions delegated to modules accessible as transparently as possible by adding
the code automatically as needed and without user interaction.


Situations can arise in which it is not possible to uniquely define which module is required to provide
the desired functionality. Consider the case that aUSB stick is added to the system. The host controller
driver recognizes the new device. The module that needs to be loaded isusb-storage, but how can the
kernel know this? The solution to the problem is a small ‘‘database‘‘ that is attached to every module.
The contents describe which devices are supported by the module. In case of USB devices, this is a list of
supported interface types, manufacturer IDs, or any similar piece of information that identifies the device.
Modules that provide a driver for PCI devices, as another example, also use the unique IDs associated
with the device. The module provides a list of all supported devices.


The database information is provided viamodule aliases. These are generic identifiers for modules that
encode the described pieces of information. The macroMODULE_ALIASis used to generate module
aliases.


<modules.h>
/* Generic info of form tag = "info" */
#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)

/* For userspace: you can also call me... */
#define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)

<moduleparam.h>
#define __MODULE_INFO(tag, name, info) \
static const char __module_cat(name,__LINE__)[] \
__attribute_used__ \
__attribute__((section(".modinfo"),unused)) = __stringify(tag) "=" info

The alias provided toMODULE_ALIASis stored in the.modinfosection of the module binary. If a module
provides several different services, appropriate aliases are inserted directly. The code for RAID 4, 5, and
6 is contained in the same module, for instance.


drivers/md/raid5.c
MODULE_ALIAS("md-personality-4"); /* RAID5 */
MODULE_ALIAS("md-raid5");
MODULE_ALIAS("md-raid4");
MODULE_ALIAS("md-level-5");
MODULE_ALIAS("md-level-4");
MODULE_ALIAS("md-personality-8"); /* RAID6 */
MODULE_ALIAS("md-raid6");
MODULE_ALIAS("md-level-6");
Free download pdf