tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Locking strategy for device deletion (also see PR kern/48536)



On Wed, 8 Jun 2016, Robert Elz wrote:

   Date:        Wed, 8 Jun 2016 22:16:28 +0800 (PHT)
   From:        Paul Goyette <paul%whooppee.com@localhost>
   Message-ID:  <Pine.NEB.4.64.1606082214090.1631%pokey.whooppee.com@localhost>

 | Hmmm.  Would it be valid, then, for my close() routine to reset the
 | ref-count to zero rather than simply decrementing?

Do you really need a reference count for anything?   Wasn't that just
a way of determining whether anything had the device open?

Correct. The test I need to make is "Is this device being used by anyone?" I don't really care how many anyones, only zero vs non-zero.

This is why device drivers have just an open flag in their private state
(when they care enough to have even that.)

 | Does the close() only get called if there are _NO_ outstanding open()s
 | for _any_ process?

Processes, yes, processes are irrelevant at this level.   There was once
(long ago) an issue when multiple inodes (vnodes now) referenced the same
device, the close would get called when the vnode ref count went to 0
(not caring that another might still be referencing the device.)   I hope
that bug has been long fixed...  (if not, it should be.)

But close routines can do stuff like resetting the hardware, rewinding a tape,
dropping DTR to a modem, ...   so there are plenty of reasons to make sure
that the close is only called when it really should be.

Kewl.  Thanks!


+------------------+--------------------------+------------------------+
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:      |
| (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com   |
| Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd.org |
+------------------+--------------------------+------------------------+


Home | Main Index | Thread Index | Old Index