Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/fs/nilfs Prepare nilfs for vcache:
details: https://anonhg.NetBSD.org/src/rev/99569df2d814
branches: trunk
changeset: 333032:99569df2d814
user: hannken <hannken%NetBSD.org@localhost>
date: Wed Oct 15 09:03:53 2014 +0000
description:
Prepare nilfs for vcache:
- Calling getnewvnode() with "mp == NULL" is wrong. Stop attaching a
vnode to system file nodes and change nilfs_bread() to translate
the block address and then uyse the device for the read.
- Move the vnode initialisation to nilfs_get_node() and use
nilfs_get_node_raw() to initialise the nilfs node only.
- Same for nilfs_reclaim() versus nilfs_dispose_node().
- Change nilfs_get_node() to return an unlocked vnode instead of
a nilfs node with locked vnode. Adapt nilfs_lookup() and nilfs_root().
- Don't treat unsupported node types (blk, chr ...) as regular,
return ENXIO instead.
- Fix nilfs_getattr() to mask the mode with ALLPERMS.
- Destroy sync_cv before free.
diffstat:
sys/fs/nilfs/nilfs_subr.c | 154 ++++++++++++++++++++++++--------------------
sys/fs/nilfs/nilfs_subr.h | 5 +-
sys/fs/nilfs/nilfs_vfsops.c | 53 ++++-----------
sys/fs/nilfs/nilfs_vnops.c | 44 +++++-------
4 files changed, 120 insertions(+), 136 deletions(-)
diffs (truncated from 564 to 300 lines):
diff -r 91806abe8f6a -r 99569df2d814 sys/fs/nilfs/nilfs_subr.c
--- a/sys/fs/nilfs/nilfs_subr.c Wed Oct 15 08:14:44 2014 +0000
+++ b/sys/fs/nilfs/nilfs_subr.c Wed Oct 15 09:03:53 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nilfs_subr.c,v 1.10 2013/10/18 19:57:28 christos Exp $ */
+/* $NetBSD: nilfs_subr.c,v 1.11 2014/10/15 09:03:53 hannken Exp $ */
/*
* Copyright (c) 2008, 2009 Reinoud Zandijk
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: nilfs_subr.c,v 1.10 2013/10/18 19:57:28 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nilfs_subr.c,v 1.11 2014/10/15 09:03:53 hannken Exp $");
#endif /* not lint */
#include <sys/param.h>
@@ -149,12 +149,22 @@
nilfs_bread(struct nilfs_node *node, uint64_t blocknr,
struct kauth_cred *cred, int flags, struct buf **bpp)
{
- uint64_t vblocknr;
+ struct nilfs_device *nilfsdev = node->nilfsdev;
+ uint64_t vblocknr, pblockno;
int error;
error = nilfs_btree_lookup(node, blocknr, &vblocknr);
if (error)
return error;
+
+ /* Read special files through devvp as they have no vnode attached. */
+ if (node->ino < NILFS_USER_INO && node->ino != NILFS_ROOT_INO) {
+ error = nilfs_nvtop(node, 1, &vblocknr, &pblockno);
+ if (error)
+ return error;
+ return nilfs_dev_bread(nilfsdev, pblockno, cred, flags, bpp);
+ }
+
return bread(node->vnode, vblocknr, node->nilfsdev->blocksize,
cred, flags, bpp);
}
@@ -746,7 +756,7 @@
}
-static void
+void
nilfs_deregister_node(struct nilfs_node *node)
{
struct nilfs_mount *ump;
@@ -799,67 +809,25 @@
uint64_t ino, struct nilfs_inode *inode, struct nilfs_node **nodep)
{
struct nilfs_node *node;
- struct vnode *nvp;
- struct mount *mp;
- int (**vnodeops)(void *);
- int error;
*nodep = NULL;
- vnodeops = nilfs_vnodeop_p;
-
- /* associate with mountpoint if present*/
- mp = ump? ump->vfs_mountp : NULL;
- error = getnewvnode(VT_NILFS, mp, vnodeops, NULL, &nvp);
- if (error)
- return error;
-
- /* lock node */
- error = vn_lock(nvp, LK_EXCLUSIVE | LK_RETRY);
- if (error) {
- nvp->v_data = NULL;
- ungetnewvnode(nvp);
- return error;
- }
node = pool_get(&nilfs_node_pool, PR_WAITOK);
memset(node, 0, sizeof(struct nilfs_node));
/* crosslink */
- node->vnode = nvp;
node->ump = ump;
node->nilfsdev = nilfsdev;
- nvp->v_data = node;
/* initiase nilfs node */
node->ino = ino;
node->inode = *inode;
node->lockf = NULL;
- /* needed? */
+ /* initialise locks */
mutex_init(&node->node_mutex, MUTEX_DEFAULT, IPL_NONE);
cv_init(&node->node_lock, "nilfsnlk");
- /* initialise genfs */
- genfs_node_init(nvp, &nilfs_genfsops);
-
- /* check if we're fetching the root */
- if (ino == NILFS_ROOT_INO)
- nvp->v_vflag |= VV_ROOT;
-
- /* update vnode's file type XXX is there a function for this? */
- nvp->v_type = VREG;
- if (S_ISDIR(inode->i_mode))
- nvp->v_type = VDIR;
- if (S_ISLNK(inode->i_mode))
- nvp->v_type = VLNK;
-#if 0
- if (S_ISCHR(inode->i_mode))
- nvp->v_type = VCHR;
- if (S_ISBLK(inode->i_mode))
- nvp->v_type = VBLK;
-#endif
- /* XXX what else? */
-
/* fixup inode size for system nodes */
if ((ino < NILFS_USER_INO) && (ino != NILFS_ROOT_INO)) {
DPRINTF(VOLUMES, ("NEED TO GET my size for inode %"PRIu64"\n",
@@ -868,39 +836,41 @@
inode->i_size = nilfs_rw64(((uint64_t) -2));
}
- uvm_vnp_setsize(nvp, nilfs_rw64(inode->i_size));
-
- if (ump)
- nilfs_register_node(node);
-
/* return node */
*nodep = node;
return 0;
}
-
int
-nilfs_get_node(struct nilfs_mount *ump, uint64_t ino, struct nilfs_node **nodep)
+nilfs_get_node(struct mount *mp, uint64_t ino, struct vnode **vpp)
{
struct nilfs_device *nilfsdev;
struct nilfs_inode inode, *entry;
+ struct nilfs_node *node;
+ struct nilfs_mount *ump = VFSTONILFS(mp);
+ struct vnode *nvp;
struct buf *bp;
uint64_t ivblocknr;
uint32_t entry_in_block;
int error;
/* lookup node in hash table */
- *nodep = nilfs_hash_lookup(ump, ino);
- if (*nodep)
+ node = nilfs_hash_lookup(ump, ino);
+ if (node) {
+ *vpp = node->vnode;
+ VOP_UNLOCK(*vpp);
return 0;
+ }
/* lock to disallow simultanious creation of same udf_node */
mutex_enter(&ump->get_node_lock);
/* relookup since it could be created while waiting for the mutex */
- *nodep = nilfs_hash_lookup(ump, ino);
- if (*nodep) {
+ node = nilfs_hash_lookup(ump, ino);
+ if (node) {
+ *vpp = node->vnode;
mutex_exit(&ump->get_node_lock);
+ VOP_UNLOCK(*vpp);
return 0;
}
@@ -931,17 +901,70 @@
brelse(bp, BC_AGE);
/* get node */
- error = nilfs_get_node_raw(ump->nilfsdev, ump, ino, &inode, nodep);
+ error = nilfs_get_node_raw(ump->nilfsdev, ump, ino, &inode, &node);
+ if (error) {
+ mutex_exit(&ump->get_node_lock);
+ return error;
+ }
+
+ error = getnewvnode(VT_NILFS, mp, nilfs_vnodeop_p, NULL, &nvp);
+ if (error) {
+ nilfs_dispose_node(&node);
+ mutex_exit(&ump->get_node_lock);
+ return error;
+ }
+
+ /* lock node */
+ error = vn_lock(nvp, LK_EXCLUSIVE | LK_RETRY);
+ if (error) {
+ ungetnewvnode(nvp);
+ nilfs_dispose_node(&node);
+ mutex_exit(&ump->get_node_lock);
+ return error;
+ }
+
+ nvp->v_type = IFTOVT(inode.i_mode);
+ switch (nvp->v_type) {
+ case VREG:
+ case VDIR:
+ case VLNK:
+ break;
+ /* other types not yet supported. */
+ default:
+ nvp->v_type = VNON;
+ VOP_UNLOCK(nvp);
+ ungetnewvnode(nvp);
+ nilfs_dispose_node(&node);
+ mutex_exit(&ump->get_node_lock);
+ return ENXIO;
+ }
+
+ node->vnode = nvp;
+ nvp->v_data = node;
+
+ /* initialise genfs */
+ genfs_node_init(nvp, &nilfs_genfsops);
+
+ /* check if we're fetching the root */
+ if (ino == NILFS_ROOT_INO)
+ nvp->v_vflag |= VV_ROOT;
+
+ uvm_vnp_setsize(nvp, nilfs_rw64(inode.i_size));
+
+ nilfs_register_node(node);
+
mutex_exit(&ump->get_node_lock);
- return error;
+ *vpp = nvp;
+ VOP_UNLOCK(*vpp);
+
+ return 0;
}
void
nilfs_dispose_node(struct nilfs_node **nodep)
{
- struct vnode *vp;
struct nilfs_node *node;
/* protect against rogue values */
@@ -949,23 +972,14 @@
return;
node = *nodep;
- vp = node->vnode;
/* remove dirhash if present */
dirhash_purge(&node->dir_hash);
- /* remove from our hash lookup table */
- if (node->ump)
- nilfs_deregister_node(node);
-
/* destroy our locks */
mutex_destroy(&node->node_mutex);
cv_destroy(&node->node_lock);
- /* dissociate from our vnode */
- genfs_node_destroy(node->vnode);
- vp->v_data = NULL;
-
/* free our associated memory */
pool_put(&nilfs_node_pool, node);
diff -r 91806abe8f6a -r 99569df2d814 sys/fs/nilfs/nilfs_subr.h
--- a/sys/fs/nilfs/nilfs_subr.h Wed Oct 15 08:14:44 2014 +0000
+++ b/sys/fs/nilfs/nilfs_subr.h Wed Oct 15 09:03:53 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nilfs_subr.h,v 1.1 2009/07/18 16:31:42 reinoud Exp $ */
+/* $NetBSD: nilfs_subr.h,v 1.2 2014/10/15 09:03:53 hannken Exp $ */
/*
* Copyright (c) 2008, 2009 Reinoud Zandijk
@@ -56,7 +56,8 @@
int nilfs_nvtop(struct nilfs_node *node, uint64_t blks, uint64_t *l2vmap, uint64_t *v2pmap);
/* node action implementators */
-int nilfs_get_node(struct nilfs_mount *ump, uint64_t ino, struct nilfs_node **nodep);
+void nilfs_deregister_node(struct nilfs_node *);
+int nilfs_get_node(struct mount *mp, uint64_t ino, struct vnode **vpp);
int nilfs_get_node_raw(struct nilfs_device *nilfsdev, struct nilfs_mount *ump, uint64_t ino, struct nilfs_inode *inode, struct nilfs_node **nodep);
void nilfs_dispose_node(struct nilfs_node **node);
diff -r 91806abe8f6a -r 99569df2d814 sys/fs/nilfs/nilfs_vfsops.c
--- a/sys/fs/nilfs/nilfs_vfsops.c Wed Oct 15 08:14:44 2014 +0000
+++ b/sys/fs/nilfs/nilfs_vfsops.c Wed Oct 15 09:03:53 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nilfs_vfsops.c,v 1.16 2014/04/16 18:55:18 maxv Exp $ */
+/* $NetBSD: nilfs_vfsops.c,v 1.17 2014/10/15 09:03:53 hannken Exp $ */
/*
* Copyright (c) 2008, 2009 Reinoud Zandijk
@@ -28,7 +28,7 @@
Home |
Main Index |
Thread Index |
Old Index