2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)nfs_vnops.c 8.16 (Berkeley) 5/27/95
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
43 * vnode op calls for Sun NFS version 2 and 3
48 #include <sys/param.h>
49 #include <sys/kernel.h>
50 #include <sys/systm.h>
51 #include <sys/resourcevar.h>
53 #include <sys/mount.h>
56 #include <sys/malloc.h>
58 #include <sys/namei.h>
59 #include <sys/socket.h>
60 #include <sys/vnode.h>
61 #include <sys/dirent.h>
62 #include <sys/fcntl.h>
63 #include <sys/lockf.h>
65 #include <sys/sysctl.h>
68 #include <vm/vm_extern.h>
70 #include <fs/fifofs/fifo.h>
72 #include <nfs/rpcv2.h>
73 #include <nfs/nfsproto.h>
74 #include <nfsclient/nfs.h>
75 #include <nfsclient/nfsnode.h>
76 #include <nfsclient/nfsmount.h>
77 #include <nfsclient/nfs_lock.h>
78 #include <nfs/xdr_subs.h>
79 #include <nfsclient/nfsm_subs.h>
82 #include <netinet/in.h>
83 #include <netinet/in_var.h>
90 * Ifdef for FreeBSD-current merged buffer cache. It is unfortunate that these
91 * calls are not in getblk() and brelse() so that they would not be necessary
95 #define vfs_busy_pages(bp, f)
98 static int nfsspec_read(struct vop_read_args *);
99 static int nfsspec_write(struct vop_write_args *);
100 static int nfsfifo_read(struct vop_read_args *);
101 static int nfsfifo_write(struct vop_write_args *);
102 static int nfsspec_close(struct vop_close_args *);
103 static int nfsfifo_close(struct vop_close_args *);
104 static int nfs_flush(struct vnode *, struct ucred *, int, struct thread *,
106 static int nfs_setattrrpc(struct vnode *, struct vattr *, struct ucred *,
108 static int nfs_lookup(struct vop_lookup_args *);
109 static int nfs_create(struct vop_create_args *);
110 static int nfs_mknod(struct vop_mknod_args *);
111 static int nfs_open(struct vop_open_args *);
112 static int nfs_close(struct vop_close_args *);
113 static int nfs_access(struct vop_access_args *);
114 static int nfs_getattr(struct vop_getattr_args *);
115 static int nfs_setattr(struct vop_setattr_args *);
116 static int nfs_read(struct vop_read_args *);
117 static int nfs_fsync(struct vop_fsync_args *);
118 static int nfs_remove(struct vop_remove_args *);
119 static int nfs_link(struct vop_link_args *);
120 static int nfs_rename(struct vop_rename_args *);
121 static int nfs_mkdir(struct vop_mkdir_args *);
122 static int nfs_rmdir(struct vop_rmdir_args *);
123 static int nfs_symlink(struct vop_symlink_args *);
124 static int nfs_readdir(struct vop_readdir_args *);
125 static int nfs_strategy(struct vop_strategy_args *);
126 static int nfs_lookitup(struct vnode *, const char *, int,
127 struct ucred *, struct thread *, struct nfsnode **);
128 static int nfs_sillyrename(struct vnode *, struct vnode *,
129 struct componentname *);
130 static int nfsspec_access(struct vop_access_args *);
131 static int nfs_readlink(struct vop_readlink_args *);
132 static int nfs_print(struct vop_print_args *);
133 static int nfs_advlock(struct vop_advlock_args *);
136 * Global vfs data structures for nfs
138 vop_t **nfsv2_vnodeop_p;
139 static struct vnodeopv_entry_desc nfsv2_vnodeop_entries[] = {
140 { &vop_default_desc, (vop_t *) vop_defaultop },
141 { &vop_access_desc, (vop_t *) nfs_access },
142 { &vop_advlock_desc, (vop_t *) nfs_advlock },
143 { &vop_close_desc, (vop_t *) nfs_close },
144 { &vop_create_desc, (vop_t *) nfs_create },
145 { &vop_fsync_desc, (vop_t *) nfs_fsync },
146 { &vop_getattr_desc, (vop_t *) nfs_getattr },
147 { &vop_getpages_desc, (vop_t *) nfs_getpages },
148 { &vop_putpages_desc, (vop_t *) nfs_putpages },
149 { &vop_inactive_desc, (vop_t *) nfs_inactive },
150 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
151 { &vop_lease_desc, (vop_t *) vop_null },
152 { &vop_link_desc, (vop_t *) nfs_link },
153 { &vop_lock_desc, (vop_t *) vop_sharedlock },
154 { &vop_lookup_desc, (vop_t *) nfs_lookup },
155 { &vop_mkdir_desc, (vop_t *) nfs_mkdir },
156 { &vop_mknod_desc, (vop_t *) nfs_mknod },
157 { &vop_open_desc, (vop_t *) nfs_open },
158 { &vop_print_desc, (vop_t *) nfs_print },
159 { &vop_read_desc, (vop_t *) nfs_read },
160 { &vop_readdir_desc, (vop_t *) nfs_readdir },
161 { &vop_readlink_desc, (vop_t *) nfs_readlink },
162 { &vop_reclaim_desc, (vop_t *) nfs_reclaim },
163 { &vop_remove_desc, (vop_t *) nfs_remove },
164 { &vop_rename_desc, (vop_t *) nfs_rename },
165 { &vop_rmdir_desc, (vop_t *) nfs_rmdir },
166 { &vop_setattr_desc, (vop_t *) nfs_setattr },
167 { &vop_strategy_desc, (vop_t *) nfs_strategy },
168 { &vop_symlink_desc, (vop_t *) nfs_symlink },
169 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
170 { &vop_write_desc, (vop_t *) nfs_write },
173 static struct vnodeopv_desc nfsv2_vnodeop_opv_desc =
174 { &nfsv2_vnodeop_p, nfsv2_vnodeop_entries };
175 VNODEOP_SET(nfsv2_vnodeop_opv_desc);
178 * Special device vnode ops
180 vop_t **spec_nfsv2nodeop_p;
181 static struct vnodeopv_entry_desc nfsv2_specop_entries[] = {
182 { &vop_default_desc, (vop_t *) spec_vnoperate },
183 { &vop_access_desc, (vop_t *) nfsspec_access },
184 { &vop_close_desc, (vop_t *) nfsspec_close },
185 { &vop_fsync_desc, (vop_t *) nfs_fsync },
186 { &vop_getattr_desc, (vop_t *) nfs_getattr },
187 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
188 { &vop_inactive_desc, (vop_t *) nfs_inactive },
189 { &vop_lock_desc, (vop_t *) vop_sharedlock },
190 { &vop_print_desc, (vop_t *) nfs_print },
191 { &vop_read_desc, (vop_t *) nfsspec_read },
192 { &vop_reclaim_desc, (vop_t *) nfs_reclaim },
193 { &vop_setattr_desc, (vop_t *) nfs_setattr },
194 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
195 { &vop_write_desc, (vop_t *) nfsspec_write },
198 static struct vnodeopv_desc spec_nfsv2nodeop_opv_desc =
199 { &spec_nfsv2nodeop_p, nfsv2_specop_entries };
200 VNODEOP_SET(spec_nfsv2nodeop_opv_desc);
202 vop_t **fifo_nfsv2nodeop_p;
203 static struct vnodeopv_entry_desc nfsv2_fifoop_entries[] = {
204 { &vop_default_desc, (vop_t *) fifo_vnoperate },
205 { &vop_access_desc, (vop_t *) nfsspec_access },
206 { &vop_close_desc, (vop_t *) nfsfifo_close },
207 { &vop_fsync_desc, (vop_t *) nfs_fsync },
208 { &vop_getattr_desc, (vop_t *) nfs_getattr },
209 { &vop_inactive_desc, (vop_t *) nfs_inactive },
210 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
211 { &vop_lock_desc, (vop_t *) vop_sharedlock },
212 { &vop_print_desc, (vop_t *) nfs_print },
213 { &vop_read_desc, (vop_t *) nfsfifo_read },
214 { &vop_reclaim_desc, (vop_t *) nfs_reclaim },
215 { &vop_setattr_desc, (vop_t *) nfs_setattr },
216 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
217 { &vop_write_desc, (vop_t *) nfsfifo_write },
220 static struct vnodeopv_desc fifo_nfsv2nodeop_opv_desc =
221 { &fifo_nfsv2nodeop_p, nfsv2_fifoop_entries };
222 VNODEOP_SET(fifo_nfsv2nodeop_opv_desc);
224 static int nfs_mknodrpc(struct vnode *dvp, struct vnode **vpp,
225 struct componentname *cnp, struct vattr *vap);
226 static int nfs_removerpc(struct vnode *dvp, const char *name, int namelen,
227 struct ucred *cred, struct thread *td);
228 static int nfs_renamerpc(struct vnode *fdvp, const char *fnameptr,
229 int fnamelen, struct vnode *tdvp,
230 const char *tnameptr, int tnamelen,
231 struct ucred *cred, struct thread *td);
232 static int nfs_renameit(struct vnode *sdvp, struct componentname *scnp,
233 struct sillyrename *sp);
238 struct proc *nfs_iodwant[NFS_MAXASYNCDAEMON];
239 struct nfsmount *nfs_iodmount[NFS_MAXASYNCDAEMON];
240 int nfs_numasync = 0;
241 #define DIRHDSIZ (sizeof (struct dirent) - (MAXNAMLEN + 1))
243 SYSCTL_DECL(_vfs_nfs);
245 static int nfsaccess_cache_timeout = NFS_MAXATTRTIMO;
246 SYSCTL_INT(_vfs_nfs, OID_AUTO, access_cache_timeout, CTLFLAG_RW,
247 &nfsaccess_cache_timeout, 0, "NFS ACCESS cache timeout");
249 static int nfsv3_commit_on_close = 0;
250 SYSCTL_INT(_vfs_nfs, OID_AUTO, nfsv3_commit_on_close, CTLFLAG_RW,
251 &nfsv3_commit_on_close, 0, "write+commit on close, else only write");
253 SYSCTL_INT(_vfs_nfs, OID_AUTO, access_cache_hits, CTLFLAG_RD,
254 &nfsstats.accesscache_hits, 0, "NFS ACCESS cache hit count");
256 SYSCTL_INT(_vfs_nfs, OID_AUTO, access_cache_misses, CTLFLAG_RD,
257 &nfsstats.accesscache_misses, 0, "NFS ACCESS cache miss count");
260 #define NFSV3ACCESS_ALL (NFSV3ACCESS_READ | NFSV3ACCESS_MODIFY \
261 | NFSV3ACCESS_EXTEND | NFSV3ACCESS_EXECUTE \
262 | NFSV3ACCESS_DELETE | NFSV3ACCESS_LOOKUP)
264 nfs3_access_otw(struct vnode *vp, int wmode, struct thread *td,
269 int error = 0, attrflag;
271 struct mbuf *mreq, *mrep, *md, *mb;
274 struct nfsnode *np = VTONFS(vp);
276 nfsstats.rpccnt[NFSPROC_ACCESS]++;
277 mreq = nfsm_reqhead(vp, NFSPROC_ACCESS, NFSX_FH(v3) + NFSX_UNSIGNED);
279 bpos = mtod(mb, caddr_t);
281 tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED);
282 *tl = txdr_unsigned(wmode);
283 nfsm_request(vp, NFSPROC_ACCESS, td, cred);
284 nfsm_postop_attr(vp, attrflag);
286 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
287 rmode = fxdr_unsigned(u_int32_t, *tl);
289 np->n_modeuid = cred->cr_uid;
290 np->n_modestamp = time_second;
298 * nfs access vnode op.
299 * For nfs version 2, just return ok. File accesses may fail later.
300 * For nfs version 3, use the access rpc to check accessibility. If file modes
301 * are changed on the server, accesses might still fail later.
304 nfs_access(struct vop_access_args *ap)
306 struct vnode *vp = ap->a_vp;
308 u_int32_t mode, wmode;
309 int v3 = NFS_ISV3(vp);
310 struct nfsnode *np = VTONFS(vp);
313 * Disallow write attempts on filesystems mounted read-only;
314 * unless the file is a socket, fifo, or a block or character
315 * device resident on the filesystem.
317 if ((ap->a_mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
318 switch (vp->v_type) {
328 * For nfs v3, check to see if we have done this recently, and if
329 * so return our cached result instead of making an ACCESS call.
330 * If not, do an access rpc, otherwise you are stuck emulating
331 * ufs_access() locally using the vattr. This may not be correct,
332 * since the server may apply other access criteria such as
333 * client uid-->server uid mapping that we do not know about.
336 if (ap->a_mode & VREAD)
337 mode = NFSV3ACCESS_READ;
340 if (vp->v_type != VDIR) {
341 if (ap->a_mode & VWRITE)
342 mode |= (NFSV3ACCESS_MODIFY | NFSV3ACCESS_EXTEND);
343 if (ap->a_mode & VEXEC)
344 mode |= NFSV3ACCESS_EXECUTE;
346 if (ap->a_mode & VWRITE)
347 mode |= (NFSV3ACCESS_MODIFY | NFSV3ACCESS_EXTEND |
349 if (ap->a_mode & VEXEC)
350 mode |= NFSV3ACCESS_LOOKUP;
352 /* XXX safety belt, only make blanket request if caching */
353 if (nfsaccess_cache_timeout > 0) {
354 wmode = NFSV3ACCESS_READ | NFSV3ACCESS_MODIFY |
355 NFSV3ACCESS_EXTEND | NFSV3ACCESS_EXECUTE |
356 NFSV3ACCESS_DELETE | NFSV3ACCESS_LOOKUP;
362 * Does our cached result allow us to give a definite yes to
365 if ((time_second < (np->n_modestamp + nfsaccess_cache_timeout)) &&
366 (ap->a_cred->cr_uid == np->n_modeuid) &&
367 ((np->n_mode & mode) == mode)) {
368 nfsstats.accesscache_hits++;
371 * Either a no, or a don't know. Go to the wire.
373 nfsstats.accesscache_misses++;
374 error = nfs3_access_otw(vp, wmode, ap->a_td,ap->a_cred);
376 if ((np->n_mode & mode) != mode) {
383 if ((error = nfsspec_access(ap)) != 0)
387 * Attempt to prevent a mapped root from accessing a file
388 * which it shouldn't. We try to read a byte from the file
389 * if the user is root and the file is not zero length.
390 * After calling nfsspec_access, we should have the correct
393 if (ap->a_cred->cr_uid == 0 && (ap->a_mode & VREAD)
394 && VTONFS(vp)->n_size > 0) {
401 auio.uio_iov = &aiov;
405 auio.uio_segflg = UIO_SYSSPACE;
406 auio.uio_rw = UIO_READ;
407 auio.uio_td = ap->a_td;
409 if (vp->v_type == VREG)
410 error = nfs_readrpc(vp, &auio, ap->a_cred);
411 else if (vp->v_type == VDIR) {
413 bp = malloc(NFS_DIRBLKSIZ, M_TEMP, M_WAITOK);
415 aiov.iov_len = auio.uio_resid = NFS_DIRBLKSIZ;
416 error = nfs_readdirrpc(vp, &auio, ap->a_cred);
418 } else if (vp->v_type == VLNK)
419 error = nfs_readlinkrpc(vp, &auio, ap->a_cred);
429 * Check to see if the type is ok
430 * and that deletion is not in progress.
431 * For paged in text files, you will need to flush the page cache
432 * if consistency is lost.
436 nfs_open(struct vop_open_args *ap)
438 struct vnode *vp = ap->a_vp;
439 struct nfsnode *np = VTONFS(vp);
443 if (vp->v_type != VREG && vp->v_type != VDIR && vp->v_type != VLNK) {
445 printf("open eacces vtyp=%d\n", vp->v_type);
450 * Get a valid lease. If cached data is stale, flush it.
452 if (np->n_flag & NMODIFIED) {
453 if ((error = nfs_vinvalbuf(vp, V_SAVE, ap->a_cred,
454 ap->a_td, 1)) == EINTR)
457 if (vp->v_type == VDIR)
458 np->n_direofoffset = 0;
459 error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);
462 np->n_mtime = vattr.va_mtime.tv_sec;
464 error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);
467 if (np->n_mtime != vattr.va_mtime.tv_sec) {
468 if (vp->v_type == VDIR)
469 np->n_direofoffset = 0;
470 if ((error = nfs_vinvalbuf(vp, V_SAVE,
471 ap->a_cred, ap->a_td, 1)) == EINTR)
473 np->n_mtime = vattr.va_mtime.tv_sec;
476 np->n_attrstamp = 0; /* For Open/Close consistency */
482 * What an NFS client should do upon close after writing is a debatable issue.
483 * Most NFS clients push delayed writes to the server upon close, basically for
485 * 1 - So that any write errors may be reported back to the client process
486 * doing the close system call. By far the two most likely errors are
487 * NFSERR_NOSPC and NFSERR_DQUOT to indicate space allocation failure.
488 * 2 - To put a worst case upper bound on cache inconsistency between
489 * multiple clients for the file.
490 * There is also a consistency problem for Version 2 of the protocol w.r.t.
491 * not being able to tell if other clients are writing a file concurrently,
492 * since there is no way of knowing if the changed modify time in the reply
493 * is only due to the write for this client.
494 * (NFS Version 3 provides weak cache consistency data in the reply that
495 * should be sufficient to detect and handle this case.)
497 * The current code does the following:
498 * for NFS Version 2 - play it safe and flush/invalidate all dirty buffers
499 * for NFS Version 3 - flush dirty buffers to the server but don't invalidate
500 * or commit them (this satisfies 1 and 2 except for the
501 * case where the server crashes after this close but
502 * before the commit RPC, which is felt to be "good
503 * enough". Changing the last argument to nfs_flush() to
504 * a 1 would force a commit operation, if it is felt a
505 * commit is necessary now.
509 nfs_close(struct vop_close_args *ap)
511 struct vnode *vp = ap->a_vp;
512 struct nfsnode *np = VTONFS(vp);
515 if (vp->v_type == VREG) {
516 if (np->n_flag & NMODIFIED) {
519 * Under NFSv3 we have dirty buffers to dispose of. We
520 * must flush them to the NFS server. We have the option
521 * of waiting all the way through the commit rpc or just
522 * waiting for the initial write. The default is to only
523 * wait through the initial write so the data is in the
524 * server's cache, which is roughly similar to the state
525 * a standard disk subsystem leaves the file in on close().
527 * We cannot clear the NMODIFIED bit in np->n_flag due to
528 * potential races with other processes, and certainly
529 * cannot clear it if we don't commit.
531 int cm = nfsv3_commit_on_close ? 1 : 0;
532 error = nfs_flush(vp, ap->a_cred, MNT_WAIT, ap->a_td, cm);
533 /* np->n_flag &= ~NMODIFIED; */
535 error = nfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_td, 1);
539 if (np->n_flag & NWRITEERR) {
540 np->n_flag &= ~NWRITEERR;
548 * nfs getattr call from vfs.
551 nfs_getattr(struct vop_getattr_args *ap)
553 struct vnode *vp = ap->a_vp;
554 struct nfsnode *np = VTONFS(vp);
557 struct mbuf *mreq, *mrep, *md, *mb;
558 int v3 = NFS_ISV3(vp);
561 * Update local times for special files.
563 if (np->n_flag & (NACC | NUPD))
566 * First look in the cache.
568 if (nfs_getattrcache(vp, ap->a_vap) == 0)
571 if (v3 && nfsaccess_cache_timeout > 0) {
572 nfsstats.accesscache_misses++;
573 nfs3_access_otw(vp, NFSV3ACCESS_ALL, ap->a_td, ap->a_cred);
574 if (nfs_getattrcache(vp, ap->a_vap) == 0)
578 nfsstats.rpccnt[NFSPROC_GETATTR]++;
579 mreq = nfsm_reqhead(vp, NFSPROC_GETATTR, NFSX_FH(v3));
581 bpos = mtod(mb, caddr_t);
583 nfsm_request(vp, NFSPROC_GETATTR, ap->a_td, ap->a_cred);
585 nfsm_loadattr(vp, ap->a_vap);
596 nfs_setattr(struct vop_setattr_args *ap)
598 struct vnode *vp = ap->a_vp;
599 struct nfsnode *np = VTONFS(vp);
600 struct vattr *vap = ap->a_vap;
609 * Setting of flags is not supported.
611 if (vap->va_flags != VNOVAL)
615 * Disallow write attempts if the filesystem is mounted read-only.
617 if ((vap->va_flags != VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
618 vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
619 vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL) &&
620 (vp->v_mount->mnt_flag & MNT_RDONLY))
622 if (vap->va_size != VNOVAL) {
623 switch (vp->v_type) {
630 if (vap->va_mtime.tv_sec == VNOVAL &&
631 vap->va_atime.tv_sec == VNOVAL &&
632 vap->va_mode == (mode_t)VNOVAL &&
633 vap->va_uid == (uid_t)VNOVAL &&
634 vap->va_gid == (gid_t)VNOVAL)
636 vap->va_size = VNOVAL;
640 * Disallow write attempts if the filesystem is
643 if (vp->v_mount->mnt_flag & MNT_RDONLY)
647 * We run vnode_pager_setsize() early (why?),
648 * we must set np->n_size now to avoid vinvalbuf
649 * V_SAVE races that might setsize a lower
654 error = nfs_meta_setsize(vp, ap->a_cred,
655 ap->a_td, vap->va_size);
657 if (np->n_flag & NMODIFIED) {
658 if (vap->va_size == 0)
659 error = nfs_vinvalbuf(vp, 0,
660 ap->a_cred, ap->a_td, 1);
662 error = nfs_vinvalbuf(vp, V_SAVE,
663 ap->a_cred, ap->a_td, 1);
665 vnode_pager_setsize(vp, np->n_size);
669 np->n_vattr.va_size = vap->va_size;
671 } else if ((vap->va_mtime.tv_sec != VNOVAL ||
672 vap->va_atime.tv_sec != VNOVAL) && (np->n_flag & NMODIFIED) &&
673 vp->v_type == VREG &&
674 (error = nfs_vinvalbuf(vp, V_SAVE, ap->a_cred,
675 ap->a_td, 1)) == EINTR)
677 error = nfs_setattrrpc(vp, vap, ap->a_cred, ap->a_td);
678 if (error && vap->va_size != VNOVAL) {
679 np->n_size = np->n_vattr.va_size = tsize;
680 vnode_pager_setsize(vp, np->n_size);
686 * Do an nfs setattr rpc.
689 nfs_setattrrpc(struct vnode *vp, struct vattr *vap, struct ucred *cred,
692 struct nfsv2_sattr *sp;
695 int error = 0, wccflag = NFSV3_WCCRATTR;
696 struct mbuf *mreq, *mrep, *md, *mb;
697 int v3 = NFS_ISV3(vp);
699 nfsstats.rpccnt[NFSPROC_SETATTR]++;
700 mreq = nfsm_reqhead(vp, NFSPROC_SETATTR, NFSX_FH(v3) + NFSX_SATTR(v3));
702 bpos = mtod(mb, caddr_t);
705 nfsm_v3attrbuild(vap, TRUE);
706 tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED);
709 sp = nfsm_build(struct nfsv2_sattr *, NFSX_V2SATTR);
710 if (vap->va_mode == (mode_t)VNOVAL)
711 sp->sa_mode = nfs_xdrneg1;
713 sp->sa_mode = vtonfsv2_mode(vp->v_type, vap->va_mode);
714 if (vap->va_uid == (uid_t)VNOVAL)
715 sp->sa_uid = nfs_xdrneg1;
717 sp->sa_uid = txdr_unsigned(vap->va_uid);
718 if (vap->va_gid == (gid_t)VNOVAL)
719 sp->sa_gid = nfs_xdrneg1;
721 sp->sa_gid = txdr_unsigned(vap->va_gid);
722 sp->sa_size = txdr_unsigned(vap->va_size);
723 txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
724 txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
726 nfsm_request(vp, NFSPROC_SETATTR, td, cred);
728 nfsm_wcc_data(vp, wccflag);
730 nfsm_loadattr(vp, (struct vattr *)0);
737 * nfs lookup call, one step at a time...
738 * First look in cache
739 * If not found, unlock the directory nfsnode and do the rpc
742 nfs_lookup(struct vop_lookup_args *ap)
744 struct componentname *cnp = ap->a_cnp;
745 struct vnode *dvp = ap->a_dvp;
746 struct vnode **vpp = ap->a_vpp;
747 int flags = cnp->cn_flags;
749 struct nfsmount *nmp;
751 struct mbuf *mreq, *mrep, *md, *mb;
755 int lockparent, wantparent, error = 0, attrflag, fhsize;
756 int v3 = NFS_ISV3(dvp);
757 struct thread *td = cnp->cn_thread;
760 cnp->cn_flags &= ~PDIRUNLOCK;
761 if ((flags & ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
762 (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
764 if (dvp->v_type != VDIR)
766 lockparent = flags & LOCKPARENT;
767 wantparent = flags & (LOCKPARENT|WANTPARENT);
768 nmp = VFSTONFS(dvp->v_mount);
770 if ((error = cache_lookup(dvp, vpp, cnp)) && error != ENOENT) {
774 if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td)) != 0) {
782 * See the comment starting `Step through' in ufs/ufs_lookup.c
783 * for an explanation of the locking protocol
788 } else if (flags & ISDOTDOT) {
789 VOP_UNLOCK(dvp, 0, td);
790 cnp->cn_flags |= PDIRUNLOCK;
791 error = vget(newvp, LK_EXCLUSIVE, td);
792 if (!error && lockparent && (flags & ISLASTCN)) {
793 error = vn_lock(dvp, LK_EXCLUSIVE, td);
795 cnp->cn_flags &= ~PDIRUNLOCK;
798 error = vget(newvp, LK_EXCLUSIVE, td);
799 if (!lockparent || error || !(flags & ISLASTCN)) {
800 VOP_UNLOCK(dvp, 0, td);
801 cnp->cn_flags |= PDIRUNLOCK;
805 if (vpid == newvp->v_id) {
806 if (!VOP_GETATTR(newvp, &vattr, cnp->cn_cred, td)
807 && vattr.va_ctime.tv_sec == VTONFS(newvp)->n_ctime) {
808 nfsstats.lookupcache_hits++;
809 if (cnp->cn_nameiop != LOOKUP &&
811 cnp->cn_flags |= SAVENAME;
817 if (lockparent && dvp != newvp && (flags & ISLASTCN))
818 VOP_UNLOCK(dvp, 0, td);
820 error = vn_lock(dvp, LK_EXCLUSIVE, td);
823 cnp->cn_flags |= PDIRUNLOCK;
826 cnp->cn_flags &= ~PDIRUNLOCK;
830 nfsstats.lookupcache_misses++;
831 nfsstats.rpccnt[NFSPROC_LOOKUP]++;
832 len = cnp->cn_namelen;
833 mreq = nfsm_reqhead(dvp, NFSPROC_LOOKUP,
834 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len));
836 bpos = mtod(mb, caddr_t);
838 nfsm_strtom(cnp->cn_nameptr, len, NFS_MAXNAMLEN);
839 nfsm_request(dvp, NFSPROC_LOOKUP, cnp->cn_thread, cnp->cn_cred);
841 nfsm_postop_attr(dvp, attrflag);
845 nfsm_getfh(fhp, fhsize, v3);
848 * Handle RENAME case...
850 if (cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN)) {
851 if (NFS_CMPFH(np, fhp, fhsize)) {
855 error = nfs_nget(dvp->v_mount, fhp, fhsize, &np);
862 nfsm_postop_attr(newvp, attrflag);
863 nfsm_postop_attr(dvp, attrflag);
865 nfsm_loadattr(newvp, (struct vattr *)0);
868 cnp->cn_flags |= SAVENAME;
870 VOP_UNLOCK(dvp, 0, td);
871 cnp->cn_flags |= PDIRUNLOCK;
876 if (flags & ISDOTDOT) {
877 VOP_UNLOCK(dvp, 0, td);
878 error = nfs_nget(dvp->v_mount, fhp, fhsize, &np);
880 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
884 if (lockparent && (flags & ISLASTCN)) {
885 error = vn_lock(dvp, LK_EXCLUSIVE, td);
887 cnp->cn_flags |= PDIRUNLOCK;
892 cnp->cn_flags |= PDIRUNLOCK;
893 } else if (NFS_CMPFH(np, fhp, fhsize)) {
897 error = nfs_nget(dvp->v_mount, fhp, fhsize, &np);
902 if (!lockparent || !(flags & ISLASTCN)) {
903 cnp->cn_flags |= PDIRUNLOCK;
904 VOP_UNLOCK(dvp, 0, td);
909 nfsm_postop_attr(newvp, attrflag);
910 nfsm_postop_attr(dvp, attrflag);
912 nfsm_loadattr(newvp, (struct vattr *)0);
913 if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
914 cnp->cn_flags |= SAVENAME;
915 if ((cnp->cn_flags & MAKEENTRY) &&
916 (cnp->cn_nameiop != DELETE || !(flags & ISLASTCN))) {
917 np->n_ctime = np->n_vattr.va_ctime.tv_sec;
918 cache_enter(dvp, newvp, cnp);
924 if (newvp != NULLVP) {
928 if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) &&
929 (flags & ISLASTCN) && error == ENOENT) {
931 VOP_UNLOCK(dvp, 0, td);
932 cnp->cn_flags |= PDIRUNLOCK;
934 if (dvp->v_mount->mnt_flag & MNT_RDONLY)
939 if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
940 cnp->cn_flags |= SAVENAME;
947 * Just call nfs_bioread() to do the work.
950 nfs_read(struct vop_read_args *ap)
952 struct vnode *vp = ap->a_vp;
954 if (vp->v_type != VREG)
956 return (nfs_bioread(vp, ap->a_uio, ap->a_ioflag, ap->a_cred));
963 nfs_readlink(struct vop_readlink_args *ap)
965 struct vnode *vp = ap->a_vp;
967 if (vp->v_type != VLNK)
969 return (nfs_bioread(vp, ap->a_uio, 0, ap->a_cred));
974 * Called by nfs_doio() from below the buffer cache.
977 nfs_readlinkrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred)
980 int error = 0, len, attrflag;
981 struct mbuf *mreq, *mrep, *md, *mb;
982 int v3 = NFS_ISV3(vp);
984 nfsstats.rpccnt[NFSPROC_READLINK]++;
985 mreq = nfsm_reqhead(vp, NFSPROC_READLINK, NFSX_FH(v3));
987 bpos = mtod(mb, caddr_t);
989 nfsm_request(vp, NFSPROC_READLINK, uiop->uio_td, cred);
991 nfsm_postop_attr(vp, attrflag);
993 nfsm_strsiz(len, NFS_MAXPATHLEN);
994 if (len == NFS_MAXPATHLEN) {
995 struct nfsnode *np = VTONFS(vp);
996 if (np->n_size && np->n_size < NFS_MAXPATHLEN)
999 nfsm_mtouio(uiop, len);
1011 nfs_readrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred)
1015 struct mbuf *mreq, *mrep, *md, *mb;
1016 struct nfsmount *nmp;
1017 int error = 0, len, retlen, tsiz, eof, attrflag;
1018 int v3 = NFS_ISV3(vp);
1023 nmp = VFSTONFS(vp->v_mount);
1024 tsiz = uiop->uio_resid;
1025 if (uiop->uio_offset + tsiz > nmp->nm_maxfilesize)
1028 nfsstats.rpccnt[NFSPROC_READ]++;
1029 len = (tsiz > nmp->nm_rsize) ? nmp->nm_rsize : tsiz;
1030 mreq = nfsm_reqhead(vp, NFSPROC_READ, NFSX_FH(v3) + NFSX_UNSIGNED * 3);
1032 bpos = mtod(mb, caddr_t);
1034 tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED * 3);
1036 txdr_hyper(uiop->uio_offset, tl);
1037 *(tl + 2) = txdr_unsigned(len);
1039 *tl++ = txdr_unsigned(uiop->uio_offset);
1040 *tl++ = txdr_unsigned(len);
1043 nfsm_request(vp, NFSPROC_READ, uiop->uio_td, cred);
1045 nfsm_postop_attr(vp, attrflag);
1050 tl = nfsm_dissect(u_int32_t *, 2 * NFSX_UNSIGNED);
1051 eof = fxdr_unsigned(int, *(tl + 1));
1053 nfsm_loadattr(vp, (struct vattr *)0);
1054 nfsm_strsiz(retlen, nmp->nm_rsize);
1055 nfsm_mtouio(uiop, retlen);
1059 if (eof || retlen == 0) {
1062 } else if (retlen < len) {
1074 nfs_writerpc(struct vnode *vp, struct uio *uiop, struct ucred *cred,
1075 int *iomode, int *must_commit)
1080 struct mbuf *mreq, *mrep, *md, *mb;
1081 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
1082 int error = 0, len, tsiz, wccflag = NFSV3_WCCRATTR, rlen, commit;
1083 int v3 = NFS_ISV3(vp), committed = NFSV3WRITE_FILESYNC;
1086 if (uiop->uio_iovcnt != 1)
1087 panic("nfs: writerpc iovcnt > 1");
1090 tsiz = uiop->uio_resid;
1091 if (uiop->uio_offset + tsiz > nmp->nm_maxfilesize)
1094 nfsstats.rpccnt[NFSPROC_WRITE]++;
1095 len = (tsiz > nmp->nm_wsize) ? nmp->nm_wsize : tsiz;
1096 mreq = nfsm_reqhead(vp, NFSPROC_WRITE,
1097 NFSX_FH(v3) + 5 * NFSX_UNSIGNED + nfsm_rndup(len));
1099 bpos = mtod(mb, caddr_t);
1102 tl = nfsm_build(u_int32_t *, 5 * NFSX_UNSIGNED);
1103 txdr_hyper(uiop->uio_offset, tl);
1105 *tl++ = txdr_unsigned(len);
1106 *tl++ = txdr_unsigned(*iomode);
1107 *tl = txdr_unsigned(len);
1111 tl = nfsm_build(u_int32_t *, 4 * NFSX_UNSIGNED);
1112 /* Set both "begin" and "current" to non-garbage. */
1113 x = txdr_unsigned((u_int32_t)uiop->uio_offset);
1114 *tl++ = x; /* "begin offset" */
1115 *tl++ = x; /* "current offset" */
1116 x = txdr_unsigned(len);
1117 *tl++ = x; /* total to this offset */
1118 *tl = x; /* size of this write */
1120 nfsm_uiotom(uiop, len);
1121 nfsm_request(vp, NFSPROC_WRITE, uiop->uio_td, cred);
1123 wccflag = NFSV3_WCCCHK;
1124 nfsm_wcc_data(vp, wccflag);
1126 tl = nfsm_dissect(u_int32_t *, 2 * NFSX_UNSIGNED
1127 + NFSX_V3WRITEVERF);
1128 rlen = fxdr_unsigned(int, *tl++);
1133 } else if (rlen < len) {
1134 backup = len - rlen;
1135 uiop->uio_iov->iov_base -= backup;
1136 uiop->uio_iov->iov_len += backup;
1137 uiop->uio_offset -= backup;
1138 uiop->uio_resid += backup;
1141 commit = fxdr_unsigned(int, *tl++);
1144 * Return the lowest committment level
1145 * obtained by any of the RPCs.
1147 if (committed == NFSV3WRITE_FILESYNC)
1149 else if (committed == NFSV3WRITE_DATASYNC &&
1150 commit == NFSV3WRITE_UNSTABLE)
1152 if ((nmp->nm_state & NFSSTA_HASWRITEVERF) == 0){
1153 bcopy((caddr_t)tl, (caddr_t)nmp->nm_verf,
1155 nmp->nm_state |= NFSSTA_HASWRITEVERF;
1156 } else if (bcmp((caddr_t)tl,
1157 (caddr_t)nmp->nm_verf, NFSX_V3WRITEVERF)) {
1159 bcopy((caddr_t)tl, (caddr_t)nmp->nm_verf,
1164 nfsm_loadattr(vp, (struct vattr *)0);
1166 VTONFS(vp)->n_mtime = VTONFS(vp)->n_vattr.va_mtime.tv_sec;
1173 if (vp->v_mount->mnt_flag & MNT_ASYNC)
1174 committed = NFSV3WRITE_FILESYNC;
1175 *iomode = committed;
1177 uiop->uio_resid = tsiz;
1183 * For NFS v2 this is a kludge. Use a create rpc but with the IFMT bits of the
1184 * mode set to specify the file type and the size field for rdev.
1187 nfs_mknodrpc(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp,
1190 struct nfsv2_sattr *sp;
1192 struct vnode *newvp = (struct vnode *)0;
1193 struct nfsnode *np = (struct nfsnode *)0;
1196 int error = 0, wccflag = NFSV3_WCCRATTR, gotvp = 0;
1197 struct mbuf *mreq, *mrep, *md, *mb;
1199 int v3 = NFS_ISV3(dvp);
1201 if (vap->va_type == VCHR || vap->va_type == VBLK)
1202 rdev = txdr_unsigned(vap->va_rdev);
1203 else if (vap->va_type == VFIFO || vap->va_type == VSOCK)
1206 return (EOPNOTSUPP);
1208 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread)) != 0) {
1211 nfsstats.rpccnt[NFSPROC_MKNOD]++;
1212 mreq = nfsm_reqhead(dvp, NFSPROC_MKNOD, NFSX_FH(v3) + 4 * NFSX_UNSIGNED +
1213 + nfsm_rndup(cnp->cn_namelen) + NFSX_SATTR(v3));
1215 bpos = mtod(mb, caddr_t);
1216 nfsm_fhtom(dvp, v3);
1217 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
1219 tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED);
1220 *tl++ = vtonfsv3_type(vap->va_type);
1221 nfsm_v3attrbuild(vap, FALSE);
1222 if (vap->va_type == VCHR || vap->va_type == VBLK) {
1223 tl = nfsm_build(u_int32_t *, 2 * NFSX_UNSIGNED);
1224 *tl++ = txdr_unsigned(umajor(vap->va_rdev));
1225 *tl = txdr_unsigned(uminor(vap->va_rdev));
1228 sp = nfsm_build(struct nfsv2_sattr *, NFSX_V2SATTR);
1229 sp->sa_mode = vtonfsv2_mode(vap->va_type, vap->va_mode);
1230 sp->sa_uid = nfs_xdrneg1;
1231 sp->sa_gid = nfs_xdrneg1;
1233 txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
1234 txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
1236 nfsm_request(dvp, NFSPROC_MKNOD, cnp->cn_thread, cnp->cn_cred);
1238 nfsm_mtofh(dvp, newvp, v3, gotvp);
1242 newvp = (struct vnode *)0;
1244 error = nfs_lookitup(dvp, cnp->cn_nameptr,
1245 cnp->cn_namelen, cnp->cn_cred, cnp->cn_thread, &np);
1251 nfsm_wcc_data(dvp, wccflag);
1258 if (cnp->cn_flags & MAKEENTRY)
1259 cache_enter(dvp, newvp, cnp);
1262 VTONFS(dvp)->n_flag |= NMODIFIED;
1264 VTONFS(dvp)->n_attrstamp = 0;
1270 * just call nfs_mknodrpc() to do the work.
1274 nfs_mknod(struct vop_mknod_args *ap)
1277 return nfs_mknodrpc(ap->a_dvp, ap->a_vpp, ap->a_cnp, ap->a_vap);
1280 static u_long create_verf;
1282 * nfs file create call
1285 nfs_create(struct vop_create_args *ap)
1287 struct vnode *dvp = ap->a_dvp;
1288 struct vattr *vap = ap->a_vap;
1289 struct componentname *cnp = ap->a_cnp;
1290 struct nfsv2_sattr *sp;
1292 struct nfsnode *np = (struct nfsnode *)0;
1293 struct vnode *newvp = (struct vnode *)0;
1295 int error = 0, wccflag = NFSV3_WCCRATTR, gotvp = 0, fmode = 0;
1296 struct mbuf *mreq, *mrep, *md, *mb;
1298 int v3 = NFS_ISV3(dvp);
1301 * Oops, not for me..
1303 if (vap->va_type == VSOCK)
1304 return (nfs_mknodrpc(dvp, ap->a_vpp, cnp, vap));
1306 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread)) != 0) {
1309 if (vap->va_vaflags & VA_EXCLUSIVE)
1312 nfsstats.rpccnt[NFSPROC_CREATE]++;
1313 mreq = nfsm_reqhead(dvp, NFSPROC_CREATE, NFSX_FH(v3) + 2 * NFSX_UNSIGNED +
1314 nfsm_rndup(cnp->cn_namelen) + NFSX_SATTR(v3));
1316 bpos = mtod(mb, caddr_t);
1317 nfsm_fhtom(dvp, v3);
1318 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
1320 tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED);
1321 if (fmode & O_EXCL) {
1322 *tl = txdr_unsigned(NFSV3CREATE_EXCLUSIVE);
1323 tl = nfsm_build(u_int32_t *, NFSX_V3CREATEVERF);
1325 if (!TAILQ_EMPTY(&in_ifaddrhead))
1326 *tl++ = IA_SIN(TAILQ_FIRST(&in_ifaddrhead))->sin_addr.s_addr;
1329 *tl++ = create_verf;
1330 *tl = ++create_verf;
1332 *tl = txdr_unsigned(NFSV3CREATE_UNCHECKED);
1333 nfsm_v3attrbuild(vap, FALSE);
1336 sp = nfsm_build(struct nfsv2_sattr *, NFSX_V2SATTR);
1337 sp->sa_mode = vtonfsv2_mode(vap->va_type, vap->va_mode);
1338 sp->sa_uid = nfs_xdrneg1;
1339 sp->sa_gid = nfs_xdrneg1;
1341 txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
1342 txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
1344 nfsm_request(dvp, NFSPROC_CREATE, cnp->cn_thread, cnp->cn_cred);
1346 nfsm_mtofh(dvp, newvp, v3, gotvp);
1350 newvp = (struct vnode *)0;
1352 error = nfs_lookitup(dvp, cnp->cn_nameptr,
1353 cnp->cn_namelen, cnp->cn_cred, cnp->cn_thread, &np);
1359 nfsm_wcc_data(dvp, wccflag);
1363 if (v3 && (fmode & O_EXCL) && error == NFSERR_NOTSUPP) {
1369 } else if (v3 && (fmode & O_EXCL)) {
1371 * We are normally called with only a partially initialized
1372 * VAP. Since the NFSv3 spec says that server may use the
1373 * file attributes to store the verifier, the spec requires
1374 * us to do a SETATTR RPC. FreeBSD servers store the verifier
1375 * in atime, but we can't really assume that all servers will
1376 * so we ensure that our SETATTR sets both atime and mtime.
1378 if (vap->va_mtime.tv_sec == VNOVAL)
1379 vfs_timestamp(&vap->va_mtime);
1380 if (vap->va_atime.tv_sec == VNOVAL)
1381 vap->va_atime = vap->va_mtime;
1382 error = nfs_setattrrpc(newvp, vap, cnp->cn_cred, cnp->cn_thread);
1385 if (cnp->cn_flags & MAKEENTRY)
1386 cache_enter(dvp, newvp, cnp);
1389 VTONFS(dvp)->n_flag |= NMODIFIED;
1391 VTONFS(dvp)->n_attrstamp = 0;
1396 * nfs file remove call
1397 * To try and make nfs semantics closer to ufs semantics, a file that has
1398 * other processes using the vnode is renamed instead of removed and then
1399 * removed later on the last close.
1400 * - If v_usecount > 1
1401 * If a rename is not already in the works
1402 * call nfs_sillyrename() to set it up
1407 nfs_remove(struct vop_remove_args *ap)
1409 struct vnode *vp = ap->a_vp;
1410 struct vnode *dvp = ap->a_dvp;
1411 struct componentname *cnp = ap->a_cnp;
1412 struct nfsnode *np = VTONFS(vp);
1417 if ((cnp->cn_flags & HASBUF) == 0)
1418 panic("nfs_remove: no name");
1419 if (vp->v_usecount < 1)
1420 panic("nfs_remove: bad v_usecount");
1422 if (vp->v_type == VDIR)
1424 else if (vp->v_usecount == 1 || (np->n_sillyrename &&
1425 VOP_GETATTR(vp, &vattr, cnp->cn_cred, cnp->cn_thread) == 0 &&
1426 vattr.va_nlink > 1)) {
1428 * Purge the name cache so that the chance of a lookup for
1429 * the name succeeding while the remove is in progress is
1430 * minimized. Without node locking it can still happen, such
1431 * that an I/O op returns ESTALE, but since you get this if
1432 * another host removes the file..
1436 * throw away biocache buffers, mainly to avoid
1437 * unnecessary delayed writes later.
1439 error = nfs_vinvalbuf(vp, 0, cnp->cn_cred, cnp->cn_thread, 1);
1442 error = nfs_removerpc(dvp, cnp->cn_nameptr,
1443 cnp->cn_namelen, cnp->cn_cred, cnp->cn_thread);
1445 * Kludge City: If the first reply to the remove rpc is lost..
1446 * the reply to the retransmitted request will be ENOENT
1447 * since the file was in fact removed
1448 * Therefore, we cheat and return success.
1450 if (error == ENOENT)
1452 } else if (!np->n_sillyrename)
1453 error = nfs_sillyrename(dvp, vp, cnp);
1454 np->n_attrstamp = 0;
1459 * nfs file remove rpc called from nfs_inactive
1462 nfs_removeit(struct sillyrename *sp)
1465 return (nfs_removerpc(sp->s_dvp, sp->s_name, sp->s_namlen, sp->s_cred,
1466 (struct thread *)0));
1470 * Nfs remove rpc, called from nfs_remove() and nfs_removeit().
1473 nfs_removerpc(struct vnode *dvp, const char *name, int namelen,
1474 struct ucred *cred, struct thread *td)
1477 int error = 0, wccflag = NFSV3_WCCRATTR;
1478 struct mbuf *mreq, *mrep, *md, *mb;
1479 int v3 = NFS_ISV3(dvp);
1481 nfsstats.rpccnt[NFSPROC_REMOVE]++;
1482 mreq = nfsm_reqhead(dvp, NFSPROC_REMOVE,
1483 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(namelen));
1485 bpos = mtod(mb, caddr_t);
1486 nfsm_fhtom(dvp, v3);
1487 nfsm_strtom(name, namelen, NFS_MAXNAMLEN);
1488 nfsm_request(dvp, NFSPROC_REMOVE, td, cred);
1490 nfsm_wcc_data(dvp, wccflag);
1493 VTONFS(dvp)->n_flag |= NMODIFIED;
1495 VTONFS(dvp)->n_attrstamp = 0;
1500 * nfs file rename call
1503 nfs_rename(struct vop_rename_args *ap)
1505 struct vnode *fvp = ap->a_fvp;
1506 struct vnode *tvp = ap->a_tvp;
1507 struct vnode *fdvp = ap->a_fdvp;
1508 struct vnode *tdvp = ap->a_tdvp;
1509 struct componentname *tcnp = ap->a_tcnp;
1510 struct componentname *fcnp = ap->a_fcnp;
1514 if ((tcnp->cn_flags & HASBUF) == 0 ||
1515 (fcnp->cn_flags & HASBUF) == 0)
1516 panic("nfs_rename: no name");
1518 /* Check for cross-device rename */
1519 if ((fvp->v_mount != tdvp->v_mount) ||
1520 (tvp && (fvp->v_mount != tvp->v_mount))) {
1526 * We have to flush B_DELWRI data prior to renaming
1527 * the file. If we don't, the delayed-write buffers
1528 * can be flushed out later after the file has gone stale
1529 * under NFSV3. NFSV2 does not have this problem because
1530 * ( as far as I can tell ) it flushes dirty buffers more
1534 VOP_FSYNC(fvp, fcnp->cn_cred, MNT_WAIT, fcnp->cn_thread);
1536 VOP_FSYNC(tvp, tcnp->cn_cred, MNT_WAIT, tcnp->cn_thread);
1539 * If the tvp exists and is in use, sillyrename it before doing the
1540 * rename of the new file over it.
1541 * XXX Can't sillyrename a directory.
1543 if (tvp && tvp->v_usecount > 1 && !VTONFS(tvp)->n_sillyrename &&
1544 tvp->v_type != VDIR && !nfs_sillyrename(tdvp, tvp, tcnp)) {
1549 error = nfs_renamerpc(fdvp, fcnp->cn_nameptr, fcnp->cn_namelen,
1550 tdvp, tcnp->cn_nameptr, tcnp->cn_namelen, tcnp->cn_cred,
1553 if (fvp->v_type == VDIR) {
1554 if (tvp != NULL && tvp->v_type == VDIR)
1569 * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry.
1571 if (error == ENOENT)
1577 * nfs file rename rpc called from nfs_remove() above
1580 nfs_renameit(struct vnode *sdvp, struct componentname *scnp,
1581 struct sillyrename *sp)
1584 return (nfs_renamerpc(sdvp, scnp->cn_nameptr, scnp->cn_namelen, sdvp,
1585 sp->s_name, sp->s_namlen, scnp->cn_cred, scnp->cn_thread));
1589 * Do an nfs rename rpc. Called from nfs_rename() and nfs_renameit().
1592 nfs_renamerpc(struct vnode *fdvp, const char *fnameptr, int fnamelen,
1593 struct vnode *tdvp, const char *tnameptr, int tnamelen, struct ucred *cred,
1597 int error = 0, fwccflag = NFSV3_WCCRATTR, twccflag = NFSV3_WCCRATTR;
1598 struct mbuf *mreq, *mrep, *md, *mb;
1599 int v3 = NFS_ISV3(fdvp);
1601 nfsstats.rpccnt[NFSPROC_RENAME]++;
1602 mreq = nfsm_reqhead(fdvp, NFSPROC_RENAME,
1603 (NFSX_FH(v3) + NFSX_UNSIGNED)*2 + nfsm_rndup(fnamelen) +
1604 nfsm_rndup(tnamelen));
1606 bpos = mtod(mb, caddr_t);
1607 nfsm_fhtom(fdvp, v3);
1608 nfsm_strtom(fnameptr, fnamelen, NFS_MAXNAMLEN);
1609 nfsm_fhtom(tdvp, v3);
1610 nfsm_strtom(tnameptr, tnamelen, NFS_MAXNAMLEN);
1611 nfsm_request(fdvp, NFSPROC_RENAME, td, cred);
1613 nfsm_wcc_data(fdvp, fwccflag);
1614 nfsm_wcc_data(tdvp, twccflag);
1618 VTONFS(fdvp)->n_flag |= NMODIFIED;
1619 VTONFS(tdvp)->n_flag |= NMODIFIED;
1621 VTONFS(fdvp)->n_attrstamp = 0;
1623 VTONFS(tdvp)->n_attrstamp = 0;
1628 * nfs hard link create call
1631 nfs_link(struct vop_link_args *ap)
1633 struct vnode *vp = ap->a_vp;
1634 struct vnode *tdvp = ap->a_tdvp;
1635 struct componentname *cnp = ap->a_cnp;
1637 int error = 0, wccflag = NFSV3_WCCRATTR, attrflag = 0;
1638 struct mbuf *mreq, *mrep, *md, *mb;
1641 if (vp->v_mount != tdvp->v_mount) {
1646 * Push all writes to the server, so that the attribute cache
1647 * doesn't get "out of sync" with the server.
1648 * XXX There should be a better way!
1650 VOP_FSYNC(vp, cnp->cn_cred, MNT_WAIT, cnp->cn_thread);
1653 nfsstats.rpccnt[NFSPROC_LINK]++;
1654 mreq = nfsm_reqhead(vp, NFSPROC_LINK,
1655 NFSX_FH(v3)*2 + NFSX_UNSIGNED + nfsm_rndup(cnp->cn_namelen));
1657 bpos = mtod(mb, caddr_t);
1659 nfsm_fhtom(tdvp, v3);
1660 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
1661 nfsm_request(vp, NFSPROC_LINK, cnp->cn_thread, cnp->cn_cred);
1663 nfsm_postop_attr(vp, attrflag);
1664 nfsm_wcc_data(tdvp, wccflag);
1668 VTONFS(tdvp)->n_flag |= NMODIFIED;
1670 VTONFS(vp)->n_attrstamp = 0;
1672 VTONFS(tdvp)->n_attrstamp = 0;
1674 * Kludge: Map EEXIST => 0 assuming that it is a reply to a retry.
1676 if (error == EEXIST)
1682 * nfs symbolic link create call
1685 nfs_symlink(struct vop_symlink_args *ap)
1687 struct vnode *dvp = ap->a_dvp;
1688 struct vattr *vap = ap->a_vap;
1689 struct componentname *cnp = ap->a_cnp;
1690 struct nfsv2_sattr *sp;
1692 int slen, error = 0, wccflag = NFSV3_WCCRATTR, gotvp;
1693 struct mbuf *mreq, *mrep, *md, *mb;
1694 struct vnode *newvp = (struct vnode *)0;
1695 int v3 = NFS_ISV3(dvp);
1697 nfsstats.rpccnt[NFSPROC_SYMLINK]++;
1698 slen = strlen(ap->a_target);
1699 mreq = nfsm_reqhead(dvp, NFSPROC_SYMLINK, NFSX_FH(v3) + 2*NFSX_UNSIGNED +
1700 nfsm_rndup(cnp->cn_namelen) + nfsm_rndup(slen) + NFSX_SATTR(v3));
1702 bpos = mtod(mb, caddr_t);
1703 nfsm_fhtom(dvp, v3);
1704 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
1706 nfsm_v3attrbuild(vap, FALSE);
1708 nfsm_strtom(ap->a_target, slen, NFS_MAXPATHLEN);
1710 sp = nfsm_build(struct nfsv2_sattr *, NFSX_V2SATTR);
1711 sp->sa_mode = vtonfsv2_mode(VLNK, vap->va_mode);
1712 sp->sa_uid = nfs_xdrneg1;
1713 sp->sa_gid = nfs_xdrneg1;
1714 sp->sa_size = nfs_xdrneg1;
1715 txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
1716 txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
1720 * Issue the NFS request and get the rpc response.
1722 * Only NFSv3 responses returning an error of 0 actually return
1723 * a file handle that can be converted into newvp without having
1724 * to do an extra lookup rpc.
1726 nfsm_request(dvp, NFSPROC_SYMLINK, cnp->cn_thread, cnp->cn_cred);
1729 nfsm_mtofh(dvp, newvp, v3, gotvp);
1730 nfsm_wcc_data(dvp, wccflag);
1734 * out code jumps -> here, mrep is also freed.
1741 * If we get an EEXIST error, silently convert it to no-error
1742 * in case of an NFS retry.
1744 if (error == EEXIST)
1748 * If we do not have (or no longer have) an error, and we could
1749 * not extract the newvp from the response due to the request being
1750 * NFSv2 or the error being EEXIST. We have to do a lookup in order
1751 * to obtain a newvp to return.
1753 if (error == 0 && newvp == NULL) {
1754 struct nfsnode *np = NULL;
1756 error = nfs_lookitup(dvp, cnp->cn_nameptr, cnp->cn_namelen,
1757 cnp->cn_cred, cnp->cn_thread, &np);
1767 VTONFS(dvp)->n_flag |= NMODIFIED;
1769 VTONFS(dvp)->n_attrstamp = 0;
1777 nfs_mkdir(struct vop_mkdir_args *ap)
1779 struct vnode *dvp = ap->a_dvp;
1780 struct vattr *vap = ap->a_vap;
1781 struct componentname *cnp = ap->a_cnp;
1782 struct nfsv2_sattr *sp;
1784 struct nfsnode *np = (struct nfsnode *)0;
1785 struct vnode *newvp = (struct vnode *)0;
1787 int error = 0, wccflag = NFSV3_WCCRATTR;
1789 struct mbuf *mreq, *mrep, *md, *mb;
1791 int v3 = NFS_ISV3(dvp);
1793 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread)) != 0) {
1796 len = cnp->cn_namelen;
1797 nfsstats.rpccnt[NFSPROC_MKDIR]++;
1798 mreq = nfsm_reqhead(dvp, NFSPROC_MKDIR,
1799 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len) + NFSX_SATTR(v3));
1801 bpos = mtod(mb, caddr_t);
1802 nfsm_fhtom(dvp, v3);
1803 nfsm_strtom(cnp->cn_nameptr, len, NFS_MAXNAMLEN);
1805 nfsm_v3attrbuild(vap, FALSE);
1807 sp = nfsm_build(struct nfsv2_sattr *, NFSX_V2SATTR);
1808 sp->sa_mode = vtonfsv2_mode(VDIR, vap->va_mode);
1809 sp->sa_uid = nfs_xdrneg1;
1810 sp->sa_gid = nfs_xdrneg1;
1811 sp->sa_size = nfs_xdrneg1;
1812 txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
1813 txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
1815 nfsm_request(dvp, NFSPROC_MKDIR, cnp->cn_thread, cnp->cn_cred);
1817 nfsm_mtofh(dvp, newvp, v3, gotvp);
1819 nfsm_wcc_data(dvp, wccflag);
1822 VTONFS(dvp)->n_flag |= NMODIFIED;
1824 VTONFS(dvp)->n_attrstamp = 0;
1826 * Kludge: Map EEXIST => 0 assuming that you have a reply to a retry
1827 * if we can succeed in looking up the directory.
1829 if (error == EEXIST || (!error && !gotvp)) {
1832 newvp = (struct vnode *)0;
1834 error = nfs_lookitup(dvp, cnp->cn_nameptr, len, cnp->cn_cred,
1835 cnp->cn_thread, &np);
1838 if (newvp->v_type != VDIR)
1851 * nfs remove directory call
1854 nfs_rmdir(struct vop_rmdir_args *ap)
1856 struct vnode *vp = ap->a_vp;
1857 struct vnode *dvp = ap->a_dvp;
1858 struct componentname *cnp = ap->a_cnp;
1860 int error = 0, wccflag = NFSV3_WCCRATTR;
1861 struct mbuf *mreq, *mrep, *md, *mb;
1862 int v3 = NFS_ISV3(dvp);
1866 nfsstats.rpccnt[NFSPROC_RMDIR]++;
1867 mreq = nfsm_reqhead(dvp, NFSPROC_RMDIR,
1868 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(cnp->cn_namelen));
1870 bpos = mtod(mb, caddr_t);
1871 nfsm_fhtom(dvp, v3);
1872 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
1873 nfsm_request(dvp, NFSPROC_RMDIR, cnp->cn_thread, cnp->cn_cred);
1875 nfsm_wcc_data(dvp, wccflag);
1878 VTONFS(dvp)->n_flag |= NMODIFIED;
1880 VTONFS(dvp)->n_attrstamp = 0;
1884 * Kludge: Map ENOENT => 0 assuming that you have a reply to a retry.
1886 if (error == ENOENT)
1895 nfs_readdir(struct vop_readdir_args *ap)
1897 struct vnode *vp = ap->a_vp;
1898 struct nfsnode *np = VTONFS(vp);
1899 struct uio *uio = ap->a_uio;
1903 if (vp->v_type != VDIR)
1906 * First, check for hit on the EOF offset cache
1908 if (np->n_direofoffset > 0 && uio->uio_offset >= np->n_direofoffset &&
1909 (np->n_flag & NMODIFIED) == 0) {
1910 if (VOP_GETATTR(vp, &vattr, ap->a_cred, uio->uio_td) == 0 &&
1911 np->n_mtime == vattr.va_mtime.tv_sec) {
1912 nfsstats.direofcache_hits++;
1918 * Call nfs_bioread() to do the real work.
1920 tresid = uio->uio_resid;
1921 error = nfs_bioread(vp, uio, 0, ap->a_cred);
1923 if (!error && uio->uio_resid == tresid)
1924 nfsstats.direofcache_misses++;
1930 * Called from below the buffer cache by nfs_doio().
1933 nfs_readdirrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred)
1936 struct dirent *dp = NULL;
1941 struct mbuf *mreq, *mrep, *md, *mb;
1943 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
1944 struct nfsnode *dnp = VTONFS(vp);
1946 int error = 0, tlen, more_dirs = 1, blksiz = 0, bigenough = 1;
1948 int v3 = NFS_ISV3(vp);
1951 if (uiop->uio_iovcnt != 1 || (uiop->uio_offset & (DIRBLKSIZ - 1)) ||
1952 (uiop->uio_resid & (DIRBLKSIZ - 1)))
1953 panic("nfs readdirrpc bad uio");
1957 * If there is no cookie, assume directory was stale.
1959 cookiep = nfs_getcookie(dnp, uiop->uio_offset, 0);
1963 return (NFSERR_BAD_COOKIE);
1965 * Loop around doing readdir rpc's of size nm_readdirsize
1966 * truncated to a multiple of DIRBLKSIZ.
1967 * The stopping criteria is EOF or buffer full.
1969 while (more_dirs && bigenough) {
1970 nfsstats.rpccnt[NFSPROC_READDIR]++;
1971 mreq = nfsm_reqhead(vp, NFSPROC_READDIR, NFSX_FH(v3) +
1974 bpos = mtod(mb, caddr_t);
1977 tl = nfsm_build(u_int32_t *, 5 * NFSX_UNSIGNED);
1978 *tl++ = cookie.nfsuquad[0];
1979 *tl++ = cookie.nfsuquad[1];
1980 *tl++ = dnp->n_cookieverf.nfsuquad[0];
1981 *tl++ = dnp->n_cookieverf.nfsuquad[1];
1983 tl = nfsm_build(u_int32_t *, 2 * NFSX_UNSIGNED);
1984 *tl++ = cookie.nfsuquad[0];
1986 *tl = txdr_unsigned(nmp->nm_readdirsize);
1987 nfsm_request(vp, NFSPROC_READDIR, uiop->uio_td, cred);
1989 nfsm_postop_attr(vp, attrflag);
1991 tl = nfsm_dissect(u_int32_t *,
1993 dnp->n_cookieverf.nfsuquad[0] = *tl++;
1994 dnp->n_cookieverf.nfsuquad[1] = *tl;
2000 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
2001 more_dirs = fxdr_unsigned(int, *tl);
2003 /* loop thru the dir entries, doctoring them to 4bsd form */
2004 while (more_dirs && bigenough) {
2006 tl = nfsm_dissect(u_int32_t *,
2008 fileno = fxdr_hyper(tl);
2009 len = fxdr_unsigned(int, *(tl + 2));
2011 tl = nfsm_dissect(u_int32_t *,
2013 fileno = fxdr_unsigned(u_quad_t, *tl++);
2014 len = fxdr_unsigned(int, *tl);
2016 if (len <= 0 || len > NFS_MAXNAMLEN) {
2021 tlen = nfsm_rndup(len);
2023 tlen += 4; /* To ensure null termination */
2024 left = DIRBLKSIZ - blksiz;
2025 if ((tlen + DIRHDSIZ) > left) {
2026 dp->d_reclen += left;
2027 uiop->uio_iov->iov_base += left;
2028 uiop->uio_iov->iov_len -= left;
2029 uiop->uio_offset += left;
2030 uiop->uio_resid -= left;
2033 if ((tlen + DIRHDSIZ) > uiop->uio_resid)
2036 dp = (struct dirent *)uiop->uio_iov->iov_base;
2037 dp->d_fileno = (int)fileno;
2039 dp->d_reclen = tlen + DIRHDSIZ;
2040 dp->d_type = DT_UNKNOWN;
2041 blksiz += dp->d_reclen;
2042 if (blksiz == DIRBLKSIZ)
2044 uiop->uio_offset += DIRHDSIZ;
2045 uiop->uio_resid -= DIRHDSIZ;
2046 uiop->uio_iov->iov_base += DIRHDSIZ;
2047 uiop->uio_iov->iov_len -= DIRHDSIZ;
2048 nfsm_mtouio(uiop, len);
2049 cp = uiop->uio_iov->iov_base;
2051 *cp = '\0'; /* null terminate */
2052 uiop->uio_iov->iov_base += tlen;
2053 uiop->uio_iov->iov_len -= tlen;
2054 uiop->uio_offset += tlen;
2055 uiop->uio_resid -= tlen;
2057 nfsm_adv(nfsm_rndup(len));
2059 tl = nfsm_dissect(u_int32_t *,
2062 tl = nfsm_dissect(u_int32_t *,
2066 cookie.nfsuquad[0] = *tl++;
2068 cookie.nfsuquad[1] = *tl++;
2073 more_dirs = fxdr_unsigned(int, *tl);
2076 * If at end of rpc data, get the eof boolean
2079 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
2080 more_dirs = (fxdr_unsigned(int, *tl) == 0);
2085 * Fill last record, iff any, out to a multiple of DIRBLKSIZ
2086 * by increasing d_reclen for the last record.
2089 left = DIRBLKSIZ - blksiz;
2090 dp->d_reclen += left;
2091 uiop->uio_iov->iov_base += left;
2092 uiop->uio_iov->iov_len -= left;
2093 uiop->uio_offset += left;
2094 uiop->uio_resid -= left;
2098 * We are now either at the end of the directory or have filled the
2102 dnp->n_direofoffset = uiop->uio_offset;
2104 if (uiop->uio_resid > 0)
2105 printf("EEK! readdirrpc resid > 0\n");
2106 cookiep = nfs_getcookie(dnp, uiop->uio_offset, 1);
2114 * NFS V3 readdir plus RPC. Used in place of nfs_readdirrpc().
2117 nfs_readdirplusrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred)
2123 struct vnode *newvp;
2125 caddr_t bpos, dpos, dpossav1, dpossav2;
2126 struct mbuf *mreq, *mrep, *md, *mb, *mdsav1, *mdsav2;
2127 struct nameidata nami, *ndp = &nami;
2128 struct componentname *cnp = &ndp->ni_cnd;
2130 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2131 struct nfsnode *dnp = VTONFS(vp), *np;
2134 int error = 0, tlen, more_dirs = 1, blksiz = 0, doit, bigenough = 1, i;
2135 int attrflag, fhsize;
2138 dp = (struct dirent *)0;
2141 if (uiop->uio_iovcnt != 1 || (uiop->uio_offset & (DIRBLKSIZ - 1)) ||
2142 (uiop->uio_resid & (DIRBLKSIZ - 1)))
2143 panic("nfs readdirplusrpc bad uio");
2149 * If there is no cookie, assume directory was stale.
2151 cookiep = nfs_getcookie(dnp, uiop->uio_offset, 0);
2155 return (NFSERR_BAD_COOKIE);
2157 * Loop around doing readdir rpc's of size nm_readdirsize
2158 * truncated to a multiple of DIRBLKSIZ.
2159 * The stopping criteria is EOF or buffer full.
2161 while (more_dirs && bigenough) {
2162 nfsstats.rpccnt[NFSPROC_READDIRPLUS]++;
2163 mreq = nfsm_reqhead(vp, NFSPROC_READDIRPLUS,
2164 NFSX_FH(1) + 6 * NFSX_UNSIGNED);
2166 bpos = mtod(mb, caddr_t);
2168 tl = nfsm_build(u_int32_t *, 6 * NFSX_UNSIGNED);
2169 *tl++ = cookie.nfsuquad[0];
2170 *tl++ = cookie.nfsuquad[1];
2171 *tl++ = dnp->n_cookieverf.nfsuquad[0];
2172 *tl++ = dnp->n_cookieverf.nfsuquad[1];
2173 *tl++ = txdr_unsigned(nmp->nm_readdirsize);
2174 *tl = txdr_unsigned(nmp->nm_rsize);
2175 nfsm_request(vp, NFSPROC_READDIRPLUS, uiop->uio_td, cred);
2176 nfsm_postop_attr(vp, attrflag);
2181 tl = nfsm_dissect(u_int32_t *, 3 * NFSX_UNSIGNED);
2182 dnp->n_cookieverf.nfsuquad[0] = *tl++;
2183 dnp->n_cookieverf.nfsuquad[1] = *tl++;
2184 more_dirs = fxdr_unsigned(int, *tl);
2186 /* loop thru the dir entries, doctoring them to 4bsd form */
2187 while (more_dirs && bigenough) {
2188 tl = nfsm_dissect(u_int32_t *, 3 * NFSX_UNSIGNED);
2189 fileno = fxdr_hyper(tl);
2190 len = fxdr_unsigned(int, *(tl + 2));
2191 if (len <= 0 || len > NFS_MAXNAMLEN) {
2196 tlen = nfsm_rndup(len);
2198 tlen += 4; /* To ensure null termination*/
2199 left = DIRBLKSIZ - blksiz;
2200 if ((tlen + DIRHDSIZ) > left) {
2201 dp->d_reclen += left;
2202 uiop->uio_iov->iov_base += left;
2203 uiop->uio_iov->iov_len -= left;
2204 uiop->uio_offset += left;
2205 uiop->uio_resid -= left;
2208 if ((tlen + DIRHDSIZ) > uiop->uio_resid)
2211 dp = (struct dirent *)uiop->uio_iov->iov_base;
2212 dp->d_fileno = (int)fileno;
2214 dp->d_reclen = tlen + DIRHDSIZ;
2215 dp->d_type = DT_UNKNOWN;
2216 blksiz += dp->d_reclen;
2217 if (blksiz == DIRBLKSIZ)
2219 uiop->uio_offset += DIRHDSIZ;
2220 uiop->uio_resid -= DIRHDSIZ;
2221 uiop->uio_iov->iov_base += DIRHDSIZ;
2222 uiop->uio_iov->iov_len -= DIRHDSIZ;
2223 cnp->cn_nameptr = uiop->uio_iov->iov_base;
2224 cnp->cn_namelen = len;
2225 nfsm_mtouio(uiop, len);
2226 cp = uiop->uio_iov->iov_base;
2229 uiop->uio_iov->iov_base += tlen;
2230 uiop->uio_iov->iov_len -= tlen;
2231 uiop->uio_offset += tlen;
2232 uiop->uio_resid -= tlen;
2234 nfsm_adv(nfsm_rndup(len));
2235 tl = nfsm_dissect(u_int32_t *, 3 * NFSX_UNSIGNED);
2237 cookie.nfsuquad[0] = *tl++;
2238 cookie.nfsuquad[1] = *tl++;
2243 * Since the attributes are before the file handle
2244 * (sigh), we must skip over the attributes and then
2245 * come back and get them.
2247 attrflag = fxdr_unsigned(int, *tl);
2251 nfsm_adv(NFSX_V3FATTR);
2252 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
2253 doit = fxdr_unsigned(int, *tl);
2255 nfsm_getfh(fhp, fhsize, 1);
2256 if (NFS_CMPFH(dnp, fhp, fhsize)) {
2261 error = nfs_nget(vp->v_mount, fhp,
2269 if (doit && bigenough) {
2274 nfsm_loadattr(newvp, (struct vattr *)0);
2278 IFTODT(VTTOIF(np->n_vattr.va_type));
2280 cache_enter(ndp->ni_dvp, ndp->ni_vp, cnp);
2283 /* Just skip over the file handle */
2284 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
2285 i = fxdr_unsigned(int, *tl);
2286 nfsm_adv(nfsm_rndup(i));
2288 if (newvp != NULLVP) {
2295 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
2296 more_dirs = fxdr_unsigned(int, *tl);
2299 * If at end of rpc data, get the eof boolean
2302 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
2303 more_dirs = (fxdr_unsigned(int, *tl) == 0);
2308 * Fill last record, iff any, out to a multiple of DIRBLKSIZ
2309 * by increasing d_reclen for the last record.
2312 left = DIRBLKSIZ - blksiz;
2313 dp->d_reclen += left;
2314 uiop->uio_iov->iov_base += left;
2315 uiop->uio_iov->iov_len -= left;
2316 uiop->uio_offset += left;
2317 uiop->uio_resid -= left;
2321 * We are now either at the end of the directory or have filled the
2325 dnp->n_direofoffset = uiop->uio_offset;
2327 if (uiop->uio_resid > 0)
2328 printf("EEK! readdirplusrpc resid > 0\n");
2329 cookiep = nfs_getcookie(dnp, uiop->uio_offset, 1);
2333 if (newvp != NULLVP) {
2344 * Silly rename. To make the NFS filesystem that is stateless look a little
2345 * more like the "ufs" a remove of an active vnode is translated to a rename
2346 * to a funny looking filename that is removed by nfs_inactive on the
2347 * nfsnode. There is the potential for another process on a different client
2348 * to create the same funny name between the nfs_lookitup() fails and the
2349 * nfs_rename() completes, but...
2352 nfs_sillyrename(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
2354 struct sillyrename *sp;
2362 if (vp->v_type == VDIR)
2363 panic("nfs: sillyrename dir");
2365 MALLOC(sp, struct sillyrename *, sizeof (struct sillyrename),
2366 M_NFSREQ, M_WAITOK);
2367 sp->s_cred = crhold(cnp->cn_cred);
2371 /* Fudge together a funny name */
2372 pid = cnp->cn_thread->td_proc->p_pid;
2373 sp->s_namlen = sprintf(sp->s_name, ".nfsA%04x4.4", pid);
2375 /* Try lookitups until we get one that isn't there */
2376 while (nfs_lookitup(dvp, sp->s_name, sp->s_namlen, sp->s_cred,
2377 cnp->cn_thread, (struct nfsnode **)0) == 0) {
2379 if (sp->s_name[4] > 'z') {
2384 error = nfs_renameit(dvp, cnp, sp);
2387 error = nfs_lookitup(dvp, sp->s_name, sp->s_namlen, sp->s_cred,
2388 cnp->cn_thread, &np);
2389 np->n_sillyrename = sp;
2394 free((caddr_t)sp, M_NFSREQ);
2399 * Look up a file name and optionally either update the file handle or
2400 * allocate an nfsnode, depending on the value of npp.
2401 * npp == NULL --> just do the lookup
2402 * *npp == NULL --> allocate a new nfsnode and make sure attributes are
2404 * *npp != NULL --> update the file handle in the vnode
2407 nfs_lookitup(struct vnode *dvp, const char *name, int len, struct ucred *cred,
2408 struct thread *td, struct nfsnode **npp)
2410 struct vnode *newvp = (struct vnode *)0;
2411 struct nfsnode *np, *dnp = VTONFS(dvp);
2413 int error = 0, fhlen, attrflag;
2414 struct mbuf *mreq, *mrep, *md, *mb;
2416 int v3 = NFS_ISV3(dvp);
2418 nfsstats.rpccnt[NFSPROC_LOOKUP]++;
2419 mreq = nfsm_reqhead(dvp, NFSPROC_LOOKUP,
2420 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len));
2422 bpos = mtod(mb, caddr_t);
2423 nfsm_fhtom(dvp, v3);
2424 nfsm_strtom(name, len, NFS_MAXNAMLEN);
2425 nfsm_request(dvp, NFSPROC_LOOKUP, td, cred);
2426 if (npp && !error) {
2427 nfsm_getfh(nfhp, fhlen, v3);
2430 if (np->n_fhsize > NFS_SMALLFH && fhlen <= NFS_SMALLFH) {
2431 free((caddr_t)np->n_fhp, M_NFSBIGFH);
2432 np->n_fhp = &np->n_fh;
2433 } else if (np->n_fhsize <= NFS_SMALLFH && fhlen>NFS_SMALLFH)
2434 np->n_fhp =(nfsfh_t *)malloc(fhlen, M_NFSBIGFH, M_WAITOK);
2435 bcopy((caddr_t)nfhp, (caddr_t)np->n_fhp, fhlen);
2436 np->n_fhsize = fhlen;
2438 } else if (NFS_CMPFH(dnp, nfhp, fhlen)) {
2442 error = nfs_nget(dvp->v_mount, nfhp, fhlen, &np);
2450 nfsm_postop_attr(newvp, attrflag);
2451 if (!attrflag && *npp == NULL) {
2460 nfsm_loadattr(newvp, (struct vattr *)0);
2464 if (npp && *npp == NULL) {
2479 * Nfs Version 3 commit rpc
2482 nfs_commit(struct vnode *vp, u_quad_t offset, int cnt, struct ucred *cred,
2486 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2488 int error = 0, wccflag = NFSV3_WCCRATTR;
2489 struct mbuf *mreq, *mrep, *md, *mb;
2491 if ((nmp->nm_state & NFSSTA_HASWRITEVERF) == 0)
2493 nfsstats.rpccnt[NFSPROC_COMMIT]++;
2494 mreq = nfsm_reqhead(vp, NFSPROC_COMMIT, NFSX_FH(1));
2496 bpos = mtod(mb, caddr_t);
2498 tl = nfsm_build(u_int32_t *, 3 * NFSX_UNSIGNED);
2499 txdr_hyper(offset, tl);
2501 *tl = txdr_unsigned(cnt);
2502 nfsm_request(vp, NFSPROC_COMMIT, td, cred);
2503 nfsm_wcc_data(vp, wccflag);
2505 tl = nfsm_dissect(u_int32_t *, NFSX_V3WRITEVERF);
2506 if (bcmp((caddr_t)nmp->nm_verf, (caddr_t)tl,
2507 NFSX_V3WRITEVERF)) {
2508 bcopy((caddr_t)tl, (caddr_t)nmp->nm_verf,
2510 error = NFSERR_STALEWRITEVERF;
2520 * For async requests when nfsiod(s) are running, queue the request by
2521 * calling nfs_asyncio(), otherwise just all nfs_doio() to do the
2525 nfs_strategy(struct vop_strategy_args *ap)
2527 struct buf *bp = ap->a_bp;
2532 KASSERT(!(bp->b_flags & B_DONE), ("nfs_strategy: buffer %p unexpectedly marked B_DONE", bp));
2533 KASSERT(BUF_REFCNT(bp) > 0, ("nfs_strategy: buffer %p not locked", bp));
2535 if (bp->b_flags & B_PHYS)
2536 panic("nfs physio");
2538 if (bp->b_flags & B_ASYNC)
2539 td = (struct thread *)0;
2541 td = curthread; /* XXX */
2543 if (bp->b_iocmd == BIO_READ)
2549 * If the op is asynchronous and an i/o daemon is waiting
2550 * queue the request, wake it up and wait for completion
2551 * otherwise just do it ourselves.
2553 if ((bp->b_flags & B_ASYNC) == 0 ||
2554 nfs_asyncio(bp, NOCRED, td))
2555 error = nfs_doio(bp, cr, td);
2560 * fsync vnode op. Just call nfs_flush() with commit == 1.
2564 nfs_fsync(struct vop_fsync_args *ap)
2567 return (nfs_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));
2571 * Flush all the blocks associated with a vnode.
2572 * Walk through the buffer pool and push any dirty pages
2573 * associated with the vnode.
2576 nfs_flush(struct vnode *vp, struct ucred *cred, int waitfor, struct thread *td,
2579 struct nfsnode *np = VTONFS(vp);
2583 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2584 int s, error = 0, slptimeo = 0, slpflag = 0, retv, bvecpos;
2586 u_quad_t off, endoff, toff;
2587 struct ucred* wcred = NULL;
2588 struct buf **bvec = NULL;
2589 #ifndef NFS_COMMITBVECSIZ
2590 #define NFS_COMMITBVECSIZ 20
2592 struct buf *bvec_on_stack[NFS_COMMITBVECSIZ];
2593 int bvecsize = 0, bveccount;
2595 if (nmp->nm_flag & NFSMNT_INT)
2600 * A b_flags == (B_DELWRI | B_NEEDCOMMIT) block has been written to the
2601 * server, but nas not been committed to stable storage on the server
2602 * yet. On the first pass, the byte range is worked out and the commit
2603 * rpc is done. On the second pass, nfs_writebp() is called to do the
2610 if (NFS_ISV3(vp) && commit) {
2613 * Count up how many buffers waiting for a commit.
2616 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
2617 nbp = TAILQ_NEXT(bp, b_vnbufs);
2618 if (BUF_REFCNT(bp) == 0 &&
2619 (bp->b_flags & (B_DELWRI | B_NEEDCOMMIT))
2620 == (B_DELWRI | B_NEEDCOMMIT))
2624 * Allocate space to remember the list of bufs to commit. It is
2625 * important to use M_NOWAIT here to avoid a race with nfs_write.
2626 * If we can't get memory (for whatever reason), we will end up
2627 * committing the buffers one-by-one in the loop below.
2629 if (bvec != NULL && bvec != bvec_on_stack)
2631 if (bveccount > NFS_COMMITBVECSIZ) {
2632 bvec = (struct buf **)
2633 malloc(bveccount * sizeof(struct buf *),
2636 bvec = bvec_on_stack;
2637 bvecsize = NFS_COMMITBVECSIZ;
2639 bvecsize = bveccount;
2641 bvec = bvec_on_stack;
2642 bvecsize = NFS_COMMITBVECSIZ;
2644 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
2645 nbp = TAILQ_NEXT(bp, b_vnbufs);
2646 if (bvecpos >= bvecsize)
2648 if ((bp->b_flags & (B_DELWRI | B_NEEDCOMMIT)) !=
2649 (B_DELWRI | B_NEEDCOMMIT) ||
2650 BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT))
2654 * Work out if all buffers are using the same cred
2655 * so we can deal with them all with one commit.
2657 * NOTE: we are not clearing B_DONE here, so we have
2658 * to do it later on in this routine if we intend to
2659 * initiate I/O on the bp.
2661 * Note: to avoid loopback deadlocks, we do not
2662 * assign b_runningbufspace.
2665 wcred = bp->b_wcred;
2666 else if (wcred != bp->b_wcred)
2668 bp->b_flags |= B_WRITEINPROG;
2669 vfs_busy_pages(bp, 1);
2672 * bp is protected by being locked, but nbp is not
2673 * and vfs_busy_pages() may sleep. We have to
2676 nbp = TAILQ_NEXT(bp, b_vnbufs);
2679 * A list of these buffers is kept so that the
2680 * second loop knows which buffers have actually
2681 * been committed. This is necessary, since there
2682 * may be a race between the commit rpc and new
2683 * uncommitted writes on the file.
2685 bvec[bvecpos++] = bp;
2686 toff = ((u_quad_t)bp->b_blkno) * DEV_BSIZE +
2690 toff += (u_quad_t)(bp->b_dirtyend - bp->b_dirtyoff);
2698 * Commit data on the server, as required.
2699 * If all bufs are using the same wcred, then use that with
2700 * one call for all of them, otherwise commit each one
2703 if (wcred != NOCRED)
2704 retv = nfs_commit(vp, off, (int)(endoff - off),
2708 for (i = 0; i < bvecpos; i++) {
2711 off = ((u_quad_t)bp->b_blkno) * DEV_BSIZE +
2713 size = (u_quad_t)(bp->b_dirtyend
2715 retv = nfs_commit(vp, off, (int)size,
2721 if (retv == NFSERR_STALEWRITEVERF)
2722 nfs_clearcommit(vp->v_mount);
2725 * Now, either mark the blocks I/O done or mark the
2726 * blocks dirty, depending on whether the commit
2729 for (i = 0; i < bvecpos; i++) {
2731 bp->b_flags &= ~(B_NEEDCOMMIT | B_WRITEINPROG | B_CLUSTEROK);
2734 * Error, leave B_DELWRI intact
2736 vfs_unbusy_pages(bp);
2740 * Success, remove B_DELWRI ( bundirty() ).
2742 * b_dirtyoff/b_dirtyend seem to be NFS
2743 * specific. We should probably move that
2744 * into bundirty(). XXX
2748 bp->b_flags |= B_ASYNC;
2750 bp->b_flags &= ~B_DONE;
2751 bp->b_ioflags &= ~BIO_ERROR;
2752 bp->b_dirtyoff = bp->b_dirtyend = 0;
2760 * Start/do any write(s) that are required.
2764 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
2765 nbp = TAILQ_NEXT(bp, b_vnbufs);
2766 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT)) {
2767 if (waitfor != MNT_WAIT || passone)
2769 error = BUF_TIMELOCK(bp, LK_EXCLUSIVE | LK_SLEEPFAIL,
2770 "nfsfsync", slpflag, slptimeo);
2773 panic("nfs_fsync: inconsistent lock");
2774 if (error == ENOLCK)
2776 if (nfs_sigintr(nmp, (struct nfsreq *)0, td->td_proc)) {
2780 if (slpflag == PCATCH) {
2786 if ((bp->b_flags & B_DELWRI) == 0)
2787 panic("nfs_fsync: not dirty");
2788 if ((passone || !commit) && (bp->b_flags & B_NEEDCOMMIT)) {
2793 if (passone || !commit)
2794 bp->b_flags |= B_ASYNC;
2796 bp->b_flags |= B_ASYNC | B_WRITEINPROG;
2806 if (waitfor == MNT_WAIT) {
2807 while (vp->v_numoutput) {
2808 vp->v_flag |= VBWAIT;
2809 error = tsleep((caddr_t)&vp->v_numoutput,
2810 slpflag | (PRIBIO + 1), "nfsfsync", slptimeo);
2812 if (nfs_sigintr(nmp, (struct nfsreq *)0, td->td_proc)) {
2816 if (slpflag == PCATCH) {
2822 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd) && commit) {
2826 if (np->n_flag & NWRITEERR) {
2827 error = np->n_error;
2828 np->n_flag &= ~NWRITEERR;
2831 if (bvec != NULL && bvec != bvec_on_stack)
2837 * NFS advisory byte-level locks.
2840 nfs_advlock(struct vop_advlock_args *ap)
2843 if ((VFSTONFS(ap->a_vp->v_mount)->nm_flag & NFSMNT_NOLOCKD) != 0) {
2844 struct nfsnode *np = VTONFS(ap->a_vp);
2846 return (lf_advlock(ap, &(np->n_lockf), np->n_size));
2848 return (nfs_dolock(ap));
2852 * Print out the contents of an nfsnode.
2855 nfs_print(struct vop_print_args *ap)
2857 struct vnode *vp = ap->a_vp;
2858 struct nfsnode *np = VTONFS(vp);
2860 printf("tag VT_NFS, fileid %ld fsid 0x%x",
2861 np->n_vattr.va_fileid, np->n_vattr.va_fsid);
2862 if (vp->v_type == VFIFO)
2869 * This is the "real" nfs::bwrite(struct buf*).
2870 * B_WRITEINPROG isn't set unless the force flag is one and it
2871 * handles the B_NEEDCOMMIT flag.
2872 * We set B_CACHE if this is a VMIO buffer.
2875 nfs_writebp(struct buf *bp, int force, struct thread *td)
2878 int oldflags = bp->b_flags;
2884 if (BUF_REFCNT(bp) == 0)
2885 panic("bwrite: buffer is not locked???");
2887 if (bp->b_flags & B_INVAL) {
2892 bp->b_flags |= B_CACHE;
2895 * Undirty the bp. We will redirty it later if the I/O fails.
2900 bp->b_flags &= ~B_DONE;
2901 bp->b_ioflags &= ~BIO_ERROR;
2902 bp->b_iocmd = BIO_WRITE;
2904 bp->b_vp->v_numoutput++;
2905 curthread->td_proc->p_stats->p_ru.ru_oublock++;
2909 * Note: to avoid loopback deadlocks, we do not
2910 * assign b_runningbufspace.
2912 vfs_busy_pages(bp, 1);
2915 bp->b_flags |= B_WRITEINPROG;
2919 if( (oldflags & B_ASYNC) == 0) {
2920 int rtval = bufwait(bp);
2922 if (oldflags & B_DELWRI) {
2924 reassignbuf(bp, bp->b_vp);
2936 * nfs special file access vnode op.
2937 * Essentially just get vattr and then imitate iaccess() since the device is
2938 * local to the client.
2941 nfsspec_access(struct vop_access_args *ap)
2945 struct ucred *cred = ap->a_cred;
2946 struct vnode *vp = ap->a_vp;
2947 mode_t mode = ap->a_mode;
2953 * Disallow write attempts on filesystems mounted read-only;
2954 * unless the file is a socket, fifo, or a block or character
2955 * device resident on the filesystem.
2957 if ((mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
2958 switch (vp->v_type) {
2968 * If you're the super-user,
2969 * you always get access.
2971 if (cred->cr_uid == 0)
2974 error = VOP_GETATTR(vp, vap, cred, ap->a_td);
2978 * Access check is based on only one of owner, group, public.
2979 * If not owner, then check group. If not a member of the
2980 * group, then check public access.
2982 if (cred->cr_uid != vap->va_uid) {
2984 gp = cred->cr_groups;
2985 for (i = 0; i < cred->cr_ngroups; i++, gp++)
2986 if (vap->va_gid == *gp)
2992 error = (vap->va_mode & mode) == mode ? 0 : EACCES;
2997 * Read wrapper for special devices.
3000 nfsspec_read(struct vop_read_args *ap)
3002 struct nfsnode *np = VTONFS(ap->a_vp);
3008 getnanotime(&np->n_atim);
3009 return (VOCALL(spec_vnodeop_p, VOFFSET(vop_read), ap));
3013 * Write wrapper for special devices.
3016 nfsspec_write(struct vop_write_args *ap)
3018 struct nfsnode *np = VTONFS(ap->a_vp);
3024 getnanotime(&np->n_mtim);
3025 return (VOCALL(spec_vnodeop_p, VOFFSET(vop_write), ap));
3029 * Close wrapper for special devices.
3031 * Update the times on the nfsnode then do device close.
3034 nfsspec_close(struct vop_close_args *ap)
3036 struct vnode *vp = ap->a_vp;
3037 struct nfsnode *np = VTONFS(vp);
3040 if (np->n_flag & (NACC | NUPD)) {
3042 if (vp->v_usecount == 1 &&
3043 (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
3045 if (np->n_flag & NACC)
3046 vattr.va_atime = np->n_atim;
3047 if (np->n_flag & NUPD)
3048 vattr.va_mtime = np->n_mtim;
3049 (void)VOP_SETATTR(vp, &vattr, ap->a_cred, ap->a_td);
3052 return (VOCALL(spec_vnodeop_p, VOFFSET(vop_close), ap));
3056 * Read wrapper for fifos.
3059 nfsfifo_read(struct vop_read_args *ap)
3061 struct nfsnode *np = VTONFS(ap->a_vp);
3067 getnanotime(&np->n_atim);
3068 return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_read), ap));
3072 * Write wrapper for fifos.
3075 nfsfifo_write(struct vop_write_args *ap)
3077 struct nfsnode *np = VTONFS(ap->a_vp);
3083 getnanotime(&np->n_mtim);
3084 return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_write), ap));
3088 * Close wrapper for fifos.
3090 * Update the times on the nfsnode then do fifo close.
3093 nfsfifo_close(struct vop_close_args *ap)
3095 struct vnode *vp = ap->a_vp;
3096 struct nfsnode *np = VTONFS(vp);
3100 if (np->n_flag & (NACC | NUPD)) {
3102 if (np->n_flag & NACC)
3104 if (np->n_flag & NUPD)
3107 if (vp->v_usecount == 1 &&
3108 (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
3110 if (np->n_flag & NACC)
3111 vattr.va_atime = np->n_atim;
3112 if (np->n_flag & NUPD)
3113 vattr.va_mtime = np->n_mtim;
3114 (void)VOP_SETATTR(vp, &vattr, ap->a_cred, ap->a_td);
3117 return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_close), ap));