Device layering work patch #4
Matthew Dillon
dillon at apollo.backplane.com
Mon May 17 18:13:56 PDT 2004
Here's device patch #4:
fetch http://apollo.backplane.com/DFlyMisc/dev04.patch
This patch fixes the issue that Joerg brought up... nice and neat,
in fact! And, as an added bonus, it fixes a USB panic as a side effect.
* cdevsw_add() and cdevsw_remove() now take a minor number mask and match,
allowing devices to use these functions on a unit-by-unit basis.
* dev_t reference counting should now be quite solid. Note that
ref count debugging is enabled on this patch so you will get a lot
of console messages.
* The VNODE subsystem was assuming that the dev_t descriptor it caches
in vp->v_rdev will *always* represent the specific (major,minor).
This does not take into account the case where a device might go
away or, worse, go away and come back.
e.g. if a program has an open descriptor on a device, the kernel will
have called the device open function on the device. But if the device
goes away and then comes back (unplug USB device then plug it back in),
the device state will be reset, the dev_t will become valid again,
but the vnode subsystem will still believe the device to be open.
Or, worse, if a device detaches and a different device or
a device representing a different peripheral attaches to the same
(major,minor), all hell can break lose.
To fix this problem, we now only cache the UDEV in the vnode long
term. v_rdev is only initialized when the vnode is actually opened,
and it is cleared when the vnode is closed.
* Devices detach when the device backend destroys them. All further
operations on open descriptors will fail, even if the device is
reattached later.
This isn't quite working the way I want it to... *all* references to
the vnode must go away for the vnode to reload a new device descriptor.
You can't simply open("/dev/...", ...) again if another program is
still holding an open descriptor on that device.
(revoke() should still work properly but I haven't checked it).
-Matt
More information about the Kernel
mailing list