Date: Wed, 16 Oct 1996 06:22:23 +1000 From: Bruce Evans <bde@zeta.org.au> To: current@freebsd.org, phk@critter.tfs.com Subject: Re: device driver open/close inconsistency Message-ID: <199610152022.GAA21446@godzilla.zeta.org.au>
next in thread | raw e-mail | index | archive | help
>Why do we call a device-driver->open() on all opens, but only ->close() >once on the last close ? Because it's easier to count references in vfs than in hundreds of drivers. The device close function would also need to be called on all dup()s and implicit dup()s for fork()s to give it a chance of counting references. There is also an extra reference for controlling terminals. There are also complications for /dev/tty. Unfortunately, it's hard to count references properly in vfs too: Bug 1: the reference count is incremented before calling the device open function, so processes sleeping in open are effectively counted as successful opens. Suppose there is a process sleeping in open and another process opens the device, does some ioctls to mess up the device state, and closes the device. Then it is necessary to call the device close function to clean up and kick the process sleeping in open, but the device close function is never called because the reference count is always >= 1. I believe this is (mis)handled in some versions of **ix by not allowing processes to sleep in open when another open of the same device to complete. This causes other problems. O_NONBLOCK is per-open, so I think it is wrong to let a !O_NOBLOCK open succeed in the presences of the blocking condition just because another process has done a successful open using O_NOBLOCK. Bug 2: It is difficult to get rid of controlling terminals. In 4.4Lite, exiting was the only way. Thus device close functions for controlliing terminals were never called until exit. In 4.4Lite2 and most versions of FreeBSD-2.x, the controlling terminal can be changed using TIOCSCTTY. Bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199610152022.GAA21446>