summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_conf.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2008-05-21 09:31:44 +0000
committerkib <kib@FreeBSD.org>2008-05-21 09:31:44 +0000
commit5971791c189c2ddb0bee3aadd934e064d60bf299 (patch)
treed53ea3307f3403eee99e9e7722a901bbe968da35 /sys/kern/kern_conf.c
parent24431c62bbd3a2bf725a240b11c756552e0fa3ff (diff)
downloadFreeBSD-src-5971791c189c2ddb0bee3aadd934e064d60bf299.zip
FreeBSD-src-5971791c189c2ddb0bee3aadd934e064d60bf299.tar.gz
Implement the per-open file data for the cdev.
The patch does not change the cdevsw KBI. Management of the data is provided by the functions int devfs_set_cdevpriv(void *priv, cdevpriv_dtr_t dtr); int devfs_get_cdevpriv(void **datap); void devfs_clear_cdevpriv(void); All of the functions are supposed to be called from the cdevsw method contexts. - devfs_set_cdevpriv assigns the priv as private data for the file descriptor which is used to initiate currently performed driver operation. dtr is the function that will be called when either the last refernce to the file goes away, the device is destroyed or devfs_clear_cdevpriv is called. - devfs_get_cdevpriv is the obvious accessor. - devfs_clear_cdevpriv allows to clear the private data for the still open file. Implementation keeps the driver-supplied pointers in the struct cdev_privdata, that is referenced both from the struct file and struct cdev, and cannot outlive any of the referee. Man pages will be provided after the KPI stabilizes. Reviewed by: jhb Useful suggestions from: jeff, antoine Debugging help and tested by: pho MFC after: 1 month
Diffstat (limited to 'sys/kern/kern_conf.c')
-rw-r--r--sys/kern/kern_conf.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c
index f8e7a10..0e4aa22 100644
--- a/sys/kern/kern_conf.c
+++ b/sys/kern/kern_conf.c
@@ -839,6 +839,7 @@ static void
destroy_devl(struct cdev *dev)
{
struct cdevsw *csw;
+ struct cdev_privdata *p, *p1;
mtx_assert(&devmtx, MA_OWNED);
KASSERT(dev->si_flags & SI_NAMED,
@@ -880,9 +881,15 @@ destroy_devl(struct cdev *dev)
msleep(&csw, &devmtx, PRIBIO, "devdrn", hz / 10);
}
- mtx_unlock(&devmtx);
+ dev_unlock();
notify_destroy(dev);
- mtx_lock(&devmtx);
+ mtx_lock(&cdevpriv_mtx);
+ LIST_FOREACH_SAFE(p, &dev->si_priv->cdp_fdpriv, cdpd_list, p1) {
+ devfs_destroy_cdevpriv(p);
+ mtx_lock(&cdevpriv_mtx);
+ }
+ mtx_unlock(&cdevpriv_mtx);
+ dev_lock();
dev->si_drv1 = 0;
dev->si_drv2 = 0;
OpenPOWER on IntegriCloud