Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 08 Dec 2001 04:16:14 -0800
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Poul-Henning Kamp <phk@critter.freebsd.dk>
Cc:        Dave Rufino <dr263@hermes.cam.ac.uk>, Alfred Perlstein <bright@mu.org>, freebsd-hackers@FreeBSD.ORG
Subject:   Re: statefulness in character device drivers
Message-ID:  <3C12048E.9DB7EB7D@mindspring.com>
References:  <47779.1007808692@critter.freebsd.dk>

next in thread | previous in thread | raw e-mail | index | archive | help
Poul-Henning Kamp wrote:
> >> The issue is non-trivial to fix because we currently don't pass
> >> dup(2) events through the vnode layer.
> >
> >Are you sure this is even necessary?
> >
> >They are talking about "per-open", not "per-fd-instance" data,
> >which could easily exclude dup, dup2, and fcntl(f_DUPFD).
> 
> If you don't include dup/dup2/fnctl in your accounting, you
> can only reliably tell "first open", "another open", "some close"
> and "final close".  You an modulate this with the pid, but you
> still have no idea what is going on in any amount of detail.

My point was not that you would not do reference counting, but
that you would have unique information in only the open(2) case
(as you point out, these other cases don't call down to the
vnode).

So if I open(2) and then dup(2), I have only one per-open instance
with a reference count of 2, but if I then open(2) again, I get a
second open instance, so I have a total open instance of 2, with
reference counts of 2 and 1, respectively.

If I close one of the first instances (either the result of the
open or the dup), then my reference count goes to 1, and then if
I close the second (the remaining one, the result of the dup or
the open), then when the reference count goes from 1 to 0, I
destroy the per instance data.

There is actually a good argument for doing things this way,
since it permits particular instances to be passed to other
programs, whereas if each dup/dup2/F_DUPFD resulted in a new
instance, you wouldn't be able to pass the instance to another
program (since it, effectively, dup's the fd).

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3C12048E.9DB7EB7D>