Skip to contentSkip to conversation

Unloading drivers, start-up, shut-down and some clean-ups (a problem)

DISCUSSION stamit 2 participants 2 messages Oct 2, 2001 – Oct 3, 2001

lore
Share & tools
lore

stamit

author
#0 lore raw

(please don't hate me for this... :-)

There are two obvious problems with the previous patch...

1. From the beginning I tried to verbosely comment the scripts (so they can be self-explanatory and easy to read) and, apparently, I forgot to update the comments in the "uhci.agent" after reorganizing the scripts (to experiment with), so... the comments in /etc/hotplug/pci/uhci.agent are wrong, misleading and confusing (ouch)!

2. Only after posting that previous patch I realised that the way in which the "start" and "stop" events are passed down from policy agents to driver agents was, well, not so good. "start" was passed if a kernel module was already loaded and "stop" was passed if a module was already unloaded. Well, it turns out that the right thing is to handle start/stop in the same (almost) way that add/remove events are handled. The only difference is that, for start/stop, $MODULE is also exported and is the name of the currently loaded kernel module ("-" if none, "#" if undetermined).

Now, the final thing that remains for unloading to be complete is reference counting. I tried to do it with bash (by storing counts in *.ref files in the driver directories) and guess what I stumbled to... a race condition! Multiple hotplug events can be processed by the scripts at the same time. So I took it back. Isn't there a way to use modutils programs to play with the module's real refrence counts? It would make things a whole lot easier (and safer).

#1 lore raw
Quoted 7 lines · stamit

Now, the final thing that remains for unloading to be complete is reference counting. I tried to do it with bash (by storing counts in *.ref files in the driver directories) and guess what I stumbled to... a race condition! Multiple hotplug events can be processed by the scripts at the same time. So I took it back. Isn't there a way to use modutils programs to play with the module's real refrence counts? It would make things a whole lot easier (and safer).

Without knowing exactly what you are trying to do I am guessing but it sounds like you need this:

* kernel/module.c registers /proc/sys/kernel/mod_use_count, mode 600.
* module.c creates a dummy module entry called mod_use_count the first time that /proc/sys/kernel/mod_use_count is written to.
* /proc/sys/kernel/mod_use_count recognises commands like
up module-name
down module-name
and adjusts the use counts and reference chain accordingly. Hotplug scripts use mod_use_count to bump the reference count before allowing a start event to continue and after completing a stop event.

If the module does not exist (already unloaded) then write fails with some return code. There is no specific code for "module does not exist" so pick something similar, like ESRCH or ENXIO.

_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel