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
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include <sys/capability.h>
40 * Functions that perform the vfs operations required by the routines in
41 * nfsd_serv.c. It is hoped that this change will make the server more
45 #include <fs/nfs/nfsport.h>
47 #include <sys/sysctl.h>
48 #include <nlm/nlm_prot.h>
51 FEATURE(nfsd, "NFSv4 server");
53 extern u_int32_t newnfs_true, newnfs_false, newnfs_xdrneg1;
54 extern int nfsrv_useacl;
55 extern int newnfs_numnfsd;
56 extern struct mount nfsv4root_mnt;
57 extern struct nfsrv_stablefirst nfsrv_stablefirst;
58 extern void (*nfsd_call_servertimer)(void);
59 extern SVCPOOL *nfsrvd_pool;
60 extern struct nfsv4lock nfsd_suspend_lock;
61 struct vfsoptlist nfsv4root_opt, nfsv4root_newopt;
63 struct mtx nfs_cache_mutex;
64 struct mtx nfs_v4root_mutex;
65 struct nfsrvfh nfs_rootfh, nfs_pubfh;
66 int nfs_pubfhset = 0, nfs_rootfhset = 0;
67 struct proc *nfsd_master_proc = NULL;
68 static pid_t nfsd_master_pid = (pid_t)-1;
69 static char nfsd_master_comm[MAXCOMLEN + 1];
70 static struct timeval nfsd_master_start;
71 static uint32_t nfsv4_sysid = 0;
73 static int nfssvc_srvcall(struct thread *, struct nfssvc_args *,
76 int nfsrv_enable_crossmntpt = 1;
77 static int nfs_commit_blks;
78 static int nfs_commit_miss;
79 extern int nfsrv_issuedelegs;
80 extern int nfsrv_dolocallocks;
82 SYSCTL_NODE(_vfs, OID_AUTO, nfsd, CTLFLAG_RW, 0, "New NFS server");
83 SYSCTL_INT(_vfs_nfsd, OID_AUTO, mirrormnt, CTLFLAG_RW,
84 &nfsrv_enable_crossmntpt, 0, "Enable nfsd to cross mount points");
85 SYSCTL_INT(_vfs_nfsd, OID_AUTO, commit_blks, CTLFLAG_RW, &nfs_commit_blks,
87 SYSCTL_INT(_vfs_nfsd, OID_AUTO, commit_miss, CTLFLAG_RW, &nfs_commit_miss,
89 SYSCTL_INT(_vfs_nfsd, OID_AUTO, issue_delegations, CTLFLAG_RW,
90 &nfsrv_issuedelegs, 0, "Enable nfsd to issue delegations");
91 SYSCTL_INT(_vfs_nfsd, OID_AUTO, enable_locallocks, CTLFLAG_RW,
92 &nfsrv_dolocallocks, 0, "Enable nfsd to acquire local locks on files");
94 #define MAX_REORDERED_RPC 16
95 #define NUM_HEURISTIC 1031
98 #define NHUSE_MAX 2048
100 static struct nfsheur {
101 struct vnode *nh_vp; /* vp to match (unreferenced pointer) */
102 off_t nh_nextoff; /* next offset for sequential detection */
103 int nh_use; /* use count for selection */
104 int nh_seqcount; /* heuristic */
105 } nfsheur[NUM_HEURISTIC];
109 * Heuristic to detect sequential operation.
111 static struct nfsheur *
112 nfsrv_sequential_heuristic(struct uio *uio, struct vnode *vp)
117 /* Locate best candidate. */
119 hi = ((int)(vm_offset_t)vp / sizeof(struct vnode)) % NUM_HEURISTIC;
122 if (nfsheur[hi].nh_vp == vp) {
126 if (nfsheur[hi].nh_use > 0)
127 --nfsheur[hi].nh_use;
128 hi = (hi + 1) % NUM_HEURISTIC;
129 if (nfsheur[hi].nh_use < nh->nh_use)
133 /* Initialize hint if this is a new file. */
134 if (nh->nh_vp != vp) {
136 nh->nh_nextoff = uio->uio_offset;
137 nh->nh_use = NHUSE_INIT;
138 if (uio->uio_offset == 0)
144 /* Calculate heuristic. */
145 if ((uio->uio_offset == 0 && nh->nh_seqcount > 0) ||
146 uio->uio_offset == nh->nh_nextoff) {
147 /* See comments in vfs_vnops.c:sequential_heuristic(). */
148 nh->nh_seqcount += howmany(uio->uio_resid, 16384);
149 if (nh->nh_seqcount > IO_SEQMAX)
150 nh->nh_seqcount = IO_SEQMAX;
151 } else if (qabs(uio->uio_offset - nh->nh_nextoff) <= MAX_REORDERED_RPC *
152 imax(vp->v_mount->mnt_stat.f_iosize, uio->uio_resid)) {
153 /* Probably a reordered RPC, leave seqcount alone. */
154 } else if (nh->nh_seqcount > 1) {
155 nh->nh_seqcount /= 2;
159 nh->nh_use += NHUSE_INC;
160 if (nh->nh_use > NHUSE_MAX)
161 nh->nh_use = NHUSE_MAX;
166 * Get attributes into nfsvattr structure.
169 nfsvno_getattr(struct vnode *vp, struct nfsvattr *nvap, struct ucred *cred,
170 struct thread *p, int vpislocked)
172 int error, lockedit = 0;
174 if (vpislocked == 0) {
176 * When vpislocked == 0, the vnode is either exclusively
177 * locked by this thread or not locked by this thread.
178 * As such, shared lock it, if not exclusively locked.
180 if (NFSVOPISLOCKED(vp) != LK_EXCLUSIVE) {
182 NFSVOPLOCK(vp, LK_SHARED | LK_RETRY);
185 error = VOP_GETATTR(vp, &nvap->na_vattr, cred);
194 * Get a file handle for a vnode.
197 nfsvno_getfh(struct vnode *vp, fhandle_t *fhp, struct thread *p)
201 NFSBZERO((caddr_t)fhp, sizeof(fhandle_t));
202 fhp->fh_fsid = vp->v_mount->mnt_stat.f_fsid;
203 error = VOP_VPTOFH(vp, &fhp->fh_fid);
210 * Perform access checking for vnodes obtained from file handles that would
211 * refer to files already opened by a Unix client. You cannot just use
212 * vn_writechk() and VOP_ACCESSX() for two reasons.
213 * 1 - You must check for exported rdonly as well as MNT_RDONLY for the write
215 * 2 - The owner is to be given access irrespective of mode bits for some
216 * operations, so that processes that chmod after opening a file don't
220 nfsvno_accchk(struct vnode *vp, accmode_t accmode, struct ucred *cred,
221 struct nfsexstuff *exp, struct thread *p, int override, int vpislocked,
222 u_int32_t *supportedtypep)
225 int error = 0, getret = 0;
227 if (vpislocked == 0) {
228 if (NFSVOPLOCK(vp, LK_SHARED) != 0) {
233 if (accmode & VWRITE) {
234 /* Just vn_writechk() changed to check rdonly */
236 * Disallow write attempts on read-only file systems;
237 * unless the file is a socket or a block or character
238 * device resident on the file system.
240 if (NFSVNO_EXRDONLY(exp) ||
241 (vp->v_mount->mnt_flag & MNT_RDONLY)) {
242 switch (vp->v_type) {
252 * If there's shared text associated with
253 * the inode, try to free it up once. If
254 * we fail, we can't allow writing.
256 if (VOP_IS_TEXT(vp) && error == 0)
266 * Should the override still be applied when ACLs are enabled?
268 error = VOP_ACCESSX(vp, accmode, cred, p);
269 if (error != 0 && (accmode & (VDELETE | VDELETE_CHILD))) {
271 * Try again with VEXPLICIT_DENY, to see if the test for
272 * deletion is supported.
274 error = VOP_ACCESSX(vp, accmode | VEXPLICIT_DENY, cred, p);
276 if (vp->v_type == VDIR) {
277 accmode &= ~(VDELETE | VDELETE_CHILD);
279 error = VOP_ACCESSX(vp, accmode, cred, p);
280 } else if (supportedtypep != NULL) {
281 *supportedtypep &= ~NFSACCESS_DELETE;
287 * Allow certain operations for the owner (reads and writes
288 * on files that are already open).
290 if (override != NFSACCCHK_NOOVERRIDE &&
291 (error == EPERM || error == EACCES)) {
292 if (cred->cr_uid == 0 && (override & NFSACCCHK_ALLOWROOT))
294 else if (override & NFSACCCHK_ALLOWOWNER) {
295 getret = VOP_GETATTR(vp, &vattr, cred);
296 if (getret == 0 && cred->cr_uid == vattr.va_uid)
309 * Set attribute(s) vnop.
312 nfsvno_setattr(struct vnode *vp, struct nfsvattr *nvap, struct ucred *cred,
313 struct thread *p, struct nfsexstuff *exp)
317 error = VOP_SETATTR(vp, &nvap->na_vattr, cred);
323 * Set up nameidata for a lookup() call and do it.
326 nfsvno_namei(struct nfsrv_descript *nd, struct nameidata *ndp,
327 struct vnode *dp, int islocked, struct nfsexstuff *exp, struct thread *p,
328 struct vnode **retdirp)
330 struct componentname *cnp = &ndp->ni_cnd;
334 int lockleaf = (cnp->cn_flags & LOCKLEAF) != 0, linklen;
335 int error = 0, crossmnt;
339 cnp->cn_nameptr = cnp->cn_pnbuf;
340 ndp->ni_strictrelative = 0;
342 * Extract and set starting directory.
344 if (dp->v_type != VDIR) {
349 nfsvno_relpathbuf(ndp);
357 if (NFSVNO_EXRDONLY(exp))
358 cnp->cn_flags |= RDONLY;
359 ndp->ni_segflg = UIO_SYSSPACE;
362 if (nd->nd_flag & ND_PUBLOOKUP) {
364 if (cnp->cn_pnbuf[0] == '/') {
367 * Check for degenerate pathnames here, since lookup()
370 for (i = 1; i < ndp->ni_pathlen; i++)
371 if (cnp->cn_pnbuf[i] != '/')
373 if (i == ndp->ni_pathlen) {
374 error = NFSERR_ACCES;
380 } else if ((nfsrv_enable_crossmntpt == 0 && NFSVNO_EXPORTED(exp)) ||
381 (nd->nd_flag & ND_NFSV4) == 0) {
383 * Only cross mount points for NFSv4 when doing a
384 * mount while traversing the file system above
385 * the mount point, unless nfsrv_enable_crossmntpt is set.
387 cnp->cn_flags |= NOCROSSMOUNT;
392 * Initialize for scan, set ni_startdir and bump ref on dp again
393 * because lookup() will dereference ni_startdir.
397 ndp->ni_startdir = dp;
398 ndp->ni_rootdir = rootvnode;
399 ndp->ni_topdir = NULL;
402 cnp->cn_flags |= LOCKLEAF;
404 cnp->cn_nameptr = cnp->cn_pnbuf;
406 * Call lookup() to do the real work. If an error occurs,
407 * ndp->ni_vp and ni_dvp are left uninitialized or NULL and
408 * we do not have to dereference anything before returning.
409 * In either case ni_startdir will be dereferenced and NULLed
417 * Check for encountering a symbolic link. Trivial
418 * termination occurs if no symlink encountered.
420 if ((cnp->cn_flags & ISSYMLINK) == 0) {
421 if ((cnp->cn_flags & (SAVENAME | SAVESTART)) == 0)
422 nfsvno_relpathbuf(ndp);
423 if (ndp->ni_vp && !lockleaf)
424 NFSVOPUNLOCK(ndp->ni_vp, 0);
431 if ((cnp->cn_flags & LOCKPARENT) && ndp->ni_pathlen == 1)
432 NFSVOPUNLOCK(ndp->ni_dvp, 0);
433 if (!(nd->nd_flag & ND_PUBLOOKUP)) {
438 if (ndp->ni_loopcnt++ >= MAXSYMLINKS) {
442 if (ndp->ni_pathlen > 1)
443 cp = uma_zalloc(namei_zone, M_WAITOK);
447 aiov.iov_len = MAXPATHLEN;
448 auio.uio_iov = &aiov;
451 auio.uio_rw = UIO_READ;
452 auio.uio_segflg = UIO_SYSSPACE;
454 auio.uio_resid = MAXPATHLEN;
455 error = VOP_READLINK(ndp->ni_vp, &auio, cnp->cn_cred);
458 if (ndp->ni_pathlen > 1)
459 uma_zfree(namei_zone, cp);
465 linklen = MAXPATHLEN - auio.uio_resid;
470 if (linklen + ndp->ni_pathlen >= MAXPATHLEN) {
471 error = ENAMETOOLONG;
476 * Adjust or replace path
478 if (ndp->ni_pathlen > 1) {
479 NFSBCOPY(ndp->ni_next, cp + linklen, ndp->ni_pathlen);
480 uma_zfree(namei_zone, cnp->cn_pnbuf);
483 cnp->cn_pnbuf[linklen] = '\0';
484 ndp->ni_pathlen += linklen;
487 * Cleanup refs for next loop and check if root directory
488 * should replace current directory. Normally ni_dvp
489 * becomes the new base directory and is cleaned up when
490 * we loop. Explicitly null pointers after invalidation
491 * to clarify operation.
496 if (cnp->cn_pnbuf[0] == '/') {
498 ndp->ni_dvp = ndp->ni_rootdir;
501 ndp->ni_startdir = ndp->ni_dvp;
505 cnp->cn_flags &= ~LOCKLEAF;
509 nfsvno_relpathbuf(ndp);
512 ndp->ni_startdir = NULL;
513 } else if ((ndp->ni_cnd.cn_flags & (WANTPARENT|LOCKPARENT)) == 0) {
518 NFSEXITCODE2(error, nd);
523 * Set up a pathname buffer and return a pointer to it and, optionally
524 * set a hash pointer.
527 nfsvno_setpathbuf(struct nameidata *ndp, char **bufpp, u_long **hashpp)
529 struct componentname *cnp = &ndp->ni_cnd;
531 cnp->cn_flags |= (NOMACCHECK | HASBUF);
532 cnp->cn_pnbuf = uma_zalloc(namei_zone, M_WAITOK);
535 *bufpp = cnp->cn_pnbuf;
539 * Release the above path buffer, if not released by nfsvno_namei().
542 nfsvno_relpathbuf(struct nameidata *ndp)
545 if ((ndp->ni_cnd.cn_flags & HASBUF) == 0)
547 uma_zfree(namei_zone, ndp->ni_cnd.cn_pnbuf);
548 ndp->ni_cnd.cn_flags &= ~HASBUF;
552 * Readlink vnode op into an mbuf list.
555 nfsvno_readlink(struct vnode *vp, struct ucred *cred, struct thread *p,
556 struct mbuf **mpp, struct mbuf **mpendp, int *lenp)
558 struct iovec iv[(NFS_MAXPATHLEN+MLEN-1)/MLEN];
559 struct iovec *ivp = iv;
560 struct uio io, *uiop = &io;
561 struct mbuf *mp, *mp2 = NULL, *mp3 = NULL;
562 int i, len, tlen, error = 0;
566 while (len < NFS_MAXPATHLEN) {
568 MCLGET(mp, M_WAITOK);
569 mp->m_len = NFSMSIZ(mp);
576 if ((len + mp->m_len) > NFS_MAXPATHLEN) {
577 mp->m_len = NFS_MAXPATHLEN - len;
578 len = NFS_MAXPATHLEN;
582 ivp->iov_base = mtod(mp, caddr_t);
583 ivp->iov_len = mp->m_len;
588 uiop->uio_iovcnt = i;
589 uiop->uio_offset = 0;
590 uiop->uio_resid = len;
591 uiop->uio_rw = UIO_READ;
592 uiop->uio_segflg = UIO_SYSSPACE;
594 error = VOP_READLINK(vp, uiop, cred);
600 if (uiop->uio_resid > 0) {
601 len -= uiop->uio_resid;
602 tlen = NFSM_RNDUP(len);
603 nfsrv_adj(mp3, NFS_MAXPATHLEN - tlen, tlen - len);
615 * Read vnode op call into mbuf list.
618 nfsvno_read(struct vnode *vp, off_t off, int cnt, struct ucred *cred,
619 struct thread *p, struct mbuf **mpp, struct mbuf **mpendp)
625 int error = 0, len, left, siz, tlen, ioflag = 0;
626 struct mbuf *m2 = NULL, *m3;
627 struct uio io, *uiop = &io;
630 len = left = NFSM_RNDUP(cnt);
633 * Generate the mbuf list with the uio_iov ref. to it.
640 siz = min(M_TRAILINGSPACE(m), left);
649 MALLOC(iv, struct iovec *, i * sizeof (struct iovec),
651 uiop->uio_iov = iv2 = iv;
657 panic("nfsvno_read iov");
658 siz = min(M_TRAILINGSPACE(m), left);
660 iv->iov_base = mtod(m, caddr_t) + m->m_len;
669 uiop->uio_iovcnt = i;
670 uiop->uio_offset = off;
671 uiop->uio_resid = len;
672 uiop->uio_rw = UIO_READ;
673 uiop->uio_segflg = UIO_SYSSPACE;
674 nh = nfsrv_sequential_heuristic(uiop, vp);
675 ioflag |= nh->nh_seqcount << IO_SEQSHIFT;
676 error = VOP_READ(vp, uiop, IO_NODELOCKED | ioflag, cred);
677 FREE((caddr_t)iv2, M_TEMP);
683 nh->nh_nextoff = uiop->uio_offset;
684 tlen = len - uiop->uio_resid;
685 cnt = cnt < tlen ? cnt : tlen;
686 tlen = NFSM_RNDUP(cnt);
690 } else if (len != tlen || tlen != cnt)
691 nfsrv_adj(m3, len - tlen, tlen - cnt);
701 * Write vnode op from an mbuf list.
704 nfsvno_write(struct vnode *vp, off_t off, int retlen, int cnt, int stable,
705 struct mbuf *mp, char *cp, struct ucred *cred, struct thread *p)
711 struct uio io, *uiop = &io;
714 MALLOC(ivp, struct iovec *, cnt * sizeof (struct iovec), M_TEMP,
716 uiop->uio_iov = iv = ivp;
717 uiop->uio_iovcnt = cnt;
718 i = mtod(mp, caddr_t) + mp->m_len - cp;
722 panic("nfsvno_write");
733 cp = mtod(mp, caddr_t);
737 if (stable == NFSWRITE_UNSTABLE)
738 ioflags = IO_NODELOCKED;
740 ioflags = (IO_SYNC | IO_NODELOCKED);
741 uiop->uio_resid = retlen;
742 uiop->uio_rw = UIO_WRITE;
743 uiop->uio_segflg = UIO_SYSSPACE;
745 uiop->uio_offset = off;
746 nh = nfsrv_sequential_heuristic(uiop, vp);
747 ioflags |= nh->nh_seqcount << IO_SEQSHIFT;
748 error = VOP_WRITE(vp, uiop, ioflags, cred);
750 nh->nh_nextoff = uiop->uio_offset;
751 FREE((caddr_t)iv, M_TEMP);
758 * Common code for creating a regular file (plus special files for V2).
761 nfsvno_createsub(struct nfsrv_descript *nd, struct nameidata *ndp,
762 struct vnode **vpp, struct nfsvattr *nvap, int *exclusive_flagp,
763 int32_t *cverf, NFSDEV_T rdev, struct thread *p, struct nfsexstuff *exp)
768 error = nd->nd_repstat;
769 if (!error && ndp->ni_vp == NULL) {
770 if (nvap->na_type == VREG || nvap->na_type == VSOCK) {
771 vrele(ndp->ni_startdir);
772 error = VOP_CREATE(ndp->ni_dvp,
773 &ndp->ni_vp, &ndp->ni_cnd, &nvap->na_vattr);
775 nfsvno_relpathbuf(ndp);
777 if (*exclusive_flagp) {
778 *exclusive_flagp = 0;
779 NFSVNO_ATTRINIT(nvap);
780 nvap->na_atime.tv_sec = cverf[0];
781 nvap->na_atime.tv_nsec = cverf[1];
782 error = VOP_SETATTR(ndp->ni_vp,
783 &nvap->na_vattr, nd->nd_cred);
787 * NFS V2 Only. nfsrvd_mknod() does this for V3.
788 * (This implies, just get out on an error.)
790 } else if (nvap->na_type == VCHR || nvap->na_type == VBLK ||
791 nvap->na_type == VFIFO) {
792 if (nvap->na_type == VCHR && rdev == 0xffffffff)
793 nvap->na_type = VFIFO;
794 if (nvap->na_type != VFIFO &&
795 (error = priv_check_cred(nd->nd_cred,
796 PRIV_VFS_MKNOD_DEV, 0))) {
797 vrele(ndp->ni_startdir);
798 nfsvno_relpathbuf(ndp);
802 nvap->na_rdev = rdev;
803 error = VOP_MKNOD(ndp->ni_dvp, &ndp->ni_vp,
804 &ndp->ni_cnd, &nvap->na_vattr);
806 nfsvno_relpathbuf(ndp);
807 vrele(ndp->ni_startdir);
811 vrele(ndp->ni_startdir);
812 nfsvno_relpathbuf(ndp);
820 * Handle cases where error is already set and/or
822 * 1 - clean up the lookup
823 * 2 - iff !error and na_size set, truncate it
825 vrele(ndp->ni_startdir);
826 nfsvno_relpathbuf(ndp);
828 if (ndp->ni_dvp == *vpp)
832 if (!error && nvap->na_size != VNOVAL) {
833 error = nfsvno_accchk(*vpp, VWRITE,
834 nd->nd_cred, exp, p, NFSACCCHK_NOOVERRIDE,
835 NFSACCCHK_VPISLOCKED, NULL);
837 tempsize = nvap->na_size;
838 NFSVNO_ATTRINIT(nvap);
839 nvap->na_size = tempsize;
840 error = VOP_SETATTR(*vpp,
841 &nvap->na_vattr, nd->nd_cred);
854 * Do a mknod vnode op.
857 nfsvno_mknod(struct nameidata *ndp, struct nfsvattr *nvap, struct ucred *cred,
863 vtyp = nvap->na_type;
865 * Iff doesn't exist, create it.
868 vrele(ndp->ni_startdir);
869 nfsvno_relpathbuf(ndp);
875 if (vtyp != VCHR && vtyp != VBLK && vtyp != VSOCK && vtyp != VFIFO) {
876 vrele(ndp->ni_startdir);
877 nfsvno_relpathbuf(ndp);
879 error = NFSERR_BADTYPE;
883 vrele(ndp->ni_startdir);
884 error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp,
885 &ndp->ni_cnd, &nvap->na_vattr);
887 nfsvno_relpathbuf(ndp);
889 if (nvap->na_type != VFIFO &&
890 (error = priv_check_cred(cred, PRIV_VFS_MKNOD_DEV, 0))) {
891 vrele(ndp->ni_startdir);
892 nfsvno_relpathbuf(ndp);
896 error = VOP_MKNOD(ndp->ni_dvp, &ndp->ni_vp,
897 &ndp->ni_cnd, &nvap->na_vattr);
899 nfsvno_relpathbuf(ndp);
900 vrele(ndp->ni_startdir);
902 * Since VOP_MKNOD returns the ni_vp, I can't
903 * see any reason to do the lookup.
916 nfsvno_mkdir(struct nameidata *ndp, struct nfsvattr *nvap, uid_t saved_uid,
917 struct ucred *cred, struct thread *p, struct nfsexstuff *exp)
921 if (ndp->ni_vp != NULL) {
922 if (ndp->ni_dvp == ndp->ni_vp)
927 nfsvno_relpathbuf(ndp);
931 error = VOP_MKDIR(ndp->ni_dvp, &ndp->ni_vp, &ndp->ni_cnd,
934 nfsvno_relpathbuf(ndp);
945 nfsvno_symlink(struct nameidata *ndp, struct nfsvattr *nvap, char *pathcp,
946 int pathlen, int not_v2, uid_t saved_uid, struct ucred *cred, struct thread *p,
947 struct nfsexstuff *exp)
952 vrele(ndp->ni_startdir);
953 nfsvno_relpathbuf(ndp);
954 if (ndp->ni_dvp == ndp->ni_vp)
963 error = VOP_SYMLINK(ndp->ni_dvp, &ndp->ni_vp, &ndp->ni_cnd,
964 &nvap->na_vattr, pathcp);
966 vrele(ndp->ni_startdir);
967 nfsvno_relpathbuf(ndp);
969 * Although FreeBSD still had the lookup code in
970 * it for 7/current, there doesn't seem to be any
971 * point, since VOP_SYMLINK() returns the ni_vp.
972 * Just vput it for v2.
974 if (!not_v2 && !error)
983 * Parse symbolic link arguments.
984 * This function has an ugly side effect. It will MALLOC() an area for
985 * the symlink and set iov_base to point to it, only if it succeeds.
986 * So, if it returns with uiop->uio_iov->iov_base != NULL, that must
990 nfsvno_getsymlink(struct nfsrv_descript *nd, struct nfsvattr *nvap,
991 struct thread *p, char **pathcpp, int *lenp)
996 struct nfsv2_sattr *sp;
1000 if ((nd->nd_flag & ND_NFSV3) &&
1001 (error = nfsrv_sattr(nd, nvap, NULL, NULL, p)))
1003 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
1004 len = fxdr_unsigned(int, *tl);
1005 if (len > NFS_MAXPATHLEN || len <= 0) {
1009 MALLOC(pathcp, caddr_t, len + 1, M_TEMP, M_WAITOK);
1010 error = nfsrv_mtostr(nd, pathcp, len);
1013 if (nd->nd_flag & ND_NFSV2) {
1014 NFSM_DISSECT(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
1015 nvap->na_mode = fxdr_unsigned(u_int16_t, sp->sa_mode);
1019 NFSEXITCODE2(0, nd);
1023 free(pathcp, M_TEMP);
1024 NFSEXITCODE2(error, nd);
1029 * Remove a non-directory object.
1032 nfsvno_removesub(struct nameidata *ndp, int is_v4, struct ucred *cred,
1033 struct thread *p, struct nfsexstuff *exp)
1039 if (vp->v_type == VDIR)
1040 error = NFSERR_ISDIR;
1042 error = nfsrv_checkremove(vp, 1, p);
1044 error = VOP_REMOVE(ndp->ni_dvp, vp, &ndp->ni_cnd);
1045 if (ndp->ni_dvp == vp)
1050 if ((ndp->ni_cnd.cn_flags & SAVENAME) != 0)
1051 nfsvno_relpathbuf(ndp);
1057 * Remove a directory.
1060 nfsvno_rmdirsub(struct nameidata *ndp, int is_v4, struct ucred *cred,
1061 struct thread *p, struct nfsexstuff *exp)
1067 if (vp->v_type != VDIR) {
1072 * No rmdir "." please.
1074 if (ndp->ni_dvp == vp) {
1079 * The root of a mounted filesystem cannot be deleted.
1081 if (vp->v_vflag & VV_ROOT)
1085 error = VOP_RMDIR(ndp->ni_dvp, vp, &ndp->ni_cnd);
1086 if (ndp->ni_dvp == vp)
1091 if ((ndp->ni_cnd.cn_flags & SAVENAME) != 0)
1092 nfsvno_relpathbuf(ndp);
1101 nfsvno_rename(struct nameidata *fromndp, struct nameidata *tondp,
1102 u_int32_t ndstat, u_int32_t ndflag, struct ucred *cred, struct thread *p)
1104 struct vnode *fvp, *tvp, *tdvp;
1107 fvp = fromndp->ni_vp;
1109 vrele(fromndp->ni_dvp);
1114 tdvp = tondp->ni_dvp;
1117 if (fvp->v_type == VDIR && tvp->v_type != VDIR) {
1118 error = (ndflag & ND_NFSV2) ? EISDIR : EEXIST;
1120 } else if (fvp->v_type != VDIR && tvp->v_type == VDIR) {
1121 error = (ndflag & ND_NFSV2) ? ENOTDIR : EEXIST;
1124 if (tvp->v_type == VDIR && tvp->v_mountedhere) {
1125 error = (ndflag & ND_NFSV2) ? ENOTEMPTY : EXDEV;
1130 * A rename to '.' or '..' results in a prematurely
1131 * unlocked vnode on FreeBSD5, so I'm just going to fail that
1134 if ((tondp->ni_cnd.cn_namelen == 1 &&
1135 tondp->ni_cnd.cn_nameptr[0] == '.') ||
1136 (tondp->ni_cnd.cn_namelen == 2 &&
1137 tondp->ni_cnd.cn_nameptr[0] == '.' &&
1138 tondp->ni_cnd.cn_nameptr[1] == '.')) {
1143 if (fvp->v_type == VDIR && fvp->v_mountedhere) {
1144 error = (ndflag & ND_NFSV2) ? ENOTEMPTY : EXDEV;
1147 if (fvp->v_mount != tdvp->v_mount) {
1148 error = (ndflag & ND_NFSV2) ? ENOTEMPTY : EXDEV;
1152 error = (ndflag & ND_NFSV2) ? ENOTEMPTY : EINVAL;
1157 * If source and destination are the same, there is nothing to
1158 * do. Set error to -1 to indicate this.
1163 if (ndflag & ND_NFSV4) {
1164 if (NFSVOPLOCK(fvp, LK_EXCLUSIVE) == 0) {
1165 error = nfsrv_checkremove(fvp, 0, p);
1166 NFSVOPUNLOCK(fvp, 0);
1170 error = nfsrv_checkremove(tvp, 1, p);
1173 * For NFSv2 and NFSv3, try to get rid of the delegation, so
1174 * that the NFSv4 client won't be confused by the rename.
1175 * Since nfsd_recalldelegation() can only be called on an
1176 * unlocked vnode at this point and fvp is the file that will
1177 * still exist after the rename, just do fvp.
1179 nfsd_recalldelegation(fvp, p);
1183 error = VOP_RENAME(fromndp->ni_dvp, fromndp->ni_vp,
1184 &fromndp->ni_cnd, tondp->ni_dvp, tondp->ni_vp,
1193 vrele(fromndp->ni_dvp);
1198 vrele(tondp->ni_startdir);
1199 nfsvno_relpathbuf(tondp);
1201 vrele(fromndp->ni_startdir);
1202 nfsvno_relpathbuf(fromndp);
1211 nfsvno_link(struct nameidata *ndp, struct vnode *vp, struct ucred *cred,
1212 struct thread *p, struct nfsexstuff *exp)
1222 if (vp->v_mount != xp->v_mount)
1226 NFSVOPLOCK(vp, LK_EXCLUSIVE | LK_RETRY);
1227 if ((vp->v_iflag & VI_DOOMED) == 0)
1228 error = VOP_LINK(ndp->ni_dvp, vp, &ndp->ni_cnd);
1231 if (ndp->ni_dvp == vp)
1235 NFSVOPUNLOCK(vp, 0);
1237 if (ndp->ni_dvp == ndp->ni_vp)
1244 nfsvno_relpathbuf(ndp);
1250 * Do the fsync() appropriate for the commit.
1253 nfsvno_fsync(struct vnode *vp, u_int64_t off, int cnt, struct ucred *cred,
1259 * RFC 1813 3.3.21: if count is 0, a flush from offset to the end of
1260 * file is done. At this time VOP_FSYNC does not accept offset and
1261 * byte count parameters so call VOP_FSYNC the whole file for now.
1262 * The same is true for NFSv4: RFC 3530 Sec. 14.2.3.
1264 if (cnt == 0 || cnt > MAX_COMMIT_COUNT) {
1266 * Give up and do the whole thing
1269 (vp->v_object->flags & OBJ_MIGHTBEDIRTY)) {
1270 VM_OBJECT_WLOCK(vp->v_object);
1271 vm_object_page_clean(vp->v_object, 0, 0, OBJPC_SYNC);
1272 VM_OBJECT_WUNLOCK(vp->v_object);
1274 error = VOP_FSYNC(vp, MNT_WAIT, td);
1277 * Locate and synchronously write any buffers that fall
1278 * into the requested range. Note: we are assuming that
1279 * f_iosize is a power of 2.
1281 int iosize = vp->v_mount->mnt_stat.f_iosize;
1282 int iomask = iosize - 1;
1287 * Align to iosize boundry, super-align to page boundry.
1290 cnt += off & iomask;
1291 off &= ~(u_quad_t)iomask;
1293 if (off & PAGE_MASK) {
1294 cnt += off & PAGE_MASK;
1295 off &= ~(u_quad_t)PAGE_MASK;
1297 lblkno = off / iosize;
1300 (vp->v_object->flags & OBJ_MIGHTBEDIRTY)) {
1301 VM_OBJECT_WLOCK(vp->v_object);
1302 vm_object_page_clean(vp->v_object, off, off + cnt,
1304 VM_OBJECT_WUNLOCK(vp->v_object);
1313 * If we have a buffer and it is marked B_DELWRI we
1314 * have to lock and write it. Otherwise the prior
1315 * write is assumed to have already been committed.
1317 * gbincore() can return invalid buffers now so we
1318 * have to check that bit as well (though B_DELWRI
1319 * should not be set if B_INVAL is set there could be
1320 * a race here since we haven't locked the buffer).
1322 if ((bp = gbincore(&vp->v_bufobj, lblkno)) != NULL) {
1323 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_SLEEPFAIL |
1324 LK_INTERLOCK, BO_LOCKPTR(bo)) == ENOLCK) {
1326 continue; /* retry */
1328 if ((bp->b_flags & (B_DELWRI|B_INVAL)) ==
1331 bp->b_flags &= ~B_ASYNC;
1354 nfsvno_statfs(struct vnode *vp, struct statfs *sf)
1358 error = VFS_STATFS(vp->v_mount, sf);
1361 * Since NFS handles these values as unsigned on the
1362 * wire, there is no way to represent negative values,
1363 * so set them to 0. Without this, they will appear
1364 * to be very large positive values for clients like
1367 if (sf->f_bavail < 0)
1369 if (sf->f_ffree < 0)
1377 * Do the vnode op stuff for Open. Similar to nfsvno_createsub(), but
1378 * must handle nfsrv_opencheck() calls after any other access checks.
1381 nfsvno_open(struct nfsrv_descript *nd, struct nameidata *ndp,
1382 nfsquad_t clientid, nfsv4stateid_t *stateidp, struct nfsstate *stp,
1383 int *exclusive_flagp, struct nfsvattr *nvap, int32_t *cverf, int create,
1384 NFSACL_T *aclp, nfsattrbit_t *attrbitp, struct ucred *cred, struct thread *p,
1385 struct nfsexstuff *exp, struct vnode **vpp)
1387 struct vnode *vp = NULL;
1389 struct nfsexstuff nes;
1391 if (ndp->ni_vp == NULL)
1392 nd->nd_repstat = nfsrv_opencheck(clientid,
1393 stateidp, stp, NULL, nd, p, nd->nd_repstat);
1394 if (!nd->nd_repstat) {
1395 if (ndp->ni_vp == NULL) {
1396 vrele(ndp->ni_startdir);
1397 nd->nd_repstat = VOP_CREATE(ndp->ni_dvp,
1398 &ndp->ni_vp, &ndp->ni_cnd, &nvap->na_vattr);
1400 nfsvno_relpathbuf(ndp);
1401 if (!nd->nd_repstat) {
1402 if (*exclusive_flagp) {
1403 *exclusive_flagp = 0;
1404 NFSVNO_ATTRINIT(nvap);
1405 nvap->na_atime.tv_sec = cverf[0];
1406 nvap->na_atime.tv_nsec = cverf[1];
1407 nd->nd_repstat = VOP_SETATTR(ndp->ni_vp,
1408 &nvap->na_vattr, cred);
1410 nfsrv_fixattr(nd, ndp->ni_vp, nvap,
1411 aclp, p, attrbitp, exp);
1416 if (ndp->ni_startdir)
1417 vrele(ndp->ni_startdir);
1418 nfsvno_relpathbuf(ndp);
1420 if (create == NFSV4OPEN_CREATE) {
1421 if (ndp->ni_dvp == vp)
1426 if (NFSVNO_ISSETSIZE(nvap) && vp->v_type == VREG) {
1427 if (ndp->ni_cnd.cn_flags & RDONLY)
1428 NFSVNO_SETEXRDONLY(&nes);
1430 NFSVNO_EXINIT(&nes);
1431 nd->nd_repstat = nfsvno_accchk(vp,
1432 VWRITE, cred, &nes, p,
1433 NFSACCCHK_NOOVERRIDE,
1434 NFSACCCHK_VPISLOCKED, NULL);
1435 nd->nd_repstat = nfsrv_opencheck(clientid,
1436 stateidp, stp, vp, nd, p, nd->nd_repstat);
1437 if (!nd->nd_repstat) {
1438 tempsize = nvap->na_size;
1439 NFSVNO_ATTRINIT(nvap);
1440 nvap->na_size = tempsize;
1441 nd->nd_repstat = VOP_SETATTR(vp,
1442 &nvap->na_vattr, cred);
1444 } else if (vp->v_type == VREG) {
1445 nd->nd_repstat = nfsrv_opencheck(clientid,
1446 stateidp, stp, vp, nd, p, nd->nd_repstat);
1450 if (ndp->ni_cnd.cn_flags & HASBUF)
1451 nfsvno_relpathbuf(ndp);
1452 if (ndp->ni_startdir && create == NFSV4OPEN_CREATE) {
1453 vrele(ndp->ni_startdir);
1454 if (ndp->ni_dvp == ndp->ni_vp)
1464 NFSEXITCODE2(0, nd);
1468 * Updates the file rev and sets the mtime and ctime
1469 * to the current clock time, returning the va_filerev and va_Xtime
1473 nfsvno_updfilerev(struct vnode *vp, struct nfsvattr *nvap,
1474 struct ucred *cred, struct thread *p)
1479 vfs_timestamp(&va.va_mtime);
1480 (void) VOP_SETATTR(vp, &va, cred);
1481 (void) nfsvno_getattr(vp, nvap, cred, p, 1);
1485 * Glue routine to nfsv4_fillattr().
1488 nfsvno_fillattr(struct nfsrv_descript *nd, struct mount *mp, struct vnode *vp,
1489 struct nfsvattr *nvap, fhandle_t *fhp, int rderror, nfsattrbit_t *attrbitp,
1490 struct ucred *cred, struct thread *p, int isdgram, int reterr,
1491 int supports_nfsv4acls, int at_root, uint64_t mounted_on_fileno)
1495 error = nfsv4_fillattr(nd, mp, vp, NULL, &nvap->na_vattr, fhp, rderror,
1496 attrbitp, cred, p, isdgram, reterr, supports_nfsv4acls, at_root,
1498 NFSEXITCODE2(0, nd);
1502 /* Since the Readdir vnode ops vary, put the entire functions in here. */
1504 * nfs readdir service
1505 * - mallocs what it thinks is enough to read
1506 * count rounded up to a multiple of DIRBLKSIZ <= NFS_MAXREADDIR
1507 * - calls VOP_READDIR()
1508 * - loops around building the reply
1509 * if the output generated exceeds count break out of loop
1510 * The NFSM_CLGET macro is used here so that the reply will be packed
1511 * tightly in mbuf clusters.
1512 * - it trims out records with d_fileno == 0
1513 * this doesn't matter for Unix clients, but they might confuse clients
1515 * - it trims out records with d_type == DT_WHT
1516 * these cannot be seen through NFS (unless we extend the protocol)
1517 * The alternate call nfsrvd_readdirplus() does lookups as well.
1518 * PS: The NFS protocol spec. does not clarify what the "count" byte
1519 * argument is a count of.. just name strings and file id's or the
1520 * entire reply rpc or ...
1521 * I tried just file name and id sizes and it confused the Sun client,
1522 * so I am using the full rpc size now. The "paranoia.." comment refers
1523 * to including the status longwords that are not a part of the dir.
1524 * "entry" structures, but are in the rpc.
1527 nfsrvd_readdir(struct nfsrv_descript *nd, int isdgram,
1528 struct vnode *vp, struct thread *p, struct nfsexstuff *exp)
1533 char *cpos, *cend, *rbuf;
1535 int nlen, error = 0, getret = 1;
1536 int siz, cnt, fullsiz, eofflag, ncookies;
1537 u_int64_t off, toff, verf;
1538 u_long *cookies = NULL, *cookiep;
1543 if (nd->nd_repstat) {
1544 nfsrv_postopattr(nd, getret, &at);
1547 if (nd->nd_flag & ND_NFSV2) {
1548 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1549 off = fxdr_unsigned(u_quad_t, *tl++);
1551 NFSM_DISSECT(tl, u_int32_t *, 5 * NFSX_UNSIGNED);
1552 off = fxdr_hyper(tl);
1554 verf = fxdr_hyper(tl);
1558 cnt = fxdr_unsigned(int, *tl);
1559 if (cnt > NFS_SRVMAXDATA(nd) || cnt < 0)
1560 cnt = NFS_SRVMAXDATA(nd);
1561 siz = ((cnt + DIRBLKSIZ - 1) & ~(DIRBLKSIZ - 1));
1563 if (nd->nd_flag & ND_NFSV3) {
1564 nd->nd_repstat = getret = nfsvno_getattr(vp, &at, nd->nd_cred,
1568 * va_filerev is not sufficient as a cookie verifier,
1569 * since it is not supposed to change when entries are
1570 * removed/added unless that offset cookies returned to
1571 * the client are no longer valid.
1573 if (!nd->nd_repstat && toff && verf != at.na_filerev)
1574 nd->nd_repstat = NFSERR_BAD_COOKIE;
1577 if (!nd->nd_repstat && vp->v_type != VDIR)
1578 nd->nd_repstat = NFSERR_NOTDIR;
1579 if (nd->nd_repstat == 0 && cnt == 0) {
1580 if (nd->nd_flag & ND_NFSV2)
1581 /* NFSv2 does not have NFSERR_TOOSMALL */
1582 nd->nd_repstat = EPERM;
1584 nd->nd_repstat = NFSERR_TOOSMALL;
1586 if (!nd->nd_repstat)
1587 nd->nd_repstat = nfsvno_accchk(vp, VEXEC,
1588 nd->nd_cred, exp, p, NFSACCCHK_NOOVERRIDE,
1589 NFSACCCHK_VPISLOCKED, NULL);
1590 if (nd->nd_repstat) {
1592 if (nd->nd_flag & ND_NFSV3)
1593 nfsrv_postopattr(nd, getret, &at);
1596 not_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs");
1597 MALLOC(rbuf, caddr_t, siz, M_TEMP, M_WAITOK);
1601 free((caddr_t)cookies, M_TEMP);
1609 io.uio_offset = (off_t)off;
1611 io.uio_segflg = UIO_SYSSPACE;
1612 io.uio_rw = UIO_READ;
1614 nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag, &ncookies,
1616 off = (u_int64_t)io.uio_offset;
1618 siz -= io.uio_resid;
1620 if (!cookies && !nd->nd_repstat)
1621 nd->nd_repstat = NFSERR_PERM;
1622 if (nd->nd_flag & ND_NFSV3) {
1623 getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1);
1624 if (!nd->nd_repstat)
1625 nd->nd_repstat = getret;
1629 * Handles the failed cases. nd->nd_repstat == 0 past here.
1631 if (nd->nd_repstat) {
1633 free((caddr_t)rbuf, M_TEMP);
1635 free((caddr_t)cookies, M_TEMP);
1636 if (nd->nd_flag & ND_NFSV3)
1637 nfsrv_postopattr(nd, getret, &at);
1641 * If nothing read, return eof
1646 if (nd->nd_flag & ND_NFSV2) {
1647 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1649 nfsrv_postopattr(nd, getret, &at);
1650 NFSM_BUILD(tl, u_int32_t *, 4 * NFSX_UNSIGNED);
1651 txdr_hyper(at.na_filerev, tl);
1654 *tl++ = newnfs_false;
1656 FREE((caddr_t)rbuf, M_TEMP);
1657 FREE((caddr_t)cookies, M_TEMP);
1662 * Check for degenerate cases of nothing useful read.
1663 * If so go try again
1667 dp = (struct dirent *)cpos;
1671 * For some reason FreeBSD's ufs_readdir() chooses to back the
1672 * directory offset up to a block boundary, so it is necessary to
1673 * skip over the records that precede the requested offset. This
1674 * requires the assumption that file offset cookies monotonically
1676 * Since the offset cookies don't monotonically increase for ZFS,
1677 * this is not done when ZFS is the file system.
1679 while (cpos < cend && ncookies > 0 &&
1680 (dp->d_fileno == 0 || dp->d_type == DT_WHT ||
1681 (not_zfs != 0 && ((u_quad_t)(*cookiep)) <= toff))) {
1682 cpos += dp->d_reclen;
1683 dp = (struct dirent *)cpos;
1687 if (cpos >= cend || ncookies == 0) {
1695 * dirlen is the size of the reply, including all XDR and must
1696 * not exceed cnt. For NFSv2, RFC1094 didn't clearly indicate
1697 * if the XDR should be included in "count", but to be safe, we do.
1698 * (Include the two booleans at the end of the reply in dirlen now.)
1700 if (nd->nd_flag & ND_NFSV3) {
1701 nfsrv_postopattr(nd, getret, &at);
1702 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1703 txdr_hyper(at.na_filerev, tl);
1704 dirlen = NFSX_V3POSTOPATTR + NFSX_VERF + 2 * NFSX_UNSIGNED;
1706 dirlen = 2 * NFSX_UNSIGNED;
1709 /* Loop through the records and build reply */
1710 while (cpos < cend && ncookies > 0) {
1711 nlen = dp->d_namlen;
1712 if (dp->d_fileno != 0 && dp->d_type != DT_WHT &&
1713 nlen <= NFS_MAXNAMLEN) {
1714 if (nd->nd_flag & ND_NFSV3)
1715 dirlen += (6*NFSX_UNSIGNED + NFSM_RNDUP(nlen));
1717 dirlen += (4*NFSX_UNSIGNED + NFSM_RNDUP(nlen));
1724 * Build the directory record xdr from
1727 if (nd->nd_flag & ND_NFSV3) {
1728 NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
1729 *tl++ = newnfs_true;
1732 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1733 *tl++ = newnfs_true;
1735 *tl = txdr_unsigned(dp->d_fileno);
1736 (void) nfsm_strtom(nd, dp->d_name, nlen);
1737 if (nd->nd_flag & ND_NFSV3) {
1738 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1741 NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
1742 *tl = txdr_unsigned(*cookiep);
1744 cpos += dp->d_reclen;
1745 dp = (struct dirent *)cpos;
1751 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1752 *tl++ = newnfs_false;
1757 FREE((caddr_t)rbuf, M_TEMP);
1758 FREE((caddr_t)cookies, M_TEMP);
1761 NFSEXITCODE2(0, nd);
1765 NFSEXITCODE2(error, nd);
1770 * Readdirplus for V3 and Readdir for V4.
1773 nfsrvd_readdirplus(struct nfsrv_descript *nd, int isdgram,
1774 struct vnode *vp, struct thread *p, struct nfsexstuff *exp)
1779 char *cpos, *cend, *rbuf;
1782 struct nfsvattr nva, at, *nvap = &nva;
1783 struct mbuf *mb0, *mb1;
1784 struct nfsreferral *refp;
1785 int nlen, r, error = 0, getret = 1, usevget = 1;
1786 int siz, cnt, fullsiz, eofflag, ncookies, entrycnt;
1787 caddr_t bpos0, bpos1;
1788 u_int64_t off, toff, verf;
1789 u_long *cookies = NULL, *cookiep;
1790 nfsattrbit_t attrbits, rderrbits, savbits;
1793 struct componentname cn;
1794 int at_root, needs_unbusy, not_zfs, supports_nfsv4acls;
1795 struct mount *mp, *new_mp;
1796 uint64_t mounted_on_fileno;
1798 if (nd->nd_repstat) {
1799 nfsrv_postopattr(nd, getret, &at);
1802 NFSM_DISSECT(tl, u_int32_t *, 6 * NFSX_UNSIGNED);
1803 off = fxdr_hyper(tl);
1806 verf = fxdr_hyper(tl);
1808 siz = fxdr_unsigned(int, *tl++);
1809 cnt = fxdr_unsigned(int, *tl);
1812 * Use the server's maximum data transfer size as the upper bound
1815 if (cnt > NFS_SRVMAXDATA(nd) || cnt < 0)
1816 cnt = NFS_SRVMAXDATA(nd);
1819 * siz is a "hint" of how much directory information (name, fileid,
1820 * cookie) should be in the reply. At least one client "hints" 0,
1821 * so I set it to cnt for that case. I also round it up to the
1822 * next multiple of DIRBLKSIZ.
1826 siz = ((siz + DIRBLKSIZ - 1) & ~(DIRBLKSIZ - 1));
1828 if (nd->nd_flag & ND_NFSV4) {
1829 error = nfsrv_getattrbits(nd, &attrbits, NULL, NULL);
1832 NFSSET_ATTRBIT(&savbits, &attrbits);
1833 NFSCLRNOTFILLABLE_ATTRBIT(&attrbits);
1834 NFSZERO_ATTRBIT(&rderrbits);
1835 NFSSETBIT_ATTRBIT(&rderrbits, NFSATTRBIT_RDATTRERROR);
1837 NFSZERO_ATTRBIT(&attrbits);
1840 nd->nd_repstat = getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1);
1841 if (!nd->nd_repstat) {
1842 if (off && verf != at.na_filerev) {
1844 * va_filerev is not sufficient as a cookie verifier,
1845 * since it is not supposed to change when entries are
1846 * removed/added unless that offset cookies returned to
1847 * the client are no longer valid.
1850 if (nd->nd_flag & ND_NFSV4) {
1851 nd->nd_repstat = NFSERR_NOTSAME;
1853 nd->nd_repstat = NFSERR_BAD_COOKIE;
1856 } else if ((nd->nd_flag & ND_NFSV4) && off == 0 && verf != 0) {
1857 nd->nd_repstat = NFSERR_BAD_COOKIE;
1860 if (!nd->nd_repstat && vp->v_type != VDIR)
1861 nd->nd_repstat = NFSERR_NOTDIR;
1862 if (!nd->nd_repstat && cnt == 0)
1863 nd->nd_repstat = NFSERR_TOOSMALL;
1864 if (!nd->nd_repstat)
1865 nd->nd_repstat = nfsvno_accchk(vp, VEXEC,
1866 nd->nd_cred, exp, p, NFSACCCHK_NOOVERRIDE,
1867 NFSACCCHK_VPISLOCKED, NULL);
1868 if (nd->nd_repstat) {
1870 if (nd->nd_flag & ND_NFSV3)
1871 nfsrv_postopattr(nd, getret, &at);
1874 not_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs");
1876 MALLOC(rbuf, caddr_t, siz, M_TEMP, M_WAITOK);
1880 free((caddr_t)cookies, M_TEMP);
1888 io.uio_offset = (off_t)off;
1890 io.uio_segflg = UIO_SYSSPACE;
1891 io.uio_rw = UIO_READ;
1893 nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag, &ncookies,
1895 off = (u_int64_t)io.uio_offset;
1897 siz -= io.uio_resid;
1899 getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1);
1901 if (!cookies && !nd->nd_repstat)
1902 nd->nd_repstat = NFSERR_PERM;
1903 if (!nd->nd_repstat)
1904 nd->nd_repstat = getret;
1905 if (nd->nd_repstat) {
1908 free((caddr_t)cookies, M_TEMP);
1909 free((caddr_t)rbuf, M_TEMP);
1910 if (nd->nd_flag & ND_NFSV3)
1911 nfsrv_postopattr(nd, getret, &at);
1915 * If nothing read, return eof
1920 if (nd->nd_flag & ND_NFSV3)
1921 nfsrv_postopattr(nd, getret, &at);
1922 NFSM_BUILD(tl, u_int32_t *, 4 * NFSX_UNSIGNED);
1923 txdr_hyper(at.na_filerev, tl);
1925 *tl++ = newnfs_false;
1927 free((caddr_t)cookies, M_TEMP);
1928 free((caddr_t)rbuf, M_TEMP);
1933 * Check for degenerate cases of nothing useful read.
1934 * If so go try again
1938 dp = (struct dirent *)cpos;
1942 * For some reason FreeBSD's ufs_readdir() chooses to back the
1943 * directory offset up to a block boundary, so it is necessary to
1944 * skip over the records that precede the requested offset. This
1945 * requires the assumption that file offset cookies monotonically
1947 * Since the offset cookies don't monotonically increase for ZFS,
1948 * this is not done when ZFS is the file system.
1950 while (cpos < cend && ncookies > 0 &&
1951 (dp->d_fileno == 0 || dp->d_type == DT_WHT ||
1952 (not_zfs != 0 && ((u_quad_t)(*cookiep)) <= toff) ||
1953 ((nd->nd_flag & ND_NFSV4) &&
1954 ((dp->d_namlen == 1 && dp->d_name[0] == '.') ||
1955 (dp->d_namlen==2 && dp->d_name[0]=='.' && dp->d_name[1]=='.'))))) {
1956 cpos += dp->d_reclen;
1957 dp = (struct dirent *)cpos;
1961 if (cpos >= cend || ncookies == 0) {
1968 * Busy the file system so that the mount point won't go away
1969 * and, as such, VFS_VGET() can be used safely.
1973 NFSVOPUNLOCK(vp, 0);
1974 nd->nd_repstat = vfs_busy(mp, 0);
1976 if (nd->nd_repstat != 0) {
1978 free(cookies, M_TEMP);
1980 if (nd->nd_flag & ND_NFSV3)
1981 nfsrv_postopattr(nd, getret, &at);
1986 * Save this position, in case there is an error before one entry
1990 bpos0 = nd->nd_bpos;
1993 * Fill in the first part of the reply.
1994 * dirlen is the reply length in bytes and cannot exceed cnt.
1995 * (Include the two booleans at the end of the reply in dirlen now,
1996 * so we recognize when we have exceeded cnt.)
1998 if (nd->nd_flag & ND_NFSV3) {
1999 dirlen = NFSX_V3POSTOPATTR + NFSX_VERF + 2 * NFSX_UNSIGNED;
2000 nfsrv_postopattr(nd, getret, &at);
2002 dirlen = NFSX_VERF + 2 * NFSX_UNSIGNED;
2004 NFSM_BUILD(tl, u_int32_t *, NFSX_VERF);
2005 txdr_hyper(at.na_filerev, tl);
2008 * Save this position, in case there is an empty reply needed.
2011 bpos1 = nd->nd_bpos;
2013 /* Loop through the records and build reply */
2015 while (cpos < cend && ncookies > 0 && dirlen < cnt) {
2016 nlen = dp->d_namlen;
2017 if (dp->d_fileno != 0 && dp->d_type != DT_WHT &&
2018 nlen <= NFS_MAXNAMLEN &&
2019 ((nd->nd_flag & ND_NFSV3) || nlen > 2 ||
2020 (nlen==2 && (dp->d_name[0]!='.' || dp->d_name[1]!='.'))
2021 || (nlen == 1 && dp->d_name[0] != '.'))) {
2023 * Save the current position in the reply, in case
2024 * this entry exceeds cnt.
2027 bpos1 = nd->nd_bpos;
2030 * For readdir_and_lookup get the vnode using
2039 mounted_on_fileno = (uint64_t)dp->d_fileno;
2040 if ((nd->nd_flag & ND_NFSV3) ||
2041 NFSNONZERO_ATTRBIT(&savbits)) {
2042 if (nd->nd_flag & ND_NFSV4)
2043 refp = nfsv4root_getreferral(NULL,
2047 r = VFS_VGET(mp, dp->d_fileno,
2051 if (r == EOPNOTSUPP) {
2054 cn.cn_nameiop = LOOKUP;
2062 cn.cn_nameptr = dp->d_name;
2063 cn.cn_namelen = nlen;
2064 cn.cn_flags = ISLASTCN |
2065 NOFOLLOW | LOCKLEAF;
2067 dp->d_name[0] == '.' &&
2068 dp->d_name[1] == '.')
2071 if (NFSVOPLOCK(vp, LK_SHARED)
2073 nd->nd_repstat = EPERM;
2076 if ((vp->v_vflag & VV_ROOT) != 0
2077 && (cn.cn_flags & ISDOTDOT)
2083 r = VOP_LOOKUP(vp, &nvp,
2092 * For NFSv4, check to see if nvp is
2093 * a mount point and get the mount
2094 * point vnode, as required.
2097 nfsrv_enable_crossmntpt != 0 &&
2098 (nd->nd_flag & ND_NFSV4) != 0 &&
2099 nvp->v_type == VDIR &&
2100 nvp->v_mountedhere != NULL) {
2101 new_mp = nvp->v_mountedhere;
2102 r = vfs_busy(new_mp, 0);
2106 r = VFS_ROOT(new_mp,
2116 ((nd->nd_flag & ND_NFSV3) ||
2117 NFSNONZERO_ATTRBIT(&attrbits))) {
2118 r = nfsvno_getfh(nvp, &nfh, p);
2120 r = nfsvno_getattr(nvp, nvap,
2127 if (!NFSISSET_ATTRBIT(&attrbits,
2128 NFSATTRBIT_RDATTRERROR)) {
2131 if (needs_unbusy != 0)
2140 * Build the directory record xdr
2142 if (nd->nd_flag & ND_NFSV3) {
2143 NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
2144 *tl++ = newnfs_true;
2146 *tl = txdr_unsigned(dp->d_fileno);
2147 dirlen += nfsm_strtom(nd, dp->d_name, nlen);
2148 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2150 *tl = txdr_unsigned(*cookiep);
2151 nfsrv_postopattr(nd, 0, nvap);
2152 dirlen += nfsm_fhtom(nd,(u_int8_t *)&nfh,0,1);
2153 dirlen += (5*NFSX_UNSIGNED+NFSX_V3POSTOPATTR);
2157 NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
2158 *tl++ = newnfs_true;
2160 *tl = txdr_unsigned(*cookiep);
2161 dirlen += nfsm_strtom(nd, dp->d_name, nlen);
2163 supports_nfsv4acls =
2164 nfs_supportsnfsv4acls(nvp);
2165 NFSVOPUNLOCK(nvp, 0);
2167 supports_nfsv4acls = 0;
2169 dirlen += nfsrv_putreferralattr(nd,
2172 if (nd->nd_repstat) {
2175 if (needs_unbusy != 0)
2180 dirlen += nfsvno_fillattr(nd, new_mp,
2181 nvp, nvap, &nfh, r, &rderrbits,
2182 nd->nd_cred, p, isdgram, 0,
2183 supports_nfsv4acls, at_root,
2186 dirlen += nfsvno_fillattr(nd, new_mp,
2187 nvp, nvap, &nfh, r, &attrbits,
2188 nd->nd_cred, p, isdgram, 0,
2189 supports_nfsv4acls, at_root,
2194 dirlen += (3 * NFSX_UNSIGNED);
2196 if (needs_unbusy != 0)
2201 cpos += dp->d_reclen;
2202 dp = (struct dirent *)cpos;
2210 * If dirlen > cnt, we must strip off the last entry. If that
2211 * results in an empty reply, report NFSERR_TOOSMALL.
2213 if (dirlen > cnt || nd->nd_repstat) {
2214 if (!nd->nd_repstat && entrycnt == 0)
2215 nd->nd_repstat = NFSERR_TOOSMALL;
2217 newnfs_trimtrailing(nd, mb0, bpos0);
2219 newnfs_trimtrailing(nd, mb1, bpos1);
2221 } else if (cpos < cend)
2223 if (!nd->nd_repstat) {
2224 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2225 *tl++ = newnfs_false;
2231 FREE((caddr_t)cookies, M_TEMP);
2232 FREE((caddr_t)rbuf, M_TEMP);
2235 NFSEXITCODE2(0, nd);
2239 NFSEXITCODE2(error, nd);
2244 * Get the settable attributes out of the mbuf list.
2245 * (Return 0 or EBADRPC)
2248 nfsrv_sattr(struct nfsrv_descript *nd, struct nfsvattr *nvap,
2249 nfsattrbit_t *attrbitp, NFSACL_T *aclp, struct thread *p)
2252 struct nfsv2_sattr *sp;
2253 int error = 0, toclient = 0;
2255 switch (nd->nd_flag & (ND_NFSV2 | ND_NFSV3 | ND_NFSV4)) {
2257 NFSM_DISSECT(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
2259 * Some old clients didn't fill in the high order 16bits.
2260 * --> check the low order 2 bytes for 0xffff
2262 if ((fxdr_unsigned(int, sp->sa_mode) & 0xffff) != 0xffff)
2263 nvap->na_mode = nfstov_mode(sp->sa_mode);
2264 if (sp->sa_uid != newnfs_xdrneg1)
2265 nvap->na_uid = fxdr_unsigned(uid_t, sp->sa_uid);
2266 if (sp->sa_gid != newnfs_xdrneg1)
2267 nvap->na_gid = fxdr_unsigned(gid_t, sp->sa_gid);
2268 if (sp->sa_size != newnfs_xdrneg1)
2269 nvap->na_size = fxdr_unsigned(u_quad_t, sp->sa_size);
2270 if (sp->sa_atime.nfsv2_sec != newnfs_xdrneg1) {
2272 fxdr_nfsv2time(&sp->sa_atime, &nvap->na_atime);
2274 nvap->na_atime.tv_sec =
2275 fxdr_unsigned(u_int32_t,sp->sa_atime.nfsv2_sec);
2276 nvap->na_atime.tv_nsec = 0;
2279 if (sp->sa_mtime.nfsv2_sec != newnfs_xdrneg1)
2280 fxdr_nfsv2time(&sp->sa_mtime, &nvap->na_mtime);
2283 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2284 if (*tl == newnfs_true) {
2285 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2286 nvap->na_mode = nfstov_mode(*tl);
2288 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2289 if (*tl == newnfs_true) {
2290 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2291 nvap->na_uid = fxdr_unsigned(uid_t, *tl);
2293 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2294 if (*tl == newnfs_true) {
2295 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2296 nvap->na_gid = fxdr_unsigned(gid_t, *tl);
2298 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2299 if (*tl == newnfs_true) {
2300 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2301 nvap->na_size = fxdr_hyper(tl);
2303 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2304 switch (fxdr_unsigned(int, *tl)) {
2305 case NFSV3SATTRTIME_TOCLIENT:
2306 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2307 fxdr_nfsv3time(tl, &nvap->na_atime);
2310 case NFSV3SATTRTIME_TOSERVER:
2311 vfs_timestamp(&nvap->na_atime);
2312 nvap->na_vaflags |= VA_UTIMES_NULL;
2315 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2316 switch (fxdr_unsigned(int, *tl)) {
2317 case NFSV3SATTRTIME_TOCLIENT:
2318 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2319 fxdr_nfsv3time(tl, &nvap->na_mtime);
2320 nvap->na_vaflags &= ~VA_UTIMES_NULL;
2322 case NFSV3SATTRTIME_TOSERVER:
2323 vfs_timestamp(&nvap->na_mtime);
2325 nvap->na_vaflags |= VA_UTIMES_NULL;
2330 error = nfsv4_sattr(nd, nvap, attrbitp, aclp, p);
2333 NFSEXITCODE2(error, nd);
2338 * Handle the setable attributes for V4.
2339 * Returns NFSERR_BADXDR if it can't be parsed, 0 otherwise.
2342 nfsv4_sattr(struct nfsrv_descript *nd, struct nfsvattr *nvap,
2343 nfsattrbit_t *attrbitp, NFSACL_T *aclp, struct thread *p)
2348 int error, attrsize, bitpos, aclsize, aceerr, retnotsup = 0;
2350 u_char *cp, namestr[NFSV4_SMALLSTR + 1];
2354 error = nfsrv_getattrbits(nd, attrbitp, NULL, &retnotsup);
2357 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2358 attrsize = fxdr_unsigned(int, *tl);
2361 * Loop around getting the setable attributes. If an unsupported
2362 * one is found, set nd_repstat == NFSERR_ATTRNOTSUPP and return.
2365 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2366 bitpos = NFSATTRBIT_MAX;
2370 for (; bitpos < NFSATTRBIT_MAX; bitpos++) {
2371 if (attrsum > attrsize) {
2372 error = NFSERR_BADXDR;
2375 if (NFSISSET_ATTRBIT(attrbitp, bitpos))
2377 case NFSATTRBIT_SIZE:
2378 NFSM_DISSECT(tl, u_int32_t *, NFSX_HYPER);
2379 nvap->na_size = fxdr_hyper(tl);
2380 attrsum += NFSX_HYPER;
2382 case NFSATTRBIT_ACL:
2383 error = nfsrv_dissectacl(nd, aclp, &aceerr, &aclsize,
2387 if (aceerr && !nd->nd_repstat)
2388 nd->nd_repstat = aceerr;
2391 case NFSATTRBIT_ARCHIVE:
2392 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2393 if (!nd->nd_repstat)
2394 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2395 attrsum += NFSX_UNSIGNED;
2397 case NFSATTRBIT_HIDDEN:
2398 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2399 if (!nd->nd_repstat)
2400 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2401 attrsum += NFSX_UNSIGNED;
2403 case NFSATTRBIT_MIMETYPE:
2404 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2405 i = fxdr_unsigned(int, *tl);
2406 error = nfsm_advance(nd, NFSM_RNDUP(i), -1);
2409 if (!nd->nd_repstat)
2410 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2411 attrsum += (NFSX_UNSIGNED + NFSM_RNDUP(i));
2413 case NFSATTRBIT_MODE:
2414 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2415 nvap->na_mode = nfstov_mode(*tl);
2416 attrsum += NFSX_UNSIGNED;
2418 case NFSATTRBIT_OWNER:
2419 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2420 j = fxdr_unsigned(int, *tl);
2422 error = NFSERR_BADXDR;
2425 if (j > NFSV4_SMALLSTR)
2426 cp = malloc(j + 1, M_NFSSTRING, M_WAITOK);
2429 error = nfsrv_mtostr(nd, cp, j);
2431 if (j > NFSV4_SMALLSTR)
2432 free(cp, M_NFSSTRING);
2435 if (!nd->nd_repstat) {
2436 nd->nd_repstat = nfsv4_strtouid(nd, cp, j, &uid,
2438 if (!nd->nd_repstat)
2441 if (j > NFSV4_SMALLSTR)
2442 free(cp, M_NFSSTRING);
2443 attrsum += (NFSX_UNSIGNED + NFSM_RNDUP(j));
2445 case NFSATTRBIT_OWNERGROUP:
2446 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2447 j = fxdr_unsigned(int, *tl);
2449 error = NFSERR_BADXDR;
2452 if (j > NFSV4_SMALLSTR)
2453 cp = malloc(j + 1, M_NFSSTRING, M_WAITOK);
2456 error = nfsrv_mtostr(nd, cp, j);
2458 if (j > NFSV4_SMALLSTR)
2459 free(cp, M_NFSSTRING);
2462 if (!nd->nd_repstat) {
2463 nd->nd_repstat = nfsv4_strtogid(nd, cp, j, &gid,
2465 if (!nd->nd_repstat)
2468 if (j > NFSV4_SMALLSTR)
2469 free(cp, M_NFSSTRING);
2470 attrsum += (NFSX_UNSIGNED + NFSM_RNDUP(j));
2472 case NFSATTRBIT_SYSTEM:
2473 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2474 if (!nd->nd_repstat)
2475 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2476 attrsum += NFSX_UNSIGNED;
2478 case NFSATTRBIT_TIMEACCESSSET:
2479 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2480 attrsum += NFSX_UNSIGNED;
2481 if (fxdr_unsigned(int, *tl)==NFSV4SATTRTIME_TOCLIENT) {
2482 NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME);
2483 fxdr_nfsv4time(tl, &nvap->na_atime);
2485 attrsum += NFSX_V4TIME;
2487 vfs_timestamp(&nvap->na_atime);
2488 nvap->na_vaflags |= VA_UTIMES_NULL;
2491 case NFSATTRBIT_TIMEBACKUP:
2492 NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME);
2493 if (!nd->nd_repstat)
2494 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2495 attrsum += NFSX_V4TIME;
2497 case NFSATTRBIT_TIMECREATE:
2498 NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME);
2499 if (!nd->nd_repstat)
2500 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2501 attrsum += NFSX_V4TIME;
2503 case NFSATTRBIT_TIMEMODIFYSET:
2504 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2505 attrsum += NFSX_UNSIGNED;
2506 if (fxdr_unsigned(int, *tl)==NFSV4SATTRTIME_TOCLIENT) {
2507 NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME);
2508 fxdr_nfsv4time(tl, &nvap->na_mtime);
2509 nvap->na_vaflags &= ~VA_UTIMES_NULL;
2510 attrsum += NFSX_V4TIME;
2512 vfs_timestamp(&nvap->na_mtime);
2514 nvap->na_vaflags |= VA_UTIMES_NULL;
2518 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2520 * set bitpos so we drop out of the loop.
2522 bitpos = NFSATTRBIT_MAX;
2528 * some clients pad the attrlist, so we need to skip over the
2531 if (attrsum > attrsize) {
2532 error = NFSERR_BADXDR;
2534 attrsize = NFSM_RNDUP(attrsize);
2535 if (attrsum < attrsize)
2536 error = nfsm_advance(nd, attrsize - attrsum, -1);
2539 NFSEXITCODE2(error, nd);
2544 * Check/setup export credentials.
2547 nfsd_excred(struct nfsrv_descript *nd, struct nfsexstuff *exp,
2548 struct ucred *credanon)
2553 * Check/setup credentials.
2555 if (nd->nd_flag & ND_GSS)
2556 exp->nes_exflag &= ~MNT_EXPORTANON;
2559 * Check to see if the operation is allowed for this security flavor.
2560 * RFC2623 suggests that the NFSv3 Fsinfo RPC be allowed to
2561 * AUTH_NONE or AUTH_SYS for file systems requiring RPCSEC_GSS.
2562 * Also, allow Secinfo, so that it can acquire the correct flavor(s).
2564 if (nfsvno_testexp(nd, exp) &&
2565 nd->nd_procnum != NFSV4OP_SECINFO &&
2566 nd->nd_procnum != NFSPROC_FSINFO) {
2567 if (nd->nd_flag & ND_NFSV4)
2568 error = NFSERR_WRONGSEC;
2570 error = (NFSERR_AUTHERR | AUTH_TOOWEAK);
2575 * Check to see if the file system is exported V4 only.
2577 if (NFSVNO_EXV4ONLY(exp) && !(nd->nd_flag & ND_NFSV4)) {
2578 error = NFSERR_PROGNOTV4;
2583 * Now, map the user credentials.
2584 * (Note that ND_AUTHNONE will only be set for an NFSv3
2585 * Fsinfo RPC. If set for anything else, this code might need
2588 if (NFSVNO_EXPORTED(exp) &&
2589 ((!(nd->nd_flag & ND_GSS) && nd->nd_cred->cr_uid == 0) ||
2590 NFSVNO_EXPORTANON(exp) ||
2591 (nd->nd_flag & ND_AUTHNONE))) {
2592 nd->nd_cred->cr_uid = credanon->cr_uid;
2593 nd->nd_cred->cr_gid = credanon->cr_gid;
2594 crsetgroups(nd->nd_cred, credanon->cr_ngroups,
2595 credanon->cr_groups);
2599 NFSEXITCODE2(error, nd);
2607 nfsvno_checkexp(struct mount *mp, struct sockaddr *nam, struct nfsexstuff *exp,
2608 struct ucred **credp)
2610 int i, error, *secflavors;
2612 error = VFS_CHECKEXP(mp, nam, &exp->nes_exflag, credp,
2613 &exp->nes_numsecflavor, &secflavors);
2615 if (nfs_rootfhset) {
2616 exp->nes_exflag = 0;
2617 exp->nes_numsecflavor = 0;
2621 /* Copy the security flavors. */
2622 for (i = 0; i < exp->nes_numsecflavor; i++)
2623 exp->nes_secflavors[i] = secflavors[i];
2630 * Get a vnode for a file handle and export stuff.
2633 nfsvno_fhtovp(struct mount *mp, fhandle_t *fhp, struct sockaddr *nam,
2634 int lktype, struct vnode **vpp, struct nfsexstuff *exp,
2635 struct ucred **credp)
2637 int i, error, *secflavors;
2640 exp->nes_numsecflavor = 0;
2641 error = VFS_FHTOVP(mp, &fhp->fh_fid, lktype, vpp);
2643 /* Make sure the server replies ESTALE to the client. */
2645 if (nam && !error) {
2646 error = VFS_CHECKEXP(mp, nam, &exp->nes_exflag, credp,
2647 &exp->nes_numsecflavor, &secflavors);
2649 if (nfs_rootfhset) {
2650 exp->nes_exflag = 0;
2651 exp->nes_numsecflavor = 0;
2657 /* Copy the security flavors. */
2658 for (i = 0; i < exp->nes_numsecflavor; i++)
2659 exp->nes_secflavors[i] = secflavors[i];
2667 * nfsd_fhtovp() - convert a fh to a vnode ptr
2668 * - look up fsid in mount list (if not found ret error)
2669 * - get vp and export rights by calling nfsvno_fhtovp()
2670 * - if cred->cr_uid == 0 or MNT_EXPORTANON set it to credanon
2672 * - if mpp != NULL, return the mount point so that it can
2673 * be used for vn_finished_write() by the caller
2676 nfsd_fhtovp(struct nfsrv_descript *nd, struct nfsrvfh *nfp, int lktype,
2677 struct vnode **vpp, struct nfsexstuff *exp,
2678 struct mount **mpp, int startwrite, struct thread *p)
2681 struct ucred *credanon;
2684 fhp = (fhandle_t *)nfp->nfsrvfh_data;
2686 * Check for the special case of the nfsv4root_fh.
2688 mp = vfs_busyfs(&fhp->fh_fsid);
2693 nd->nd_repstat = ESTALE;
2698 vn_start_write(NULL, mpp, V_WAIT);
2699 if (lktype == LK_SHARED && !(MNT_SHARED_WRITES(mp)))
2700 lktype = LK_EXCLUSIVE;
2702 nd->nd_repstat = nfsvno_fhtovp(mp, fhp, nd->nd_nam, lktype, vpp, exp,
2707 * For NFSv4 without a pseudo root fs, unexported file handles
2708 * can be returned, so that Lookup works everywhere.
2710 if (!nd->nd_repstat && exp->nes_exflag == 0 &&
2711 !(nd->nd_flag & ND_NFSV4)) {
2713 nd->nd_repstat = EACCES;
2717 * Personally, I've never seen any point in requiring a
2718 * reserved port#, since only in the rare case where the
2719 * clients are all boxes with secure system priviledges,
2720 * does it provide any enhanced security, but... some people
2721 * believe it to be useful and keep putting this code back in.
2722 * (There is also some "security checker" out there that
2723 * complains if the nfs server doesn't enforce this.)
2724 * However, note the following:
2725 * RFC3530 (NFSv4) specifies that a reserved port# not be
2727 * RFC2623 recommends that, if a reserved port# is checked for,
2728 * that there be a way to turn that off--> ifdef'd.
2730 #ifdef NFS_REQRSVPORT
2731 if (!nd->nd_repstat) {
2732 struct sockaddr_in *saddr;
2733 struct sockaddr_in6 *saddr6;
2735 saddr = NFSSOCKADDR(nd->nd_nam, struct sockaddr_in *);
2736 saddr6 = NFSSOCKADDR(nd->nd_nam, struct sockaddr_in6 *);
2737 if (!(nd->nd_flag & ND_NFSV4) &&
2738 ((saddr->sin_family == AF_INET &&
2739 ntohs(saddr->sin_port) >= IPPORT_RESERVED) ||
2740 (saddr6->sin6_family == AF_INET6 &&
2741 ntohs(saddr6->sin6_port) >= IPPORT_RESERVED))) {
2743 nd->nd_repstat = (NFSERR_AUTHERR | AUTH_TOOWEAK);
2746 #endif /* NFS_REQRSVPORT */
2749 * Check/setup credentials.
2751 if (!nd->nd_repstat) {
2752 nd->nd_saveduid = nd->nd_cred->cr_uid;
2753 nd->nd_repstat = nfsd_excred(nd, exp, credanon);
2757 if (credanon != NULL)
2759 if (nd->nd_repstat) {
2761 vn_finished_write(mp);
2768 NFSEXITCODE2(0, nd);
2775 fp_getfvp(struct thread *p, int fd, struct file **fpp, struct vnode **vpp)
2777 struct filedesc *fdp;
2781 fdp = p->td_proc->p_fd;
2782 if (fd < 0 || fd >= fdp->fd_nfiles ||
2783 (fp = fdp->fd_ofiles[fd].fde_file) == NULL) {
2795 * Called from nfssvc() to update the exports list. Just call
2796 * vfs_export(). This has to be done, since the v4 root fake fs isn't
2797 * in the mount list.
2800 nfsrv_v4rootexport(void *argp, struct ucred *cred, struct thread *p)
2802 struct nfsex_args *nfsexargp = (struct nfsex_args *)argp;
2804 struct nameidata nd;
2807 error = vfs_export(&nfsv4root_mnt, &nfsexargp->export);
2808 if ((nfsexargp->export.ex_flags & MNT_DELEXPORT) != 0)
2810 else if (error == 0) {
2811 if (nfsexargp->fspec == NULL) {
2816 * If fspec != NULL, this is the v4root path.
2818 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE,
2819 nfsexargp->fspec, p);
2820 if ((error = namei(&nd)) != 0)
2822 error = nfsvno_getfh(nd.ni_vp, &fh, p);
2825 nfs_rootfh.nfsrvfh_len = NFSX_MYFH;
2826 NFSBCOPY((caddr_t)&fh,
2827 nfs_rootfh.nfsrvfh_data,
2828 sizeof (fhandle_t));
2839 * Get the tcp socket sequence numbers we need.
2840 * (Maybe this should be moved to the tcp sources?)
2843 nfsrv_getsocksndseq(struct socket *so, tcp_seq *maxp, tcp_seq *unap)
2849 inp = sotoinpcb(so);
2850 KASSERT(inp != NULL, ("nfsrv_getsocksndseq: inp == NULL"));
2852 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
2857 tp = intotcpcb(inp);
2858 if (tp->t_state != TCPS_ESTABLISHED) {
2863 *maxp = tp->snd_max;
2864 *unap = tp->snd_una;
2873 * This function needs to test to see if the system is near its limit
2874 * for memory allocation via malloc() or mget() and return True iff
2875 * either of these resources are near their limit.
2876 * XXX (For now, this is just a stub.)
2878 int nfsrv_testmalloclimit = 0;
2880 nfsrv_mallocmget_limit(void)
2882 static int printmesg = 0;
2883 static int testval = 1;
2885 if (nfsrv_testmalloclimit && (testval++ % 1000) == 0) {
2886 if ((printmesg++ % 100) == 0)
2887 printf("nfsd: malloc/mget near limit\n");
2894 * BSD specific initialization of a mount point.
2899 static int inited = 0;
2904 nfsv4root_mnt.mnt_flag = (MNT_RDONLY | MNT_EXPORTED);
2905 TAILQ_INIT(&nfsv4root_mnt.mnt_nvnodelist);
2906 TAILQ_INIT(&nfsv4root_mnt.mnt_activevnodelist);
2907 nfsv4root_mnt.mnt_export = NULL;
2908 TAILQ_INIT(&nfsv4root_opt);
2909 TAILQ_INIT(&nfsv4root_newopt);
2910 nfsv4root_mnt.mnt_opt = &nfsv4root_opt;
2911 nfsv4root_mnt.mnt_optnew = &nfsv4root_newopt;
2912 nfsv4root_mnt.mnt_nvnodelistsize = 0;
2913 nfsv4root_mnt.mnt_activevnodelistsize = 0;
2917 * Get a vnode for a file handle, without checking exports, etc.
2920 nfsvno_getvp(fhandle_t *fhp)
2926 mp = vfs_busyfs(&fhp->fh_fsid);
2929 error = VFS_FHTOVP(mp, &fhp->fh_fid, LK_EXCLUSIVE, &vp);
2937 * Do a local VOP_ADVLOCK().
2940 nfsvno_advlock(struct vnode *vp, int ftype, u_int64_t first,
2941 u_int64_t end, struct thread *td)
2947 if (nfsrv_dolocallocks == 0)
2950 /* Check for VI_DOOMED here, so that VOP_ADVLOCK() isn't performed. */
2951 if ((vp->v_iflag & VI_DOOMED) != 0) {
2956 fl.l_whence = SEEK_SET;
2958 fl.l_start = (off_t)first;
2959 if (end == NFS64BITSSET) {
2963 fl.l_len = (off_t)tlen;
2966 * For FreeBSD8, the l_pid and l_sysid must be set to the same
2967 * values for all calls, so that all locks will be held by the
2968 * nfsd server. (The nfsd server handles conflicts between the
2970 * Since an NFSv4 lockowner is a ClientID plus an array of up to 1024
2971 * bytes, so it can't be put in l_sysid.
2973 if (nfsv4_sysid == 0)
2974 nfsv4_sysid = nlm_acquire_next_sysid();
2975 fl.l_pid = (pid_t)0;
2976 fl.l_sysid = (int)nfsv4_sysid;
2978 NFSVOPUNLOCK(vp, 0);
2979 if (ftype == F_UNLCK)
2980 error = VOP_ADVLOCK(vp, (caddr_t)td->td_proc, F_UNLCK, &fl,
2981 (F_POSIX | F_REMOTE));
2983 error = VOP_ADVLOCK(vp, (caddr_t)td->td_proc, F_SETLK, &fl,
2984 (F_POSIX | F_REMOTE));
2985 NFSVOPLOCK(vp, LK_EXCLUSIVE | LK_RETRY);
2993 * Check the nfsv4 root exports.
2996 nfsvno_v4rootexport(struct nfsrv_descript *nd)
2998 struct ucred *credanon;
2999 int exflags, error = 0, numsecflavor, *secflavors, i;
3001 error = vfs_stdcheckexp(&nfsv4root_mnt, nd->nd_nam, &exflags,
3002 &credanon, &numsecflavor, &secflavors);
3004 error = NFSERR_PROGUNAVAIL;
3007 if (credanon != NULL)
3009 for (i = 0; i < numsecflavor; i++) {
3010 if (secflavors[i] == AUTH_SYS)
3011 nd->nd_flag |= ND_EXAUTHSYS;
3012 else if (secflavors[i] == RPCSEC_GSS_KRB5)
3013 nd->nd_flag |= ND_EXGSS;
3014 else if (secflavors[i] == RPCSEC_GSS_KRB5I)
3015 nd->nd_flag |= ND_EXGSSINTEGRITY;
3016 else if (secflavors[i] == RPCSEC_GSS_KRB5P)
3017 nd->nd_flag |= ND_EXGSSPRIVACY;
3026 * Nfs server psuedo system call for the nfsd's
3032 nfssvc_nfsd(struct thread *td, struct nfssvc_args *uap)
3035 struct nfsd_addsock_args sockarg;
3036 struct nfsd_nfsd_args nfsdarg;
3039 if (uap->flag & NFSSVC_NFSDADDSOCK) {
3040 error = copyin(uap->argp, (caddr_t)&sockarg, sizeof (sockarg));
3044 * Since we don't know what rights might be required,
3045 * pretend that we need them all. It is better to be too
3046 * careful than too reckless.
3048 if ((error = fget(td, sockarg.sock, CAP_SOCK_SERVER, &fp)) != 0)
3050 if (fp->f_type != DTYPE_SOCKET) {
3055 error = nfsrvd_addsock(fp);
3057 } else if (uap->flag & NFSSVC_NFSDNFSD) {
3058 if (uap->argp == NULL) {
3062 error = copyin(uap->argp, (caddr_t)&nfsdarg,
3066 error = nfsrvd_nfsd(td, &nfsdarg);
3068 error = nfssvc_srvcall(td, uap, td->td_ucred);
3077 nfssvc_srvcall(struct thread *p, struct nfssvc_args *uap, struct ucred *cred)
3079 struct nfsex_args export;
3080 struct file *fp = NULL;
3082 struct nfsd_clid adminrevoke;
3083 struct nfsd_dumplist dumplist;
3084 struct nfsd_dumpclients *dumpclients;
3085 struct nfsd_dumplocklist dumplocklist;
3086 struct nfsd_dumplocks *dumplocks;
3087 struct nameidata nd;
3089 int error = EINVAL, igotlock;
3091 static int suspend_nfsd = 0;
3093 if (uap->flag & NFSSVC_PUBLICFH) {
3094 NFSBZERO((caddr_t)&nfs_pubfh.nfsrvfh_data,
3095 sizeof (fhandle_t));
3096 error = copyin(uap->argp,
3097 &nfs_pubfh.nfsrvfh_data, sizeof (fhandle_t));
3100 } else if (uap->flag & NFSSVC_V4ROOTEXPORT) {
3101 error = copyin(uap->argp,(caddr_t)&export,
3102 sizeof (struct nfsex_args));
3104 error = nfsrv_v4rootexport(&export, cred, p);
3105 } else if (uap->flag & NFSSVC_NOPUBLICFH) {
3108 } else if (uap->flag & NFSSVC_STABLERESTART) {
3109 error = copyin(uap->argp, (caddr_t)&stablefd,
3112 error = fp_getfvp(p, stablefd, &fp, &vp);
3113 if (!error && (NFSFPFLAG(fp) & (FREAD | FWRITE)) != (FREAD | FWRITE))
3115 if (!error && newnfs_numnfsd != 0)
3118 nfsrv_stablefirst.nsf_fp = fp;
3119 nfsrv_setupstable(p);
3121 } else if (uap->flag & NFSSVC_ADMINREVOKE) {
3122 error = copyin(uap->argp, (caddr_t)&adminrevoke,
3123 sizeof (struct nfsd_clid));
3125 error = nfsrv_adminrevoke(&adminrevoke, p);
3126 } else if (uap->flag & NFSSVC_DUMPCLIENTS) {
3127 error = copyin(uap->argp, (caddr_t)&dumplist,
3128 sizeof (struct nfsd_dumplist));
3129 if (!error && (dumplist.ndl_size < 1 ||
3130 dumplist.ndl_size > NFSRV_MAXDUMPLIST))
3133 len = sizeof (struct nfsd_dumpclients) * dumplist.ndl_size;
3134 dumpclients = (struct nfsd_dumpclients *)malloc(len,
3136 nfsrv_dumpclients(dumpclients, dumplist.ndl_size);
3137 error = copyout(dumpclients,
3138 CAST_USER_ADDR_T(dumplist.ndl_list), len);
3139 free((caddr_t)dumpclients, M_TEMP);
3141 } else if (uap->flag & NFSSVC_DUMPLOCKS) {
3142 error = copyin(uap->argp, (caddr_t)&dumplocklist,
3143 sizeof (struct nfsd_dumplocklist));
3144 if (!error && (dumplocklist.ndllck_size < 1 ||
3145 dumplocklist.ndllck_size > NFSRV_MAXDUMPLIST))
3148 error = nfsrv_lookupfilename(&nd,
3149 dumplocklist.ndllck_fname, p);
3151 len = sizeof (struct nfsd_dumplocks) *
3152 dumplocklist.ndllck_size;
3153 dumplocks = (struct nfsd_dumplocks *)malloc(len,
3155 nfsrv_dumplocks(nd.ni_vp, dumplocks,
3156 dumplocklist.ndllck_size, p);
3158 error = copyout(dumplocks,
3159 CAST_USER_ADDR_T(dumplocklist.ndllck_list), len);
3160 free((caddr_t)dumplocks, M_TEMP);
3162 } else if (uap->flag & NFSSVC_BACKUPSTABLE) {
3165 nfsd_master_pid = procp->p_pid;
3166 bcopy(procp->p_comm, nfsd_master_comm, MAXCOMLEN + 1);
3167 nfsd_master_start = procp->p_stats->p_start;
3168 nfsd_master_proc = procp;
3170 } else if ((uap->flag & NFSSVC_SUSPENDNFSD) != 0) {
3171 NFSLOCKV4ROOTMUTEX();
3172 if (suspend_nfsd == 0) {
3173 /* Lock out all nfsd threads */
3175 igotlock = nfsv4_lock(&nfsd_suspend_lock, 1,
3176 NULL, NFSV4ROOTLOCKMUTEXPTR, NULL);
3177 } while (igotlock == 0 && suspend_nfsd == 0);
3180 NFSUNLOCKV4ROOTMUTEX();
3182 } else if ((uap->flag & NFSSVC_RESUMENFSD) != 0) {
3183 NFSLOCKV4ROOTMUTEX();
3184 if (suspend_nfsd != 0) {
3185 nfsv4_unlock(&nfsd_suspend_lock, 0);
3188 NFSUNLOCKV4ROOTMUTEX();
3198 * Returns 0 if ok, 1 otherwise.
3201 nfsvno_testexp(struct nfsrv_descript *nd, struct nfsexstuff *exp)
3206 * This seems odd, but allow the case where the security flavor
3207 * list is empty. This happens when NFSv4 is traversing non-exported
3208 * file systems. Exported file systems should always have a non-empty
3209 * security flavor list.
3211 if (exp->nes_numsecflavor == 0)
3214 for (i = 0; i < exp->nes_numsecflavor; i++) {
3216 * The tests for privacy and integrity must be first,
3217 * since ND_GSS is set for everything but AUTH_SYS.
3219 if (exp->nes_secflavors[i] == RPCSEC_GSS_KRB5P &&
3220 (nd->nd_flag & ND_GSSPRIVACY))
3222 if (exp->nes_secflavors[i] == RPCSEC_GSS_KRB5I &&
3223 (nd->nd_flag & ND_GSSINTEGRITY))
3225 if (exp->nes_secflavors[i] == RPCSEC_GSS_KRB5 &&
3226 (nd->nd_flag & ND_GSS))
3228 if (exp->nes_secflavors[i] == AUTH_SYS &&
3229 (nd->nd_flag & ND_GSS) == 0)
3236 * Calculate a hash value for the fid in a file handle.
3239 nfsrv_hashfh(fhandle_t *fhp)
3243 hashval = hash32_buf(&fhp->fh_fid, sizeof(struct fid), 0);
3248 * Signal the userland master nfsd to backup the stable restart file.
3251 nfsrv_backupstable(void)
3255 if (nfsd_master_proc != NULL) {
3256 procp = pfind(nfsd_master_pid);
3257 /* Try to make sure it is the correct process. */
3258 if (procp == nfsd_master_proc &&
3259 procp->p_stats->p_start.tv_sec ==
3260 nfsd_master_start.tv_sec &&
3261 procp->p_stats->p_start.tv_usec ==
3262 nfsd_master_start.tv_usec &&
3263 strcmp(procp->p_comm, nfsd_master_comm) == 0)
3264 kern_psignal(procp, SIGUSR2);
3266 nfsd_master_proc = NULL;
3273 extern int (*nfsd_call_nfsd)(struct thread *, struct nfssvc_args *);
3276 * Called once to initialize data structures...
3279 nfsd_modevent(module_t mod, int type, void *data)
3282 static int loaded = 0;
3289 mtx_init(&nfs_cache_mutex, "nfs_cache_mutex", NULL, MTX_DEF);
3290 mtx_init(&nfs_v4root_mutex, "nfs_v4root_mutex", NULL, MTX_DEF);
3291 mtx_init(&nfsv4root_mnt.mnt_mtx, "struct mount mtx", NULL,
3293 lockinit(&nfsv4root_mnt.mnt_explock, PVFS, "explock", 0, 0);
3300 #ifdef VV_DISABLEDELEG
3301 vn_deleg_ops.vndeleg_recall = nfsd_recalldelegation;
3302 vn_deleg_ops.vndeleg_disable = nfsd_disabledelegation;
3304 nfsd_call_servertimer = nfsrv_servertimer;
3305 nfsd_call_nfsd = nfssvc_nfsd;
3310 if (newnfs_numnfsd != 0) {
3315 #ifdef VV_DISABLEDELEG
3316 vn_deleg_ops.vndeleg_recall = NULL;
3317 vn_deleg_ops.vndeleg_disable = NULL;
3319 nfsd_call_servertimer = NULL;
3320 nfsd_call_nfsd = NULL;
3322 /* Clean out all NFSv4 state. */
3323 nfsrv_throwawayallstate(curthread);
3325 /* Clean the NFS server reply cache */
3326 nfsrvd_cleancache();
3328 /* Free up the krpc server pool. */
3329 if (nfsrvd_pool != NULL)
3330 svcpool_destroy(nfsrvd_pool);
3332 /* and get rid of the locks */
3333 mtx_destroy(&nfs_cache_mutex);
3334 mtx_destroy(&nfs_v4root_mutex);
3335 mtx_destroy(&nfsv4root_mnt.mnt_mtx);
3336 lockdestroy(&nfsv4root_mnt.mnt_explock);
3348 static moduledata_t nfsd_mod = {
3353 DECLARE_MODULE(nfsd, nfsd_mod, SI_SUB_VFS, SI_ORDER_ANY);
3355 /* So that loader and kldload(2) can find us, wherever we are.. */
3356 MODULE_VERSION(nfsd, 1);
3357 MODULE_DEPEND(nfsd, nfscommon, 1, 1, 1);
3358 MODULE_DEPEND(nfsd, nfslock, 1, 1, 1);
3359 MODULE_DEPEND(nfsd, nfslockd, 1, 1, 1);
3360 MODULE_DEPEND(nfsd, krpc, 1, 1, 1);
3361 MODULE_DEPEND(nfsd, nfssvc, 1, 1, 1);