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
37 * $FreeBSD: src/sys/nfs/nfs_vnops.c,v 1.150.2.5 2001/12/20 19:56:28 dillon Exp $
38 * $DragonFly: src/sys/vfs/nfs/nfs_vnops.c,v 1.13 2003/10/09 22:27:26 dillon Exp $
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>
55 #include <sys/malloc.h>
57 #include <sys/namei.h>
58 #include <sys/socket.h>
59 #include <sys/vnode.h>
60 #include <sys/dirent.h>
61 #include <sys/fcntl.h>
62 #include <sys/lockf.h>
64 #include <sys/sysctl.h>
68 #include <vm/vm_extern.h>
69 #include <vm/vm_zone.h>
73 #include <vfs/fifofs/fifo.h>
81 #include "nfsm_subs.h"
85 #include <netinet/in.h>
86 #include <netinet/in_var.h>
93 * Ifdef for FreeBSD-current merged buffer cache. It is unfortunate that these
94 * calls are not in getblk() and brelse() so that they would not be necessary
98 #define vfs_busy_pages(bp, f)
101 static int nfsspec_read (struct vop_read_args *);
102 static int nfsspec_write (struct vop_write_args *);
103 static int nfsfifo_read (struct vop_read_args *);
104 static int nfsfifo_write (struct vop_write_args *);
105 static int nfsspec_close (struct vop_close_args *);
106 static int nfsfifo_close (struct vop_close_args *);
107 #define nfs_poll vop_nopoll
108 static int nfs_flush (struct vnode *,int,struct thread *,int);
109 static int nfs_setattrrpc (struct vnode *,struct vattr *,struct ucred *,struct thread *);
110 static int nfs_lookup (struct vop_lookup_args *);
111 static int nfs_create (struct vop_create_args *);
112 static int nfs_mknod (struct vop_mknod_args *);
113 static int nfs_open (struct vop_open_args *);
114 static int nfs_close (struct vop_close_args *);
115 static int nfs_access (struct vop_access_args *);
116 static int nfs_getattr (struct vop_getattr_args *);
117 static int nfs_setattr (struct vop_setattr_args *);
118 static int nfs_read (struct vop_read_args *);
119 static int nfs_mmap (struct vop_mmap_args *);
120 static int nfs_fsync (struct vop_fsync_args *);
121 static int nfs_remove (struct vop_remove_args *);
122 static int nfs_link (struct vop_link_args *);
123 static int nfs_rename (struct vop_rename_args *);
124 static int nfs_mkdir (struct vop_mkdir_args *);
125 static int nfs_rmdir (struct vop_rmdir_args *);
126 static int nfs_symlink (struct vop_symlink_args *);
127 static int nfs_readdir (struct vop_readdir_args *);
128 static int nfs_bmap (struct vop_bmap_args *);
129 static int nfs_strategy (struct vop_strategy_args *);
130 static int nfs_lookitup (struct vnode *, const char *, int,
131 struct ucred *, struct thread *, struct nfsnode **);
132 static int nfs_sillyrename (struct vnode *,struct vnode *,struct componentname *);
133 static int nfsspec_access (struct vop_access_args *);
134 static int nfs_readlink (struct vop_readlink_args *);
135 static int nfs_print (struct vop_print_args *);
136 static int nfs_advlock (struct vop_advlock_args *);
137 static int nfs_bwrite (struct vop_bwrite_args *);
139 * Global vfs data structures for nfs
141 vop_t **nfsv2_vnodeop_p;
142 static struct vnodeopv_entry_desc nfsv2_vnodeop_entries[] = {
143 { &vop_default_desc, (vop_t *) vop_defaultop },
144 { &vop_access_desc, (vop_t *) nfs_access },
145 { &vop_advlock_desc, (vop_t *) nfs_advlock },
146 { &vop_bmap_desc, (vop_t *) nfs_bmap },
147 { &vop_bwrite_desc, (vop_t *) nfs_bwrite },
148 { &vop_close_desc, (vop_t *) nfs_close },
149 { &vop_create_desc, (vop_t *) nfs_create },
150 { &vop_fsync_desc, (vop_t *) nfs_fsync },
151 { &vop_getattr_desc, (vop_t *) nfs_getattr },
152 { &vop_getpages_desc, (vop_t *) nfs_getpages },
153 { &vop_putpages_desc, (vop_t *) nfs_putpages },
154 { &vop_inactive_desc, (vop_t *) nfs_inactive },
155 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
156 { &vop_lease_desc, (vop_t *) vop_null },
157 { &vop_link_desc, (vop_t *) nfs_link },
158 { &vop_lock_desc, (vop_t *) vop_sharedlock },
159 { &vop_lookup_desc, (vop_t *) nfs_lookup },
160 { &vop_mkdir_desc, (vop_t *) nfs_mkdir },
161 { &vop_mknod_desc, (vop_t *) nfs_mknod },
162 { &vop_mmap_desc, (vop_t *) nfs_mmap },
163 { &vop_open_desc, (vop_t *) nfs_open },
164 { &vop_poll_desc, (vop_t *) nfs_poll },
165 { &vop_print_desc, (vop_t *) nfs_print },
166 { &vop_read_desc, (vop_t *) nfs_read },
167 { &vop_readdir_desc, (vop_t *) nfs_readdir },
168 { &vop_readlink_desc, (vop_t *) nfs_readlink },
169 { &vop_reclaim_desc, (vop_t *) nfs_reclaim },
170 { &vop_remove_desc, (vop_t *) nfs_remove },
171 { &vop_rename_desc, (vop_t *) nfs_rename },
172 { &vop_rmdir_desc, (vop_t *) nfs_rmdir },
173 { &vop_setattr_desc, (vop_t *) nfs_setattr },
174 { &vop_strategy_desc, (vop_t *) nfs_strategy },
175 { &vop_symlink_desc, (vop_t *) nfs_symlink },
176 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
177 { &vop_write_desc, (vop_t *) nfs_write },
180 static struct vnodeopv_desc nfsv2_vnodeop_opv_desc =
181 { &nfsv2_vnodeop_p, nfsv2_vnodeop_entries };
182 VNODEOP_SET(nfsv2_vnodeop_opv_desc);
185 * Special device vnode ops
187 vop_t **spec_nfsv2nodeop_p;
188 static struct vnodeopv_entry_desc nfsv2_specop_entries[] = {
189 { &vop_default_desc, (vop_t *) spec_vnoperate },
190 { &vop_access_desc, (vop_t *) nfsspec_access },
191 { &vop_close_desc, (vop_t *) nfsspec_close },
192 { &vop_fsync_desc, (vop_t *) nfs_fsync },
193 { &vop_getattr_desc, (vop_t *) nfs_getattr },
194 { &vop_inactive_desc, (vop_t *) nfs_inactive },
195 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
196 { &vop_lock_desc, (vop_t *) vop_sharedlock },
197 { &vop_print_desc, (vop_t *) nfs_print },
198 { &vop_read_desc, (vop_t *) nfsspec_read },
199 { &vop_reclaim_desc, (vop_t *) nfs_reclaim },
200 { &vop_setattr_desc, (vop_t *) nfs_setattr },
201 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
202 { &vop_write_desc, (vop_t *) nfsspec_write },
205 static struct vnodeopv_desc spec_nfsv2nodeop_opv_desc =
206 { &spec_nfsv2nodeop_p, nfsv2_specop_entries };
207 VNODEOP_SET(spec_nfsv2nodeop_opv_desc);
209 vop_t **fifo_nfsv2nodeop_p;
210 static struct vnodeopv_entry_desc nfsv2_fifoop_entries[] = {
211 { &vop_default_desc, (vop_t *) fifo_vnoperate },
212 { &vop_access_desc, (vop_t *) nfsspec_access },
213 { &vop_close_desc, (vop_t *) nfsfifo_close },
214 { &vop_fsync_desc, (vop_t *) nfs_fsync },
215 { &vop_getattr_desc, (vop_t *) nfs_getattr },
216 { &vop_inactive_desc, (vop_t *) nfs_inactive },
217 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
218 { &vop_lock_desc, (vop_t *) vop_sharedlock },
219 { &vop_print_desc, (vop_t *) nfs_print },
220 { &vop_read_desc, (vop_t *) nfsfifo_read },
221 { &vop_reclaim_desc, (vop_t *) nfs_reclaim },
222 { &vop_setattr_desc, (vop_t *) nfs_setattr },
223 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
224 { &vop_write_desc, (vop_t *) nfsfifo_write },
227 static struct vnodeopv_desc fifo_nfsv2nodeop_opv_desc =
228 { &fifo_nfsv2nodeop_p, nfsv2_fifoop_entries };
229 VNODEOP_SET(fifo_nfsv2nodeop_opv_desc);
231 static int nfs_mknodrpc (struct vnode *dvp, struct vnode **vpp,
232 struct componentname *cnp,
234 static int nfs_removerpc (struct vnode *dvp, const char *name,
236 struct ucred *cred, struct thread *td);
237 static int nfs_renamerpc (struct vnode *fdvp, const char *fnameptr,
238 int fnamelen, struct vnode *tdvp,
239 const char *tnameptr, int tnamelen,
240 struct ucred *cred, struct thread *td);
241 static int nfs_renameit (struct vnode *sdvp,
242 struct componentname *scnp,
243 struct sillyrename *sp);
248 extern u_int32_t nfs_true, nfs_false;
249 extern u_int32_t nfs_xdrneg1;
250 extern struct nfsstats nfsstats;
251 extern nfstype nfsv3_type[9];
252 struct thread *nfs_iodwant[NFS_MAXASYNCDAEMON];
253 struct nfsmount *nfs_iodmount[NFS_MAXASYNCDAEMON];
254 int nfs_numasync = 0;
255 #define DIRHDSIZ (sizeof (struct dirent) - (MAXNAMLEN + 1))
257 SYSCTL_DECL(_vfs_nfs);
259 static int nfsaccess_cache_timeout = NFS_MAXATTRTIMO;
260 SYSCTL_INT(_vfs_nfs, OID_AUTO, access_cache_timeout, CTLFLAG_RW,
261 &nfsaccess_cache_timeout, 0, "NFS ACCESS cache timeout");
263 static int nfsv3_commit_on_close = 0;
264 SYSCTL_INT(_vfs_nfs, OID_AUTO, nfsv3_commit_on_close, CTLFLAG_RW,
265 &nfsv3_commit_on_close, 0, "write+commit on close, else only write");
267 SYSCTL_INT(_vfs_nfs, OID_AUTO, access_cache_hits, CTLFLAG_RD,
268 &nfsstats.accesscache_hits, 0, "NFS ACCESS cache hit count");
270 SYSCTL_INT(_vfs_nfs, OID_AUTO, access_cache_misses, CTLFLAG_RD,
271 &nfsstats.accesscache_misses, 0, "NFS ACCESS cache miss count");
274 #define NFSV3ACCESS_ALL (NFSV3ACCESS_READ | NFSV3ACCESS_MODIFY \
275 | NFSV3ACCESS_EXTEND | NFSV3ACCESS_EXECUTE \
276 | NFSV3ACCESS_DELETE | NFSV3ACCESS_LOOKUP)
278 nfs3_access_otw(struct vnode *vp, int wmode,
279 struct thread *td, struct ucred *cred)
283 int error = 0, attrflag;
285 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
286 caddr_t bpos, dpos, cp2;
290 struct nfsnode *np = VTONFS(vp);
292 nfsstats.rpccnt[NFSPROC_ACCESS]++;
293 nfsm_reqhead(vp, NFSPROC_ACCESS, NFSX_FH(v3) + NFSX_UNSIGNED);
295 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
296 *tl = txdr_unsigned(wmode);
297 nfsm_request(vp, NFSPROC_ACCESS, td, cred);
298 nfsm_postop_attr(vp, attrflag);
300 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
301 rmode = fxdr_unsigned(u_int32_t, *tl);
303 np->n_modeuid = cred->cr_uid;
304 np->n_modestamp = time_second;
311 * nfs access vnode op.
312 * For nfs version 2, just return ok. File accesses may fail later.
313 * For nfs version 3, use the access rpc to check accessibility. If file modes
314 * are changed on the server, accesses might still fail later.
318 struct vop_access_args /* {
321 struct ucred *a_cred;
325 struct vnode *vp = ap->a_vp;
327 u_int32_t mode, wmode;
328 int v3 = NFS_ISV3(vp);
329 struct nfsnode *np = VTONFS(vp);
332 * Disallow write attempts on filesystems mounted read-only;
333 * unless the file is a socket, fifo, or a block or character
334 * device resident on the filesystem.
336 if ((ap->a_mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
337 switch (vp->v_type) {
347 * For nfs v3, check to see if we have done this recently, and if
348 * so return our cached result instead of making an ACCESS call.
349 * If not, do an access rpc, otherwise you are stuck emulating
350 * ufs_access() locally using the vattr. This may not be correct,
351 * since the server may apply other access criteria such as
352 * client uid-->server uid mapping that we do not know about.
355 if (ap->a_mode & VREAD)
356 mode = NFSV3ACCESS_READ;
359 if (vp->v_type != VDIR) {
360 if (ap->a_mode & VWRITE)
361 mode |= (NFSV3ACCESS_MODIFY | NFSV3ACCESS_EXTEND);
362 if (ap->a_mode & VEXEC)
363 mode |= NFSV3ACCESS_EXECUTE;
365 if (ap->a_mode & VWRITE)
366 mode |= (NFSV3ACCESS_MODIFY | NFSV3ACCESS_EXTEND |
368 if (ap->a_mode & VEXEC)
369 mode |= NFSV3ACCESS_LOOKUP;
371 /* XXX safety belt, only make blanket request if caching */
372 if (nfsaccess_cache_timeout > 0) {
373 wmode = NFSV3ACCESS_READ | NFSV3ACCESS_MODIFY |
374 NFSV3ACCESS_EXTEND | NFSV3ACCESS_EXECUTE |
375 NFSV3ACCESS_DELETE | NFSV3ACCESS_LOOKUP;
381 * Does our cached result allow us to give a definite yes to
384 if ((time_second < (np->n_modestamp + nfsaccess_cache_timeout)) &&
385 (ap->a_cred->cr_uid == np->n_modeuid) &&
386 ((np->n_mode & mode) == mode)) {
387 nfsstats.accesscache_hits++;
390 * Either a no, or a don't know. Go to the wire.
392 nfsstats.accesscache_misses++;
393 error = nfs3_access_otw(vp, wmode, ap->a_td,ap->a_cred);
395 if ((np->n_mode & mode) != mode) {
402 if ((error = nfsspec_access(ap)) != 0)
406 * Attempt to prevent a mapped root from accessing a file
407 * which it shouldn't. We try to read a byte from the file
408 * if the user is root and the file is not zero length.
409 * After calling nfsspec_access, we should have the correct
412 if (ap->a_cred->cr_uid == 0 && (ap->a_mode & VREAD)
413 && VTONFS(vp)->n_size > 0) {
420 auio.uio_iov = &aiov;
424 auio.uio_segflg = UIO_SYSSPACE;
425 auio.uio_rw = UIO_READ;
426 auio.uio_td = ap->a_td;
428 if (vp->v_type == VREG)
429 error = nfs_readrpc(vp, &auio);
430 else if (vp->v_type == VDIR) {
432 bp = malloc(NFS_DIRBLKSIZ, M_TEMP, M_WAITOK);
434 aiov.iov_len = auio.uio_resid = NFS_DIRBLKSIZ;
435 error = nfs_readdirrpc(vp, &auio);
437 } else if (vp->v_type == VLNK)
438 error = nfs_readlinkrpc(vp, &auio);
448 * Check to see if the type is ok
449 * and that deletion is not in progress.
450 * For paged in text files, you will need to flush the page cache
451 * if consistency is lost.
456 struct vop_open_args /* {
459 struct ucred *a_cred;
463 struct vnode *vp = ap->a_vp;
464 struct nfsnode *np = VTONFS(vp);
465 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
469 if (vp->v_type != VREG && vp->v_type != VDIR && vp->v_type != VLNK) {
471 printf("open eacces vtyp=%d\n",vp->v_type);
476 * Get a valid lease. If cached data is stale, flush it.
478 if (nmp->nm_flag & NFSMNT_NQNFS) {
479 if (NQNFS_CKINVALID(vp, np, ND_READ)) {
481 error = nqnfs_getlease(vp, ND_READ, ap->a_td);
482 } while (error == NQNFS_EXPIRED);
485 if (np->n_lrev != np->n_brev ||
486 (np->n_flag & NQNFSNONCACHE)) {
487 if ((error = nfs_vinvalbuf(vp, V_SAVE, ap->a_td, 1))
491 np->n_brev = np->n_lrev;
495 if (np->n_flag & NMODIFIED) {
496 if ((error = nfs_vinvalbuf(vp, V_SAVE, ap->a_td, 1))
501 if (vp->v_type == VDIR)
502 np->n_direofoffset = 0;
503 error = VOP_GETATTR(vp, &vattr, ap->a_td);
506 np->n_mtime = vattr.va_mtime.tv_sec;
508 error = VOP_GETATTR(vp, &vattr, ap->a_td);
511 if (np->n_mtime != vattr.va_mtime.tv_sec) {
512 if (vp->v_type == VDIR)
513 np->n_direofoffset = 0;
514 if ((error = nfs_vinvalbuf(vp, V_SAVE,
515 ap->a_td, 1)) == EINTR) {
518 np->n_mtime = vattr.va_mtime.tv_sec;
522 if ((nmp->nm_flag & NFSMNT_NQNFS) == 0)
523 np->n_attrstamp = 0; /* For Open/Close consistency */
529 * What an NFS client should do upon close after writing is a debatable issue.
530 * Most NFS clients push delayed writes to the server upon close, basically for
532 * 1 - So that any write errors may be reported back to the client process
533 * doing the close system call. By far the two most likely errors are
534 * NFSERR_NOSPC and NFSERR_DQUOT to indicate space allocation failure.
535 * 2 - To put a worst case upper bound on cache inconsistency between
536 * multiple clients for the file.
537 * There is also a consistency problem for Version 2 of the protocol w.r.t.
538 * not being able to tell if other clients are writing a file concurrently,
539 * since there is no way of knowing if the changed modify time in the reply
540 * is only due to the write for this client.
541 * (NFS Version 3 provides weak cache consistency data in the reply that
542 * should be sufficient to detect and handle this case.)
544 * The current code does the following:
545 * for NFS Version 2 - play it safe and flush/invalidate all dirty buffers
546 * for NFS Version 3 - flush dirty buffers to the server but don't invalidate
547 * or commit them (this satisfies 1 and 2 except for the
548 * case where the server crashes after this close but
549 * before the commit RPC, which is felt to be "good
550 * enough". Changing the last argument to nfs_flush() to
551 * a 1 would force a commit operation, if it is felt a
552 * commit is necessary now.
553 * for NQNFS - do nothing now, since 2 is dealt with via leases and
554 * 1 should be dealt with via an fsync() system call for
555 * cases where write errors are important.
560 struct vop_close_args /* {
561 struct vnodeop_desc *a_desc;
564 struct ucred *a_cred;
568 struct vnode *vp = ap->a_vp;
569 struct nfsnode *np = VTONFS(vp);
572 if (vp->v_type == VREG) {
573 if ((VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NQNFS) == 0 &&
574 (np->n_flag & NMODIFIED)) {
577 * Under NFSv3 we have dirty buffers to dispose of. We
578 * must flush them to the NFS server. We have the option
579 * of waiting all the way through the commit rpc or just
580 * waiting for the initial write. The default is to only
581 * wait through the initial write so the data is in the
582 * server's cache, which is roughly similar to the state
583 * a standard disk subsystem leaves the file in on close().
585 * We cannot clear the NMODIFIED bit in np->n_flag due to
586 * potential races with other processes, and certainly
587 * cannot clear it if we don't commit.
589 int cm = nfsv3_commit_on_close ? 1 : 0;
590 error = nfs_flush(vp, MNT_WAIT, ap->a_td, cm);
591 /* np->n_flag &= ~NMODIFIED; */
593 error = nfs_vinvalbuf(vp, V_SAVE, ap->a_td, 1);
597 if (np->n_flag & NWRITEERR) {
598 np->n_flag &= ~NWRITEERR;
606 * nfs getattr call from vfs.
610 struct vop_getattr_args /* {
613 struct ucred *a_cred;
617 struct vnode *vp = ap->a_vp;
618 struct nfsnode *np = VTONFS(vp);
624 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
625 int v3 = NFS_ISV3(vp);
628 * Update local times for special files.
630 if (np->n_flag & (NACC | NUPD))
633 * First look in the cache.
635 if (nfs_getattrcache(vp, ap->a_vap) == 0)
638 if (v3 && nfsaccess_cache_timeout > 0) {
639 nfsstats.accesscache_misses++;
640 nfs3_access_otw(vp, NFSV3ACCESS_ALL, ap->a_td, NFSVPCRED(vp));
641 if (nfs_getattrcache(vp, ap->a_vap) == 0)
645 nfsstats.rpccnt[NFSPROC_GETATTR]++;
646 nfsm_reqhead(vp, NFSPROC_GETATTR, NFSX_FH(v3));
648 nfsm_request(vp, NFSPROC_GETATTR, ap->a_td, NFSVPCRED(vp));
650 nfsm_loadattr(vp, ap->a_vap);
661 struct vop_setattr_args /* {
662 struct vnodeop_desc *a_desc;
665 struct ucred *a_cred;
669 struct vnode *vp = ap->a_vp;
670 struct nfsnode *np = VTONFS(vp);
671 struct vattr *vap = ap->a_vap;
680 * Setting of flags is not supported.
682 if (vap->va_flags != VNOVAL)
686 * Disallow write attempts if the filesystem is mounted read-only.
688 if ((vap->va_flags != VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
689 vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
690 vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL) &&
691 (vp->v_mount->mnt_flag & MNT_RDONLY))
693 if (vap->va_size != VNOVAL) {
694 switch (vp->v_type) {
701 if (vap->va_mtime.tv_sec == VNOVAL &&
702 vap->va_atime.tv_sec == VNOVAL &&
703 vap->va_mode == (mode_t)VNOVAL &&
704 vap->va_uid == (uid_t)VNOVAL &&
705 vap->va_gid == (gid_t)VNOVAL)
707 vap->va_size = VNOVAL;
711 * Disallow write attempts if the filesystem is
714 if (vp->v_mount->mnt_flag & MNT_RDONLY)
718 * We run vnode_pager_setsize() early (why?),
719 * we must set np->n_size now to avoid vinvalbuf
720 * V_SAVE races that might setsize a lower
725 error = nfs_meta_setsize(vp, ap->a_td, vap->va_size);
727 if (np->n_flag & NMODIFIED) {
728 if (vap->va_size == 0)
729 error = nfs_vinvalbuf(vp, 0, ap->a_td, 1);
731 error = nfs_vinvalbuf(vp, V_SAVE, ap->a_td, 1);
734 vnode_pager_setsize(vp, np->n_size);
738 /* np->n_size has already been set to vap->va_size
739 * in nfs_meta_setsize(). We must set it again since
740 * nfs_loadattrcache() could be called through
741 * nfs_meta_setsize() and could modify np->n_size.
743 np->n_vattr.va_size = np->n_size = vap->va_size;
745 } else if ((vap->va_mtime.tv_sec != VNOVAL ||
746 vap->va_atime.tv_sec != VNOVAL) && (np->n_flag & NMODIFIED) &&
747 vp->v_type == VREG &&
748 (error = nfs_vinvalbuf(vp, V_SAVE, ap->a_td, 1)) == EINTR)
750 error = nfs_setattrrpc(vp, vap, ap->a_cred, ap->a_td);
751 if (error && vap->va_size != VNOVAL) {
752 np->n_size = np->n_vattr.va_size = tsize;
753 vnode_pager_setsize(vp, np->n_size);
759 * Do an nfs setattr rpc.
762 nfs_setattrrpc(struct vnode *vp, struct vattr *vap,
763 struct ucred *cred, struct thread *td)
765 struct nfsv2_sattr *sp;
768 caddr_t bpos, dpos, cp2;
770 int error = 0, wccflag = NFSV3_WCCRATTR;
771 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
772 int v3 = NFS_ISV3(vp);
774 nfsstats.rpccnt[NFSPROC_SETATTR]++;
775 nfsm_reqhead(vp, NFSPROC_SETATTR, NFSX_FH(v3) + NFSX_SATTR(v3));
778 nfsm_v3attrbuild(vap, TRUE);
779 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
782 nfsm_build(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
783 if (vap->va_mode == (mode_t)VNOVAL)
784 sp->sa_mode = nfs_xdrneg1;
786 sp->sa_mode = vtonfsv2_mode(vp->v_type, vap->va_mode);
787 if (vap->va_uid == (uid_t)VNOVAL)
788 sp->sa_uid = nfs_xdrneg1;
790 sp->sa_uid = txdr_unsigned(vap->va_uid);
791 if (vap->va_gid == (gid_t)VNOVAL)
792 sp->sa_gid = nfs_xdrneg1;
794 sp->sa_gid = txdr_unsigned(vap->va_gid);
795 sp->sa_size = txdr_unsigned(vap->va_size);
796 txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
797 txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
799 nfsm_request(vp, NFSPROC_SETATTR, td, cred);
801 nfsm_wcc_data(vp, wccflag);
803 nfsm_loadattr(vp, (struct vattr *)0);
809 * nfs lookup call, one step at a time...
810 * First look in cache
811 * If not found, unlock the directory nfsnode and do the rpc
815 struct vop_lookup_args /* {
816 struct vnodeop_desc *a_desc;
818 struct vnode **a_vpp;
819 struct componentname *a_cnp;
822 struct componentname *cnp = ap->a_cnp;
823 struct vnode *dvp = ap->a_dvp;
824 struct vnode **vpp = ap->a_vpp;
825 int flags = cnp->cn_flags;
830 struct nfsmount *nmp;
831 caddr_t bpos, dpos, cp2;
832 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
836 int lockparent, wantparent, error = 0, attrflag, fhsize;
837 int v3 = NFS_ISV3(dvp);
838 struct thread *td = cnp->cn_td;
841 if ((flags & CNP_ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
842 (cnp->cn_nameiop == NAMEI_DELETE || cnp->cn_nameiop == NAMEI_RENAME))
844 if (dvp->v_type != VDIR)
846 lockparent = flags & CNP_LOCKPARENT;
847 wantparent = flags & (CNP_LOCKPARENT|CNP_WANTPARENT);
848 nmp = VFSTONFS(dvp->v_mount);
850 if ((error = cache_lookup(dvp, NCPNULL, vpp, NCPPNULL, cnp)) && error != ENOENT) {
854 if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td)) != 0) {
862 * See the comment starting `Step through' in ufs/ufs_lookup.c
863 * for an explanation of the locking protocol
868 } else if (flags & CNP_ISDOTDOT) {
869 VOP_UNLOCK(dvp, 0, td);
870 error = vget(newvp, LK_EXCLUSIVE, td);
871 if (!error && lockparent && (flags & CNP_ISLASTCN))
872 error = vn_lock(dvp, LK_EXCLUSIVE, td);
874 error = vget(newvp, LK_EXCLUSIVE, td);
875 if (!lockparent || error || !(flags & CNP_ISLASTCN))
876 VOP_UNLOCK(dvp, 0, td);
879 if (vpid == newvp->v_id) {
880 if (!VOP_GETATTR(newvp, &vattr, td)
881 && vattr.va_ctime.tv_sec == VTONFS(newvp)->n_ctime) {
882 nfsstats.lookupcache_hits++;
883 if (cnp->cn_nameiop != NAMEI_LOOKUP &&
884 (flags & CNP_ISLASTCN))
885 cnp->cn_flags |= CNP_SAVENAME;
891 if (lockparent && dvp != newvp && (flags & CNP_ISLASTCN))
892 VOP_UNLOCK(dvp, 0, td);
894 error = vn_lock(dvp, LK_EXCLUSIVE, td);
901 nfsstats.lookupcache_misses++;
902 nfsstats.rpccnt[NFSPROC_LOOKUP]++;
903 len = cnp->cn_namelen;
904 nfsm_reqhead(dvp, NFSPROC_LOOKUP,
905 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len));
907 nfsm_strtom(cnp->cn_nameptr, len, NFS_MAXNAMLEN);
908 nfsm_request(dvp, NFSPROC_LOOKUP, cnp->cn_td, cnp->cn_cred);
910 nfsm_postop_attr(dvp, attrflag);
914 nfsm_getfh(fhp, fhsize, v3);
917 * Handle RENAME case...
919 if (cnp->cn_nameiop == NAMEI_RENAME && wantparent && (flags & CNP_ISLASTCN)) {
920 if (NFS_CMPFH(np, fhp, fhsize)) {
924 error = nfs_nget(dvp->v_mount, fhp, fhsize, &np);
931 nfsm_postop_attr(newvp, attrflag);
932 nfsm_postop_attr(dvp, attrflag);
934 nfsm_loadattr(newvp, (struct vattr *)0);
937 cnp->cn_flags |= CNP_SAVENAME;
939 VOP_UNLOCK(dvp, 0, td);
943 if (flags & CNP_ISDOTDOT) {
944 VOP_UNLOCK(dvp, 0, td);
945 error = nfs_nget(dvp->v_mount, fhp, fhsize, &np);
947 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
951 if (lockparent && (flags & CNP_ISLASTCN) &&
952 (error = vn_lock(dvp, LK_EXCLUSIVE, td))) {
956 } else if (NFS_CMPFH(np, fhp, fhsize)) {
960 error = nfs_nget(dvp->v_mount, fhp, fhsize, &np);
965 if (!lockparent || !(flags & CNP_ISLASTCN))
966 VOP_UNLOCK(dvp, 0, td);
970 nfsm_postop_attr(newvp, attrflag);
971 nfsm_postop_attr(dvp, attrflag);
973 nfsm_loadattr(newvp, (struct vattr *)0);
974 if (cnp->cn_nameiop != NAMEI_LOOKUP && (flags & CNP_ISLASTCN))
975 cnp->cn_flags |= CNP_SAVENAME;
976 if ((cnp->cn_flags & CNP_MAKEENTRY) &&
977 (cnp->cn_nameiop != NAMEI_DELETE || !(flags & CNP_ISLASTCN))) {
978 np->n_ctime = np->n_vattr.va_ctime.tv_sec;
979 cache_enter(dvp, NCPNULL, newvp, cnp);
984 if (newvp != NULLVP) {
988 if ((cnp->cn_nameiop == NAMEI_CREATE || cnp->cn_nameiop == NAMEI_RENAME) &&
989 (flags & CNP_ISLASTCN) && error == ENOENT) {
991 VOP_UNLOCK(dvp, 0, td);
992 if (dvp->v_mount->mnt_flag & MNT_RDONLY)
997 if (cnp->cn_nameiop != NAMEI_LOOKUP && (flags & CNP_ISLASTCN))
998 cnp->cn_flags |= CNP_SAVENAME;
1005 * Just call nfs_bioread() to do the work.
1009 struct vop_read_args /* {
1013 struct ucred *a_cred;
1016 struct vnode *vp = ap->a_vp;
1018 if (vp->v_type != VREG)
1020 return (nfs_bioread(vp, ap->a_uio, ap->a_ioflag));
1028 struct vop_readlink_args /* {
1031 struct ucred *a_cred;
1034 struct vnode *vp = ap->a_vp;
1036 if (vp->v_type != VLNK)
1038 return (nfs_bioread(vp, ap->a_uio, 0));
1042 * Do a readlink rpc.
1043 * Called by nfs_doio() from below the buffer cache.
1046 nfs_readlinkrpc(struct vnode *vp, struct uio *uiop)
1051 caddr_t bpos, dpos, cp2;
1052 int error = 0, len, attrflag;
1053 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
1054 int v3 = NFS_ISV3(vp);
1056 nfsstats.rpccnt[NFSPROC_READLINK]++;
1057 nfsm_reqhead(vp, NFSPROC_READLINK, NFSX_FH(v3));
1059 nfsm_request(vp, NFSPROC_READLINK, uiop->uio_td, NFSVPCRED(vp));
1061 nfsm_postop_attr(vp, attrflag);
1063 nfsm_strsiz(len, NFS_MAXPATHLEN);
1064 if (len == NFS_MAXPATHLEN) {
1065 struct nfsnode *np = VTONFS(vp);
1066 if (np->n_size && np->n_size < NFS_MAXPATHLEN)
1069 nfsm_mtouio(uiop, len);
1080 nfs_readrpc(struct vnode *vp, struct uio *uiop)
1085 caddr_t bpos, dpos, cp2;
1086 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
1087 struct nfsmount *nmp;
1088 int error = 0, len, retlen, tsiz, eof, attrflag;
1089 int v3 = NFS_ISV3(vp);
1094 nmp = VFSTONFS(vp->v_mount);
1095 tsiz = uiop->uio_resid;
1096 if (uiop->uio_offset + tsiz > nmp->nm_maxfilesize)
1099 nfsstats.rpccnt[NFSPROC_READ]++;
1100 len = (tsiz > nmp->nm_rsize) ? nmp->nm_rsize : tsiz;
1101 nfsm_reqhead(vp, NFSPROC_READ, NFSX_FH(v3) + NFSX_UNSIGNED * 3);
1103 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED * 3);
1105 txdr_hyper(uiop->uio_offset, tl);
1106 *(tl + 2) = txdr_unsigned(len);
1108 *tl++ = txdr_unsigned(uiop->uio_offset);
1109 *tl++ = txdr_unsigned(len);
1112 nfsm_request(vp, NFSPROC_READ, uiop->uio_td, NFSVPCRED(vp));
1114 nfsm_postop_attr(vp, attrflag);
1119 nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1120 eof = fxdr_unsigned(int, *(tl + 1));
1122 nfsm_loadattr(vp, (struct vattr *)0);
1123 nfsm_strsiz(retlen, nmp->nm_rsize);
1124 nfsm_mtouio(uiop, retlen);
1128 if (eof || retlen == 0) {
1131 } else if (retlen < len) {
1143 nfs_writerpc(vp, uiop, iomode, must_commit)
1146 int *iomode, *must_commit;
1150 int32_t t1, t2, backup;
1151 caddr_t bpos, dpos, cp2;
1152 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
1153 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
1154 int error = 0, len, tsiz, wccflag = NFSV3_WCCRATTR, rlen, commit;
1155 int v3 = NFS_ISV3(vp), committed = NFSV3WRITE_FILESYNC;
1158 if (uiop->uio_iovcnt != 1)
1159 panic("nfs: writerpc iovcnt > 1");
1162 tsiz = uiop->uio_resid;
1163 if (uiop->uio_offset + tsiz > nmp->nm_maxfilesize)
1166 nfsstats.rpccnt[NFSPROC_WRITE]++;
1167 len = (tsiz > nmp->nm_wsize) ? nmp->nm_wsize : tsiz;
1168 nfsm_reqhead(vp, NFSPROC_WRITE,
1169 NFSX_FH(v3) + 5 * NFSX_UNSIGNED + nfsm_rndup(len));
1172 nfsm_build(tl, u_int32_t *, 5 * NFSX_UNSIGNED);
1173 txdr_hyper(uiop->uio_offset, tl);
1175 *tl++ = txdr_unsigned(len);
1176 *tl++ = txdr_unsigned(*iomode);
1177 *tl = txdr_unsigned(len);
1181 nfsm_build(tl, u_int32_t *, 4 * NFSX_UNSIGNED);
1182 /* Set both "begin" and "current" to non-garbage. */
1183 x = txdr_unsigned((u_int32_t)uiop->uio_offset);
1184 *tl++ = x; /* "begin offset" */
1185 *tl++ = x; /* "current offset" */
1186 x = txdr_unsigned(len);
1187 *tl++ = x; /* total to this offset */
1188 *tl = x; /* size of this write */
1190 nfsm_uiotom(uiop, len);
1191 nfsm_request(vp, NFSPROC_WRITE, uiop->uio_td, NFSVPCRED(vp));
1193 wccflag = NFSV3_WCCCHK;
1194 nfsm_wcc_data(vp, wccflag);
1196 nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED
1197 + NFSX_V3WRITEVERF);
1198 rlen = fxdr_unsigned(int, *tl++);
1203 } else if (rlen < len) {
1204 backup = len - rlen;
1205 uiop->uio_iov->iov_base -= backup;
1206 uiop->uio_iov->iov_len += backup;
1207 uiop->uio_offset -= backup;
1208 uiop->uio_resid += backup;
1211 commit = fxdr_unsigned(int, *tl++);
1214 * Return the lowest committment level
1215 * obtained by any of the RPCs.
1217 if (committed == NFSV3WRITE_FILESYNC)
1219 else if (committed == NFSV3WRITE_DATASYNC &&
1220 commit == NFSV3WRITE_UNSTABLE)
1222 if ((nmp->nm_state & NFSSTA_HASWRITEVERF) == 0){
1223 bcopy((caddr_t)tl, (caddr_t)nmp->nm_verf,
1225 nmp->nm_state |= NFSSTA_HASWRITEVERF;
1226 } else if (bcmp((caddr_t)tl,
1227 (caddr_t)nmp->nm_verf, NFSX_V3WRITEVERF)) {
1229 bcopy((caddr_t)tl, (caddr_t)nmp->nm_verf,
1234 nfsm_loadattr(vp, (struct vattr *)0);
1236 VTONFS(vp)->n_mtime = VTONFS(vp)->n_vattr.va_mtime.tv_sec;
1243 if (vp->v_mount->mnt_flag & MNT_ASYNC)
1244 committed = NFSV3WRITE_FILESYNC;
1245 *iomode = committed;
1247 uiop->uio_resid = tsiz;
1253 * For NFS v2 this is a kludge. Use a create rpc but with the IFMT bits of the
1254 * mode set to specify the file type and the size field for rdev.
1257 nfs_mknodrpc(dvp, vpp, cnp, vap)
1260 struct componentname *cnp;
1263 struct nfsv2_sattr *sp;
1267 struct vnode *newvp = (struct vnode *)0;
1268 struct nfsnode *np = (struct nfsnode *)0;
1272 int error = 0, wccflag = NFSV3_WCCRATTR, gotvp = 0;
1273 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
1275 int v3 = NFS_ISV3(dvp);
1277 if (vap->va_type == VCHR || vap->va_type == VBLK)
1278 rdev = txdr_unsigned(vap->va_rdev);
1279 else if (vap->va_type == VFIFO || vap->va_type == VSOCK)
1282 return (EOPNOTSUPP);
1284 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_td)) != 0) {
1287 nfsstats.rpccnt[NFSPROC_MKNOD]++;
1288 nfsm_reqhead(dvp, NFSPROC_MKNOD, NFSX_FH(v3) + 4 * NFSX_UNSIGNED +
1289 + nfsm_rndup(cnp->cn_namelen) + NFSX_SATTR(v3));
1290 nfsm_fhtom(dvp, v3);
1291 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
1293 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
1294 *tl++ = vtonfsv3_type(vap->va_type);
1295 nfsm_v3attrbuild(vap, FALSE);
1296 if (vap->va_type == VCHR || vap->va_type == VBLK) {
1297 nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1298 *tl++ = txdr_unsigned(umajor(vap->va_rdev));
1299 *tl = txdr_unsigned(uminor(vap->va_rdev));
1302 nfsm_build(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
1303 sp->sa_mode = vtonfsv2_mode(vap->va_type, vap->va_mode);
1304 sp->sa_uid = nfs_xdrneg1;
1305 sp->sa_gid = nfs_xdrneg1;
1307 txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
1308 txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
1310 nfsm_request(dvp, NFSPROC_MKNOD, cnp->cn_td, cnp->cn_cred);
1312 nfsm_mtofh(dvp, newvp, v3, gotvp);
1316 newvp = (struct vnode *)0;
1318 error = nfs_lookitup(dvp, cnp->cn_nameptr,
1319 cnp->cn_namelen, cnp->cn_cred, cnp->cn_td, &np);
1325 nfsm_wcc_data(dvp, wccflag);
1331 if (cnp->cn_flags & CNP_MAKEENTRY)
1332 cache_enter(dvp, NCPNULL, newvp, cnp);
1335 VTONFS(dvp)->n_flag |= NMODIFIED;
1337 VTONFS(dvp)->n_attrstamp = 0;
1343 * just call nfs_mknodrpc() to do the work.
1348 struct vop_mknod_args /* {
1349 struct vnode *a_dvp;
1350 struct vnode **a_vpp;
1351 struct componentname *a_cnp;
1352 struct vattr *a_vap;
1355 return nfs_mknodrpc(ap->a_dvp, ap->a_vpp, ap->a_cnp, ap->a_vap);
1358 static u_long create_verf;
1360 * nfs file create call
1364 struct vop_create_args /* {
1365 struct vnode *a_dvp;
1366 struct vnode **a_vpp;
1367 struct componentname *a_cnp;
1368 struct vattr *a_vap;
1371 struct vnode *dvp = ap->a_dvp;
1372 struct vattr *vap = ap->a_vap;
1373 struct componentname *cnp = ap->a_cnp;
1374 struct nfsv2_sattr *sp;
1378 struct nfsnode *np = (struct nfsnode *)0;
1379 struct vnode *newvp = (struct vnode *)0;
1380 caddr_t bpos, dpos, cp2;
1381 int error = 0, wccflag = NFSV3_WCCRATTR, gotvp = 0, fmode = 0;
1382 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
1384 int v3 = NFS_ISV3(dvp);
1387 * Oops, not for me..
1389 if (vap->va_type == VSOCK)
1390 return (nfs_mknodrpc(dvp, ap->a_vpp, cnp, vap));
1392 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_td)) != 0) {
1395 if (vap->va_vaflags & VA_EXCLUSIVE)
1398 nfsstats.rpccnt[NFSPROC_CREATE]++;
1399 nfsm_reqhead(dvp, NFSPROC_CREATE, NFSX_FH(v3) + 2 * NFSX_UNSIGNED +
1400 nfsm_rndup(cnp->cn_namelen) + NFSX_SATTR(v3));
1401 nfsm_fhtom(dvp, v3);
1402 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
1404 nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
1405 if (fmode & O_EXCL) {
1406 *tl = txdr_unsigned(NFSV3CREATE_EXCLUSIVE);
1407 nfsm_build(tl, u_int32_t *, NFSX_V3CREATEVERF);
1409 if (!TAILQ_EMPTY(&in_ifaddrhead))
1410 *tl++ = IA_SIN(in_ifaddrhead.tqh_first)->sin_addr.s_addr;
1413 *tl++ = create_verf;
1414 *tl = ++create_verf;
1416 *tl = txdr_unsigned(NFSV3CREATE_UNCHECKED);
1417 nfsm_v3attrbuild(vap, FALSE);
1420 nfsm_build(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
1421 sp->sa_mode = vtonfsv2_mode(vap->va_type, vap->va_mode);
1422 sp->sa_uid = nfs_xdrneg1;
1423 sp->sa_gid = nfs_xdrneg1;
1425 txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
1426 txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
1428 nfsm_request(dvp, NFSPROC_CREATE, cnp->cn_td, cnp->cn_cred);
1430 nfsm_mtofh(dvp, newvp, v3, gotvp);
1434 newvp = (struct vnode *)0;
1436 error = nfs_lookitup(dvp, cnp->cn_nameptr,
1437 cnp->cn_namelen, cnp->cn_cred, cnp->cn_td, &np);
1443 nfsm_wcc_data(dvp, wccflag);
1446 if (v3 && (fmode & O_EXCL) && error == NFSERR_NOTSUPP) {
1452 } else if (v3 && (fmode & O_EXCL)) {
1454 * We are normally called with only a partially initialized
1455 * VAP. Since the NFSv3 spec says that server may use the
1456 * file attributes to store the verifier, the spec requires
1457 * us to do a SETATTR RPC. FreeBSD servers store the verifier
1458 * in atime, but we can't really assume that all servers will
1459 * so we ensure that our SETATTR sets both atime and mtime.
1461 if (vap->va_mtime.tv_sec == VNOVAL)
1462 vfs_timestamp(&vap->va_mtime);
1463 if (vap->va_atime.tv_sec == VNOVAL)
1464 vap->va_atime = vap->va_mtime;
1465 error = nfs_setattrrpc(newvp, vap, cnp->cn_cred, cnp->cn_td);
1468 if (cnp->cn_flags & CNP_MAKEENTRY)
1469 cache_enter(dvp, NCPNULL, newvp, cnp);
1472 VTONFS(dvp)->n_flag |= NMODIFIED;
1474 VTONFS(dvp)->n_attrstamp = 0;
1479 * nfs file remove call
1480 * To try and make nfs semantics closer to ufs semantics, a file that has
1481 * other processes using the vnode is renamed instead of removed and then
1482 * removed later on the last close.
1483 * - If v_usecount > 1
1484 * If a rename is not already in the works
1485 * call nfs_sillyrename() to set it up
1491 struct vop_remove_args /* {
1492 struct vnodeop_desc *a_desc;
1493 struct vnode * a_dvp;
1494 struct vnode * a_vp;
1495 struct componentname * a_cnp;
1498 struct vnode *vp = ap->a_vp;
1499 struct vnode *dvp = ap->a_dvp;
1500 struct componentname *cnp = ap->a_cnp;
1501 struct nfsnode *np = VTONFS(vp);
1506 if ((cnp->cn_flags & CNP_HASBUF) == 0)
1507 panic("nfs_remove: no name");
1508 if (vp->v_usecount < 1)
1509 panic("nfs_remove: bad v_usecount");
1511 if (vp->v_type == VDIR)
1513 else if (vp->v_usecount == 1 || (np->n_sillyrename &&
1514 VOP_GETATTR(vp, &vattr, cnp->cn_td) == 0 &&
1515 vattr.va_nlink > 1)) {
1517 * Purge the name cache so that the chance of a lookup for
1518 * the name succeeding while the remove is in progress is
1519 * minimized. Without node locking it can still happen, such
1520 * that an I/O op returns ESTALE, but since you get this if
1521 * another host removes the file..
1525 * throw away biocache buffers, mainly to avoid
1526 * unnecessary delayed writes later.
1528 error = nfs_vinvalbuf(vp, 0, cnp->cn_td, 1);
1531 error = nfs_removerpc(dvp, cnp->cn_nameptr,
1532 cnp->cn_namelen, cnp->cn_cred, cnp->cn_td);
1534 * Kludge City: If the first reply to the remove rpc is lost..
1535 * the reply to the retransmitted request will be ENOENT
1536 * since the file was in fact removed
1537 * Therefore, we cheat and return success.
1539 if (error == ENOENT)
1541 } else if (!np->n_sillyrename)
1542 error = nfs_sillyrename(dvp, vp, cnp);
1543 np->n_attrstamp = 0;
1548 * nfs file remove rpc called from nfs_inactive
1551 nfs_removeit(struct sillyrename *sp)
1554 return (nfs_removerpc(sp->s_dvp, sp->s_name, sp->s_namlen,
1559 * Nfs remove rpc, called from nfs_remove() and nfs_removeit().
1562 nfs_removerpc(dvp, name, namelen, cred, td)
1572 caddr_t bpos, dpos, cp2;
1573 int error = 0, wccflag = NFSV3_WCCRATTR;
1574 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
1575 int v3 = NFS_ISV3(dvp);
1577 nfsstats.rpccnt[NFSPROC_REMOVE]++;
1578 nfsm_reqhead(dvp, NFSPROC_REMOVE,
1579 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(namelen));
1580 nfsm_fhtom(dvp, v3);
1581 nfsm_strtom(name, namelen, NFS_MAXNAMLEN);
1582 nfsm_request(dvp, NFSPROC_REMOVE, td, cred);
1584 nfsm_wcc_data(dvp, wccflag);
1586 VTONFS(dvp)->n_flag |= NMODIFIED;
1588 VTONFS(dvp)->n_attrstamp = 0;
1593 * nfs file rename call
1597 struct vop_rename_args /* {
1598 struct vnode *a_fdvp;
1599 struct vnode *a_fvp;
1600 struct componentname *a_fcnp;
1601 struct vnode *a_tdvp;
1602 struct vnode *a_tvp;
1603 struct componentname *a_tcnp;
1606 struct vnode *fvp = ap->a_fvp;
1607 struct vnode *tvp = ap->a_tvp;
1608 struct vnode *fdvp = ap->a_fdvp;
1609 struct vnode *tdvp = ap->a_tdvp;
1610 struct componentname *tcnp = ap->a_tcnp;
1611 struct componentname *fcnp = ap->a_fcnp;
1615 if ((tcnp->cn_flags & CNP_HASBUF) == 0 ||
1616 (fcnp->cn_flags & CNP_HASBUF) == 0)
1617 panic("nfs_rename: no name");
1619 /* Check for cross-device rename */
1620 if ((fvp->v_mount != tdvp->v_mount) ||
1621 (tvp && (fvp->v_mount != tvp->v_mount))) {
1627 * We have to flush B_DELWRI data prior to renaming
1628 * the file. If we don't, the delayed-write buffers
1629 * can be flushed out later after the file has gone stale
1630 * under NFSV3. NFSV2 does not have this problem because
1631 * ( as far as I can tell ) it flushes dirty buffers more
1635 VOP_FSYNC(fvp, MNT_WAIT, fcnp->cn_td);
1637 VOP_FSYNC(tvp, MNT_WAIT, tcnp->cn_td);
1640 * If the tvp exists and is in use, sillyrename it before doing the
1641 * rename of the new file over it.
1642 * XXX Can't sillyrename a directory.
1644 if (tvp && tvp->v_usecount > 1 && !VTONFS(tvp)->n_sillyrename &&
1645 tvp->v_type != VDIR && !nfs_sillyrename(tdvp, tvp, tcnp)) {
1650 error = nfs_renamerpc(fdvp, fcnp->cn_nameptr, fcnp->cn_namelen,
1651 tdvp, tcnp->cn_nameptr, tcnp->cn_namelen, tcnp->cn_cred,
1654 if (fvp->v_type == VDIR) {
1655 if (tvp != NULL && tvp->v_type == VDIR)
1670 * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry.
1672 if (error == ENOENT)
1678 * nfs file rename rpc called from nfs_remove() above
1681 nfs_renameit(sdvp, scnp, sp)
1683 struct componentname *scnp;
1684 struct sillyrename *sp;
1686 return (nfs_renamerpc(sdvp, scnp->cn_nameptr, scnp->cn_namelen,
1687 sdvp, sp->s_name, sp->s_namlen, scnp->cn_cred, scnp->cn_td));
1691 * Do an nfs rename rpc. Called from nfs_rename() and nfs_renameit().
1694 nfs_renamerpc(fdvp, fnameptr, fnamelen, tdvp, tnameptr, tnamelen, cred, td)
1696 const char *fnameptr;
1699 const char *tnameptr;
1707 caddr_t bpos, dpos, cp2;
1708 int error = 0, fwccflag = NFSV3_WCCRATTR, twccflag = NFSV3_WCCRATTR;
1709 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
1710 int v3 = NFS_ISV3(fdvp);
1712 nfsstats.rpccnt[NFSPROC_RENAME]++;
1713 nfsm_reqhead(fdvp, NFSPROC_RENAME,
1714 (NFSX_FH(v3) + NFSX_UNSIGNED)*2 + nfsm_rndup(fnamelen) +
1715 nfsm_rndup(tnamelen));
1716 nfsm_fhtom(fdvp, v3);
1717 nfsm_strtom(fnameptr, fnamelen, NFS_MAXNAMLEN);
1718 nfsm_fhtom(tdvp, v3);
1719 nfsm_strtom(tnameptr, tnamelen, NFS_MAXNAMLEN);
1720 nfsm_request(fdvp, NFSPROC_RENAME, td, cred);
1722 nfsm_wcc_data(fdvp, fwccflag);
1723 nfsm_wcc_data(tdvp, twccflag);
1726 VTONFS(fdvp)->n_flag |= NMODIFIED;
1727 VTONFS(tdvp)->n_flag |= NMODIFIED;
1729 VTONFS(fdvp)->n_attrstamp = 0;
1731 VTONFS(tdvp)->n_attrstamp = 0;
1736 * nfs hard link create call
1740 struct vop_link_args /* {
1741 struct vnode *a_tdvp;
1743 struct componentname *a_cnp;
1746 struct vnode *vp = ap->a_vp;
1747 struct vnode *tdvp = ap->a_tdvp;
1748 struct componentname *cnp = ap->a_cnp;
1752 caddr_t bpos, dpos, cp2;
1753 int error = 0, wccflag = NFSV3_WCCRATTR, attrflag = 0;
1754 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
1757 if (vp->v_mount != tdvp->v_mount) {
1762 * Push all writes to the server, so that the attribute cache
1763 * doesn't get "out of sync" with the server.
1764 * XXX There should be a better way!
1766 VOP_FSYNC(vp, MNT_WAIT, cnp->cn_td);
1769 nfsstats.rpccnt[NFSPROC_LINK]++;
1770 nfsm_reqhead(vp, NFSPROC_LINK,
1771 NFSX_FH(v3)*2 + NFSX_UNSIGNED + nfsm_rndup(cnp->cn_namelen));
1773 nfsm_fhtom(tdvp, v3);
1774 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
1775 nfsm_request(vp, NFSPROC_LINK, cnp->cn_td, cnp->cn_cred);
1777 nfsm_postop_attr(vp, attrflag);
1778 nfsm_wcc_data(tdvp, wccflag);
1781 VTONFS(tdvp)->n_flag |= NMODIFIED;
1783 VTONFS(vp)->n_attrstamp = 0;
1785 VTONFS(tdvp)->n_attrstamp = 0;
1787 * Kludge: Map EEXIST => 0 assuming that it is a reply to a retry.
1789 if (error == EEXIST)
1795 * nfs symbolic link create call
1799 struct vop_symlink_args /* {
1800 struct vnode *a_dvp;
1801 struct vnode **a_vpp;
1802 struct componentname *a_cnp;
1803 struct vattr *a_vap;
1807 struct vnode *dvp = ap->a_dvp;
1808 struct vattr *vap = ap->a_vap;
1809 struct componentname *cnp = ap->a_cnp;
1810 struct nfsv2_sattr *sp;
1814 caddr_t bpos, dpos, cp2;
1815 int slen, error = 0, wccflag = NFSV3_WCCRATTR, gotvp;
1816 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
1817 struct vnode *newvp = (struct vnode *)0;
1818 int v3 = NFS_ISV3(dvp);
1820 nfsstats.rpccnt[NFSPROC_SYMLINK]++;
1821 slen = strlen(ap->a_target);
1822 nfsm_reqhead(dvp, NFSPROC_SYMLINK, NFSX_FH(v3) + 2*NFSX_UNSIGNED +
1823 nfsm_rndup(cnp->cn_namelen) + nfsm_rndup(slen) + NFSX_SATTR(v3));
1824 nfsm_fhtom(dvp, v3);
1825 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
1827 nfsm_v3attrbuild(vap, FALSE);
1829 nfsm_strtom(ap->a_target, slen, NFS_MAXPATHLEN);
1831 nfsm_build(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
1832 sp->sa_mode = vtonfsv2_mode(VLNK, vap->va_mode);
1833 sp->sa_uid = nfs_xdrneg1;
1834 sp->sa_gid = nfs_xdrneg1;
1835 sp->sa_size = nfs_xdrneg1;
1836 txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
1837 txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
1841 * Issue the NFS request and get the rpc response.
1843 * Only NFSv3 responses returning an error of 0 actually return
1844 * a file handle that can be converted into newvp without having
1845 * to do an extra lookup rpc.
1847 nfsm_request(dvp, NFSPROC_SYMLINK, cnp->cn_td, cnp->cn_cred);
1850 nfsm_mtofh(dvp, newvp, v3, gotvp);
1851 nfsm_wcc_data(dvp, wccflag);
1855 * out code jumps -> here, mrep is also freed.
1861 * If we get an EEXIST error, silently convert it to no-error
1862 * in case of an NFS retry.
1864 if (error == EEXIST)
1868 * If we do not have (or no longer have) an error, and we could
1869 * not extract the newvp from the response due to the request being
1870 * NFSv2 or the error being EEXIST. We have to do a lookup in order
1871 * to obtain a newvp to return.
1873 if (error == 0 && newvp == NULL) {
1874 struct nfsnode *np = NULL;
1876 error = nfs_lookitup(dvp, cnp->cn_nameptr, cnp->cn_namelen,
1877 cnp->cn_cred, cnp->cn_td, &np);
1887 VTONFS(dvp)->n_flag |= NMODIFIED;
1889 VTONFS(dvp)->n_attrstamp = 0;
1898 struct vop_mkdir_args /* {
1899 struct vnode *a_dvp;
1900 struct vnode **a_vpp;
1901 struct componentname *a_cnp;
1902 struct vattr *a_vap;
1905 struct vnode *dvp = ap->a_dvp;
1906 struct vattr *vap = ap->a_vap;
1907 struct componentname *cnp = ap->a_cnp;
1908 struct nfsv2_sattr *sp;
1913 struct nfsnode *np = (struct nfsnode *)0;
1914 struct vnode *newvp = (struct vnode *)0;
1915 caddr_t bpos, dpos, cp2;
1916 int error = 0, wccflag = NFSV3_WCCRATTR;
1918 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
1920 int v3 = NFS_ISV3(dvp);
1922 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_td)) != 0) {
1925 len = cnp->cn_namelen;
1926 nfsstats.rpccnt[NFSPROC_MKDIR]++;
1927 nfsm_reqhead(dvp, NFSPROC_MKDIR,
1928 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len) + NFSX_SATTR(v3));
1929 nfsm_fhtom(dvp, v3);
1930 nfsm_strtom(cnp->cn_nameptr, len, NFS_MAXNAMLEN);
1932 nfsm_v3attrbuild(vap, FALSE);
1934 nfsm_build(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
1935 sp->sa_mode = vtonfsv2_mode(VDIR, vap->va_mode);
1936 sp->sa_uid = nfs_xdrneg1;
1937 sp->sa_gid = nfs_xdrneg1;
1938 sp->sa_size = nfs_xdrneg1;
1939 txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
1940 txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
1942 nfsm_request(dvp, NFSPROC_MKDIR, cnp->cn_td, cnp->cn_cred);
1944 nfsm_mtofh(dvp, newvp, v3, gotvp);
1946 nfsm_wcc_data(dvp, wccflag);
1948 VTONFS(dvp)->n_flag |= NMODIFIED;
1950 VTONFS(dvp)->n_attrstamp = 0;
1952 * Kludge: Map EEXIST => 0 assuming that you have a reply to a retry
1953 * if we can succeed in looking up the directory.
1955 if (error == EEXIST || (!error && !gotvp)) {
1958 newvp = (struct vnode *)0;
1960 error = nfs_lookitup(dvp, cnp->cn_nameptr, len, cnp->cn_cred,
1964 if (newvp->v_type != VDIR)
1977 * nfs remove directory call
1981 struct vop_rmdir_args /* {
1982 struct vnode *a_dvp;
1984 struct componentname *a_cnp;
1987 struct vnode *vp = ap->a_vp;
1988 struct vnode *dvp = ap->a_dvp;
1989 struct componentname *cnp = ap->a_cnp;
1993 caddr_t bpos, dpos, cp2;
1994 int error = 0, wccflag = NFSV3_WCCRATTR;
1995 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
1996 int v3 = NFS_ISV3(dvp);
2000 nfsstats.rpccnt[NFSPROC_RMDIR]++;
2001 nfsm_reqhead(dvp, NFSPROC_RMDIR,
2002 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(cnp->cn_namelen));
2003 nfsm_fhtom(dvp, v3);
2004 nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
2005 nfsm_request(dvp, NFSPROC_RMDIR, cnp->cn_td, cnp->cn_cred);
2007 nfsm_wcc_data(dvp, wccflag);
2009 VTONFS(dvp)->n_flag |= NMODIFIED;
2011 VTONFS(dvp)->n_attrstamp = 0;
2015 * Kludge: Map ENOENT => 0 assuming that you have a reply to a retry.
2017 if (error == ENOENT)
2027 struct vop_readdir_args /* {
2030 struct ucred *a_cred;
2033 struct vnode *vp = ap->a_vp;
2034 struct nfsnode *np = VTONFS(vp);
2035 struct uio *uio = ap->a_uio;
2039 if (vp->v_type != VDIR)
2042 * First, check for hit on the EOF offset cache
2044 if (np->n_direofoffset > 0 && uio->uio_offset >= np->n_direofoffset &&
2045 (np->n_flag & NMODIFIED) == 0) {
2046 if (VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NQNFS) {
2047 if (NQNFS_CKCACHABLE(vp, ND_READ)) {
2048 nfsstats.direofcache_hits++;
2051 } else if (VOP_GETATTR(vp, &vattr, uio->uio_td) == 0 &&
2052 np->n_mtime == vattr.va_mtime.tv_sec) {
2053 nfsstats.direofcache_hits++;
2059 * Call nfs_bioread() to do the real work.
2061 tresid = uio->uio_resid;
2062 error = nfs_bioread(vp, uio, 0);
2064 if (!error && uio->uio_resid == tresid)
2065 nfsstats.direofcache_misses++;
2071 * Called from below the buffer cache by nfs_doio().
2074 nfs_readdirrpc(struct vnode *vp, struct uio *uiop)
2077 struct dirent *dp = NULL;
2082 caddr_t bpos, dpos, cp2;
2083 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
2085 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2086 struct nfsnode *dnp = VTONFS(vp);
2088 int error = 0, tlen, more_dirs = 1, blksiz = 0, bigenough = 1;
2090 int v3 = NFS_ISV3(vp);
2093 if (uiop->uio_iovcnt != 1 || (uiop->uio_offset & (DIRBLKSIZ - 1)) ||
2094 (uiop->uio_resid & (DIRBLKSIZ - 1)))
2095 panic("nfs readdirrpc bad uio");
2099 * If there is no cookie, assume directory was stale.
2101 cookiep = nfs_getcookie(dnp, uiop->uio_offset, 0);
2105 return (NFSERR_BAD_COOKIE);
2107 * Loop around doing readdir rpc's of size nm_readdirsize
2108 * truncated to a multiple of DIRBLKSIZ.
2109 * The stopping criteria is EOF or buffer full.
2111 while (more_dirs && bigenough) {
2112 nfsstats.rpccnt[NFSPROC_READDIR]++;
2113 nfsm_reqhead(vp, NFSPROC_READDIR, NFSX_FH(v3) +
2117 nfsm_build(tl, u_int32_t *, 5 * NFSX_UNSIGNED);
2118 *tl++ = cookie.nfsuquad[0];
2119 *tl++ = cookie.nfsuquad[1];
2120 *tl++ = dnp->n_cookieverf.nfsuquad[0];
2121 *tl++ = dnp->n_cookieverf.nfsuquad[1];
2123 nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2124 *tl++ = cookie.nfsuquad[0];
2126 *tl = txdr_unsigned(nmp->nm_readdirsize);
2127 nfsm_request(vp, NFSPROC_READDIR, uiop->uio_td, NFSVPCRED(vp));
2129 nfsm_postop_attr(vp, attrflag);
2131 nfsm_dissect(tl, u_int32_t *,
2133 dnp->n_cookieverf.nfsuquad[0] = *tl++;
2134 dnp->n_cookieverf.nfsuquad[1] = *tl;
2140 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
2141 more_dirs = fxdr_unsigned(int, *tl);
2143 /* loop thru the dir entries, doctoring them to 4bsd form */
2144 while (more_dirs && bigenough) {
2146 nfsm_dissect(tl, u_int32_t *,
2148 fileno = fxdr_hyper(tl);
2149 len = fxdr_unsigned(int, *(tl + 2));
2151 nfsm_dissect(tl, u_int32_t *,
2153 fileno = fxdr_unsigned(u_quad_t, *tl++);
2154 len = fxdr_unsigned(int, *tl);
2156 if (len <= 0 || len > NFS_MAXNAMLEN) {
2161 tlen = nfsm_rndup(len);
2163 tlen += 4; /* To ensure null termination */
2164 left = DIRBLKSIZ - blksiz;
2165 if ((tlen + DIRHDSIZ) > left) {
2166 dp->d_reclen += left;
2167 uiop->uio_iov->iov_base += left;
2168 uiop->uio_iov->iov_len -= left;
2169 uiop->uio_offset += left;
2170 uiop->uio_resid -= left;
2173 if ((tlen + DIRHDSIZ) > uiop->uio_resid)
2176 dp = (struct dirent *)uiop->uio_iov->iov_base;
2177 dp->d_fileno = (int)fileno;
2179 dp->d_reclen = tlen + DIRHDSIZ;
2180 dp->d_type = DT_UNKNOWN;
2181 blksiz += dp->d_reclen;
2182 if (blksiz == DIRBLKSIZ)
2184 uiop->uio_offset += DIRHDSIZ;
2185 uiop->uio_resid -= DIRHDSIZ;
2186 uiop->uio_iov->iov_base += DIRHDSIZ;
2187 uiop->uio_iov->iov_len -= DIRHDSIZ;
2188 nfsm_mtouio(uiop, len);
2189 cp = uiop->uio_iov->iov_base;
2191 *cp = '\0'; /* null terminate */
2192 uiop->uio_iov->iov_base += tlen;
2193 uiop->uio_iov->iov_len -= tlen;
2194 uiop->uio_offset += tlen;
2195 uiop->uio_resid -= tlen;
2197 nfsm_adv(nfsm_rndup(len));
2199 nfsm_dissect(tl, u_int32_t *,
2202 nfsm_dissect(tl, u_int32_t *,
2206 cookie.nfsuquad[0] = *tl++;
2208 cookie.nfsuquad[1] = *tl++;
2213 more_dirs = fxdr_unsigned(int, *tl);
2216 * If at end of rpc data, get the eof boolean
2219 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
2220 more_dirs = (fxdr_unsigned(int, *tl) == 0);
2225 * Fill last record, iff any, out to a multiple of DIRBLKSIZ
2226 * by increasing d_reclen for the last record.
2229 left = DIRBLKSIZ - blksiz;
2230 dp->d_reclen += left;
2231 uiop->uio_iov->iov_base += left;
2232 uiop->uio_iov->iov_len -= left;
2233 uiop->uio_offset += left;
2234 uiop->uio_resid -= left;
2238 * We are now either at the end of the directory or have filled the
2242 dnp->n_direofoffset = uiop->uio_offset;
2244 if (uiop->uio_resid > 0)
2245 printf("EEK! readdirrpc resid > 0\n");
2246 cookiep = nfs_getcookie(dnp, uiop->uio_offset, 1);
2254 * NFS V3 readdir plus RPC. Used in place of nfs_readdirrpc().
2257 nfs_readdirplusrpc(struct vnode *vp, struct uio *uiop)
2264 struct vnode *newvp;
2266 caddr_t bpos, dpos, cp2, dpossav1, dpossav2;
2267 struct mbuf *mreq, *mrep, *md, *mb, *mb2, *mdsav1, *mdsav2;
2268 struct nameidata nami, *ndp = &nami;
2269 struct componentname *cnp = &ndp->ni_cnd;
2271 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2272 struct nfsnode *dnp = VTONFS(vp), *np;
2275 int error = 0, tlen, more_dirs = 1, blksiz = 0, doit, bigenough = 1, i;
2276 int attrflag, fhsize;
2279 dp = (struct dirent *)0;
2282 if (uiop->uio_iovcnt != 1 || (uiop->uio_offset & (DIRBLKSIZ - 1)) ||
2283 (uiop->uio_resid & (DIRBLKSIZ - 1)))
2284 panic("nfs readdirplusrpc bad uio");
2290 * If there is no cookie, assume directory was stale.
2292 cookiep = nfs_getcookie(dnp, uiop->uio_offset, 0);
2296 return (NFSERR_BAD_COOKIE);
2298 * Loop around doing readdir rpc's of size nm_readdirsize
2299 * truncated to a multiple of DIRBLKSIZ.
2300 * The stopping criteria is EOF or buffer full.
2302 while (more_dirs && bigenough) {
2303 nfsstats.rpccnt[NFSPROC_READDIRPLUS]++;
2304 nfsm_reqhead(vp, NFSPROC_READDIRPLUS,
2305 NFSX_FH(1) + 6 * NFSX_UNSIGNED);
2307 nfsm_build(tl, u_int32_t *, 6 * NFSX_UNSIGNED);
2308 *tl++ = cookie.nfsuquad[0];
2309 *tl++ = cookie.nfsuquad[1];
2310 *tl++ = dnp->n_cookieverf.nfsuquad[0];
2311 *tl++ = dnp->n_cookieverf.nfsuquad[1];
2312 *tl++ = txdr_unsigned(nmp->nm_readdirsize);
2313 *tl = txdr_unsigned(nmp->nm_rsize);
2314 nfsm_request(vp, NFSPROC_READDIRPLUS, uiop->uio_td, NFSVPCRED(vp));
2315 nfsm_postop_attr(vp, attrflag);
2320 nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
2321 dnp->n_cookieverf.nfsuquad[0] = *tl++;
2322 dnp->n_cookieverf.nfsuquad[1] = *tl++;
2323 more_dirs = fxdr_unsigned(int, *tl);
2325 /* loop thru the dir entries, doctoring them to 4bsd form */
2326 while (more_dirs && bigenough) {
2327 nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
2328 fileno = fxdr_hyper(tl);
2329 len = fxdr_unsigned(int, *(tl + 2));
2330 if (len <= 0 || len > NFS_MAXNAMLEN) {
2335 tlen = nfsm_rndup(len);
2337 tlen += 4; /* To ensure null termination*/
2338 left = DIRBLKSIZ - blksiz;
2339 if ((tlen + DIRHDSIZ) > left) {
2340 dp->d_reclen += left;
2341 uiop->uio_iov->iov_base += left;
2342 uiop->uio_iov->iov_len -= left;
2343 uiop->uio_offset += left;
2344 uiop->uio_resid -= left;
2347 if ((tlen + DIRHDSIZ) > uiop->uio_resid)
2350 dp = (struct dirent *)uiop->uio_iov->iov_base;
2351 dp->d_fileno = (int)fileno;
2353 dp->d_reclen = tlen + DIRHDSIZ;
2354 dp->d_type = DT_UNKNOWN;
2355 blksiz += dp->d_reclen;
2356 if (blksiz == DIRBLKSIZ)
2358 uiop->uio_offset += DIRHDSIZ;
2359 uiop->uio_resid -= DIRHDSIZ;
2360 uiop->uio_iov->iov_base += DIRHDSIZ;
2361 uiop->uio_iov->iov_len -= DIRHDSIZ;
2362 cnp->cn_nameptr = uiop->uio_iov->iov_base;
2363 cnp->cn_namelen = len;
2364 nfsm_mtouio(uiop, len);
2365 cp = uiop->uio_iov->iov_base;
2368 uiop->uio_iov->iov_base += tlen;
2369 uiop->uio_iov->iov_len -= tlen;
2370 uiop->uio_offset += tlen;
2371 uiop->uio_resid -= tlen;
2373 nfsm_adv(nfsm_rndup(len));
2374 nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
2376 cookie.nfsuquad[0] = *tl++;
2377 cookie.nfsuquad[1] = *tl++;
2382 * Since the attributes are before the file handle
2383 * (sigh), we must skip over the attributes and then
2384 * come back and get them.
2386 attrflag = fxdr_unsigned(int, *tl);
2390 nfsm_adv(NFSX_V3FATTR);
2391 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
2392 doit = fxdr_unsigned(int, *tl);
2394 nfsm_getfh(fhp, fhsize, 1);
2395 if (NFS_CMPFH(dnp, fhp, fhsize)) {
2400 error = nfs_nget(vp->v_mount, fhp,
2408 if (doit && bigenough) {
2413 nfsm_loadattr(newvp, (struct vattr *)0);
2417 IFTODT(VTTOIF(np->n_vattr.va_type));
2419 cache_enter(ndp->ni_dvp, NCPNULL, ndp->ni_vp, cnp);
2422 /* Just skip over the file handle */
2423 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
2424 i = fxdr_unsigned(int, *tl);
2425 nfsm_adv(nfsm_rndup(i));
2427 if (newvp != NULLVP) {
2434 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
2435 more_dirs = fxdr_unsigned(int, *tl);
2438 * If at end of rpc data, get the eof boolean
2441 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
2442 more_dirs = (fxdr_unsigned(int, *tl) == 0);
2447 * Fill last record, iff any, out to a multiple of DIRBLKSIZ
2448 * by increasing d_reclen for the last record.
2451 left = DIRBLKSIZ - blksiz;
2452 dp->d_reclen += left;
2453 uiop->uio_iov->iov_base += left;
2454 uiop->uio_iov->iov_len -= left;
2455 uiop->uio_offset += left;
2456 uiop->uio_resid -= left;
2460 * We are now either at the end of the directory or have filled the
2464 dnp->n_direofoffset = uiop->uio_offset;
2466 if (uiop->uio_resid > 0)
2467 printf("EEK! readdirplusrpc resid > 0\n");
2468 cookiep = nfs_getcookie(dnp, uiop->uio_offset, 1);
2472 if (newvp != NULLVP) {
2483 * Silly rename. To make the NFS filesystem that is stateless look a little
2484 * more like the "ufs" a remove of an active vnode is translated to a rename
2485 * to a funny looking filename that is removed by nfs_inactive on the
2486 * nfsnode. There is the potential for another process on a different client
2487 * to create the same funny name between the nfs_lookitup() fails and the
2488 * nfs_rename() completes, but...
2491 nfs_sillyrename(dvp, vp, cnp)
2492 struct vnode *dvp, *vp;
2493 struct componentname *cnp;
2495 struct sillyrename *sp;
2502 if (vp->v_type == VDIR)
2503 panic("nfs: sillyrename dir");
2505 MALLOC(sp, struct sillyrename *, sizeof (struct sillyrename),
2506 M_NFSREQ, M_WAITOK);
2507 sp->s_cred = crdup(cnp->cn_cred);
2511 /* Fudge together a funny name */
2512 sp->s_namlen = sprintf(sp->s_name, ".nfsA%08x4.4", (int)cnp->cn_td);
2514 /* Try lookitups until we get one that isn't there */
2515 while (nfs_lookitup(dvp, sp->s_name, sp->s_namlen, sp->s_cred,
2516 cnp->cn_td, (struct nfsnode **)0) == 0) {
2518 if (sp->s_name[4] > 'z') {
2523 error = nfs_renameit(dvp, cnp, sp);
2526 error = nfs_lookitup(dvp, sp->s_name, sp->s_namlen, sp->s_cred,
2528 np->n_sillyrename = sp;
2533 free((caddr_t)sp, M_NFSREQ);
2538 * Look up a file name and optionally either update the file handle or
2539 * allocate an nfsnode, depending on the value of npp.
2540 * npp == NULL --> just do the lookup
2541 * *npp == NULL --> allocate a new nfsnode and make sure attributes are
2543 * *npp != NULL --> update the file handle in the vnode
2546 nfs_lookitup(dvp, name, len, cred, td, npp)
2552 struct nfsnode **npp;
2557 struct vnode *newvp = (struct vnode *)0;
2558 struct nfsnode *np, *dnp = VTONFS(dvp);
2559 caddr_t bpos, dpos, cp2;
2560 int error = 0, fhlen, attrflag;
2561 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
2563 int v3 = NFS_ISV3(dvp);
2565 nfsstats.rpccnt[NFSPROC_LOOKUP]++;
2566 nfsm_reqhead(dvp, NFSPROC_LOOKUP,
2567 NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len));
2568 nfsm_fhtom(dvp, v3);
2569 nfsm_strtom(name, len, NFS_MAXNAMLEN);
2570 nfsm_request(dvp, NFSPROC_LOOKUP, td, cred);
2571 if (npp && !error) {
2572 nfsm_getfh(nfhp, fhlen, v3);
2575 if (np->n_fhsize > NFS_SMALLFH && fhlen <= NFS_SMALLFH) {
2576 free((caddr_t)np->n_fhp, M_NFSBIGFH);
2577 np->n_fhp = &np->n_fh;
2578 } else if (np->n_fhsize <= NFS_SMALLFH && fhlen>NFS_SMALLFH)
2579 np->n_fhp =(nfsfh_t *)malloc(fhlen,M_NFSBIGFH,M_WAITOK);
2580 bcopy((caddr_t)nfhp, (caddr_t)np->n_fhp, fhlen);
2581 np->n_fhsize = fhlen;
2583 } else if (NFS_CMPFH(dnp, nfhp, fhlen)) {
2587 error = nfs_nget(dvp->v_mount, nfhp, fhlen, &np);
2595 nfsm_postop_attr(newvp, attrflag);
2596 if (!attrflag && *npp == NULL) {
2605 nfsm_loadattr(newvp, (struct vattr *)0);
2608 if (npp && *npp == NULL) {
2623 * Nfs Version 3 commit rpc
2626 nfs_commit(struct vnode *vp, u_quad_t offset, int cnt, struct thread *td)
2631 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2632 caddr_t bpos, dpos, cp2;
2633 int error = 0, wccflag = NFSV3_WCCRATTR;
2634 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
2636 if ((nmp->nm_state & NFSSTA_HASWRITEVERF) == 0)
2638 nfsstats.rpccnt[NFSPROC_COMMIT]++;
2639 nfsm_reqhead(vp, NFSPROC_COMMIT, NFSX_FH(1));
2641 nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
2642 txdr_hyper(offset, tl);
2644 *tl = txdr_unsigned(cnt);
2645 nfsm_request(vp, NFSPROC_COMMIT, td, NFSVPCRED(vp));
2646 nfsm_wcc_data(vp, wccflag);
2648 nfsm_dissect(tl, u_int32_t *, NFSX_V3WRITEVERF);
2649 if (bcmp((caddr_t)nmp->nm_verf, (caddr_t)tl,
2650 NFSX_V3WRITEVERF)) {
2651 bcopy((caddr_t)tl, (caddr_t)nmp->nm_verf,
2653 error = NFSERR_STALEWRITEVERF;
2662 * - make nfs_bmap() essentially a no-op that does no translation
2663 * - do nfs_strategy() by doing I/O with nfs_readrpc/nfs_writerpc
2664 * (Maybe I could use the process's page mapping, but I was concerned that
2665 * Kernel Write might not be enabled and also figured copyout() would do
2666 * a lot more work than bcopy() and also it currently happens in the
2667 * context of the swapper process (2).
2671 struct vop_bmap_args /* {
2674 struct vnode **a_vpp;
2680 struct vnode *vp = ap->a_vp;
2682 if (ap->a_vpp != NULL)
2684 if (ap->a_bnp != NULL)
2685 *ap->a_bnp = ap->a_bn * btodb(vp->v_mount->mnt_stat.f_iosize);
2686 if (ap->a_runp != NULL)
2688 if (ap->a_runb != NULL)
2695 * For async requests when nfsiod(s) are running, queue the request by
2696 * calling nfs_asyncio(), otherwise just all nfs_doio() to do the
2701 struct vop_strategy_args *ap;
2703 struct buf *bp = ap->a_bp;
2707 KASSERT(!(bp->b_flags & B_DONE), ("nfs_strategy: buffer %p unexpectedly marked B_DONE", bp));
2708 KASSERT(BUF_REFCNT(bp) > 0, ("nfs_strategy: buffer %p not locked", bp));
2710 if (bp->b_flags & B_PHYS)
2711 panic("nfs physio");
2713 if (bp->b_flags & B_ASYNC)
2716 td = curthread; /* XXX */
2719 * If the op is asynchronous and an i/o daemon is waiting
2720 * queue the request, wake it up and wait for completion
2721 * otherwise just do it ourselves.
2723 if ((bp->b_flags & B_ASYNC) == 0 ||
2724 nfs_asyncio(bp, td))
2725 error = nfs_doio(bp, td);
2732 * NB Currently unsupported.
2737 struct vop_mmap_args /* {
2740 struct ucred *a_cred;
2741 struct thread *a_td;
2749 * fsync vnode op. Just call nfs_flush() with commit == 1.
2754 struct vop_fsync_args /* {
2755 struct vnodeop_desc *a_desc;
2756 struct vnode * a_vp;
2757 struct ucred * a_cred;
2759 struct thread * a_td;
2763 return (nfs_flush(ap->a_vp, ap->a_waitfor, ap->a_td, 1));
2767 * Flush all the blocks associated with a vnode.
2768 * Walk through the buffer pool and push any dirty pages
2769 * associated with the vnode.
2772 nfs_flush(vp, waitfor, td, commit)
2778 struct nfsnode *np = VTONFS(vp);
2782 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2783 int s, error = 0, slptimeo = 0, slpflag = 0, retv, bvecpos;
2785 u_quad_t off, endoff, toff;
2786 struct buf **bvec = NULL;
2787 #ifndef NFS_COMMITBVECSIZ
2788 #define NFS_COMMITBVECSIZ 20
2790 struct buf *bvec_on_stack[NFS_COMMITBVECSIZ];
2791 int bvecsize = 0, bveccount;
2793 if (nmp->nm_flag & NFSMNT_INT)
2798 * A b_flags == (B_DELWRI | B_NEEDCOMMIT) block has been written to the
2799 * server, but nas not been committed to stable storage on the server
2800 * yet. On the first pass, the byte range is worked out and the commit
2801 * rpc is done. On the second pass, nfs_writebp() is called to do the
2808 if (NFS_ISV3(vp) && commit) {
2811 * Count up how many buffers waiting for a commit.
2814 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
2815 nbp = TAILQ_NEXT(bp, b_vnbufs);
2816 if (BUF_REFCNT(bp) == 0 &&
2817 (bp->b_flags & (B_DELWRI | B_NEEDCOMMIT))
2818 == (B_DELWRI | B_NEEDCOMMIT))
2822 * Allocate space to remember the list of bufs to commit. It is
2823 * important to use M_NOWAIT here to avoid a race with nfs_write.
2824 * If we can't get memory (for whatever reason), we will end up
2825 * committing the buffers one-by-one in the loop below.
2827 if (bvec != NULL && bvec != bvec_on_stack)
2829 if (bveccount > NFS_COMMITBVECSIZ) {
2830 bvec = (struct buf **)
2831 malloc(bveccount * sizeof(struct buf *),
2834 bvec = bvec_on_stack;
2835 bvecsize = NFS_COMMITBVECSIZ;
2837 bvecsize = bveccount;
2839 bvec = bvec_on_stack;
2840 bvecsize = NFS_COMMITBVECSIZ;
2842 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
2843 nbp = TAILQ_NEXT(bp, b_vnbufs);
2844 if (bvecpos >= bvecsize)
2846 if ((bp->b_flags & (B_DELWRI | B_NEEDCOMMIT)) !=
2847 (B_DELWRI | B_NEEDCOMMIT) ||
2848 BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT))
2852 * NOTE: we are not clearing B_DONE here, so we have
2853 * to do it later on in this routine if we intend to
2854 * initiate I/O on the bp.
2856 * Note: to avoid loopback deadlocks, we do not
2857 * assign b_runningbufspace.
2859 bp->b_flags |= B_WRITEINPROG;
2860 vfs_busy_pages(bp, 1);
2863 * bp is protected by being locked, but nbp is not
2864 * and vfs_busy_pages() may sleep. We have to
2867 nbp = TAILQ_NEXT(bp, b_vnbufs);
2870 * A list of these buffers is kept so that the
2871 * second loop knows which buffers have actually
2872 * been committed. This is necessary, since there
2873 * may be a race between the commit rpc and new
2874 * uncommitted writes on the file.
2876 bvec[bvecpos++] = bp;
2877 toff = ((u_quad_t)bp->b_blkno) * DEV_BSIZE +
2881 toff += (u_quad_t)(bp->b_dirtyend - bp->b_dirtyoff);
2889 * Commit data on the server, as required. Note that
2890 * nfs_commit will use the vnode's cred for the commit.
2892 retv = nfs_commit(vp, off, (int)(endoff - off), td);
2894 if (retv == NFSERR_STALEWRITEVERF)
2895 nfs_clearcommit(vp->v_mount);
2898 * Now, either mark the blocks I/O done or mark the
2899 * blocks dirty, depending on whether the commit
2902 for (i = 0; i < bvecpos; i++) {
2904 bp->b_flags &= ~(B_NEEDCOMMIT | B_WRITEINPROG | B_CLUSTEROK);
2907 * Error, leave B_DELWRI intact
2909 vfs_unbusy_pages(bp);
2913 * Success, remove B_DELWRI ( bundirty() ).
2915 * b_dirtyoff/b_dirtyend seem to be NFS
2916 * specific. We should probably move that
2917 * into bundirty(). XXX
2921 bp->b_flags |= B_ASYNC;
2923 bp->b_flags &= ~(B_READ|B_DONE|B_ERROR);
2924 bp->b_dirtyoff = bp->b_dirtyend = 0;
2932 * Start/do any write(s) that are required.
2936 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
2937 nbp = TAILQ_NEXT(bp, b_vnbufs);
2938 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT)) {
2939 if (waitfor != MNT_WAIT || passone)
2941 error = BUF_TIMELOCK(bp, LK_EXCLUSIVE | LK_SLEEPFAIL,
2942 "nfsfsync", slpflag, slptimeo);
2945 panic("nfs_fsync: inconsistent lock");
2946 if (error == ENOLCK)
2948 if (nfs_sigintr(nmp, (struct nfsreq *)0, td)) {
2952 if (slpflag == PCATCH) {
2958 if ((bp->b_flags & B_DELWRI) == 0)
2959 panic("nfs_fsync: not dirty");
2960 if ((passone || !commit) && (bp->b_flags & B_NEEDCOMMIT)) {
2965 if (passone || !commit)
2966 bp->b_flags |= B_ASYNC;
2968 bp->b_flags |= B_ASYNC | B_WRITEINPROG;
2970 VOP_BWRITE(bp->b_vp, bp);
2978 if (waitfor == MNT_WAIT) {
2979 while (vp->v_numoutput) {
2980 vp->v_flag |= VBWAIT;
2981 error = tsleep((caddr_t)&vp->v_numoutput,
2982 slpflag, "nfsfsync", slptimeo);
2984 if (nfs_sigintr(nmp, (struct nfsreq *)0, td)) {
2988 if (slpflag == PCATCH) {
2994 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd) && commit) {
2998 if (np->n_flag & NWRITEERR) {
2999 error = np->n_error;
3000 np->n_flag &= ~NWRITEERR;
3003 if (bvec != NULL && bvec != bvec_on_stack)
3009 * NFS advisory byte-level locks.
3010 * Currently unsupported.
3014 struct vop_advlock_args /* {
3022 struct nfsnode *np = VTONFS(ap->a_vp);
3025 * The following kludge is to allow diskless support to work
3026 * until a real NFS lockd is implemented. Basically, just pretend
3027 * that this is a local lock.
3029 return (lf_advlock(ap, &(np->n_lockf), np->n_size));
3033 * Print out the contents of an nfsnode.
3037 struct vop_print_args /* {
3041 struct vnode *vp = ap->a_vp;
3042 struct nfsnode *np = VTONFS(vp);
3044 printf("tag VT_NFS, fileid %ld fsid 0x%x",
3045 np->n_vattr.va_fileid, np->n_vattr.va_fsid);
3046 if (vp->v_type == VFIFO)
3053 * Just call nfs_writebp() with the force argument set to 1.
3055 * NOTE: B_DONE may or may not be set in a_bp on call.
3059 struct vop_bwrite_args /* {
3063 return (nfs_writebp(ap->a_bp, 1, curthread));
3067 * This is a clone of vn_bwrite(), except that B_WRITEINPROG isn't set unless
3068 * the force flag is one and it also handles the B_NEEDCOMMIT flag. We set
3069 * B_CACHE if this is a VMIO buffer.
3072 nfs_writebp(bp, force, td)
3078 int oldflags = bp->b_flags;
3084 if (BUF_REFCNT(bp) == 0)
3085 panic("bwrite: buffer is not locked???");
3087 if (bp->b_flags & B_INVAL) {
3092 bp->b_flags |= B_CACHE;
3095 * Undirty the bp. We will redirty it later if the I/O fails.
3100 bp->b_flags &= ~(B_READ|B_DONE|B_ERROR);
3102 bp->b_vp->v_numoutput++;
3106 * Note: to avoid loopback deadlocks, we do not
3107 * assign b_runningbufspace.
3109 vfs_busy_pages(bp, 1);
3112 bp->b_flags |= B_WRITEINPROG;
3114 VOP_STRATEGY(bp->b_vp, bp);
3116 if( (oldflags & B_ASYNC) == 0) {
3117 int rtval = biowait(bp);
3119 if (oldflags & B_DELWRI) {
3121 reassignbuf(bp, bp->b_vp);
3133 * nfs special file access vnode op.
3134 * Essentially just get vattr and then imitate iaccess() since the device is
3135 * local to the client.
3139 struct vop_access_args /* {
3142 struct ucred *a_cred;
3143 struct thread *a_td;
3148 struct ucred *cred = ap->a_cred;
3149 struct vnode *vp = ap->a_vp;
3150 mode_t mode = ap->a_mode;
3156 * Disallow write attempts on filesystems mounted read-only;
3157 * unless the file is a socket, fifo, or a block or character
3158 * device resident on the filesystem.
3160 if ((mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
3161 switch (vp->v_type) {
3171 * If you're the super-user,
3172 * you always get access.
3174 if (cred->cr_uid == 0)
3177 error = VOP_GETATTR(vp, vap, ap->a_td);
3181 * Access check is based on only one of owner, group, public.
3182 * If not owner, then check group. If not a member of the
3183 * group, then check public access.
3185 if (cred->cr_uid != vap->va_uid) {
3187 gp = cred->cr_groups;
3188 for (i = 0; i < cred->cr_ngroups; i++, gp++)
3189 if (vap->va_gid == *gp)
3195 error = (vap->va_mode & mode) == mode ? 0 : EACCES;
3200 * Read wrapper for special devices.
3204 struct vop_read_args /* {
3208 struct ucred *a_cred;
3211 struct nfsnode *np = VTONFS(ap->a_vp);
3217 getnanotime(&np->n_atim);
3218 return (VOCALL(spec_vnodeop_p, VOFFSET(vop_read), ap));
3222 * Write wrapper for special devices.
3226 struct vop_write_args /* {
3230 struct ucred *a_cred;
3233 struct nfsnode *np = VTONFS(ap->a_vp);
3239 getnanotime(&np->n_mtim);
3240 return (VOCALL(spec_vnodeop_p, VOFFSET(vop_write), ap));
3244 * Close wrapper for special devices.
3246 * Update the times on the nfsnode then do device close.
3250 struct vop_close_args /* {
3253 struct ucred *a_cred;
3254 struct thread *a_td;
3257 struct vnode *vp = ap->a_vp;
3258 struct nfsnode *np = VTONFS(vp);
3261 if (np->n_flag & (NACC | NUPD)) {
3263 if (vp->v_usecount == 1 &&
3264 (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
3266 if (np->n_flag & NACC)
3267 vattr.va_atime = np->n_atim;
3268 if (np->n_flag & NUPD)
3269 vattr.va_mtime = np->n_mtim;
3270 (void)VOP_SETATTR(vp, &vattr, NFSVPCRED(vp), ap->a_td);
3273 return (VOCALL(spec_vnodeop_p, VOFFSET(vop_close), ap));
3277 * Read wrapper for fifos.
3281 struct vop_read_args /* {
3285 struct ucred *a_cred;
3288 struct nfsnode *np = VTONFS(ap->a_vp);
3294 getnanotime(&np->n_atim);
3295 return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_read), ap));
3299 * Write wrapper for fifos.
3303 struct vop_write_args /* {
3307 struct ucred *a_cred;
3310 struct nfsnode *np = VTONFS(ap->a_vp);
3316 getnanotime(&np->n_mtim);
3317 return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_write), ap));
3321 * Close wrapper for fifos.
3323 * Update the times on the nfsnode then do fifo close.
3327 struct vop_close_args /* {
3330 struct thread *a_td;
3333 struct vnode *vp = ap->a_vp;
3334 struct nfsnode *np = VTONFS(vp);
3338 if (np->n_flag & (NACC | NUPD)) {
3340 if (np->n_flag & NACC)
3342 if (np->n_flag & NUPD)
3345 if (vp->v_usecount == 1 &&
3346 (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
3348 if (np->n_flag & NACC)
3349 vattr.va_atime = np->n_atim;
3350 if (np->n_flag & NUPD)
3351 vattr.va_mtime = np->n_mtim;
3352 (void)VOP_SETATTR(vp, &vattr, NFSVPCRED(vp), ap->a_td);
3355 return (VOCALL(fifo_vnodeop_p, VOFFSET(vop_close), ap));