Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Add "FSTRANS=LOCK" and "FSTRANS=UNLOCK" to vop_lock...
details: https://anonhg.NetBSD.org/src/rev/074316e46302
branches: trunk
changeset: 354103:074316e46302
user: hannken <hannken%NetBSD.org@localhost>
date: Sun Jun 04 07:59:17 2017 +0000
description:
Add "FSTRANS=LOCK" and "FSTRANS=UNLOCK" to vop_lock and vop_unlock.
Add two "static inline" functions to vnode_if.c to handle MPSAFE
and FSTRANS before and after the "VCALL()".
Take FSTRANS and handle error before "VCALL(...vop_lock...)" and
release it after "VCALL(...vop_unlock...)".
diffstat:
sys/kern/vnode_if.sh | 100 +++++++++++++++++++++++++++++++++++++++++---------
sys/kern/vnode_if.src | 6 +-
2 files changed, 85 insertions(+), 21 deletions(-)
diffs (181 lines):
diff -r 20d87ef21025 -r 074316e46302 sys/kern/vnode_if.sh
--- a/sys/kern/vnode_if.sh Sun Jun 04 07:58:29 2017 +0000
+++ b/sys/kern/vnode_if.sh Sun Jun 04 07:59:17 2017 +0000
@@ -29,7 +29,7 @@
* SUCH DAMAGE.
*/
"
-SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.64 2017/04/16 17:18:28 riastradh Exp $'
+SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.65 2017/06/04 07:59:17 hannken Exp $'
# Script to produce VFS front-end sugar.
#
@@ -100,7 +100,7 @@
args_name=$1;
argc=0;
willmake=-1;
- fstrans=0;
+ fstrans="";
next;
}
# Last line of description
@@ -113,11 +113,9 @@
if ($1 == "VERSION") {
args_name=args_name "_v" $2;
next;
- } else if ($1 == "FSTRANS=YES") {
- fstrans = 1;
- next;
- } else if ($1 == "FSTRANS=NO") {
- fstrans = -1;
+ } else if ($1 ~ "^FSTRANS=") {
+ fstrans = $1;
+ sub("FSTRANS=", "", fstrans);
next;
}
@@ -147,8 +145,12 @@
willmake=argc;
i++;
}
- if (argc == 0 && fstrans == 0 && lockstate[0] != 1)
- fstrans = 1;
+ if (argc == 0 && fstrans == "") {
+ if (lockstate[0] == 1)
+ fstrans = "NO";
+ else
+ fstrans = "YES";
+ }
# XXX: replace non-portable types for rump. We should really
# nuke the types from the kernel, but that is a battle for
@@ -316,6 +318,57 @@
if [ -z "${rump}" ] ; then
echo "
+enum fst_op { FST_NO, FST_YES, FST_TRY };
+
+static inline int
+vop_pre(vnode_t *vp, struct mount **mp, bool *mpsafe, enum fst_op op)
+{
+ int error;
+
+ *mpsafe = (vp->v_vflag & VV_MPSAFE);
+
+ if (!*mpsafe) {
+ KERNEL_LOCK(1, curlwp);
+ }
+
+ if (op == FST_YES || op == FST_TRY) {
+ for (;;) {
+ *mp = vp->v_mount;
+ if (op == FST_TRY) {
+ error = fstrans_start_nowait(*mp, FSTRANS_SHARED);
+ if (error) {
+ if (!*mpsafe) {
+ KERNEL_UNLOCK_ONE(curlwp);
+ }
+ return error;
+ }
+ } else {
+ fstrans_start(*mp, FSTRANS_SHARED);
+ }
+ if (__predict_true(*mp == vp->v_mount))
+ break;
+ fstrans_done(*mp);
+ }
+ } else {
+ *mp = vp->v_mount;
+ }
+
+ return 0;
+}
+
+static inline void
+vop_post(vnode_t *vp, struct mount *mp, bool mpsafe, enum fst_op op)
+{
+
+ if (op == FST_YES) {
+ fstrans_done(mp);
+ }
+
+ if (!mpsafe) {
+ KERNEL_UNLOCK_ONE(curlwp);
+ }
+}
+
const struct vnodeop_desc vop_default_desc = {"
echo ' 0,
"default",
@@ -402,8 +455,7 @@
function bodynorm() {
printf("{\n\tint error;\n\tbool mpsafe;\n\tstruct %s_args a;\n",
args_name);
- if (fstrans == 1)
- printf("\tstruct mount *mp = %s->v_mount;\n", argname[0]);
+ printf("\tstruct mount *mp;\n");
if (lockdebug) {
printf("#ifdef VNODE_LOCKDEBUG\n");
for (i=0; i<argc; i++) {
@@ -425,15 +477,27 @@
printf("#endif\n");
}
}
- printf("\tmpsafe = (%s->v_vflag & VV_MPSAFE);\n", argname[0]);
- printf("\tif (!mpsafe) { KERNEL_LOCK(1, curlwp); }\n");
- if (fstrans == 1)
- printf("\tfstrans_start(mp, FSTRANS_SHARED);\n");
+ if (fstrans == "LOCK")
+ printf("\terror = vop_pre(%s, &mp, &mpsafe, %s);\n",
+ argname[0], "(flags & LK_NOWAIT ? FST_TRY : FST_YES)");
+ else if (fstrans == "UNLOCK")
+ printf("\terror = vop_pre(%s, &mp, &mpsafe, FST_%s);\n",
+ argname[0], "NO");
+ else
+ printf("\terror = vop_pre(%s, &mp, &mpsafe, FST_%s);\n",
+ argname[0], fstrans);
+ printf("\tif (error)\n\t\treturn error;\n");
printf("\terror = (VCALL(%s, VOFFSET(%s), &a));\n",
argname[0], name);
- if (fstrans == 1)
- printf("\tfstrans_done(mp);\n");
- printf("\tif (!mpsafe) { KERNEL_UNLOCK_ONE(curlwp); }\n");
+ if (fstrans == "LOCK")
+ printf("\tvop_post(%s, mp, mpsafe, %s);\n",
+ argname[0], "(error ? FST_YES : FST_NO)");
+ else if (fstrans == "UNLOCK")
+ printf("\tvop_post(%s, mp, mpsafe, FST_%s);\n",
+ argname[0], "YES");
+ else
+ printf("\tvop_post(%s, mp, mpsafe, FST_%s);\n",
+ argname[0], fstrans);
if (willmake != -1) {
printf("#ifdef DIAGNOSTIC\n");
printf("\tif (error == 0)\n" \
diff -r 20d87ef21025 -r 074316e46302 sys/kern/vnode_if.src
--- a/sys/kern/vnode_if.src Sun Jun 04 07:58:29 2017 +0000
+++ b/sys/kern/vnode_if.src Sun Jun 04 07:59:17 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: vnode_if.src,v 1.75 2017/05/26 14:21:00 riastradh Exp $
+# $NetBSD: vnode_if.src,v 1.76 2017/06/04 07:59:17 hannken Exp $
#
# Copyright (c) 1992, 1993
# The Regents of the University of California. All rights reserved.
@@ -407,7 +407,7 @@
#% lock vp U L U
#
vop_lock {
- FSTRANS=NO
+ FSTRANS=LOCK
IN LOCKED=NO struct vnode *vp;
IN int flags;
};
@@ -416,7 +416,7 @@
#% unlock vp L U L
#
vop_unlock {
- FSTRANS=NO
+ FSTRANS=UNLOCK
IN LOCKED=YES struct vnode *vp;
};
Home |
Main Index |
Thread Index |
Old Index