[Midnightbsd-cvs] src [8547] trunk/sys: fix how we handle v_writecount

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Mon Sep 19 10:03:01 EDT 2016


Revision: 8547
          http://svnweb.midnightbsd.org/src/?rev=8547
Author:   laffer1
Date:     2016-09-19 10:03:00 -0400 (Mon, 19 Sep 2016)
Log Message:
-----------
 fix how we handle v_writecount

Modified Paths:
--------------
    trunk/sys/compat/linux/linux_misc.c
    trunk/sys/fs/nullfs/null_vnops.c
    trunk/sys/fs/unionfs/union_subr.c
    trunk/sys/kern/kern_exec.c
    trunk/sys/kern/vfs_default.c
    trunk/sys/kern/vfs_vnops.c
    trunk/sys/kern/vnode_if.src
    trunk/sys/ufs/ufs/ufs_extattr.c
    trunk/sys/vm/vnode_pager.c

Modified: trunk/sys/compat/linux/linux_misc.c
===================================================================
--- trunk/sys/compat/linux/linux_misc.c	2016-09-19 14:02:17 UTC (rev 8546)
+++ trunk/sys/compat/linux/linux_misc.c	2016-09-19 14:03:00 UTC (rev 8547)
@@ -233,8 +233,7 @@
 	unsigned long bss_size;
 	char *library;
 	ssize_t aresid;
-	int error;
-	int locked, vfslocked;
+	int error, locked, vfslocked, writecount;
 
 	LCONVPATHEXIST(td, args->library, &library);
 
@@ -266,7 +265,10 @@
 	locked = 1;
 
 	/* Writable? */
-	if (vp->v_writecount) {
+	error = VOP_GET_WRITECOUNT(vp, &writecount);
+	if (error != 0)
+		goto cleanup;
+	if (writecount != 0) {
 		error = ETXTBSY;
 		goto cleanup;
 	}

Modified: trunk/sys/fs/nullfs/null_vnops.c
===================================================================
--- trunk/sys/fs/nullfs/null_vnops.c	2016-09-19 14:02:17 UTC (rev 8546)
+++ trunk/sys/fs/nullfs/null_vnops.c	2016-09-19 14:03:00 UTC (rev 8547)
@@ -329,6 +329,26 @@
 	return (error);
 }
 
+static int
+null_add_writecount(struct vop_add_writecount_args *ap)
+{
+	struct vnode *lvp, *vp;
+	int error;
+
+	vp = ap->a_vp;
+	lvp = NULLVPTOLOWERVP(vp);
+	KASSERT(vp->v_writecount + ap->a_inc >= 0, ("wrong writecount inc"));
+	if (vp->v_writecount > 0 && vp->v_writecount + ap->a_inc == 0)
+		error = VOP_ADD_WRITECOUNT(lvp, -1);
+	else if (vp->v_writecount == 0 && vp->v_writecount + ap->a_inc > 0)
+		error = VOP_ADD_WRITECOUNT(lvp, 1);
+	else
+		error = 0;
+	if (error == 0)
+		vp->v_writecount += ap->a_inc;
+	return (error);
+}
+
 /*
  * We have to carry on the locking protocol on the null layer vnodes
  * as we progress through the tree. We also have to enforce read-only
@@ -836,4 +856,5 @@
 	.vop_unlock =		null_unlock,
 	.vop_vptocnp =		null_vptocnp,
 	.vop_vptofh =		null_vptofh,
+	.vop_add_writecount =	null_add_writecount,
 };

Modified: trunk/sys/fs/unionfs/union_subr.c
===================================================================
--- trunk/sys/fs/unionfs/union_subr.c	2016-09-19 14:02:17 UTC (rev 8546)
+++ trunk/sys/fs/unionfs/union_subr.c	2016-09-19 14:03:00 UTC (rev 8547)
@@ -954,7 +954,7 @@
 		vput(vp);
 		goto unionfs_vn_create_on_upper_free_out1;
 	}
-	vp->v_writecount++;
+	VOP_ADD_WRITECOUNT(vp, 1);
 	*vpp = vp;
 
 unionfs_vn_create_on_upper_free_out1:
@@ -1089,7 +1089,7 @@
 		}
 	}
 	VOP_CLOSE(uvp, FWRITE, cred, td);
-	uvp->v_writecount--;
+	VOP_ADD_WRITECOUNT(uvp, -1);
 
 	vn_finished_write(mp);
 

Modified: trunk/sys/kern/kern_exec.c
===================================================================
--- trunk/sys/kern/kern_exec.c	2016-09-19 14:02:17 UTC (rev 8546)
+++ trunk/sys/kern/kern_exec.c	2016-09-19 14:03:00 UTC (rev 8547)
@@ -1393,7 +1393,7 @@
 	struct vnode *vp = imgp->vp;
 	struct vattr *attr = imgp->attr;
 	struct thread *td;
-	int error;
+	int error, writecount;
 
 	td = curthread;
 
@@ -1438,7 +1438,10 @@
 	 * Check number of open-for-writes on the file and deny execution
 	 * if there are any.
 	 */
