Commit | Line | Data |
---|---|---|
a2907882 KM |
1 | /* |
2 | * Copyright (c) 1989 The Regents of the University of California. | |
3 | * 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 are permitted | |
9 | * provided that the above copyright notice and this paragraph are | |
10 | * duplicated in all such forms and that any documentation, | |
11 | * advertising materials, and other materials related to such | |
12 | * distribution and use acknowledge that the software was developed | |
13 | * by the University of California, Berkeley. The name of the | |
14 | * University may not be used to endorse or promote products derived | |
15 | * from this software without specific prior written permission. | |
16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
17 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
19 | * | |
e49b1a6c | 20 | * @(#)nfs_vnops.c 7.32 (Berkeley) %G% |
a2907882 KM |
21 | */ |
22 | ||
23 | /* | |
24 | * vnode op calls for sun nfs version 2 | |
25 | */ | |
26 | ||
27 | #include "machine/pte.h" | |
28 | #include "machine/mtpr.h" | |
a2907882 KM |
29 | #include "param.h" |
30 | #include "user.h" | |
31 | #include "proc.h" | |
e49b1a6c | 32 | #include "kernel.h" |
a2907882 KM |
33 | #include "mount.h" |
34 | #include "buf.h" | |
35 | #include "vm.h" | |
a2907882 KM |
36 | #include "malloc.h" |
37 | #include "mbuf.h" | |
a2907882 KM |
38 | #include "errno.h" |
39 | #include "file.h" | |
40 | #include "conf.h" | |
41 | #include "vnode.h" | |
8c379a26 | 42 | #include "text.h" |
9238aa59 | 43 | #include "map.h" |
a2907882 KM |
44 | #include "nfsv2.h" |
45 | #include "nfs.h" | |
46 | #include "nfsnode.h" | |
47 | #include "nfsmount.h" | |
48 | #include "xdr_subs.h" | |
49 | #include "nfsm_subs.h" | |
9238aa59 | 50 | #include "nfsiom.h" |
a2907882 KM |
51 | |
52 | /* Defs */ | |
53 | #define TRUE 1 | |
54 | #define FALSE 0 | |
55 | ||
56 | /* Global vars */ | |
57 | int nfs_lookup(), | |
58 | nfs_create(), | |
f67785e5 | 59 | nfs_mknod(), |
a2907882 KM |
60 | nfs_open(), |
61 | nfs_close(), | |
62 | nfs_access(), | |
63 | nfs_getattr(), | |
64 | nfs_setattr(), | |
65 | nfs_read(), | |
66 | nfs_write(), | |
67 | vfs_noop(), | |
68 | vfs_nullop(), | |
69 | nfs_remove(), | |
70 | nfs_link(), | |
71 | nfs_rename(), | |
72 | nfs_mkdir(), | |
73 | nfs_rmdir(), | |
74 | nfs_symlink(), | |
75 | nfs_readdir(), | |
76 | nfs_readlink(), | |
77 | nfs_abortop(), | |
78 | nfs_lock(), | |
79 | nfs_unlock(), | |
80 | nfs_bmap(), | |
81 | nfs_strategy(), | |
9238aa59 | 82 | nfs_fsync(), |
8c7139ba | 83 | nfs_inactive(), |
d002709d | 84 | nfs_reclaim(), |
2bde67fd KM |
85 | nfs_print(), |
86 | nfs_islocked(); | |
a2907882 KM |
87 | |
88 | struct vnodeops nfsv2_vnodeops = { | |
d002709d KM |
89 | nfs_lookup, /* lookup */ |
90 | nfs_create, /* create */ | |
91 | nfs_mknod, /* mknod */ | |
92 | nfs_open, /* open */ | |
93 | nfs_close, /* close */ | |
94 | nfs_access, /* access */ | |
95 | nfs_getattr, /* getattr */ | |
96 | nfs_setattr, /* setattr */ | |
97 | nfs_read, /* read */ | |
98 | nfs_write, /* write */ | |
99 | vfs_noop, /* ioctl */ | |
100 | vfs_noop, /* select */ | |
101 | vfs_noop, /* mmap */ | |
102 | nfs_fsync, /* fsync */ | |
103 | vfs_nullop, /* seek */ | |
104 | nfs_remove, /* remove */ | |
105 | nfs_link, /* link */ | |
106 | nfs_rename, /* rename */ | |
107 | nfs_mkdir, /* mkdir */ | |
108 | nfs_rmdir, /* rmdir */ | |
109 | nfs_symlink, /* symlink */ | |
110 | nfs_readdir, /* readdir */ | |
111 | nfs_readlink, /* readlink */ | |
112 | nfs_abortop, /* abortop */ | |
113 | nfs_inactive, /* inactive */ | |
114 | nfs_reclaim, /* reclaim */ | |
115 | nfs_lock, /* lock */ | |
116 | nfs_unlock, /* unlock */ | |
117 | nfs_bmap, /* bmap */ | |
118 | nfs_strategy, /* strategy */ | |
119 | nfs_print, /* print */ | |
2bde67fd | 120 | nfs_islocked, /* islocked */ |
a2907882 KM |
121 | }; |
122 | ||
123 | /* Special device vnode ops */ | |
8a1675f3 KM |
124 | int spec_lookup(), |
125 | spec_open(), | |
126 | spec_read(), | |
127 | spec_write(), | |
128 | spec_strategy(), | |
d002709d | 129 | spec_bmap(), |
8a1675f3 KM |
130 | spec_ioctl(), |
131 | spec_select(), | |
132 | spec_close(), | |
133 | spec_badop(), | |
134 | spec_nullop(); | |
a2907882 | 135 | |
8a1675f3 | 136 | struct vnodeops spec_nfsv2nodeops = { |
9106dc18 KM |
137 | spec_lookup, /* lookup */ |
138 | spec_badop, /* create */ | |
139 | spec_badop, /* mknod */ | |
140 | spec_open, /* open */ | |
141 | spec_close, /* close */ | |
142 | nfs_access, /* access */ | |
143 | nfs_getattr, /* getattr */ | |
144 | nfs_setattr, /* setattr */ | |
145 | spec_read, /* read */ | |
146 | spec_write, /* write */ | |
147 | spec_ioctl, /* ioctl */ | |
148 | spec_select, /* select */ | |
149 | spec_badop, /* mmap */ | |
150 | spec_nullop, /* fsync */ | |
151 | spec_badop, /* seek */ | |
152 | spec_badop, /* remove */ | |
153 | spec_badop, /* link */ | |
154 | spec_badop, /* rename */ | |
155 | spec_badop, /* mkdir */ | |
156 | spec_badop, /* rmdir */ | |
157 | spec_badop, /* symlink */ | |
158 | spec_badop, /* readdir */ | |
159 | spec_badop, /* readlink */ | |
160 | spec_badop, /* abortop */ | |
161 | nfs_inactive, /* inactive */ | |
162 | nfs_reclaim, /* reclaim */ | |
163 | nfs_lock, /* lock */ | |
164 | nfs_unlock, /* unlock */ | |
d002709d | 165 | spec_bmap, /* bmap */ |
9106dc18 | 166 | spec_strategy, /* strategy */ |
d002709d | 167 | nfs_print, /* print */ |
2bde67fd | 168 | nfs_islocked, /* islocked */ |
a2907882 KM |
169 | }; |
170 | ||
b2d955e4 KM |
171 | #ifdef FIFO |
172 | int fifo_lookup(), | |
173 | fifo_open(), | |
174 | fifo_read(), | |
175 | fifo_write(), | |
176 | fifo_bmap(), | |
177 | fifo_ioctl(), | |
178 | fifo_select(), | |
179 | fifo_close(), | |
180 | fifo_print(), | |
181 | fifo_badop(), | |
182 | fifo_nullop(); | |
183 | ||
184 | struct vnodeops fifo_nfsv2nodeops = { | |
185 | fifo_lookup, /* lookup */ | |
186 | fifo_badop, /* create */ | |
187 | fifo_badop, /* mknod */ | |
188 | fifo_open, /* open */ | |
189 | fifo_close, /* close */ | |
190 | nfs_access, /* access */ | |
191 | nfs_getattr, /* getattr */ | |
192 | nfs_setattr, /* setattr */ | |
193 | fifo_read, /* read */ | |
194 | fifo_write, /* write */ | |
195 | fifo_ioctl, /* ioctl */ | |
196 | fifo_select, /* select */ | |
197 | fifo_badop, /* mmap */ | |
198 | fifo_nullop, /* fsync */ | |
199 | fifo_badop, /* seek */ | |
200 | fifo_badop, /* remove */ | |
201 | fifo_badop, /* link */ | |
202 | fifo_badop, /* rename */ | |
203 | fifo_badop, /* mkdir */ | |
204 | fifo_badop, /* rmdir */ | |
205 | fifo_badop, /* symlink */ | |
206 | fifo_badop, /* readdir */ | |
207 | fifo_badop, /* readlink */ | |
208 | fifo_badop, /* abortop */ | |
209 | nfs_inactive, /* inactive */ | |
210 | nfs_reclaim, /* reclaim */ | |
211 | nfs_lock, /* lock */ | |
212 | nfs_unlock, /* unlock */ | |
213 | fifo_bmap, /* bmap */ | |
214 | fifo_badop, /* strategy */ | |
215 | nfs_print, /* print */ | |
216 | nfs_islocked, /* islocked */ | |
217 | }; | |
218 | #endif /* FIFO */ | |
219 | ||
a2907882 KM |
220 | extern u_long nfs_procids[NFS_NPROCS]; |
221 | extern u_long nfs_prog, nfs_vers; | |
a2907882 | 222 | extern char nfsiobuf[MAXPHYS+NBPG]; |
f5f6c13e | 223 | extern int nonidempotent[NFS_NPROCS]; |
9238aa59 | 224 | struct map nfsmap[NFS_MSIZ]; |
a2907882 | 225 | enum vtype v_type[NFLNK+1]; |
9238aa59 | 226 | struct buf nfs_bqueue; /* Queue head for nfsiod's */ |
ffe6f482 KM |
227 | int nfs_asyncdaemons = 0; |
228 | struct proc *nfs_iodwant[MAX_ASYNCDAEMON]; | |
9238aa59 | 229 | static int nfsmap_want = 0; |
a2907882 KM |
230 | |
231 | /* | |
232 | * nfs null call from vfs. | |
233 | */ | |
234 | nfs_null(vp, cred) | |
235 | struct vnode *vp; | |
236 | struct ucred *cred; | |
237 | { | |
13576453 KM |
238 | caddr_t bpos, dpos; |
239 | u_long xid; | |
240 | int error = 0; | |
241 | struct mbuf *mreq, *mrep, *md, *mb; | |
a2907882 KM |
242 | |
243 | nfsm_reqhead(nfs_procids[NFSPROC_NULL], cred, 0); | |
f5f6c13e | 244 | nfsm_request(vp, nonidempotent[NFSPROC_NULL]); |
a2907882 KM |
245 | nfsm_reqdone; |
246 | return (error); | |
247 | } | |
248 | ||
249 | /* | |
250 | * nfs access vnode op. | |
251 | * Essentially just get vattr and then imitate iaccess() | |
252 | */ | |
253 | nfs_access(vp, mode, cred) | |
254 | struct vnode *vp; | |
255 | int mode; | |
256 | register struct ucred *cred; | |
257 | { | |
258 | register struct vattr *vap; | |
259 | register gid_t *gp; | |
260 | struct vattr vattr; | |
261 | register int i; | |
262 | int error; | |
263 | ||
264 | /* | |
265 | * If you're the super-user, | |
266 | * you always get access. | |
267 | */ | |
268 | if (cred->cr_uid == 0) | |
269 | return (0); | |
270 | vap = &vattr; | |
9238aa59 RM |
271 | if (error = nfs_getattr(vp, vap, cred)) |
272 | return (error); | |
a2907882 KM |
273 | /* |
274 | * Access check is based on only one of owner, group, public. | |
275 | * If not owner, then check group. If not a member of the | |
276 | * group, then check public access. | |
277 | */ | |
278 | if (cred->cr_uid != vap->va_uid) { | |
279 | mode >>= 3; | |
280 | gp = cred->cr_groups; | |
281 | for (i = 0; i < cred->cr_ngroups; i++, gp++) | |
282 | if (vap->va_gid == *gp) | |
283 | goto found; | |
284 | mode >>= 3; | |
285 | found: | |
286 | ; | |
287 | } | |
288 | if ((vap->va_mode & mode) != 0) | |
289 | return (0); | |
290 | return (EACCES); | |
291 | } | |
292 | ||
293 | /* | |
294 | * nfs open vnode op | |
295 | * Just check to see if the type is ok | |
296 | */ | |
13576453 | 297 | /* ARGSUSED */ |
a2907882 KM |
298 | nfs_open(vp, mode, cred) |
299 | struct vnode *vp; | |
300 | int mode; | |
301 | struct ucred *cred; | |
302 | { | |
303 | register enum vtype vtyp; | |
304 | ||
305 | vtyp = vp->v_type; | |
306 | if (vtyp == VREG || vtyp == VDIR || vtyp == VLNK) | |
307 | return (0); | |
308 | else | |
309 | return (EACCES); | |
310 | } | |
311 | ||
312 | /* | |
313 | * nfs close vnode op | |
9238aa59 | 314 | * For reg files, invalidate any buffer cache entries. |
a2907882 | 315 | */ |
13576453 | 316 | /* ARGSUSED */ |
a2907882 KM |
317 | nfs_close(vp, fflags, cred) |
318 | register struct vnode *vp; | |
319 | int fflags; | |
320 | struct ucred *cred; | |
321 | { | |
13576453 | 322 | register struct nfsnode *np = VTONFS(vp); |
ffe6f482 | 323 | int error = 0; |
a2907882 | 324 | |
fe53c871 | 325 | if (vp->v_type == VREG && ((np->n_flag & NMODIFIED) || |
ffe6f482 | 326 | ((np->n_flag & NBUFFERED) && np->n_sillyrename))) { |
8a1675f3 | 327 | nfs_lock(vp); |
ffe6f482 | 328 | np->n_flag &= ~(NMODIFIED|NBUFFERED); |
e8540f59 | 329 | vinvalbuf(vp, TRUE); |
ffe6f482 KM |
330 | if (np->n_flag & NWRITEERR) { |
331 | np->n_flag &= ~NWRITEERR; | |
e8540f59 | 332 | error = np->n_error; |
ffe6f482 | 333 | } |
8a1675f3 | 334 | nfs_unlock(vp); |
9238aa59 | 335 | } |
a2907882 KM |
336 | return (error); |
337 | } | |
338 | ||
339 | /* | |
340 | * nfs getattr call from vfs. | |
341 | */ | |
342 | nfs_getattr(vp, vap, cred) | |
13576453 KM |
343 | register struct vnode *vp; |
344 | struct vattr *vap; | |
a2907882 KM |
345 | struct ucred *cred; |
346 | { | |
13576453 KM |
347 | register caddr_t cp; |
348 | register long t1; | |
349 | caddr_t bpos, dpos; | |
350 | u_long xid; | |
351 | int error = 0; | |
352 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
353 | |
354 | /* First look in the cache.. */ | |
355 | if (nfs_getattrcache(vp, vap) == 0) | |
356 | return (0); | |
357 | nfsstats.rpccnt[NFSPROC_GETATTR]++; | |
358 | nfsm_reqhead(nfs_procids[NFSPROC_GETATTR], cred, NFSX_FH); | |
359 | nfsm_fhtom(vp); | |
f5f6c13e | 360 | nfsm_request(vp, nonidempotent[NFSPROC_GETATTR]); |
a2907882 KM |
361 | nfsm_loadattr(vp, vap); |
362 | nfsm_reqdone; | |
363 | return (error); | |
364 | } | |
365 | ||
366 | /* | |
367 | * nfs setattr call. | |
368 | */ | |
369 | nfs_setattr(vp, vap, cred) | |
13576453 | 370 | register struct vnode *vp; |
a2907882 KM |
371 | register struct vattr *vap; |
372 | struct ucred *cred; | |
373 | { | |
9238aa59 | 374 | register struct nfsv2_sattr *sp; |
13576453 KM |
375 | register caddr_t cp; |
376 | register long t1; | |
377 | caddr_t bpos, dpos; | |
378 | u_long xid; | |
379 | int error = 0; | |
380 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
00b72154 | 381 | struct nfsnode *np; |
a2907882 KM |
382 | |
383 | nfsstats.rpccnt[NFSPROC_SETATTR]++; | |
384 | nfsm_reqhead(nfs_procids[NFSPROC_SETATTR], cred, NFSX_FH+NFSX_SATTR); | |
385 | nfsm_fhtom(vp); | |
9238aa59 | 386 | nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR); |
a2907882 | 387 | if (vap->va_mode == 0xffff) |
9238aa59 | 388 | sp->sa_mode = VNOVAL; |
a2907882 | 389 | else |
9238aa59 | 390 | sp->sa_mode = vtonfs_mode(vp->v_type, vap->va_mode); |
a2907882 | 391 | if (vap->va_uid == 0xffff) |
9238aa59 | 392 | sp->sa_uid = VNOVAL; |
a2907882 | 393 | else |
9238aa59 | 394 | sp->sa_uid = txdr_unsigned(vap->va_uid); |
a2907882 | 395 | if (vap->va_gid == 0xffff) |
9238aa59 | 396 | sp->sa_gid = VNOVAL; |
a2907882 | 397 | else |
9238aa59 RM |
398 | sp->sa_gid = txdr_unsigned(vap->va_gid); |
399 | sp->sa_size = txdr_unsigned(vap->va_size); | |
00b72154 KM |
400 | if (vap->va_size != VNOVAL) { |
401 | np = VTONFS(vp); | |
402 | if (np->n_flag & NMODIFIED) { | |
403 | np->n_flag &= ~NMODIFIED; | |
fe53c871 | 404 | vinvalbuf(vp, TRUE); |
00b72154 KM |
405 | } |
406 | } | |
e8540f59 KM |
407 | sp->sa_atime.tv_sec = txdr_unsigned(vap->va_atime.tv_sec); |
408 | sp->sa_atime.tv_usec = txdr_unsigned(vap->va_flags); | |
9238aa59 | 409 | txdr_time(&vap->va_mtime, &sp->sa_mtime); |
f5f6c13e | 410 | nfsm_request(vp, nonidempotent[NFSPROC_SETATTR]); |
a2907882 KM |
411 | nfsm_loadattr(vp, (struct vattr *)0); |
412 | /* should we fill in any vap fields ?? */ | |
413 | nfsm_reqdone; | |
414 | return (error); | |
415 | } | |
416 | ||
417 | /* | |
418 | * nfs lookup call, one step at a time... | |
419 | * First look in cache | |
420 | * If not found, unlock the directory nfsnode and do the rpc | |
421 | */ | |
422 | nfs_lookup(vp, ndp) | |
423 | register struct vnode *vp; | |
424 | register struct nameidata *ndp; | |
425 | { | |
426 | register struct vnode *vdp; | |
13576453 KM |
427 | register u_long *p; |
428 | register caddr_t cp; | |
429 | register long t1, t2; | |
430 | caddr_t bpos, dpos, cp2; | |
431 | u_long xid; | |
432 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
433 | struct vnode *newvp; |
434 | long len; | |
435 | nfsv2fh_t *fhp; | |
436 | struct nfsnode *np; | |
13576453 | 437 | int lockparent, wantparent, flag, error = 0; |
a2907882 KM |
438 | |
439 | ndp->ni_dvp = vp; | |
440 | ndp->ni_vp = NULL; | |
441 | if (vp->v_type != VDIR) | |
442 | return (ENOTDIR); | |
443 | lockparent = ndp->ni_nameiop & LOCKPARENT; | |
444 | flag = ndp->ni_nameiop & OPFLAG; | |
445 | wantparent = ndp->ni_nameiop & (LOCKPARENT|WANTPARENT); | |
ffe6f482 | 446 | if ((error = cache_lookup(ndp)) && error != ENOENT) { |
9238aa59 RM |
447 | struct vattr vattr; |
448 | int vpid; | |
449 | ||
8a1675f3 KM |
450 | if (vp == ndp->ni_rdir && ndp->ni_isdotdot) |
451 | panic("nfs_lookup: .. through root"); | |
452 | vdp = ndp->ni_vp; | |
9238aa59 | 453 | vpid = vdp->v_id; |
a2907882 | 454 | /* |
9238aa59 RM |
455 | * See the comment starting `Step through' in ufs/ufs_lookup.c |
456 | * for an explanation of the locking protocol | |
a2907882 KM |
457 | */ |
458 | if (vp == vdp) { | |
36c3043b | 459 | VREF(vdp); |
8a1675f3 | 460 | error = 0; |
a2907882 KM |
461 | } else if (ndp->ni_isdotdot) { |
462 | nfs_unlock(vp); | |
8a1675f3 | 463 | error = vget(vdp); |
a2907882 | 464 | } else { |
8a1675f3 | 465 | error = vget(vdp); |
a2907882 KM |
466 | nfs_unlock(vp); |
467 | } | |
8a1675f3 | 468 | if (!error) { |
8c379a26 KM |
469 | if (vpid == vdp->v_id) { |
470 | if (!nfs_getattr(vdp, &vattr, ndp->ni_cred) && | |
471 | vattr.va_ctime.tv_sec == VTONFS(vdp)->n_ctime) { | |
8a1675f3 KM |
472 | nfsstats.lookupcache_hits++; |
473 | return (0); | |
8c379a26 KM |
474 | } else { |
475 | cache_purge(vdp); | |
476 | nfs_nput(vdp); | |
477 | } | |
8a1675f3 KM |
478 | } else { |
479 | nfs_nput(vdp); | |
480 | } | |
9238aa59 | 481 | } |
9238aa59 | 482 | ndp->ni_vp = (struct vnode *)0; |
e8540f59 KM |
483 | } else |
484 | nfs_unlock(vp); | |
ffe6f482 | 485 | error = 0; |
a2907882 | 486 | nfsstats.lookupcache_misses++; |
a2907882 KM |
487 | nfsstats.rpccnt[NFSPROC_LOOKUP]++; |
488 | len = ndp->ni_namelen; | |
489 | nfsm_reqhead(nfs_procids[NFSPROC_LOOKUP], ndp->ni_cred, NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len)); | |
490 | nfsm_fhtom(vp); | |
491 | nfsm_strtom(ndp->ni_ptr, len, NFS_MAXNAMLEN); | |
f5f6c13e | 492 | nfsm_request(vp, nonidempotent[NFSPROC_LOOKUP]); |
a2907882 KM |
493 | nfsmout: |
494 | if (error) { | |
e8540f59 KM |
495 | if (lockparent || (flag != CREATE && flag != RENAME) || |
496 | *ndp->ni_next != 0) | |
497 | nfs_lock(vp); | |
a2907882 KM |
498 | return (ENOENT); |
499 | } | |
500 | nfsm_disect(fhp,nfsv2fh_t *,NFSX_FH); | |
501 | ||
502 | /* | |
503 | * Handle DELETE and RENAME cases... | |
504 | */ | |
505 | if (flag == DELETE && *ndp->ni_next == 0) { | |
506 | if (!bcmp(VTONFS(vp)->n_fh.fh_bytes, (caddr_t)fhp, NFSX_FH)) { | |
36c3043b | 507 | VREF(vp); |
a2907882 KM |
508 | newvp = vp; |
509 | np = VTONFS(vp); | |
510 | } else { | |
511 | if (error = nfs_nget(vp->v_mount, fhp, &np)) { | |
e8540f59 | 512 | nfs_lock(vp); |
a2907882 KM |
513 | m_freem(mrep); |
514 | return (error); | |
515 | } | |
516 | newvp = NFSTOV(np); | |
517 | } | |
f67785e5 KM |
518 | if (error = |
519 | nfs_loadattrcache(&newvp, &md, &dpos, (struct vattr *)0)) { | |
e8540f59 | 520 | nfs_lock(vp); |
a2907882 KM |
521 | if (newvp != vp) |
522 | nfs_nput(newvp); | |
523 | else | |
36c3043b | 524 | vrele(vp); |
a2907882 KM |
525 | m_freem(mrep); |
526 | return (error); | |
527 | } | |
a2907882 | 528 | ndp->ni_vp = newvp; |
e8540f59 KM |
529 | if (lockparent || vp == newvp) |
530 | nfs_lock(vp); | |
a2907882 KM |
531 | m_freem(mrep); |
532 | return (0); | |
533 | } | |
534 | ||
535 | if (flag == RENAME && wantparent && *ndp->ni_next == 0) { | |
536 | if (!bcmp(VTONFS(vp)->n_fh.fh_bytes, (caddr_t)fhp, NFSX_FH)) { | |
e8540f59 | 537 | nfs_lock(vp); |
a2907882 KM |
538 | m_freem(mrep); |
539 | return (EISDIR); | |
540 | } | |
541 | if (error = nfs_nget(vp->v_mount, fhp, &np)) { | |
e8540f59 | 542 | nfs_lock(vp); |
a2907882 KM |
543 | m_freem(mrep); |
544 | return (error); | |
545 | } | |
546 | newvp = NFSTOV(np); | |
f67785e5 KM |
547 | if (error = |
548 | nfs_loadattrcache(&newvp, &md, &dpos, (struct vattr *)0)) { | |
e8540f59 | 549 | nfs_lock(vp); |
36c3043b | 550 | nfs_nput(newvp); |
a2907882 KM |
551 | m_freem(mrep); |
552 | return (error); | |
553 | } | |
554 | ndp->ni_vp = newvp; | |
e8540f59 KM |
555 | if (lockparent) |
556 | nfs_lock(vp); | |
a2907882 KM |
557 | return (0); |
558 | } | |
559 | ||
560 | if (!bcmp(VTONFS(vp)->n_fh.fh_bytes, (caddr_t)fhp, NFSX_FH)) { | |
36c3043b | 561 | VREF(vp); |
a2907882 KM |
562 | newvp = vp; |
563 | np = VTONFS(vp); | |
564 | } else if (ndp->ni_isdotdot) { | |
a2907882 KM |
565 | if (error = nfs_nget(vp->v_mount, fhp, &np)) { |
566 | nfs_lock(vp); | |
567 | m_freem(mrep); | |
568 | return (error); | |
569 | } | |
a2907882 KM |
570 | newvp = NFSTOV(np); |
571 | } else { | |
572 | if (error = nfs_nget(vp->v_mount, fhp, &np)) { | |
e8540f59 | 573 | nfs_lock(vp); |
a2907882 KM |
574 | m_freem(mrep); |
575 | return (error); | |
576 | } | |
577 | newvp = NFSTOV(np); | |
578 | } | |
f67785e5 | 579 | if (error = nfs_loadattrcache(&newvp, &md, &dpos, (struct vattr *)0)) { |
e8540f59 | 580 | nfs_lock(vp); |
a2907882 KM |
581 | if (newvp != vp) |
582 | nfs_nput(newvp); | |
583 | else | |
36c3043b | 584 | vrele(vp); |
a2907882 KM |
585 | m_freem(mrep); |
586 | return (error); | |
587 | } | |
588 | m_freem(mrep); | |
a2907882 | 589 | |
e8540f59 KM |
590 | if (vp == newvp || (lockparent && *ndp->ni_next == '\0')) |
591 | nfs_lock(vp); | |
a2907882 | 592 | ndp->ni_vp = newvp; |
8c379a26 KM |
593 | if (error == 0 && ndp->ni_makeentry) { |
594 | np->n_ctime = np->n_vattr.va_ctime.tv_sec; | |
a2907882 | 595 | cache_enter(ndp); |
8c379a26 | 596 | } |
a2907882 KM |
597 | return (error); |
598 | } | |
599 | ||
600 | /* | |
601 | * nfs readlink call | |
602 | */ | |
603 | nfs_readlink(vp, uiop, cred) | |
13576453 | 604 | register struct vnode *vp; |
a2907882 KM |
605 | struct uio *uiop; |
606 | struct ucred *cred; | |
607 | { | |
13576453 KM |
608 | register u_long *p; |
609 | register caddr_t cp; | |
610 | register long t1; | |
611 | caddr_t bpos, dpos, cp2; | |
612 | u_long xid; | |
613 | int error = 0; | |
614 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
615 | long len; |
616 | ||
617 | nfsstats.rpccnt[NFSPROC_READLINK]++; | |
618 | nfsm_reqhead(nfs_procids[NFSPROC_READLINK], cred, NFSX_FH); | |
619 | nfsm_fhtom(vp); | |
f5f6c13e | 620 | nfsm_request(vp, nonidempotent[NFSPROC_READLINK]); |
a2907882 KM |
621 | nfsm_strsiz(len, NFS_MAXPATHLEN); |
622 | nfsm_mtouio(uiop, len); | |
623 | nfsm_reqdone; | |
624 | return (error); | |
625 | } | |
626 | ||
627 | /* | |
628 | * nfs read call | |
629 | */ | |
f8428623 | 630 | nfs_readrpc(vp, uiop, cred) |
13576453 | 631 | register struct vnode *vp; |
a2907882 | 632 | struct uio *uiop; |
a2907882 KM |
633 | struct ucred *cred; |
634 | { | |
13576453 KM |
635 | register u_long *p; |
636 | register caddr_t cp; | |
637 | register long t1; | |
638 | caddr_t bpos, dpos, cp2; | |
639 | u_long xid; | |
640 | int error = 0; | |
641 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
642 | struct nfsmount *nmp; |
643 | long len, retlen, tsiz; | |
644 | ||
645 | nmp = vfs_to_nfs(vp->v_mount); | |
646 | tsiz = uiop->uio_resid; | |
a2907882 KM |
647 | while (tsiz > 0) { |
648 | nfsstats.rpccnt[NFSPROC_READ]++; | |
649 | len = (tsiz > nmp->nm_rsize) ? nmp->nm_rsize : tsiz; | |
650 | nfsm_reqhead(nfs_procids[NFSPROC_READ], cred, NFSX_FH+NFSX_UNSIGNED*3); | |
651 | nfsm_fhtom(vp); | |
652 | nfsm_build(p, u_long *, NFSX_UNSIGNED*3); | |
f8428623 | 653 | *p++ = txdr_unsigned(uiop->uio_offset); |
a2907882 KM |
654 | *p++ = txdr_unsigned(len); |
655 | *p = 0; | |
f5f6c13e | 656 | nfsm_request(vp, nonidempotent[NFSPROC_READ]); |
a2907882 KM |
657 | nfsm_loadattr(vp, (struct vattr *)0); |
658 | nfsm_strsiz(retlen, nmp->nm_rsize); | |
659 | nfsm_mtouio(uiop, retlen); | |
660 | m_freem(mrep); | |
a2907882 KM |
661 | if (retlen < len) |
662 | tsiz = 0; | |
663 | else | |
664 | tsiz -= len; | |
665 | } | |
666 | nfsmout: | |
a2907882 KM |
667 | return (error); |
668 | } | |
669 | ||
670 | /* | |
671 | * nfs write call | |
672 | */ | |
f8428623 | 673 | nfs_writerpc(vp, uiop, cred) |
13576453 | 674 | register struct vnode *vp; |
a2907882 | 675 | struct uio *uiop; |
a2907882 KM |
676 | struct ucred *cred; |
677 | { | |
13576453 KM |
678 | register u_long *p; |
679 | register caddr_t cp; | |
680 | register long t1; | |
681 | caddr_t bpos, dpos; | |
682 | u_long xid; | |
683 | int error = 0; | |
684 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
685 | struct nfsmount *nmp; |
686 | long len, tsiz; | |
a2907882 KM |
687 | |
688 | nmp = vfs_to_nfs(vp->v_mount); | |
689 | tsiz = uiop->uio_resid; | |
a2907882 KM |
690 | while (tsiz > 0) { |
691 | nfsstats.rpccnt[NFSPROC_WRITE]++; | |
692 | len = (tsiz > nmp->nm_wsize) ? nmp->nm_wsize : tsiz; | |
693 | nfsm_reqhead(nfs_procids[NFSPROC_WRITE], cred, | |
694 | NFSX_FH+NFSX_UNSIGNED*4); | |
695 | nfsm_fhtom(vp); | |
696 | nfsm_build(p, u_long *, NFSX_UNSIGNED*4); | |
f8428623 | 697 | *(p+1) = txdr_unsigned(uiop->uio_offset); |
a2907882 KM |
698 | *(p+3) = txdr_unsigned(len); |
699 | nfsm_uiotom(uiop, len); | |
f5f6c13e | 700 | nfsm_request(vp, nonidempotent[NFSPROC_WRITE]); |
a2907882 KM |
701 | nfsm_loadattr(vp, (struct vattr *)0); |
702 | m_freem(mrep); | |
703 | tsiz -= len; | |
a2907882 KM |
704 | } |
705 | nfsmout: | |
a2907882 KM |
706 | return (error); |
707 | } | |
708 | ||
f67785e5 KM |
709 | /* |
710 | * nfs mknod call | |
711 | * This call is currently not supported. | |
712 | */ | |
713 | /* ARGSUSED */ | |
714 | nfs_mknod(ndp, vap, cred) | |
715 | struct nameidata *ndp; | |
716 | struct ucred *cred; | |
717 | struct vattr *vap; | |
718 | { | |
719 | ||
720 | nfs_abortop(ndp); | |
721 | return (EOPNOTSUPP); | |
722 | } | |
723 | ||
a2907882 KM |
724 | /* |
725 | * nfs file create call | |
726 | */ | |
727 | nfs_create(ndp, vap) | |
728 | register struct nameidata *ndp; | |
729 | register struct vattr *vap; | |
730 | { | |
9238aa59 | 731 | register struct nfsv2_sattr *sp; |
13576453 KM |
732 | register u_long *p; |
733 | register caddr_t cp; | |
734 | register long t1, t2; | |
735 | caddr_t bpos, dpos, cp2; | |
736 | u_long xid; | |
737 | int error = 0; | |
738 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
739 | |
740 | nfsstats.rpccnt[NFSPROC_CREATE]++; | |
741 | nfsm_reqhead(nfs_procids[NFSPROC_CREATE], ndp->ni_cred, | |
742 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(ndp->ni_dent.d_namlen)+NFSX_SATTR); | |
743 | nfsm_fhtom(ndp->ni_dvp); | |
744 | nfsm_strtom(ndp->ni_dent.d_name, ndp->ni_dent.d_namlen, NFS_MAXNAMLEN); | |
9238aa59 RM |
745 | nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR); |
746 | sp->sa_mode = vtonfs_mode(VREG, vap->va_mode); | |
747 | sp->sa_uid = txdr_unsigned(ndp->ni_cred->cr_uid); | |
748 | sp->sa_gid = txdr_unsigned(ndp->ni_cred->cr_gid); | |
749 | sp->sa_size = txdr_unsigned(0); | |
a2907882 | 750 | /* or should these be VNOVAL ?? */ |
9238aa59 RM |
751 | txdr_time(&vap->va_atime, &sp->sa_atime); |
752 | txdr_time(&vap->va_mtime, &sp->sa_mtime); | |
f5f6c13e | 753 | nfsm_request(ndp->ni_dvp, nonidempotent[NFSPROC_CREATE]); |
a2907882 KM |
754 | nfsm_mtofh(ndp->ni_dvp, ndp->ni_vp); |
755 | nfsm_reqdone; | |
e49b1a6c | 756 | VTONFS(ndp->ni_dvp)->n_direofstamp = 0; |
a2907882 KM |
757 | nfs_nput(ndp->ni_dvp); |
758 | return (error); | |
759 | } | |
760 | ||
761 | /* | |
762 | * nfs file remove call | |
ffe6f482 KM |
763 | * To try and make nfs semantics closer to vfs semantics, a file that has |
764 | * other references to the vnode is renamed instead of removed and then | |
765 | * removed later on the last close. | |
766 | * Unfortunately you must flush the buffer cache and cmap to get rid of | |
767 | * all extraneous vnode references before you check the reference cnt. | |
768 | * 1 - If the file could have blocks in the buffer cache | |
769 | * flush them out and invalidate them | |
770 | * mpurge the vnode to flush out cmap references | |
771 | * (This is necessary to update the vnode ref cnt as well as sensible | |
772 | * for actual removes, to free up the buffers) | |
1f7e9641 | 773 | * 2 - If v_usecount > 1 |
ffe6f482 KM |
774 | * If a rename is not already in the works |
775 | * call nfs_sillyrename() to set it up | |
776 | * else | |
777 | * do the remove rpc | |
a2907882 KM |
778 | */ |
779 | nfs_remove(ndp) | |
780 | register struct nameidata *ndp; | |
781 | { | |
ffe6f482 KM |
782 | register struct vnode *vp = ndp->ni_vp; |
783 | register struct nfsnode *np = VTONFS(ndp->ni_vp); | |
13576453 KM |
784 | register u_long *p; |
785 | register caddr_t cp; | |
786 | register long t1, t2; | |
787 | caddr_t bpos, dpos; | |
788 | u_long xid; | |
789 | int error = 0; | |
790 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 | 791 | |
ffe6f482 KM |
792 | if (vp->v_type == VREG) { |
793 | if (np->n_flag & (NMODIFIED|NBUFFERED)) { | |
794 | np->n_flag &= ~(NMODIFIED|NBUFFERED); | |
fe53c871 | 795 | vinvalbuf(vp, TRUE); |
ffe6f482 | 796 | } |
e8540f59 KM |
797 | if (np->n_flag & NPAGEDON) { |
798 | np->n_flag &= ~NPAGEDON; | |
ffe6f482 | 799 | mpurge(vp); /* In case cmap entries still ref it */ |
e8540f59 | 800 | } |
ffe6f482 | 801 | } |
1f7e9641 | 802 | if (vp->v_usecount > 1) { |
ffe6f482 KM |
803 | if (!np->n_sillyrename) |
804 | error = nfs_sillyrename(ndp, REMOVE); | |
805 | } else { | |
a2907882 KM |
806 | nfsstats.rpccnt[NFSPROC_REMOVE]++; |
807 | nfsm_reqhead(nfs_procids[NFSPROC_REMOVE], ndp->ni_cred, | |
808 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(ndp->ni_dent.d_namlen)); | |
809 | nfsm_fhtom(ndp->ni_dvp); | |
810 | nfsm_strtom(ndp->ni_dent.d_name, ndp->ni_dent.d_namlen, NFS_MAXNAMLEN); | |
f5f6c13e | 811 | nfsm_request(ndp->ni_dvp, nonidempotent[NFSPROC_REMOVE]); |
a2907882 | 812 | nfsm_reqdone; |
e49b1a6c | 813 | VTONFS(ndp->ni_dvp)->n_direofstamp = 0; |
e8540f59 KM |
814 | /* |
815 | * Kludge City: If the first reply to the remove rpc is lost.. | |
816 | * the reply to the retransmitted request will be ENOENT | |
817 | * since the file was in fact removed | |
818 | * Therefore, we cheat and return success. | |
819 | */ | |
820 | if (error == ENOENT) | |
821 | error = 0; | |
a2907882 | 822 | } |
86dea069 | 823 | np->n_attrstamp = 0; |
f5f6c13e KM |
824 | if (ndp->ni_dvp == vp) |
825 | vrele(vp); | |
a2907882 | 826 | else |
f5f6c13e KM |
827 | nfs_nput(ndp->ni_dvp); |
828 | nfs_nput(vp); | |
a2907882 KM |
829 | return (error); |
830 | } | |
831 | ||
832 | /* | |
833 | * nfs file remove rpc called from nfs_inactive | |
834 | */ | |
835 | nfs_removeit(ndp) | |
836 | register struct nameidata *ndp; | |
837 | { | |
13576453 KM |
838 | register u_long *p; |
839 | register caddr_t cp; | |
840 | register long t1, t2; | |
841 | caddr_t bpos, dpos; | |
842 | u_long xid; | |
843 | int error = 0; | |
844 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
845 | |
846 | nfsstats.rpccnt[NFSPROC_REMOVE]++; | |
847 | nfsm_reqhead(nfs_procids[NFSPROC_REMOVE], ndp->ni_cred, | |
848 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(ndp->ni_dent.d_namlen)); | |
849 | nfsm_fhtom(ndp->ni_dvp); | |
850 | nfsm_strtom(ndp->ni_dent.d_name, ndp->ni_dent.d_namlen, NFS_MAXNAMLEN); | |
f5f6c13e | 851 | nfsm_request(ndp->ni_dvp, nonidempotent[NFSPROC_REMOVE]); |
a2907882 | 852 | nfsm_reqdone; |
e49b1a6c | 853 | VTONFS(ndp->ni_dvp)->n_direofstamp = 0; |
a2907882 KM |
854 | return (error); |
855 | } | |
856 | ||
857 | /* | |
858 | * nfs file rename call | |
859 | */ | |
860 | nfs_rename(sndp, tndp) | |
861 | register struct nameidata *sndp, *tndp; | |
862 | { | |
13576453 KM |
863 | register u_long *p; |
864 | register caddr_t cp; | |
865 | register long t1, t2; | |
866 | caddr_t bpos, dpos; | |
867 | u_long xid; | |
868 | int error = 0; | |
869 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
870 | |
871 | nfsstats.rpccnt[NFSPROC_RENAME]++; | |
872 | nfsm_reqhead(nfs_procids[NFSPROC_RENAME], tndp->ni_cred, | |
873 | (NFSX_FH+NFSX_UNSIGNED)*2+nfsm_rndup(sndp->ni_dent.d_namlen)+ | |
874 | nfsm_rndup(tndp->ni_dent.d_namlen)); /* or sndp->ni_cred?*/ | |
875 | nfsm_fhtom(sndp->ni_dvp); | |
876 | nfsm_strtom(sndp->ni_dent.d_name,sndp->ni_dent.d_namlen,NFS_MAXNAMLEN); | |
877 | nfsm_fhtom(tndp->ni_dvp); | |
878 | nfsm_strtom(tndp->ni_dent.d_name,tndp->ni_dent.d_namlen,NFS_MAXNAMLEN); | |
f5f6c13e | 879 | nfsm_request(sndp->ni_dvp, nonidempotent[NFSPROC_RENAME]); |
a2907882 | 880 | nfsm_reqdone; |
e49b1a6c KM |
881 | VTONFS(sndp->ni_dvp)->n_direofstamp = 0; |
882 | VTONFS(tndp->ni_dvp)->n_direofstamp = 0; | |
a2907882 KM |
883 | if (sndp->ni_vp->v_type == VDIR) { |
884 | if (tndp->ni_vp != NULL && tndp->ni_vp->v_type == VDIR) | |
885 | cache_purge(tndp->ni_dvp); | |
886 | cache_purge(sndp->ni_dvp); | |
887 | } | |
a2907882 KM |
888 | nfs_abortop(sndp); |
889 | nfs_abortop(tndp); | |
f5f6c13e KM |
890 | /* |
891 | * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry. | |
892 | */ | |
893 | if (error == ENOENT) | |
894 | error = 0; | |
a2907882 KM |
895 | return (error); |
896 | } | |
897 | ||
898 | /* | |
899 | * nfs file rename rpc called from above | |
900 | */ | |
901 | nfs_renameit(sndp, tndp) | |
902 | register struct nameidata *sndp, *tndp; | |
903 | { | |
13576453 KM |
904 | register u_long *p; |
905 | register caddr_t cp; | |
906 | register long t1, t2; | |
907 | caddr_t bpos, dpos; | |
908 | u_long xid; | |
909 | int error = 0; | |
910 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
911 | |
912 | nfsstats.rpccnt[NFSPROC_RENAME]++; | |
913 | nfsm_reqhead(nfs_procids[NFSPROC_RENAME], tndp->ni_cred, | |
914 | (NFSX_FH+NFSX_UNSIGNED)*2+nfsm_rndup(sndp->ni_dent.d_namlen)+ | |
915 | nfsm_rndup(tndp->ni_dent.d_namlen)); /* or sndp->ni_cred?*/ | |
916 | nfsm_fhtom(sndp->ni_dvp); | |
917 | nfsm_strtom(sndp->ni_dent.d_name,sndp->ni_dent.d_namlen,NFS_MAXNAMLEN); | |
918 | nfsm_fhtom(tndp->ni_dvp); | |
919 | nfsm_strtom(tndp->ni_dent.d_name,tndp->ni_dent.d_namlen,NFS_MAXNAMLEN); | |
f5f6c13e | 920 | nfsm_request(sndp->ni_dvp, nonidempotent[NFSPROC_RENAME]); |
a2907882 | 921 | nfsm_reqdone; |
e49b1a6c KM |
922 | VTONFS(sndp->ni_dvp)->n_direofstamp = 0; |
923 | VTONFS(tndp->ni_dvp)->n_direofstamp = 0; | |
a2907882 KM |
924 | return (error); |
925 | } | |
926 | ||
927 | /* | |
928 | * nfs hard link create call | |
929 | */ | |
930 | nfs_link(vp, ndp) | |
13576453 | 931 | register struct vnode *vp; |
a2907882 KM |
932 | register struct nameidata *ndp; |
933 | { | |
13576453 KM |
934 | register u_long *p; |
935 | register caddr_t cp; | |
936 | register long t1, t2; | |
937 | caddr_t bpos, dpos; | |
938 | u_long xid; | |
939 | int error = 0; | |
940 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 | 941 | |
36c3043b KM |
942 | if (ndp->ni_dvp != vp) |
943 | nfs_lock(vp); | |
a2907882 KM |
944 | nfsstats.rpccnt[NFSPROC_LINK]++; |
945 | nfsm_reqhead(nfs_procids[NFSPROC_LINK], ndp->ni_cred, | |
946 | NFSX_FH*2+NFSX_UNSIGNED+nfsm_rndup(ndp->ni_dent.d_namlen)); | |
947 | nfsm_fhtom(vp); | |
948 | nfsm_fhtom(ndp->ni_dvp); | |
949 | nfsm_strtom(ndp->ni_dent.d_name, ndp->ni_dent.d_namlen, NFS_MAXNAMLEN); | |
f5f6c13e | 950 | nfsm_request(vp, nonidempotent[NFSPROC_LINK]); |
a2907882 | 951 | nfsm_reqdone; |
86dea069 | 952 | VTONFS(vp)->n_attrstamp = 0; |
e49b1a6c | 953 | VTONFS(ndp->ni_dvp)->n_direofstamp = 0; |
36c3043b KM |
954 | if (ndp->ni_dvp != vp) |
955 | nfs_unlock(vp); | |
a2907882 | 956 | nfs_nput(ndp->ni_dvp); |
f5f6c13e KM |
957 | /* |
958 | * Kludge: Map EEXIST => 0 assuming that it is a reply to a retry. | |
959 | */ | |
960 | if (error == EEXIST) | |
961 | error = 0; | |
a2907882 KM |
962 | return (error); |
963 | } | |
964 | ||
965 | /* | |
966 | * nfs symbolic link create call | |
967 | */ | |
968 | nfs_symlink(ndp, vap, nm) | |
969 | struct nameidata *ndp; | |
970 | struct vattr *vap; | |
971 | char *nm; /* is this the path ?? */ | |
972 | { | |
9238aa59 | 973 | register struct nfsv2_sattr *sp; |
13576453 KM |
974 | register u_long *p; |
975 | register caddr_t cp; | |
976 | register long t1, t2; | |
977 | caddr_t bpos, dpos; | |
978 | u_long xid; | |
979 | int error = 0; | |
980 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
981 | |
982 | nfsstats.rpccnt[NFSPROC_SYMLINK]++; | |
983 | nfsm_reqhead(nfs_procids[NFSPROC_SYMLINK], ndp->ni_cred, | |
984 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(ndp->ni_dent.d_namlen)+NFSX_UNSIGNED); | |
985 | nfsm_fhtom(ndp->ni_dvp); | |
986 | nfsm_strtom(ndp->ni_dent.d_name, ndp->ni_dent.d_namlen, NFS_MAXNAMLEN); | |
987 | nfsm_strtom(nm, strlen(nm), NFS_MAXPATHLEN); | |
9238aa59 RM |
988 | nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR); |
989 | sp->sa_mode = vtonfs_mode(VLNK, vap->va_mode); | |
990 | sp->sa_uid = txdr_unsigned(ndp->ni_cred->cr_uid); | |
991 | sp->sa_gid = txdr_unsigned(ndp->ni_cred->cr_gid); | |
992 | sp->sa_size = txdr_unsigned(VNOVAL); | |
f5f6c13e | 993 | txdr_time(&vap->va_atime, &sp->sa_atime); /* or VNOVAL ?? */ |
9238aa59 | 994 | txdr_time(&vap->va_mtime, &sp->sa_mtime); /* or VNOVAL ?? */ |
f5f6c13e | 995 | nfsm_request(ndp->ni_dvp, nonidempotent[NFSPROC_SYMLINK]); |
a2907882 | 996 | nfsm_reqdone; |
e49b1a6c | 997 | VTONFS(ndp->ni_dvp)->n_direofstamp = 0; |
a2907882 | 998 | nfs_nput(ndp->ni_dvp); |
f5f6c13e KM |
999 | /* |
1000 | * Kludge: Map EEXIST => 0 assuming that it is a reply to a retry. | |
1001 | */ | |
1002 | if (error == EEXIST) | |
1003 | error = 0; | |
a2907882 KM |
1004 | return (error); |
1005 | } | |
1006 | ||
1007 | /* | |
1008 | * nfs make dir call | |
1009 | */ | |
1010 | nfs_mkdir(ndp, vap) | |
13576453 | 1011 | register struct nameidata *ndp; |
a2907882 KM |
1012 | struct vattr *vap; |
1013 | { | |
9238aa59 | 1014 | register struct nfsv2_sattr *sp; |
13576453 KM |
1015 | register u_long *p; |
1016 | register caddr_t cp; | |
1017 | register long t1, t2; | |
1018 | caddr_t bpos, dpos, cp2; | |
1019 | u_long xid; | |
1020 | int error = 0; | |
1021 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
1022 | |
1023 | nfsstats.rpccnt[NFSPROC_MKDIR]++; | |
1024 | nfsm_reqhead(nfs_procids[NFSPROC_MKDIR], ndp->ni_cred, | |
1025 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(ndp->ni_dent.d_namlen)+NFSX_SATTR); | |
1026 | nfsm_fhtom(ndp->ni_dvp); | |
1027 | nfsm_strtom(ndp->ni_dent.d_name, ndp->ni_dent.d_namlen, NFS_MAXNAMLEN); | |
9238aa59 RM |
1028 | nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR); |
1029 | sp->sa_mode = vtonfs_mode(VDIR, vap->va_mode); | |
1030 | sp->sa_uid = txdr_unsigned(ndp->ni_cred->cr_uid); | |
1031 | sp->sa_gid = txdr_unsigned(ndp->ni_cred->cr_gid); | |
1032 | sp->sa_size = txdr_unsigned(VNOVAL); | |
f5f6c13e | 1033 | txdr_time(&vap->va_atime, &sp->sa_atime); /* or VNOVAL ?? */ |
9238aa59 | 1034 | txdr_time(&vap->va_mtime, &sp->sa_mtime); /* or VNOVAL ?? */ |
f5f6c13e | 1035 | nfsm_request(ndp->ni_dvp, nonidempotent[NFSPROC_MKDIR]); |
a2907882 KM |
1036 | nfsm_mtofh(ndp->ni_dvp, ndp->ni_vp); |
1037 | nfsm_reqdone; | |
e49b1a6c | 1038 | VTONFS(ndp->ni_dvp)->n_direofstamp = 0; |
a2907882 | 1039 | nfs_nput(ndp->ni_dvp); |
f5f6c13e KM |
1040 | /* |
1041 | * Kludge: Map EEXIST => 0 assuming that you have a reply to a retry. | |
1042 | */ | |
1043 | if (error == EEXIST) | |
1044 | error = 0; | |
a2907882 KM |
1045 | return (error); |
1046 | } | |
1047 | ||
1048 | /* | |
1049 | * nfs remove directory call | |
1050 | */ | |
1051 | nfs_rmdir(ndp) | |
1052 | register struct nameidata *ndp; | |
1053 | { | |
13576453 KM |
1054 | register u_long *p; |
1055 | register caddr_t cp; | |
1056 | register long t1, t2; | |
1057 | caddr_t bpos, dpos; | |
1058 | u_long xid; | |
1059 | int error = 0; | |
1060 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
1061 | |
1062 | if (ndp->ni_dvp == ndp->ni_vp) { | |
1063 | vrele(ndp->ni_dvp); | |
1064 | nfs_nput(ndp->ni_dvp); | |
1065 | return (EINVAL); | |
1066 | } | |
a2907882 KM |
1067 | nfsstats.rpccnt[NFSPROC_RMDIR]++; |
1068 | nfsm_reqhead(nfs_procids[NFSPROC_RMDIR], ndp->ni_cred, | |
1069 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(ndp->ni_dent.d_namlen)); | |
1070 | nfsm_fhtom(ndp->ni_dvp); | |
1071 | nfsm_strtom(ndp->ni_dent.d_name, ndp->ni_dent.d_namlen, NFS_MAXNAMLEN); | |
f5f6c13e | 1072 | nfsm_request(ndp->ni_dvp, nonidempotent[NFSPROC_RMDIR]); |
a2907882 | 1073 | nfsm_reqdone; |
e49b1a6c | 1074 | VTONFS(ndp->ni_dvp)->n_direofstamp = 0; |
9238aa59 RM |
1075 | cache_purge(ndp->ni_dvp); |
1076 | cache_purge(ndp->ni_vp); | |
9238aa59 RM |
1077 | nfs_nput(ndp->ni_vp); |
1078 | nfs_nput(ndp->ni_dvp); | |
f5f6c13e KM |
1079 | /* |
1080 | * Kludge: Map ENOENT => 0 assuming that you have a reply to a retry. | |
1081 | */ | |
1082 | if (error == ENOENT) | |
1083 | error = 0; | |
a2907882 KM |
1084 | return (error); |
1085 | } | |
1086 | ||
1087 | /* | |
1088 | * nfs readdir call | |
1089 | * Although cookie is defined as opaque, I translate it to/from net byte | |
1090 | * order so that it looks more sensible. This appears consistent with the | |
1091 | * Ultrix implementation of NFS. | |
1092 | */ | |
e49b1a6c | 1093 | nfs_readdir(vp, uiop, cred, eofflagp) |
13576453 | 1094 | register struct vnode *vp; |
a2907882 | 1095 | struct uio *uiop; |
a2907882 | 1096 | struct ucred *cred; |
e49b1a6c | 1097 | int *eofflagp; |
a2907882 KM |
1098 | { |
1099 | register long len; | |
1100 | register struct direct *dp; | |
13576453 KM |
1101 | register u_long *p; |
1102 | register caddr_t cp; | |
1103 | register long t1; | |
1389ccec | 1104 | long tlen; |
13576453 KM |
1105 | caddr_t bpos, dpos, cp2; |
1106 | u_long xid; | |
1107 | int error = 0; | |
1108 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
1109 | struct mbuf *md2; |
1110 | caddr_t dpos2; | |
1111 | int siz; | |
e49b1a6c | 1112 | int more_dirs = 1; |
a2907882 KM |
1113 | off_t off, savoff; |
1114 | struct direct *savdp; | |
e49b1a6c KM |
1115 | struct nfsmount *nmp; |
1116 | struct nfsnode *np = VTONFS(vp); | |
1117 | long tresid; | |
a2907882 | 1118 | |
a2907882 | 1119 | /* |
e49b1a6c | 1120 | * First, check for hit on the EOF offset cache |
a2907882 | 1121 | */ |
e49b1a6c KM |
1122 | if (uiop->uio_offset != 0 && uiop->uio_offset == np->n_direofoffset && |
1123 | (time.tv_sec - np->n_direofstamp) < NFS_ATTRTIMEO) { | |
1124 | *eofflagp = 1; | |
1125 | nfsstats.direofcache_hits++; | |
1126 | return (0); | |
1127 | } | |
1128 | ||
1129 | nmp = vfs_to_nfs(vp->v_mount); | |
1130 | tresid = uiop->uio_resid; | |
a2907882 | 1131 | /* |
e49b1a6c KM |
1132 | * Loop around doing readdir rpc's of size uio_resid or nm_rsize, |
1133 | * whichever is smaller, truncated to a multiple of DIRBLKSIZ. | |
1134 | * The stopping criteria is EOF or less than DIRBLKSIZ of the | |
1135 | * request left. | |
a2907882 | 1136 | */ |
e49b1a6c KM |
1137 | while (more_dirs && uiop->uio_resid >= DIRBLKSIZ) { |
1138 | nfsstats.rpccnt[NFSPROC_READDIR]++; | |
1139 | nfsm_reqhead(nfs_procids[NFSPROC_READDIR], cred, xid); | |
1140 | nfsm_fhtom(vp); | |
1141 | nfsm_build(p, u_long *, 2*NFSX_UNSIGNED); | |
1142 | *p++ = txdr_unsigned(uiop->uio_offset); | |
1143 | *p = txdr_unsigned(((uiop->uio_resid > nmp->nm_rsize) ? | |
1144 | nmp->nm_rsize : uiop->uio_resid) & ~(DIRBLKSIZ-1)); | |
1145 | nfsm_request(vp, nonidempotent[NFSPROC_READDIR]); | |
1146 | siz = 0; | |
1147 | nfsm_disect(p, u_long *, NFSX_UNSIGNED); | |
1148 | more_dirs = fxdr_unsigned(int, *p); | |
1149 | ||
1150 | /* Save the position so that we can do nfsm_mtouio() later */ | |
1151 | dpos2 = dpos; | |
1152 | md2 = md; | |
1153 | ||
1154 | /* loop thru the dir entries, doctoring them to 4bsd form */ | |
1155 | savoff = off = 0; | |
1156 | savdp = dp = NULL; | |
1157 | while (more_dirs && siz < uiop->uio_resid) { | |
1158 | savoff = off; /* Hold onto offset and dp */ | |
1159 | savdp = dp; | |
1160 | nfsm_disecton(p, u_long *, 2*NFSX_UNSIGNED); | |
1161 | dp = (struct direct *)p; | |
1162 | dp->d_ino = fxdr_unsigned(u_long, *p++); | |
1163 | len = fxdr_unsigned(int, *p); | |
1164 | if (len <= 0 || len > NFS_MAXNAMLEN) { | |
1165 | error = EBADRPC; | |
1166 | m_freem(mrep); | |
1167 | goto nfsmout; | |
1168 | } | |
1169 | dp->d_namlen = (u_short)len; | |
1170 | nfsm_adv(len); /* Point past name */ | |
1171 | tlen = nfsm_rndup(len); | |
1172 | /* | |
1173 | * This should not be necessary, but some servers have | |
1174 | * broken XDR such that these bytes are not null filled. | |
1175 | */ | |
1176 | if (tlen != len) { | |
1177 | *dpos = '\0'; /* Null-terminate */ | |
1178 | nfsm_adv(tlen - len); | |
1179 | len = tlen; | |
1180 | } | |
1181 | nfsm_disecton(p, u_long *, 2*NFSX_UNSIGNED); | |
1182 | off = fxdr_unsigned(off_t, *p); | |
1183 | *p++ = 0; /* Ensures null termination of name */ | |
1184 | more_dirs = fxdr_unsigned(int, *p); | |
1185 | dp->d_reclen = len+4*NFSX_UNSIGNED; | |
1186 | siz += dp->d_reclen; | |
1187 | } | |
1188 | /* | |
1189 | * If at end of rpc data, get the eof boolean | |
1190 | */ | |
1191 | if (!more_dirs) { | |
1192 | nfsm_disecton(p, u_long *, NFSX_UNSIGNED); | |
1193 | more_dirs = (fxdr_unsigned(int, *p) == 0); | |
1194 | ||
1195 | /* | |
1196 | * If at EOF, cache directory offset | |
1197 | */ | |
1198 | if (!more_dirs) { | |
1199 | np->n_direofoffset = off; | |
1200 | np->n_direofstamp = time.tv_sec; | |
1201 | } | |
1202 | } | |
1203 | /* | |
1204 | * If there is too much to fit in the data buffer, use savoff and | |
1205 | * savdp to trim off the last record. | |
1206 | * --> we are not at eof | |
1207 | */ | |
1208 | if (siz > uiop->uio_resid) { | |
1209 | off = savoff; | |
1210 | siz -= dp->d_reclen; | |
1211 | dp = savdp; | |
1212 | more_dirs = 0; /* Paranoia */ | |
1213 | } | |
1214 | if (siz > 0) { | |
1215 | md = md2; | |
1216 | dpos = dpos2; | |
1217 | nfsm_mtouio(uiop, siz); | |
1218 | uiop->uio_offset = off; | |
1219 | } else | |
1220 | more_dirs = 0; /* Ugh, never happens, but in case.. */ | |
1221 | m_freem(mrep); | |
a2907882 | 1222 | } |
e49b1a6c KM |
1223 | nfsmout: |
1224 | if (tresid == uiop->uio_resid) { | |
1225 | *eofflagp = 1; | |
1226 | nfsstats.direofcache_misses++; | |
1227 | } else { | |
1228 | *eofflagp = 0; | |
a2907882 | 1229 | } |
a2907882 KM |
1230 | return (error); |
1231 | } | |
1232 | ||
1233 | /* | |
1234 | * nfs statfs call | |
1235 | * (Actually a vfsop, not a vnode op) | |
1236 | */ | |
1237 | nfs_statfs(mp, sbp) | |
1238 | struct mount *mp; | |
1239 | register struct statfs *sbp; | |
1240 | { | |
13576453 | 1241 | register struct vnode *vp; |
9238aa59 | 1242 | register struct nfsv2_statfs *sfp; |
13576453 KM |
1243 | register caddr_t cp; |
1244 | register long t1; | |
1245 | caddr_t bpos, dpos, cp2; | |
1246 | u_long xid; | |
1247 | int error = 0; | |
1248 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
9238aa59 | 1249 | struct nfsmount *nmp; |
a2907882 KM |
1250 | struct ucred *cred; |
1251 | struct nfsnode *np; | |
a2907882 KM |
1252 | |
1253 | nmp = vfs_to_nfs(mp); | |
1254 | if (error = nfs_nget(mp, &nmp->nm_fh, &np)) | |
1255 | return (error); | |
1256 | vp = NFSTOV(np); | |
1257 | nfsstats.rpccnt[NFSPROC_STATFS]++; | |
1258 | cred = crget(); | |
1259 | cred->cr_ngroups = 1; | |
1260 | nfsm_reqhead(nfs_procids[NFSPROC_STATFS], cred, NFSX_FH); | |
1261 | nfsm_fhtom(vp); | |
f5f6c13e | 1262 | nfsm_request(vp, nonidempotent[NFSPROC_STATFS]); |
9238aa59 | 1263 | nfsm_disect(sfp, struct nfsv2_statfs *, NFSX_STATFS); |
a2907882 | 1264 | sbp->f_type = MOUNT_NFS; |
e8540f59 | 1265 | sbp->f_flags = nmp->nm_flag; |
9238aa59 RM |
1266 | sbp->f_bsize = fxdr_unsigned(long, sfp->sf_tsize); |
1267 | sbp->f_fsize = fxdr_unsigned(long, sfp->sf_bsize); | |
1268 | sbp->f_blocks = fxdr_unsigned(long, sfp->sf_blocks); | |
1269 | sbp->f_bfree = fxdr_unsigned(long, sfp->sf_bfree); | |
1270 | sbp->f_bavail = fxdr_unsigned(long, sfp->sf_bavail); | |
0b9c4686 KM |
1271 | sbp->f_files = 0; |
1272 | sbp->f_ffree = 0; | |
e8540f59 KM |
1273 | sbp->f_fsid.val[0] = mp->m_fsid.val[0]; |
1274 | sbp->f_fsid.val[1] = mp->m_fsid.val[1]; | |
a2907882 KM |
1275 | bcopy(nmp->nm_path, sbp->f_mntonname, MNAMELEN); |
1276 | bcopy(nmp->nm_host, sbp->f_mntfromname, MNAMELEN); | |
1277 | nfsm_reqdone; | |
1278 | nfs_nput(vp); | |
1279 | crfree(cred); | |
1280 | return (error); | |
1281 | } | |
1282 | ||
13576453 | 1283 | static char hextoasc[] = "0123456789abcdef"; |
a2907882 KM |
1284 | |
1285 | /* | |
1286 | * Silly rename. To make the NFS filesystem that is stateless look a little | |
1287 | * more like the "ufs" a remove of an active vnode is translated to a rename | |
1288 | * to a funny looking filename that is removed by nfs_inactive on the | |
1289 | * nfsnode. There is the potential for another process on a different client | |
1290 | * to create the same funny name between the nfs_lookitup() fails and the | |
1291 | * nfs_rename() completes, but... | |
1292 | */ | |
1293 | nfs_sillyrename(ndp, flag) | |
13576453 | 1294 | register struct nameidata *ndp; |
a2907882 KM |
1295 | int flag; |
1296 | { | |
1297 | register struct nfsnode *np; | |
1298 | register struct sillyrename *sp; | |
1299 | register struct nameidata *tndp; | |
1300 | int error; | |
1301 | short pid; | |
1302 | ||
1303 | np = VTONFS(ndp->ni_dvp); | |
ffe6f482 | 1304 | cache_purge(ndp->ni_dvp); |
a2907882 | 1305 | MALLOC(sp, struct sillyrename *, sizeof (struct sillyrename), |
9238aa59 | 1306 | M_TEMP, M_WAITOK); |
a2907882 KM |
1307 | sp->s_flag = flag; |
1308 | bcopy((caddr_t)&np->n_fh, (caddr_t)&sp->s_fh, NFSX_FH); | |
1309 | np = VTONFS(ndp->ni_vp); | |
1310 | tndp = &sp->s_namei; | |
1311 | tndp->ni_cred = crdup(ndp->ni_cred); | |
1312 | ||
1313 | /* Fudge together a funny name */ | |
1314 | pid = u.u_procp->p_pid; | |
1315 | bcopy(".nfsAxxxx4.4", tndp->ni_dent.d_name, 13); | |
1316 | tndp->ni_dent.d_namlen = 12; | |
13576453 KM |
1317 | tndp->ni_dent.d_name[8] = hextoasc[pid & 0xf]; |
1318 | tndp->ni_dent.d_name[7] = hextoasc[(pid >> 4) & 0xf]; | |
1319 | tndp->ni_dent.d_name[6] = hextoasc[(pid >> 8) & 0xf]; | |
1320 | tndp->ni_dent.d_name[5] = hextoasc[(pid >> 12) & 0xf]; | |
a2907882 KM |
1321 | |
1322 | /* Try lookitups until we get one that isn't there */ | |
1323 | while (nfs_lookitup(ndp->ni_dvp, tndp, (nfsv2fh_t *)0) == 0) { | |
1324 | tndp->ni_dent.d_name[4]++; | |
1325 | if (tndp->ni_dent.d_name[4] > 'z') { | |
1326 | error = EINVAL; | |
1327 | goto bad; | |
1328 | } | |
1329 | } | |
1330 | if (error = nfs_renameit(ndp, tndp)) | |
1331 | goto bad; | |
1332 | nfs_lookitup(ndp->ni_dvp, tndp, &np->n_fh); | |
1333 | np->n_sillyrename = sp; | |
1334 | return (0); | |
1335 | bad: | |
9238aa59 | 1336 | crfree(tndp->ni_cred); |
a2907882 KM |
1337 | free((caddr_t)sp, M_TEMP); |
1338 | return (error); | |
1339 | } | |
1340 | ||
1341 | /* | |
1342 | * Look up a file name for silly rename stuff. | |
1343 | * Just like nfs_lookup() except that it doesn't load returned values | |
1344 | * into the nfsnode table. | |
1345 | * If fhp != NULL it copies the returned file handle out | |
1346 | */ | |
1347 | nfs_lookitup(vp, ndp, fhp) | |
1348 | register struct vnode *vp; | |
1349 | register struct nameidata *ndp; | |
1350 | nfsv2fh_t *fhp; | |
1351 | { | |
13576453 KM |
1352 | register u_long *p; |
1353 | register caddr_t cp; | |
1354 | register long t1, t2; | |
1355 | caddr_t bpos, dpos, cp2; | |
1356 | u_long xid; | |
1357 | int error = 0; | |
1358 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
1359 | long len; |
1360 | ||
1361 | nfsstats.rpccnt[NFSPROC_LOOKUP]++; | |
1362 | ndp->ni_dvp = vp; | |
1363 | ndp->ni_vp = NULL; | |
1364 | len = ndp->ni_dent.d_namlen; | |
1365 | nfsm_reqhead(nfs_procids[NFSPROC_LOOKUP], ndp->ni_cred, NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len)); | |
1366 | nfsm_fhtom(vp); | |
1367 | nfsm_strtom(ndp->ni_dent.d_name, len, NFS_MAXNAMLEN); | |
f5f6c13e | 1368 | nfsm_request(vp, nonidempotent[NFSPROC_LOOKUP]); |
a2907882 KM |
1369 | if (fhp != NULL) { |
1370 | nfsm_disect(cp, caddr_t, NFSX_FH); | |
1371 | bcopy(cp, (caddr_t)fhp, NFSX_FH); | |
1372 | } | |
1373 | nfsm_reqdone; | |
1374 | return (error); | |
1375 | } | |
1376 | ||
1377 | /* | |
1378 | * Kludge City.. | |
1379 | * - make nfs_bmap() essentially a no-op that does no translation | |
1380 | * - do nfs_strategy() by faking physical I/O with nfs_readit/nfs_writeit | |
1381 | * after mapping the physical addresses into Kernel Virtual space in the | |
1382 | * nfsiobuf area. | |
1383 | * (Maybe I could use the process's page mapping, but I was concerned that | |
1384 | * Kernel Write might not be enabled and also figured copyout() would do | |
1385 | * a lot more work than bcopy() and also it currently happens in the | |
1386 | * context of the swapper process (2). | |
1387 | */ | |
1388 | nfs_bmap(vp, bn, vpp, bnp) | |
1389 | struct vnode *vp; | |
1390 | daddr_t bn; | |
1391 | struct vnode **vpp; | |
1392 | daddr_t *bnp; | |
1393 | { | |
1394 | if (vpp != NULL) | |
1395 | *vpp = vp; | |
1396 | if (bnp != NULL) | |
1397 | *bnp = bn * btodb(vp->v_mount->m_bsize); | |
1398 | return (0); | |
1399 | } | |
1400 | ||
1401 | /* | |
9238aa59 RM |
1402 | * Strategy routine for phys. i/o |
1403 | * If the biod's are running, queue a request | |
1404 | * otherwise just call nfs_doio() to get it done | |
a2907882 KM |
1405 | */ |
1406 | nfs_strategy(bp) | |
1407 | register struct buf *bp; | |
9238aa59 RM |
1408 | { |
1409 | register struct buf *dp; | |
ffe6f482 | 1410 | register int i; |
9238aa59 RM |
1411 | struct proc *rp; |
1412 | int error = 0; | |
ffe6f482 | 1413 | int fnd = 0; |
9238aa59 RM |
1414 | |
1415 | /* | |
1416 | * If an i/o daemon is waiting | |
1417 | * queue the request, wake it up and wait for completion | |
1418 | * otherwise just do it ourselves | |
1419 | */ | |
ffe6f482 KM |
1420 | for (i = 0; i < nfs_asyncdaemons; i++) { |
1421 | if (rp = nfs_iodwant[i]) { | |
1422 | /* | |
1423 | * Ensure that the async_daemon is still waiting here | |
1424 | */ | |
1425 | if (rp->p_stat != SSLEEP || | |
1426 | rp->p_wchan != ((caddr_t)&nfs_iodwant[i])) { | |
1427 | nfs_iodwant[i] = (struct proc *)0; | |
1428 | continue; | |
1429 | } | |
1430 | dp = &nfs_bqueue; | |
1431 | if (dp->b_actf == NULL) { | |
1432 | dp->b_actl = bp; | |
1433 | bp->b_actf = dp; | |
1434 | } else { | |
1435 | dp->b_actf->b_actl = bp; | |
1436 | bp->b_actf = dp->b_actf; | |
1437 | } | |
1438 | dp->b_actf = bp; | |
1439 | bp->b_actl = dp; | |
1440 | fnd++; | |
1441 | nfs_iodwant[i] = (struct proc *)0; | |
1442 | wakeup((caddr_t)&nfs_iodwant[i]); | |
1443 | break; | |
9238aa59 | 1444 | } |
ffe6f482 KM |
1445 | } |
1446 | if (!fnd) | |
9238aa59 RM |
1447 | error = nfs_doio(bp); |
1448 | return (error); | |
1449 | } | |
1450 | ||
1451 | /* | |
1452 | * Fun and games with i/o | |
1453 | * Essentially play ubasetup() and disk interrupt service routine by | |
1454 | * mapping the data buffer into kernel virtual space and doing the | |
1455 | * nfs read or write rpc's from it. | |
1456 | * If the biod's are not running, this is just called from nfs_strategy(), | |
1457 | * otherwise it is called by the biod's to do what would normally be | |
1458 | * partially disk interrupt driven. | |
1459 | */ | |
1460 | nfs_doio(bp) | |
1461 | register struct buf *bp; | |
a2907882 KM |
1462 | { |
1463 | register struct pte *pte, *ppte; | |
1464 | register caddr_t vaddr; | |
1465 | register struct uio *uiop; | |
a2907882 | 1466 | register struct vnode *vp; |
ffe6f482 | 1467 | struct nfsnode *np; |
9238aa59 RM |
1468 | struct ucred *cr; |
1469 | int npf, npf2; | |
1470 | int reg; | |
1471 | caddr_t vbase; | |
a2907882 KM |
1472 | unsigned v; |
1473 | struct proc *rp; | |
1474 | int o, error; | |
a2907882 KM |
1475 | struct uio uio; |
1476 | struct iovec io; | |
1477 | ||
1478 | vp = bp->b_vp; | |
8c379a26 | 1479 | np = VTONFS(vp); |
a2907882 KM |
1480 | uiop = &uio; |
1481 | uiop->uio_iov = &io; | |
1482 | uiop->uio_iovcnt = 1; | |
a2907882 | 1483 | uiop->uio_segflg = UIO_SYSSPACE; |
e8540f59 | 1484 | |
a2907882 | 1485 | /* |
9238aa59 RM |
1486 | * For phys i/o, map the b_addr into kernel virtual space using |
1487 | * the Nfsiomap pte's | |
1488 | * Also, add a temporary b_rcred for reading using the process's uid | |
1489 | * and a guess at a group | |
a2907882 | 1490 | */ |
9238aa59 | 1491 | if (bp->b_flags & B_PHYS) { |
8c379a26 | 1492 | np->n_flag |= NPAGEDON; |
9238aa59 RM |
1493 | bp->b_rcred = cr = crget(); |
1494 | rp = (bp->b_flags & B_DIRTY) ? &proc[2] : bp->b_proc; | |
1495 | cr->cr_uid = rp->p_uid; | |
1496 | cr->cr_gid = 0; /* Anything ?? */ | |
1497 | cr->cr_ngroups = 1; | |
e8540f59 KM |
1498 | o = (int)bp->b_un.b_addr & PGOFSET; |
1499 | npf2 = npf = btoc(bp->b_bcount + o); | |
1500 | ||
9238aa59 RM |
1501 | /* |
1502 | * Get some mapping page table entries | |
1503 | */ | |
1504 | while ((reg = rmalloc(nfsmap, (long)npf)) == 0) { | |
1505 | nfsmap_want++; | |
1506 | sleep((caddr_t)&nfsmap_want, PZERO-1); | |
1507 | } | |
1508 | reg--; | |
e8540f59 KM |
1509 | if (bp->b_flags & B_PAGET) |
1510 | pte = &Usrptmap[btokmx((struct pte *)bp->b_un.b_addr)]; | |
9238aa59 | 1511 | else { |
e8540f59 | 1512 | v = btop(bp->b_un.b_addr); |
9238aa59 RM |
1513 | if (bp->b_flags & B_UAREA) |
1514 | pte = &rp->p_addr[v]; | |
1515 | else | |
1516 | pte = vtopte(rp, v); | |
1517 | } | |
e8540f59 | 1518 | |
9238aa59 RM |
1519 | /* |
1520 | * Play vmaccess() but with the Nfsiomap page table | |
1521 | */ | |
1522 | ppte = &Nfsiomap[reg]; | |
1523 | vbase = vaddr = &nfsiobuf[reg*NBPG]; | |
1524 | while (npf != 0) { | |
1525 | mapin(ppte, (u_int)vaddr, pte->pg_pfnum, (int)(PG_V|PG_KW)); | |
a2907882 | 1526 | #if defined(tahoe) |
9238aa59 | 1527 | mtpr(P1DC, vaddr); |
a2907882 | 1528 | #endif |
9238aa59 RM |
1529 | ppte++; |
1530 | pte++; | |
1531 | vaddr += NBPG; | |
1532 | --npf; | |
1533 | } | |
e8540f59 KM |
1534 | |
1535 | /* | |
1536 | * And do the i/o rpc | |
1537 | */ | |
9238aa59 | 1538 | io.iov_base = vbase+o; |
e8540f59 | 1539 | io.iov_len = uiop->uio_resid = bp->b_bcount; |
589be24d | 1540 | uiop->uio_offset = bp->b_blkno * DEV_BSIZE; |
e8540f59 KM |
1541 | if (bp->b_flags & B_READ) { |
1542 | uiop->uio_rw = UIO_READ; | |
1543 | nfsstats.read_physios++; | |
1544 | bp->b_error = error = nfs_readrpc(vp, uiop, bp->b_rcred); | |
8c379a26 KM |
1545 | /* |
1546 | * If a text file has been modified since it was exec'd | |
1547 | * blow the process' out of the water. This is the | |
1548 | * closest we can come to "Text File Busy" in good old | |
1549 | * stateless nfs. | |
1550 | */ | |
1551 | if ((vp->v_flag & VTEXT) && | |
1552 | (vp->v_text->x_mtime != np->n_vattr.va_mtime.tv_sec)) | |
1553 | xinval(vp); | |
e8540f59 KM |
1554 | } else { |
1555 | uiop->uio_rw = UIO_WRITE; | |
1556 | nfsstats.write_physios++; | |
1557 | bp->b_error = error = nfs_writerpc(vp, uiop, bp->b_wcred); | |
ffe6f482 | 1558 | } |
e8540f59 KM |
1559 | |
1560 | /* | |
1561 | * Finally, release pte's used by physical i/o | |
1562 | */ | |
9238aa59 RM |
1563 | crfree(cr); |
1564 | rmfree(nfsmap, (long)npf2, (long)++reg); | |
1565 | if (nfsmap_want) { | |
1566 | nfsmap_want = 0; | |
1567 | wakeup((caddr_t)&nfsmap_want); | |
1568 | } | |
e8540f59 KM |
1569 | } else { |
1570 | if (bp->b_flags & B_READ) { | |
1571 | io.iov_len = uiop->uio_resid = bp->b_bcount; | |
589be24d | 1572 | uiop->uio_offset = bp->b_blkno * DEV_BSIZE; |
e8540f59 KM |
1573 | io.iov_base = bp->b_un.b_addr; |
1574 | uiop->uio_rw = UIO_READ; | |
1575 | nfsstats.read_bios++; | |
1576 | bp->b_error = error = nfs_readrpc(vp, uiop, bp->b_rcred); | |
1577 | } else { | |
1578 | io.iov_len = uiop->uio_resid = bp->b_dirtyend | |
1579 | - bp->b_dirtyoff; | |
589be24d | 1580 | uiop->uio_offset = (bp->b_blkno * DEV_BSIZE) |
e8540f59 KM |
1581 | + bp->b_dirtyoff; |
1582 | io.iov_base = bp->b_un.b_addr + bp->b_dirtyoff; | |
1583 | uiop->uio_rw = UIO_WRITE; | |
1584 | nfsstats.write_bios++; | |
1585 | bp->b_error = error = nfs_writerpc(vp, uiop, bp->b_wcred); | |
1586 | if (error) { | |
e8540f59 KM |
1587 | np->n_error = error; |
1588 | np->n_flag |= NWRITEERR; | |
1589 | } | |
1590 | bp->b_dirtyoff = bp->b_dirtyend = 0; | |
1591 | } | |
9238aa59 | 1592 | } |
e8540f59 KM |
1593 | if (error) |
1594 | bp->b_flags |= B_ERROR; | |
1595 | bp->b_resid = uiop->uio_resid; | |
a2907882 | 1596 | biodone(bp); |
9238aa59 RM |
1597 | return (error); |
1598 | } | |
1599 | ||
1600 | /* | |
1601 | * Flush all the blocks associated with a vnode. | |
1602 | * Walk through the buffer pool and push any dirty pages | |
1603 | * associated with the vnode. | |
1604 | */ | |
13576453 | 1605 | /* ARGSUSED */ |
f8428623 | 1606 | nfs_fsync(vp, fflags, cred, waitfor) |
9238aa59 RM |
1607 | register struct vnode *vp; |
1608 | int fflags; | |
1609 | struct ucred *cred; | |
f8428623 | 1610 | int waitfor; |
9238aa59 RM |
1611 | { |
1612 | register struct nfsnode *np = VTONFS(vp); | |
e8540f59 | 1613 | int error = 0; |
9238aa59 | 1614 | |
9238aa59 RM |
1615 | if (np->n_flag & NMODIFIED) { |
1616 | np->n_flag &= ~NMODIFIED; | |
e8540f59 | 1617 | vflushbuf(vp, waitfor == MNT_WAIT ? B_SYNC : 0); |
9238aa59 | 1618 | } |
e8540f59 KM |
1619 | if (!error && (np->n_flag & NWRITEERR)) |
1620 | error = np->n_error; | |
a2907882 KM |
1621 | return (error); |
1622 | } | |
d002709d KM |
1623 | |
1624 | /* | |
1625 | * Print out the contents of an nfsnode. | |
1626 | */ | |
1627 | nfs_print(vp) | |
1628 | struct vnode *vp; | |
1629 | { | |
1630 | register struct nfsnode *np = VTONFS(vp); | |
1631 | ||
b2d955e4 KM |
1632 | printf("tag VT_NFS, fileid %d fsid 0x%x", |
1633 | np->n_vattr.va_fileid, np->n_vattr.va_fsid); | |
1634 | #ifdef FIFO | |
1635 | if (vp->v_type == VFIFO) | |
1636 | fifo_printinfo(vp); | |
1637 | #endif /* FIFO */ | |
1638 | printf("%s\n", (np->n_flag & NLOCKED) ? " (LOCKED)" : ""); | |
1a1dbccb KM |
1639 | if (np->n_lockholder == 0) |
1640 | return; | |
1641 | printf("\towner pid %d", np->n_lockholder); | |
1642 | if (np->n_lockwaiter) | |
1643 | printf(" waiting pid %d", np->n_lockwaiter); | |
1644 | printf("\n"); | |
d002709d | 1645 | } |