[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: MOD_INC_USE_COUNT
On Mon, 9 Dec 2002, Edward Gerhold wrote:
>
>
> Jose Luis Alarcon wrote:
>
> > Hi, kernel developers.
> >
> > I has a big surprise when, adding at the beginning of init_module()
> > the macro MOD_INC_USE_COUNT, for have a module use counter. My program
> > get compile well and insmod work too.
> >
> > But the surprise was when i did rmmod, cos the output said:
> >
> > FATAL: the module is in use
> >
> > I did lsmod, and i got that my module was used by [unsafe].
> >
> > Any kernel programmer with experience knows why happen this?.
> >
> > IMHO a use counter is a very few dangerous thing. So i was trying with.
> >
> > Thanks you, very much, in advance.
> >
> > Regards.
> >
> > Jose.
> >
>
> I don't know why this happens,
> but can it be, that you forgot MOD_DEC_USE_COUNT in your cleanup routine ?
>
> bye
> Edward
>
Basically, adding MOD_INC_USE_COUNT in init_module() is not a right
idea, usage counts are used to keep track of current users of the module &
the system doesn't allow removing the module if usage count is non-zero.
In your case,
- You have incremented usage count to 1 during init_module()
- When you run rmmod, it calls delete_module() system call which
checks for the usage count, if it is zero, then ONLY it calls the
cleanup routine of corresponding module, if it is non-zero, system
call returns EBUSY error thinking someone is using this module, so
even if you do add MOD_DEC_USE_COUNT in clenup routine, it's of no
use. For more info. look for implementation of sys_delete_module().
bye,
Madhu
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/