summaryrefslogtreecommitdiffstats
path: root/sys/fs
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2015-12-22 20:37:34 +0000
committerkib <kib@FreeBSD.org>2015-12-22 20:37:34 +0000
commit76abdf80abd52cbd12cc65ecf3dde21790190789 (patch)
treee2a5d62f098471bcf5bafa2b393dd67bf0fadc43 /sys/fs
parent3808bf980c2c46dcb44722f214c1d89db5b6c04d (diff)
downloadFreeBSD-src-76abdf80abd52cbd12cc65ecf3dde21790190789.zip
FreeBSD-src-76abdf80abd52cbd12cc65ecf3dde21790190789.tar.gz
Make it possible for the cdevsw d_close() driver method to detect last
close and close due to revoke(2)-like operation. A new FLASTCLOSE flag indicates that this is last close. FREVOKE is set for revokes, and FNONBLOCK is also set, same as is already done for VOP_CLOSE() call from vgonel(). The flags reuse user open(2) flags which are never stored in f_flag, to not consume bit space in the ABI visible way. Assert this with the static check. Requested and reviewed by: bde Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
Diffstat (limited to 'sys/fs')
-rw-r--r--sys/fs/devfs/devfs_vnops.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c
index 5a49a9e..eb2f98a 100644
--- a/sys/fs/devfs/devfs_vnops.c
+++ b/sys/fs/devfs/devfs_vnops.c
@@ -557,7 +557,9 @@ devfs_access(struct vop_access_args *ap)
return (error);
}
-/* ARGSUSED */
+_Static_assert(((FMASK | FCNTLFLAGS) & (FLASTCLOSE | FREVOKE)) == 0,
+ "devfs-only flag reuse failed");
+
static int
devfs_close(struct vop_close_args *ap)
{
@@ -566,7 +568,7 @@ devfs_close(struct vop_close_args *ap)
struct proc *p;
struct cdev *dev = vp->v_rdev;
struct cdevsw *dsw;
- int vp_locked, error, ref;
+ int dflags, error, ref, vp_locked;
/*
* XXX: Don't call d_close() if we were called because of
@@ -621,9 +623,11 @@ devfs_close(struct vop_close_args *ap)
dsw = dev_refthread(dev, &ref);
if (dsw == NULL)
return (ENXIO);
+ dflags = 0;
VI_LOCK(vp);
if (vp->v_iflag & VI_DOOMED) {
/* Forced close. */
+ dflags |= FREVOKE | FNONBLOCK;
} else if (dsw->d_flags & D_TRACKCLOSE) {
/* Keep device updated on status. */
} else if (count_dev(dev) > 1) {
@@ -631,13 +635,15 @@ devfs_close(struct vop_close_args *ap)
dev_relthread(dev, ref);
return (0);
}
+ if (count_dev(dev) == 1)
+ dflags |= FLASTCLOSE;
vholdl(vp);
VI_UNLOCK(vp);
vp_locked = VOP_ISLOCKED(vp);
VOP_UNLOCK(vp, 0);
KASSERT(dev->si_refcount > 0,
("devfs_close() on un-referenced struct cdev *(%s)", devtoname(dev)));
- error = dsw->d_close(dev, ap->a_fflag, S_IFCHR, td);
+ error = dsw->d_close(dev, ap->a_fflag | dflags, S_IFCHR, td);
dev_relthread(dev, ref);
vn_lock(vp, vp_locked | LK_RETRY);
vdrop(vp);
OpenPOWER on IntegriCloud