device driver: cdesw questions?

Kostik Belousov kostikbel at gmail.com
Wed Jan 21 05:35:27 PST 2009


On Wed, Jan 21, 2009 at 01:20:51PM +0200, Andriy Gapon wrote:
> 
> Question 1:
> I am writing a driver that would use per-open private data (among other
> features).
> Do I have to use D_TRACKCLOSE flag in this case?
No, the dtr registered with devfs_set_cdevpriv(), is called exactly once
when the last close is performed, or the device is destroyed.

> In general I am a little bit confused about when d_close is invoked.
> Supposing D_TRACKCLOSE is not set and multiple programs concurrently
> open, use and close a device - when d_close is called - when one program
> closes its last descriptor tied to the device or when the system-wide
> last such descriptor is closed?

D_TRACKCLOSE (attempt to) tracks _file_ close, not filedescriptor close.
This actually becomes quite messed up when revoke(2) or forced unmounts
of the devfs mount points are mixed in.

> 
> Question 2:
> I also would like the driver to provide a select capability quite
> similar to that of network (e.g. TCP) sockets using d_poll. I.e. a
> userland program should be able to query when it can write data to the
> device without blocking and when it can read data without blocking, plus
> when an error occurred in the device/driver, so there is no point in
> further waiting.
> At this moment I am thoroughly confused by meaning of various event
> masks described in poll(2).  E.g. what is normal priority, non-zero
> priority and high priority.
poll(2) comes from the Streams, where the messages in the queues do
have priorities. See getmsgp(2) on Solaris for the start.
Most likely, you do not need any priorities except POLLXXNORM, and
FreeBSD uses POLLRDBAND for OOB TCP data only.

> Which flags should I care about if all data is the same priority for me?
> Which flag(s) should I set when I'd like to communicate an error
> condition (e.g. similar to TCP connection reset)?
I believe, it is a POLLHUP.

See the sys_pipe.c, pipe_poll() for the rather clean example of the
poll handler.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20090121/a5485a99/attachment.pgp


More information about the freebsd-hackers mailing list