mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* opening files in /proc, and modules
@ 2001-03-08 16:01 Michael Rothwell
  2001-03-08 16:35 ` Michael Rothwell
  2001-03-08 16:39 ` Brian Gerst
  0 siblings, 2 replies; 5+ messages in thread
From: Michael Rothwell @ 2001-03-08 16:01 UTC (permalink / raw)
  To: linux-kernel

How can I detect that open() has been called on a file in procfs that a
module provides? If I modprobe my module, open one or more if its proc
entries, then rmmod the module while the proc files are still open, then
the deletion of those entries is deferred. When I close the file(s), the
kernel oopses. I need to be able to detect open() and close() in order
to increment/decrement the reference count for my module, to prevent it
from being rmmoded when in use. Any tips?

Thanks! 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: opening files in /proc, and modules
  2001-03-08 16:01 opening files in /proc, and modules Michael Rothwell
@ 2001-03-08 16:35 ` Michael Rothwell
  2001-03-08 16:43   ` Alexander Viro
  2001-03-08 16:39 ` Brian Gerst
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Rothwell @ 2001-03-08 16:35 UTC (permalink / raw)
  To: linux-kernel

Figured it out -- I think. This appears to be the answer:

In struct proc_dir_entry,set the fill_inode function pointer to a
callback to handle refcounts.

struct proc_dir_entry
{
...
void (*fill_inode)(struct inode *, int);
...
};


void fill_inode_cb(struct inode *i, int v)
{
 if (v==0)
 {
  MOD_DEC_USE_COUNT;
  return;
 };
 if (v==1)
 {
  MOD_INC_USE_COUNT;
  return;
 };
};


... right?  :)


On 08 Mar 2001 11:01:28 -0500, Michael Rothwell wrote:
> How can I detect that open() has been called on a file in procfs that a
> module provides? If I modprobe my module, open one or more if its proc
> entries, then rmmod the module while the proc files are still open, then
> the deletion of those entries is deferred. When I close the file(s), the
> kernel oopses. I need to be able to detect open() and close() in order
> to increment/decrement the reference count for my module, to prevent it
> from being rmmoded when in use. Any tips?
> 
> Thanks! 
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: opening files in /proc, and modules
  2001-03-08 16:01 opening files in /proc, and modules Michael Rothwell
  2001-03-08 16:35 ` Michael Rothwell
@ 2001-03-08 16:39 ` Brian Gerst
  1 sibling, 0 replies; 5+ messages in thread
From: Brian Gerst @ 2001-03-08 16:39 UTC (permalink / raw)
  To: Michael Rothwell; +Cc: linux-kernel

Michael Rothwell wrote:
> 
> How can I detect that open() has been called on a file in procfs that a
> module provides? If I modprobe my module, open one or more if its proc
> entries, then rmmod the module while the proc files are still open, then
> the deletion of those entries is deferred. When I close the file(s), the
> kernel oopses. I need to be able to detect open() and close() in order
> to increment/decrement the reference count for my module, to prevent it
> from being rmmoded when in use. Any tips?
> 
> Thanks!

Really, the procfs needs a pointer to the module so it can do the
reference before calling the code in the module.

--

				Brian Gerst

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: opening files in /proc, and modules
  2001-03-08 16:35 ` Michael Rothwell
@ 2001-03-08 16:43   ` Alexander Viro
  2001-03-08 16:48     ` Michael Rothwell
  0 siblings, 1 reply; 5+ messages in thread
From: Alexander Viro @ 2001-03-08 16:43 UTC (permalink / raw)
  To: Michael Rothwell; +Cc: linux-kernel



On 8 Mar 2001, Michael Rothwell wrote:

> Figured it out -- I think. This appears to be the answer:
> 
> In struct proc_dir_entry,set the fill_inode function pointer to a
> callback to handle refcounts.
> 
> struct proc_dir_entry
> {
> ...
> void (*fill_inode)(struct inode *, int);
> ...
> };
[snip]
> ... right?  :)

Right for 2.2, wrong for 2.4. There you just set ->owner to THIS_MODULE
and forget about the whole mess with callbacks.
								Cheers,
									Al


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: opening files in /proc, and modules
  2001-03-08 16:43   ` Alexander Viro
@ 2001-03-08 16:48     ` Michael Rothwell
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Rothwell @ 2001-03-08 16:48 UTC (permalink / raw)
  To: Alexander Viro; +Cc: linux-kernel

Sweet! Thanks!

I'm working on 2.2 for now, but the 2.4 API looks nicer... :)

-M

On 08 Mar 2001 11:43:24 -0500, Alexander Viro wrote:
> 
> 
> On 8 Mar 2001, Michael Rothwell wrote:
> 
> > Figured it out -- I think. This appears to be the answer:
> > 
> > In struct proc_dir_entry,set the fill_inode function pointer to a
> > callback to handle refcounts.
> > 
> > struct proc_dir_entry
> > {
> > ...
> > void (*fill_inode)(struct inode *, int);
> > ...
> > };
> [snip]
> > ... right?  :)
> 
> Right for 2.2, wrong for 2.4. There you just set ->owner to THIS_MODULE
> and forget about the whole mess with callbacks.
>                                                               Cheers,
>                                                                       Al


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-03-08 16:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-08 16:01 opening files in /proc, and modules Michael Rothwell
2001-03-08 16:35 ` Michael Rothwell
2001-03-08 16:43   ` Alexander Viro
2001-03-08 16:48     ` Michael Rothwell
2001-03-08 16:39 ` Brian Gerst

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®