pseudofs_vncache.c (77965) | pseudofs_vncache.c (77998) |
---|---|
1/*- 2 * Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * | 1/*- 2 * Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * |
28 * $FreeBSD: head/sys/fs/pseudofs/pseudofs_vncache.c 77965 2001-06-10 10:36:16Z des $ | 28 * $FreeBSD: head/sys/fs/pseudofs/pseudofs_vncache.c 77998 2001-06-10 18:39:21Z des $ |
29 */ 30 31#include <sys/param.h> 32#include <sys/kernel.h> 33#include <sys/systm.h> 34#include <sys/malloc.h> 35#include <sys/mount.h> 36#include <sys/mutex.h> 37#include <sys/sbuf.h> 38#include <sys/sysctl.h> 39#include <sys/vnode.h> 40 41#include <fs/pseudofs/pseudofs.h> 42#include <fs/pseudofs/pseudofs_internal.h> 43 | 29 */ 30 31#include <sys/param.h> 32#include <sys/kernel.h> 33#include <sys/systm.h> 34#include <sys/malloc.h> 35#include <sys/mount.h> 36#include <sys/mutex.h> 37#include <sys/sbuf.h> 38#include <sys/sysctl.h> 39#include <sys/vnode.h> 40 41#include <fs/pseudofs/pseudofs.h> 42#include <fs/pseudofs/pseudofs_internal.h> 43 |
44static MALLOC_DEFINE(M_PFSVNCACHE, "pseudofs_vncache", "pseudofs vnode cache"); | 44static MALLOC_DEFINE(M_PFSVNCACHE, "pfs_vncache", "pseudofs vnode cache"); |
45 46static struct mtx pfs_vncache_mutex; 47 48struct pfs_vnode { 49 struct vnode *pv_vnode; 50 struct pfs_vnode *pv_next; 51} *pfs_vncache; 52 --- 27 unchanged lines hidden (view full) --- 80{ 81 mtx_destroy(&pfs_vncache_mutex); 82} 83 84/* 85 * Allocate a vnode 86 */ 87int | 45 46static struct mtx pfs_vncache_mutex; 47 48struct pfs_vnode { 49 struct vnode *pv_vnode; 50 struct pfs_vnode *pv_next; 51} *pfs_vncache; 52 --- 27 unchanged lines hidden (view full) --- 80{ 81 mtx_destroy(&pfs_vncache_mutex); 82} 83 84/* 85 * Allocate a vnode 86 */ 87int |
88pfs_vncache_alloc(struct mount *mp, struct vnode **vpp, struct pfs_node *pn) | 88pfs_vncache_alloc(struct mount *mp, struct vnode **vpp, 89 struct pfs_node *pn, pid_t pid) |
89{ 90 struct pfs_vnode *pv; | 90{ 91 struct pfs_vnode *pv; |
92 struct pfs_vdata *pvd; |
|
91 int error; 92 | 93 int error; 94 |
93 mtx_lock(&pfs_vncache_mutex); 94 | |
95 /* see if the vnode is in the cache */ | 95 /* see if the vnode is in the cache */ |
96 for (pv = pfs_vncache; pv; pv = pv->pv_next) 97 if (pv->pv_vnode->v_data == pn) | 96 mtx_lock(&pfs_vncache_mutex); 97 for (pv = pfs_vncache; pv; pv = pv->pv_next) { 98 pvd = (struct pfs_vdata *)pv->pv_vnode->v_data; 99 if (pvd->pvd_pn == pn && pvd->pvd_pid == pid) { |
98 if (vget(pv->pv_vnode, 0, curproc) == 0) { 99 ++pfs_vncache_hits; 100 *vpp = pv->pv_vnode; 101 mtx_unlock(&pfs_vncache_mutex); 102 return (0); 103 } | 100 if (vget(pv->pv_vnode, 0, curproc) == 0) { 101 ++pfs_vncache_hits; 102 *vpp = pv->pv_vnode; 103 mtx_unlock(&pfs_vncache_mutex); 104 return (0); 105 } |
106 /* XXX if this can happen, we're in trouble */ 107 break; 108 } 109 } 110 mtx_unlock(&pfs_vncache_mutex); |
|
104 ++pfs_vncache_misses; 105 106 /* nope, get a new one */ 107 MALLOC(pv, struct pfs_vnode *, sizeof *pv, M_PFSVNCACHE, M_WAITOK); | 111 ++pfs_vncache_misses; 112 113 /* nope, get a new one */ 114 MALLOC(pv, struct pfs_vnode *, sizeof *pv, M_PFSVNCACHE, M_WAITOK); |
115 MALLOC(pvd, struct pfs_vdata *, sizeof *pvd, M_PFSVNCACHE, M_WAITOK); |
|
108 error = getnewvnode(VT_PSEUDOFS, mp, pfs_vnodeop_p, vpp); | 116 error = getnewvnode(VT_PSEUDOFS, mp, pfs_vnodeop_p, vpp); |
109 if (error) { 110 mtx_unlock(&pfs_vncache_mutex); | 117 if (error) |
111 return (error); | 118 return (error); |
112 } 113 (*vpp)->v_data = pn; | 119 pvd->pvd_pn = pn; 120 pvd->pvd_pid = pid; 121 (*vpp)->v_data = pvd; |
114 switch (pn->pn_type) { 115 case pfstype_root: 116 (*vpp)->v_flag = VROOT; 117#if 0 118 printf("root vnode allocated\n"); 119#endif 120 case pfstype_dir: 121 case pfstype_this: 122 case pfstype_parent: | 122 switch (pn->pn_type) { 123 case pfstype_root: 124 (*vpp)->v_flag = VROOT; 125#if 0 126 printf("root vnode allocated\n"); 127#endif 128 case pfstype_dir: 129 case pfstype_this: 130 case pfstype_parent: |
131 case pfstype_procdir: |
|
123 (*vpp)->v_type = VDIR; 124 break; 125 case pfstype_file: 126 (*vpp)->v_type = VREG; 127 break; 128 case pfstype_symlink: 129 (*vpp)->v_type = VLNK; 130 break; | 132 (*vpp)->v_type = VDIR; 133 break; 134 case pfstype_file: 135 (*vpp)->v_type = VREG; 136 break; 137 case pfstype_symlink: 138 (*vpp)->v_type = VLNK; 139 break; |
140 case pfstype_none: 141 KASSERT(0, ("pfs_vncache_alloc called for null node\n")); |
|
131 default: 132 panic("%s has unexpected type: %d", pn->pn_name, pn->pn_type); 133 } 134 pv->pv_vnode = *vpp; | 142 default: 143 panic("%s has unexpected type: %d", pn->pn_name, pn->pn_type); 144 } 145 pv->pv_vnode = *vpp; |
146 mtx_lock(&pfs_vncache_mutex); |
|
135 pv->pv_next = pfs_vncache; 136 pfs_vncache = pv; 137 mtx_unlock(&pfs_vncache_mutex); 138 return (0); 139} 140 141/* 142 * Free a vnode 143 */ 144int 145pfs_vncache_free(struct vnode *vp) 146{ 147 struct pfs_vnode *prev, *pv; | 147 pv->pv_next = pfs_vncache; 148 pfs_vncache = pv; 149 mtx_unlock(&pfs_vncache_mutex); 150 return (0); 151} 152 153/* 154 * Free a vnode 155 */ 156int 157pfs_vncache_free(struct vnode *vp) 158{ 159 struct pfs_vnode *prev, *pv; |
160 struct pfs_vdata *pvd; |
|
148 149 mtx_lock(&pfs_vncache_mutex); 150 for (prev = NULL, pv = pfs_vncache; pv; prev = pv, pv = pv->pv_next) 151 if (pv->pv_vnode == vp) 152 break; | 161 162 mtx_lock(&pfs_vncache_mutex); 163 for (prev = NULL, pv = pfs_vncache; pv; prev = pv, pv = pv->pv_next) 164 if (pv->pv_vnode == vp) 165 break; |
153 if (!pv) 154 printf("pfs_vncache_free(): not in cache\n"); /* it should be! */ 155#if 0 156 if (vp->v_data == ((struct pfs_info *)vp->v_mount->mnt_data)->pi_root) 157 printf("root vnode reclaimed\n"); 158#endif 159 vp->v_data = NULL; 160 if (pv) { 161 if (prev) 162 prev->pv_next = pv->pv_next; 163 else 164 pfs_vncache = pv->pv_next; 165 FREE(pv, M_PFSVNCACHE); 166 } | 166 KASSERT(pv != NULL, ("pfs_vncache_free(): not in cache\n")); 167 if (prev) 168 prev->pv_next = pv->pv_next; 169 else 170 pfs_vncache = pv->pv_next; |
167 mtx_unlock(&pfs_vncache_mutex); | 171 mtx_unlock(&pfs_vncache_mutex); |
172 173 pvd = (struct pfs_vdata *)vp->v_data; 174 FREE(pvd, M_PFSVNCACHE); 175 vp->v_data = NULL; 176 FREE(pv, M_PFSVNCACHE); |
|
168 return (0); 169} | 177 return (0); 178} |