From 5971791c189c2ddb0bee3aadd934e064d60bf299 Mon Sep 17 00:00:00 2001 From: kib Date: Wed, 21 May 2008 09:31:44 +0000 Subject: 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 --- sys/kern/kern_conf.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'sys/kern/kern_conf.c') 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; -- cgit v1.1