1/*- 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Rick Macklem at The University of Guelph. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 4. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * from nfs_subs.c 8.8 (Berkeley) 5/22/95 33 */ 34 35#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Rick Macklem at The University of Guelph. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 4. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * from nfs_subs.c 8.8 (Berkeley) 5/22/95 33 */ 34 35#include <sys/cdefs.h>
|
36__FBSDID("$FreeBSD: head/sys/fs/nfsclient/nfs_clsubs.c 221973 2011-05-15 20:52:43Z rmacklem $");
| 36__FBSDID("$FreeBSD: head/sys/fs/nfsclient/nfs_clsubs.c 223280 2011-06-18 23:02:53Z rmacklem $");
|
37
| 37
|
| 38#include "opt_kdtrace.h" 39
|
38/* 39 * These functions support the macros and help fiddle mbuf chains for 40 * the nfs op functions. They do things like create the rpc header and 41 * copy data between mbuf chains and uio lists. 42 */ 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/kernel.h> 47#include <sys/bio.h> 48#include <sys/buf.h> 49#include <sys/proc.h> 50#include <sys/mount.h> 51#include <sys/vnode.h> 52#include <sys/namei.h> 53#include <sys/mbuf.h> 54#include <sys/socket.h> 55#include <sys/stat.h> 56#include <sys/malloc.h> 57#include <sys/sysent.h> 58#include <sys/syscall.h> 59#include <sys/sysproto.h> 60#include <sys/taskqueue.h> 61 62#include <vm/vm.h> 63#include <vm/vm_object.h> 64#include <vm/vm_extern.h> 65#include <vm/uma.h> 66 67#include <fs/nfs/nfsport.h> 68#include <fs/nfsclient/nfsnode.h> 69#include <fs/nfsclient/nfsmount.h> 70#include <fs/nfsclient/nfs.h>
| 40/* 41 * These functions support the macros and help fiddle mbuf chains for 42 * the nfs op functions. They do things like create the rpc header and 43 * copy data between mbuf chains and uio lists. 44 */ 45 46#include <sys/param.h> 47#include <sys/systm.h> 48#include <sys/kernel.h> 49#include <sys/bio.h> 50#include <sys/buf.h> 51#include <sys/proc.h> 52#include <sys/mount.h> 53#include <sys/vnode.h> 54#include <sys/namei.h> 55#include <sys/mbuf.h> 56#include <sys/socket.h> 57#include <sys/stat.h> 58#include <sys/malloc.h> 59#include <sys/sysent.h> 60#include <sys/syscall.h> 61#include <sys/sysproto.h> 62#include <sys/taskqueue.h> 63 64#include <vm/vm.h> 65#include <vm/vm_object.h> 66#include <vm/vm_extern.h> 67#include <vm/uma.h> 68 69#include <fs/nfs/nfsport.h> 70#include <fs/nfsclient/nfsnode.h> 71#include <fs/nfsclient/nfsmount.h> 72#include <fs/nfsclient/nfs.h>
|
| 73#include <fs/nfsclient/nfs_kdtrace.h>
|
71 72#include <netinet/in.h> 73 74/* 75 * Note that stdarg.h and the ANSI style va_start macro is used for both 76 * ANSI and traditional C compilers. 77 */ 78#include <machine/stdarg.h> 79 80extern struct mtx ncl_iod_mutex; 81extern enum nfsiod_state ncl_iodwant[NFS_MAXASYNCDAEMON]; 82extern struct nfsmount *ncl_iodmount[NFS_MAXASYNCDAEMON]; 83extern int ncl_numasync; 84extern unsigned int ncl_iodmax; 85extern struct nfsstats newnfsstats; 86 87struct task ncl_nfsiodnew_task; 88 89int 90ncl_uninit(struct vfsconf *vfsp) 91{ 92 /* 93 * XXX: Unloading of nfscl module is unsupported. 94 */ 95#if 0 96 int i; 97 98 /* 99 * Tell all nfsiod processes to exit. Clear ncl_iodmax, and wakeup 100 * any sleeping nfsiods so they check ncl_iodmax and exit. 101 */ 102 mtx_lock(&ncl_iod_mutex); 103 ncl_iodmax = 0; 104 for (i = 0; i < ncl_numasync; i++) 105 if (ncl_iodwant[i] == NFSIOD_AVAILABLE) 106 wakeup(&ncl_iodwant[i]); 107 /* The last nfsiod to exit will wake us up when ncl_numasync hits 0 */ 108 while (ncl_numasync) 109 msleep(&ncl_numasync, &ncl_iod_mutex, PWAIT, "ioddie", 0); 110 mtx_unlock(&ncl_iod_mutex); 111 ncl_nhuninit(); 112 return (0); 113#else 114 return (EOPNOTSUPP); 115#endif 116} 117 118void 119ncl_dircookie_lock(struct nfsnode *np) 120{ 121 mtx_lock(&np->n_mtx); 122 while (np->n_flag & NDIRCOOKIELK) 123 (void) msleep(&np->n_flag, &np->n_mtx, PZERO, "nfsdirlk", 0); 124 np->n_flag |= NDIRCOOKIELK; 125 mtx_unlock(&np->n_mtx); 126} 127 128void 129ncl_dircookie_unlock(struct nfsnode *np) 130{ 131 mtx_lock(&np->n_mtx); 132 np->n_flag &= ~NDIRCOOKIELK; 133 wakeup(&np->n_flag); 134 mtx_unlock(&np->n_mtx); 135} 136 137int 138ncl_upgrade_vnlock(struct vnode *vp) 139{ 140 int old_lock; 141 142 ASSERT_VOP_LOCKED(vp, "ncl_upgrade_vnlock"); 143 old_lock = VOP_ISLOCKED(vp); 144 if (old_lock != LK_EXCLUSIVE) { 145 KASSERT(old_lock == LK_SHARED, 146 ("ncl_upgrade_vnlock: wrong old_lock %d", old_lock)); 147 /* Upgrade to exclusive lock, this might block */ 148 vn_lock(vp, LK_UPGRADE | LK_RETRY); 149 } 150 return (old_lock); 151} 152 153void 154ncl_downgrade_vnlock(struct vnode *vp, int old_lock) 155{ 156 if (old_lock != LK_EXCLUSIVE) { 157 KASSERT(old_lock == LK_SHARED, ("wrong old_lock %d", old_lock)); 158 /* Downgrade from exclusive lock. */ 159 vn_lock(vp, LK_DOWNGRADE | LK_RETRY); 160 } 161} 162 163void 164ncl_printf(const char *fmt, ...) 165{ 166 va_list ap; 167 168 mtx_lock(&Giant); 169 va_start(ap, fmt); 170 vprintf(fmt, ap); 171 va_end(ap); 172 mtx_unlock(&Giant); 173} 174 175#ifdef NFS_ACDEBUG 176#include <sys/sysctl.h> 177SYSCTL_DECL(_vfs_nfs); 178static int nfs_acdebug; 179SYSCTL_INT(_vfs_nfs, OID_AUTO, acdebug, CTLFLAG_RW, &nfs_acdebug, 0, ""); 180#endif 181 182/* 183 * Check the time stamp 184 * If the cache is valid, copy contents to *vap and return 0 185 * otherwise return an error 186 */ 187int 188ncl_getattrcache(struct vnode *vp, struct vattr *vaper) 189{ 190 struct nfsnode *np; 191 struct vattr *vap; 192 struct nfsmount *nmp; 193 int timeo, mustflush; 194 195 np = VTONFS(vp); 196 vap = &np->n_vattr.na_vattr; 197 nmp = VFSTONFS(vp->v_mount); 198 mustflush = nfscl_mustflush(vp); /* must be before mtx_lock() */ 199#ifdef NFS_ACDEBUG 200 mtx_lock(&Giant); /* ncl_printf() */ 201#endif 202 mtx_lock(&np->n_mtx); 203 /* XXX n_mtime doesn't seem to be updated on a miss-and-reload */ 204 timeo = (time_second - np->n_mtime.tv_sec) / 10; 205 206#ifdef NFS_ACDEBUG 207 if (nfs_acdebug>1) 208 ncl_printf("nfs_getattrcache: initial timeo = %d\n", timeo); 209#endif 210 211 if (vap->va_type == VDIR) { 212 if ((np->n_flag & NMODIFIED) || timeo < nmp->nm_acdirmin) 213 timeo = nmp->nm_acdirmin; 214 else if (timeo > nmp->nm_acdirmax) 215 timeo = nmp->nm_acdirmax; 216 } else { 217 if ((np->n_flag & NMODIFIED) || timeo < nmp->nm_acregmin) 218 timeo = nmp->nm_acregmin; 219 else if (timeo > nmp->nm_acregmax) 220 timeo = nmp->nm_acregmax; 221 } 222 223#ifdef NFS_ACDEBUG 224 if (nfs_acdebug > 2) 225 ncl_printf("acregmin %d; acregmax %d; acdirmin %d; acdirmax %d\n", 226 nmp->nm_acregmin, nmp->nm_acregmax, 227 nmp->nm_acdirmin, nmp->nm_acdirmax); 228 229 if (nfs_acdebug) 230 ncl_printf("nfs_getattrcache: age = %d; final timeo = %d\n", 231 (time_second - np->n_attrstamp), timeo); 232#endif 233 234 if ((time_second - np->n_attrstamp) >= timeo && 235 (mustflush != 0 || np->n_attrstamp == 0)) { 236 newnfsstats.attrcache_misses++; 237 mtx_unlock(&np->n_mtx); 238#ifdef NFS_ACDEBUG 239 mtx_unlock(&Giant); /* ncl_printf() */ 240#endif
| 74 75#include <netinet/in.h> 76 77/* 78 * Note that stdarg.h and the ANSI style va_start macro is used for both 79 * ANSI and traditional C compilers. 80 */ 81#include <machine/stdarg.h> 82 83extern struct mtx ncl_iod_mutex; 84extern enum nfsiod_state ncl_iodwant[NFS_MAXASYNCDAEMON]; 85extern struct nfsmount *ncl_iodmount[NFS_MAXASYNCDAEMON]; 86extern int ncl_numasync; 87extern unsigned int ncl_iodmax; 88extern struct nfsstats newnfsstats; 89 90struct task ncl_nfsiodnew_task; 91 92int 93ncl_uninit(struct vfsconf *vfsp) 94{ 95 /* 96 * XXX: Unloading of nfscl module is unsupported. 97 */ 98#if 0 99 int i; 100 101 /* 102 * Tell all nfsiod processes to exit. Clear ncl_iodmax, and wakeup 103 * any sleeping nfsiods so they check ncl_iodmax and exit. 104 */ 105 mtx_lock(&ncl_iod_mutex); 106 ncl_iodmax = 0; 107 for (i = 0; i < ncl_numasync; i++) 108 if (ncl_iodwant[i] == NFSIOD_AVAILABLE) 109 wakeup(&ncl_iodwant[i]); 110 /* The last nfsiod to exit will wake us up when ncl_numasync hits 0 */ 111 while (ncl_numasync) 112 msleep(&ncl_numasync, &ncl_iod_mutex, PWAIT, "ioddie", 0); 113 mtx_unlock(&ncl_iod_mutex); 114 ncl_nhuninit(); 115 return (0); 116#else 117 return (EOPNOTSUPP); 118#endif 119} 120 121void 122ncl_dircookie_lock(struct nfsnode *np) 123{ 124 mtx_lock(&np->n_mtx); 125 while (np->n_flag & NDIRCOOKIELK) 126 (void) msleep(&np->n_flag, &np->n_mtx, PZERO, "nfsdirlk", 0); 127 np->n_flag |= NDIRCOOKIELK; 128 mtx_unlock(&np->n_mtx); 129} 130 131void 132ncl_dircookie_unlock(struct nfsnode *np) 133{ 134 mtx_lock(&np->n_mtx); 135 np->n_flag &= ~NDIRCOOKIELK; 136 wakeup(&np->n_flag); 137 mtx_unlock(&np->n_mtx); 138} 139 140int 141ncl_upgrade_vnlock(struct vnode *vp) 142{ 143 int old_lock; 144 145 ASSERT_VOP_LOCKED(vp, "ncl_upgrade_vnlock"); 146 old_lock = VOP_ISLOCKED(vp); 147 if (old_lock != LK_EXCLUSIVE) { 148 KASSERT(old_lock == LK_SHARED, 149 ("ncl_upgrade_vnlock: wrong old_lock %d", old_lock)); 150 /* Upgrade to exclusive lock, this might block */ 151 vn_lock(vp, LK_UPGRADE | LK_RETRY); 152 } 153 return (old_lock); 154} 155 156void 157ncl_downgrade_vnlock(struct vnode *vp, int old_lock) 158{ 159 if (old_lock != LK_EXCLUSIVE) { 160 KASSERT(old_lock == LK_SHARED, ("wrong old_lock %d", old_lock)); 161 /* Downgrade from exclusive lock. */ 162 vn_lock(vp, LK_DOWNGRADE | LK_RETRY); 163 } 164} 165 166void 167ncl_printf(const char *fmt, ...) 168{ 169 va_list ap; 170 171 mtx_lock(&Giant); 172 va_start(ap, fmt); 173 vprintf(fmt, ap); 174 va_end(ap); 175 mtx_unlock(&Giant); 176} 177 178#ifdef NFS_ACDEBUG 179#include <sys/sysctl.h> 180SYSCTL_DECL(_vfs_nfs); 181static int nfs_acdebug; 182SYSCTL_INT(_vfs_nfs, OID_AUTO, acdebug, CTLFLAG_RW, &nfs_acdebug, 0, ""); 183#endif 184 185/* 186 * Check the time stamp 187 * If the cache is valid, copy contents to *vap and return 0 188 * otherwise return an error 189 */ 190int 191ncl_getattrcache(struct vnode *vp, struct vattr *vaper) 192{ 193 struct nfsnode *np; 194 struct vattr *vap; 195 struct nfsmount *nmp; 196 int timeo, mustflush; 197 198 np = VTONFS(vp); 199 vap = &np->n_vattr.na_vattr; 200 nmp = VFSTONFS(vp->v_mount); 201 mustflush = nfscl_mustflush(vp); /* must be before mtx_lock() */ 202#ifdef NFS_ACDEBUG 203 mtx_lock(&Giant); /* ncl_printf() */ 204#endif 205 mtx_lock(&np->n_mtx); 206 /* XXX n_mtime doesn't seem to be updated on a miss-and-reload */ 207 timeo = (time_second - np->n_mtime.tv_sec) / 10; 208 209#ifdef NFS_ACDEBUG 210 if (nfs_acdebug>1) 211 ncl_printf("nfs_getattrcache: initial timeo = %d\n", timeo); 212#endif 213 214 if (vap->va_type == VDIR) { 215 if ((np->n_flag & NMODIFIED) || timeo < nmp->nm_acdirmin) 216 timeo = nmp->nm_acdirmin; 217 else if (timeo > nmp->nm_acdirmax) 218 timeo = nmp->nm_acdirmax; 219 } else { 220 if ((np->n_flag & NMODIFIED) || timeo < nmp->nm_acregmin) 221 timeo = nmp->nm_acregmin; 222 else if (timeo > nmp->nm_acregmax) 223 timeo = nmp->nm_acregmax; 224 } 225 226#ifdef NFS_ACDEBUG 227 if (nfs_acdebug > 2) 228 ncl_printf("acregmin %d; acregmax %d; acdirmin %d; acdirmax %d\n", 229 nmp->nm_acregmin, nmp->nm_acregmax, 230 nmp->nm_acdirmin, nmp->nm_acdirmax); 231 232 if (nfs_acdebug) 233 ncl_printf("nfs_getattrcache: age = %d; final timeo = %d\n", 234 (time_second - np->n_attrstamp), timeo); 235#endif 236 237 if ((time_second - np->n_attrstamp) >= timeo && 238 (mustflush != 0 || np->n_attrstamp == 0)) { 239 newnfsstats.attrcache_misses++; 240 mtx_unlock(&np->n_mtx); 241#ifdef NFS_ACDEBUG 242 mtx_unlock(&Giant); /* ncl_printf() */ 243#endif
|
| 244 KDTRACE_NFS_ATTRCACHE_GET_MISS(vp);
|
241 return( ENOENT); 242 } 243 newnfsstats.attrcache_hits++; 244 if (vap->va_size != np->n_size) { 245 if (vap->va_type == VREG) { 246 if (np->n_flag & NMODIFIED) { 247 if (vap->va_size < np->n_size) 248 vap->va_size = np->n_size; 249 else 250 np->n_size = vap->va_size; 251 } else { 252 np->n_size = vap->va_size; 253 } 254 vnode_pager_setsize(vp, np->n_size); 255 } else { 256 np->n_size = vap->va_size; 257 } 258 } 259 bcopy((caddr_t)vap, (caddr_t)vaper, sizeof(struct vattr)); 260 if (np->n_flag & NCHG) { 261 if (np->n_flag & NACC) 262 vaper->va_atime = np->n_atim; 263 if (np->n_flag & NUPD) 264 vaper->va_mtime = np->n_mtim; 265 } 266 mtx_unlock(&np->n_mtx); 267#ifdef NFS_ACDEBUG 268 mtx_unlock(&Giant); /* ncl_printf() */ 269#endif
| 245 return( ENOENT); 246 } 247 newnfsstats.attrcache_hits++; 248 if (vap->va_size != np->n_size) { 249 if (vap->va_type == VREG) { 250 if (np->n_flag & NMODIFIED) { 251 if (vap->va_size < np->n_size) 252 vap->va_size = np->n_size; 253 else 254 np->n_size = vap->va_size; 255 } else { 256 np->n_size = vap->va_size; 257 } 258 vnode_pager_setsize(vp, np->n_size); 259 } else { 260 np->n_size = vap->va_size; 261 } 262 } 263 bcopy((caddr_t)vap, (caddr_t)vaper, sizeof(struct vattr)); 264 if (np->n_flag & NCHG) { 265 if (np->n_flag & NACC) 266 vaper->va_atime = np->n_atim; 267 if (np->n_flag & NUPD) 268 vaper->va_mtime = np->n_mtim; 269 } 270 mtx_unlock(&np->n_mtx); 271#ifdef NFS_ACDEBUG 272 mtx_unlock(&Giant); /* ncl_printf() */ 273#endif
|
| 274 KDTRACE_NFS_ATTRCACHE_GET_HIT(vp, vap);
|
270 return (0); 271} 272 273static nfsuint64 nfs_nullcookie = { { 0, 0 } }; 274/* 275 * This function finds the directory cookie that corresponds to the 276 * logical byte offset given. 277 */ 278nfsuint64 * 279ncl_getcookie(struct nfsnode *np, off_t off, int add) 280{ 281 struct nfsdmap *dp, *dp2; 282 int pos; 283 nfsuint64 *retval = NULL; 284 285 pos = (uoff_t)off / NFS_DIRBLKSIZ; 286 if (pos == 0 || off < 0) { 287 KASSERT(!add, ("nfs getcookie add at <= 0")); 288 return (&nfs_nullcookie); 289 } 290 pos--; 291 dp = LIST_FIRST(&np->n_cookies); 292 if (!dp) { 293 if (add) { 294 MALLOC(dp, struct nfsdmap *, sizeof (struct nfsdmap), 295 M_NFSDIROFF, M_WAITOK); 296 dp->ndm_eocookie = 0; 297 LIST_INSERT_HEAD(&np->n_cookies, dp, ndm_list); 298 } else 299 goto out; 300 } 301 while (pos >= NFSNUMCOOKIES) { 302 pos -= NFSNUMCOOKIES; 303 if (LIST_NEXT(dp, ndm_list)) { 304 if (!add && dp->ndm_eocookie < NFSNUMCOOKIES && 305 pos >= dp->ndm_eocookie) 306 goto out; 307 dp = LIST_NEXT(dp, ndm_list); 308 } else if (add) { 309 MALLOC(dp2, struct nfsdmap *, sizeof (struct nfsdmap), 310 M_NFSDIROFF, M_WAITOK); 311 dp2->ndm_eocookie = 0; 312 LIST_INSERT_AFTER(dp, dp2, ndm_list); 313 dp = dp2; 314 } else 315 goto out; 316 } 317 if (pos >= dp->ndm_eocookie) { 318 if (add) 319 dp->ndm_eocookie = pos + 1; 320 else 321 goto out; 322 } 323 retval = &dp->ndm_cookies[pos]; 324out: 325 return (retval); 326} 327 328/* 329 * Invalidate cached directory information, except for the actual directory 330 * blocks (which are invalidated separately). 331 * Done mainly to avoid the use of stale offset cookies. 332 */ 333void 334ncl_invaldir(struct vnode *vp) 335{ 336 struct nfsnode *np = VTONFS(vp); 337 338 KASSERT(vp->v_type == VDIR, ("nfs: invaldir not dir")); 339 ncl_dircookie_lock(np); 340 np->n_direofoffset = 0; 341 np->n_cookieverf.nfsuquad[0] = 0; 342 np->n_cookieverf.nfsuquad[1] = 0; 343 if (LIST_FIRST(&np->n_cookies)) 344 LIST_FIRST(&np->n_cookies)->ndm_eocookie = 0; 345 ncl_dircookie_unlock(np); 346} 347 348/* 349 * The write verifier has changed (probably due to a server reboot), so all 350 * B_NEEDCOMMIT blocks will have to be written again. Since they are on the 351 * dirty block list as B_DELWRI, all this takes is clearing the B_NEEDCOMMIT 352 * and B_CLUSTEROK flags. Once done the new write verifier can be set for the 353 * mount point. 354 * 355 * B_CLUSTEROK must be cleared along with B_NEEDCOMMIT because stage 1 data 356 * writes are not clusterable. 357 */ 358void 359ncl_clearcommit(struct mount *mp) 360{ 361 struct vnode *vp, *nvp; 362 struct buf *bp, *nbp; 363 struct bufobj *bo; 364 365 MNT_ILOCK(mp); 366 MNT_VNODE_FOREACH(vp, mp, nvp) { 367 bo = &vp->v_bufobj; 368 VI_LOCK(vp); 369 if (vp->v_iflag & VI_DOOMED) { 370 VI_UNLOCK(vp); 371 continue; 372 } 373 vholdl(vp); 374 VI_UNLOCK(vp); 375 MNT_IUNLOCK(mp); 376 BO_LOCK(bo); 377 TAILQ_FOREACH_SAFE(bp, &bo->bo_dirty.bv_hd, b_bobufs, nbp) { 378 if (!BUF_ISLOCKED(bp) && 379 (bp->b_flags & (B_DELWRI | B_NEEDCOMMIT)) 380 == (B_DELWRI | B_NEEDCOMMIT)) 381 bp->b_flags &= ~(B_NEEDCOMMIT | B_CLUSTEROK); 382 } 383 BO_UNLOCK(bo); 384 vdrop(vp); 385 MNT_ILOCK(mp); 386 } 387 MNT_IUNLOCK(mp); 388} 389 390/* 391 * Called once to initialize data structures... 392 */ 393int 394ncl_init(struct vfsconf *vfsp) 395{ 396 int i; 397 398 /* Ensure async daemons disabled */ 399 for (i = 0; i < NFS_MAXASYNCDAEMON; i++) { 400 ncl_iodwant[i] = NFSIOD_NOT_AVAILABLE; 401 ncl_iodmount[i] = NULL; 402 } 403 TASK_INIT(&ncl_nfsiodnew_task, 0, ncl_nfsiodnew_tq, NULL); 404 ncl_nhinit(); /* Init the nfsnode table */ 405 406 return (0); 407} 408
| 275 return (0); 276} 277 278static nfsuint64 nfs_nullcookie = { { 0, 0 } }; 279/* 280 * This function finds the directory cookie that corresponds to the 281 * logical byte offset given. 282 */ 283nfsuint64 * 284ncl_getcookie(struct nfsnode *np, off_t off, int add) 285{ 286 struct nfsdmap *dp, *dp2; 287 int pos; 288 nfsuint64 *retval = NULL; 289 290 pos = (uoff_t)off / NFS_DIRBLKSIZ; 291 if (pos == 0 || off < 0) { 292 KASSERT(!add, ("nfs getcookie add at <= 0")); 293 return (&nfs_nullcookie); 294 } 295 pos--; 296 dp = LIST_FIRST(&np->n_cookies); 297 if (!dp) { 298 if (add) { 299 MALLOC(dp, struct nfsdmap *, sizeof (struct nfsdmap), 300 M_NFSDIROFF, M_WAITOK); 301 dp->ndm_eocookie = 0; 302 LIST_INSERT_HEAD(&np->n_cookies, dp, ndm_list); 303 } else 304 goto out; 305 } 306 while (pos >= NFSNUMCOOKIES) { 307 pos -= NFSNUMCOOKIES; 308 if (LIST_NEXT(dp, ndm_list)) { 309 if (!add && dp->ndm_eocookie < NFSNUMCOOKIES && 310 pos >= dp->ndm_eocookie) 311 goto out; 312 dp = LIST_NEXT(dp, ndm_list); 313 } else if (add) { 314 MALLOC(dp2, struct nfsdmap *, sizeof (struct nfsdmap), 315 M_NFSDIROFF, M_WAITOK); 316 dp2->ndm_eocookie = 0; 317 LIST_INSERT_AFTER(dp, dp2, ndm_list); 318 dp = dp2; 319 } else 320 goto out; 321 } 322 if (pos >= dp->ndm_eocookie) { 323 if (add) 324 dp->ndm_eocookie = pos + 1; 325 else 326 goto out; 327 } 328 retval = &dp->ndm_cookies[pos]; 329out: 330 return (retval); 331} 332 333/* 334 * Invalidate cached directory information, except for the actual directory 335 * blocks (which are invalidated separately). 336 * Done mainly to avoid the use of stale offset cookies. 337 */ 338void 339ncl_invaldir(struct vnode *vp) 340{ 341 struct nfsnode *np = VTONFS(vp); 342 343 KASSERT(vp->v_type == VDIR, ("nfs: invaldir not dir")); 344 ncl_dircookie_lock(np); 345 np->n_direofoffset = 0; 346 np->n_cookieverf.nfsuquad[0] = 0; 347 np->n_cookieverf.nfsuquad[1] = 0; 348 if (LIST_FIRST(&np->n_cookies)) 349 LIST_FIRST(&np->n_cookies)->ndm_eocookie = 0; 350 ncl_dircookie_unlock(np); 351} 352 353/* 354 * The write verifier has changed (probably due to a server reboot), so all 355 * B_NEEDCOMMIT blocks will have to be written again. Since they are on the 356 * dirty block list as B_DELWRI, all this takes is clearing the B_NEEDCOMMIT 357 * and B_CLUSTEROK flags. Once done the new write verifier can be set for the 358 * mount point. 359 * 360 * B_CLUSTEROK must be cleared along with B_NEEDCOMMIT because stage 1 data 361 * writes are not clusterable. 362 */ 363void 364ncl_clearcommit(struct mount *mp) 365{ 366 struct vnode *vp, *nvp; 367 struct buf *bp, *nbp; 368 struct bufobj *bo; 369 370 MNT_ILOCK(mp); 371 MNT_VNODE_FOREACH(vp, mp, nvp) { 372 bo = &vp->v_bufobj; 373 VI_LOCK(vp); 374 if (vp->v_iflag & VI_DOOMED) { 375 VI_UNLOCK(vp); 376 continue; 377 } 378 vholdl(vp); 379 VI_UNLOCK(vp); 380 MNT_IUNLOCK(mp); 381 BO_LOCK(bo); 382 TAILQ_FOREACH_SAFE(bp, &bo->bo_dirty.bv_hd, b_bobufs, nbp) { 383 if (!BUF_ISLOCKED(bp) && 384 (bp->b_flags & (B_DELWRI | B_NEEDCOMMIT)) 385 == (B_DELWRI | B_NEEDCOMMIT)) 386 bp->b_flags &= ~(B_NEEDCOMMIT | B_CLUSTEROK); 387 } 388 BO_UNLOCK(bo); 389 vdrop(vp); 390 MNT_ILOCK(mp); 391 } 392 MNT_IUNLOCK(mp); 393} 394 395/* 396 * Called once to initialize data structures... 397 */ 398int 399ncl_init(struct vfsconf *vfsp) 400{ 401 int i; 402 403 /* Ensure async daemons disabled */ 404 for (i = 0; i < NFS_MAXASYNCDAEMON; i++) { 405 ncl_iodwant[i] = NFSIOD_NOT_AVAILABLE; 406 ncl_iodmount[i] = NULL; 407 } 408 TASK_INIT(&ncl_nfsiodnew_task, 0, ncl_nfsiodnew_tq, NULL); 409 ncl_nhinit(); /* Init the nfsnode table */ 410 411 return (0); 412} 413
|