-	if (vp->v_writecount)
+	error = VOP_GET_WRITECOUNT(vp, &writecount);
+	if (error != 0)
+		return (error);
+	if (writecount != 0)
 		return (ETXTBSY);
 
 	/*

Modified: trunk/sys/kern/vfs_default.c
===================================================================
--- trunk/sys/kern/vfs_default.c	2016-09-19 14:02:17 UTC (rev 8546)
+++ trunk/sys/kern/vfs_default.c	2016-09-19 14:03:00 UTC (rev 8547)
@@ -81,6 +81,8 @@
 static int vop_stdis_text(struct vop_is_text_args *ap);
 static int vop_stdset_text(struct vop_set_text_args *ap);
 static int vop_stdunset_text(struct vop_unset_text_args *ap);
+static int vop_stdget_writecount(struct vop_get_writecount_args *ap);
+static int vop_stdadd_writecount(struct vop_add_writecount_args *ap);
 
 /*
  * This vnode table stores what we want to do if the filesystem doesn't
@@ -133,6 +135,8 @@
 	.vop_is_text =		vop_stdis_text,
 	.vop_set_text =		vop_stdset_text,
 	.vop_unset_text =	vop_stdunset_text,
+	.vop_get_writecount =	vop_stdget_writecount,
+	.vop_add_writecount =	vop_stdadd_writecount,
 };
 
 /*
@@ -1103,6 +1107,22 @@
 	return (0);
 }
 
+static int
+vop_stdget_writecount(struct vop_get_writecount_args *ap)
+{
+
+	*ap->a_writecount = ap->a_vp->v_writecount;
+	return (0);
+}
+
+static int
+vop_stdadd_writecount(struct vop_add_writecount_args *ap)
+{
+
+	ap->a_vp->v_writecount += ap->a_inc;
+	return (0);
+}
+
 /*
  * vfs default ops
  * used to fill the vfs function table to get reasonable default return values.

Modified: trunk/sys/kern/vfs_vnops.c
===================================================================
--- trunk/sys/kern/vfs_vnops.c	2016-09-19 14:02:17 UTC (rev 8546)
+++ trunk/sys/kern/vfs_vnops.c	2016-09-19 14:03:00 UTC (rev 8547)
@@ -252,7 +252,7 @@
 		goto bad;
 
 	if (fmode & FWRITE)
-		vp->v_writecount++;
+		VOP_ADD_WRITECOUNT(vp, 1);
 	*flagp = fmode;
 	ASSERT_VOP_LOCKED(vp, "vn_open_cred");
 	if (!mpsafe)
@@ -314,7 +314,7 @@
 	if (flags & FWRITE) {
 		VNASSERT(vp->v_writecount > 0, vp, 
 		    ("vn_close: negative writecount"));
-		vp->v_writecount--;
+		VOP_ADD_WRITECOUNT(vp, -1);
 	}
 	error = VOP_CLOSE(vp, flags, file_cred, td);
 	vput(vp);

Modified: trunk/sys/kern/vnode_if.src
===================================================================
--- trunk/sys/kern/vnode_if.src	2016-09-19 14:02:17 UTC (rev 8546)
+++ trunk/sys/kern/vnode_if.src	2016-09-19 14:03:00 UTC (rev 8547)
@@ -690,6 +690,20 @@
 	IN struct vnode *vp;
 };
 
+%% get_writecount	vp	L L L
+
+vop_get_writecount {
+	IN struct vnode *vp;
+	OUT int *writecount;
+};
+
+%% add_writecount	vp	E E E
+
+vop_add_writecount {
+	IN struct vnode *vp;
+	IN int inc;
+};
+
 # The VOPs below are spares at the end of the table to allow new VOPs to be
 # added in stable branches without breaking the KBI.  New VOPs in HEAD should
 # be added above these spares.  When merging a new VOP to a stable branch,

Modified: trunk/sys/ufs/ufs/ufs_extattr.c
===================================================================
--- trunk/sys/ufs/ufs/ufs_extattr.c	2016-09-19 14:02:17 UTC (rev 8546)
+++ trunk/sys/ufs/ufs/ufs_extattr.c	2016-09-19 14:03:00 UTC (rev 8547)
@@ -334,7 +334,7 @@
 		return (error);
 	}
 
-	vp->v_writecount++;
+	VOP_ADD_WRITECOUNT(vp, 1);
 
 	vref(vp);
 

Modified: trunk/sys/vm/vnode_pager.c
===================================================================
--- trunk/sys/vm/vnode_pager.c	2016-09-19 14:02:17 UTC (rev 8546)
+++ trunk/sys/vm/vnode_pager.c	2016-09-19 14:03:00 UTC (rev 8547)
@@ -272,7 +272,7 @@
 	ASSERT_VOP_ELOCKED(vp, "vnode_pager_dealloc");
 	if (object->un_pager.vnp.writemappings > 0) {
 		object->un_pager.vnp.writemappings = 0;
-		vp->v_writecount--;
+		VOP_ADD_WRITECOUNT(vp, -1);
 	}
 	vp->v_object = NULL;
 	VOP_UNSET_TEXT(vp);
@@ -1216,10 +1216,10 @@
 	vp = object->handle;
 	if (old_wm == 0 && object->un_pager.vnp.writemappings != 0) {
 		ASSERT_VOP_ELOCKED(vp, "v_writecount inc");
-		vp->v_writecount++;
+		VOP_ADD_WRITECOUNT(vp, 1);
 	} else if (old_wm != 0 && object->un_pager.vnp.writemappings == 0) {
 		ASSERT_VOP_ELOCKED(vp, "v_writecount dec");
-		vp->v_writecount--;
+		VOP_ADD_WRITECOUNT(vp, -1);
 	}
 	VM_OBJECT_UNLOCK(object);
 }



More information about the Midnightbsd-cvs mailing list