Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I define dependency among kernel modules?

How one can define a dependency for modules in kernel,

Example:

got module1 and module2.

How do I say say kernel module2 should be loaded after module1 or module2 is dependent of module1?

Note : module2 is not using any symbol from module1, but still order is important in my use case. so don't relate with moddep in kernel.

like image 883
guru th Avatar asked Apr 18 '15 13:04

guru th


2 Answers

As of the linux 4.4 kernel (and maybe earlier) soft dependencies can be used to specify that a kernel module be loaded before or after a module is requested to be loaded. Those soft dependencies can be setup in a configuration file as described in the modprobe.d (5) manpage, or they can be specified directly in the code for the kernel module directly using the MODULE_SOFTDEP macro.

To accomplish loading module2 after module1 by modifying the code of module2, add this line outside of a function to the module2 code:

MODULE_SOFTDEP("pre: module1")

To accomplish the same by modifying the module1 code, you would use this line:

MODULE_SOFTDEP("post: module2")

like image 109
Robert McLean Avatar answered Sep 27 '22 22:09

Robert McLean


Quote from man page of depmod:

   Linux kernel modules can provide services (called "symbols") for other
   modules to use (using one of the EXPORT_SYMBOL variants in the code).
   If a second module uses this symbol, that second module clearly depends
   on the first module. These dependencies can get quite complex.

   depmod creates a list of module dependencies by reading each module
   under /lib/modules/version and determining what symbols it exports and
   what symbols it needs. By default, this list is written to modules.dep,
   and a binary hashed version named modules.dep.bin, in the same
   directory. If filenames are given on the command line, only those
   modules are examined (which is rarely useful unless all modules are
   listed).  depmod also creates a list of symbols provided by modules in
   the file named modules.symbols and its binary hashed version,
   modules.symbols.bin. Finally, depmod will output a file named
   modules.devname if modules supply special device names (devname) that
   should be populated in /dev on boot (by a utility such as udev).
like image 21
Chris Tsui Avatar answered Sep 27 '22 22:09

Chris Tsui