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