All of lore.kernel.org
 help / color / mirror / Atom feed
* rmmod while module is in use
@ 2005-02-17 12:47 Davide Rossetti
  2005-02-17 13:04 ` linux-os
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Davide Rossetti @ 2005-02-17 12:47 UTC (permalink / raw)
  To: linux-kernel

maybe RTFM...
a module:
- char device driver for..
- a PCI device

any clue as to how to protect from module unloading while there is still 
some process opening it??? have I to sleep in the remove_one() pci 
driver function till last process closes its file descriptor???

static void __devexit apedev_remove_one(struct pci_dev *pdev)
{
    ApeDev* apedev = pci_get_drvdata(pdev);

    if(test_bit(APEDEV_FLAG_OPEN, &apedev->flags)) {
        PERROR("still open flag on!!! (flags=0x%08x)\n", apedev->flags);

        // sleep here till it gets closed...

    }
    ...
}

static struct pci_driver apedev_driver = {
    .name     =  DEVNAME,
    .id_table =  apedev_pci_tbl,
    .probe    =  apedev_init_one,
    .remove   =  __devexit_p(apedev_remove_one),
};


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

* Re: rmmod while module is in use
  2005-02-17 12:47 rmmod while module is in use Davide Rossetti
@ 2005-02-17 13:04 ` linux-os
  2005-02-17 13:11 ` Sean Neakums
  2005-02-17 14:40 ` Zwane Mwaikambo
  2 siblings, 0 replies; 5+ messages in thread
From: linux-os @ 2005-02-17 13:04 UTC (permalink / raw)
  To: Davide Rossetti; +Cc: linux-kernel

On Thu, 17 Feb 2005, Davide Rossetti wrote:

> maybe RTFM...
> a module:
> - char device driver for..
> - a PCI device
>
> any clue as to how to protect from module unloading while there is still some 
> process opening it??? have I to sleep in the remove_one() pci driver function 
> till last process closes its file descriptor???
>

The kernel code is supposed to prevent module removal when it
is still in use. Have you discovered a bug where the kernel
will allow unloading when it's still being used???

There used to be MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT
macros to be using in open() and close(). However their
use has been depreciated in favor of some internal kernel
magic. So, unless you have discovered a bug, your code
doesn't have to worry anymore.

> static void __devexit apedev_remove_one(struct pci_dev *pdev)
> {
>   ApeDev* apedev = pci_get_drvdata(pdev);
>
>   if(test_bit(APEDEV_FLAG_OPEN, &apedev->flags)) {
>       PERROR("still open flag on!!! (flags=0x%08x)\n", apedev->flags);
>
>       // sleep here till it gets closed...
>
>   }
>   ...
> }
>
> static struct pci_driver apedev_driver = {
>   .name     =  DEVNAME,
>   .id_table =  apedev_pci_tbl,
>   .probe    =  apedev_init_one,
>   .remove   =  __devexit_p(apedev_remove_one),
> };
>

Cheers,
Dick Johnson
Penguin : Linux version 2.6.10 on an i686 machine (5537.79 BogoMips).
  Notice : All mail here is now cached for review by Dictator Bush.
                  98.36% of all statistics are fiction.

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

* Re: rmmod while module is in use
  2005-02-17 12:47 rmmod while module is in use Davide Rossetti
  2005-02-17 13:04 ` linux-os
@ 2005-02-17 13:11 ` Sean Neakums
  2005-02-17 14:40 ` Zwane Mwaikambo
  2 siblings, 0 replies; 5+ messages in thread
From: Sean Neakums @ 2005-02-17 13:11 UTC (permalink / raw)
  To: Davide Rossetti; +Cc: linux-kernel

Davide Rossetti <davide.rossetti@roma1.infn.it> writes:

> maybe RTFM...
> a module:
> - char device driver for..
> - a PCI device

Setting the 'owner' field of your char device's file_operations
structure to THIS_MODULE should be sufficient to enable the kernel to
manage the reference count for you.  This is the "magic" referred to
in linux-os's reply.

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

* Re: rmmod while module is in use
  2005-02-17 12:47 rmmod while module is in use Davide Rossetti
  2005-02-17 13:04 ` linux-os
  2005-02-17 13:11 ` Sean Neakums
@ 2005-02-17 14:40 ` Zwane Mwaikambo
  2005-02-17 14:48   ` Zwane Mwaikambo
  2 siblings, 1 reply; 5+ messages in thread
From: Zwane Mwaikambo @ 2005-02-17 14:40 UTC (permalink / raw)
  To: Davide Rossetti; +Cc: linux-kernel

On Thu, 17 Feb 2005, Davide Rossetti wrote:

> maybe RTFM...
> a module:
> - char device driver for..
> - a PCI device
> 
> any clue as to how to protect from module unloading while there is still some
> process opening it??? have I to sleep in the remove_one() pci driver function
> till last process closes its file descriptor???
> 
> static void __devexit apedev_remove_one(struct pci_dev *pdev)
> {
>    ApeDev* apedev = pci_get_drvdata(pdev);
> 
>    if(test_bit(APEDEV_FLAG_OPEN, &apedev->flags)) {
>        PERROR("still open flag on!!! (flags=0x%08x)\n", apedev->flags);
> 
>        // sleep here till it gets closed...
> 
>    }
>    ...
> }
> 
> static struct pci_driver apedev_driver = {
>    .name     =  DEVNAME,
>    .id_table =  apedev_pci_tbl,
>    .probe    =  apedev_init_one,
>    .remove   =  __devexit_p(apedev_remove_one),
> };

Add .module = THIS_MODULE to your file_operations.


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

* Re: rmmod while module is in use
  2005-02-17 14:40 ` Zwane Mwaikambo
@ 2005-02-17 14:48   ` Zwane Mwaikambo
  0 siblings, 0 replies; 5+ messages in thread
From: Zwane Mwaikambo @ 2005-02-17 14:48 UTC (permalink / raw)
  To: Davide Rossetti; +Cc: linux-kernel

On Thu, 17 Feb 2005, Zwane Mwaikambo wrote:

> On Thu, 17 Feb 2005, Davide Rossetti wrote:
> 
> > maybe RTFM...
> > a module:
> > - char device driver for..
> > - a PCI device
> > 
> > any clue as to how to protect from module unloading while there is still some
> > process opening it??? have I to sleep in the remove_one() pci driver function
> > till last process closes its file descriptor???
> > 
> > static void __devexit apedev_remove_one(struct pci_dev *pdev)
> > {
> >    ApeDev* apedev = pci_get_drvdata(pdev);
> > 
> >    if(test_bit(APEDEV_FLAG_OPEN, &apedev->flags)) {
> >        PERROR("still open flag on!!! (flags=0x%08x)\n", apedev->flags);
> > 
> >        // sleep here till it gets closed...
> > 
> >    }
> >    ...
> > }
> > 
> > static struct pci_driver apedev_driver = {
> >    .name     =  DEVNAME,
> >    .id_table =  apedev_pci_tbl,
> >    .probe    =  apedev_init_one,
> >    .remove   =  __devexit_p(apedev_remove_one),
> > };
> 
> Add .module = THIS_MODULE to your file_operations.
      ^^^^^^^

That should be .owner


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

end of thread, other threads:[~2005-02-17 14:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-17 12:47 rmmod while module is in use Davide Rossetti
2005-02-17 13:04 ` linux-os
2005-02-17 13:11 ` Sean Neakums
2005-02-17 14:40 ` Zwane Mwaikambo
2005-02-17 14:48   ` Zwane Mwaikambo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.