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 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * from nfs_vnops.c 8.16 (Berkeley) 5/27/95
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
39 * vnode op calls for Sun NFS version 2, 3 and 4
44 #include <sys/param.h>
45 #include <sys/kernel.h>
46 #include <sys/systm.h>
47 #include <sys/resourcevar.h>
49 #include <sys/mount.h>
53 #include <sys/malloc.h>
55 #include <sys/namei.h>
56 #include <sys/socket.h>
57 #include <sys/vnode.h>
58 #include <sys/dirent.h>
59 #include <sys/fcntl.h>
60 #include <sys/lockf.h>
62 #include <sys/sysctl.h>
63 #include <sys/signalvar.h>
66 #include <vm/vm_object.h>
67 #include <vm/vm_extern.h>
68 #include <vm/vm_object.h>
71 #include <fs/nfs/nfsport.h>
72 #include <fs/nfsclient/nfsnode.h>
73 #include <fs/nfsclient/nfsmount.h>
74 #include <fs/nfsclient/nfs.h>
75 #include <fs/nfsclient/nfs_lock.h>
78 #include <netinet/in.h>
79 #include <netinet/in_var.h>
85 extern struct nfsstats newnfsstats;
86 MALLOC_DECLARE(M_NEWNFSREQ);
87 vop_advlock_t *ncl_advlock_p = ncl_dolock;
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 vop_read_t nfsfifo_read;
99 static vop_write_t nfsfifo_write;
100 static vop_close_t nfsfifo_close;
101 static int nfs_setattrrpc(struct vnode *, struct vattr *, struct ucred *,
103 static vop_lookup_t nfs_lookup;
104 static vop_create_t nfs_create;
105 static vop_mknod_t nfs_mknod;
106 static vop_open_t nfs_open;
107 static vop_close_t nfs_close;
108 static vop_access_t nfs_access;
109 static vop_getattr_t nfs_getattr;
110 static vop_setattr_t nfs_setattr;
111 static vop_read_t nfs_read;
112 static vop_fsync_t nfs_fsync;
113 static vop_remove_t nfs_remove;
114 static vop_link_t nfs_link;
115 static vop_rename_t nfs_rename;
116 static vop_mkdir_t nfs_mkdir;
117 static vop_rmdir_t nfs_rmdir;
118 static vop_symlink_t nfs_symlink;
119 static vop_readdir_t nfs_readdir;
120 static vop_strategy_t nfs_strategy;
121 static vop_lock1_t nfs_lock1;
122 static int nfs_lookitup(struct vnode *, char *, int,
123 struct ucred *, struct thread *, struct nfsnode **);
124 static int nfs_sillyrename(struct vnode *, struct vnode *,
125 struct componentname *);
126 static vop_access_t nfsspec_access;
127 static vop_readlink_t nfs_readlink;
128 static vop_print_t nfs_print;
129 static vop_advlock_t nfs_advlock;
130 static vop_advlockasync_t nfs_advlockasync;
131 #ifdef NFS4_ACL_EXTATTR_NAME
132 static vop_getacl_t nfs_getacl;
133 static vop_setacl_t nfs_setacl;
137 * Global vfs data structures for nfs
139 struct vop_vector newnfs_vnodeops = {
140 .vop_default = &default_vnodeops,
141 .vop_access = nfs_access,
142 .vop_advlock = nfs_advlock,
143 .vop_advlockasync = nfs_advlockasync,
144 .vop_close = nfs_close,
145 .vop_create = nfs_create,
146 .vop_fsync = nfs_fsync,
147 .vop_getattr = nfs_getattr,
148 .vop_getpages = ncl_getpages,
149 .vop_putpages = ncl_putpages,
150 .vop_inactive = ncl_inactive,
151 .vop_link = nfs_link,
152 .vop_lock1 = nfs_lock1,
153 .vop_lookup = nfs_lookup,
154 .vop_mkdir = nfs_mkdir,
155 .vop_mknod = nfs_mknod,
156 .vop_open = nfs_open,
157 .vop_print = nfs_print,
158 .vop_read = nfs_read,
159 .vop_readdir = nfs_readdir,
160 .vop_readlink = nfs_readlink,
161 .vop_reclaim = ncl_reclaim,
162 .vop_remove = nfs_remove,
163 .vop_rename = nfs_rename,
164 .vop_rmdir = nfs_rmdir,
165 .vop_setattr = nfs_setattr,
166 .vop_strategy = nfs_strategy,
167 .vop_symlink = nfs_symlink,
168 .vop_write = ncl_write,
169 #ifdef NFS4_ACL_EXTATTR_NAME
170 .vop_getacl = nfs_getacl,
171 .vop_setacl = nfs_setacl,
175 struct vop_vector newnfs_fifoops = {
176 .vop_default = &fifo_specops,
177 .vop_access = nfsspec_access,
178 .vop_close = nfsfifo_close,
179 .vop_fsync = nfs_fsync,
180 .vop_getattr = nfs_getattr,
181 .vop_inactive = ncl_inactive,
182 .vop_print = nfs_print,
183 .vop_read = nfsfifo_read,
184 .vop_reclaim = ncl_reclaim,
185 .vop_setattr = nfs_setattr,
186 .vop_write = nfsfifo_write,
189 static int nfs_mknodrpc(struct vnode *dvp, struct vnode **vpp,
190 struct componentname *cnp, struct vattr *vap);
191 static int nfs_removerpc(struct vnode *dvp, struct vnode *vp, char *name,
192 int namelen, struct ucred *cred, struct thread *td);
193 static int nfs_renamerpc(struct vnode *fdvp, struct vnode *fvp,
194 char *fnameptr, int fnamelen, struct vnode *tdvp, struct vnode *tvp,
195 char *tnameptr, int tnamelen, struct ucred *cred, struct thread *td);
196 static int nfs_renameit(struct vnode *sdvp, struct vnode *svp,
197 struct componentname *scnp, struct sillyrename *sp);
202 #define DIRHDSIZ (sizeof (struct dirent) - (MAXNAMLEN + 1))
204 SYSCTL_DECL(_vfs_newnfs);
206 static int nfsaccess_cache_timeout = NFS_MAXATTRTIMO;
207 SYSCTL_INT(_vfs_newnfs, OID_AUTO, access_cache_timeout, CTLFLAG_RW,
208 &nfsaccess_cache_timeout, 0, "NFS ACCESS cache timeout");
210 static int nfs_prime_access_cache = 0;
211 SYSCTL_INT(_vfs_newnfs, OID_AUTO, prime_access_cache, CTLFLAG_RW,
212 &nfs_prime_access_cache, 0,
213 "Prime NFS ACCESS cache when fetching attributes");
215 static int newnfs_commit_on_close = 0;
216 SYSCTL_INT(_vfs_newnfs, OID_AUTO, commit_on_close, CTLFLAG_RW,
217 &newnfs_commit_on_close, 0, "write+commit on close, else only write");
219 static int nfs_clean_pages_on_close = 1;
220 SYSCTL_INT(_vfs_newnfs, OID_AUTO, clean_pages_on_close, CTLFLAG_RW,
221 &nfs_clean_pages_on_close, 0, "NFS clean dirty pages on close");
223 int newnfs_directio_enable = 0;
224 SYSCTL_INT(_vfs_newnfs, OID_AUTO, directio_enable, CTLFLAG_RW,
225 &newnfs_directio_enable, 0, "Enable NFS directio");
227 static int newnfs_neglookup_enable = 1;
228 SYSCTL_INT(_vfs_newnfs, OID_AUTO, neglookup_enable, CTLFLAG_RW,
229 &newnfs_neglookup_enable, 0, "Enable NFS negative lookup caching");
232 * This sysctl allows other processes to mmap a file that has been opened
233 * O_DIRECT by a process. In general, having processes mmap the file while
234 * Direct IO is in progress can lead to Data Inconsistencies. But, we allow
235 * this by default to prevent DoS attacks - to prevent a malicious user from
236 * opening up files O_DIRECT preventing other users from mmap'ing these
237 * files. "Protected" environments where stricter consistency guarantees are
238 * required can disable this knob. The process that opened the file O_DIRECT
239 * cannot mmap() the file, because mmap'ed IO on an O_DIRECT open() is not
242 int newnfs_directio_allow_mmap = 1;
243 SYSCTL_INT(_vfs_newnfs, OID_AUTO, directio_allow_mmap, CTLFLAG_RW,
244 &newnfs_directio_allow_mmap, 0, "Enable mmaped IO on file with O_DIRECT opens");
247 SYSCTL_INT(_vfs_newnfs, OID_AUTO, access_cache_hits, CTLFLAG_RD,
248 &newnfsstats.accesscache_hits, 0, "NFS ACCESS cache hit count");
250 SYSCTL_INT(_vfs_newnfs, OID_AUTO, access_cache_misses, CTLFLAG_RD,
251 &newnfsstats.accesscache_misses, 0, "NFS ACCESS cache miss count");
254 #define NFSACCESS_ALL (NFSACCESS_READ | NFSACCESS_MODIFY \
255 | NFSACCESS_EXTEND | NFSACCESS_EXECUTE \
256 | NFSACCESS_DELETE | NFSACCESS_LOOKUP)
260 * The list of locks after the description of the lock is the ordering
261 * of other locks acquired with the lock held.
262 * np->n_mtx : Protects the fields in the nfsnode.
264 VI_MTX (acquired indirectly)
265 * nmp->nm_mtx : Protects the fields in the nfsmount.
267 * ncl_iod_mutex : Global lock, protects shared nfsiod state.
268 * nfs_reqq_mtx : Global lock, protects the nfs_reqq list.
271 * rep->r_mtx : Protects the fields in an nfsreq.
275 nfs34_access_otw(struct vnode *vp, int wmode, struct thread *td,
276 struct ucred *cred, u_int32_t *retmode)
278 int error = 0, attrflag, i, lrupos;
280 struct nfsnode *np = VTONFS(vp);
281 struct nfsvattr nfsva;
283 error = nfsrpc_accessrpc(vp, wmode, cred, td, &nfsva, &attrflag,
286 (void) nfscl_loadattrcache(&vp, &nfsva, NULL, NULL, 0, 1);
289 mtx_lock(&np->n_mtx);
290 for (i = 0; i < NFS_ACCESSCACHESIZE; i++) {
291 if (np->n_accesscache[i].uid == cred->cr_uid) {
292 np->n_accesscache[i].mode = rmode;
293 np->n_accesscache[i].stamp = time_second;
296 if (i > 0 && np->n_accesscache[i].stamp <
297 np->n_accesscache[lrupos].stamp)
300 if (i == NFS_ACCESSCACHESIZE) {
301 np->n_accesscache[lrupos].uid = cred->cr_uid;
302 np->n_accesscache[lrupos].mode = rmode;
303 np->n_accesscache[lrupos].stamp = time_second;
305 mtx_unlock(&np->n_mtx);
308 } else if (NFS_ISV4(vp)) {
309 error = nfscl_maperr(td, error, (uid_t)0, (gid_t)0);
315 * nfs access vnode op.
316 * For nfs version 2, just return ok. File accesses may fail later.
317 * For nfs version 3, use the access rpc to check accessibility. If file modes
318 * are changed on the server, accesses might still fail later.
321 nfs_access(struct vop_access_args *ap)
323 struct vnode *vp = ap->a_vp;
324 int error = 0, i, gotahit;
325 u_int32_t mode, wmode, rmode;
326 int v34 = NFS_ISV34(vp);
327 struct nfsnode *np = VTONFS(vp);
330 * Disallow write attempts on filesystems mounted read-only;
331 * unless the file is a socket, fifo, or a block or character
332 * device resident on the filesystem.
334 if ((ap->a_accmode & (VWRITE | VAPPEND
335 #ifdef NFS4_ACL_EXTATTR_NAME
336 | VWRITE_NAMED_ATTRS | VDELETE_CHILD | VWRITE_ATTRIBUTES |
337 VDELETE | VWRITE_ACL | VWRITE_OWNER
339 )) != 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) != 0) {
340 switch (vp->v_type) {
350 * For nfs v3 or v4, check to see if we have done this recently, and if
351 * so return our cached result instead of making an ACCESS call.
352 * If not, do an access rpc, otherwise you are stuck emulating
353 * ufs_access() locally using the vattr. This may not be correct,
354 * since the server may apply other access criteria such as
355 * client uid-->server uid mapping that we do not know about.
358 if (ap->a_accmode & VREAD)
359 mode = NFSACCESS_READ;
362 if (vp->v_type != VDIR) {
363 if (ap->a_accmode & VWRITE)
364 mode |= (NFSACCESS_MODIFY | NFSACCESS_EXTEND);
365 if (ap->a_accmode & VAPPEND)
366 mode |= NFSACCESS_EXTEND;
367 if (ap->a_accmode & VEXEC)
368 mode |= NFSACCESS_EXECUTE;
369 #ifdef NFS4_ACL_EXTATTR_NAME
370 if (ap->a_accmode & VDELETE)
371 mode |= NFSACCESS_DELETE;
374 if (ap->a_accmode & VWRITE)
375 mode |= (NFSACCESS_MODIFY | NFSACCESS_EXTEND);
376 if (ap->a_accmode & VAPPEND)
377 mode |= NFSACCESS_EXTEND;
378 if (ap->a_accmode & VEXEC)
379 mode |= NFSACCESS_LOOKUP;
380 #ifdef NFS4_ACL_EXTATTR_NAME
381 if (ap->a_accmode & VDELETE)
382 mode |= NFSACCESS_DELETE;
383 if (ap->a_accmode & VDELETE_CHILD)
384 mode |= NFSACCESS_MODIFY;
387 /* XXX safety belt, only make blanket request if caching */
388 if (nfsaccess_cache_timeout > 0) {
389 wmode = NFSACCESS_READ | NFSACCESS_MODIFY |
390 NFSACCESS_EXTEND | NFSACCESS_EXECUTE |
391 NFSACCESS_DELETE | NFSACCESS_LOOKUP;
397 * Does our cached result allow us to give a definite yes to
401 mtx_lock(&np->n_mtx);
402 for (i = 0; i < NFS_ACCESSCACHESIZE; i++) {
403 if (ap->a_cred->cr_uid == np->n_accesscache[i].uid) {
404 if (time_second < (np->n_accesscache[i].stamp
405 + nfsaccess_cache_timeout) &&
406 (np->n_accesscache[i].mode & mode) == mode) {
407 NFSINCRGLOBAL(newnfsstats.accesscache_hits);
413 mtx_unlock(&np->n_mtx);
416 * Either a no, or a don't know. Go to the wire.
418 NFSINCRGLOBAL(newnfsstats.accesscache_misses);
419 error = nfs34_access_otw(vp, wmode, ap->a_td,
422 (rmode & mode) != mode)
427 if ((error = nfsspec_access(ap)) != 0) {
431 * Attempt to prevent a mapped root from accessing a file
432 * which it shouldn't. We try to read a byte from the file
433 * if the user is root and the file is not zero length.
434 * After calling nfsspec_access, we should have the correct
437 mtx_lock(&np->n_mtx);
438 if (ap->a_cred->cr_uid == 0 && (ap->a_accmode & VREAD)
439 && VTONFS(vp)->n_size > 0) {
444 mtx_unlock(&np->n_mtx);
447 auio.uio_iov = &aiov;
451 auio.uio_segflg = UIO_SYSSPACE;
452 auio.uio_rw = UIO_READ;
453 auio.uio_td = ap->a_td;
455 if (vp->v_type == VREG)
456 error = ncl_readrpc(vp, &auio, ap->a_cred);
457 else if (vp->v_type == VDIR) {
459 bp = malloc(NFS_DIRBLKSIZ, M_TEMP, M_WAITOK);
461 aiov.iov_len = auio.uio_resid = NFS_DIRBLKSIZ;
462 error = ncl_readdirrpc(vp, &auio, ap->a_cred,
465 } else if (vp->v_type == VLNK)
466 error = ncl_readlinkrpc(vp, &auio, ap->a_cred);
470 mtx_unlock(&np->n_mtx);
478 * Check to see if the type is ok
479 * and that deletion is not in progress.
480 * For paged in text files, you will need to flush the page cache
481 * if consistency is lost.
485 nfs_open(struct vop_open_args *ap)
487 struct vnode *vp = ap->a_vp;
488 struct nfsnode *np = VTONFS(vp);
491 int fmode = ap->a_mode;
493 if (vp->v_type != VREG && vp->v_type != VDIR && vp->v_type != VLNK)
497 * For NFSv4, we need to do the Open Op before cache validation,
498 * so that we conform to RFC3530 Sec. 9.3.1.
501 error = nfsrpc_open(vp, fmode, ap->a_cred, ap->a_td);
503 error = nfscl_maperr(ap->a_td, error, (uid_t)0,
510 * Now, if this Open will be doing reading, re-validate/flush the
511 * cache, so that Close/Open coherency is maintained.
513 if ((fmode & FREAD) && (!NFS_ISV4(vp) || nfscl_mustflush(vp))) {
514 mtx_lock(&np->n_mtx);
515 if (np->n_flag & NMODIFIED) {
516 mtx_unlock(&np->n_mtx);
517 error = ncl_vinvalbuf(vp, V_SAVE, ap->a_td, 1);
518 if (error == EINTR || error == EIO) {
520 (void) nfsrpc_close(vp, 0, ap->a_td);
524 if (vp->v_type == VDIR)
525 np->n_direofoffset = 0;
526 error = VOP_GETATTR(vp, &vattr, ap->a_cred);
529 (void) nfsrpc_close(vp, 0, ap->a_td);
532 mtx_lock(&np->n_mtx);
533 np->n_mtime = vattr.va_mtime;
535 np->n_change = vattr.va_filerev;
536 mtx_unlock(&np->n_mtx);
538 struct thread *td = curthread;
540 if (np->n_ac_ts_syscalls != td->td_syscalls ||
541 np->n_ac_ts_tid != td->td_tid ||
542 td->td_proc == NULL ||
543 np->n_ac_ts_pid != td->td_proc->p_pid) {
546 mtx_unlock(&np->n_mtx);
547 error = VOP_GETATTR(vp, &vattr, ap->a_cred);
550 (void) nfsrpc_close(vp, 0, ap->a_td);
553 mtx_lock(&np->n_mtx);
554 if ((NFS_ISV4(vp) && np->n_change != vattr.va_filerev) ||
555 NFS_TIMESPEC_COMPARE(&np->n_mtime, &vattr.va_mtime)) {
556 if (vp->v_type == VDIR)
557 np->n_direofoffset = 0;
558 mtx_unlock(&np->n_mtx);
559 error = ncl_vinvalbuf(vp, V_SAVE, ap->a_td, 1);
560 if (error == EINTR || error == EIO) {
562 (void) nfsrpc_close(vp, 0,
566 mtx_lock(&np->n_mtx);
567 np->n_mtime = vattr.va_mtime;
569 np->n_change = vattr.va_filerev;
571 mtx_unlock(&np->n_mtx);
576 * If the object has >= 1 O_DIRECT active opens, we disable caching.
578 if (newnfs_directio_enable && (fmode & O_DIRECT) && (vp->v_type == VREG)) {
579 if (np->n_directio_opens == 0) {
580 error = ncl_vinvalbuf(vp, V_SAVE, ap->a_td, 1);
583 (void) nfsrpc_close(vp, 0, ap->a_td);
586 mtx_lock(&np->n_mtx);
587 np->n_flag |= NNONCACHE;
589 mtx_lock(&np->n_mtx);
591 np->n_directio_opens++;
592 mtx_unlock(&np->n_mtx);
594 vnode_create_vobject(vp, vattr.va_size, ap->a_td);
600 * What an NFS client should do upon close after writing is a debatable issue.
601 * Most NFS clients push delayed writes to the server upon close, basically for
603 * 1 - So that any write errors may be reported back to the client process
604 * doing the close system call. By far the two most likely errors are
605 * NFSERR_NOSPC and NFSERR_DQUOT to indicate space allocation failure.
606 * 2 - To put a worst case upper bound on cache inconsistency between
607 * multiple clients for the file.
608 * There is also a consistency problem for Version 2 of the protocol w.r.t.
609 * not being able to tell if other clients are writing a file concurrently,
610 * since there is no way of knowing if the changed modify time in the reply
611 * is only due to the write for this client.
612 * (NFS Version 3 provides weak cache consistency data in the reply that
613 * should be sufficient to detect and handle this case.)
615 * The current code does the following:
616 * for NFS Version 2 - play it safe and flush/invalidate all dirty buffers
617 * for NFS Version 3 - flush dirty buffers to the server but don't invalidate
618 * or commit them (this satisfies 1 and 2 except for the
619 * case where the server crashes after this close but
620 * before the commit RPC, which is felt to be "good
621 * enough". Changing the last argument to ncl_flush() to
622 * a 1 would force a commit operation, if it is felt a
623 * commit is necessary now.
624 * for NFS Version 4 - flush the dirty buffers and commit them, if
625 * nfscl_mustflush() says this is necessary.
626 * It is necessary if there is no write delegation held,
627 * in order to satisfy open/close coherency.
628 * If the file isn't cached on local stable storage,
629 * it may be necessary in order to detect "out of space"
630 * errors from the server, if the write delegation
631 * issued by the server doesn't allow the file to grow.
635 nfs_close(struct vop_close_args *ap)
637 struct vnode *vp = ap->a_vp;
638 struct nfsnode *np = VTONFS(vp);
639 struct nfsvattr nfsva;
641 int error = 0, ret, localcred = 0;
642 int fmode = ap->a_fflag;
644 if ((vp->v_mount->mnt_kern_flag & MNTK_UNMOUNTF))
647 * During shutdown, a_cred isn't valid, so just use root.
649 if (ap->a_cred == NOCRED) {
650 cred = newnfs_getcred();
655 if (vp->v_type == VREG) {
657 * Examine and clean dirty pages, regardless of NMODIFIED.
658 * This closes a major hole in close-to-open consistency.
659 * We want to push out all dirty pages (and buffers) on
660 * close, regardless of whether they were dirtied by
661 * mmap'ed writes or via write().
663 if (nfs_clean_pages_on_close && vp->v_object) {
664 VM_OBJECT_LOCK(vp->v_object);
665 vm_object_page_clean(vp->v_object, 0, 0, 0);
666 VM_OBJECT_UNLOCK(vp->v_object);
668 mtx_lock(&np->n_mtx);
669 if (np->n_flag & NMODIFIED) {
670 mtx_unlock(&np->n_mtx);
673 * Under NFSv3 we have dirty buffers to dispose of. We
674 * must flush them to the NFS server. We have the option
675 * of waiting all the way through the commit rpc or just
676 * waiting for the initial write. The default is to only
677 * wait through the initial write so the data is in the
678 * server's cache, which is roughly similar to the state
679 * a standard disk subsystem leaves the file in on close().
681 * We cannot clear the NMODIFIED bit in np->n_flag due to
682 * potential races with other processes, and certainly
683 * cannot clear it if we don't commit.
684 * These races occur when there is no longer the old
685 * traditional vnode locking implemented for Vnode Ops.
687 int cm = newnfs_commit_on_close ? 1 : 0;
688 error = ncl_flush(vp, MNT_WAIT, cred, ap->a_td, cm);
689 /* np->n_flag &= ~NMODIFIED; */
690 } else if (NFS_ISV4(vp)) {
691 if (nfscl_mustflush(vp)) {
692 int cm = newnfs_commit_on_close ? 1 : 0;
693 error = ncl_flush(vp, MNT_WAIT, cred, ap->a_td,
696 * as above w.r.t races when clearing
698 * np->n_flag &= ~NMODIFIED;
702 error = ncl_vinvalbuf(vp, V_SAVE, ap->a_td, 1);
703 mtx_lock(&np->n_mtx);
706 * Invalidate the attribute cache in all cases.
707 * An open is going to fetch fresh attrs any way, other procs
708 * on this node that have file open will be forced to do an
709 * otw attr fetch, but this is safe.
710 * --> A user found that their RPC count dropped by 20% when
711 * this was commented out and I can't see any requirement
712 * for it, so I've disabled it when negative lookups are
713 * enabled. (What does this have to do with negative lookup
714 * caching? Well nothing, except it was reported by the
715 * same user that needed negative lookup caching and I wanted
716 * there to be a way to disable it via sysctl to see if it
717 * is the cause of some caching/coherency issue that might
720 if (newnfs_neglookup_enable == 0)
722 if (np->n_flag & NWRITEERR) {
723 np->n_flag &= ~NWRITEERR;
726 mtx_unlock(&np->n_mtx);
731 * Get attributes so "change" is up to date.
734 ret = nfsrpc_getattr(vp, cred, ap->a_td, &nfsva,
737 np->n_change = nfsva.na_filerev;
738 (void) nfscl_loadattrcache(&vp, &nfsva, NULL,
746 ret = nfsrpc_close(vp, 0, ap->a_td);
750 error = nfscl_maperr(ap->a_td, error, (uid_t)0,
753 if (newnfs_directio_enable)
754 KASSERT((np->n_directio_asyncwr == 0),
755 ("nfs_close: dirty unflushed (%d) directio buffers\n",
756 np->n_directio_asyncwr));
757 if (newnfs_directio_enable && (fmode & O_DIRECT) && (vp->v_type == VREG)) {
758 mtx_lock(&np->n_mtx);
759 KASSERT((np->n_directio_opens > 0),
760 ("nfs_close: unexpectedly value (0) of n_directio_opens\n"));
761 np->n_directio_opens--;
762 if (np->n_directio_opens == 0)
763 np->n_flag &= ~NNONCACHE;
764 mtx_unlock(&np->n_mtx);
772 * nfs getattr call from vfs.
775 nfs_getattr(struct vop_getattr_args *ap)
777 struct vnode *vp = ap->a_vp;
778 struct thread *td = curthread; /* XXX */
779 struct nfsnode *np = VTONFS(vp);
781 struct nfsvattr nfsva;
782 struct vattr *vap = ap->a_vap;
786 * Update local times for special files.
788 mtx_lock(&np->n_mtx);
789 if (np->n_flag & (NACC | NUPD))
791 mtx_unlock(&np->n_mtx);
793 * First look in the cache.
795 if (ncl_getattrcache(vp, &vattr) == 0) {
796 vap->va_type = vattr.va_type;
797 vap->va_mode = vattr.va_mode;
798 vap->va_nlink = vattr.va_nlink;
799 vap->va_uid = vattr.va_uid;
800 vap->va_gid = vattr.va_gid;
801 vap->va_fsid = vattr.va_fsid;
802 vap->va_fileid = vattr.va_fileid;
803 vap->va_size = vattr.va_size;
804 vap->va_blocksize = vattr.va_blocksize;
805 vap->va_atime = vattr.va_atime;
806 vap->va_mtime = vattr.va_mtime;
807 vap->va_ctime = vattr.va_ctime;
808 vap->va_gen = vattr.va_gen;
809 vap->va_flags = vattr.va_flags;
810 vap->va_rdev = vattr.va_rdev;
811 vap->va_bytes = vattr.va_bytes;
812 vap->va_filerev = vattr.va_filerev;
814 * Get the local modify time for the case of a write
817 nfscl_deleggetmodtime(vp, &vap->va_mtime);
821 if (NFS_ISV34(vp) && nfs_prime_access_cache &&
822 nfsaccess_cache_timeout > 0) {
823 NFSINCRGLOBAL(newnfsstats.accesscache_misses);
824 nfs34_access_otw(vp, NFSACCESS_ALL, td, ap->a_cred, NULL);
825 if (ncl_getattrcache(vp, ap->a_vap) == 0) {
826 nfscl_deleggetmodtime(vp, &ap->a_vap->va_mtime);
830 error = nfsrpc_getattr(vp, ap->a_cred, td, &nfsva, NULL);
832 error = nfscl_loadattrcache(&vp, &nfsva, vap, NULL, 0, 0);
835 * Get the local modify time for the case of a write
838 nfscl_deleggetmodtime(vp, &vap->va_mtime);
839 } else if (NFS_ISV4(vp)) {
840 error = nfscl_maperr(td, error, (uid_t)0, (gid_t)0);
849 nfs_setattr(struct vop_setattr_args *ap)
851 struct vnode *vp = ap->a_vp;
852 struct nfsnode *np = VTONFS(vp);
853 struct thread *td = curthread; /* XXX */
854 struct vattr *vap = ap->a_vap;
863 * Setting of flags and marking of atimes are not supported.
865 if (vap->va_flags != VNOVAL)
869 * Disallow write attempts if the filesystem is mounted read-only.
871 if ((vap->va_flags != VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
872 vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
873 vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL) &&
874 (vp->v_mount->mnt_flag & MNT_RDONLY))
876 if (vap->va_size != VNOVAL) {
877 switch (vp->v_type) {
884 if (vap->va_mtime.tv_sec == VNOVAL &&
885 vap->va_atime.tv_sec == VNOVAL &&
886 vap->va_mode == (mode_t)VNOVAL &&
887 vap->va_uid == (uid_t)VNOVAL &&
888 vap->va_gid == (gid_t)VNOVAL)
890 vap->va_size = VNOVAL;
894 * Disallow write attempts if the filesystem is
897 if (vp->v_mount->mnt_flag & MNT_RDONLY)
900 * We run vnode_pager_setsize() early (why?),
901 * we must set np->n_size now to avoid vinvalbuf
902 * V_SAVE races that might setsize a lower
905 mtx_lock(&np->n_mtx);
907 mtx_unlock(&np->n_mtx);
908 error = ncl_meta_setsize(vp, ap->a_cred, td,
910 mtx_lock(&np->n_mtx);
911 if (np->n_flag & NMODIFIED) {
913 mtx_unlock(&np->n_mtx);
914 if (vap->va_size == 0)
915 error = ncl_vinvalbuf(vp, 0, td, 1);
917 error = ncl_vinvalbuf(vp, V_SAVE, td, 1);
919 vnode_pager_setsize(vp, tsize);
923 * Call nfscl_delegmodtime() to set the modify time
924 * locally, as required.
926 nfscl_delegmodtime(vp);
928 mtx_unlock(&np->n_mtx);
930 * np->n_size has already been set to vap->va_size
931 * in ncl_meta_setsize(). We must set it again since
932 * nfs_loadattrcache() could be called through
933 * ncl_meta_setsize() and could modify np->n_size.
935 mtx_lock(&np->n_mtx);
936 np->n_vattr.na_size = np->n_size = vap->va_size;
937 mtx_unlock(&np->n_mtx);
940 mtx_lock(&np->n_mtx);
941 if ((vap->va_mtime.tv_sec != VNOVAL || vap->va_atime.tv_sec != VNOVAL) &&
942 (np->n_flag & NMODIFIED) && vp->v_type == VREG) {
943 mtx_unlock(&np->n_mtx);
944 if ((error = ncl_vinvalbuf(vp, V_SAVE, td, 1)) != 0 &&
945 (error == EINTR || error == EIO))
948 mtx_unlock(&np->n_mtx);
950 error = nfs_setattrrpc(vp, vap, ap->a_cred, td);
951 if (error && vap->va_size != VNOVAL) {
952 mtx_lock(&np->n_mtx);
953 np->n_size = np->n_vattr.na_size = tsize;
954 vnode_pager_setsize(vp, tsize);
955 mtx_unlock(&np->n_mtx);
961 * Do an nfs setattr rpc.
964 nfs_setattrrpc(struct vnode *vp, struct vattr *vap, struct ucred *cred,
967 struct nfsnode *np = VTONFS(vp);
968 int error, ret, attrflag, i;
969 struct nfsvattr nfsva;
972 mtx_lock(&np->n_mtx);
973 for (i = 0; i < NFS_ACCESSCACHESIZE; i++)
974 np->n_accesscache[i].stamp = 0;
975 np->n_flag |= NDELEGMOD;
976 mtx_unlock(&np->n_mtx);
978 error = nfsrpc_setattr(vp, vap, NULL, cred, td, &nfsva, &attrflag,
981 ret = nfscl_loadattrcache(&vp, &nfsva, NULL, NULL, 0, 1);
985 if (error && NFS_ISV4(vp))
986 error = nfscl_maperr(td, error, vap->va_uid, vap->va_gid);
991 * nfs lookup call, one step at a time...
992 * First look in cache
993 * If not found, unlock the directory nfsnode and do the rpc
996 nfs_lookup(struct vop_lookup_args *ap)
998 struct componentname *cnp = ap->a_cnp;
999 struct vnode *dvp = ap->a_dvp;
1000 struct vnode **vpp = ap->a_vpp;
1001 struct mount *mp = dvp->v_mount;
1002 int flags = cnp->cn_flags;
1003 struct vnode *newvp;
1004 struct nfsmount *nmp;
1006 int error = 0, attrflag, dattrflag, ltype;
1007 struct thread *td = cnp->cn_thread;
1009 struct nfsvattr dnfsva, nfsva;
1012 if ((flags & ISLASTCN) && (mp->mnt_flag & MNT_RDONLY) &&
1013 (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
1015 if (dvp->v_type != VDIR)
1020 /* For NFSv4, wait until any remove is done. */
1021 mtx_lock(&np->n_mtx);
1022 while (NFSHASNFSV4(nmp) && (np->n_flag & NREMOVEINPROG)) {
1023 np->n_flag |= NREMOVEWANT;
1024 (void) msleep((caddr_t)np, &np->n_mtx, PZERO, "nfslkup", 0);
1026 mtx_unlock(&np->n_mtx);
1028 if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td)) != 0)
1030 if ((error = cache_lookup(dvp, vpp, cnp)) &&
1031 (error != ENOENT || newnfs_neglookup_enable != 0)) {
1034 if (error == ENOENT) {
1035 if (!VOP_GETATTR(dvp, &vattr, cnp->cn_cred) &&
1036 vattr.va_mtime.tv_sec == np->n_dmtime) {
1037 NFSINCRGLOBAL(newnfsstats.lookupcache_hits);
1040 cache_purge_negative(dvp);
1044 if (nfscl_nodeleg(newvp, 0) == 0 ||
1045 (!VOP_GETATTR(newvp, &vattr, cnp->cn_cred) &&
1046 vattr.va_ctime.tv_sec==VTONFS(newvp)->n_ctime)) {
1047 NFSINCRGLOBAL(newnfsstats.lookupcache_hits);
1048 if (cnp->cn_nameiop != LOOKUP &&
1050 cnp->cn_flags |= SAVENAME;
1063 NFSINCRGLOBAL(newnfsstats.lookupcache_misses);
1064 error = nfsrpc_lookup(dvp, cnp->cn_nameptr, cnp->cn_namelen,
1065 cnp->cn_cred, td, &dnfsva, &nfsva, &nfhp, &attrflag, &dattrflag,
1068 (void) nfscl_loadattrcache(&dvp, &dnfsva, NULL, NULL, 0, 1);
1070 if (newnfs_neglookup_enable != 0 &&
1071 error == ENOENT && (cnp->cn_flags & MAKEENTRY) &&
1072 cnp->cn_nameiop != CREATE) {
1073 if (np->n_dmtime == 0)
1074 np->n_dmtime = np->n_vattr.na_mtime.tv_sec;
1075 cache_enter(dvp, NULL, cnp);
1077 if (newvp != NULLVP) {
1081 if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) &&
1082 (flags & ISLASTCN) && error == ENOENT) {
1083 if (mp->mnt_flag & MNT_RDONLY)
1086 error = EJUSTRETURN;
1088 if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
1089 cnp->cn_flags |= SAVENAME;
1091 error = nfscl_maperr(td, error, (uid_t)0, (gid_t)0);
1096 * Handle RENAME case...
1098 if (cnp->cn_nameiop == RENAME && (flags & ISLASTCN)) {
1099 if (NFS_CMPFH(np, nfhp->nfh_fh, nfhp->nfh_len)) {
1100 FREE((caddr_t)nfhp, M_NFSFH);
1103 error = nfscl_nget(mp, dvp, nfhp, cnp, td, &np, NULL);
1108 (void) nfscl_loadattrcache(&newvp, &nfsva, NULL, NULL,
1111 cnp->cn_flags |= SAVENAME;
1115 if (flags & ISDOTDOT) {
1116 ltype = VOP_ISLOCKED(dvp);
1117 error = vfs_busy(mp, MBF_NOWAIT);
1121 error = vfs_busy(mp, 0);
1122 vn_lock(dvp, ltype | LK_RETRY);
1124 if (error == 0 && (dvp->v_iflag & VI_DOOMED)) {
1132 error = nfscl_nget(mp, dvp, nfhp, cnp, td, &np, NULL);
1137 vn_lock(dvp, ltype | LK_RETRY);
1138 if (dvp->v_iflag & VI_DOOMED) {
1150 (void) nfscl_loadattrcache(&newvp, &nfsva, NULL, NULL,
1152 } else if (NFS_CMPFH(np, nfhp->nfh_fh, nfhp->nfh_len)) {
1153 FREE((caddr_t)nfhp, M_NFSFH);
1157 (void) nfscl_loadattrcache(&newvp, &nfsva, NULL, NULL,
1160 error = nfscl_nget(mp, dvp, nfhp, cnp, td, &np, NULL);
1165 (void) nfscl_loadattrcache(&newvp, &nfsva, NULL, NULL,
1168 if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
1169 cnp->cn_flags |= SAVENAME;
1170 if ((cnp->cn_flags & MAKEENTRY) &&
1171 (cnp->cn_nameiop != DELETE || !(flags & ISLASTCN))) {
1172 np->n_ctime = np->n_vattr.na_vattr.va_ctime.tv_sec;
1173 cache_enter(dvp, newvp, cnp);
1181 * Just call ncl_bioread() to do the work.
1184 nfs_read(struct vop_read_args *ap)
1186 struct vnode *vp = ap->a_vp;
1188 switch (vp->v_type) {
1190 return (ncl_bioread(vp, ap->a_uio, ap->a_ioflag, ap->a_cred));
1194 return (EOPNOTSUPP);
1202 nfs_readlink(struct vop_readlink_args *ap)
1204 struct vnode *vp = ap->a_vp;
1206 if (vp->v_type != VLNK)
1208 return (ncl_bioread(vp, ap->a_uio, 0, ap->a_cred));
1212 * Do a readlink rpc.
1213 * Called by ncl_doio() from below the buffer cache.
1216 ncl_readlinkrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred)
1218 int error, ret, attrflag;
1219 struct nfsvattr nfsva;
1221 error = nfsrpc_readlink(vp, uiop, cred, uiop->uio_td, &nfsva,
1224 ret = nfscl_loadattrcache(&vp, &nfsva, NULL, NULL, 0, 1);
1228 if (error && NFS_ISV4(vp))
1229 error = nfscl_maperr(uiop->uio_td, error, (uid_t)0, (gid_t)0);
1238 ncl_readrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred)
1240 int error, ret, attrflag;
1241 struct nfsvattr nfsva;
1243 error = nfsrpc_read(vp, uiop, cred, uiop->uio_td, &nfsva, &attrflag,
1246 ret = nfscl_loadattrcache(&vp, &nfsva, NULL, NULL, 0, 1);
1250 if (error && NFS_ISV4(vp))
1251 error = nfscl_maperr(uiop->uio_td, error, (uid_t)0, (gid_t)0);
1259 ncl_writerpc(struct vnode *vp, struct uio *uiop, struct ucred *cred,
1260 int *iomode, int *must_commit)
1262 struct nfsvattr nfsva;
1263 int error = 0, attrflag, ret;
1264 u_char verf[NFSX_VERF];
1265 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
1268 error = nfsrpc_write(vp, uiop, iomode, verf, cred,
1269 uiop->uio_td, &nfsva, &attrflag, NULL);
1271 if (!error && NFSHASWRITEVERF(nmp) &&
1272 NFSBCMP(verf, nmp->nm_verf, NFSX_VERF)) {
1274 NFSBCOPY(verf, nmp->nm_verf, NFSX_VERF);
1278 if (VTONFS(vp)->n_flag & ND_NFSV4)
1279 ret = nfscl_loadattrcache(&vp, &nfsva, NULL, NULL, 1,
1282 ret = nfscl_loadattrcache(&vp, &nfsva, NULL, NULL, 0,
1287 if (vp->v_mount->mnt_kern_flag & MNTK_ASYNC)
1288 *iomode = NFSWRITE_FILESYNC;
1289 if (error && NFS_ISV4(vp))
1290 error = nfscl_maperr(uiop->uio_td, error, (uid_t)0, (gid_t)0);
1296 * For NFS v2 this is a kludge. Use a create rpc but with the IFMT bits of the
1297 * mode set to specify the file type and the size field for rdev.
1300 nfs_mknodrpc(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp,
1303 struct nfsvattr nfsva, dnfsva;
1304 struct vnode *newvp = NULL;
1305 struct nfsnode *np = NULL, *dnp;
1308 int error = 0, attrflag, dattrflag;
1311 if (vap->va_type == VCHR || vap->va_type == VBLK)
1312 rdev = vap->va_rdev;
1313 else if (vap->va_type == VFIFO || vap->va_type == VSOCK)
1316 return (EOPNOTSUPP);
1317 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred)))
1319 error = nfsrpc_mknod(dvp, cnp->cn_nameptr, cnp->cn_namelen, vap,
1320 rdev, vap->va_type, cnp->cn_cred, cnp->cn_thread, &dnfsva,
1321 &nfsva, &nfhp, &attrflag, &dattrflag, NULL);
1324 (void) nfsrpc_lookup(dvp, cnp->cn_nameptr,
1325 cnp->cn_namelen, cnp->cn_cred, cnp->cn_thread,
1326 &dnfsva, &nfsva, &nfhp, &attrflag, &dattrflag,
1329 error = nfscl_nget(dvp->v_mount, dvp, nfhp, cnp,
1330 cnp->cn_thread, &np, NULL);
1333 (void) nfscl_loadattrcache(&dvp, &dnfsva, NULL, NULL, 0, 1);
1337 error = nfscl_loadattrcache(&newvp, &nfsva, NULL, NULL,
1341 if ((cnp->cn_flags & MAKEENTRY))
1342 cache_enter(dvp, newvp, cnp);
1344 } else if (NFS_ISV4(dvp)) {
1345 error = nfscl_maperr(cnp->cn_thread, error, vap->va_uid,
1349 mtx_lock(&dnp->n_mtx);
1350 dnp->n_flag |= NMODIFIED;
1352 dnp->n_attrstamp = 0;
1353 mtx_unlock(&dnp->n_mtx);
1359 * just call nfs_mknodrpc() to do the work.
1363 nfs_mknod(struct vop_mknod_args *ap)
1365 return (nfs_mknodrpc(ap->a_dvp, ap->a_vpp, ap->a_cnp, ap->a_vap));
1368 static u_long create_verf;
1370 * nfs file create call
1373 nfs_create(struct vop_create_args *ap)
1375 struct vnode *dvp = ap->a_dvp;
1376 struct vattr *vap = ap->a_vap;
1377 struct componentname *cnp = ap->a_cnp;
1378 struct nfsnode *np = NULL, *dnp;
1379 struct vnode *newvp = NULL;
1380 struct nfsmount *nmp;
1381 struct nfsvattr dnfsva, nfsva;
1384 int error = 0, attrflag, dattrflag, fmode = 0;
1388 * Oops, not for me..
1390 if (vap->va_type == VSOCK)
1391 return (nfs_mknodrpc(dvp, ap->a_vpp, cnp, vap));
1393 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred)))
1395 if (vap->va_vaflags & VA_EXCLUSIVE)
1398 nmp = VFSTONFS(vnode_mount(dvp));
1400 /* For NFSv4, wait until any remove is done. */
1401 mtx_lock(&dnp->n_mtx);
1402 while (NFSHASNFSV4(nmp) && (dnp->n_flag & NREMOVEINPROG)) {
1403 dnp->n_flag |= NREMOVEWANT;
1404 (void) msleep((caddr_t)dnp, &dnp->n_mtx, PZERO, "nfscrt", 0);
1406 mtx_unlock(&dnp->n_mtx);
1408 CURVNET_SET(P_TO_VNET(&proc0));
1411 if (!TAILQ_EMPTY(&V_in_ifaddrhead))
1412 cverf.lval[0] = IA_SIN(TAILQ_FIRST(&V_in_ifaddrhead))->sin_addr.s_addr;
1415 cverf.lval[0] = create_verf;
1417 IN_IFADDR_RUNLOCK();
1419 cverf.lval[1] = ++create_verf;
1421 error = nfsrpc_create(dvp, cnp->cn_nameptr, cnp->cn_namelen,
1422 vap, cverf, fmode, cnp->cn_cred, cnp->cn_thread, &dnfsva, &nfsva,
1423 &nfhp, &attrflag, &dattrflag, NULL);
1426 (void) nfsrpc_lookup(dvp, cnp->cn_nameptr,
1427 cnp->cn_namelen, cnp->cn_cred, cnp->cn_thread,
1428 &dnfsva, &nfsva, &nfhp, &attrflag, &dattrflag,
1431 error = nfscl_nget(dvp->v_mount, dvp, nfhp, cnp,
1432 cnp->cn_thread, &np, NULL);
1435 (void) nfscl_loadattrcache(&dvp, &dnfsva, NULL, NULL, 0, 1);
1439 error = nfscl_loadattrcache(&newvp, &nfsva, NULL, NULL,
1443 if (newvp != NULL) {
1447 if (NFS_ISV34(dvp) && (fmode & O_EXCL) &&
1448 error == NFSERR_NOTSUPP) {
1452 } else if (NFS_ISV34(dvp) && (fmode & O_EXCL)) {
1453 if (nfscl_checksattr(vap, &nfsva)) {
1454 error = nfsrpc_setattr(newvp, vap, NULL, cnp->cn_cred,
1455 cnp->cn_thread, &nfsva, &attrflag, NULL);
1456 if (error && (vap->va_uid != (uid_t)VNOVAL ||
1457 vap->va_gid != (gid_t)VNOVAL)) {
1458 /* try again without setting uid/gid */
1459 vap->va_uid = (uid_t)VNOVAL;
1460 vap->va_gid = (uid_t)VNOVAL;
1461 error = nfsrpc_setattr(newvp, vap, NULL,
1462 cnp->cn_cred, cnp->cn_thread, &nfsva,
1466 (void) nfscl_loadattrcache(&newvp, &nfsva, NULL,
1471 if (cnp->cn_flags & MAKEENTRY)
1472 cache_enter(dvp, newvp, cnp);
1474 } else if (NFS_ISV4(dvp)) {
1475 error = nfscl_maperr(cnp->cn_thread, error, vap->va_uid,
1478 mtx_lock(&dnp->n_mtx);
1479 dnp->n_flag |= NMODIFIED;
1481 dnp->n_attrstamp = 0;
1482 mtx_unlock(&dnp->n_mtx);
1487 * nfs file remove call
1488 * To try and make nfs semantics closer to ufs semantics, a file that has
1489 * other processes using the vnode is renamed instead of removed and then
1490 * removed later on the last close.
1491 * - If v_usecount > 1
1492 * If a rename is not already in the works
1493 * call nfs_sillyrename() to set it up
1498 nfs_remove(struct vop_remove_args *ap)
1500 struct vnode *vp = ap->a_vp;
1501 struct vnode *dvp = ap->a_dvp;
1502 struct componentname *cnp = ap->a_cnp;
1503 struct nfsnode *np = VTONFS(vp);
1508 if ((cnp->cn_flags & HASBUF) == 0)
1509 panic("nfs_remove: no name");
1510 if (vrefcnt(vp) < 1)
1511 panic("nfs_remove: bad v_usecount");
1513 if (vp->v_type == VDIR)
1515 else if (vrefcnt(vp) == 1 || (np->n_sillyrename &&
1516 VOP_GETATTR(vp, &vattr, cnp->cn_cred) == 0 &&
1517 vattr.va_nlink > 1)) {
1519 * Purge the name cache so that the chance of a lookup for
1520 * the name succeeding while the remove is in progress is
1521 * minimized. Without node locking it can still happen, such
1522 * that an I/O op returns ESTALE, but since you get this if
1523 * another host removes the file..
1527 * throw away biocache buffers, mainly to avoid
1528 * unnecessary delayed writes later.
1530 error = ncl_vinvalbuf(vp, 0, cnp->cn_thread, 1);
1532 if (error != EINTR && error != EIO)
1533 error = nfs_removerpc(dvp, vp, cnp->cn_nameptr,
1534 cnp->cn_namelen, cnp->cn_cred, cnp->cn_thread);
1536 * Kludge City: If the first reply to the remove rpc is lost..
1537 * the reply to the retransmitted request will be ENOENT
1538 * since the file was in fact removed
1539 * Therefore, we cheat and return success.
1541 if (error == ENOENT)
1543 } else if (!np->n_sillyrename)
1544 error = nfs_sillyrename(dvp, vp, cnp);
1545 np->n_attrstamp = 0;
1550 * nfs file remove rpc called from nfs_inactive
1553 ncl_removeit(struct sillyrename *sp, struct vnode *vp)
1556 * Make sure that the directory vnode is still valid.
1557 * XXX we should lock sp->s_dvp here.
1559 if (sp->s_dvp->v_type == VBAD)
1561 return (nfs_removerpc(sp->s_dvp, vp, sp->s_name, sp->s_namlen,
1566 * Nfs remove rpc, called from nfs_remove() and ncl_removeit().
1569 nfs_removerpc(struct vnode *dvp, struct vnode *vp, char *name,
1570 int namelen, struct ucred *cred, struct thread *td)
1572 struct nfsvattr dnfsva;
1573 struct nfsnode *dnp = VTONFS(dvp);
1574 int error = 0, dattrflag;
1576 mtx_lock(&dnp->n_mtx);
1577 dnp->n_flag |= NREMOVEINPROG;
1578 mtx_unlock(&dnp->n_mtx);
1579 error = nfsrpc_remove(dvp, name, namelen, vp, cred, td, &dnfsva,
1581 mtx_lock(&dnp->n_mtx);
1582 if ((dnp->n_flag & NREMOVEWANT)) {
1583 dnp->n_flag &= ~(NREMOVEWANT | NREMOVEINPROG);
1584 mtx_unlock(&dnp->n_mtx);
1585 wakeup((caddr_t)dnp);
1587 dnp->n_flag &= ~NREMOVEINPROG;
1588 mtx_unlock(&dnp->n_mtx);
1591 (void) nfscl_loadattrcache(&dvp, &dnfsva, NULL, NULL, 0, 1);
1592 mtx_lock(&dnp->n_mtx);
1593 dnp->n_flag |= NMODIFIED;
1595 dnp->n_attrstamp = 0;
1596 mtx_unlock(&dnp->n_mtx);
1597 if (error && NFS_ISV4(dvp))
1598 error = nfscl_maperr(td, error, (uid_t)0, (gid_t)0);
1603 * nfs file rename call
1606 nfs_rename(struct vop_rename_args *ap)
1608 struct vnode *fvp = ap->a_fvp;
1609 struct vnode *tvp = ap->a_tvp;
1610 struct vnode *fdvp = ap->a_fdvp;
1611 struct vnode *tdvp = ap->a_tdvp;
1612 struct componentname *tcnp = ap->a_tcnp;
1613 struct componentname *fcnp = ap->a_fcnp;
1614 struct nfsnode *fnp = VTONFS(ap->a_fvp);
1615 struct nfsnode *tdnp = VTONFS(ap->a_tdvp);
1616 struct nfsv4node *newv4 = NULL;
1620 if ((tcnp->cn_flags & HASBUF) == 0 ||
1621 (fcnp->cn_flags & HASBUF) == 0)
1622 panic("nfs_rename: no name");
1624 /* Check for cross-device rename */
1625 if ((fvp->v_mount != tdvp->v_mount) ||
1626 (tvp && (fvp->v_mount != tvp->v_mount))) {
1632 ncl_printf("nfs_rename: fvp == tvp (can't happen)\n");
1636 if ((error = vn_lock(fvp, LK_EXCLUSIVE)))
1640 * We have to flush B_DELWRI data prior to renaming
1641 * the file. If we don't, the delayed-write buffers
1642 * can be flushed out later after the file has gone stale
1643 * under NFSV3. NFSV2 does not have this problem because
1644 * ( as far as I can tell ) it flushes dirty buffers more
1647 * Skip the rename operation if the fsync fails, this can happen
1648 * due to the server's volume being full, when we pushed out data
1649 * that was written back to our cache earlier. Not checking for
1650 * this condition can result in potential (silent) data loss.
1652 error = VOP_FSYNC(fvp, MNT_WAIT, fcnp->cn_thread);
1655 error = VOP_FSYNC(tvp, MNT_WAIT, tcnp->cn_thread);
1660 * If the tvp exists and is in use, sillyrename it before doing the
1661 * rename of the new file over it.
1662 * XXX Can't sillyrename a directory.
1664 if (tvp && vrefcnt(tvp) > 1 && !VTONFS(tvp)->n_sillyrename &&
1665 tvp->v_type != VDIR && !nfs_sillyrename(tdvp, tvp, tcnp)) {
1670 error = nfs_renamerpc(fdvp, fvp, fcnp->cn_nameptr, fcnp->cn_namelen,
1671 tdvp, tvp, tcnp->cn_nameptr, tcnp->cn_namelen, tcnp->cn_cred,
1676 * For NFSv4, check to see if it is the same name and
1677 * replace the name, if it is different.
1679 MALLOC(newv4, struct nfsv4node *,
1680 sizeof (struct nfsv4node) +
1681 tdnp->n_fhp->nfh_len + tcnp->cn_namelen - 1,
1682 M_NFSV4NODE, M_WAITOK);
1683 mtx_lock(&tdnp->n_mtx);
1684 mtx_lock(&fnp->n_mtx);
1685 if (fnp->n_v4 != NULL && fvp->v_type == VREG &&
1686 (fnp->n_v4->n4_namelen != tcnp->cn_namelen ||
1687 NFSBCMP(tcnp->cn_nameptr, NFS4NODENAME(fnp->n_v4),
1688 tcnp->cn_namelen) ||
1689 tdnp->n_fhp->nfh_len != fnp->n_v4->n4_fhlen ||
1690 NFSBCMP(tdnp->n_fhp->nfh_fh, fnp->n_v4->n4_data,
1691 tdnp->n_fhp->nfh_len))) {
1693 { char nnn[100]; int nnnl;
1694 nnnl = (tcnp->cn_namelen < 100) ? tcnp->cn_namelen : 99;
1695 bcopy(tcnp->cn_nameptr, nnn, nnnl);
1697 printf("ren replace=%s\n",nnn);
1700 FREE((caddr_t)fnp->n_v4, M_NFSV4NODE);
1703 fnp->n_v4->n4_fhlen = tdnp->n_fhp->nfh_len;
1704 fnp->n_v4->n4_namelen = tcnp->cn_namelen;
1705 NFSBCOPY(tdnp->n_fhp->nfh_fh, fnp->n_v4->n4_data,
1706 tdnp->n_fhp->nfh_len);
1707 NFSBCOPY(tcnp->cn_nameptr,
1708 NFS4NODENAME(fnp->n_v4), tcnp->cn_namelen);
1710 mtx_unlock(&tdnp->n_mtx);
1711 mtx_unlock(&fnp->n_mtx);
1713 FREE((caddr_t)newv4, M_NFSV4NODE);
1716 if (fvp->v_type == VDIR) {
1717 if (tvp != NULL && tvp->v_type == VDIR)
1732 * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry.
1734 if (error == ENOENT)
1740 * nfs file rename rpc called from nfs_remove() above
1743 nfs_renameit(struct vnode *sdvp, struct vnode *svp, struct componentname *scnp,
1744 struct sillyrename *sp)
1747 return (nfs_renamerpc(sdvp, svp, scnp->cn_nameptr, scnp->cn_namelen,
1748 sdvp, NULL, sp->s_name, sp->s_namlen, scnp->cn_cred,
1753 * Do an nfs rename rpc. Called from nfs_rename() and nfs_renameit().
1756 nfs_renamerpc(struct vnode *fdvp, struct vnode *fvp, char *fnameptr,
1757 int fnamelen, struct vnode *tdvp, struct vnode *tvp, char *tnameptr,
1758 int tnamelen, struct ucred *cred, struct thread *td)
1760 struct nfsvattr fnfsva, tnfsva;
1761 struct nfsnode *fdnp = VTONFS(fdvp);
1762 struct nfsnode *tdnp = VTONFS(tdvp);
1763 int error = 0, fattrflag, tattrflag;
1765 error = nfsrpc_rename(fdvp, fvp, fnameptr, fnamelen, tdvp, tvp,
1766 tnameptr, tnamelen, cred, td, &fnfsva, &tnfsva, &fattrflag,
1767 &tattrflag, NULL, NULL);
1768 mtx_lock(&fdnp->n_mtx);
1769 fdnp->n_flag |= NMODIFIED;
1770 mtx_unlock(&fdnp->n_mtx);
1771 mtx_lock(&tdnp->n_mtx);
1772 tdnp->n_flag |= NMODIFIED;
1773 mtx_unlock(&tdnp->n_mtx);
1775 (void) nfscl_loadattrcache(&fdvp, &fnfsva, NULL, NULL, 0, 1);
1777 fdnp->n_attrstamp = 0;
1779 (void) nfscl_loadattrcache(&tdvp, &tnfsva, NULL, NULL, 0, 1);
1781 tdnp->n_attrstamp = 0;
1782 if (error && NFS_ISV4(fdvp))
1783 error = nfscl_maperr(td, error, (uid_t)0, (gid_t)0);
1788 * nfs hard link create call
1791 nfs_link(struct vop_link_args *ap)
1793 struct vnode *vp = ap->a_vp;
1794 struct vnode *tdvp = ap->a_tdvp;
1795 struct componentname *cnp = ap->a_cnp;
1796 struct nfsnode *tdnp;
1797 struct nfsvattr nfsva, dnfsva;
1798 int error = 0, attrflag, dattrflag;
1800 if (vp->v_mount != tdvp->v_mount) {
1805 * Push all writes to the server, so that the attribute cache
1806 * doesn't get "out of sync" with the server.
1807 * XXX There should be a better way!
1809 VOP_FSYNC(vp, MNT_WAIT, cnp->cn_thread);
1811 error = nfsrpc_link(tdvp, vp, cnp->cn_nameptr, cnp->cn_namelen,
1812 cnp->cn_cred, cnp->cn_thread, &dnfsva, &nfsva, &attrflag,
1814 tdnp = VTONFS(tdvp);
1815 mtx_lock(&tdnp->n_mtx);
1816 tdnp->n_flag |= NMODIFIED;
1817 mtx_unlock(&tdnp->n_mtx);
1819 (void) nfscl_loadattrcache(&vp, &nfsva, NULL, NULL, 0, 1);
1821 VTONFS(vp)->n_attrstamp = 0;
1823 (void) nfscl_loadattrcache(&tdvp, &dnfsva, NULL, NULL, 0, 1);
1825 tdnp->n_attrstamp = 0;
1827 * If negative lookup caching is enabled, I might as well
1828 * add an entry for this node. Not necessary for correctness,
1829 * but if negative caching is enabled, then the system
1830 * must care about lookup caching hit rate, so...
1832 if (newnfs_neglookup_enable != 0 &&
1833 (cnp->cn_flags & MAKEENTRY))
1834 cache_enter(tdvp, vp, cnp);
1835 if (error && NFS_ISV4(vp))
1836 error = nfscl_maperr(cnp->cn_thread, error, (uid_t)0,
1842 * nfs symbolic link create call
1845 nfs_symlink(struct vop_symlink_args *ap)
1847 struct vnode *dvp = ap->a_dvp;
1848 struct vattr *vap = ap->a_vap;
1849 struct componentname *cnp = ap->a_cnp;
1850 struct nfsvattr nfsva, dnfsva;
1852 struct nfsnode *np = NULL, *dnp;
1853 struct vnode *newvp = NULL;
1854 int error = 0, attrflag, dattrflag, ret;
1856 vap->va_type = VLNK;
1857 error = nfsrpc_symlink(dvp, cnp->cn_nameptr, cnp->cn_namelen,
1858 ap->a_target, vap, cnp->cn_cred, cnp->cn_thread, &dnfsva,
1859 &nfsva, &nfhp, &attrflag, &dattrflag, NULL);
1861 ret = nfscl_nget(dvp->v_mount, dvp, nfhp, cnp, cnp->cn_thread,
1868 if (newvp != NULL) {
1870 (void) nfscl_loadattrcache(&newvp, &nfsva, NULL, NULL,
1872 } else if (!error) {
1874 * If we do not have an error and we could not extract the
1875 * newvp from the response due to the request being NFSv2, we
1876 * have to do a lookup in order to obtain a newvp to return.
1878 error = nfs_lookitup(dvp, cnp->cn_nameptr, cnp->cn_namelen,
1879 cnp->cn_cred, cnp->cn_thread, &np);
1887 error = nfscl_maperr(cnp->cn_thread, error,
1888 vap->va_uid, vap->va_gid);
1891 * If negative lookup caching is enabled, I might as well
1892 * add an entry for this node. Not necessary for correctness,
1893 * but if negative caching is enabled, then the system
1894 * must care about lookup caching hit rate, so...
1896 if (newnfs_neglookup_enable != 0 &&
1897 (cnp->cn_flags & MAKEENTRY))
1898 cache_enter(dvp, newvp, cnp);
1903 mtx_lock(&dnp->n_mtx);
1904 dnp->n_flag |= NMODIFIED;
1905 mtx_unlock(&dnp->n_mtx);
1907 (void) nfscl_loadattrcache(&dvp, &dnfsva, NULL, NULL, 0, 1);
1909 dnp->n_attrstamp = 0;
1917 nfs_mkdir(struct vop_mkdir_args *ap)
1919 struct vnode *dvp = ap->a_dvp;
1920 struct vattr *vap = ap->a_vap;
1921 struct componentname *cnp = ap->a_cnp;
1922 struct nfsnode *np = NULL, *dnp;
1923 struct vnode *newvp = NULL;
1926 struct nfsvattr nfsva, dnfsva;
1927 int error = 0, attrflag, dattrflag, ret;
1929 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred)))
1931 vap->va_type = VDIR;
1932 error = nfsrpc_mkdir(dvp, cnp->cn_nameptr, cnp->cn_namelen,
1933 vap, cnp->cn_cred, cnp->cn_thread, &dnfsva, &nfsva, &nfhp,
1934 &attrflag, &dattrflag, NULL);
1936 mtx_lock(&dnp->n_mtx);
1937 dnp->n_flag |= NMODIFIED;
1938 mtx_unlock(&dnp->n_mtx);
1940 (void) nfscl_loadattrcache(&dvp, &dnfsva, NULL, NULL, 0, 1);
1942 dnp->n_attrstamp = 0;
1944 ret = nfscl_nget(dvp->v_mount, dvp, nfhp, cnp, cnp->cn_thread,
1949 (void) nfscl_loadattrcache(&newvp, &nfsva, NULL,
1954 if (!error && newvp == NULL) {
1955 error = nfs_lookitup(dvp, cnp->cn_nameptr, cnp->cn_namelen,
1956 cnp->cn_cred, cnp->cn_thread, &np);
1959 if (newvp->v_type != VDIR)
1967 error = nfscl_maperr(cnp->cn_thread, error,
1968 vap->va_uid, vap->va_gid);
1971 * If negative lookup caching is enabled, I might as well
1972 * add an entry for this node. Not necessary for correctness,
1973 * but if negative caching is enabled, then the system
1974 * must care about lookup caching hit rate, so...
1976 if (newnfs_neglookup_enable != 0 &&
1977 (cnp->cn_flags & MAKEENTRY))
1978 cache_enter(dvp, newvp, cnp);
1985 * nfs remove directory call
1988 nfs_rmdir(struct vop_rmdir_args *ap)
1990 struct vnode *vp = ap->a_vp;
1991 struct vnode *dvp = ap->a_dvp;
1992 struct componentname *cnp = ap->a_cnp;
1993 struct nfsnode *dnp;
1994 struct nfsvattr dnfsva;
1995 int error, dattrflag;
1999 error = nfsrpc_rmdir(dvp, cnp->cn_nameptr, cnp->cn_namelen,
2000 cnp->cn_cred, cnp->cn_thread, &dnfsva, &dattrflag, NULL);
2002 mtx_lock(&dnp->n_mtx);
2003 dnp->n_flag |= NMODIFIED;
2004 mtx_unlock(&dnp->n_mtx);
2006 (void) nfscl_loadattrcache(&dvp, &dnfsva, NULL, NULL, 0, 1);
2008 dnp->n_attrstamp = 0;
2012 if (error && NFS_ISV4(dvp))
2013 error = nfscl_maperr(cnp->cn_thread, error, (uid_t)0,
2016 * Kludge: Map ENOENT => 0 assuming that you have a reply to a retry.
2018 if (error == ENOENT)
2027 nfs_readdir(struct vop_readdir_args *ap)
2029 struct vnode *vp = ap->a_vp;
2030 struct nfsnode *np = VTONFS(vp);
2031 struct uio *uio = ap->a_uio;
2032 int tresid, error = 0;
2035 if (vp->v_type != VDIR)
2039 * First, check for hit on the EOF offset cache
2041 if (np->n_direofoffset > 0 && uio->uio_offset >= np->n_direofoffset &&
2042 (np->n_flag & NMODIFIED) == 0) {
2043 if (VOP_GETATTR(vp, &vattr, ap->a_cred) == 0) {
2044 mtx_lock(&np->n_mtx);
2045 if ((NFS_ISV4(vp) && np->n_change == vattr.va_filerev) ||
2046 !NFS_TIMESPEC_COMPARE(&np->n_mtime, &vattr.va_mtime)) {
2047 mtx_unlock(&np->n_mtx);
2048 NFSINCRGLOBAL(newnfsstats.direofcache_hits);
2051 mtx_unlock(&np->n_mtx);
2056 * Call ncl_bioread() to do the real work.
2058 tresid = uio->uio_resid;
2059 error = ncl_bioread(vp, uio, 0, ap->a_cred);
2061 if (!error && uio->uio_resid == tresid)
2062 NFSINCRGLOBAL(newnfsstats.direofcache_misses);
2068 * Called from below the buffer cache by ncl_doio().
2071 ncl_readdirrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred,
2074 struct nfsvattr nfsva;
2075 nfsuint64 *cookiep, cookie;
2076 struct nfsnode *dnp = VTONFS(vp);
2077 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2078 int error = 0, eof, attrflag;
2081 if (uiop->uio_iovcnt != 1 || (uiop->uio_offset & (DIRBLKSIZ - 1)) ||
2082 (uiop->uio_resid & (DIRBLKSIZ - 1)))
2083 panic("nfs readdirrpc bad uio");
2087 * If there is no cookie, assume directory was stale.
2089 ncl_dircookie_lock(dnp);
2090 cookiep = ncl_getcookie(dnp, uiop->uio_offset, 0);
2093 ncl_dircookie_unlock(dnp);
2095 ncl_dircookie_unlock(dnp);
2096 return (NFSERR_BAD_COOKIE);
2099 if (NFSHASNFSV3(nmp) && !NFSHASGOTFSINFO(nmp))
2100 (void)ncl_fsinfo(nmp, vp, cred, td);
2102 error = nfsrpc_readdir(vp, uiop, &cookie, cred, td, &nfsva,
2103 &attrflag, &eof, NULL);
2105 (void) nfscl_loadattrcache(&vp, &nfsva, NULL, NULL, 0, 1);
2109 * We are now either at the end of the directory or have filled
2113 dnp->n_direofoffset = uiop->uio_offset;
2115 if (uiop->uio_resid > 0)
2116 ncl_printf("EEK! readdirrpc resid > 0\n");
2117 ncl_dircookie_lock(dnp);
2118 cookiep = ncl_getcookie(dnp, uiop->uio_offset, 1);
2120 ncl_dircookie_unlock(dnp);
2122 } else if (NFS_ISV4(vp)) {
2123 error = nfscl_maperr(td, error, (uid_t)0, (gid_t)0);
2129 * NFS V3 readdir plus RPC. Used in place of ncl_readdirrpc().
2132 ncl_readdirplusrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred,
2135 struct nfsvattr nfsva;
2136 nfsuint64 *cookiep, cookie;
2137 struct nfsnode *dnp = VTONFS(vp);
2138 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2139 int error = 0, attrflag, eof;
2142 if (uiop->uio_iovcnt != 1 || (uiop->uio_offset & (DIRBLKSIZ - 1)) ||
2143 (uiop->uio_resid & (DIRBLKSIZ - 1)))
2144 panic("nfs readdirplusrpc bad uio");
2148 * If there is no cookie, assume directory was stale.
2150 ncl_dircookie_lock(dnp);
2151 cookiep = ncl_getcookie(dnp, uiop->uio_offset, 0);
2154 ncl_dircookie_unlock(dnp);
2156 ncl_dircookie_unlock(dnp);
2157 return (NFSERR_BAD_COOKIE);
2160 if (NFSHASNFSV3(nmp) && !NFSHASGOTFSINFO(nmp))
2161 (void)ncl_fsinfo(nmp, vp, cred, td);
2162 error = nfsrpc_readdirplus(vp, uiop, &cookie, cred, td, &nfsva,
2163 &attrflag, &eof, NULL);
2165 (void) nfscl_loadattrcache(&vp, &nfsva, NULL, NULL, 0, 1);
2169 * We are now either at end of the directory or have filled the
2173 dnp->n_direofoffset = uiop->uio_offset;
2175 if (uiop->uio_resid > 0)
2176 ncl_printf("EEK! readdirplusrpc resid > 0\n");
2177 ncl_dircookie_lock(dnp);
2178 cookiep = ncl_getcookie(dnp, uiop->uio_offset, 1);
2180 ncl_dircookie_unlock(dnp);
2182 } else if (NFS_ISV4(vp)) {
2183 error = nfscl_maperr(td, error, (uid_t)0, (gid_t)0);
2189 * Silly rename. To make the NFS filesystem that is stateless look a little
2190 * more like the "ufs" a remove of an active vnode is translated to a rename
2191 * to a funny looking filename that is removed by nfs_inactive on the
2192 * nfsnode. There is the potential for another process on a different client
2193 * to create the same funny name between the nfs_lookitup() fails and the
2194 * nfs_rename() completes, but...
2197 nfs_sillyrename(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
2199 struct sillyrename *sp;
2203 unsigned int lticks;
2208 if (vp->v_type == VDIR)
2209 panic("nfs: sillyrename dir");
2211 MALLOC(sp, struct sillyrename *, sizeof (struct sillyrename),
2212 M_NEWNFSREQ, M_WAITOK);
2213 sp->s_cred = crhold(cnp->cn_cred);
2218 * Fudge together a funny name.
2219 * Changing the format of the funny name to accomodate more
2220 * sillynames per directory.
2221 * The name is now changed to .nfs.<ticks>.<pid>.4, where ticks is
2222 * CPU ticks since boot.
2224 pid = cnp->cn_thread->td_proc->p_pid;
2225 lticks = (unsigned int)ticks;
2227 sp->s_namlen = sprintf(sp->s_name,
2228 ".nfs.%08x.%04x4.4", lticks,
2230 if (nfs_lookitup(dvp, sp->s_name, sp->s_namlen, sp->s_cred,
2231 cnp->cn_thread, NULL))
2235 error = nfs_renameit(dvp, vp, cnp, sp);
2238 error = nfs_lookitup(dvp, sp->s_name, sp->s_namlen, sp->s_cred,
2239 cnp->cn_thread, &np);
2240 np->n_sillyrename = sp;
2245 free((caddr_t)sp, M_NEWNFSREQ);
2250 * Look up a file name and optionally either update the file handle or
2251 * allocate an nfsnode, depending on the value of npp.
2252 * npp == NULL --> just do the lookup
2253 * *npp == NULL --> allocate a new nfsnode and make sure attributes are
2255 * *npp != NULL --> update the file handle in the vnode
2258 nfs_lookitup(struct vnode *dvp, char *name, int len, struct ucred *cred,
2259 struct thread *td, struct nfsnode **npp)
2261 struct vnode *newvp = NULL, *vp;
2262 struct nfsnode *np, *dnp = VTONFS(dvp);
2263 struct nfsfh *nfhp, *onfhp;
2264 struct nfsvattr nfsva, dnfsva;
2265 struct componentname cn;
2266 int error = 0, attrflag, dattrflag;
2269 error = nfsrpc_lookup(dvp, name, len, cred, td, &dnfsva, &nfsva,
2270 &nfhp, &attrflag, &dattrflag, NULL);
2272 (void) nfscl_loadattrcache(&dvp, &dnfsva, NULL, NULL, 0, 1);
2273 if (npp && !error) {
2278 * For NFSv4, check to see if it is the same name and
2279 * replace the name, if it is different.
2281 if (np->n_v4 != NULL && nfsva.na_type == VREG &&
2282 (np->n_v4->n4_namelen != len ||
2283 NFSBCMP(name, NFS4NODENAME(np->n_v4), len) ||
2284 dnp->n_fhp->nfh_len != np->n_v4->n4_fhlen ||
2285 NFSBCMP(dnp->n_fhp->nfh_fh, np->n_v4->n4_data,
2286 dnp->n_fhp->nfh_len))) {
2288 { char nnn[100]; int nnnl;
2289 nnnl = (len < 100) ? len : 99;
2290 bcopy(name, nnn, nnnl);
2292 printf("replace=%s\n",nnn);
2295 FREE((caddr_t)np->n_v4, M_NFSV4NODE);
2296 MALLOC(np->n_v4, struct nfsv4node *,
2297 sizeof (struct nfsv4node) +
2298 dnp->n_fhp->nfh_len + len - 1,
2299 M_NFSV4NODE, M_WAITOK);
2300 np->n_v4->n4_fhlen = dnp->n_fhp->nfh_len;
2301 np->n_v4->n4_namelen = len;
2302 NFSBCOPY(dnp->n_fhp->nfh_fh, np->n_v4->n4_data,
2303 dnp->n_fhp->nfh_len);
2304 NFSBCOPY(name, NFS4NODENAME(np->n_v4), len);
2306 hash = fnv_32_buf(nfhp->nfh_fh, nfhp->nfh_len,
2310 * Rehash node for new file handle.
2312 vfs_hash_rehash(vp, hash);
2315 FREE((caddr_t)onfhp, M_NFSFH);
2317 } else if (NFS_CMPFH(dnp, nfhp->nfh_fh, nfhp->nfh_len)) {
2318 FREE((caddr_t)nfhp, M_NFSFH);
2322 cn.cn_nameptr = name;
2323 cn.cn_namelen = len;
2324 error = nfscl_nget(dvp->v_mount, dvp, nfhp, &cn, td,
2330 if (!attrflag && *npp == NULL) {
2335 (void) nfscl_loadattrcache(&newvp, &nfsva, NULL, NULL,
2338 if (npp && *npp == NULL) {
2349 if (error && NFS_ISV4(dvp))
2350 error = nfscl_maperr(td, error, (uid_t)0, (gid_t)0);
2355 * Nfs Version 3 and 4 commit rpc
2358 ncl_commit(struct vnode *vp, u_quad_t offset, int cnt, struct ucred *cred,
2361 struct nfsvattr nfsva;
2362 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2363 int error, attrflag;
2364 u_char verf[NFSX_VERF];
2366 mtx_lock(&nmp->nm_mtx);
2367 if ((nmp->nm_state & NFSSTA_HASWRITEVERF) == 0) {
2368 mtx_unlock(&nmp->nm_mtx);
2371 mtx_unlock(&nmp->nm_mtx);
2372 error = nfsrpc_commit(vp, offset, cnt, cred, td, verf, &nfsva,
2375 if (NFSBCMP((caddr_t)nmp->nm_verf, verf, NFSX_VERF)) {
2376 NFSBCOPY(verf, (caddr_t)nmp->nm_verf, NFSX_VERF);
2377 error = NFSERR_STALEWRITEVERF;
2379 if (!error && attrflag)
2380 (void) nfscl_loadattrcache(&vp, &nfsva, NULL, NULL,
2382 } else if (NFS_ISV4(vp)) {
2383 error = nfscl_maperr(td, error, (uid_t)0, (gid_t)0);
2390 * For async requests when nfsiod(s) are running, queue the request by
2391 * calling ncl_asyncio(), otherwise just all ncl_doio() to do the
2395 nfs_strategy(struct vop_strategy_args *ap)
2397 struct buf *bp = ap->a_bp;
2400 KASSERT(!(bp->b_flags & B_DONE),
2401 ("nfs_strategy: buffer %p unexpectedly marked B_DONE", bp));
2402 BUF_ASSERT_HELD(bp);
2404 if (bp->b_iocmd == BIO_READ)
2410 * If the op is asynchronous and an i/o daemon is waiting
2411 * queue the request, wake it up and wait for completion
2412 * otherwise just do it ourselves.
2414 if ((bp->b_flags & B_ASYNC) == 0 ||
2415 ncl_asyncio(VFSTONFS(ap->a_vp->v_mount), bp, NOCRED, curthread))
2416 (void)ncl_doio(ap->a_vp, bp, cr, curthread);
2421 * fsync vnode op. Just call ncl_flush() with commit == 1.
2425 nfs_fsync(struct vop_fsync_args *ap)
2427 return (ncl_flush(ap->a_vp, ap->a_waitfor, NULL, ap->a_td, 1));
2431 * Flush all the blocks associated with a vnode.
2432 * Walk through the buffer pool and push any dirty pages
2433 * associated with the vnode.
2436 ncl_flush(struct vnode *vp, int waitfor, struct ucred *cred, struct thread *td,
2439 struct nfsnode *np = VTONFS(vp);
2443 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2444 int error = 0, slptimeo = 0, slpflag = 0, retv, bvecpos;
2445 int passone = 1, trycnt = 0;
2446 u_quad_t off, endoff, toff;
2447 struct ucred* wcred = NULL;
2448 struct buf **bvec = NULL;
2450 #ifndef NFS_COMMITBVECSIZ
2451 #define NFS_COMMITBVECSIZ 20
2453 struct buf *bvec_on_stack[NFS_COMMITBVECSIZ];
2454 int bvecsize = 0, bveccount;
2456 if (nmp->nm_flag & NFSMNT_INT)
2457 slpflag = NFS_PCATCH;
2462 * A b_flags == (B_DELWRI | B_NEEDCOMMIT) block has been written to the
2463 * server, but has not been committed to stable storage on the server
2464 * yet. On the first pass, the byte range is worked out and the commit
2465 * rpc is done. On the second pass, ncl_writebp() is called to do the
2472 if (NFS_ISV34(vp) && commit) {
2473 if (bvec != NULL && bvec != bvec_on_stack)
2476 * Count up how many buffers waiting for a commit.
2480 TAILQ_FOREACH_SAFE(bp, &bo->bo_dirty.bv_hd, b_bobufs, nbp) {
2481 if (!BUF_ISLOCKED(bp) &&
2482 (bp->b_flags & (B_DELWRI | B_NEEDCOMMIT))
2483 == (B_DELWRI | B_NEEDCOMMIT))
2487 * Allocate space to remember the list of bufs to commit. It is
2488 * important to use M_NOWAIT here to avoid a race with nfs_write.
2489 * If we can't get memory (for whatever reason), we will end up
2490 * committing the buffers one-by-one in the loop below.
2492 if (bveccount > NFS_COMMITBVECSIZ) {
2494 * Release the vnode interlock to avoid a lock
2498 bvec = (struct buf **)
2499 malloc(bveccount * sizeof(struct buf *),
2503 bvec = bvec_on_stack;
2504 bvecsize = NFS_COMMITBVECSIZ;
2506 bvecsize = bveccount;
2508 bvec = bvec_on_stack;
2509 bvecsize = NFS_COMMITBVECSIZ;
2511 TAILQ_FOREACH_SAFE(bp, &bo->bo_dirty.bv_hd, b_bobufs, nbp) {
2512 if (bvecpos >= bvecsize)
2514 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL)) {
2515 nbp = TAILQ_NEXT(bp, b_bobufs);
2518 if ((bp->b_flags & (B_DELWRI | B_NEEDCOMMIT)) !=
2519 (B_DELWRI | B_NEEDCOMMIT)) {
2521 nbp = TAILQ_NEXT(bp, b_bobufs);
2527 * Work out if all buffers are using the same cred
2528 * so we can deal with them all with one commit.
2530 * NOTE: we are not clearing B_DONE here, so we have
2531 * to do it later on in this routine if we intend to
2532 * initiate I/O on the bp.
2534 * Note: to avoid loopback deadlocks, we do not
2535 * assign b_runningbufspace.
2538 wcred = bp->b_wcred;
2539 else if (wcred != bp->b_wcred)
2541 vfs_busy_pages(bp, 1);
2545 * bp is protected by being locked, but nbp is not
2546 * and vfs_busy_pages() may sleep. We have to
2549 nbp = TAILQ_NEXT(bp, b_bobufs);
2552 * A list of these buffers is kept so that the
2553 * second loop knows which buffers have actually
2554 * been committed. This is necessary, since there
2555 * may be a race between the commit rpc and new
2556 * uncommitted writes on the file.
2558 bvec[bvecpos++] = bp;
2559 toff = ((u_quad_t)bp->b_blkno) * DEV_BSIZE +
2563 toff += (u_quad_t)(bp->b_dirtyend - bp->b_dirtyoff);
2571 * Commit data on the server, as required.
2572 * If all bufs are using the same wcred, then use that with
2573 * one call for all of them, otherwise commit each one
2576 if (wcred != NOCRED)
2577 retv = ncl_commit(vp, off, (int)(endoff - off),
2581 for (i = 0; i < bvecpos; i++) {
2584 off = ((u_quad_t)bp->b_blkno) * DEV_BSIZE +
2586 size = (u_quad_t)(bp->b_dirtyend
2588 retv = ncl_commit(vp, off, (int)size,
2594 if (retv == NFSERR_STALEWRITEVERF)
2595 ncl_clearcommit(vp->v_mount);
2598 * Now, either mark the blocks I/O done or mark the
2599 * blocks dirty, depending on whether the commit
2602 for (i = 0; i < bvecpos; i++) {
2604 bp->b_flags &= ~(B_NEEDCOMMIT | B_CLUSTEROK);
2607 * Error, leave B_DELWRI intact
2609 vfs_unbusy_pages(bp);
2613 * Success, remove B_DELWRI ( bundirty() ).
2615 * b_dirtyoff/b_dirtyend seem to be NFS
2616 * specific. We should probably move that
2617 * into bundirty(). XXX
2620 bp->b_flags |= B_ASYNC;
2622 bp->b_flags &= ~B_DONE;
2623 bp->b_ioflags &= ~BIO_ERROR;
2624 bp->b_dirtyoff = bp->b_dirtyend = 0;
2631 * Start/do any write(s) that are required.
2635 TAILQ_FOREACH_SAFE(bp, &bo->bo_dirty.bv_hd, b_bobufs, nbp) {
2636 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL)) {
2637 if (waitfor != MNT_WAIT || passone)
2640 error = BUF_TIMELOCK(bp,
2641 LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK,
2642 BO_MTX(bo), "nfsfsync", slpflag, slptimeo);
2647 if (error == ENOLCK) {
2651 if (newnfs_sigintr(nmp, td)) {
2655 if (slpflag & PCATCH) {
2661 if ((bp->b_flags & B_DELWRI) == 0)
2662 panic("nfs_fsync: not dirty");
2663 if ((passone || !commit) && (bp->b_flags & B_NEEDCOMMIT)) {
2669 if (passone || !commit)
2670 bp->b_flags |= B_ASYNC;
2672 bp->b_flags |= B_ASYNC;
2674 if (newnfs_sigintr(nmp, td)) {
2685 if (waitfor == MNT_WAIT) {
2686 while (bo->bo_numoutput) {
2687 error = bufobj_wwait(bo, slpflag, slptimeo);
2690 error = newnfs_sigintr(nmp, td);
2693 if (slpflag & PCATCH) {
2700 if (bo->bo_dirty.bv_cnt != 0 && commit) {
2705 * Wait for all the async IO requests to drain
2708 mtx_lock(&np->n_mtx);
2709 while (np->n_directio_asyncwr > 0) {
2710 np->n_flag |= NFSYNCWAIT;
2711 error = ncl_msleep(td, (caddr_t)&np->n_directio_asyncwr,
2712 &np->n_mtx, slpflag | (PRIBIO + 1),
2715 if (newnfs_sigintr(nmp, td)) {
2716 mtx_unlock(&np->n_mtx);
2722 mtx_unlock(&np->n_mtx);
2725 mtx_lock(&np->n_mtx);
2726 if (np->n_flag & NWRITEERR) {
2727 error = np->n_error;
2728 np->n_flag &= ~NWRITEERR;
2730 if (commit && bo->bo_dirty.bv_cnt == 0 &&
2731 bo->bo_numoutput == 0 && np->n_directio_asyncwr == 0)
2732 np->n_flag &= ~NMODIFIED;
2733 mtx_unlock(&np->n_mtx);
2735 if (bvec != NULL && bvec != bvec_on_stack)
2737 if (error == 0 && commit != 0 && waitfor == MNT_WAIT &&
2738 (bo->bo_dirty.bv_cnt != 0 || bo->bo_numoutput != 0 ||
2739 np->n_directio_asyncwr != 0) && trycnt++ < 5) {
2740 /* try, try again... */
2745 printf("try%d\n", trycnt);
2752 * NFS advisory byte-level locks.
2755 nfs_advlock(struct vop_advlock_args *ap)
2757 struct vnode *vp = ap->a_vp;
2759 struct nfsnode *np = VTONFS(ap->a_vp);
2760 struct proc *p = (struct proc *)ap->a_id;
2761 struct thread *td = curthread; /* XXX */
2763 int ret, error = EOPNOTSUPP;
2766 if (NFS_ISV4(vp) && (ap->a_flags & F_POSIX)) {
2768 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
2769 if (vp->v_iflag & VI_DOOMED) {
2775 * If this is unlocking a write locked region, flush and
2776 * commit them before unlocking. This is required by
2777 * RFC3530 Sec. 9.3.2.
2779 if (ap->a_op == F_UNLCK &&
2780 nfscl_checkwritelocked(vp, ap->a_fl, cred, td))
2781 (void) ncl_flush(vp, MNT_WAIT, cred, td, 1);
2784 * Loop around doing the lock op, while a blocking lock
2785 * must wait for the lock op to succeed.
2788 ret = nfsrpc_advlock(vp, np->n_size, ap->a_op,
2789 ap->a_fl, 0, cred, td);
2790 if (ret == NFSERR_DENIED && (ap->a_flags & F_WAIT) &&
2791 ap->a_op == F_SETLK) {
2793 error = nfs_catnap(PZERO | PCATCH, "ncladvl");
2796 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
2797 if (vp->v_iflag & VI_DOOMED) {
2802 } while (ret == NFSERR_DENIED && (ap->a_flags & F_WAIT) &&
2803 ap->a_op == F_SETLK);
2804 if (ret == NFSERR_DENIED) {
2807 } else if (ret == EINVAL || ret == EBADF || ret == EINTR) {
2810 } else if (ret != 0) {
2816 * Now, if we just got a lock, invalidate data in the buffer
2817 * cache, as required, so that the coherency conforms with
2818 * RFC3530 Sec. 9.3.2.
2820 if (ap->a_op == F_SETLK) {
2821 if ((np->n_flag & NMODIFIED) == 0) {
2822 np->n_attrstamp = 0;
2823 ret = VOP_GETATTR(vp, &va, cred);
2825 if ((np->n_flag & NMODIFIED) || ret ||
2826 np->n_change != va.va_filerev) {
2827 (void) ncl_vinvalbuf(vp, V_SAVE, td, 1);
2828 np->n_attrstamp = 0;
2829 ret = VOP_GETATTR(vp, &va, cred);
2831 np->n_mtime = va.va_mtime;
2832 np->n_change = va.va_filerev;
2838 } else if (!NFS_ISV4(vp)) {
2839 error = vn_lock(vp, LK_SHARED);
2842 if ((VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NOLOCKD) != 0) {
2843 size = VTONFS(vp)->n_size;
2845 error = lf_advlock(ap, &(vp->v_lockf), size);
2848 error = ncl_advlock_p(ap);
2857 * NFS advisory byte-level locks.
2860 nfs_advlockasync(struct vop_advlockasync_args *ap)
2862 struct vnode *vp = ap->a_vp;
2867 return (EOPNOTSUPP);
2868 error = vn_lock(vp, LK_SHARED);
2871 if ((VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NOLOCKD) != 0) {
2872 size = VTONFS(vp)->n_size;
2874 error = lf_advlockasync(ap, &(vp->v_lockf), size);
2883 * Print out the contents of an nfsnode.
2886 nfs_print(struct vop_print_args *ap)
2888 struct vnode *vp = ap->a_vp;
2889 struct nfsnode *np = VTONFS(vp);
2891 ncl_printf("\tfileid %ld fsid 0x%x",
2892 np->n_vattr.na_fileid, np->n_vattr.na_fsid);
2893 if (vp->v_type == VFIFO)
2900 * This is the "real" nfs::bwrite(struct buf*).
2901 * We set B_CACHE if this is a VMIO buffer.
2904 ncl_writebp(struct buf *bp, int force __unused, struct thread *td)
2907 int oldflags = bp->b_flags;
2913 BUF_ASSERT_HELD(bp);
2915 if (bp->b_flags & B_INVAL) {
2920 bp->b_flags |= B_CACHE;
2923 * Undirty the bp. We will redirty it later if the I/O fails.
2928 bp->b_flags &= ~B_DONE;
2929 bp->b_ioflags &= ~BIO_ERROR;
2930 bp->b_iocmd = BIO_WRITE;
2932 bufobj_wref(bp->b_bufobj);
2933 curthread->td_ru.ru_oublock++;
2937 * Note: to avoid loopback deadlocks, we do not
2938 * assign b_runningbufspace.
2940 vfs_busy_pages(bp, 1);
2943 bp->b_iooffset = dbtob(bp->b_blkno);
2946 if( (oldflags & B_ASYNC) == 0) {
2947 int rtval = bufwait(bp);
2949 if (oldflags & B_DELWRI) {
2962 * nfs special file access vnode op.
2963 * Essentially just get vattr and then imitate iaccess() since the device is
2964 * local to the client.
2967 nfsspec_access(struct vop_access_args *ap)
2970 struct ucred *cred = ap->a_cred;
2971 struct vnode *vp = ap->a_vp;
2972 accmode_t accmode = ap->a_accmode;
2977 * Disallow write attempts on filesystems mounted read-only;
2978 * unless the file is a socket, fifo, or a block or character
2979 * device resident on the filesystem.
2981 if ((accmode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
2982 switch (vp->v_type) {
2992 error = VOP_GETATTR(vp, vap, cred);
2995 error = vaccess(vp->v_type, vap->va_mode, vap->va_uid, vap->va_gid,
2996 accmode, cred, NULL);
3002 * Read wrapper for fifos.
3005 nfsfifo_read(struct vop_read_args *ap)
3007 struct nfsnode *np = VTONFS(ap->a_vp);
3013 mtx_lock(&np->n_mtx);
3015 getnanotime(&np->n_atim);
3016 mtx_unlock(&np->n_mtx);
3017 error = fifo_specops.vop_read(ap);
3022 * Write wrapper for fifos.
3025 nfsfifo_write(struct vop_write_args *ap)
3027 struct nfsnode *np = VTONFS(ap->a_vp);
3032 mtx_lock(&np->n_mtx);
3034 getnanotime(&np->n_mtim);
3035 mtx_unlock(&np->n_mtx);
3036 return(fifo_specops.vop_write(ap));
3040 * Close wrapper for fifos.
3042 * Update the times on the nfsnode then do fifo close.
3045 nfsfifo_close(struct vop_close_args *ap)
3047 struct vnode *vp = ap->a_vp;
3048 struct nfsnode *np = VTONFS(vp);
3052 mtx_lock(&np->n_mtx);
3053 if (np->n_flag & (NACC | NUPD)) {
3055 if (np->n_flag & NACC)
3057 if (np->n_flag & NUPD)
3060 if (vrefcnt(vp) == 1 &&
3061 (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
3063 if (np->n_flag & NACC)
3064 vattr.va_atime = np->n_atim;
3065 if (np->n_flag & NUPD)
3066 vattr.va_mtime = np->n_mtim;
3067 mtx_unlock(&np->n_mtx);
3068 (void)VOP_SETATTR(vp, &vattr, ap->a_cred);
3072 mtx_unlock(&np->n_mtx);
3074 return (fifo_specops.vop_close(ap));
3078 * Just call ncl_writebp() with the force argument set to 1.
3080 * NOTE: B_DONE may or may not be set in a_bp on call.
3083 nfs_bwrite(struct buf *bp)
3086 return (ncl_writebp(bp, 1, curthread));
3089 struct buf_ops buf_ops_newnfs = {
3090 .bop_name = "buf_ops_nfs",
3091 .bop_write = nfs_bwrite,
3092 .bop_strategy = bufstrategy,
3093 .bop_sync = bufsync,
3094 .bop_bdflush = bufbdflush,
3098 * Cloned from vop_stdlock(), and then the ugly hack added.
3101 nfs_lock1(struct vop_lock1_args *ap)
3103 struct vnode *vp = ap->a_vp;
3107 * Since vfs_hash_get() calls vget() and it will no longer work
3108 * for FreeBSD8 with flags == 0, I can only think of this horrible
3109 * hack to work around it. I call vfs_hash_get() with LK_EXCLOTHER
3110 * and then handle it here. All I want for this case is a v_usecount
3111 * on the vnode to use for recovery, while another thread might
3112 * hold a lock on the vnode. I have the other threads blocked, so
3113 * there isn't any race problem.
3115 if ((ap->a_flags & LK_TYPE_MASK) == LK_EXCLOTHER) {
3116 if ((ap->a_flags & LK_INTERLOCK) == 0)
3118 if ((vp->v_iflag & VI_DOOMED))
3123 return (_lockmgr_args(vp->v_vnlock, ap->a_flags, VI_MTX(vp),
3124 LK_WMESG_DEFAULT, LK_PRIO_DEFAULT, LK_TIMO_DEFAULT, ap->a_file,
3128 #ifdef NFS4_ACL_EXTATTR_NAME
3130 nfs_getacl(struct vop_getacl_args *ap)
3134 if (ap->a_type != ACL_TYPE_NFS4)
3135 return (EOPNOTSUPP);
3136 error = nfsrpc_getacl(ap->a_vp, ap->a_cred, ap->a_td, ap->a_aclp,
3138 if (error > NFSERR_STALE) {
3139 (void) nfscl_maperr(ap->a_td, error, (uid_t)0, (gid_t)0);
3146 nfs_setacl(struct vop_setacl_args *ap)
3150 if (ap->a_type != ACL_TYPE_NFS4)
3151 return (EOPNOTSUPP);
3152 error = nfsrpc_setacl(ap->a_vp, ap->a_cred, ap->a_td, ap->a_aclp,
3154 if (error > NFSERR_STALE) {
3155 (void) nfscl_maperr(ap->a_td, error, (uid_t)0, (gid_t)0);
3161 #endif /* NFS4_ACL_EXTATTR_NAME */