Re: open() and close() from multithread application
Beesdeckar <[email protected]> Wed, 11 Mar 2026 20:10:34 +0100
| Newsgroups | gmane.os.netbsd.devel.kernel |
|---|---|
| Message-ID | <[email protected]> |
On 08-Mar-26 12:10 PM, J. Hannken-Illjes wrote: >> On 7. Mar 2026, at 18:59, Beesdeckar <[email protected]> wrote: >> >> Hello, >> >> I have application with three threads, second and third threads are created with pthread_create(). >> In kernel module my d_open and d_close handlers contains reference count incrementing in d_open and decrementing in d_close handler. >> All is right in several first sequences open(), ioctl(), close() . >> These sequences can be called from all three threads simultaneously. >> After some time module comes to state that d_close is never reached when called close(), I checked close() in user-mode debugger and it returns always 0. >> I am sure that d_close is not called I don't see my printf() output, >> but I see all another d_open calls, and when checked my reference count >> it is on every d_open incremented and never decremented. >> >> What to investigate to find why d_close handler is not called ? >> I use kernel with enabled DIAGNOSTIC, DEBUG, LOCKDEBUG. > > Suppose d_open() gets called on every open while d_close() only gets called on last close. > > -- > J. Hannken-Illjes - [email protected] I put this question to find how to implement reference counting in kernel module. I want to return EBUSY to modunload if some user-mode app has device opened and calls ioctl(). Does exist some way how to force calling d_close on every close() ? Or does exist way how to retrieve some OS internal reference count for kernel module ?