Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Nov 2000 20:33:33 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        rizzo@aciri.org (Luigi Rizzo)
Cc:        bschwand@dvart.com (bruno schwander), freebsd-hackers@FreeBSD.ORG
Subject:   Re: close call in a device ?
Message-ID:  <200011082033.NAA25455@usr08.primenet.com>
In-Reply-To: <200011080157.RAA00555@iguana.aciri.org> from "Luigi Rizzo" at Nov 07, 2000 05:57:02 PM

next in thread | previous in thread | raw e-mail | index | archive | help
> > when a process closes the device, I do not get a "close" call for each
> > process closing the device. I instead get a close only on the last
> > process closing the device.
> 
> the reason for this is that you might have a process fork() after
> it has opened the device, and you do not want to get to the
> device all close calls from all processes generated by the original
> one, but really only the last instance.
> 
> The thing is, i think your model (allocating per-user resources on
> open) is wrong. It cannot protect you from a process forking
> and then having two instances using the same device.
> 
> If you want multiple instances of the device, one option could be
> to use the minor number and really create multiple instances
> of the device, and open them in exclusive way so you know that
> there can be only one open per device (you should scan available
> devices in a similar way as the one is used for scanning pty's).

To add to this, the close calls can be forces; there is a flag
in the device structure wich can force notification.  I'm not
sure what it does over a fork(), though: I think you really want
open notification.

The main problem with per process resources is that the VFS that
implements devices, specfs, doesn't own its own vnodes.

This is actually the primary reason that VMWARE can only run
one instance at a time of a virtual machine: there is no way
to have per open instance resources, which are not shared.

If you were to use the TFS flag (grep for TFS in the headers,
that's a substring), you could make specfs own its own vnodes.

The way you would handle your problem then is by returning a
different instance of the device, with a different instance of
per process attached storage.  It's pretty simple to do this:
just return a different vnode for the next open of the same
device, instead of the same vnode with an additional reference.

You will have to worry about close tracking in this case, as
well.  Other potential pitfalls are the directory name lookup
cache returning a cached reference to the vnode from the last
open (you will need to disable it), and the fork() and decriptor
passing (using UNIX domain sockets) mechanisms, since what they
return is a reference to the same reference, instead of a
reference to a seperate, new reference (look at the per process
open file table code to understand this).

NB: If you are trying to do this for VMWARE or some other binary
code, there's no way that the pty opening soloution suggested in
the previous posting will be able to work for you, since the code
will expect a particular behaviour.  Right now, FreeBSD doesn't
support this behaviour (cloning devices), but as pointed out
above, it's not hard to implement, it's mostly just labor
intensive.


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.


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?200011082033.NAA25455>