Re: module using another module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 28 Jan 2010, at 12:30 PM, Jason Nymble wrote:


On 09 Dec 2009, at 12:09 PM, Matze wrote:

From: Jason Nymble <jason.nymble@xxxxxxxxx>
Date: 2009/12/8
Subject: module using another module
To: kernelnewbies <kernelnewbies@xxxxxxxxxxxx> What is the correct/ recommended way for one module to "plug in to" or use another module? e.g. if I have one module (call it A) which exports a symbol allowing a different module (call it B) to register (and unregister) a function pointer (which gets called by A if it has a valid value), it would be very good if A cannot unload while B is using it (registered), and also that B can unload without A being aware it has unregistered. The latter can simply be achieved by having B call the unregister function of A when it unloads. The former I suppose could be done via some sort of refcount scheme, but I'm sure this type of problem has a proper correct solution in the Linux kernel (e.g. all the modules that use the i2c module etc. etc.),
and I'd obviously like to avoid re-inventing the wheel (badly).

you can use modprobe for that reason. yust edit your modules.dep file so that loading module B will automatically load module A. Then the kernel don't let you unload A when B is still loaded.
regards,
Matthias
Is there not a way to do this in the source of module B, so that depmod will automatically generate the modules.dep correctly? Note I don't necessarily want A to be autoloaded if B is being loaded (though that would obviously be nice), I just want to prevent A from being unloaded while B is loaded. For example, if one just looks at the output of lsmod, the "used by" column shows modules using other modules, and the ones that are used cannot be unloaded. How is this achieved? Perhaps it is as simple as: if module B uses any symbols exported from module A, then module A is automatically marked as being used by B while B is loaded, in which case one does not need to do anything? I've briefly looked at the source of a few of the modules of in the "used by" column, and I can't see them explicitly doing anything to "lock" the modules that they use, so I'm thinking this just happens automagically because they're using exported functions.


Actually, I just tried the above with some minimal kernel modules that I made quickly, it does work that way. Awesome! So I don't really need to do anything special at all to prevent A from being unloaded, the very fact that B just references one of A's exported symbols is good enough.

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux