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