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, NULL);
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) {
783 * See the comment starting `Step through' in ufs/ufs_lookup.c
784 * for an explanation of the locking protocol
789 } else if (flags & ISDOTDOT) {
790 VOP_UNLOCK(dvp, 0, td);
791 cnp->cn_flags |= PDIRUNLOCK;
792 error = vget(newvp, LK_EXCLUSIVE, td);
793 if (!error && lockparent && (flags & ISLASTCN)) {
794 error = vn_lock(dvp, LK_EXCLUSIVE, td);
796 cnp->cn_flags &= ~PDIRUNLOCK;
799 error = vget(newvp, LK_EXCLUSIVE, td);
800 if (!lockparent || error || !(flags & ISLASTCN)) {
801 VOP_UNLOCK(dvp, 0, td);
802 cnp->cn_flags |= PDIRUNLOCK;
806 if (vpid == newvp->v_id) {
807 if (!VOP_GETATTR(newvp, &vattr, cnp->cn_cred, td)
808 && vattr.va_ctime.tv_sec == VTONFS(newvp)->n_ctime) {
809 nfsstats.lookupcache_hits++;
810 if (cnp->cn_nameiop != LOOKUP &&
812 cnp->cn_flags |= SAVENAME;
819 if (lockparent && dvp != newvp && (flags & ISLASTCN))
820 VOP_UNLOCK(dvp, 0, td);
823 error = vn_lock(dvp, LK_EXCLUSIVE, td);
826 cnp->cn_flags |= PDIRUNLOCK;
829 cnp->cn_flags &= ~PDIRUNLOCK;
833 nfsstats.lookupcache_misses++;
834 nfsstats.rpccnt[NFSPROC_LOOKUP]++;
835 len = cnp->cn_namelen;
836 mreq = nfsm_reqhead(dvp, NFSPROC_LOOKUP,
837 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len));
839 bpos = mtod(mb, caddr_t);
841 nfsm_strtom(cnp->cn_nameptr, len, NFS_MAXNAMLEN);
842 nfsm_request(dvp, NFSPROC_LOOKUP, cnp->cn_thread, cnp->cn_cred);
844 nfsm_postop_attr(dvp, attrflag);
848 nfsm_getfh(fhp, fhsize, v3);
851 * Handle RENAME case...
853 if (cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN)) {
854 if (NFS_CMPFH(np, fhp, fhsize)) {
858 error = nfs_nget(dvp->v_mount, fhp, fhsize, &np);
865 nfsm_postop_attr(newvp, attrflag);
866 nfsm_postop_attr(dvp, attrflag);
868 nfsm_loadattr(newvp, NULL);
871 cnp->cn_flags |= SAVENAME;
873 VOP_UNLOCK(dvp, 0, td);
874 cnp->cn_flags |= PDIRUNLOCK;
879 if (flags & ISDOTDOT) {
880 VOP_UNLOCK(dvp, 0, td);
881 error = nfs_nget(dvp->v_mount, fhp, fhsize, &np);
883 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
887 if (lockparent && (flags & ISLASTCN)) {
888 error = vn_lock(dvp, LK_EXCLUSIVE, td);
890 cnp->cn_flags |= PDIRUNLOCK;
895 cnp->cn_flags |= PDIRUNLOCK;
896 } else if (NFS_CMPFH(np, fhp, fhsize)) {
900 error = nfs_nget(dvp->v_mount, fhp, fhsize, &np);
905 if (!lockparent || !(flags & ISLASTCN)) {
906 cnp->cn_flags |= PDIRUNLOCK;
907 VOP_UNLOCK(dvp, 0, td);
912 nfsm_postop_attr(newvp, attrflag);
913 nfsm_postop_attr(dvp, attrflag);
915 nfsm_loadattr(newvp, NULL);
916 if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
917 cnp->cn_flags |= SAVENAME;
918 if ((cnp->cn_flags & MAKEENTRY) &&
919 (cnp->cn_nameiop != DELETE || !(flags & ISLASTCN))) {
920 np->n_ctime = np->n_vattr.va_ctime.tv_sec;
921 cache_enter(dvp, newvp, cnp);
927 if (newvp != NULLVP) {
931 if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) &&
932 (flags & ISLASTCN) && error == ENOENT) {
934 VOP_UNLOCK(dvp, 0, td);
935 cnp->cn_flags |= PDIRUNLOCK;
937 if (dvp->v_mount->mnt_flag & MNT_RDONLY)
942 if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
943 cnp->cn_flags |= SAVENAME;
950 * Just call nfs_bioread() to do the work.
953 nfs_read(struct vop_read_args *ap)
955 struct vnode *vp = ap->a_vp;
957 if (vp->v_type != VREG)
959 return (nfs_bioread(vp, ap->a_uio, ap->a_ioflag, ap->a_cred));
966 nfs_readlink(struct vop_readlink_args *ap)
968 struct vnode *vp = ap->a_vp;
970 if (vp->v_type != VLNK)
972 return (nfs_bioread(vp, ap->a_uio, 0, ap->a_cred));
977 * Called by nfs_doio() from below the buffer cache.
980 nfs_readlinkrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred)
983 int error = 0, len, attrflag;
984 struct mbuf *mreq, *mrep, *md, *mb;
985 int v3 = NFS_ISV3(vp);
987 nfsstats.rpccnt[NFSPROC_READLINK]++;
988 mreq = nfsm_reqhead(vp, NFSPROC_READLINK, NFSX_FH(v3));
990 bpos = mtod(mb, caddr_t);
992 nfsm_request(vp, NFSPROC_READLINK, uiop->uio_td, cred);
994 nfsm_postop_attr(vp, attrflag);
996 nfsm_strsiz(len, NFS_MAXPATHLEN);
997 if (len == NFS_MAXPATHLEN) {
998 struct nfsnode *np = VTONFS(vp);
999 if (np->n_size && np->n_size < NFS_MAXPATHLEN)
1002 nfsm_mtouio(uiop, len);
1014 nfs_readrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred)
1018 struct mbuf *mreq, *mrep, *md, *mb;
1019 struct nfsmount *nmp;
1020 int error = 0, len, retlen, tsiz, eof, attrflag;
1021 int v3 = NFS_ISV3(vp);
1026 nmp = VFSTONFS(vp->v_mount);
1027 tsiz = uiop->uio_resid;
1028 if (uiop->uio_offset + tsiz > nmp->nm_maxfilesize)
1031 nfsstats.rpccnt[NFSPROC_READ]++;
1032 len = (tsiz > nmp->nm_rsize) ? nmp->nm_rsize : tsiz;
1033 mreq = nfsm_reqhead(vp, NFSPROC_READ, NFSX_FH(v3) + NFSX_UNSIGNED * 3);
1035 bpos = mtod(mb, caddr_t);
1037 tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED * 3);
1039 txdr_hyper(uiop->uio_offset, tl);
1040 *(tl + 2) = txdr_unsigned(len);
1042 *tl++ = txdr_unsigned(uiop->uio_offset);
1043 *tl++ = txdr_unsigned(len);
1046 nfsm_request(vp, NFSPROC_READ, uiop->uio_td, cred);
1048 nfsm_postop_attr(vp, attrflag);
1053 tl = nfsm_dissect(u_int32_t *, 2 * NFSX_UNSIGNED);
1054 eof = fxdr_unsigned(int, *(tl + 1));
1056 nfsm_loadattr(vp, NULL);
1057 nfsm_strsiz(retlen, nmp->nm_rsize);
1058 nfsm_mtouio(uiop, retlen);
1062 if (eof || retlen == 0) {
1065 } else if (retlen < len) {
1077 nfs_writerpc(struct vnode *vp, struct uio *uiop, struct ucred *cred,
1078 int *iomode, int *must_commit)
1083 struct mbuf *mreq, *mrep, *md, *mb;
1084 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
1085 int error = 0, len, tsiz, wccflag = NFSV3_WCCRATTR, rlen, commit;
1086 int v3 = NFS_ISV3(vp), committed = NFSV3WRITE_FILESYNC;
1089 if (uiop->uio_iovcnt != 1)
1090 panic("nfs: writerpc iovcnt > 1");
1093 tsiz = uiop->uio_resid;
1094 if (uiop->uio_offset + tsiz > nmp->nm_maxfilesize)
1097 nfsstats.rpccnt[NFSPROC_WRITE]++;
1098 len = (tsiz > nmp->nm_wsize) ? nmp->nm_wsize : tsiz;
1099 mreq = nfsm_reqhead(vp, NFSPROC_WRITE,
1100 NFSX_FH(v3) + 5 * NFSX_UNSIGNED + nfsm_rndup(len));
1102 bpos = mtod(mb, caddr_t);
1105 tl = nfsm_build(u_int32_t *, 5 * NFSX_UNSIGNED);
1106 txdr_hyper(uiop->uio_offset, tl);
1108 *tl++ = txdr_unsigned(len);
1109 *tl++ = txdr_unsigned(*iomode);
1110 *tl = txdr_unsigned(len);
1114 tl = nfsm_build(u_int32_t *, 4 * NFSX_UNSIGNED);
1115 /* Set both "begin" and "current" to non-garbage. */
1116 x = txdr_unsigned((u_int32_t)uiop->uio_offset);
1117 *tl++ = x; /* "begin offset" */
1118 *tl++ = x; /* "current offset" */
1119 x = txdr_unsigned(len);
1120 *tl++ = x; /* total to this offset */
1121 *tl = x; /* size of this write */
1123 nfsm_uiotom(uiop, len);
1124 nfsm_request(vp, NFSPROC_WRITE, uiop->uio_td, cred);
1126 wccflag = NFSV3_WCCCHK;
1127 nfsm_wcc_data(vp, wccflag);
1129 tl = nfsm_dissect(u_int32_t *, 2 * NFSX_UNSIGNED
1130 + NFSX_V3WRITEVERF);
1131 rlen = fxdr_unsigned(int, *tl++);
1136 } else if (rlen < len) {
1137 backup = len - rlen;
1138 uiop->uio_iov->iov_base =
1139 (char *)uiop->uio_iov->iov_base -
1141 uiop->uio_iov->iov_len += backup;
1142 uiop->uio_offset -= backup;
1143 uiop->uio_resid += backup;
1146 commit = fxdr_unsigned(int, *tl++);
1149 * Return the lowest committment level
1150 * obtained by any of the RPCs.
1152 if (committed == NFSV3WRITE_FILESYNC)
1154 else if (committed == NFSV3WRITE_DATASYNC &&
1155 commit == NFSV3WRITE_UNSTABLE)
1157 if ((nmp->nm_state & NFSSTA_HASWRITEVERF) == 0){
1158 bcopy((caddr_t)tl, (caddr_t)nmp->nm_verf,
1160 nmp->nm_state |= NFSSTA_HASWRITEVERF;
1161 } else if (bcmp((caddr_t)tl,
1162 (caddr_t)nmp->nm_verf, NFSX_V3WRITEVERF)) {
1164 bcopy((caddr_t)tl, (caddr_t)nmp->nm_verf,
1169 nfsm_loadattr(vp, NULL);
1171 VTONFS(vp)->n_mtime = VTONFS(vp)->n_vattr.va_mtime.tv_sec;
1178 if (vp->v_mount->mnt_flag & MNT_ASYNC)
1179 committed = NFSV3WRITE_FILESYNC;
1180 *iomode = committed;
1182 uiop->uio_resid = tsiz;
1188 * For NFS v2 this is a kludge. Use a create rpc but with the IFMT bits of the
1189 * mode set to specify the file type and the size field for rdev.
1192 nfs_mknodrpc(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp,
1195 struct nfsv2_sattr *sp;
1197 struct vnode *newvp = NULL;
1198 struct nfsnode *np = NULL;
1201 int error = 0, wccflag = NFSV3_WCCRATTR, gotvp = 0;
1202 struct mbuf *mreq, *mrep, *md, *mb;
1204 int v3 = NFS_ISV3(dvp);
1206 if (vap->va_type == VCHR || vap->va_type == VBLK)
1207 rdev = txdr_unsigned(vap->va_rdev);
1208 else if (vap->va_type == VFIFO || vap->va_type == VSOCK)
1211 return (EOPNOTSUPP);
1213 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread)) != 0) {
1216 nfsstats.rpccnt[NFSPROC_MKNOD]++;
1217 mreq = nfsm_reqhead(dvp, NFSPROC_MKNOD, NFSX_FH(v3) + 4 * NFSX_UNSIGNED +
1218 + nfsm_rndup(cnp->cn_namelen) + NFSX_SATTR(v3));
1220 bpos = mtod(mb, caddr_t);
1221 nfsm_fhtom(dvp, v3);
1222 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
1224 tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED);
1225 *tl++ = vtonfsv3_type(vap->va_type);
1226 nfsm_v3attrbuild(vap, FALSE);
1227 if (vap->va_type == VCHR || vap->va_type == VBLK) {
1228 tl = nfsm_build(u_int32_t *, 2 * NFSX_UNSIGNED);
1229 *tl++ = txdr_unsigned(umajor(vap->va_rdev));
1230 *tl = txdr_unsigned(uminor(vap->va_rdev));
1233 sp = nfsm_build(struct nfsv2_sattr *, NFSX_V2SATTR);
1234 sp->sa_mode = vtonfsv2_mode(vap->va_type, vap->va_mode);
1235 sp->sa_uid = nfs_xdrneg1;
1236 sp->sa_gid = nfs_xdrneg1;
1238 txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
1239 txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
1241 nfsm_request(dvp, NFSPROC_MKNOD, cnp->cn_thread, cnp->cn_cred);
1243 nfsm_mtofh(dvp, newvp, v3, gotvp);
1249 error = nfs_lookitup(dvp, cnp->cn_nameptr,
1250 cnp->cn_namelen, cnp->cn_cred, cnp->cn_thread, &np);
1256 nfsm_wcc_data(dvp, wccflag);
1263 if (cnp->cn_flags & MAKEENTRY)
1264 cache_enter(dvp, newvp, cnp);
1267 VTONFS(dvp)->n_flag |= NMODIFIED;
1269 VTONFS(dvp)->n_attrstamp = 0;
1275 * just call nfs_mknodrpc() to do the work.
1279 nfs_mknod(struct vop_mknod_args *ap)
1282 return nfs_mknodrpc(ap->a_dvp, ap->a_vpp, ap->a_cnp, ap->a_vap);
1285 static u_long create_verf;
1287 * nfs file create call
1290 nfs_create(struct vop_create_args *ap)
1292 struct vnode *dvp = ap->a_dvp;
1293 struct vattr *vap = ap->a_vap;
1294 struct componentname *cnp = ap->a_cnp;
1295 struct nfsv2_sattr *sp;
1297 struct nfsnode *np = NULL;
1298 struct vnode *newvp = NULL;
1300 int error = 0, wccflag = NFSV3_WCCRATTR, gotvp = 0, fmode = 0;
1301 struct mbuf *mreq, *mrep, *md, *mb;
1303 int v3 = NFS_ISV3(dvp);
1306 * Oops, not for me..
1308 if (vap->va_type == VSOCK)
1309 return (nfs_mknodrpc(dvp, ap->a_vpp, cnp, vap));
1311 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread)) != 0) {
1314 if (vap->va_vaflags & VA_EXCLUSIVE)
1317 nfsstats.rpccnt[NFSPROC_CREATE]++;
1318 mreq = nfsm_reqhead(dvp, NFSPROC_CREATE, NFSX_FH(v3) + 2 * NFSX_UNSIGNED +
1319 nfsm_rndup(cnp->cn_namelen) + NFSX_SATTR(v3));
1321 bpos = mtod(mb, caddr_t);
1322 nfsm_fhtom(dvp, v3);
1323 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
1325 tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED);
1326 if (fmode & O_EXCL) {
1327 *tl = txdr_unsigned(NFSV3CREATE_EXCLUSIVE);
1328 tl = nfsm_build(u_int32_t *, NFSX_V3CREATEVERF);
1330 if (!TAILQ_EMPTY(&in_ifaddrhead))
1331 *tl++ = IA_SIN(TAILQ_FIRST(&in_ifaddrhead))->sin_addr.s_addr;
1334 *tl++ = create_verf;
1335 *tl = ++create_verf;
1337 *tl = txdr_unsigned(NFSV3CREATE_UNCHECKED);
1338 nfsm_v3attrbuild(vap, FALSE);
1341 sp = nfsm_build(struct nfsv2_sattr *, NFSX_V2SATTR);
1342 sp->sa_mode = vtonfsv2_mode(vap->va_type, vap->va_mode);
1343 sp->sa_uid = nfs_xdrneg1;
1344 sp->sa_gid = nfs_xdrneg1;
1346 txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
1347 txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
1349 nfsm_request(dvp, NFSPROC_CREATE, cnp->cn_thread, cnp->cn_cred);
1351 nfsm_mtofh(dvp, newvp, v3, gotvp);
1357 error = nfs_lookitup(dvp, cnp->cn_nameptr,
1358 cnp->cn_namelen, cnp->cn_cred, cnp->cn_thread, &np);
1364 nfsm_wcc_data(dvp, wccflag);
1368 if (v3 && (fmode & O_EXCL) && error == NFSERR_NOTSUPP) {
1374 } else if (v3 && (fmode & O_EXCL)) {
1376 * We are normally called with only a partially initialized
1377 * VAP. Since the NFSv3 spec says that server may use the
1378 * file attributes to store the verifier, the spec requires
1379 * us to do a SETATTR RPC. FreeBSD servers store the verifier
1380 * in atime, but we can't really assume that all servers will
1381 * so we ensure that our SETATTR sets both atime and mtime.
1383 if (vap->va_mtime.tv_sec == VNOVAL)
1384 vfs_timestamp(&vap->va_mtime);
1385 if (vap->va_atime.tv_sec == VNOVAL)
1386 vap->va_atime = vap->va_mtime;
1387 error = nfs_setattrrpc(newvp, vap, cnp->cn_cred, cnp->cn_thread);
1390 if (cnp->cn_flags & MAKEENTRY)
1391 cache_enter(dvp, newvp, cnp);
1394 VTONFS(dvp)->n_flag |= NMODIFIED;
1396 VTONFS(dvp)->n_attrstamp = 0;
1401 * nfs file remove call
1402 * To try and make nfs semantics closer to ufs semantics, a file that has
1403 * other processes using the vnode is renamed instead of removed and then
1404 * removed later on the last close.
1405 * - If v_usecount > 1
1406 * If a rename is not already in the works
1407 * call nfs_sillyrename() to set it up
1412 nfs_remove(struct vop_remove_args *ap)
1414 struct vnode *vp = ap->a_vp;
1415 struct vnode *dvp = ap->a_dvp;
1416 struct componentname *cnp = ap->a_cnp;
1417 struct nfsnode *np = VTONFS(vp);
1422 if ((cnp->cn_flags & HASBUF) == 0)
1423 panic("nfs_remove: no name");
1424 if (vrefcnt(vp) < 1)
1425 panic("nfs_remove: bad v_usecount");
1427 if (vp->v_type == VDIR)
1429 else if (vrefcnt(vp) == 1 || (np->n_sillyrename &&
1430 VOP_GETATTR(vp, &vattr, cnp->cn_cred, cnp->cn_thread) == 0 &&
1431 vattr.va_nlink > 1)) {
1433 * Purge the name cache so that the chance of a lookup for
1434 * the name succeeding while the remove is in progress is
1435 * minimized. Without node locking it can still happen, such
1436 * that an I/O op returns ESTALE, but since you get this if
1437 * another host removes the file..
1441 * throw away biocache buffers, mainly to avoid
1442 * unnecessary delayed writes later.
1444 error = nfs_vinvalbuf(vp, 0, cnp->cn_cred, cnp->cn_thread, 1);
1447 error = nfs_removerpc(dvp, cnp->cn_nameptr,
1448 cnp->cn_namelen, cnp->cn_cred, cnp->cn_thread);
1450 * Kludge City: If the first reply to the remove rpc is lost..
1451 * the reply to the retransmitted request will be ENOENT
1452 * since the file was in fact removed
1453 * Therefore, we cheat and return success.
1455 if (error == ENOENT)
1457 } else if (!np->n_sillyrename)
1458 error = nfs_sillyrename(dvp, vp, cnp);
1459 np->n_attrstamp = 0;
1464 * nfs file remove rpc called from nfs_inactive
1467 nfs_removeit(struct sillyrename *sp)
1470 return (nfs_removerpc(sp->s_dvp, sp->s_name, sp->s_namlen, sp->s_cred,
1475 * Nfs remove rpc, called from nfs_remove() and nfs_removeit().
1478 nfs_removerpc(struct vnode *dvp, const char *name, int namelen,
1479 struct ucred *cred, struct thread *td)
1482 int error = 0, wccflag = NFSV3_WCCRATTR;
1483 struct mbuf *mreq, *mrep, *md, *mb;
1484 int v3 = NFS_ISV3(dvp);
1486 nfsstats.rpccnt[NFSPROC_REMOVE]++;
1487 mreq = nfsm_reqhead(dvp, NFSPROC_REMOVE,
1488 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(namelen));
1490 bpos = mtod(mb, caddr_t);
1491 nfsm_fhtom(dvp, v3);
1492 nfsm_strtom(name, namelen, NFS_MAXNAMLEN);
1493 nfsm_request(dvp, NFSPROC_REMOVE, td, cred);
1495 nfsm_wcc_data(dvp, wccflag);
1498 VTONFS(dvp)->n_flag |= NMODIFIED;
1500 VTONFS(dvp)->n_attrstamp = 0;
1505 * nfs file rename call
1508 nfs_rename(struct vop_rename_args *ap)
1510 struct vnode *fvp = ap->a_fvp;
1511 struct vnode *tvp = ap->a_tvp;
1512 struct vnode *fdvp = ap->a_fdvp;
1513 struct vnode *tdvp = ap->a_tdvp;
1514 struct componentname *tcnp = ap->a_tcnp;
1515 struct componentname *fcnp = ap->a_fcnp;
1519 if ((tcnp->cn_flags & HASBUF) == 0 ||
1520 (fcnp->cn_flags & HASBUF) == 0)
1521 panic("nfs_rename: no name");
1523 /* Check for cross-device rename */
1524 if ((fvp->v_mount != tdvp->v_mount) ||
1525 (tvp && (fvp->v_mount != tvp->v_mount))) {
1531 * We have to flush B_DELWRI data prior to renaming
1532 * the file. If we don't, the delayed-write buffers
1533 * can be flushed out later after the file has gone stale
1534 * under NFSV3. NFSV2 does not have this problem because
1535 * ( as far as I can tell ) it flushes dirty buffers more
1539 VOP_FSYNC(fvp, fcnp->cn_cred, MNT_WAIT, fcnp->cn_thread);
1541 VOP_FSYNC(tvp, tcnp->cn_cred, MNT_WAIT, tcnp->cn_thread);
1544 * If the tvp exists and is in use, sillyrename it before doing the
1545 * rename of the new file over it.
1546 * XXX Can't sillyrename a directory.
1548 if (tvp && vrefcnt(tvp) > 1 && !VTONFS(tvp)->n_sillyrename &&
1549 tvp->v_type != VDIR && !nfs_sillyrename(tdvp, tvp, tcnp)) {
1554 error = nfs_renamerpc(fdvp, fcnp->cn_nameptr, fcnp->cn_namelen,
1555 tdvp, tcnp->cn_nameptr, tcnp->cn_namelen, tcnp->cn_cred,
1558 if (fvp->v_type == VDIR) {
1559 if (tvp != NULL && tvp->v_type == VDIR)
1574 * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry.
1576 if (error == ENOENT)
1582 * nfs file rename rpc called from nfs_remove() above
1585 nfs_renameit(struct vnode *sdvp, struct componentname *scnp,
1586 struct sillyrename *sp)
1589 return (nfs_renamerpc(sdvp, scnp->cn_nameptr, scnp->cn_namelen, sdvp,
1590 sp->s_name, sp->s_namlen, scnp->cn_cred, scnp->cn_thread));
1594 * Do an nfs rename rpc. Called from nfs_rename() and nfs_renameit().
1597 nfs_renamerpc(struct vnode *fdvp, const char *fnameptr, int fnamelen,
1598 struct vnode *tdvp, const char *tnameptr, int tnamelen, struct ucred *cred,
1602 int error = 0, fwccflag = NFSV3_WCCRATTR, twccflag = NFSV3_WCCRATTR;
1603 struct mbuf *mreq, *mrep, *md, *mb;
1604 int v3 = NFS_ISV3(fdvp);
1606 nfsstats.rpccnt[NFSPROC_RENAME]++;
1607 mreq = nfsm_reqhead(fdvp, NFSPROC_RENAME,
1608 (NFSX_FH(v3) + NFSX_UNSIGNED)*2 + nfsm_rndup(fnamelen) +
1609 nfsm_rndup(tnamelen));
1611 bpos = mtod(mb, caddr_t);
1612 nfsm_fhtom(fdvp, v3);
1613 nfsm_strtom(fnameptr, fnamelen, NFS_MAXNAMLEN);
1614 nfsm_fhtom(tdvp, v3);
1615 nfsm_strtom(tnameptr, tnamelen, NFS_MAXNAMLEN);
1616 nfsm_request(fdvp, NFSPROC_RENAME, td, cred);
1618 nfsm_wcc_data(fdvp, fwccflag);
1619 nfsm_wcc_data(tdvp, twccflag);
1623 VTONFS(fdvp)->n_flag |= NMODIFIED;
1624 VTONFS(tdvp)->n_flag |= NMODIFIED;
1626 VTONFS(fdvp)->n_attrstamp = 0;
1628 VTONFS(tdvp)->n_attrstamp = 0;
1633 * nfs hard link create call
1636 nfs_link(struct vop_link_args *ap)
1638 struct vnode *vp = ap->a_vp;
1639 struct vnode *tdvp = ap->a_tdvp;
1640 struct componentname *cnp = ap->a_cnp;
1642 int error = 0, wccflag = NFSV3_WCCRATTR, attrflag = 0;
1643 struct mbuf *mreq, *mrep, *md, *mb;
1646 if (vp->v_mount != tdvp->v_mount) {
1651 * Push all writes to the server, so that the attribute cache
1652 * doesn't get "out of sync" with the server.
1653 * XXX There should be a better way!
1655 VOP_FSYNC(vp, cnp->cn_cred, MNT_WAIT, cnp->cn_thread);
1658 nfsstats.rpccnt[NFSPROC_LINK]++;
1659 mreq = nfsm_reqhead(vp, NFSPROC_LINK,
1660 NFSX_FH(v3)*2 + NFSX_UNSIGNED + nfsm_rndup(cnp->cn_namelen));
1662 bpos = mtod(mb, caddr_t);
1664 nfsm_fhtom(tdvp, v3);
1665 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
1666 nfsm_request(vp, NFSPROC_LINK, cnp->cn_thread, cnp->cn_cred);
1668 nfsm_postop_attr(vp, attrflag);
1669 nfsm_wcc_data(tdvp, wccflag);
1673 VTONFS(tdvp)->n_flag |= NMODIFIED;
1675 VTONFS(vp)->n_attrstamp = 0;
1677 VTONFS(tdvp)->n_attrstamp = 0;
1679 * Kludge: Map EEXIST => 0 assuming that it is a reply to a retry.
1681 if (error == EEXIST)
1687 * nfs symbolic link create call
1690 nfs_symlink(struct vop_symlink_args *ap)
1692 struct vnode *dvp = ap->a_dvp;
1693 struct vattr *vap = ap->a_vap;
1694 struct componentname *cnp = ap->a_cnp;
1695 struct nfsv2_sattr *sp;
1697 int slen, error = 0, wccflag = NFSV3_WCCRATTR, gotvp;
1698 struct mbuf *mreq, *mrep, *md, *mb;
1699 struct vnode *newvp = NULL;
1700 int v3 = NFS_ISV3(dvp);
1702 nfsstats.rpccnt[NFSPROC_SYMLINK]++;
1703 slen = strlen(ap->a_target);
1704 mreq = nfsm_reqhead(dvp, NFSPROC_SYMLINK, NFSX_FH(v3) + 2*NFSX_UNSIGNED +
1705 nfsm_rndup(cnp->cn_namelen) + nfsm_rndup(slen) + NFSX_SATTR(v3));
1707 bpos = mtod(mb, caddr_t);
1708 nfsm_fhtom(dvp, v3);
1709 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
1711 nfsm_v3attrbuild(vap, FALSE);
1713 nfsm_strtom(ap->a_target, slen, NFS_MAXPATHLEN);
1715 sp = nfsm_build(struct nfsv2_sattr *, NFSX_V2SATTR);
1716 sp->sa_mode = vtonfsv2_mode(VLNK, vap->va_mode);
1717 sp->sa_uid = nfs_xdrneg1;
1718 sp->sa_gid = nfs_xdrneg1;
1719 sp->sa_size = nfs_xdrneg1;
1720 txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
1721 txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
1725 * Issue the NFS request and get the rpc response.
1727 * Only NFSv3 responses returning an error of 0 actually return
1728 * a file handle that can be converted into newvp without having
1729 * to do an extra lookup rpc.
1731 nfsm_request(dvp, NFSPROC_SYMLINK, cnp->cn_thread, cnp->cn_cred);
1734 nfsm_mtofh(dvp, newvp, v3, gotvp);
1735 nfsm_wcc_data(dvp, wccflag);
1739 * out code jumps -> here, mrep is also freed.
1746 * If we get an EEXIST error, silently convert it to no-error
1747 * in case of an NFS retry.
1749 if (error == EEXIST)
1753 * If we do not have (or no longer have) an error, and we could
1754 * not extract the newvp from the response due to the request being
1755 * NFSv2 or the error being EEXIST. We have to do a lookup in order
1756 * to obtain a newvp to return.
1758 if (error == 0 && newvp == NULL) {
1759 struct nfsnode *np = NULL;
1761 error = nfs_lookitup(dvp, cnp->cn_nameptr, cnp->cn_namelen,
1762 cnp->cn_cred, cnp->cn_thread, &np);
1772 VTONFS(dvp)->n_flag |= NMODIFIED;
1774 VTONFS(dvp)->n_attrstamp = 0;
1782 nfs_mkdir(struct vop_mkdir_args *ap)
1784 struct vnode *dvp = ap->a_dvp;
1785 struct vattr *vap = ap->a_vap;
1786 struct componentname *cnp = ap->a_cnp;
1787 struct nfsv2_sattr *sp;
1789 struct nfsnode *np = NULL;
1790 struct vnode *newvp = NULL;
1792 int error = 0, wccflag = NFSV3_WCCRATTR;
1794 struct mbuf *mreq, *mrep, *md, *mb;
1796 int v3 = NFS_ISV3(dvp);
1798 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread)) != 0) {
1801 len = cnp->cn_namelen;
1802 nfsstats.rpccnt[NFSPROC_MKDIR]++;
1803 mreq = nfsm_reqhead(dvp, NFSPROC_MKDIR,
1804 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len) + NFSX_SATTR(v3));
1806 bpos = mtod(mb, caddr_t);
1807 nfsm_fhtom(dvp, v3);
1808 nfsm_strtom(cnp->cn_nameptr, len, NFS_MAXNAMLEN);
1810 nfsm_v3attrbuild(vap, FALSE);
1812 sp = nfsm_build(struct nfsv2_sattr *, NFSX_V2SATTR);
1813 sp->sa_mode = vtonfsv2_mode(VDIR, vap->va_mode);
1814 sp->sa_uid = nfs_xdrneg1;
1815 sp->sa_gid = nfs_xdrneg1;
1816 sp->sa_size = nfs_xdrneg1;
1817 txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
1818 txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
1820 nfsm_request(dvp, NFSPROC_MKDIR, cnp->cn_thread, cnp->cn_cred);
1822 nfsm_mtofh(dvp, newvp, v3, gotvp);
1824 nfsm_wcc_data(dvp, wccflag);
1827 VTONFS(dvp)->n_flag |= NMODIFIED;
1829 VTONFS(dvp)->n_attrstamp = 0;
1831 * Kludge: Map EEXIST => 0 assuming that you have a reply to a retry
1832 * if we can succeed in looking up the directory.
1834 if (error == EEXIST || (!error && !gotvp)) {
1839 error = nfs_lookitup(dvp, cnp->cn_nameptr, len, cnp->cn_cred,
1840 cnp->cn_thread, &np);
1843 if (newvp->v_type != VDIR)
1856 * nfs remove directory call
1859 nfs_rmdir(struct vop_rmdir_args *ap)
1861 struct vnode *vp = ap->a_vp;
1862 struct vnode *dvp = ap->a_dvp;
1863 struct componentname *cnp = ap->a_cnp;
1865 int error = 0, wccflag = NFSV3_WCCRATTR;
1866 struct mbuf *mreq, *mrep, *md, *mb;
1867 int v3 = NFS_ISV3(dvp);
1871 nfsstats.rpccnt[NFSPROC_RMDIR]++;
1872 mreq = nfsm_reqhead(dvp, NFSPROC_RMDIR,
1873 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(cnp->cn_namelen));
1875 bpos = mtod(mb, caddr_t);
1876 nfsm_fhtom(dvp, v3);
1877 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
1878 nfsm_request(dvp, NFSPROC_RMDIR, cnp->cn_thread, cnp->cn_cred);
1880 nfsm_wcc_data(dvp, wccflag);
1883 VTONFS(dvp)->n_flag |= NMODIFIED;
1885 VTONFS(dvp)->n_attrstamp = 0;
1889 * Kludge: Map ENOENT => 0 assuming that you have a reply to a retry.
1891 if (error == ENOENT)
1900 nfs_readdir(struct vop_readdir_args *ap)
1902 struct vnode *vp = ap->a_vp;
1903 struct nfsnode *np = VTONFS(vp);
1904 struct uio *uio = ap->a_uio;
1908 if (vp->v_type != VDIR)
1911 * First, check for hit on the EOF offset cache
1913 if (np->n_direofoffset > 0 && uio->uio_offset >= np->n_direofoffset &&
1914 (np->n_flag & NMODIFIED) == 0) {
1915 if (VOP_GETATTR(vp, &vattr, ap->a_cred, uio->uio_td) == 0 &&
1916 np->n_mtime == vattr.va_mtime.tv_sec) {
1917 nfsstats.direofcache_hits++;
1923 * Call nfs_bioread() to do the real work.
1925 tresid = uio->uio_resid;
1926 error = nfs_bioread(vp, uio, 0, ap->a_cred);
1928 if (!error && uio->uio_resid == tresid)
1929 nfsstats.direofcache_misses++;
1935 * Called from below the buffer cache by nfs_doio().
1938 nfs_readdirrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred)
1941 struct dirent *dp = NULL;
1946 struct mbuf *mreq, *mrep, *md, *mb;
1948 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
1949 struct nfsnode *dnp = VTONFS(vp);
1951 int error = 0, tlen, more_dirs = 1, blksiz = 0, bigenough = 1;
1953 int v3 = NFS_ISV3(vp);
1956 if (uiop->uio_iovcnt != 1 || (uiop->uio_offset & (DIRBLKSIZ - 1)) ||
1957 (uiop->uio_resid & (DIRBLKSIZ - 1)))
1958 panic("nfs readdirrpc bad uio");
1962 * If there is no cookie, assume directory was stale.
1964 cookiep = nfs_getcookie(dnp, uiop->uio_offset, 0);
1968 return (NFSERR_BAD_COOKIE);
1970 * Loop around doing readdir rpc's of size nm_readdirsize
1971 * truncated to a multiple of DIRBLKSIZ.
1972 * The stopping criteria is EOF or buffer full.
1974 while (more_dirs && bigenough) {
1975 nfsstats.rpccnt[NFSPROC_READDIR]++;
1976 mreq = nfsm_reqhead(vp, NFSPROC_READDIR, NFSX_FH(v3) +
1979 bpos = mtod(mb, caddr_t);
1982 tl = nfsm_build(u_int32_t *, 5 * NFSX_UNSIGNED);
1983 *tl++ = cookie.nfsuquad[0];
1984 *tl++ = cookie.nfsuquad[1];
1985 *tl++ = dnp->n_cookieverf.nfsuquad[0];
1986 *tl++ = dnp->n_cookieverf.nfsuquad[1];
1988 tl = nfsm_build(u_int32_t *, 2 * NFSX_UNSIGNED);
1989 *tl++ = cookie.nfsuquad[0];
1991 *tl = txdr_unsigned(nmp->nm_readdirsize);
1992 nfsm_request(vp, NFSPROC_READDIR, uiop->uio_td, cred);
1994 nfsm_postop_attr(vp, attrflag);
1996 tl = nfsm_dissect(u_int32_t *,
1998 dnp->n_cookieverf.nfsuquad[0] = *tl++;
1999 dnp->n_cookieverf.nfsuquad[1] = *tl;
2005 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
2006 more_dirs = fxdr_unsigned(int, *tl);
2008 /* loop thru the dir entries, doctoring them to 4bsd form */
2009 while (more_dirs && bigenough) {
2011 tl = nfsm_dissect(u_int32_t *,
2013 fileno = fxdr_hyper(tl);
2014 len = fxdr_unsigned(int, *(tl + 2));
2016 tl = nfsm_dissect(u_int32_t *,
2018 fileno = fxdr_unsigned(u_quad_t, *tl++);
2019 len = fxdr_unsigned(int, *tl);
2021 if (len <= 0 || len > NFS_MAXNAMLEN) {
2026 tlen = nfsm_rndup(len);
2028 tlen += 4; /* To ensure null termination */
2029 left = DIRBLKSIZ - blksiz;
2030 if ((tlen + DIRHDSIZ) > left) {
2031 dp->d_reclen += left;
2032 uiop->uio_iov->iov_base =
2033 (char *)uiop->uio_iov->iov_base + left;
2034 uiop->uio_iov->iov_len -= left;
2035 uiop->uio_offset += left;
2036 uiop->uio_resid -= left;
2039 if ((tlen + DIRHDSIZ) > uiop->uio_resid)
2042 dp = (struct dirent *)uiop->uio_iov->iov_base;
2043 dp->d_fileno = (int)fileno;
2045 dp->d_reclen = tlen + DIRHDSIZ;
2046 dp->d_type = DT_UNKNOWN;
2047 blksiz += dp->d_reclen;
2048 if (blksiz == DIRBLKSIZ)
2050 uiop->uio_offset += DIRHDSIZ;
2051 uiop->uio_resid -= DIRHDSIZ;
2052 uiop->uio_iov->iov_base =
2053 (char *)uiop->uio_iov->iov_base + DIRHDSIZ;
2054 uiop->uio_iov->iov_len -= DIRHDSIZ;
2055 nfsm_mtouio(uiop, len);
2056 cp = uiop->uio_iov->iov_base;
2058 *cp = '\0'; /* null terminate */
2059 uiop->uio_iov->iov_base =
2060 (char *)uiop->uio_iov->iov_base + tlen;
2061 uiop->uio_iov->iov_len -= tlen;
2062 uiop->uio_offset += tlen;
2063 uiop->uio_resid -= tlen;
2065 nfsm_adv(nfsm_rndup(len));
2067 tl = nfsm_dissect(u_int32_t *,
2070 tl = nfsm_dissect(u_int32_t *,
2074 cookie.nfsuquad[0] = *tl++;
2076 cookie.nfsuquad[1] = *tl++;
2081 more_dirs = fxdr_unsigned(int, *tl);
2084 * If at end of rpc data, get the eof boolean
2087 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
2088 more_dirs = (fxdr_unsigned(int, *tl) == 0);
2093 * Fill last record, iff any, out to a multiple of DIRBLKSIZ
2094 * by increasing d_reclen for the last record.
2097 left = DIRBLKSIZ - blksiz;
2098 dp->d_reclen += left;
2099 uiop->uio_iov->iov_base =
2100 (char *)uiop->uio_iov->iov_base + left;
2101 uiop->uio_iov->iov_len -= left;
2102 uiop->uio_offset += left;
2103 uiop->uio_resid -= left;
2107 * We are now either at the end of the directory or have filled the
2111 dnp->n_direofoffset = uiop->uio_offset;
2113 if (uiop->uio_resid > 0)
2114 printf("EEK! readdirrpc resid > 0\n");
2115 cookiep = nfs_getcookie(dnp, uiop->uio_offset, 1);
2123 * NFS V3 readdir plus RPC. Used in place of nfs_readdirrpc().
2126 nfs_readdirplusrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred)
2132 struct vnode *newvp;
2134 caddr_t bpos, dpos, dpossav1, dpossav2;
2135 struct mbuf *mreq, *mrep, *md, *mb, *mdsav1, *mdsav2;
2136 struct nameidata nami, *ndp = &nami;
2137 struct componentname *cnp = &ndp->ni_cnd;
2139 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2140 struct nfsnode *dnp = VTONFS(vp), *np;
2143 int error = 0, tlen, more_dirs = 1, blksiz = 0, doit, bigenough = 1, i;
2144 int attrflag, fhsize;
2150 if (uiop->uio_iovcnt != 1 || (uiop->uio_offset & (DIRBLKSIZ - 1)) ||
2151 (uiop->uio_resid & (DIRBLKSIZ - 1)))
2152 panic("nfs readdirplusrpc bad uio");
2158 * If there is no cookie, assume directory was stale.
2160 cookiep = nfs_getcookie(dnp, uiop->uio_offset, 0);
2164 return (NFSERR_BAD_COOKIE);
2166 * Loop around doing readdir rpc's of size nm_readdirsize
2167 * truncated to a multiple of DIRBLKSIZ.
2168 * The stopping criteria is EOF or buffer full.
2170 while (more_dirs && bigenough) {
2171 nfsstats.rpccnt[NFSPROC_READDIRPLUS]++;
2172 mreq = nfsm_reqhead(vp, NFSPROC_READDIRPLUS,
2173 NFSX_FH(1) + 6 * NFSX_UNSIGNED);
2175 bpos = mtod(mb, caddr_t);
2177 tl = nfsm_build(u_int32_t *, 6 * NFSX_UNSIGNED);
2178 *tl++ = cookie.nfsuquad[0];
2179 *tl++ = cookie.nfsuquad[1];
2180 *tl++ = dnp->n_cookieverf.nfsuquad[0];
2181 *tl++ = dnp->n_cookieverf.nfsuquad[1];
2182 *tl++ = txdr_unsigned(nmp->nm_readdirsize);
2183 *tl = txdr_unsigned(nmp->nm_rsize);
2184 nfsm_request(vp, NFSPROC_READDIRPLUS, uiop->uio_td, cred);
2185 nfsm_postop_attr(vp, attrflag);
2190 tl = nfsm_dissect(u_int32_t *, 3 * NFSX_UNSIGNED);
2191 dnp->n_cookieverf.nfsuquad[0] = *tl++;
2192 dnp->n_cookieverf.nfsuquad[1] = *tl++;
2193 more_dirs = fxdr_unsigned(int, *tl);
2195 /* loop thru the dir entries, doctoring them to 4bsd form */
2196 while (more_dirs && bigenough) {
2197 tl = nfsm_dissect(u_int32_t *, 3 * NFSX_UNSIGNED);
2198 fileno = fxdr_hyper(tl);
2199 len = fxdr_unsigned(int, *(tl + 2));
2200 if (len <= 0 || len > NFS_MAXNAMLEN) {
2205 tlen = nfsm_rndup(len);
2207 tlen += 4; /* To ensure null termination*/
2208 left = DIRBLKSIZ - blksiz;
2209 if ((tlen + DIRHDSIZ) > left) {
2210 dp->d_reclen += left;
2211 uiop->uio_iov->iov_base =
2212 (char *)uiop->uio_iov->iov_base + left;
2213 uiop->uio_iov->iov_len -= left;
2214 uiop->uio_offset += left;
2215 uiop->uio_resid -= left;
2218 if ((tlen + DIRHDSIZ) > uiop->uio_resid)
2221 dp = (struct dirent *)uiop->uio_iov->iov_base;
2222 dp->d_fileno = (int)fileno;
2224 dp->d_reclen = tlen + DIRHDSIZ;
2225 dp->d_type = DT_UNKNOWN;
2226 blksiz += dp->d_reclen;
2227 if (blksiz == DIRBLKSIZ)
2229 uiop->uio_offset += DIRHDSIZ;
2230 uiop->uio_resid -= DIRHDSIZ;
2231 uiop->uio_iov->iov_base =
2232 (char *)uiop->uio_iov->iov_base + DIRHDSIZ;
2233 uiop->uio_iov->iov_len -= DIRHDSIZ;
2234 cnp->cn_nameptr = uiop->uio_iov->iov_base;
2235 cnp->cn_namelen = len;
2236 nfsm_mtouio(uiop, len);
2237 cp = uiop->uio_iov->iov_base;
2240 uiop->uio_iov->iov_base =
2241 (char *)uiop->uio_iov->iov_base + tlen;
2242 uiop->uio_iov->iov_len -= tlen;
2243 uiop->uio_offset += tlen;
2244 uiop->uio_resid -= tlen;
2246 nfsm_adv(nfsm_rndup(len));
2247 tl = nfsm_dissect(u_int32_t *, 3 * NFSX_UNSIGNED);
2249 cookie.nfsuquad[0] = *tl++;
2250 cookie.nfsuquad[1] = *tl++;
2255 * Since the attributes are before the file handle
2256 * (sigh), we must skip over the attributes and then
2257 * come back and get them.
2259 attrflag = fxdr_unsigned(int, *tl);
2263 nfsm_adv(NFSX_V3FATTR);
2264 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
2265 doit = fxdr_unsigned(int, *tl);
2267 nfsm_getfh(fhp, fhsize, 1);
2268 if (NFS_CMPFH(dnp, fhp, fhsize)) {
2273 error = nfs_nget(vp->v_mount, fhp,
2281 if (doit && bigenough) {
2286 nfsm_loadattr(newvp, NULL);
2290 IFTODT(VTTOIF(np->n_vattr.va_type));
2292 cache_enter(ndp->ni_dvp, ndp->ni_vp, cnp);
2295 /* Just skip over the file handle */
2296 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
2297 i = fxdr_unsigned(int, *tl);
2298 nfsm_adv(nfsm_rndup(i));
2300 if (newvp != NULLVP) {
2307 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
2308 more_dirs = fxdr_unsigned(int, *tl);
2311 * If at end of rpc data, get the eof boolean
2314 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
2315 more_dirs = (fxdr_unsigned(int, *tl) == 0);
2320 * Fill last record, iff any, out to a multiple of DIRBLKSIZ
2321 * by increasing d_reclen for the last record.
2324 left = DIRBLKSIZ - blksiz;
2325 dp->d_reclen += left;
2326 uiop->uio_iov->iov_base =
2327 (char *)uiop->uio_iov->iov_base + left;
2328 uiop->uio_iov->iov_len -= left;
2329 uiop->uio_offset += left;
2330 uiop->uio_resid -= left;
2334 * We are now either at the end of the directory or have filled the
2338 dnp->n_direofoffset = uiop->uio_offset;
2340 if (uiop->uio_resid > 0)
2341 printf("EEK! readdirplusrpc resid > 0\n");
2342 cookiep = nfs_getcookie(dnp, uiop->uio_offset, 1);
2346 if (newvp != NULLVP) {
2357 * Silly rename. To make the NFS filesystem that is stateless look a little
2358 * more like the "ufs" a remove of an active vnode is translated to a rename
2359 * to a funny looking filename that is removed by nfs_inactive on the
2360 * nfsnode. There is the potential for another process on a different client
2361 * to create the same funny name between the nfs_lookitup() fails and the
2362 * nfs_rename() completes, but...
2365 nfs_sillyrename(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
2367 struct sillyrename *sp;
2375 if (vp->v_type == VDIR)
2376 panic("nfs: sillyrename dir");
2378 MALLOC(sp, struct sillyrename *, sizeof (struct sillyrename),
2379 M_NFSREQ, M_WAITOK);
2380 sp->s_cred = crhold(cnp->cn_cred);
2384 /* Fudge together a funny name */
2385 pid = cnp->cn_thread->td_proc->p_pid;
2386 sp->s_namlen = sprintf(sp->s_name, ".nfsA%04x4.4", pid);
2388 /* Try lookitups until we get one that isn't there */
2389 while (nfs_lookitup(dvp, sp->s_name, sp->s_namlen, sp->s_cred,
2390 cnp->cn_thread, NULL) == 0) {
2392 if (sp->s_name[4] > 'z') {
2397 error = nfs_renameit(dvp, cnp, sp);
2400 error = nfs_lookitup(dvp, sp->s_name, sp->s_namlen, sp->s_cred,
2401 cnp->cn_thread, &np);
2402 np->n_sillyrename = sp;
2407 free((caddr_t)sp, M_NFSREQ);
2412 * Look up a file name and optionally either update the file handle or
2413 * allocate an nfsnode, depending on the value of npp.
2414 * npp == NULL --> just do the lookup
2415 * *npp == NULL --> allocate a new nfsnode and make sure attributes are
2417 * *npp != NULL --> update the file handle in the vnode
2420 nfs_lookitup(struct vnode *dvp, const char *name, int len, struct ucred *cred,
2421 struct thread *td, struct nfsnode **npp)
2423 struct vnode *newvp = NULL;
2424 struct nfsnode *np, *dnp = VTONFS(dvp);
2426 int error = 0, fhlen, attrflag;
2427 struct mbuf *mreq, *mrep, *md, *mb;
2429 int v3 = NFS_ISV3(dvp);
2431 nfsstats.rpccnt[NFSPROC_LOOKUP]++;
2432 mreq = nfsm_reqhead(dvp, NFSPROC_LOOKUP,
2433 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len));
2435 bpos = mtod(mb, caddr_t);
2436 nfsm_fhtom(dvp, v3);
2437 nfsm_strtom(name, len, NFS_MAXNAMLEN);
2438 nfsm_request(dvp, NFSPROC_LOOKUP, td, cred);
2439 if (npp && !error) {
2440 nfsm_getfh(nfhp, fhlen, v3);
2443 if (np->n_fhsize > NFS_SMALLFH && fhlen <= NFS_SMALLFH) {
2444 free((caddr_t)np->n_fhp, M_NFSBIGFH);
2445 np->n_fhp = &np->n_fh;
2446 } else if (np->n_fhsize <= NFS_SMALLFH && fhlen>NFS_SMALLFH)
2447 np->n_fhp =(nfsfh_t *)malloc(fhlen, M_NFSBIGFH, M_WAITOK);
2448 bcopy((caddr_t)nfhp, (caddr_t)np->n_fhp, fhlen);
2449 np->n_fhsize = fhlen;
2451 } else if (NFS_CMPFH(dnp, nfhp, fhlen)) {
2455 error = nfs_nget(dvp->v_mount, nfhp, fhlen, &np);
2463 nfsm_postop_attr(newvp, attrflag);
2464 if (!attrflag && *npp == NULL) {
2473 nfsm_loadattr(newvp, NULL);
2477 if (npp && *npp == NULL) {
2492 * Nfs Version 3 commit rpc
2495 nfs_commit(struct vnode *vp, u_quad_t offset, int cnt, struct ucred *cred,
2499 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2501 int error = 0, wccflag = NFSV3_WCCRATTR;
2502 struct mbuf *mreq, *mrep, *md, *mb;
2504 if ((nmp->nm_state & NFSSTA_HASWRITEVERF) == 0)
2506 nfsstats.rpccnt[NFSPROC_COMMIT]++;
2507 mreq = nfsm_reqhead(vp, NFSPROC_COMMIT, NFSX_FH(1));
2509 bpos = mtod(mb, caddr_t);
2511 tl = nfsm_build(u_int32_t *, 3 * NFSX_UNSIGNED);
2512 txdr_hyper(offset, tl);
2514 *tl = txdr_unsigned(cnt);
2515 nfsm_request(vp, NFSPROC_COMMIT, td, cred);
2516 nfsm_wcc_data(vp, wccflag);
2518 tl = nfsm_dissect(u_int32_t *, NFSX_V3WRITEVERF);
2519 if (bcmp((caddr_t)nmp->nm_verf, (caddr_t)tl,
2520 NFSX_V3WRITEVERF)) {
2521 bcopy((caddr_t)tl, (caddr_t)nmp->nm_verf,
2523 error = NFSERR_STALEWRITEVERF;
2533 * For async requests when nfsiod(s) are running, queue the request by
2534 * calling nfs_asyncio(), otherwise just all nfs_doio() to do the
2538 nfs_strategy(struct vop_strategy_args *ap)
2540 struct buf *bp = ap->a_bp;
2545 KASSERT(!(bp->b_flags & B_DONE), ("nfs_strategy: buffer %p unexpectedly marked B_DONE", bp));
2546 KASSERT(BUF_REFCNT(bp) > 0, ("nfs_strategy: buffer %p not locked", bp));
2548 if (bp->b_flags & B_PHYS)
2549 panic("nfs physio");
2551 if (bp->b_flags & B_ASYNC)
2554 td = curthread; /* XXX */
2556 if (bp->b_iocmd == BIO_READ)
2562 * If the op is asynchronous and an i/o daemon is waiting
2563 * queue the request, wake it up and wait for completion
2564 * otherwise just do it ourselves.
2566 if ((bp->b_flags & B_ASYNC) == 0 ||
2567 nfs_asyncio(bp, NOCRED, td))
2568 error = nfs_doio(bp, cr, td);
2573 * fsync vnode op. Just call nfs_flush() with commit == 1.
2577 nfs_fsync(struct vop_fsync_args *ap)
2580 return (nfs_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));
2584 * Flush all the blocks associated with a vnode.
2585 * Walk through the buffer pool and push any dirty pages
2586 * associated with the vnode.
2589 nfs_flush(struct vnode *vp, struct ucred *cred, int waitfor, struct thread *td,
2592 struct nfsnode *np = VTONFS(vp);
2596 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2597 int s, error = 0, slptimeo = 0, slpflag = 0, retv, bvecpos;
2599 u_quad_t off, endoff, toff;
2600 struct ucred* wcred = NULL;
2601 struct buf **bvec = NULL;
2602 #ifndef NFS_COMMITBVECSIZ
2603 #define NFS_COMMITBVECSIZ 20
2605 struct buf *bvec_on_stack[NFS_COMMITBVECSIZ];
2606 int bvecsize = 0, bveccount;
2608 if (nmp->nm_flag & NFSMNT_INT)
2613 * A b_flags == (B_DELWRI | B_NEEDCOMMIT) block has been written to the
2614 * server, but nas not been committed to stable storage on the server
2615 * yet. On the first pass, the byte range is worked out and the commit
2616 * rpc is done. On the second pass, nfs_writebp() is called to do the
2623 if (NFS_ISV3(vp) && commit) {
2626 * Count up how many buffers waiting for a commit.
2630 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
2631 nbp = TAILQ_NEXT(bp, b_vnbufs);
2632 if (BUF_REFCNT(bp) == 0 &&
2633 (bp->b_flags & (B_DELWRI | B_NEEDCOMMIT))
2634 == (B_DELWRI | B_NEEDCOMMIT))
2638 * Allocate space to remember the list of bufs to commit. It is
2639 * important to use M_NOWAIT here to avoid a race with nfs_write.
2640 * If we can't get memory (for whatever reason), we will end up
2641 * committing the buffers one-by-one in the loop below.
2643 if (bvec != NULL && bvec != bvec_on_stack)
2645 if (bveccount > NFS_COMMITBVECSIZ) {
2646 bvec = (struct buf **)
2647 malloc(bveccount * sizeof(struct buf *),
2650 bvec = bvec_on_stack;
2651 bvecsize = NFS_COMMITBVECSIZ;
2653 bvecsize = bveccount;
2655 bvec = bvec_on_stack;
2656 bvecsize = NFS_COMMITBVECSIZ;
2658 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
2659 if (bvecpos >= bvecsize)
2662 if ((bp->b_flags & (B_DELWRI | B_NEEDCOMMIT)) !=
2663 (B_DELWRI | B_NEEDCOMMIT) ||
2664 BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT)) {
2666 nbp = TAILQ_NEXT(bp, b_vnbufs);
2671 * Work out if all buffers are using the same cred
2672 * so we can deal with them all with one commit.
2674 * NOTE: we are not clearing B_DONE here, so we have
2675 * to do it later on in this routine if we intend to
2676 * initiate I/O on the bp.
2678 * Note: to avoid loopback deadlocks, we do not
2679 * assign b_runningbufspace.
2682 wcred = bp->b_wcred;
2683 else if (wcred != bp->b_wcred)
2685 bp->b_flags |= B_WRITEINPROG;
2686 vfs_busy_pages(bp, 1);
2690 * bp is protected by being locked, but nbp is not
2691 * and vfs_busy_pages() may sleep. We have to
2694 nbp = TAILQ_NEXT(bp, b_vnbufs);
2697 * A list of these buffers is kept so that the
2698 * second loop knows which buffers have actually
2699 * been committed. This is necessary, since there
2700 * may be a race between the commit rpc and new
2701 * uncommitted writes on the file.
2703 bvec[bvecpos++] = bp;
2704 toff = ((u_quad_t)bp->b_blkno) * DEV_BSIZE +
2708 toff += (u_quad_t)(bp->b_dirtyend - bp->b_dirtyoff);
2717 * Commit data on the server, as required.
2718 * If all bufs are using the same wcred, then use that with
2719 * one call for all of them, otherwise commit each one
2722 if (wcred != NOCRED)
2723 retv = nfs_commit(vp, off, (int)(endoff - off),
2727 for (i = 0; i < bvecpos; i++) {
2730 off = ((u_quad_t)bp->b_blkno) * DEV_BSIZE +
2732 size = (u_quad_t)(bp->b_dirtyend
2734 retv = nfs_commit(vp, off, (int)size,
2740 if (retv == NFSERR_STALEWRITEVERF)
2741 nfs_clearcommit(vp->v_mount);
2744 * Now, either mark the blocks I/O done or mark the
2745 * blocks dirty, depending on whether the commit
2748 for (i = 0; i < bvecpos; i++) {
2750 bp->b_flags &= ~(B_NEEDCOMMIT | B_WRITEINPROG | B_CLUSTEROK);
2753 * Error, leave B_DELWRI intact
2755 vfs_unbusy_pages(bp);
2759 * Success, remove B_DELWRI ( bundirty() ).
2761 * b_dirtyoff/b_dirtyend seem to be NFS
2762 * specific. We should probably move that
2763 * into bundirty(). XXX
2769 bp->b_flags |= B_ASYNC;
2771 bp->b_flags &= ~B_DONE;
2772 bp->b_ioflags &= ~BIO_ERROR;
2773 bp->b_dirtyoff = bp->b_dirtyend = 0;
2781 * Start/do any write(s) that are required.
2786 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
2787 nbp = TAILQ_NEXT(bp, b_vnbufs);
2789 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT)) {
2790 if (waitfor != MNT_WAIT || passone) {
2794 error = BUF_TIMELOCK(bp, LK_EXCLUSIVE | LK_SLEEPFAIL,
2795 "nfsfsync", slpflag, slptimeo);
2798 panic("nfs_fsync: inconsistent lock");
2799 if (error == ENOLCK)
2801 if (nfs_sigintr(nmp, NULL, td)) {
2805 if (slpflag == PCATCH) {
2811 if ((bp->b_flags & B_DELWRI) == 0)
2812 panic("nfs_fsync: not dirty");
2813 if ((passone || !commit) && (bp->b_flags & B_NEEDCOMMIT)) {
2819 if (passone || !commit)
2820 bp->b_flags |= B_ASYNC;
2822 bp->b_flags |= B_ASYNC | B_WRITEINPROG;
2833 if (waitfor == MNT_WAIT) {
2834 while (vp->v_numoutput) {
2835 vp->v_iflag |= VI_BWAIT;
2836 error = msleep((caddr_t)&vp->v_numoutput, VI_MTX(vp),
2837 slpflag | (PRIBIO + 1), "nfsfsync", slptimeo);
2839 if (nfs_sigintr(nmp, NULL, td)) {
2844 if (slpflag == PCATCH) {
2850 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd) && commit) {
2856 if (np->n_flag & NWRITEERR) {
2857 error = np->n_error;
2858 np->n_flag &= ~NWRITEERR;
2861 if (bvec != NULL && bvec != bvec_on_stack)
2867 * NFS advisory byte-level locks.
2870 nfs_advlock(struct vop_advlock_args *ap)
2873 if ((VFSTONFS(ap->a_vp->v_mount)->nm_flag & NFSMNT_NOLOCKD) != 0) {
2874 struct nfsnode *np = VTONFS(ap->a_vp);
2876 return (lf_advlock(ap, &(np->n_lockf), np->n_size));
2878 return (nfs_dolock(ap));
2882 * Print out the contents of an nfsnode.
2885 nfs_print(struct vop_print_args *ap)
2887 struct vnode *vp = ap->a_vp;
2888 struct nfsnode *np = VTONFS(vp);
2890 printf("tag %s fileid %ld fsid 0x%x",
2891 vp->v_tag, np->n_vattr.va_fileid, np->n_vattr.va_fsid);
2892 if (vp->v_type == VFIFO)
2899 * This is the "real" nfs::bwrite(struct buf*).
2900 * B_WRITEINPROG isn't set unless the force flag is one and it
2901 * handles the B_NEEDCOMMIT flag.
2902 * We set B_CACHE if this is a VMIO buffer.
2905 nfs_writebp(struct buf *bp, int force, struct thread *td)
2908 int oldflags = bp->b_flags;
2914 if (BUF_REFCNT(bp) == 0)
2915 panic("bwrite: buffer is not locked???");
2917 if (bp->b_flags & B_INVAL) {
2922 bp->b_flags |= B_CACHE;
2925 * Undirty the bp. We will redirty it later if the I/O fails.
2930 bp->b_flags &= ~B_DONE;
2931 bp->b_ioflags &= ~BIO_ERROR;
2932 bp->b_iocmd = BIO_WRITE;
2935 bp->b_vp->v_numoutput++;
2936 VI_UNLOCK(bp->b_vp);
2937 curthread->td_proc->p_stats->p_ru.ru_oublock++;
2941 * Note: to avoid loopback deadlocks, we do not
2942 * assign b_runningbufspace.
2944 vfs_busy_pages(bp, 1);
2947 bp->b_flags |= B_WRITEINPROG;
2951 if( (oldflags & B_ASYNC) == 0) {
2952 int rtval = bufwait(bp);
2954 if (oldflags & B_DELWRI) {
2956 reassignbuf(bp, bp->b_vp);
2968 * nfs special file access vnode op.
2969 * Essentially just get vattr and then imitate iaccess() since the device is
2970 * local to the client.
2973 nfsspec_access(struct vop_access_args *ap)
2977 struct ucred *cred = ap->a_cred;
2978 struct vnode *vp = ap->a_vp;
2979 mode_t mode = ap->a_mode;
2985 * Disallow write attempts on filesystems mounted read-only;
2986 * unless the file is a socket, fifo, or a block or character
2987 * device resident on the filesystem.
2989 if ((mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
2990 switch (vp->v_type) {
3000 * If you're the super-user,
3001 * you always get access.
3003 if (cred->cr_uid == 0)
3006 error = VOP_GETATTR(vp, vap, cred, ap->a_td);
3010 * Access check is based on only one of owner, group, public.
3011 * If not owner, then check group. If not a member of the
3012 * group, then check public access.
3014 if (cred->cr_uid != vap->va_uid) {
3016 gp = cred->cr_groups;
3017 for (i = 0; i < cred->cr_ngroups; i++, gp++)
3018 if (vap->va_gid == *gp)
3024 error = (vap->va_mode & mode) == mode ? 0 : EACCES;
3029 * Read wrapper for special devices.
3032 nfsspec_read(struct vop_read_args *ap)
3034 struct nfsnode *np = VTONFS(ap->a_vp);
3040 getnanotime(&np->n_atim);
3041 return (VOCALL(spec_vnodeop_p, VOFFSET(vop_read), ap));
3045 * Write wrapper for special devices.
3048 nfsspec_write(struct vop_write_args *ap)
3050 struct nfsnode *np = VTONFS(ap->a_vp);
3056 getnanotime(&np->n_mtim);
3057 return (VOCALL(spec_vnodeop_p, VOFFSET(vop_write), ap));
3061 * Close wrapper for special devices.
3063 * Update the times on the nfsnode then do device close.
3066 nfsspec_close(struct vop_close_args *ap)
3068 struct vnode *vp = ap->a_vp;
3069 struct nfsnode *np = VTONFS(vp);
3072 if (np->n_flag & (NACC | NUPD)) {
3074 if (vrefcnt(vp) == 1 &&
3075 (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
3077 if (np->n_flag & NACC)
3078 vattr.va_atime = np->n_atim;
3079 if (np->n_flag & NUPD)
3080 vattr.va_mtime = np->n_mtim;
3081 (void)VOP_SETATTR(vp, &vattr, ap->a_cred, ap->a_td);
3084 return (VOCALL(spec_vnodeop_p, VOFFSET(vop_close), ap));
3088 * Read wrapper for fifos.
3091 nfsfifo_read(struct vop_read_args *ap)
3093 struct nfsnode *np = VTONFS(ap->a_vp);
3099 getnanotime(&np->n_atim);
3100 return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_read), ap));
3104 * Write wrapper for fifos.
3107 nfsfifo_write(struct vop_write_args *ap)
3109 struct nfsnode *np = VTONFS(ap->a_vp);
3115 getnanotime(&np->n_mtim);
3116 return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_write), ap));
3120 * Close wrapper for fifos.
3122 * Update the times on the nfsnode then do fifo close.
3125 nfsfifo_close(struct vop_close_args *ap)
3127 struct vnode *vp = ap->a_vp;
3128 struct nfsnode *np = VTONFS(vp);
3132 if (np->n_flag & (NACC | NUPD)) {
3134 if (np->n_flag & NACC)
3136 if (np->n_flag & NUPD)
3139 if (vrefcnt(vp) == 1 &&
3140 (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
3142 if (np->n_flag & NACC)
3143 vattr.va_atime = np->n_atim;
3144 if (np->n_flag & NUPD)
3145 vattr.va_mtime = np->n_mtim;
3146 (void)VOP_SETATTR(vp, &vattr, ap->a_cred, ap->a_td);
3149 return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_close), ap));