On 5/27/07, Robert P. J. Day <rpjday@xxxxxxxxxxxxxx> wrote:
On Fri, 25 May 2007, pradeep singh wrote: > On 5/24/07, Robert P. J. Day <rpjday@xxxxxxxxxxxxxx> wrote: > > > > question about the character device example used in the LDD3 book, > > p. 59, which talks about the "release" method. in suggesting that the > > release method shut down the device on last close, this suggests that > > the code is counting the number of open instances of the device. > > > > what's the best way to do that? the open() routine would obviously > > increment a counter, while release() would decrement it. but where > > would you keep that counter? and you'd obviously need one per inode > > (not one per filp). > > > > what's the cleanest way to do that? thanks. > I guess kref is something you should use here. Isn't it? or am i > missing something here? that might work, but as i'm following the flow of content in LDD3, the kref stuff isn't covered until much later in the book. it quickly occurred to me that you could just add a counter to the scull_dev struct to count the current number of open instances (perhaps even an atomic variable to make sure you didn't have any concurrency problems, although that might be overkill).
In that send you are correct. But using kref is a well tested and faithful API for reference counting with automatic cleanup method defined by the programmer[i.e you :-)]. Just my humble suggestion. Thanks --psr
rday -- ======================================================================== Robert P. J. Day Linux Consulting, Training and Annoying Kernel Pedantry Waterloo, Ontario, CANADA http://fsdev.net/wiki/index.php?title=Main_Page ========================================================================
-- play the game -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