Add VFS_VNODE_PRIVATE protected operations vnalloc_marker() to create,

vnfree_marker() to destroy and vnis_marker() to test for marker vnodes.

Make operations vnalloc() and vnfree() local to vfs_vnode.c.
This commit is contained in:
hannken 2016-05-19 14:47:33 +00:00
parent 9f10dc7910
commit 4222e592dd
3 changed files with 55 additions and 15 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_mount.c,v 1.37 2015/08/19 08:40:02 hannken Exp $ */
/* $NetBSD: vfs_mount.c,v 1.38 2016/05/19 14:47:33 hannken Exp $ */
/*-
* Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.37 2015/08/19 08:40:02 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.38 2016/05/19 14:47:33 hannken Exp $");
#define _VFS_VNODE_PRIVATE
@ -346,7 +346,7 @@ vfs_vnode_iterator_init(struct mount *mp, struct vnode_iterator **vip)
{
struct vnode *vp;
vp = vnalloc(mp);
vp = vnalloc_marker(mp);
mutex_enter(&mntvnode_lock);
TAILQ_INSERT_HEAD(&mp->mnt_vnodelist, vp, v_mntvnodes);
@ -362,13 +362,13 @@ vfs_vnode_iterator_destroy(struct vnode_iterator *vi)
struct vnode *mvp = &vi->vi_vnode;
mutex_enter(&mntvnode_lock);
KASSERT(ISSET(mvp->v_iflag, VI_MARKER));
KASSERT(vnis_marker(mvp));
if (mvp->v_usecount != 0) {
TAILQ_REMOVE(&mvp->v_mount->mnt_vnodelist, mvp, v_mntvnodes);
mvp->v_usecount = 0;
}
mutex_exit(&mntvnode_lock);
vnfree(mvp);
vnfree_marker(mvp);
}
struct vnode *
@ -380,7 +380,7 @@ vfs_vnode_iterator_next(struct vnode_iterator *vi,
struct vnode *vp;
int error;
KASSERT(ISSET(mvp->v_iflag, VI_MARKER));
KASSERT(vnis_marker(mvp));
do {
mutex_enter(&mntvnode_lock);
@ -393,7 +393,7 @@ again:
return NULL;
}
mutex_enter(vp->v_interlock);
if (ISSET(vp->v_iflag, VI_MARKER) ||
if (vnis_marker(vp) ||
ISSET(vp->v_iflag, VI_XLOCK) ||
(f && !(*f)(cl, vp))) {
mutex_exit(vp->v_interlock);

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_vnode.c,v 1.47 2016/04/22 15:01:54 riastradh Exp $ */
/* $NetBSD: vfs_vnode.c,v 1.48 2016/05/19 14:47:33 hannken Exp $ */
/*-
* Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@ -116,7 +116,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.47 2016/04/22 15:01:54 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.48 2016/05/19 14:47:33 hannken Exp $");
#define _VFS_VNODE_PRIVATE
@ -195,6 +195,8 @@ static void vclean(vnode_t *);
static void vrelel(vnode_t *, int);
static void vdrain_thread(void *);
static void vrele_thread(void *);
static vnode_t * vnalloc(struct mount *);
static void vnfree(vnode_t *);
static void vnpanic(vnode_t *, const char *, ...)
__printflike(2, 3);
static void vwait(vnode_t *, int);
@ -235,11 +237,42 @@ vfs_vnode_sysinit(void)
KASSERTMSG((error == 0), "kthread_create(vrele) failed: %d", error);
}
/*
* Allocate a new marker vnode.
*/
vnode_t *
vnalloc_marker(struct mount *mp)
{
return vnalloc(mp);
}
/*
* Free a marker vnode.
*/
void
vnfree_marker(vnode_t *vp)
{
KASSERT(ISSET(vp->v_iflag, VI_MARKER));
vnfree(vp);
}
/*
* Test a vnode for being a marker vnode.
*/
bool
vnis_marker(vnode_t *vp)
{
return (ISSET(vp->v_iflag, VI_MARKER));
}
/*
* Allocate a new, uninitialized vnode. If 'mp' is non-NULL, this is a
* marker vnode.
*/
vnode_t *
static vnode_t *
vnalloc(struct mount *mp)
{
vnode_t *vp;
@ -280,7 +313,7 @@ vnalloc(struct mount *mp)
/*
* Free an unused, unreferenced vnode.
*/
void
static void
vnfree(vnode_t *vp)
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: vnode.h,v 1.259 2016/01/23 16:08:20 christos Exp $ */
/* $NetBSD: vnode.h,v 1.260 2016/05/19 14:47:33 hannken Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -546,9 +546,6 @@ int vtruncbuf(struct vnode *, daddr_t, bool, int);
void vwakeup(struct buf *);
int vdead_check(struct vnode *, int);
void vrevoke(struct vnode *);
struct vnode *
vnalloc(struct mount *);
void vnfree(struct vnode *);
void vremfree(struct vnode *);
int vcache_get(struct mount *, const void *, size_t, struct vnode **);
int vcache_new(struct mount *, struct vnode *,
@ -605,6 +602,16 @@ void vfs_mount_print(struct mount *, int, void (*)(const char *, ...)
__printflike(1, 2));
#endif /* DDB */
#ifdef _VFS_VNODE_PRIVATE
/*
* Private vnode manipulation functions.
*/
struct vnode *
vnalloc_marker(struct mount *);
void vnfree_marker(vnode_t *);
bool vnis_marker(vnode_t *);
#endif /* _VFS_VNODE_PRIVATE */
#endif /* _KERNEL */
#endif /* !_SYS_VNODE_H_ */