Module Name:    src
Committed By:   hannken
Date:           Mon Dec 29 15:29:38 UTC 2014

Modified Files:
        src/sys/fs/v7fs: v7fs_extern.c v7fs_extern.h v7fs_vfsops.c v7fs_vnops.c

Log Message:
Change v7fs to vcache.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/fs/v7fs/v7fs_extern.c
cvs rdiff -u -r1.1 -r1.2 src/sys/fs/v7fs/v7fs_extern.h
cvs rdiff -u -r1.11 -r1.12 src/sys/fs/v7fs/v7fs_vfsops.c
cvs rdiff -u -r1.19 -r1.20 src/sys/fs/v7fs/v7fs_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/fs/v7fs/v7fs_extern.c
diff -u src/sys/fs/v7fs/v7fs_extern.c:1.3 src/sys/fs/v7fs/v7fs_extern.c:1.4
--- src/sys/fs/v7fs/v7fs_extern.c:1.3	Fri Jul 25 08:20:52 2014
+++ src/sys/fs/v7fs/v7fs_extern.c	Mon Dec 29 15:29:38 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: v7fs_extern.c,v 1.3 2014/07/25 08:20:52 dholland Exp $	*/
+/*	$NetBSD: v7fs_extern.c,v 1.4 2014/12/29 15:29:38 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2011 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: v7fs_extern.c,v 1.3 2014/07/25 08:20:52 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: v7fs_extern.c,v 1.4 2014/12/29 15:29:38 hannken Exp $");
 
 #if defined _KERNEL_OPT
 #include "opt_v7fs.h"
@@ -235,6 +235,7 @@ struct vfsops v7fs_vfsops = {
 	.vfs_statvfs = v7fs_statvfs,
 	.vfs_sync = v7fs_sync,
 	.vfs_vget = v7fs_vget,
+	.vfs_loadvnode = v7fs_loadvnode,
 	.vfs_fhtovp = v7fs_fhtovp,
 	.vfs_vptofh = v7fs_vptofh,
 	.vfs_init = v7fs_init,

Index: src/sys/fs/v7fs/v7fs_extern.h
diff -u src/sys/fs/v7fs/v7fs_extern.h:1.1 src/sys/fs/v7fs/v7fs_extern.h:1.2
--- src/sys/fs/v7fs/v7fs_extern.h:1.1	Mon Jun 27 11:52:24 2011
+++ src/sys/fs/v7fs/v7fs_extern.h	Mon Dec 29 15:29:38 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: v7fs_extern.h,v 1.1 2011/06/27 11:52:24 uch Exp $	*/
+/*	$NetBSD: v7fs_extern.h,v 1.2 2014/12/29 15:29:38 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2011 The NetBSD Foundation, Inc.
@@ -46,7 +46,6 @@ struct v7fs_mount {
 	struct mount *mountp;
 	struct vnode *devvp;		/* block device mounted vnode */
 	struct v7fs_self *core;		/* filesystem dependent implementation*/
