Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/miscfs Handle v_writecount from layer_open(), layer_clos...
details: https://anonhg.NetBSD.org/src/rev/817e72b04d82
branches: trunk
changeset: 350929:817e72b04d82
user: hannken <hannken%NetBSD.org@localhost>
date: Fri Jan 27 10:47:13 2017 +0000
description:
Handle v_writecount from layer_open(), layer_close() and layer_revoke()
so lower file system vnodes get marked as open for writing.
diffstat:
sys/miscfs/genfs/layer_extern.h | 3 +-
sys/miscfs/genfs/layer_vnops.c | 50 ++++++++++++++++++++++++++++++++++---
sys/miscfs/nullfs/null_vnops.c | 5 ++-
sys/miscfs/overlay/overlay_vnops.c | 7 +++--
sys/miscfs/umapfs/umap_vnops.c | 5 ++-
5 files changed, 57 insertions(+), 13 deletions(-)
diffs (202 lines):
diff -r 68a56894211a -r 817e72b04d82 sys/miscfs/genfs/layer_extern.h
--- a/sys/miscfs/genfs/layer_extern.h Fri Jan 27 10:46:18 2017 +0000
+++ b/sys/miscfs/genfs/layer_extern.h Fri Jan 27 10:47:13 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: layer_extern.h,v 1.36 2014/05/25 13:51:25 hannken Exp $ */
+/* $NetBSD: layer_extern.h,v 1.37 2017/01/27 10:47:13 hannken Exp $ */
/*
* Copyright (c) 1999 National Aeronautics & Space Administration
@@ -106,6 +106,7 @@
int layer_setattr(void *);
int layer_access(void *);
int layer_open(void *);
+int layer_close(void *);
int layer_remove(void *);
int layer_rename(void *);
int layer_revoke(void *);
diff -r 68a56894211a -r 817e72b04d82 sys/miscfs/genfs/layer_vnops.c
--- a/sys/miscfs/genfs/layer_vnops.c Fri Jan 27 10:46:18 2017 +0000
+++ b/sys/miscfs/genfs/layer_vnops.c Fri Jan 27 10:47:13 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: layer_vnops.c,v 1.59 2016/08/20 12:37:09 hannken Exp $ */
+/* $NetBSD: layer_vnops.c,v 1.60 2017/01/27 10:47:13 hannken Exp $ */
/*
* Copyright (c) 1999 National Aeronautics & Space Administration
@@ -170,7 +170,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: layer_vnops.c,v 1.59 2016/08/20 12:37:09 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: layer_vnops.c,v 1.60 2017/01/27 10:47:13 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -182,6 +182,7 @@
#include <sys/kmem.h>
#include <sys/buf.h>
#include <sys/kauth.h>
+#include <sys/fcntl.h>
#include <miscfs/genfs/layer.h>
#include <miscfs/genfs/layer_extern.h>
@@ -491,7 +492,8 @@
}
/*
- * We must handle open to be able to catch MNT_NODEV and friends.
+ * We must handle open to be able to catch MNT_NODEV and friends
+ * and increment the lower v_writecount.
*/
int
layer_open(void *v)
@@ -503,12 +505,43 @@
kauth_cred_t a_cred;
} */ *ap = v;
struct vnode *vp = ap->a_vp;
- enum vtype lower_type = LAYERVPTOLOWERVP(vp)->v_type;
+ struct vnode *lvp = LAYERVPTOLOWERVP(vp);
+ int error;
- if (((lower_type == VBLK) || (lower_type == VCHR)) &&
+ if (((lvp->v_type == VBLK) || (lvp->v_type == VCHR)) &&
(vp->v_mount->mnt_flag & MNT_NODEV))
return ENXIO;
+ error = LAYERFS_DO_BYPASS(vp, ap);
+ if (error == 0 && (ap->a_mode & FWRITE)) {
+ mutex_enter(lvp->v_interlock);
+ lvp->v_writecount++;
+ mutex_exit(lvp->v_interlock);
+ }
+ return error;
+}
+
+/*
+ * We must handle close to decrement the lower v_writecount.
+ */
+int
+layer_close(void *v)
+{
+ struct vop_close_args /* {
+ const struct vnodeop_desc *a_desc;
+ struct vnode *a_vp;
+ int a_fflag;
+ kauth_cred_t a_cred;
+ } */ *ap = v;
+ struct vnode *vp = ap->a_vp;
+ struct vnode *lvp = LAYERVPTOLOWERVP(vp);
+
+ if ((ap->a_fflag & FWRITE)) {
+ mutex_enter(lvp->v_interlock);
+ KASSERT(lvp->v_writecount > 0);
+ lvp->v_writecount--;
+ mutex_exit(lvp->v_interlock);
+ }
return LAYERFS_DO_BYPASS(vp, ap);
}
@@ -660,8 +693,15 @@
* We will most likely end up in vclean which uses the v_usecount
* to determine if a vnode is active. Take an extra reference on
* the lower vnode so it will always close and inactivate.
+ * Remove our writecount from the lower vnode.
*/
vref(lvp);
+
+ mutex_enter(vp->v_interlock);
+ KASSERT(vp->v_interlock == lvp->v_interlock);
+ lvp->v_writecount -= vp->v_writecount;
+ mutex_exit(vp->v_interlock);
+
error = LAYERFS_DO_BYPASS(vp, ap);
vrele(lvp);
diff -r 68a56894211a -r 817e72b04d82 sys/miscfs/nullfs/null_vnops.c
--- a/sys/miscfs/nullfs/null_vnops.c Fri Jan 27 10:46:18 2017 +0000
+++ b/sys/miscfs/nullfs/null_vnops.c Fri Jan 27 10:47:13 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: null_vnops.c,v 1.39 2014/02/27 16:51:38 hannken Exp $ */
+/* $NetBSD: null_vnops.c,v 1.40 2017/01/27 10:47:13 hannken Exp $ */
/*
* Copyright (c) 1999 National Aeronautics & Space Administration
@@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: null_vnops.c,v 1.39 2014/02/27 16:51:38 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: null_vnops.c,v 1.40 2017/01/27 10:47:13 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -114,6 +114,7 @@
{ &vop_rmdir_desc, layer_rmdir },
{ &vop_open_desc, layer_open }, /* mount option handling */
+ { &vop_close_desc, layer_close },
{ &vop_bmap_desc, layer_bmap },
{ &vop_getpages_desc, layer_getpages },
diff -r 68a56894211a -r 817e72b04d82 sys/miscfs/overlay/overlay_vnops.c
--- a/sys/miscfs/overlay/overlay_vnops.c Fri Jan 27 10:46:18 2017 +0000
+++ b/sys/miscfs/overlay/overlay_vnops.c Fri Jan 27 10:47:13 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: overlay_vnops.c,v 1.21 2014/11/10 18:46:33 maxv Exp $ */
+/* $NetBSD: overlay_vnops.c,v 1.22 2017/01/27 10:47:13 hannken Exp $ */
/*
* Copyright (c) 1999, 2000 National Aeronautics & Space Administration
@@ -67,7 +67,7 @@
*
* Ancestors:
* @(#)lofs_vnops.c 1.2 (Berkeley) 6/18/92
- * $Id: overlay_vnops.c,v 1.21 2014/11/10 18:46:33 maxv Exp $
+ * $Id: overlay_vnops.c,v 1.22 2017/01/27 10:47:13 hannken Exp $
* ...and...
* @(#)null_vnodeops.c 1.20 92/07/07 UCLA Ficus project
*/
@@ -126,7 +126,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: overlay_vnops.c,v 1.21 2014/11/10 18:46:33 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: overlay_vnops.c,v 1.22 2017/01/27 10:47:13 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -162,6 +162,7 @@
{ &vop_rmdir_desc, layer_rmdir },
{ &vop_open_desc, layer_open }, /* mount option handling */
+ { &vop_close_desc, layer_close },
{ &vop_bmap_desc, layer_bmap },
{ &vop_getpages_desc, layer_getpages },
diff -r 68a56894211a -r 817e72b04d82 sys/miscfs/umapfs/umap_vnops.c
--- a/sys/miscfs/umapfs/umap_vnops.c Fri Jan 27 10:46:18 2017 +0000
+++ b/sys/miscfs/umapfs/umap_vnops.c Fri Jan 27 10:47:13 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: umap_vnops.c,v 1.57 2014/11/09 18:08:07 maxv Exp $ */
+/* $NetBSD: umap_vnops.c,v 1.58 2017/01/27 10:47:13 hannken Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umap_vnops.c,v 1.57 2014/11/09 18:08:07 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umap_vnops.c,v 1.58 2017/01/27 10:47:13 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -90,6 +90,7 @@
{ &vop_reclaim_desc, layer_reclaim },
{ &vop_lock_desc, layer_lock },
{ &vop_open_desc, layer_open },
+ { &vop_close_desc, layer_close },
{ &vop_setattr_desc, layer_setattr },
{ &vop_access_desc, layer_access },
{ &vop_remove_desc, layer_remove },
Home |
Main Index |
Thread Index |
Old Index