How do I define dependency among kernel modules?
For easy solution, you can add symbol in first module and check that symbol in second module init. If symbol is not exported using
EXPORT_SYMBOL
you can return from second module initialization itself.
For details, from header
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).
How to call exported kernel module functions from another module?
From my research, it seems that those are the only three ways to handle this situation, and I've gotten each of them to work, so I think I'll just pick my favorite out of those.
Inter-dependent out-of-tree kernel loadable modules in Linux
As per ugoren's answer, you can just add some hooks into a machine file.
static void (*funcA_ptr)();
void register_funcA(void(*)() fnc)
{
funcA_ptr = fnc;
}
EXPORT_SYMBOL(register_funcA);
void funcA_proxy()
{
if(funcA_ptr)
funcA_ptr();
}
EXPORT_SYMBOL(funcA_proxy);
This overhead is so small, there is no need to make it a module.
Another mechanism is to look through module.h. The functions,
int register_module_notifier(struct notifier_block * nb);
int unregister_module_notifier(struct notifier_block * nb);
Can be used to get notified whenever any module is loaded. The notifier functions are passed enum module_state
and a pointer to the module structure. You can use this to walk through the exported symbols and patch the function pointers contained with-in the module.
The first solution seems best for a limited number of functions and the 2nd seem good if you anticipate that many functions may eventually be added like this. The 2nd solution supports module removal, but you can also do this with the first by using register_funcA(NULL);
in a module_exit()
.
Auto-load Linux Kernel Module
The correct way to do this is to use a function that has an exported symbol, just like @ian Abbott said. If you don't have exported functions like i did, making a patch for the driver might be the simplest way to get this done!
Related Topics
Error: Could Not Find Tiller' When Running 'Helm Version'
While Do Loop and Variables in a Bash Script
Searching a Process' Memory on Linux
Mercurial Hg No Changes Found - Can't Hg Push Out
Find the Files Existing in One Directory But Not in the Other
How to Purge Disk I/O Caches on Linux
How to Break Up an Extremely Long String Literal in Bash
Exclude All Permission Denied Messages from "Du"
What Does Pss Mean in /Proc/Pid/Smaps
How to Automate the Installation of Eclipse Plugins with Command Line
Concurrency of Posix Threads in Multiprocessor MAChine
Join on First Column of Two Files
How to Disable CPU Cache (L1/L2) on a Linux System
How to Tell Qt to Use Different Openssl
How to Grep a String in a Directory and All Its Subdirectories
How to Mount One Partition from an Image File That Contains Multiple Partitions on Linux