Re: use counts for /proc modules
Philip Gladstone (philip@raptor.com)
Thu, 02 Oct 1997 15:49:50 -0400
Bill Hawes wrote:
>
> In my ongoing cleanup of the /proc fs I'd like to fix the problem of
> modules being unloaded while the fs still holds references to code or
> data structures. The problem arises because module use counts are
> currently being incremented only for "active" uses -- e.g. while the
> read routine is being called. If someone is just cd'ed to a directory
> and the module unloads, you've got trouble.
>
> With the use count tracking I've added for proc_dir_entries I can tell
> when the last use is released, but this needs to be translated into an
> appropriate MOD_DEC_USE_COUNT. The only way I can think to do this is
> to add another function pointer to proc_dir_entry that would increment
> or decrement the module count. Permanent entries or non-module code
> could leave it as NULL or just an empty function. The code might be
> something like
>
> void mod_use_count(int up)
> {
> if (up)
> MOD_INC_USE_COUNT;
> else
> MOD_DEC_USE_COUNT;
> }
>
> This would require adding the routine to each module, but on the other
> hand would simplify module use count tracking, as you wouldn't need it
> in the read/write/etc routines.
>
> Does this seem reasonable, or can anyone else think of a better way?
I approached the problem in a different (and yet murky) way. I have
a _fill_inode function that is pointed to by the proc_dir_entry
structure. This gets called when someone cd's into the directory. I
increment the i_count counter in the inode and also do the
MOD_INC_USE_COUNT
(first time only).
This takes care of processes going into the directory.
On a regular basis (every 30 seconds), I check to see if the i_count is
back to 1. (which means that nobody is in the directory). If so, then I
do the MOD_DEC_USE_COUNT, and do an iput on the inode to release it.
This works (but only just!).
Philip
--
Philip Gladstone +1 617 487 7700
Raptor Systems, Waltham, MA http://www.raptor.com/