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 | * | |
dbf0c423 | 8 | * %sccs.include.redist.c% |
a2907882 | 9 | * |
c5b4f497 | 10 | * @(#)nfs_vnops.c 7.67 (Berkeley) %G% |
a2907882 KM |
11 | */ |
12 | ||
13 | /* | |
14 | * vnode op calls for sun nfs version 2 | |
15 | */ | |
16 | ||
a2907882 | 17 | #include "param.h" |
a2907882 | 18 | #include "proc.h" |
e49b1a6c | 19 | #include "kernel.h" |
e3f173b4 | 20 | #include "systm.h" |
a2907882 KM |
21 | #include "mount.h" |
22 | #include "buf.h" | |
a2907882 KM |
23 | #include "malloc.h" |
24 | #include "mbuf.h" | |
a2907882 | 25 | #include "conf.h" |
26cb2431 | 26 | #include "namei.h" |
a2907882 | 27 | #include "vnode.h" |
26cb2431 KM |
28 | #include "specdev.h" |
29 | #include "fifo.h" | |
9238aa59 | 30 | #include "map.h" |
058dee65 | 31 | |
a8e2dfc1 KB |
32 | #include "ufs/ufs/quota.h" |
33 | #include "ufs/ufs/inode.h" | |
34 | #include "ufs/ufs/dir.h" | |
058dee65 | 35 | |
2c5b44a2 | 36 | #include "rpcv2.h" |
a2907882 KM |
37 | #include "nfsv2.h" |
38 | #include "nfs.h" | |
39 | #include "nfsnode.h" | |
40 | #include "nfsmount.h" | |
41 | #include "xdr_subs.h" | |
42 | #include "nfsm_subs.h" | |
2c5b44a2 | 43 | #include "nqnfs.h" |
a2907882 KM |
44 | |
45 | /* Defs */ | |
46 | #define TRUE 1 | |
47 | #define FALSE 0 | |
48 | ||
26cb2431 KM |
49 | /* |
50 | * Global vfs data structures for nfs | |
51 | */ | |
a2907882 | 52 | struct vnodeops nfsv2_vnodeops = { |
d002709d KM |
53 | nfs_lookup, /* lookup */ |
54 | nfs_create, /* create */ | |
55 | nfs_mknod, /* mknod */ | |
56 | nfs_open, /* open */ | |
57 | nfs_close, /* close */ | |
58 | nfs_access, /* access */ | |
59 | nfs_getattr, /* getattr */ | |
60 | nfs_setattr, /* setattr */ | |
61 | nfs_read, /* read */ | |
62 | nfs_write, /* write */ | |
26cb2431 KM |
63 | nfs_ioctl, /* ioctl */ |
64 | nfs_select, /* select */ | |
65 | nfs_mmap, /* mmap */ | |
d002709d | 66 | nfs_fsync, /* fsync */ |
26cb2431 | 67 | nfs_seek, /* seek */ |
d002709d KM |
68 | nfs_remove, /* remove */ |
69 | nfs_link, /* link */ | |
70 | nfs_rename, /* rename */ | |
71 | nfs_mkdir, /* mkdir */ | |
72 | nfs_rmdir, /* rmdir */ | |
73 | nfs_symlink, /* symlink */ | |
74 | nfs_readdir, /* readdir */ | |
75 | nfs_readlink, /* readlink */ | |
76 | nfs_abortop, /* abortop */ | |
77 | nfs_inactive, /* inactive */ | |
78 | nfs_reclaim, /* reclaim */ | |
79 | nfs_lock, /* lock */ | |
80 | nfs_unlock, /* unlock */ | |
81 | nfs_bmap, /* bmap */ | |
82 | nfs_strategy, /* strategy */ | |
83 | nfs_print, /* print */ | |
2bde67fd | 84 | nfs_islocked, /* islocked */ |
a4128336 | 85 | nfs_advlock, /* advlock */ |
9396df75 KM |
86 | nfs_blkatoff, /* blkatoff */ |
87 | nfs_vget, /* vget */ | |
88 | nfs_valloc, /* valloc */ | |
89 | nfs_vfree, /* vfree */ | |
90 | nfs_truncate, /* truncate */ | |
91 | nfs_update, /* update */ | |
92 | bwrite, /* bwrite */ | |
a2907882 KM |
93 | }; |
94 | ||
26cb2431 KM |
95 | /* |
96 | * Special device vnode ops | |
97 | */ | |
8a1675f3 | 98 | struct vnodeops spec_nfsv2nodeops = { |
9106dc18 | 99 | spec_lookup, /* lookup */ |
26cb2431 KM |
100 | spec_create, /* create */ |
101 | spec_mknod, /* mknod */ | |
9106dc18 KM |
102 | spec_open, /* open */ |
103 | spec_close, /* close */ | |
104 | nfs_access, /* access */ | |
105 | nfs_getattr, /* getattr */ | |
106 | nfs_setattr, /* setattr */ | |
107 | spec_read, /* read */ | |
108 | spec_write, /* write */ | |
109 | spec_ioctl, /* ioctl */ | |
110 | spec_select, /* select */ | |
26cb2431 KM |
111 | spec_mmap, /* mmap */ |
112 | spec_fsync, /* fsync */ | |
113 | spec_seek, /* seek */ | |
114 | spec_remove, /* remove */ | |
115 | spec_link, /* link */ | |
116 | spec_rename, /* rename */ | |
117 | spec_mkdir, /* mkdir */ | |
118 | spec_rmdir, /* rmdir */ | |
119 | spec_symlink, /* symlink */ | |
120 | spec_readdir, /* readdir */ | |
121 | spec_readlink, /* readlink */ | |
122 | spec_abortop, /* abortop */ | |
9106dc18 KM |
123 | nfs_inactive, /* inactive */ |
124 | nfs_reclaim, /* reclaim */ | |
125 | nfs_lock, /* lock */ | |
126 | nfs_unlock, /* unlock */ | |
d002709d | 127 | spec_bmap, /* bmap */ |
9106dc18 | 128 | spec_strategy, /* strategy */ |
d002709d | 129 | nfs_print, /* print */ |
2bde67fd | 130 | nfs_islocked, /* islocked */ |
a4128336 | 131 | spec_advlock, /* advlock */ |
9396df75 KM |
132 | spec_blkatoff, /* blkatoff */ |
133 | spec_vget, /* vget */ | |
134 | spec_valloc, /* valloc */ | |
135 | spec_vfree, /* vfree */ | |
136 | spec_truncate, /* truncate */ | |
137 | nfs_update, /* update */ | |
138 | bwrite, /* bwrite */ | |
a2907882 KM |
139 | }; |
140 | ||
b2d955e4 | 141 | #ifdef FIFO |
b2d955e4 KM |
142 | struct vnodeops fifo_nfsv2nodeops = { |
143 | fifo_lookup, /* lookup */ | |
26cb2431 KM |
144 | fifo_create, /* create */ |
145 | fifo_mknod, /* mknod */ | |
b2d955e4 KM |
146 | fifo_open, /* open */ |
147 | fifo_close, /* close */ | |
148 | nfs_access, /* access */ | |
149 | nfs_getattr, /* getattr */ | |
150 | nfs_setattr, /* setattr */ | |
151 | fifo_read, /* read */ | |
152 | fifo_write, /* write */ | |
153 | fifo_ioctl, /* ioctl */ | |
154 | fifo_select, /* select */ | |
26cb2431 KM |
155 | fifo_mmap, /* mmap */ |
156 | fifo_fsync, /* fsync */ | |
157 | fifo_seek, /* seek */ | |
158 | fifo_remove, /* remove */ | |
159 | fifo_link, /* link */ | |
160 | fifo_rename, /* rename */ | |
161 | fifo_mkdir, /* mkdir */ | |
162 | fifo_rmdir, /* rmdir */ | |
163 | fifo_symlink, /* symlink */ | |
164 | fifo_readdir, /* readdir */ | |
165 | fifo_readlink, /* readlink */ | |
166 | fifo_abortop, /* abortop */ | |
b2d955e4 KM |
167 | nfs_inactive, /* inactive */ |
168 | nfs_reclaim, /* reclaim */ | |
169 | nfs_lock, /* lock */ | |
170 | nfs_unlock, /* unlock */ | |
171 | fifo_bmap, /* bmap */ | |
172 | fifo_badop, /* strategy */ | |
173 | nfs_print, /* print */ | |
174 | nfs_islocked, /* islocked */ | |
a4128336 | 175 | fifo_advlock, /* advlock */ |
9396df75 KM |
176 | fifo_blkatoff, /* blkatoff */ |
177 | fifo_vget, /* vget */ | |
178 | fifo_valloc, /* valloc */ | |
179 | fifo_vfree, /* vfree */ | |
180 | fifo_truncate, /* truncate */ | |
181 | nfs_update, /* update */ | |
182 | bwrite, /* bwrite */ | |
b2d955e4 KM |
183 | }; |
184 | #endif /* FIFO */ | |
185 | ||
26cb2431 | 186 | /* |
2c5b44a2 | 187 | * Global variables |
26cb2431 | 188 | */ |
a2907882 KM |
189 | extern u_long nfs_procids[NFS_NPROCS]; |
190 | extern u_long nfs_prog, nfs_vers; | |
a2907882 | 191 | extern char nfsiobuf[MAXPHYS+NBPG]; |
9238aa59 | 192 | struct buf nfs_bqueue; /* Queue head for nfsiod's */ |
f0f1cbaa | 193 | struct proc *nfs_iodwant[NFS_MAXASYNCDAEMON]; |
1c89915d | 194 | int nfs_numasync = 0; |
2c5b44a2 | 195 | #define DIRHDSIZ (sizeof (struct direct) - (MAXNAMLEN + 1)) |
a2907882 KM |
196 | |
197 | /* | |
198 | * nfs null call from vfs. | |
199 | */ | |
cfef4373 | 200 | int |
2c5b44a2 | 201 | nfs_null(vp, cred, procp) |
a2907882 KM |
202 | struct vnode *vp; |
203 | struct ucred *cred; | |
2c5b44a2 | 204 | struct proc *procp; |
a2907882 | 205 | { |
13576453 | 206 | caddr_t bpos, dpos; |
13576453 KM |
207 | int error = 0; |
208 | struct mbuf *mreq, *mrep, *md, *mb; | |
a2907882 | 209 | |
2c5b44a2 KM |
210 | nfsm_reqhead(vp, NFSPROC_NULL, 0); |
211 | nfsm_request(vp, NFSPROC_NULL, procp, cred); | |
a2907882 KM |
212 | nfsm_reqdone; |
213 | return (error); | |
214 | } | |
215 | ||
216 | /* | |
217 | * nfs access vnode op. | |
218 | * Essentially just get vattr and then imitate iaccess() | |
219 | */ | |
cfef4373 | 220 | int |
2c5b44a2 | 221 | nfs_access(vp, mode, cred, procp) |
a2907882 KM |
222 | struct vnode *vp; |
223 | int mode; | |
224 | register struct ucred *cred; | |
2c5b44a2 | 225 | struct proc *procp; |
a2907882 KM |
226 | { |
227 | register struct vattr *vap; | |
228 | register gid_t *gp; | |
229 | struct vattr vattr; | |
230 | register int i; | |
231 | int error; | |
232 | ||
233 | /* | |
234 | * If you're the super-user, | |
235 | * you always get access. | |
236 | */ | |
237 | if (cred->cr_uid == 0) | |
238 | return (0); | |
239 | vap = &vattr; | |
2c5b44a2 | 240 | if (error = nfs_getattr(vp, vap, cred, procp)) |
9238aa59 | 241 | return (error); |
a2907882 KM |
242 | /* |
243 | * Access check is based on only one of owner, group, public. | |
244 | * If not owner, then check group. If not a member of the | |
245 | * group, then check public access. | |
246 | */ | |
247 | if (cred->cr_uid != vap->va_uid) { | |
248 | mode >>= 3; | |
249 | gp = cred->cr_groups; | |
250 | for (i = 0; i < cred->cr_ngroups; i++, gp++) | |
251 | if (vap->va_gid == *gp) | |
252 | goto found; | |
253 | mode >>= 3; | |
254 | found: | |
255 | ; | |
256 | } | |
257 | if ((vap->va_mode & mode) != 0) | |
258 | return (0); | |
259 | return (EACCES); | |
260 | } | |
261 | ||
262 | /* | |
263 | * nfs open vnode op | |
264 | * Just check to see if the type is ok | |
2c5b44a2 | 265 | * and that deletion is not in progress. |
a2907882 | 266 | */ |
13576453 | 267 | /* ARGSUSED */ |
cfef4373 | 268 | int |
2c5b44a2 KM |
269 | nfs_open(vp, mode, cred, procp) |
270 | register struct vnode *vp; | |
a2907882 KM |
271 | int mode; |
272 | struct ucred *cred; | |
2c5b44a2 | 273 | struct proc *procp; |
a2907882 | 274 | { |
a2907882 | 275 | |
2c5b44a2 | 276 | if (vp->v_type != VREG && vp->v_type != VDIR && vp->v_type != VLNK) |
a2907882 | 277 | return (EACCES); |
2c5b44a2 KM |
278 | if ((VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NQNFS) == 0) |
279 | VTONFS(vp)->n_attrstamp = 0; /* For Open/Close consistency */ | |
280 | return (0); | |
a2907882 KM |
281 | } |
282 | ||
283 | /* | |
284 | * nfs close vnode op | |
9238aa59 | 285 | * For reg files, invalidate any buffer cache entries. |
a2907882 | 286 | */ |
13576453 | 287 | /* ARGSUSED */ |
cfef4373 | 288 | int |
2c5b44a2 | 289 | nfs_close(vp, fflags, cred, procp) |
a2907882 KM |
290 | register struct vnode *vp; |
291 | int fflags; | |
292 | struct ucred *cred; | |
2c5b44a2 | 293 | struct proc *procp; |
a2907882 | 294 | { |
13576453 | 295 | register struct nfsnode *np = VTONFS(vp); |
ffe6f482 | 296 | int error = 0; |
a2907882 | 297 | |
2c5b44a2 KM |
298 | if ((np->n_flag & NMODIFIED) && |
299 | (VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NQNFS) == 0 && | |
300 | vp->v_type == VREG) { | |
f0f1cbaa | 301 | np->n_flag &= ~NMODIFIED; |
e8540f59 | 302 | vinvalbuf(vp, TRUE); |
f0f1cbaa | 303 | np->n_attrstamp = 0; |
ffe6f482 KM |
304 | if (np->n_flag & NWRITEERR) { |
305 | np->n_flag &= ~NWRITEERR; | |
e8540f59 | 306 | error = np->n_error; |
ffe6f482 | 307 | } |
9238aa59 | 308 | } |
a2907882 KM |
309 | return (error); |
310 | } | |
311 | ||
312 | /* | |
313 | * nfs getattr call from vfs. | |
314 | */ | |
cfef4373 | 315 | int |
2c5b44a2 | 316 | nfs_getattr(vp, vap, cred, procp) |
13576453 KM |
317 | register struct vnode *vp; |
318 | struct vattr *vap; | |
a2907882 | 319 | struct ucred *cred; |
2c5b44a2 | 320 | struct proc *procp; |
a2907882 | 321 | { |
13576453 | 322 | register caddr_t cp; |
13576453 | 323 | caddr_t bpos, dpos; |
13576453 KM |
324 | int error = 0; |
325 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
326 | |
327 | /* First look in the cache.. */ | |
328 | if (nfs_getattrcache(vp, vap) == 0) | |
329 | return (0); | |
330 | nfsstats.rpccnt[NFSPROC_GETATTR]++; | |
2c5b44a2 | 331 | nfsm_reqhead(vp, NFSPROC_GETATTR, NFSX_FH); |
a2907882 | 332 | nfsm_fhtom(vp); |
2c5b44a2 | 333 | nfsm_request(vp, NFSPROC_GETATTR, procp, cred); |
a2907882 KM |
334 | nfsm_loadattr(vp, vap); |
335 | nfsm_reqdone; | |
336 | return (error); | |
337 | } | |
338 | ||
339 | /* | |
340 | * nfs setattr call. | |
341 | */ | |
cfef4373 | 342 | int |
2c5b44a2 | 343 | nfs_setattr(vp, vap, cred, procp) |
13576453 | 344 | register struct vnode *vp; |
a2907882 KM |
345 | register struct vattr *vap; |
346 | struct ucred *cred; | |
2c5b44a2 | 347 | struct proc *procp; |
a2907882 | 348 | { |
9238aa59 | 349 | register struct nfsv2_sattr *sp; |
13576453 KM |
350 | register caddr_t cp; |
351 | register long t1; | |
2c5b44a2 KM |
352 | caddr_t bpos, dpos, cp2; |
353 | u_long *tl; | |
13576453 KM |
354 | int error = 0; |
355 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
2c5b44a2 KM |
356 | struct nfsnode *np = VTONFS(vp); |
357 | u_quad_t frev; | |
a2907882 KM |
358 | |
359 | nfsstats.rpccnt[NFSPROC_SETATTR]++; | |
2c5b44a2 | 360 | nfsm_reqhead(vp, NFSPROC_SETATTR, NFSX_FH+NFSX_SATTR); |
a2907882 | 361 | nfsm_fhtom(vp); |
9238aa59 | 362 | nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR); |
a2907882 | 363 | if (vap->va_mode == 0xffff) |
9238aa59 | 364 | sp->sa_mode = VNOVAL; |
a2907882 | 365 | else |
9238aa59 | 366 | sp->sa_mode = vtonfs_mode(vp->v_type, vap->va_mode); |
a2907882 | 367 | if (vap->va_uid == 0xffff) |
9238aa59 | 368 | sp->sa_uid = VNOVAL; |
a2907882 | 369 | else |
9238aa59 | 370 | sp->sa_uid = txdr_unsigned(vap->va_uid); |
a2907882 | 371 | if (vap->va_gid == 0xffff) |
9238aa59 | 372 | sp->sa_gid = VNOVAL; |
a2907882 | 373 | else |
9238aa59 RM |
374 | sp->sa_gid = txdr_unsigned(vap->va_gid); |
375 | sp->sa_size = txdr_unsigned(vap->va_size); | |
e556b498 KM |
376 | sp->sa_atime.tv_sec = txdr_unsigned(vap->va_atime.tv_sec); |
377 | sp->sa_atime.tv_usec = txdr_unsigned(vap->va_flags); | |
378 | txdr_time(&vap->va_mtime, &sp->sa_mtime); | |
379 | if (vap->va_size != VNOVAL || vap->va_mtime.tv_sec != VNOVAL || | |
380 | vap->va_atime.tv_sec != VNOVAL) { | |
00b72154 KM |
381 | if (np->n_flag & NMODIFIED) { |
382 | np->n_flag &= ~NMODIFIED; | |
1c89915d KM |
383 | if (vap->va_size == 0) |
384 | vinvalbuf(vp, FALSE); | |
385 | else | |
386 | vinvalbuf(vp, TRUE); | |
00b72154 KM |
387 | } |
388 | } | |
2c5b44a2 | 389 | nfsm_request(vp, NFSPROC_SETATTR, procp, cred); |
a2907882 | 390 | nfsm_loadattr(vp, (struct vattr *)0); |
2c5b44a2 KM |
391 | if ((VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NQNFS) && |
392 | NQNFS_CKCACHABLE(vp, NQL_WRITE)) { | |
393 | nfsm_dissect(tl, u_long *, 2*NFSX_UNSIGNED); | |
394 | fxdr_hyper(tl, &frev); | |
395 | if (QUADGT(frev, np->n_brev)) | |
396 | np->n_brev = frev; | |
397 | } | |
a2907882 KM |
398 | nfsm_reqdone; |
399 | return (error); | |
400 | } | |
401 | ||
402 | /* | |
403 | * nfs lookup call, one step at a time... | |
404 | * First look in cache | |
405 | * If not found, unlock the directory nfsnode and do the rpc | |
406 | */ | |
cfef4373 | 407 | int |
c5b4f497 | 408 | nfs_lookup(dvp, vpp, cnp) |
cfef4373 JH |
409 | struct vnode *dvp; |
410 | struct vnode **vpp; | |
411 | struct componentname *cnp; | |
a2907882 KM |
412 | { |
413 | register struct vnode *vdp; | |
26cb2431 | 414 | register u_long *tl; |
13576453 KM |
415 | register caddr_t cp; |
416 | register long t1, t2; | |
2c5b44a2 KM |
417 | struct nfsmount *nmp; |
418 | struct nfsnode *tp; | |
13576453 | 419 | caddr_t bpos, dpos, cp2; |
2c5b44a2 | 420 | time_t reqtime; |
13576453 | 421 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; |
a2907882 KM |
422 | struct vnode *newvp; |
423 | long len; | |
424 | nfsv2fh_t *fhp; | |
425 | struct nfsnode *np; | |
cfef4373 | 426 | int lockparent, wantparent, error = 0; |
2c5b44a2 KM |
427 | int nqlflag, cachable; |
428 | u_quad_t frev; | |
a2907882 | 429 | |
cfef4373 JH |
430 | *vpp = NULL; |
431 | if (dvp->v_type != VDIR) | |
a2907882 | 432 | return (ENOTDIR); |
cfef4373 JH |
433 | lockparent = cnp->cn_flags & LOCKPARENT; |
434 | wantparent = cnp->cn_flags & (LOCKPARENT|WANTPARENT); | |
435 | nmp = VFSTONFS(dvp->v_mount); | |
436 | np = VTONFS(dvp); | |
437 | if ((error = cache_lookup(dvp, vpp, cnp)) && error != ENOENT) { | |
9238aa59 RM |
438 | struct vattr vattr; |
439 | int vpid; | |
440 | ||
cfef4373 | 441 | vdp = *vpp; |
9238aa59 | 442 | vpid = vdp->v_id; |
a2907882 | 443 | /* |
9238aa59 RM |
444 | * See the comment starting `Step through' in ufs/ufs_lookup.c |
445 | * for an explanation of the locking protocol | |
a2907882 | 446 | */ |
cfef4373 | 447 | if (dvp == vdp) { |
36c3043b | 448 | VREF(vdp); |
8a1675f3 | 449 | error = 0; |
2c5b44a2 | 450 | } else |
8a1675f3 | 451 | error = vget(vdp); |
8a1675f3 | 452 | if (!error) { |
8c379a26 | 453 | if (vpid == vdp->v_id) { |
2c5b44a2 | 454 | if (nmp->nm_flag & NFSMNT_NQNFS) { |
cfef4373 | 455 | if (NQNFS_CKCACHABLE(dvp, NQL_READ)) { |
2c5b44a2 KM |
456 | if (QUADNE(np->n_lrev, np->n_brev) || |
457 | (np->n_flag & NMODIFIED)) { | |
458 | np->n_direofoffset = 0; | |
cfef4373 | 459 | cache_purge(dvp); |
2c5b44a2 | 460 | np->n_flag &= ~NMODIFIED; |
cfef4373 | 461 | vinvalbuf(dvp, FALSE); |
2c5b44a2 KM |
462 | np->n_brev = np->n_lrev; |
463 | } else { | |
464 | nfsstats.lookupcache_hits++; | |
cfef4373 JH |
465 | if (cnp->cn_nameiop != LOOKUP && |
466 | (cnp->cn_flags&ISLASTCN)) | |
467 | cnp->cn_flags |= SAVENAME; | |
2c5b44a2 KM |
468 | return (0); |
469 | } | |
470 | } | |
cfef4373 | 471 | } else if (!nfs_getattr(vdp, &vattr, cnp->cn_cred, cnp->cn_proc) && |
8c379a26 | 472 | vattr.va_ctime.tv_sec == VTONFS(vdp)->n_ctime) { |
8a1675f3 | 473 | nfsstats.lookupcache_hits++; |
cfef4373 JH |
474 | if (cnp->cn_nameiop != LOOKUP && (cnp->cn_flags&ISLASTCN)) |
475 | cnp->cn_flags |= SAVENAME; | |
8a1675f3 | 476 | return (0); |
8c379a26 | 477 | } |
58055488 | 478 | cache_purge(vdp); |
8a1675f3 | 479 | } |
2c5b44a2 | 480 | vrele(vdp); |
9238aa59 | 481 | } |
cfef4373 | 482 | *vpp = NULLVP; |
2c5b44a2 | 483 | } |
ffe6f482 | 484 | error = 0; |
a2907882 | 485 | nfsstats.lookupcache_misses++; |
a2907882 | 486 | nfsstats.rpccnt[NFSPROC_LOOKUP]++; |
cfef4373 JH |
487 | len = cnp->cn_namelen; |
488 | nfsm_reqhead(dvp, NFSPROC_LOOKUP, NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len)); | |
2c5b44a2 KM |
489 | |
490 | /* | |
491 | * For nqnfs optionally piggyback a getlease request for the name | |
492 | * being looked up. | |
493 | */ | |
494 | if (nmp->nm_flag & NFSMNT_NQNFS) { | |
495 | if ((nmp->nm_flag & NFSMNT_NQLOOKLEASE) && | |
cfef4373 | 496 | ((cnp->cn_flags&MAKEENTRY) && (cnp->cn_nameiop != DELETE || !(cnp->cn_flags&ISLASTCN)))) { |
2c5b44a2 KM |
497 | nfsm_build(tl, u_long *, 2*NFSX_UNSIGNED); |
498 | *tl++ = txdr_unsigned(NQL_READ); | |
499 | *tl = txdr_unsigned(nmp->nm_leaseterm); | |
500 | } else { | |
501 | nfsm_build(tl, u_long *, NFSX_UNSIGNED); | |
502 | *tl = 0; | |
503 | } | |
504 | } | |
cfef4373 JH |
505 | nfsm_fhtom(dvp); |
506 | nfsm_strtom(cnp->cn_nameptr, len, NFS_MAXNAMLEN); | |
2c5b44a2 | 507 | reqtime = time.tv_sec; |
cfef4373 | 508 | nfsm_request(dvp, NFSPROC_LOOKUP, cnp->cn_proc, cnp->cn_cred); |
a2907882 KM |
509 | nfsmout: |
510 | if (error) { | |
cfef4373 JH |
511 | if (cnp->cn_nameiop != LOOKUP && (cnp->cn_flags&ISLASTCN)) |
512 | cnp->cn_flags |= SAVENAME; | |
b2f2eab2 | 513 | return (error); |
a2907882 | 514 | } |
2c5b44a2 KM |
515 | if (nmp->nm_flag & NFSMNT_NQNFS) { |
516 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); | |
517 | if (*tl) { | |
518 | nqlflag = fxdr_unsigned(int, *tl); | |
519 | nfsm_dissect(tl, u_long *, 4*NFSX_UNSIGNED); | |
520 | cachable = fxdr_unsigned(int, *tl++); | |
521 | reqtime += fxdr_unsigned(int, *tl++); | |
522 | fxdr_hyper(tl, &frev); | |
523 | } else | |
524 | nqlflag = 0; | |
525 | } | |
526 | nfsm_dissect(fhp, nfsv2fh_t *, NFSX_FH); | |
a2907882 KM |
527 | |
528 | /* | |
2c5b44a2 | 529 | * Handle RENAME case... |
a2907882 | 530 | */ |
cfef4373 | 531 | if (cnp->cn_nameiop == RENAME && wantparent && (cnp->cn_flags&ISLASTCN)) { |
2c5b44a2 | 532 | if (!bcmp(np->n_fh.fh_bytes, (caddr_t)fhp, NFSX_FH)) { |
a2907882 KM |
533 | m_freem(mrep); |
534 | return (EISDIR); | |
535 | } | |
cfef4373 | 536 | if (error = nfs_nget(dvp->v_mount, fhp, &np)) { |
a2907882 KM |
537 | m_freem(mrep); |
538 | return (error); | |
539 | } | |
540 | newvp = NFSTOV(np); | |
f67785e5 KM |
541 | if (error = |
542 | nfs_loadattrcache(&newvp, &md, &dpos, (struct vattr *)0)) { | |
2c5b44a2 | 543 | vrele(newvp); |
a2907882 KM |
544 | m_freem(mrep); |
545 | return (error); | |
546 | } | |
cfef4373 | 547 | *vpp = newvp; |
f5dffb64 | 548 | m_freem(mrep); |
cfef4373 | 549 | cnp->cn_flags |= SAVENAME; |
a2907882 KM |
550 | return (0); |
551 | } | |
552 | ||
2c5b44a2 | 553 | if (!bcmp(np->n_fh.fh_bytes, (caddr_t)fhp, NFSX_FH)) { |
cfef4373 JH |
554 | VREF(dvp); |
555 | newvp = dvp; | |
a2907882 | 556 | } else { |
cfef4373 | 557 | if (error = nfs_nget(dvp->v_mount, fhp, &np)) { |
a2907882 KM |
558 | m_freem(mrep); |
559 | return (error); | |
560 | } | |
561 | newvp = NFSTOV(np); | |
562 | } | |
f67785e5 | 563 | if (error = nfs_loadattrcache(&newvp, &md, &dpos, (struct vattr *)0)) { |
2c5b44a2 | 564 | vrele(newvp); |
a2907882 KM |
565 | m_freem(mrep); |
566 | return (error); | |
567 | } | |
568 | m_freem(mrep); | |
cfef4373 JH |
569 | *vpp = newvp; |
570 | if (cnp->cn_nameiop != LOOKUP && (cnp->cn_flags&ISLASTCN)) | |
571 | cnp->cn_flags |= SAVENAME; | |
572 | if ((cnp->cn_flags&MAKEENTRY) && (cnp->cn_nameiop != DELETE || !(cnp->cn_flags&ISLASTCN))) { | |
2c5b44a2 KM |
573 | if ((nmp->nm_flag & NFSMNT_NQNFS) == 0) |
574 | np->n_ctime = np->n_vattr.va_ctime.tv_sec; | |
575 | else if (nqlflag && reqtime > time.tv_sec) { | |
576 | if (np->n_tnext) { | |
577 | if (np->n_tnext == (struct nfsnode *)nmp) | |
578 | nmp->nm_tprev = np->n_tprev; | |
579 | else | |
580 | np->n_tnext->n_tprev = np->n_tprev; | |
581 | if (np->n_tprev == (struct nfsnode *)nmp) | |
582 | nmp->nm_tnext = np->n_tnext; | |
583 | else | |
584 | np->n_tprev->n_tnext = np->n_tnext; | |
585 | if (nqlflag == NQL_WRITE) | |
586 | np->n_flag |= NQNFSWRITE; | |
587 | } else if (nqlflag == NQL_READ) | |
588 | np->n_flag &= ~NQNFSWRITE; | |
589 | else | |
590 | np->n_flag |= NQNFSWRITE; | |
591 | if (cachable) | |
592 | np->n_flag &= ~NQNFSNONCACHE; | |
593 | else | |
594 | np->n_flag |= NQNFSNONCACHE; | |
595 | np->n_expiry = reqtime; | |
596 | np->n_lrev = frev; | |
597 | tp = nmp->nm_tprev; | |
598 | while (tp != (struct nfsnode *)nmp && tp->n_expiry > np->n_expiry) | |
599 | tp = tp->n_tprev; | |
600 | if (tp == (struct nfsnode *)nmp) { | |
601 | np->n_tnext = nmp->nm_tnext; | |
602 | nmp->nm_tnext = np; | |
603 | } else { | |
604 | np->n_tnext = tp->n_tnext; | |
605 | tp->n_tnext = np; | |
606 | } | |
607 | np->n_tprev = tp; | |
608 | if (np->n_tnext == (struct nfsnode *)nmp) | |
609 | nmp->nm_tprev = np; | |
610 | else | |
611 | np->n_tnext->n_tprev = np; | |
612 | } | |
cfef4373 | 613 | cache_enter(dvp, *vpp, cnp); |
8c379a26 | 614 | } |
2c5b44a2 | 615 | return (0); |
a2907882 KM |
616 | } |
617 | ||
f0f1cbaa KM |
618 | /* |
619 | * nfs read call. | |
620 | * Just call nfs_bioread() to do the work. | |
621 | */ | |
cfef4373 | 622 | int |
f0f1cbaa KM |
623 | nfs_read(vp, uiop, ioflag, cred) |
624 | register struct vnode *vp; | |
625 | struct uio *uiop; | |
626 | int ioflag; | |
627 | struct ucred *cred; | |
628 | { | |
629 | if (vp->v_type != VREG) | |
630 | return (EPERM); | |
631 | return (nfs_bioread(vp, uiop, ioflag, cred)); | |
632 | } | |
633 | ||
a2907882 KM |
634 | /* |
635 | * nfs readlink call | |
636 | */ | |
cfef4373 | 637 | int |
a2907882 | 638 | nfs_readlink(vp, uiop, cred) |
f0f1cbaa KM |
639 | struct vnode *vp; |
640 | struct uio *uiop; | |
641 | struct ucred *cred; | |
642 | { | |
643 | if (vp->v_type != VLNK) | |
644 | return (EPERM); | |
645 | return (nfs_bioread(vp, uiop, 0, cred)); | |
646 | } | |
647 | ||
648 | /* | |
649 | * Do a readlink rpc. | |
650 | * Called by nfs_doio() from below the buffer cache. | |
651 | */ | |
cfef4373 | 652 | int |
26cb2431 | 653 | nfs_readlinkrpc(vp, uiop, cred) |
13576453 | 654 | register struct vnode *vp; |
a2907882 KM |
655 | struct uio *uiop; |
656 | struct ucred *cred; | |
657 | { | |
26cb2431 | 658 | register u_long *tl; |
13576453 KM |
659 | register caddr_t cp; |
660 | register long t1; | |
661 | caddr_t bpos, dpos, cp2; | |
13576453 KM |
662 | int error = 0; |
663 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
664 | long len; |
665 | ||
666 | nfsstats.rpccnt[NFSPROC_READLINK]++; | |
2c5b44a2 | 667 | nfsm_reqhead(vp, NFSPROC_READLINK, NFSX_FH); |
a2907882 | 668 | nfsm_fhtom(vp); |
2c5b44a2 | 669 | nfsm_request(vp, NFSPROC_READLINK, uiop->uio_procp, cred); |
a2907882 KM |
670 | nfsm_strsiz(len, NFS_MAXPATHLEN); |
671 | nfsm_mtouio(uiop, len); | |
672 | nfsm_reqdone; | |
673 | return (error); | |
674 | } | |
675 | ||
676 | /* | |
f0f1cbaa KM |
677 | * nfs read rpc call |
678 | * Ditto above | |
a2907882 | 679 | */ |
cfef4373 | 680 | int |
26cb2431 | 681 | nfs_readrpc(vp, uiop, cred) |
13576453 | 682 | register struct vnode *vp; |
a2907882 | 683 | struct uio *uiop; |
a2907882 KM |
684 | struct ucred *cred; |
685 | { | |
26cb2431 | 686 | register u_long *tl; |
13576453 KM |
687 | register caddr_t cp; |
688 | register long t1; | |
689 | caddr_t bpos, dpos, cp2; | |
13576453 KM |
690 | int error = 0; |
691 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
692 | struct nfsmount *nmp; |
693 | long len, retlen, tsiz; | |
694 | ||
54fb9dc2 | 695 | nmp = VFSTONFS(vp->v_mount); |
a2907882 | 696 | tsiz = uiop->uio_resid; |
a2907882 KM |
697 | while (tsiz > 0) { |
698 | nfsstats.rpccnt[NFSPROC_READ]++; | |
699 | len = (tsiz > nmp->nm_rsize) ? nmp->nm_rsize : tsiz; | |
2c5b44a2 | 700 | nfsm_reqhead(vp, NFSPROC_READ, NFSX_FH+NFSX_UNSIGNED*3); |
a2907882 | 701 | nfsm_fhtom(vp); |
26cb2431 KM |
702 | nfsm_build(tl, u_long *, NFSX_UNSIGNED*3); |
703 | *tl++ = txdr_unsigned(uiop->uio_offset); | |
704 | *tl++ = txdr_unsigned(len); | |
705 | *tl = 0; | |
2c5b44a2 | 706 | nfsm_request(vp, NFSPROC_READ, uiop->uio_procp, cred); |
a2907882 KM |
707 | nfsm_loadattr(vp, (struct vattr *)0); |
708 | nfsm_strsiz(retlen, nmp->nm_rsize); | |
709 | nfsm_mtouio(uiop, retlen); | |
710 | m_freem(mrep); | |
a2907882 KM |
711 | if (retlen < len) |
712 | tsiz = 0; | |
713 | else | |
714 | tsiz -= len; | |
715 | } | |
716 | nfsmout: | |
a2907882 KM |
717 | return (error); |
718 | } | |
719 | ||
720 | /* | |
721 | * nfs write call | |
722 | */ | |
cfef4373 | 723 | int |
26cb2431 | 724 | nfs_writerpc(vp, uiop, cred) |
13576453 | 725 | register struct vnode *vp; |
a2907882 | 726 | struct uio *uiop; |
a2907882 KM |
727 | struct ucred *cred; |
728 | { | |
26cb2431 | 729 | register u_long *tl; |
13576453 KM |
730 | register caddr_t cp; |
731 | register long t1; | |
2c5b44a2 | 732 | caddr_t bpos, dpos, cp2; |
13576453 KM |
733 | int error = 0; |
734 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 | 735 | struct nfsmount *nmp; |
2c5b44a2 KM |
736 | struct nfsnode *np = VTONFS(vp); |
737 | u_quad_t frev; | |
a2907882 | 738 | long len, tsiz; |
a2907882 | 739 | |
54fb9dc2 | 740 | nmp = VFSTONFS(vp->v_mount); |
a2907882 | 741 | tsiz = uiop->uio_resid; |
a2907882 KM |
742 | while (tsiz > 0) { |
743 | nfsstats.rpccnt[NFSPROC_WRITE]++; | |
744 | len = (tsiz > nmp->nm_wsize) ? nmp->nm_wsize : tsiz; | |
2c5b44a2 KM |
745 | nfsm_reqhead(vp, NFSPROC_WRITE, |
746 | NFSX_FH+NFSX_UNSIGNED*4+nfsm_rndup(len)); | |
a2907882 | 747 | nfsm_fhtom(vp); |
26cb2431 KM |
748 | nfsm_build(tl, u_long *, NFSX_UNSIGNED*4); |
749 | *(tl+1) = txdr_unsigned(uiop->uio_offset); | |
750 | *(tl+3) = txdr_unsigned(len); | |
a2907882 | 751 | nfsm_uiotom(uiop, len); |
2c5b44a2 | 752 | nfsm_request(vp, NFSPROC_WRITE, uiop->uio_procp, cred); |
a2907882 | 753 | nfsm_loadattr(vp, (struct vattr *)0); |
2c5b44a2 KM |
754 | if (nmp->nm_flag & NFSMNT_MYWRITE) |
755 | VTONFS(vp)->n_mtime = VTONFS(vp)->n_vattr.va_mtime.tv_sec; | |
756 | else if ((nmp->nm_flag & NFSMNT_NQNFS) && | |
757 | NQNFS_CKCACHABLE(vp, NQL_WRITE)) { | |
758 | nfsm_dissect(tl, u_long *, 2*NFSX_UNSIGNED); | |
759 | fxdr_hyper(tl, &frev); | |
760 | if (QUADGT(frev, np->n_brev)) | |
761 | np->n_brev = frev; | |
762 | } | |
a2907882 KM |
763 | m_freem(mrep); |
764 | tsiz -= len; | |
a2907882 KM |
765 | } |
766 | nfsmout: | |
2c5b44a2 KM |
767 | if (error) |
768 | uiop->uio_resid = tsiz; | |
a2907882 KM |
769 | return (error); |
770 | } | |
771 | ||
f67785e5 KM |
772 | /* |
773 | * nfs mknod call | |
7c15c5df KM |
774 | * This is a kludge. Use a create rpc but with the IFMT bits of the mode |
775 | * set to specify the file type and the size field for rdev. | |
f67785e5 KM |
776 | */ |
777 | /* ARGSUSED */ | |
cfef4373 | 778 | int |
c5b4f497 | 779 | nfs_mknod(dvp, vpp, cnp, vap) |
cfef4373 JH |
780 | struct vnode *dvp; |
781 | struct vnode **vpp; | |
782 | struct componentname *cnp; | |
783 | struct vattr *vap; | |
f67785e5 | 784 | { |
7c15c5df | 785 | register struct nfsv2_sattr *sp; |
26cb2431 | 786 | register u_long *tl; |
7c15c5df | 787 | register caddr_t cp; |
2c5b44a2 | 788 | register long t2; |
7c15c5df | 789 | caddr_t bpos, dpos; |
7c15c5df KM |
790 | int error = 0; |
791 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
792 | u_long rdev; | |
f67785e5 | 793 | |
7c15c5df KM |
794 | if (vap->va_type == VCHR || vap->va_type == VBLK) |
795 | rdev = txdr_unsigned(vap->va_rdev); | |
796 | #ifdef FIFO | |
797 | else if (vap->va_type == VFIFO) | |
798 | rdev = 0xffffffff; | |
799 | #endif /* FIFO */ | |
800 | else { | |
cfef4373 JH |
801 | VOP_ABORTOP(dvp, cnp); |
802 | vput(dvp); | |
7c15c5df KM |
803 | return (EOPNOTSUPP); |
804 | } | |
805 | nfsstats.rpccnt[NFSPROC_CREATE]++; | |
cfef4373 JH |
806 | nfsm_reqhead(dvp, NFSPROC_CREATE, |
807 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(cnp->cn_namelen)+NFSX_SATTR); | |
808 | nfsm_fhtom(dvp); | |
809 | nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN); | |
7c15c5df KM |
810 | nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR); |
811 | sp->sa_mode = vtonfs_mode(vap->va_type, vap->va_mode); | |
cfef4373 JH |
812 | sp->sa_uid = txdr_unsigned(cnp->cn_cred->cr_uid); |
813 | sp->sa_gid = txdr_unsigned(cnp->cn_cred->cr_gid); | |
7c15c5df KM |
814 | sp->sa_size = rdev; |
815 | /* or should these be VNOVAL ?? */ | |
816 | txdr_time(&vap->va_atime, &sp->sa_atime); | |
817 | txdr_time(&vap->va_mtime, &sp->sa_mtime); | |
cfef4373 | 818 | nfsm_request(dvp, NFSPROC_CREATE, cnp->cn_proc, cnp->cn_cred); |
7c15c5df | 819 | nfsm_reqdone; |
cfef4373 JH |
820 | FREE(cnp->cn_pnbuf, M_NAMEI); |
821 | VTONFS(dvp)->n_flag |= NMODIFIED; | |
822 | vrele(dvp); | |
7c15c5df | 823 | return (error); |
f67785e5 KM |
824 | } |
825 | ||
a2907882 KM |
826 | /* |
827 | * nfs file create call | |
828 | */ | |
cfef4373 | 829 | int |
c5b4f497 | 830 | nfs_create(dvp, vpp, cnp, vap) |
cfef4373 JH |
831 | struct vnode *dvp; |
832 | struct vnode **vpp; | |
833 | struct componentname *cnp; | |
834 | struct vattr *vap; | |
a2907882 | 835 | { |
9238aa59 | 836 | register struct nfsv2_sattr *sp; |
26cb2431 | 837 | register u_long *tl; |
13576453 KM |
838 | register caddr_t cp; |
839 | register long t1, t2; | |
840 | caddr_t bpos, dpos, cp2; | |
13576453 KM |
841 | int error = 0; |
842 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
843 | |
844 | nfsstats.rpccnt[NFSPROC_CREATE]++; | |
cfef4373 JH |
845 | nfsm_reqhead(dvp, NFSPROC_CREATE, |
846 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(cnp->cn_namelen)+NFSX_SATTR); | |
847 | nfsm_fhtom(dvp); | |
848 | nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN); | |
9238aa59 | 849 | nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR); |
1c89915d | 850 | sp->sa_mode = vtonfs_mode(vap->va_type, vap->va_mode); |
cfef4373 JH |
851 | sp->sa_uid = txdr_unsigned(cnp->cn_cred->cr_uid); |
852 | sp->sa_gid = txdr_unsigned(cnp->cn_cred->cr_gid); | |
9238aa59 | 853 | sp->sa_size = txdr_unsigned(0); |
a2907882 | 854 | /* or should these be VNOVAL ?? */ |
9238aa59 RM |
855 | txdr_time(&vap->va_atime, &sp->sa_atime); |
856 | txdr_time(&vap->va_mtime, &sp->sa_mtime); | |
cfef4373 JH |
857 | nfsm_request(dvp, NFSPROC_CREATE, cnp->cn_proc, cnp->cn_cred); |
858 | nfsm_mtofh(dvp, *vpp); | |
a2907882 | 859 | nfsm_reqdone; |
cfef4373 JH |
860 | FREE(cnp->cn_pnbuf, M_NAMEI); |
861 | VTONFS(dvp)->n_flag |= NMODIFIED; | |
862 | vrele(dvp); | |
a2907882 KM |
863 | return (error); |
864 | } | |
865 | ||
866 | /* | |
867 | * nfs file remove call | |
f0f1cbaa KM |
868 | * To try and make nfs semantics closer to ufs semantics, a file that has |
869 | * other processes using the vnode is renamed instead of removed and then | |
ffe6f482 | 870 | * removed later on the last close. |
f0f1cbaa | 871 | * - If v_usecount > 1 |
ffe6f482 KM |
872 | * If a rename is not already in the works |
873 | * call nfs_sillyrename() to set it up | |
874 | * else | |
875 | * do the remove rpc | |
a2907882 | 876 | */ |
cfef4373 | 877 | int |
c5b4f497 | 878 | nfs_remove(dvp, vp, cnp) |
cfef4373 JH |
879 | struct vnode *dvp, *vp; |
880 | struct componentname *cnp; | |
a2907882 | 881 | { |
cfef4373 | 882 | register struct nfsnode *np = VTONFS(vp); |
26cb2431 | 883 | register u_long *tl; |
13576453 | 884 | register caddr_t cp; |
2c5b44a2 | 885 | register long t2; |
13576453 | 886 | caddr_t bpos, dpos; |
13576453 KM |
887 | int error = 0; |
888 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 | 889 | |
1f7e9641 | 890 | if (vp->v_usecount > 1) { |
ffe6f482 | 891 | if (!np->n_sillyrename) |
c5b4f497 | 892 | error = nfs_sillyrename(dvp, vp, cnp); |
ffe6f482 | 893 | } else { |
2c5b44a2 KM |
894 | /* |
895 | * Purge the name cache so that the chance of a lookup for | |
896 | * the name succeeding while the remove is in progress is | |
897 | * minimized. Without node locking it can still happen, such | |
898 | * that an I/O op returns ESTALE, but since you get this if | |
899 | * another host removes the file.. | |
900 | */ | |
901 | cache_purge(vp); | |
902 | /* | |
903 | * Throw away biocache buffers. Mainly to avoid | |
904 | * unnecessary delayed writes. | |
905 | */ | |
906 | vinvalbuf(vp, FALSE); | |
907 | /* Do the rpc */ | |
a2907882 | 908 | nfsstats.rpccnt[NFSPROC_REMOVE]++; |
cfef4373 JH |
909 | nfsm_reqhead(dvp, NFSPROC_REMOVE, |
910 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(cnp->cn_namelen)); | |
911 | nfsm_fhtom(dvp); | |
912 | nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN); | |
913 | nfsm_request(dvp, NFSPROC_REMOVE, cnp->cn_proc, cnp->cn_cred); | |
a2907882 | 914 | nfsm_reqdone; |
cfef4373 JH |
915 | FREE(cnp->cn_pnbuf, M_NAMEI); |
916 | VTONFS(dvp)->n_flag |= NMODIFIED; | |
e8540f59 KM |
917 | /* |
918 | * Kludge City: If the first reply to the remove rpc is lost.. | |
919 | * the reply to the retransmitted request will be ENOENT | |
920 | * since the file was in fact removed | |
921 | * Therefore, we cheat and return success. | |
922 | */ | |
923 | if (error == ENOENT) | |
924 | error = 0; | |
a2907882 | 925 | } |
86dea069 | 926 | np->n_attrstamp = 0; |
cfef4373 | 927 | vrele(dvp); |
2c5b44a2 | 928 | vrele(vp); |
a2907882 KM |
929 | return (error); |
930 | } | |
931 | ||
932 | /* | |
933 | * nfs file remove rpc called from nfs_inactive | |
934 | */ | |
cfef4373 | 935 | int |
2c5b44a2 | 936 | nfs_removeit(sp, procp) |
a9b4ecb2 | 937 | register struct sillyrename *sp; |
2c5b44a2 | 938 | struct proc *procp; |
a2907882 | 939 | { |
26cb2431 | 940 | register u_long *tl; |
13576453 | 941 | register caddr_t cp; |
2c5b44a2 | 942 | register long t2; |
13576453 | 943 | caddr_t bpos, dpos; |
13576453 KM |
944 | int error = 0; |
945 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
946 | |
947 | nfsstats.rpccnt[NFSPROC_REMOVE]++; | |
2c5b44a2 | 948 | nfsm_reqhead(sp->s_dvp, NFSPROC_REMOVE, |
a9b4ecb2 KM |
949 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(sp->s_namlen)); |
950 | nfsm_fhtom(sp->s_dvp); | |
951 | nfsm_strtom(sp->s_name, sp->s_namlen, NFS_MAXNAMLEN); | |
2c5b44a2 | 952 | nfsm_request(sp->s_dvp, NFSPROC_REMOVE, procp, sp->s_cred); |
a2907882 | 953 | nfsm_reqdone; |
a9b4ecb2 | 954 | VTONFS(sp->s_dvp)->n_flag |= NMODIFIED; |
a2907882 KM |
955 | return (error); |
956 | } | |
957 | ||
958 | /* | |
959 | * nfs file rename call | |
960 | */ | |
cfef4373 JH |
961 | int |
962 | nfs_rename(fdvp, fvp, fcnp, | |
c5b4f497 | 963 | tdvp, tvp, tcnp) |
cfef4373 JH |
964 | struct vnode *fdvp, *fvp; |
965 | struct componentname *fcnp; | |
966 | struct vnode *tdvp, *tvp; | |
967 | struct componentname *tcnp; | |
a2907882 | 968 | { |
26cb2431 | 969 | register u_long *tl; |
13576453 | 970 | register caddr_t cp; |
2c5b44a2 | 971 | register long t2; |
13576453 | 972 | caddr_t bpos, dpos; |
13576453 KM |
973 | int error = 0; |
974 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
975 | |
976 | nfsstats.rpccnt[NFSPROC_RENAME]++; | |
cfef4373 JH |
977 | nfsm_reqhead(fdvp, NFSPROC_RENAME, |
978 | (NFSX_FH+NFSX_UNSIGNED)*2+nfsm_rndup(fcnp->cn_namelen)+ | |
979 | nfsm_rndup(fcnp->cn_namelen)); /* or fcnp->cn_cred?*/ | |
980 | nfsm_fhtom(fdvp); | |
981 | nfsm_strtom(fcnp->cn_nameptr, fcnp->cn_namelen, NFS_MAXNAMLEN); | |
982 | nfsm_fhtom(tdvp); | |
983 | nfsm_strtom(tcnp->cn_nameptr, tcnp->cn_namelen, NFS_MAXNAMLEN); | |
984 | nfsm_request(fdvp, NFSPROC_RENAME, tcnp->cn_proc, tcnp->cn_cred); | |
a2907882 | 985 | nfsm_reqdone; |
cfef4373 JH |
986 | VTONFS(fdvp)->n_flag |= NMODIFIED; |
987 | VTONFS(tdvp)->n_flag |= NMODIFIED; | |
988 | if (fvp->v_type == VDIR) { | |
989 | if (tvp != NULL && tvp->v_type == VDIR) | |
990 | cache_purge(tdvp); | |
991 | cache_purge(fdvp); | |
a2907882 | 992 | } |
cfef4373 JH |
993 | if (tdvp == tvp) |
994 | vrele(tdvp); | |
639383fa | 995 | else |
cfef4373 JH |
996 | vput(tdvp); |
997 | if (tvp) | |
998 | vput(tvp); | |
999 | vrele(fdvp); | |
1000 | vrele(fvp); | |
f5f6c13e KM |
1001 | /* |
1002 | * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry. | |
1003 | */ | |
1004 | if (error == ENOENT) | |
1005 | error = 0; | |
a2907882 KM |
1006 | return (error); |
1007 | } | |
1008 | ||
1009 | /* | |
f0f1cbaa | 1010 | * nfs file rename rpc called from nfs_remove() above |
a2907882 | 1011 | */ |
cfef4373 JH |
1012 | int |
1013 | nfs_renameit(sdvp, scnp, sp) | |
1014 | struct vnode *sdvp; | |
1015 | struct componentname *scnp; | |
a9b4ecb2 | 1016 | register struct sillyrename *sp; |
a2907882 | 1017 | { |
26cb2431 | 1018 | register u_long *tl; |
13576453 | 1019 | register caddr_t cp; |
2c5b44a2 | 1020 | register long t2; |
13576453 | 1021 | caddr_t bpos, dpos; |
13576453 KM |
1022 | int error = 0; |
1023 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
1024 | |
1025 | nfsstats.rpccnt[NFSPROC_RENAME]++; | |
cfef4373 JH |
1026 | nfsm_reqhead(sdvp, NFSPROC_RENAME, |
1027 | (NFSX_FH+NFSX_UNSIGNED)*2+nfsm_rndup(scnp->cn_namelen)+ | |
2c5b44a2 | 1028 | nfsm_rndup(sp->s_namlen)); |
cfef4373 JH |
1029 | nfsm_fhtom(sdvp); |
1030 | nfsm_strtom(scnp->cn_nameptr, scnp->cn_namelen, NFS_MAXNAMLEN); | |
1031 | nfsm_fhtom(sdvp); | |
a9b4ecb2 | 1032 | nfsm_strtom(sp->s_name, sp->s_namlen, NFS_MAXNAMLEN); |
cfef4373 | 1033 | nfsm_request(sdvp, NFSPROC_RENAME, scnp->cn_proc, scnp->cn_cred); |
a2907882 | 1034 | nfsm_reqdone; |
cfef4373 JH |
1035 | FREE(scnp->cn_pnbuf, M_NAMEI); |
1036 | VTONFS(sdvp)->n_flag |= NMODIFIED; | |
a2907882 KM |
1037 | return (error); |
1038 | } | |
1039 | ||
1040 | /* | |
1041 | * nfs hard link create call | |
1042 | */ | |
cfef4373 | 1043 | int |
c5b4f497 | 1044 | nfs_link(vp, tdvp, cnp) |
cfef4373 JH |
1045 | register struct vnode *vp; /* source vnode */ |
1046 | struct vnode *tdvp; | |
1047 | struct componentname *cnp; | |
a2907882 | 1048 | { |
26cb2431 | 1049 | register u_long *tl; |
13576453 | 1050 | register caddr_t cp; |
2c5b44a2 | 1051 | register long t2; |
13576453 | 1052 | caddr_t bpos, dpos; |
13576453 KM |
1053 | int error = 0; |
1054 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
1055 | |
1056 | nfsstats.rpccnt[NFSPROC_LINK]++; | |
2c5b44a2 | 1057 | nfsm_reqhead(vp, NFSPROC_LINK, |
cfef4373 | 1058 | NFSX_FH*2+NFSX_UNSIGNED+nfsm_rndup(cnp->cn_namelen)); |
a2907882 | 1059 | nfsm_fhtom(vp); |
cfef4373 JH |
1060 | nfsm_fhtom(tdvp); |
1061 | nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN); | |
1062 | nfsm_request(vp, NFSPROC_LINK, cnp->cn_proc, cnp->cn_cred); | |
a2907882 | 1063 | nfsm_reqdone; |
cfef4373 | 1064 | FREE(cnp->cn_pnbuf, M_NAMEI); |
86dea069 | 1065 | VTONFS(vp)->n_attrstamp = 0; |
cfef4373 JH |
1066 | VTONFS(tdvp)->n_flag |= NMODIFIED; |
1067 | vrele(tdvp); | |
f5f6c13e KM |
1068 | /* |
1069 | * Kludge: Map EEXIST => 0 assuming that it is a reply to a retry. | |
1070 | */ | |
1071 | if (error == EEXIST) | |
1072 | error = 0; | |
a2907882 KM |
1073 | return (error); |
1074 | } | |
1075 | ||
1076 | /* | |
1077 | * nfs symbolic link create call | |
1078 | */ | |
cfef4373 JH |
1079 | /* start here */ |
1080 | int | |
c5b4f497 | 1081 | nfs_symlink(dvp, vpp, cnp, vap, nm) |
cfef4373 JH |
1082 | struct vnode *dvp; |
1083 | struct vnode **vpp; | |
1084 | struct componentname *cnp; | |
a2907882 | 1085 | struct vattr *vap; |
2c5b44a2 | 1086 | char *nm; |
a2907882 | 1087 | { |
9238aa59 | 1088 | register struct nfsv2_sattr *sp; |
26cb2431 | 1089 | register u_long *tl; |
13576453 | 1090 | register caddr_t cp; |
2c5b44a2 | 1091 | register long t2; |
13576453 | 1092 | caddr_t bpos, dpos; |
2c5b44a2 | 1093 | int slen, error = 0; |
13576453 | 1094 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; |
a2907882 KM |
1095 | |
1096 | nfsstats.rpccnt[NFSPROC_SYMLINK]++; | |
2c5b44a2 | 1097 | slen = strlen(nm); |
cfef4373 JH |
1098 | nfsm_reqhead(dvp, NFSPROC_SYMLINK, |
1099 | NFSX_FH+2*NFSX_UNSIGNED+nfsm_rndup(cnp->cn_namelen)+nfsm_rndup(slen)+NFSX_SATTR); | |
1100 | nfsm_fhtom(dvp); | |
1101 | nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN); | |
2c5b44a2 | 1102 | nfsm_strtom(nm, slen, NFS_MAXPATHLEN); |
9238aa59 RM |
1103 | nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR); |
1104 | sp->sa_mode = vtonfs_mode(VLNK, vap->va_mode); | |
cfef4373 JH |
1105 | sp->sa_uid = txdr_unsigned(cnp->cn_cred->cr_uid); |
1106 | sp->sa_gid = txdr_unsigned(cnp->cn_cred->cr_gid); | |
9238aa59 | 1107 | sp->sa_size = txdr_unsigned(VNOVAL); |
f5f6c13e | 1108 | txdr_time(&vap->va_atime, &sp->sa_atime); /* or VNOVAL ?? */ |
9238aa59 | 1109 | txdr_time(&vap->va_mtime, &sp->sa_mtime); /* or VNOVAL ?? */ |
cfef4373 | 1110 | nfsm_request(dvp, NFSPROC_SYMLINK, cnp->cn_proc, cnp->cn_cred); |
a2907882 | 1111 | nfsm_reqdone; |
cfef4373 JH |
1112 | FREE(cnp->cn_pnbuf, M_NAMEI); |
1113 | VTONFS(dvp)->n_flag |= NMODIFIED; | |
1114 | vrele(dvp); | |
f5f6c13e KM |
1115 | /* |
1116 | * Kludge: Map EEXIST => 0 assuming that it is a reply to a retry. | |
1117 | */ | |
1118 | if (error == EEXIST) | |
1119 | error = 0; | |
a2907882 KM |
1120 | return (error); |
1121 | } | |
1122 | ||
1123 | /* | |
1124 | * nfs make dir call | |
1125 | */ | |
cfef4373 | 1126 | int |
c5b4f497 | 1127 | nfs_mkdir(dvp, vpp, cnp, vap) |
cfef4373 JH |
1128 | struct vnode *dvp; |
1129 | struct vnode **vpp; | |
1130 | struct componentname *cnp; | |
a2907882 KM |
1131 | struct vattr *vap; |
1132 | { | |
9238aa59 | 1133 | register struct nfsv2_sattr *sp; |
26cb2431 | 1134 | register u_long *tl; |
13576453 KM |
1135 | register caddr_t cp; |
1136 | register long t1, t2; | |
f0f1cbaa | 1137 | register int len; |
13576453 | 1138 | caddr_t bpos, dpos, cp2; |
f0f1cbaa | 1139 | int error = 0, firsttry = 1; |
13576453 | 1140 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; |
a2907882 | 1141 | |
cfef4373 | 1142 | len = cnp->cn_namelen; |
a2907882 | 1143 | nfsstats.rpccnt[NFSPROC_MKDIR]++; |
cfef4373 | 1144 | nfsm_reqhead(dvp, NFSPROC_MKDIR, |
f0f1cbaa | 1145 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len)+NFSX_SATTR); |
cfef4373 JH |
1146 | nfsm_fhtom(dvp); |
1147 | nfsm_strtom(cnp->cn_nameptr, len, NFS_MAXNAMLEN); | |
9238aa59 RM |
1148 | nfsm_build(sp, struct nfsv2_sattr *, NFSX_SATTR); |
1149 | sp->sa_mode = vtonfs_mode(VDIR, vap->va_mode); | |
cfef4373 JH |
1150 | sp->sa_uid = txdr_unsigned(cnp->cn_cred->cr_uid); |
1151 | sp->sa_gid = txdr_unsigned(cnp->cn_cred->cr_gid); | |
9238aa59 | 1152 | sp->sa_size = txdr_unsigned(VNOVAL); |
f5f6c13e | 1153 | txdr_time(&vap->va_atime, &sp->sa_atime); /* or VNOVAL ?? */ |
9238aa59 | 1154 | txdr_time(&vap->va_mtime, &sp->sa_mtime); /* or VNOVAL ?? */ |
cfef4373 JH |
1155 | nfsm_request(dvp, NFSPROC_MKDIR, cnp->cn_proc, cnp->cn_cred); |
1156 | nfsm_mtofh(dvp, *vpp); | |
a2907882 | 1157 | nfsm_reqdone; |
cfef4373 | 1158 | VTONFS(dvp)->n_flag |= NMODIFIED; |
f5f6c13e | 1159 | /* |
f0f1cbaa KM |
1160 | * Kludge: Map EEXIST => 0 assuming that you have a reply to a retry |
1161 | * if we can succeed in looking up the directory. | |
1162 | * "firsttry" is necessary since the macros may "goto nfsmout" which | |
1163 | * is above the if on errors. (Ugh) | |
f5f6c13e | 1164 | */ |
f0f1cbaa KM |
1165 | if (error == EEXIST && firsttry) { |
1166 | firsttry = 0; | |
f5f6c13e | 1167 | error = 0; |
f0f1cbaa | 1168 | nfsstats.rpccnt[NFSPROC_LOOKUP]++; |
cfef4373 JH |
1169 | *vpp = NULL; |
1170 | nfsm_reqhead(dvp, NFSPROC_LOOKUP, | |
f0f1cbaa | 1171 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len)); |
cfef4373 JH |
1172 | nfsm_fhtom(dvp); |
1173 | nfsm_strtom(cnp->cn_nameptr, len, NFS_MAXNAMLEN); | |
1174 | nfsm_request(dvp, NFSPROC_LOOKUP, cnp->cn_proc, cnp->cn_cred); | |
1175 | nfsm_mtofh(dvp, *vpp); | |
1176 | if ((*vpp)->v_type != VDIR) { | |
1177 | vput(*vpp); | |
f0f1cbaa KM |
1178 | error = EEXIST; |
1179 | } | |
1180 | m_freem(mrep); | |
1181 | } | |
cfef4373 JH |
1182 | FREE(cnp->cn_pnbuf, M_NAMEI); |
1183 | vrele(dvp); | |
a2907882 KM |
1184 | return (error); |
1185 | } | |
1186 | ||
1187 | /* | |
1188 | * nfs remove directory call | |
1189 | */ | |
cfef4373 | 1190 | int |
c5b4f497 | 1191 | nfs_rmdir(dvp, vp, cnp) |
cfef4373 JH |
1192 | struct vnode *dvp, *vp; |
1193 | struct componentname *cnp; | |
a2907882 | 1194 | { |
26cb2431 | 1195 | register u_long *tl; |
13576453 | 1196 | register caddr_t cp; |
2c5b44a2 | 1197 | register long t2; |
13576453 | 1198 | caddr_t bpos, dpos; |
13576453 KM |
1199 | int error = 0; |
1200 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 | 1201 | |
cfef4373 JH |
1202 | if (dvp == vp) { |
1203 | vrele(dvp); | |
1204 | vrele(dvp); | |
1205 | FREE(cnp->cn_pnbuf, M_NAMEI); | |
a2907882 KM |
1206 | return (EINVAL); |
1207 | } | |
a2907882 | 1208 | nfsstats.rpccnt[NFSPROC_RMDIR]++; |
cfef4373 JH |
1209 | nfsm_reqhead(dvp, NFSPROC_RMDIR, |
1210 | NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(cnp->cn_namelen)); | |
1211 | nfsm_fhtom(dvp); | |
1212 | nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN); | |
1213 | nfsm_request(dvp, NFSPROC_RMDIR, cnp->cn_proc, cnp->cn_cred); | |
a2907882 | 1214 | nfsm_reqdone; |
cfef4373 JH |
1215 | FREE(cnp->cn_pnbuf, M_NAMEI); |
1216 | VTONFS(dvp)->n_flag |= NMODIFIED; | |
1217 | cache_purge(dvp); | |
1218 | cache_purge(vp); | |
1219 | vrele(vp); | |
1220 | vrele(dvp); | |
f5f6c13e KM |
1221 | /* |
1222 | * Kludge: Map ENOENT => 0 assuming that you have a reply to a retry. | |
1223 | */ | |
1224 | if (error == ENOENT) | |
1225 | error = 0; | |
a2907882 KM |
1226 | return (error); |
1227 | } | |
1228 | ||
1229 | /* | |
1230 | * nfs readdir call | |
1231 | * Although cookie is defined as opaque, I translate it to/from net byte | |
1232 | * order so that it looks more sensible. This appears consistent with the | |
1233 | * Ultrix implementation of NFS. | |
1234 | */ | |
cfef4373 | 1235 | int |
e49b1a6c | 1236 | nfs_readdir(vp, uiop, cred, eofflagp) |
13576453 | 1237 | register struct vnode *vp; |
a2907882 | 1238 | struct uio *uiop; |
a2907882 | 1239 | struct ucred *cred; |
e49b1a6c | 1240 | int *eofflagp; |
f0f1cbaa KM |
1241 | { |
1242 | register struct nfsnode *np = VTONFS(vp); | |
1243 | int tresid, error; | |
1244 | struct vattr vattr; | |
1245 | ||
1246 | if (vp->v_type != VDIR) | |
1247 | return (EPERM); | |
1248 | /* | |
1249 | * First, check for hit on the EOF offset cache | |
1250 | */ | |
1251 | if (uiop->uio_offset != 0 && uiop->uio_offset == np->n_direofoffset && | |
2c5b44a2 KM |
1252 | (np->n_flag & NMODIFIED) == 0) { |
1253 | if (VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NQNFS) { | |
1254 | if (NQNFS_CKCACHABLE(vp, NQL_READ)) { | |
1255 | *eofflagp = 1; | |
1256 | nfsstats.direofcache_hits++; | |
1257 | return (0); | |
1258 | } | |
1259 | } else if (nfs_getattr(vp, &vattr, cred, uiop->uio_procp) == 0 && | |
1260 | np->n_mtime == vattr.va_mtime.tv_sec) { | |
1261 | *eofflagp = 1; | |
1262 | nfsstats.direofcache_hits++; | |
1263 | return (0); | |
1264 | } | |
f0f1cbaa KM |
1265 | } |
1266 | ||
1267 | /* | |
1268 | * Call nfs_bioread() to do the real work. | |
1269 | */ | |
1270 | tresid = uiop->uio_resid; | |
1271 | error = nfs_bioread(vp, uiop, 0, cred); | |
1272 | ||
1273 | if (!error && uiop->uio_resid == tresid) { | |
1274 | *eofflagp = 1; | |
1275 | nfsstats.direofcache_misses++; | |
1276 | } else | |
1277 | *eofflagp = 0; | |
1278 | return (error); | |
1279 | } | |
1280 | ||
1281 | /* | |
1282 | * Readdir rpc call. | |
1283 | * Called from below the buffer cache by nfs_doio(). | |
1284 | */ | |
cfef4373 | 1285 | int |
26cb2431 | 1286 | nfs_readdirrpc(vp, uiop, cred) |
f0f1cbaa KM |
1287 | register struct vnode *vp; |
1288 | struct uio *uiop; | |
1289 | struct ucred *cred; | |
a2907882 KM |
1290 | { |
1291 | register long len; | |
1292 | register struct direct *dp; | |
26cb2431 | 1293 | register u_long *tl; |
13576453 KM |
1294 | register caddr_t cp; |
1295 | register long t1; | |
f0f1cbaa | 1296 | long tlen, lastlen; |
13576453 | 1297 | caddr_t bpos, dpos, cp2; |
13576453 KM |
1298 | int error = 0; |
1299 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
1300 | struct mbuf *md2; |
1301 | caddr_t dpos2; | |
1302 | int siz; | |
e49b1a6c | 1303 | int more_dirs = 1; |
a2907882 KM |
1304 | off_t off, savoff; |
1305 | struct direct *savdp; | |
e49b1a6c KM |
1306 | struct nfsmount *nmp; |
1307 | struct nfsnode *np = VTONFS(vp); | |
1308 | long tresid; | |
a2907882 | 1309 | |
54fb9dc2 | 1310 | nmp = VFSTONFS(vp->v_mount); |
e49b1a6c | 1311 | tresid = uiop->uio_resid; |
a2907882 | 1312 | /* |
e49b1a6c | 1313 | * Loop around doing readdir rpc's of size uio_resid or nm_rsize, |
26cb2431 | 1314 | * whichever is smaller, truncated to a multiple of NFS_DIRBLKSIZ. |
f0f1cbaa | 1315 | * The stopping criteria is EOF or buffer full. |
a2907882 | 1316 | */ |
26cb2431 | 1317 | while (more_dirs && uiop->uio_resid >= NFS_DIRBLKSIZ) { |
e49b1a6c | 1318 | nfsstats.rpccnt[NFSPROC_READDIR]++; |
2c5b44a2 KM |
1319 | nfsm_reqhead(vp, NFSPROC_READDIR, |
1320 | NFSX_FH+2*NFSX_UNSIGNED); | |
e49b1a6c | 1321 | nfsm_fhtom(vp); |
26cb2431 KM |
1322 | nfsm_build(tl, u_long *, 2*NFSX_UNSIGNED); |
1323 | *tl++ = txdr_unsigned(uiop->uio_offset); | |
1324 | *tl = txdr_unsigned(((uiop->uio_resid > nmp->nm_rsize) ? | |
1325 | nmp->nm_rsize : uiop->uio_resid) & ~(NFS_DIRBLKSIZ-1)); | |
2c5b44a2 | 1326 | nfsm_request(vp, NFSPROC_READDIR, uiop->uio_procp, cred); |
e49b1a6c | 1327 | siz = 0; |
2c5b44a2 | 1328 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); |
26cb2431 | 1329 | more_dirs = fxdr_unsigned(int, *tl); |
e49b1a6c KM |
1330 | |
1331 | /* Save the position so that we can do nfsm_mtouio() later */ | |
1332 | dpos2 = dpos; | |
1333 | md2 = md; | |
1334 | ||
1335 | /* loop thru the dir entries, doctoring them to 4bsd form */ | |
f0f1cbaa | 1336 | off = uiop->uio_offset; |
7c15c5df KM |
1337 | #ifdef lint |
1338 | dp = (struct direct *)0; | |
1339 | #endif /* lint */ | |
e49b1a6c KM |
1340 | while (more_dirs && siz < uiop->uio_resid) { |
1341 | savoff = off; /* Hold onto offset and dp */ | |
1342 | savdp = dp; | |
2c5b44a2 | 1343 | nfsm_dissecton(tl, u_long *, 2*NFSX_UNSIGNED); |
26cb2431 KM |
1344 | dp = (struct direct *)tl; |
1345 | dp->d_ino = fxdr_unsigned(u_long, *tl++); | |
1346 | len = fxdr_unsigned(int, *tl); | |
e49b1a6c KM |
1347 | if (len <= 0 || len > NFS_MAXNAMLEN) { |
1348 | error = EBADRPC; | |
1349 | m_freem(mrep); | |
1350 | goto nfsmout; | |
1351 | } | |
1352 | dp->d_namlen = (u_short)len; | |
1353 | nfsm_adv(len); /* Point past name */ | |
1354 | tlen = nfsm_rndup(len); | |
1355 | /* | |
1356 | * This should not be necessary, but some servers have | |
1357 | * broken XDR such that these bytes are not null filled. | |
1358 | */ | |
1359 | if (tlen != len) { | |
1360 | *dpos = '\0'; /* Null-terminate */ | |
1361 | nfsm_adv(tlen - len); | |
1362 | len = tlen; | |
1363 | } | |
2c5b44a2 | 1364 | nfsm_dissecton(tl, u_long *, 2*NFSX_UNSIGNED); |
26cb2431 KM |
1365 | off = fxdr_unsigned(off_t, *tl); |
1366 | *tl++ = 0; /* Ensures null termination of name */ | |
1367 | more_dirs = fxdr_unsigned(int, *tl); | |
e49b1a6c KM |
1368 | dp->d_reclen = len+4*NFSX_UNSIGNED; |
1369 | siz += dp->d_reclen; | |
1370 | } | |
1371 | /* | |
1372 | * If at end of rpc data, get the eof boolean | |
1373 | */ | |
1374 | if (!more_dirs) { | |
2c5b44a2 | 1375 | nfsm_dissecton(tl, u_long *, NFSX_UNSIGNED); |
26cb2431 | 1376 | more_dirs = (fxdr_unsigned(int, *tl) == 0); |
e49b1a6c KM |
1377 | |
1378 | /* | |
1379 | * If at EOF, cache directory offset | |
1380 | */ | |
f0f1cbaa | 1381 | if (!more_dirs) |
e49b1a6c | 1382 | np->n_direofoffset = off; |
e49b1a6c KM |
1383 | } |
1384 | /* | |
1385 | * If there is too much to fit in the data buffer, use savoff and | |
1386 | * savdp to trim off the last record. | |
1387 | * --> we are not at eof | |
1388 | */ | |
1389 | if (siz > uiop->uio_resid) { | |
1390 | off = savoff; | |
1391 | siz -= dp->d_reclen; | |
1392 | dp = savdp; | |
1393 | more_dirs = 0; /* Paranoia */ | |
1394 | } | |
1395 | if (siz > 0) { | |
f0f1cbaa | 1396 | lastlen = dp->d_reclen; |
e49b1a6c KM |
1397 | md = md2; |
1398 | dpos = dpos2; | |
1399 | nfsm_mtouio(uiop, siz); | |
1400 | uiop->uio_offset = off; | |
1401 | } else | |
1402 | more_dirs = 0; /* Ugh, never happens, but in case.. */ | |
1403 | m_freem(mrep); | |
a2907882 | 1404 | } |
f0f1cbaa | 1405 | /* |
26cb2431 | 1406 | * Fill last record, iff any, out to a multiple of NFS_DIRBLKSIZ |
f0f1cbaa KM |
1407 | * by increasing d_reclen for the last record. |
1408 | */ | |
1409 | if (uiop->uio_resid < tresid) { | |
26cb2431 | 1410 | len = uiop->uio_resid & (NFS_DIRBLKSIZ - 1); |
f0f1cbaa KM |
1411 | if (len > 0) { |
1412 | dp = (struct direct *) | |
1413 | (uiop->uio_iov->iov_base - lastlen); | |
1414 | dp->d_reclen += len; | |
1415 | uiop->uio_iov->iov_base += len; | |
1416 | uiop->uio_iov->iov_len -= len; | |
1417 | uiop->uio_resid -= len; | |
1418 | } | |
c79a85cd | 1419 | } |
f0f1cbaa | 1420 | nfsmout: |
a2907882 KM |
1421 | return (error); |
1422 | } | |
1423 | ||
2c5b44a2 KM |
1424 | /* |
1425 | * Nqnfs readdir_and_lookup RPC. Used in place of nfs_readdirrpc() when | |
1426 | * the "rdirlook" mount option is specified. | |
1427 | */ | |
cfef4373 | 1428 | int |
2c5b44a2 KM |
1429 | nfs_readdirlookrpc(vp, uiop, cred) |
1430 | struct vnode *vp; | |
1431 | register struct uio *uiop; | |
1432 | struct ucred *cred; | |
1433 | { | |
1434 | register int len; | |
1435 | register struct direct *dp; | |
1436 | register u_long *tl; | |
1437 | register caddr_t cp; | |
1438 | register long t1; | |
1439 | caddr_t bpos, dpos, cp2; | |
1440 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
1441 | struct nameidata nami, *ndp = &nami; | |
c5b4f497 | 1442 | struct componentname *cnp = &ndp->ni_cnd; |
2c5b44a2 KM |
1443 | off_t off, endoff; |
1444 | time_t reqtime, ltime; | |
1445 | struct nfsmount *nmp; | |
1446 | struct nfsnode *np, *tp; | |
1447 | struct vnode *newvp; | |
1448 | nfsv2fh_t *fhp; | |
1449 | u_long fileno; | |
1450 | u_quad_t frev; | |
1451 | int error = 0, tlen, more_dirs = 1, tresid, doit, bigenough, i; | |
1452 | int cachable; | |
1453 | ||
1454 | if (uiop->uio_iovcnt != 1) | |
1455 | panic("nfs rdirlook"); | |
1456 | nmp = VFSTONFS(vp->v_mount); | |
1457 | tresid = uiop->uio_resid; | |
1458 | ndp->ni_dvp = vp; | |
1459 | newvp = NULLVP; | |
1460 | /* | |
1461 | * Loop around doing readdir rpc's of size uio_resid or nm_rsize, | |
1462 | * whichever is smaller, truncated to a multiple of NFS_DIRBLKSIZ. | |
1463 | * The stopping criteria is EOF or buffer full. | |
1464 | */ | |
1465 | while (more_dirs && uiop->uio_resid >= NFS_DIRBLKSIZ) { | |
1466 | nfsstats.rpccnt[NQNFSPROC_READDIRLOOK]++; | |
1467 | nfsm_reqhead(vp, NQNFSPROC_READDIRLOOK, | |
1468 | NFSX_FH+3*NFSX_UNSIGNED); | |
1469 | nfsm_fhtom(vp); | |
1470 | nfsm_build(tl, u_long *, 3*NFSX_UNSIGNED); | |
1471 | *tl++ = txdr_unsigned(uiop->uio_offset); | |
1472 | *tl++ = txdr_unsigned(((uiop->uio_resid > nmp->nm_rsize) ? | |
1473 | nmp->nm_rsize : uiop->uio_resid) & ~(NFS_DIRBLKSIZ-1)); | |
1474 | *tl = txdr_unsigned(nmp->nm_leaseterm); | |
1475 | reqtime = time.tv_sec; | |
1476 | nfsm_request(vp, NQNFSPROC_READDIRLOOK, uiop->uio_procp, cred); | |
1477 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); | |
1478 | more_dirs = fxdr_unsigned(int, *tl); | |
1479 | ||
1480 | /* loop thru the dir entries, doctoring them to 4bsd form */ | |
1481 | off = uiop->uio_offset; | |
1482 | bigenough = 1; | |
1483 | while (more_dirs && bigenough) { | |
1484 | doit = 1; | |
1485 | nfsm_dissect(tl, u_long *, 4*NFSX_UNSIGNED); | |
1486 | cachable = fxdr_unsigned(int, *tl++); | |
1487 | ltime = reqtime + fxdr_unsigned(int, *tl++); | |
1488 | fxdr_hyper(tl, &frev); | |
1489 | nfsm_dissect(fhp, nfsv2fh_t *, NFSX_FH); | |
1490 | if (!bcmp(VTONFS(vp)->n_fh.fh_bytes, (caddr_t)fhp, NFSX_FH)) { | |
1491 | VREF(vp); | |
1492 | newvp = vp; | |
1493 | np = VTONFS(vp); | |
1494 | } else { | |
1495 | if (error = nfs_nget(vp->v_mount, fhp, &np)) | |
1496 | doit = 0; | |
1497 | newvp = NFSTOV(np); | |
1498 | } | |
1499 | if (error = nfs_loadattrcache(&newvp, &md, &dpos, | |
1500 | (struct vattr *)0)) | |
1501 | doit = 0; | |
1502 | nfsm_dissect(tl, u_long *, 2*NFSX_UNSIGNED); | |
1503 | fileno = fxdr_unsigned(u_long, *tl++); | |
1504 | len = fxdr_unsigned(int, *tl); | |
1505 | if (len <= 0 || len > NFS_MAXNAMLEN) { | |
1506 | error = EBADRPC; | |
1507 | m_freem(mrep); | |
1508 | goto nfsmout; | |
1509 | } | |
1510 | tlen = (len + 4) & ~0x3; | |
1511 | if ((tlen + DIRHDSIZ) > uiop->uio_resid) | |
1512 | bigenough = 0; | |
1513 | if (bigenough && doit) { | |
1514 | dp = (struct direct *)uiop->uio_iov->iov_base; | |
1515 | dp->d_ino = fileno; | |
1516 | dp->d_namlen = len; | |
1517 | dp->d_reclen = tlen + DIRHDSIZ; | |
1518 | uiop->uio_resid -= DIRHDSIZ; | |
1519 | uiop->uio_iov->iov_base += DIRHDSIZ; | |
1520 | uiop->uio_iov->iov_len -= DIRHDSIZ; | |
c5b4f497 JH |
1521 | cnp->cn_nameptr = uiop->uio_iov->iov_base; |
1522 | cnp->cn_namelen = len; | |
2c5b44a2 KM |
1523 | ndp->ni_vp = newvp; |
1524 | nfsm_mtouio(uiop, len); | |
1525 | cp = uiop->uio_iov->iov_base; | |
1526 | tlen -= len; | |
1527 | for (i = 0; i < tlen; i++) | |
1528 | *cp++ = '\0'; | |
1529 | uiop->uio_iov->iov_base += tlen; | |
1530 | uiop->uio_iov->iov_len -= tlen; | |
1531 | uiop->uio_resid -= tlen; | |
c5b4f497 JH |
1532 | cnp->cn_hash = 0; |
1533 | for (cp = cnp->cn_nameptr, i = 1; i <= len; i++, cp++) | |
1534 | cnp->cn_hash += (unsigned char)*cp * i; | |
2c5b44a2 KM |
1535 | if (ltime > time.tv_sec) { |
1536 | if (np->n_tnext) { | |
1537 | if (np->n_tnext == (struct nfsnode *)nmp) | |
1538 | nmp->nm_tprev = np->n_tprev; | |
1539 | else | |
1540 | np->n_tnext->n_tprev = np->n_tprev; | |
1541 | if (np->n_tprev == (struct nfsnode *)nmp) | |
1542 | nmp->nm_tnext = np->n_tnext; | |
1543 | else | |
1544 | np->n_tprev->n_tnext = np->n_tnext; | |
1545 | } else | |
1546 | np->n_flag &= ~NQNFSWRITE; | |
1547 | if (cachable) | |
1548 | np->n_flag &= ~NQNFSNONCACHE; | |
1549 | else | |
1550 | np->n_flag |= NQNFSNONCACHE; | |
1551 | np->n_expiry = ltime; | |
1552 | np->n_lrev = frev; | |
1553 | tp = nmp->nm_tprev; | |
1554 | while (tp != (struct nfsnode *)nmp && tp->n_expiry > np->n_expiry) | |
1555 | tp = tp->n_tprev; | |
1556 | if (tp == (struct nfsnode *)nmp) { | |
1557 | np->n_tnext = nmp->nm_tnext; | |
1558 | nmp->nm_tnext = np; | |
1559 | } else { | |
1560 | np->n_tnext = tp->n_tnext; | |
1561 | tp->n_tnext = np; | |
1562 | } | |
1563 | np->n_tprev = tp; | |
1564 | if (np->n_tnext == (struct nfsnode *)nmp) | |
1565 | nmp->nm_tprev = np; | |
1566 | else | |
1567 | np->n_tnext->n_tprev = np; | |
c5b4f497 | 1568 | cache_enter(ndp->ni_dvp, ndp->ni_vp, cnp); |
2c5b44a2 KM |
1569 | } |
1570 | } else { | |
1571 | nfsm_adv(nfsm_rndup(len)); | |
1572 | } | |
1573 | if (newvp != NULLVP) { | |
1574 | vrele(newvp); | |
1575 | newvp = NULLVP; | |
1576 | } | |
1577 | nfsm_dissect(tl, u_long *, 2*NFSX_UNSIGNED); | |
1578 | if (bigenough) | |
1579 | endoff = off = fxdr_unsigned(off_t, *tl++); | |
1580 | else | |
1581 | endoff = fxdr_unsigned(off_t, *tl++); | |
1582 | more_dirs = fxdr_unsigned(int, *tl); | |
1583 | } | |
1584 | /* | |
1585 | * If at end of rpc data, get the eof boolean | |
1586 | */ | |
1587 | if (!more_dirs) { | |
1588 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); | |
1589 | more_dirs = (fxdr_unsigned(int, *tl) == 0); | |
1590 | ||
1591 | /* | |
1592 | * If at EOF, cache directory offset | |
1593 | */ | |
1594 | if (!more_dirs) | |
1595 | VTONFS(vp)->n_direofoffset = endoff; | |
1596 | } | |
1597 | if (uiop->uio_resid < tresid) | |
1598 | uiop->uio_offset = off; | |
1599 | else | |
1600 | more_dirs = 0; | |
1601 | m_freem(mrep); | |
1602 | } | |
1603 | /* | |
1604 | * Fill last record, iff any, out to a multiple of NFS_DIRBLKSIZ | |
1605 | * by increasing d_reclen for the last record. | |
1606 | */ | |
1607 | if (uiop->uio_resid < tresid) { | |
1608 | len = uiop->uio_resid & (NFS_DIRBLKSIZ - 1); | |
1609 | if (len > 0) { | |
1610 | dp->d_reclen += len; | |
1611 | uiop->uio_iov->iov_base += len; | |
1612 | uiop->uio_iov->iov_len -= len; | |
1613 | uiop->uio_resid -= len; | |
1614 | } | |
1615 | } | |
1616 | nfsmout: | |
1617 | if (newvp != NULLVP) | |
1618 | vrele(newvp); | |
1619 | return (error); | |
1620 | } | |
13576453 | 1621 | static char hextoasc[] = "0123456789abcdef"; |
a2907882 KM |
1622 | |
1623 | /* | |
1624 | * Silly rename. To make the NFS filesystem that is stateless look a little | |
1625 | * more like the "ufs" a remove of an active vnode is translated to a rename | |
1626 | * to a funny looking filename that is removed by nfs_inactive on the | |
1627 | * nfsnode. There is the potential for another process on a different client | |
1628 | * to create the same funny name between the nfs_lookitup() fails and the | |
1629 | * nfs_rename() completes, but... | |
1630 | */ | |
cfef4373 | 1631 | int |
c5b4f497 | 1632 | nfs_sillyrename(dvp, vp, cnp) |
cfef4373 JH |
1633 | struct vnode *dvp, *vp; |
1634 | struct componentname *cnp; | |
a2907882 KM |
1635 | { |
1636 | register struct nfsnode *np; | |
1637 | register struct sillyrename *sp; | |
a2907882 KM |
1638 | int error; |
1639 | short pid; | |
1640 | ||
cfef4373 JH |
1641 | cache_purge(dvp); |
1642 | np = VTONFS(vp); | |
4999e85f | 1643 | #ifdef SILLYSEPARATE |
a2907882 | 1644 | MALLOC(sp, struct sillyrename *, sizeof (struct sillyrename), |
a9b4ecb2 | 1645 | M_NFSREQ, M_WAITOK); |
4999e85f KM |
1646 | #else |
1647 | sp = &np->n_silly; | |
1648 | #endif | |
cfef4373 JH |
1649 | sp->s_cred = crdup(cnp->cn_cred); |
1650 | sp->s_dvp = dvp; | |
1651 | VREF(dvp); | |
a2907882 KM |
1652 | |
1653 | /* Fudge together a funny name */ | |
cfef4373 | 1654 | pid = cnp->cn_proc->p_pid; |
a9b4ecb2 KM |
1655 | bcopy(".nfsAxxxx4.4", sp->s_name, 13); |
1656 | sp->s_namlen = 12; | |
1657 | sp->s_name[8] = hextoasc[pid & 0xf]; | |
1658 | sp->s_name[7] = hextoasc[(pid >> 4) & 0xf]; | |
1659 | sp->s_name[6] = hextoasc[(pid >> 8) & 0xf]; | |
1660 | sp->s_name[5] = hextoasc[(pid >> 12) & 0xf]; | |
a2907882 KM |
1661 | |
1662 | /* Try lookitups until we get one that isn't there */ | |
cfef4373 | 1663 | while (nfs_lookitup(sp, (nfsv2fh_t *)0, cnp->cn_proc) == 0) { |
a9b4ecb2 KM |
1664 | sp->s_name[4]++; |
1665 | if (sp->s_name[4] > 'z') { | |
a2907882 KM |
1666 | error = EINVAL; |
1667 | goto bad; | |
1668 | } | |
1669 | } | |
cfef4373 | 1670 | if (error = nfs_renameit(dvp, cnp, sp)) |
a2907882 | 1671 | goto bad; |
cfef4373 | 1672 | nfs_lookitup(sp, &np->n_fh, cnp->cn_proc); |
a2907882 KM |
1673 | np->n_sillyrename = sp; |
1674 | return (0); | |
1675 | bad: | |
a9b4ecb2 KM |
1676 | vrele(sp->s_dvp); |
1677 | crfree(sp->s_cred); | |
4999e85f | 1678 | #ifdef SILLYSEPARATE |
a9b4ecb2 | 1679 | free((caddr_t)sp, M_NFSREQ); |
4999e85f | 1680 | #endif |
a2907882 KM |
1681 | return (error); |
1682 | } | |
1683 | ||
1684 | /* | |
1685 | * Look up a file name for silly rename stuff. | |
1686 | * Just like nfs_lookup() except that it doesn't load returned values | |
1687 | * into the nfsnode table. | |
1688 | * If fhp != NULL it copies the returned file handle out | |
1689 | */ | |
cfef4373 | 1690 | int |
2c5b44a2 | 1691 | nfs_lookitup(sp, fhp, procp) |
a9b4ecb2 | 1692 | register struct sillyrename *sp; |
a2907882 | 1693 | nfsv2fh_t *fhp; |
2c5b44a2 | 1694 | struct proc *procp; |
a2907882 | 1695 | { |
a9b4ecb2 | 1696 | register struct vnode *vp = sp->s_dvp; |
26cb2431 | 1697 | register u_long *tl; |
13576453 KM |
1698 | register caddr_t cp; |
1699 | register long t1, t2; | |
1700 | caddr_t bpos, dpos, cp2; | |
1701 | u_long xid; | |
1702 | int error = 0; | |
1703 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; | |
a2907882 KM |
1704 | long len; |
1705 | ||
1706 | nfsstats.rpccnt[NFSPROC_LOOKUP]++; | |
a9b4ecb2 | 1707 | len = sp->s_namlen; |
2c5b44a2 | 1708 | nfsm_reqhead(vp, NFSPROC_LOOKUP, NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len)); |
a2907882 | 1709 | nfsm_fhtom(vp); |
a9b4ecb2 | 1710 | nfsm_strtom(sp->s_name, len, NFS_MAXNAMLEN); |
2c5b44a2 | 1711 | nfsm_request(vp, NFSPROC_LOOKUP, procp, sp->s_cred); |
a2907882 | 1712 | if (fhp != NULL) { |
2c5b44a2 | 1713 | nfsm_dissect(cp, caddr_t, NFSX_FH); |
a2907882 KM |
1714 | bcopy(cp, (caddr_t)fhp, NFSX_FH); |
1715 | } | |
1716 | nfsm_reqdone; | |
1717 | return (error); | |
1718 | } | |
1719 | ||
1720 | /* | |
1721 | * Kludge City.. | |
1722 | * - make nfs_bmap() essentially a no-op that does no translation | |
f0f1cbaa | 1723 | * - do nfs_strategy() by faking physical I/O with nfs_readrpc/nfs_writerpc |
a2907882 KM |
1724 | * after mapping the physical addresses into Kernel Virtual space in the |
1725 | * nfsiobuf area. | |
1726 | * (Maybe I could use the process's page mapping, but I was concerned that | |
1727 | * Kernel Write might not be enabled and also figured copyout() would do | |
1728 | * a lot more work than bcopy() and also it currently happens in the | |
1729 | * context of the swapper process (2). | |
1730 | */ | |
cfef4373 | 1731 | int |
a2907882 KM |
1732 | nfs_bmap(vp, bn, vpp, bnp) |
1733 | struct vnode *vp; | |
1734 | daddr_t bn; | |
1735 | struct vnode **vpp; | |
1736 | daddr_t *bnp; | |
1737 | { | |
1738 | if (vpp != NULL) | |
1739 | *vpp = vp; | |
1740 | if (bnp != NULL) | |
2c5b44a2 | 1741 | *bnp = bn * btodb(vp->v_mount->mnt_stat.f_iosize); |
a2907882 KM |
1742 | return (0); |
1743 | } | |
1744 | ||
1745 | /* | |
9238aa59 RM |
1746 | * Strategy routine for phys. i/o |
1747 | * If the biod's are running, queue a request | |
1748 | * otherwise just call nfs_doio() to get it done | |
a2907882 | 1749 | */ |
cfef4373 | 1750 | int |
a2907882 KM |
1751 | nfs_strategy(bp) |
1752 | register struct buf *bp; | |
9238aa59 RM |
1753 | { |
1754 | register struct buf *dp; | |
ffe6f482 | 1755 | register int i; |
9238aa59 | 1756 | int error = 0; |
ffe6f482 | 1757 | int fnd = 0; |
9238aa59 | 1758 | |
f0f1cbaa KM |
1759 | /* |
1760 | * Set b_proc. It seems a bit silly to do it here, but since bread() | |
1761 | * doesn't set it, I will. | |
48531fd3 | 1762 | * Set b_proc == NULL for asynchronous ops, since these may still |
f0f1cbaa KM |
1763 | * be hanging about after the process terminates. |
1764 | */ | |
1c89915d KM |
1765 | if ((bp->b_flags & B_PHYS) == 0) { |
1766 | if (bp->b_flags & B_ASYNC) | |
1767 | bp->b_proc = (struct proc *)0; | |
1768 | else | |
058dee65 | 1769 | bp->b_proc = curproc; |
1c89915d | 1770 | } |
9238aa59 | 1771 | /* |
48531fd3 | 1772 | * If the op is asynchronous and an i/o daemon is waiting |
9238aa59 | 1773 | * queue the request, wake it up and wait for completion |
48531fd3 | 1774 | * otherwise just do it ourselves. |
9238aa59 | 1775 | */ |
1c89915d KM |
1776 | if ((bp->b_flags & B_ASYNC) == 0 || nfs_numasync == 0) |
1777 | return (nfs_doio(bp)); | |
1778 | for (i = 0; i < NFS_MAXASYNCDAEMON; i++) { | |
1779 | if (nfs_iodwant[i]) { | |
ffe6f482 KM |
1780 | dp = &nfs_bqueue; |
1781 | if (dp->b_actf == NULL) { | |
1782 | dp->b_actl = bp; | |
1783 | bp->b_actf = dp; | |
1784 | } else { | |
1785 | dp->b_actf->b_actl = bp; | |
1786 | bp->b_actf = dp->b_actf; | |
1787 | } | |
1788 | dp->b_actf = bp; | |
1789 | bp->b_actl = dp; | |
1790 | fnd++; | |
ffe6f482 KM |
1791 | wakeup((caddr_t)&nfs_iodwant[i]); |
1792 | break; | |
9238aa59 | 1793 | } |
ffe6f482 KM |
1794 | } |
1795 | if (!fnd) | |
9238aa59 RM |
1796 | error = nfs_doio(bp); |
1797 | return (error); | |
1798 | } | |
1799 | ||
1800 | /* | |
1801 | * Fun and games with i/o | |
1802 | * Essentially play ubasetup() and disk interrupt service routine by | |
1803 | * mapping the data buffer into kernel virtual space and doing the | |
1804 | * nfs read or write rpc's from it. | |
f0f1cbaa KM |
1805 | * If the nfsiod's are not running, this is just called from nfs_strategy(), |
1806 | * otherwise it is called by the nfsiods to do what would normally be | |
9238aa59 RM |
1807 | * partially disk interrupt driven. |
1808 | */ | |
cfef4373 | 1809 | int |
9238aa59 RM |
1810 | nfs_doio(bp) |
1811 | register struct buf *bp; | |
a2907882 | 1812 | { |
a2907882 | 1813 | register struct uio *uiop; |
a2907882 | 1814 | register struct vnode *vp; |
ffe6f482 | 1815 | struct nfsnode *np; |
9238aa59 | 1816 | struct ucred *cr; |
7848989c | 1817 | int error; |
a2907882 KM |
1818 | struct uio uio; |
1819 | struct iovec io; | |
1820 | ||
1821 | vp = bp->b_vp; | |
8c379a26 | 1822 | np = VTONFS(vp); |
a2907882 KM |
1823 | uiop = &uio; |
1824 | uiop->uio_iov = &io; | |
1825 | uiop->uio_iovcnt = 1; | |
a2907882 | 1826 | uiop->uio_segflg = UIO_SYSSPACE; |
2c5b44a2 | 1827 | uiop->uio_procp = bp->b_proc; |
e8540f59 | 1828 | |
a2907882 | 1829 | /* |
9238aa59 RM |
1830 | * For phys i/o, map the b_addr into kernel virtual space using |
1831 | * the Nfsiomap pte's | |
1832 | * Also, add a temporary b_rcred for reading using the process's uid | |
1833 | * and a guess at a group | |
a2907882 | 1834 | */ |
9238aa59 | 1835 | if (bp->b_flags & B_PHYS) { |
26cb2431 KM |
1836 | if (bp->b_flags & B_DIRTY) |
1837 | uiop->uio_procp = pageproc; | |
1838 | cr = crcopy(uiop->uio_procp->p_ucred); | |
7848989c KM |
1839 | /* mapping was already done by vmapbuf */ |
1840 | io.iov_base = bp->b_un.b_addr; | |
e8540f59 KM |
1841 | |
1842 | /* | |
1843 | * And do the i/o rpc | |
1844 | */ | |
e8540f59 | 1845 | io.iov_len = uiop->uio_resid = bp->b_bcount; |
589be24d | 1846 | uiop->uio_offset = bp->b_blkno * DEV_BSIZE; |
e8540f59 KM |
1847 | if (bp->b_flags & B_READ) { |
1848 | uiop->uio_rw = UIO_READ; | |
1849 | nfsstats.read_physios++; | |
26cb2431 | 1850 | bp->b_error = error = nfs_readrpc(vp, uiop, cr); |
8986c97c | 1851 | (void) vnode_pager_uncache(vp); |
e8540f59 KM |
1852 | } else { |
1853 | uiop->uio_rw = UIO_WRITE; | |
1854 | nfsstats.write_physios++; | |
26cb2431 | 1855 | bp->b_error = error = nfs_writerpc(vp, uiop, cr); |
ffe6f482 | 1856 | } |
e8540f59 KM |
1857 | |
1858 | /* | |
1859 | * Finally, release pte's used by physical i/o | |
1860 | */ | |
9238aa59 | 1861 | crfree(cr); |
e8540f59 KM |
1862 | } else { |
1863 | if (bp->b_flags & B_READ) { | |
1864 | io.iov_len = uiop->uio_resid = bp->b_bcount; | |
e8540f59 KM |
1865 | io.iov_base = bp->b_un.b_addr; |
1866 | uiop->uio_rw = UIO_READ; | |
f0f1cbaa KM |
1867 | switch (vp->v_type) { |
1868 | case VREG: | |
1869 | uiop->uio_offset = bp->b_blkno * DEV_BSIZE; | |
1870 | nfsstats.read_bios++; | |
26cb2431 | 1871 | error = nfs_readrpc(vp, uiop, bp->b_rcred); |
f0f1cbaa KM |
1872 | break; |
1873 | case VLNK: | |
1874 | uiop->uio_offset = 0; | |
1875 | nfsstats.readlink_bios++; | |
26cb2431 | 1876 | error = nfs_readlinkrpc(vp, uiop, bp->b_rcred); |
f0f1cbaa KM |
1877 | break; |
1878 | case VDIR: | |
1879 | uiop->uio_offset = bp->b_lblkno; | |
1880 | nfsstats.readdir_bios++; | |
2c5b44a2 KM |
1881 | if (VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_RDIRALOOK) |
1882 | error = nfs_readdirlookrpc(vp, uiop, bp->b_rcred); | |
1883 | else | |
1884 | error = nfs_readdirrpc(vp, uiop, bp->b_rcred); | |
f0f1cbaa KM |
1885 | /* |
1886 | * Save offset cookie in b_blkno. | |
1887 | */ | |
1888 | bp->b_blkno = uiop->uio_offset; | |
1889 | break; | |
1890 | }; | |
1891 | bp->b_error = error; | |
e8540f59 KM |
1892 | } else { |
1893 | io.iov_len = uiop->uio_resid = bp->b_dirtyend | |
1894 | - bp->b_dirtyoff; | |
589be24d | 1895 | uiop->uio_offset = (bp->b_blkno * DEV_BSIZE) |
e8540f59 KM |
1896 | + bp->b_dirtyoff; |
1897 | io.iov_base = bp->b_un.b_addr + bp->b_dirtyoff; | |
1898 | uiop->uio_rw = UIO_WRITE; | |
1899 | nfsstats.write_bios++; | |
f0f1cbaa | 1900 | bp->b_error = error = nfs_writerpc(vp, uiop, |
26cb2431 | 1901 | bp->b_wcred); |
e8540f59 | 1902 | if (error) { |
e8540f59 KM |
1903 | np->n_error = error; |
1904 | np->n_flag |= NWRITEERR; | |
1905 | } | |
1906 | bp->b_dirtyoff = bp->b_dirtyend = 0; | |
1907 | } | |
9238aa59 | 1908 | } |
e8540f59 KM |
1909 | if (error) |
1910 | bp->b_flags |= B_ERROR; | |
1911 | bp->b_resid = uiop->uio_resid; | |
a2907882 | 1912 | biodone(bp); |
9238aa59 RM |
1913 | return (error); |
1914 | } | |
1915 | ||
26cb2431 KM |
1916 | /* |
1917 | * Mmap a file | |
1918 | * | |
1919 | * NB Currently unsupported. | |
1920 | */ | |
1921 | /* ARGSUSED */ | |
cfef4373 | 1922 | int |
26cb2431 KM |
1923 | nfs_mmap(vp, fflags, cred, p) |
1924 | struct vnode *vp; | |
1925 | int fflags; | |
1926 | struct ucred *cred; | |
1927 | struct proc *p; | |
1928 | { | |
1929 | ||
1930 | return (EINVAL); | |
1931 | } | |
1932 | ||
9238aa59 RM |
1933 | /* |
1934 | * Flush all the blocks associated with a vnode. | |
1935 | * Walk through the buffer pool and push any dirty pages | |
1936 | * associated with the vnode. | |
1937 | */ | |
13576453 | 1938 | /* ARGSUSED */ |
cfef4373 | 1939 | int |
26cb2431 | 1940 | nfs_fsync(vp, fflags, cred, waitfor, p) |
9238aa59 RM |
1941 | register struct vnode *vp; |
1942 | int fflags; | |
1943 | struct ucred *cred; | |
f8428623 | 1944 | int waitfor; |
26cb2431 | 1945 | struct proc *p; |
9238aa59 RM |
1946 | { |
1947 | register struct nfsnode *np = VTONFS(vp); | |
e8540f59 | 1948 | int error = 0; |
9238aa59 | 1949 | |
9238aa59 RM |
1950 | if (np->n_flag & NMODIFIED) { |
1951 | np->n_flag &= ~NMODIFIED; | |
e8540f59 | 1952 | vflushbuf(vp, waitfor == MNT_WAIT ? B_SYNC : 0); |
9238aa59 | 1953 | } |
e8540f59 KM |
1954 | if (!error && (np->n_flag & NWRITEERR)) |
1955 | error = np->n_error; | |
a2907882 KM |
1956 | return (error); |
1957 | } | |
d002709d | 1958 | |
a4128336 KM |
1959 | /* |
1960 | * NFS advisory byte-level locks. | |
1961 | * Currently unsupported. | |
1962 | */ | |
cfef4373 | 1963 | int |
a4128336 KM |
1964 | nfs_advlock(vp, id, op, fl, flags) |
1965 | struct vnode *vp; | |
1966 | caddr_t id; | |
1967 | int op; | |
1968 | struct flock *fl; | |
1969 | int flags; | |
1970 | { | |
1971 | ||
1972 | return (EOPNOTSUPP); | |
1973 | } | |
1974 | ||
d002709d KM |
1975 | /* |
1976 | * Print out the contents of an nfsnode. | |
1977 | */ | |
cfef4373 | 1978 | int |
d002709d KM |
1979 | nfs_print(vp) |
1980 | struct vnode *vp; | |
1981 | { | |
1982 | register struct nfsnode *np = VTONFS(vp); | |
1983 | ||
b2d955e4 KM |
1984 | printf("tag VT_NFS, fileid %d fsid 0x%x", |
1985 | np->n_vattr.va_fileid, np->n_vattr.va_fsid); | |
1986 | #ifdef FIFO | |
1987 | if (vp->v_type == VFIFO) | |
1988 | fifo_printinfo(vp); | |
1989 | #endif /* FIFO */ | |
1a1dbccb | 1990 | printf("\n"); |
d002709d | 1991 | } |
9396df75 KM |
1992 | |
1993 | /* | |
1994 | * NFS directory offset lookup. | |
1995 | * Currently unsupported. | |
1996 | */ | |
cfef4373 | 1997 | int |
9396df75 KM |
1998 | nfs_blkatoff(vp, offset, res, bpp) |
1999 | struct vnode *vp; | |
2000 | off_t offset; | |
2001 | char **res; | |
2002 | struct buf **bpp; | |
2003 | { | |
2004 | ||
2005 | return (EOPNOTSUPP); | |
2006 | } | |
2007 | ||
2008 | /* | |
2009 | * NFS flat namespace lookup. | |
2010 | * Currently unsupported. | |
2011 | */ | |
cfef4373 | 2012 | int |
9396df75 KM |
2013 | nfs_vget(mp, ino, vpp) |
2014 | struct mount *mp; | |
2015 | ino_t ino; | |
2016 | struct vnode **vpp; | |
2017 | { | |
2018 | ||
2019 | return (EOPNOTSUPP); | |
2020 | } | |
2021 | ||
2022 | /* | |
2023 | * NFS flat namespace allocation. | |
2024 | * Currently unsupported. | |
2025 | */ | |
cfef4373 | 2026 | int |
9396df75 KM |
2027 | nfs_valloc(pvp, mode, cred, vpp) |
2028 | struct vnode *pvp; | |
2029 | int mode; | |
2030 | struct ucred *cred; | |
2031 | struct vnode **vpp; | |
2032 | { | |
2033 | ||
2034 | return (EOPNOTSUPP); | |
2035 | } | |
2036 | ||
2037 | /* | |
2038 | * NFS flat namespace free. | |
2039 | * Currently unsupported. | |
2040 | */ | |
2041 | void | |
2042 | nfs_vfree(pvp, ino, mode) | |
2043 | struct vnode *pvp; | |
2044 | ino_t ino; | |
2045 | int mode; | |
2046 | { | |
2047 | ||
2048 | return; | |
2049 | } | |
2050 | ||
2051 | /* | |
2052 | * NFS file truncation. | |
2053 | */ | |
cfef4373 | 2054 | int |
9396df75 KM |
2055 | nfs_truncate(vp, length, flags) |
2056 | struct vnode *vp; | |
2057 | u_long length; | |
2058 | int flags; | |
2059 | { | |
2060 | ||
2061 | /* Use nfs_setattr */ | |
2062 | printf("nfs_truncate: need to implement!!"); | |
2063 | return (EOPNOTSUPP); | |
2064 | } | |
2065 | ||
2066 | /* | |
2067 | * NFS update. | |
2068 | */ | |
cfef4373 | 2069 | int |
9396df75 KM |
2070 | nfs_update(vp, ta, tm, waitfor) |
2071 | struct vnode *vp; | |
2072 | struct timeval *ta; | |
2073 | struct timeval *tm; | |
2074 | int waitfor; | |
2075 | { | |
2076 | ||
2077 | /* Use nfs_setattr */ | |
2078 | printf("nfs_update: need to implement!!"); | |
2079 | return (EOPNOTSUPP); | |
2080 | } |