-	LIST_HEAD(, v7fs_node) v7fs_node_head;
 };
 
 struct v7fs_node {
@@ -59,8 +58,6 @@ struct v7fs_node {
 	int update_ctime;
 	int update_atime;
 	int update_mtime;
-
-	LIST_ENTRY(v7fs_node) link;
 };
 
 #define	VFSTOV7FS(mp)	((struct v7fs_mount *)((mp)->mnt_data))

Index: src/sys/fs/v7fs/v7fs_vfsops.c
diff -u src/sys/fs/v7fs/v7fs_vfsops.c:1.11 src/sys/fs/v7fs/v7fs_vfsops.c:1.12
--- src/sys/fs/v7fs/v7fs_vfsops.c:1.11	Mon Dec 29 15:28:58 2014
+++ src/sys/fs/v7fs/v7fs_vfsops.c	Mon Dec 29 15:29:38 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: v7fs_vfsops.c,v 1.11 2014/12/29 15:28:58 hannken Exp $	*/
+/*	$NetBSD: v7fs_vfsops.c,v 1.12 2014/12/29 15:29:38 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2011 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: v7fs_vfsops.c,v 1.11 2014/12/29 15:28:58 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: v7fs_vfsops.c,v 1.12 2014/12/29 15:29:38 hannken Exp $");
 #if defined _KERNEL_OPT
 #include "opt_v7fs.h"
 #endif
@@ -273,8 +273,6 @@ v7fs_mountfs(struct vnode *devvp, struct
 		goto err_exit;
 	}
 
-	LIST_INIT(&v7fsmount->v7fs_node_head);
-
 	mp->mnt_data = v7fsmount;
 	mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)devvp->v_rdev;
 	mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_V7FS);
@@ -368,47 +366,46 @@ v7fs_statvfs(struct mount *mp, struct st
 	return 0;
 }
 
+static bool
+v7fs_sync_selector(void *cl, struct vnode *vp)
+{
+	struct v7fs_node *v7fs_node = vp->v_data;
+
+	if (v7fs_node == NULL)
+		return false;
+	if (!v7fs_inode_allocated(&v7fs_node->inode))
+		return false;
+
+	return true;
+}
+
 int
 v7fs_sync(struct mount *mp, int waitfor, kauth_cred_t cred)
 {
 	struct v7fs_mount *v7fsmount = mp->mnt_data;
 	struct v7fs_self *fs = v7fsmount->core;
-	struct v7fs_node *v7fs_node;
-	struct v7fs_inode *inode;
-	struct vnode *v;
+	struct vnode_iterator *marker;
+	struct vnode *vp;
 	int err, error;
-	int retry_cnt;
 
 	DPRINTF("\n");
 
 	v7fs_superblock_writeback(fs);
-	for (retry_cnt = 0; retry_cnt < 2; retry_cnt++) {
-		error = 0;
-
-		mutex_enter(&mntvnode_lock);
-		for (v7fs_node = LIST_FIRST(&v7fsmount->v7fs_node_head);
-		    v7fs_node != NULL; v7fs_node = LIST_NEXT(v7fs_node, link)) {
-			inode = &v7fs_node->inode;
-			if (!v7fs_inode_allocated(inode)) {
-				continue;
-			}
-			v = v7fs_node->vnode;
-			mutex_enter(v->v_interlock);
-			mutex_exit(&mntvnode_lock);
-			err = vget(v, LK_EXCLUSIVE | LK_NOWAIT);
-			if (err == 0) {
-				err = VOP_FSYNC(v, cred, FSYNC_WAIT, 0, 0);
-				vput(v);
-			}
-			if (err != 0)
-				error = err;
-			mutex_enter(&mntvnode_lock);
+	error = 0;
+	vfs_vnode_iterator_init(mp, &marker);
+	while ((vp = vfs_vnode_iterator_next(marker,
+	    v7fs_sync_selector, NULL)) != NULL) {
+		err = vn_lock(vp, LK_EXCLUSIVE);
+		if (err) {
+			vrele(vp);
+			continue;
 		}
-		mutex_exit(&mntvnode_lock);
-
-		if (error == 0)
-			break;
+		err = VOP_FSYNC(vp, cred, FSYNC_WAIT, 0, 0);
+		vput(vp);
+		if (err != 0)
+			error = err;
 	}
+	vfs_vnode_iterator_destroy(marker);
 
 	return error;
 }
@@ -425,55 +422,33 @@ v7fs_mode_to_vtype (v7fs_mode_t mode)
 }
 
 int
-v7fs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
+v7fs_loadvnode(struct mount *mp, struct vnode *vp,
+    const void *key, size_t key_len, const void **new_key)
 {
-	struct v7fs_mount *v7fsmount = mp->mnt_data;
-	struct v7fs_self *fs = v7fsmount->core;
-	struct vnode *vp;
+	struct v7fs_mount *v7fsmount;
+	struct v7fs_self *fs;
 	struct v7fs_node *v7fs_node;
 	struct v7fs_inode inode;
+	v7fs_ino_t number;
 	int error;
 
+	KASSERT(key_len == sizeof(number));
+	memcpy(&number, key, key_len);
+
+	v7fsmount = mp->mnt_data;
+	fs = v7fsmount->core;
+
 	/* Lookup requested i-node */
-	if ((error = v7fs_inode_load(fs, &inode, ino))) {
+	if ((error = v7fs_inode_load(fs, &inode, number))) {
 		DPRINTF("v7fs_inode_load failed.\n");
 		return error;
 	}
 
-retry:
-	mutex_enter(&mntvnode_lock);
-	for (v7fs_node = LIST_FIRST(&v7fsmount->v7fs_node_head);
-	    v7fs_node != NULL; v7fs_node = LIST_NEXT(v7fs_node, link)) {
-		if (v7fs_node->inode.inode_number == ino) {
-			vp = v7fs_node->vnode;
-			mutex_enter(vp->v_interlock);
-			mutex_exit(&mntvnode_lock);
-			if (vget(vp, LK_EXCLUSIVE) == 0) {
-				*vpp = vp;
-				return 0;
-			} else {
-				DPRINTF("retry!\n");
-				goto retry;
-			}
-		}
-	}
-	mutex_exit(&mntvnode_lock);
-
-	/* Allocate v-node. */
-	if ((error = getnewvnode(VT_V7FS, mp, v7fs_vnodeop_p, NULL, &vp))) {
-		DPRINTF("getnewvnode error.\n");
-		return error;
-	}
-	/* Lock vnode here */
-	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+	v7fs_node = pool_get(&v7fs_node_pool, PR_WAITOK);
+	memset(v7fs_node, 0, sizeof(*v7fs_node));
 
-	/* Allocate i-node */
-	vp->v_data = pool_get(&v7fs_node_pool, PR_WAITOK);
-	memset(vp->v_data, 0, sizeof(*v7fs_node));
-	v7fs_node = vp->v_data;
-	mutex_enter(&mntvnode_lock);
-	LIST_INSERT_HEAD(&v7fsmount->v7fs_node_head, v7fs_node, link);
-	mutex_exit(&mntvnode_lock);
+	vp->v_tag = VT_V7FS;
+	vp->v_data = v7fs_node;
 	v7fs_node->vnode = vp;
 	v7fs_node->v7fsmount = v7fsmount;
 	v7fs_node->inode = inode;/*structure copy */
@@ -482,9 +457,10 @@ retry:
 	genfs_node_init(vp, &v7fs_genfsops);
 	uvm_vnp_setsize(vp, v7fs_inode_filesize(&inode));
 
-	if (ino == V7FS_ROOT_INODE) {
+	if (number == V7FS_ROOT_INODE) {
 		vp->v_type = VDIR;
 		vp->v_vflag |= VV_ROOT;
+		vp->v_op = v7fs_vnodeop_p;
 	} else {
 		vp->v_type = v7fs_mode_to_vtype(inode.mode);
 
@@ -494,16 +470,42 @@ retry:
 			spec_node_init(vp, rdev);
 		} else if (vp->v_type == VFIFO) {
 			vp->v_op = v7fs_fifoop_p;
+		} else {
+			vp->v_op = v7fs_vnodeop_p;
 		}
 	}
 
-	*vpp = vp;
+	*new_key = &v7fs_node->inode.inode_number;
 
 	return 0;
 }
 
 
 int
+v7fs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
+{
+	int error;
+	v7fs_ino_t number;
+	struct vnode *vp;
+
+	KASSERT(ino <= UINT16_MAX);
+	number = ino;
+
+	error = vcache_get(mp, &number, sizeof(number), &vp);
+	if (error)
+		return error;
+	error = vn_lock(vp, LK_EXCLUSIVE);
+	if (error) {
+		vrele(vp);
+		return error;
+	}
+
+	*vpp = vp;
+
+	return 0;
+}
+
+int
 v7fs_fhtovp(struct mount *mp, struct fid *fid, struct vnode **vpp)
 {
 

Index: src/sys/fs/v7fs/v7fs_vnops.c
diff -u src/sys/fs/v7fs/v7fs_vnops.c:1.19 src/sys/fs/v7fs/v7fs_vnops.c:1.20
--- src/sys/fs/v7fs/v7fs_vnops.c:1.19	Mon Dec 29 15:28:58 2014
+++ src/sys/fs/v7fs/v7fs_vnops.c	Mon Dec 29 15:29:38 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: v7fs_vnops.c,v 1.19 2014/12/29 15:28:58 hannken Exp $	*/
+/*	$NetBSD: v7fs_vnops.c,v 1.20 2014/12/29 15:29:38 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2011 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: v7fs_vnops.c,v 1.19 2014/12/29 15:28:58 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: v7fs_vnops.c,v 1.20 2014/12/29 15:29:38 hannken Exp $");
 #if defined _KERNEL_OPT
 #include "opt_v7fs.h"
 #endif
@@ -1050,12 +1050,13 @@ v7fs_reclaim(void *v)
 		v7fs_inode_deallocate(fs, inode->inode_number);
 		DPRINTF("remove inode\n");
 	}
-	mutex_enter(&mntvnode_lock);
-	LIST_REMOVE(v7node, link);
-	mutex_exit(&mntvnode_lock);
+	vcache_remove(vp->v_mount,
+	    &inode->inode_number, sizeof(inode->inode_number));
 	genfs_node_destroy(vp);
 	pool_put(&v7fs_node_pool, v7node);
+	mutex_enter(vp->v_interlock);
 	vp->v_data = NULL;
+	mutex_exit(vp->v_interlock);
 
 	return 0;
 }

Reply via email to