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 * becuase 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 uma_zfree(namei_zone, cnp->cn_pnbuf);
512 ndp->ni_startdir = NULL;
513 cnp->cn_flags &= ~HASBUF;
514 } else if ((ndp->ni_cnd.cn_flags & (WANTPARENT|LOCKPARENT)) == 0) {
519 NFSEXITCODE2(error, nd);
524 * Set up a pathname buffer and return a pointer to it and, optionally
525 * set a hash pointer.
528 nfsvno_setpathbuf(struct nameidata *ndp, char **bufpp, u_long **hashpp)
530 struct componentname *cnp = &ndp->ni_cnd;
532 cnp->cn_flags |= (NOMACCHECK | HASBUF);
533 cnp->cn_pnbuf = uma_zalloc(namei_zone, M_WAITOK);
536 *bufpp = cnp->cn_pnbuf;
540 * Release the above path buffer, if not released by nfsvno_namei().
543 nfsvno_relpathbuf(struct nameidata *ndp)
546 if ((ndp->ni_cnd.cn_flags & HASBUF) == 0)
548 uma_zfree(namei_zone, ndp->ni_cnd.cn_pnbuf);
549 ndp->ni_cnd.cn_flags &= ~HASBUF;
553 * Readlink vnode op into an mbuf list.
556 nfsvno_readlink(struct vnode *vp, struct ucred *cred, struct thread *p,
557 struct mbuf **mpp, struct mbuf **mpendp, int *lenp)
559 struct iovec iv[(NFS_MAXPATHLEN+MLEN-1)/MLEN];
560 struct iovec *ivp = iv;
561 struct uio io, *uiop = &io;
562 struct mbuf *mp, *mp2 = NULL, *mp3 = NULL;
563 int i, len, tlen, error = 0;
567 while (len < NFS_MAXPATHLEN) {
570 mp->m_len = NFSMSIZ(mp);
577 if ((len + mp->m_len) > NFS_MAXPATHLEN) {
578 mp->m_len = NFS_MAXPATHLEN - len;
579 len = NFS_MAXPATHLEN;
583 ivp->iov_base = mtod(mp, caddr_t);
584 ivp->iov_len = mp->m_len;
589 uiop->uio_iovcnt = i;
590 uiop->uio_offset = 0;
591 uiop->uio_resid = len;
592 uiop->uio_rw = UIO_READ;
593 uiop->uio_segflg = UIO_SYSSPACE;
595 error = VOP_READLINK(vp, uiop, cred);
601 if (uiop->uio_resid > 0) {
602 len -= uiop->uio_resid;
603 tlen = NFSM_RNDUP(len);
604 nfsrv_adj(mp3, NFS_MAXPATHLEN - tlen, tlen - len);
616 * Read vnode op call into mbuf list.
619 nfsvno_read(struct vnode *vp, off_t off, int cnt, struct ucred *cred,
620 struct thread *p, struct mbuf **mpp, struct mbuf **mpendp)
626 int error = 0, len, left, siz, tlen, ioflag = 0;
627 struct mbuf *m2 = NULL, *m3;
628 struct uio io, *uiop = &io;
631 len = left = NFSM_RNDUP(cnt);
634 * Generate the mbuf list with the uio_iov ref. to it.
641 siz = min(M_TRAILINGSPACE(m), left);
650 MALLOC(iv, struct iovec *, i * sizeof (struct iovec),
652 uiop->uio_iov = iv2 = iv;
658 panic("nfsvno_read iov");
659 siz = min(M_TRAILINGSPACE(m), left);
661 iv->iov_base = mtod(m, caddr_t) + m->m_len;
670 uiop->uio_iovcnt = i;
671 uiop->uio_offset = off;
672 uiop->uio_resid = len;
673 uiop->uio_rw = UIO_READ;
674 uiop->uio_segflg = UIO_SYSSPACE;
675 nh = nfsrv_sequential_heuristic(uiop, vp);
676 ioflag |= nh->nh_seqcount << IO_SEQSHIFT;
677 error = VOP_READ(vp, uiop, IO_NODELOCKED | ioflag, cred);
678 FREE((caddr_t)iv2, M_TEMP);
684 nh->nh_nextoff = uiop->uio_offset;
685 tlen = len - uiop->uio_resid;
686 cnt = cnt < tlen ? cnt : tlen;
687 tlen = NFSM_RNDUP(cnt);
691 } else if (len != tlen || tlen != cnt)
692 nfsrv_adj(m3, len - tlen, tlen - cnt);
702 * Write vnode op from an mbuf list.
705 nfsvno_write(struct vnode *vp, off_t off, int retlen, int cnt, int stable,
706 struct mbuf *mp, char *cp, struct ucred *cred, struct thread *p)
712 struct uio io, *uiop = &io;
715 MALLOC(ivp, struct iovec *, cnt * sizeof (struct iovec), M_TEMP,
717 uiop->uio_iov = iv = ivp;
718 uiop->uio_iovcnt = cnt;
719 i = mtod(mp, caddr_t) + mp->m_len - cp;
723 panic("nfsvno_write");
734 cp = mtod(mp, caddr_t);
738 if (stable == NFSWRITE_UNSTABLE)
739 ioflags = IO_NODELOCKED;
741 ioflags = (IO_SYNC | IO_NODELOCKED);
742 uiop->uio_resid = retlen;
743 uiop->uio_rw = UIO_WRITE;
744 uiop->uio_segflg = UIO_SYSSPACE;
746 uiop->uio_offset = off;
747 nh = nfsrv_sequential_heuristic(uiop, vp);
748 ioflags |= nh->nh_seqcount << IO_SEQSHIFT;
749 error = VOP_WRITE(vp, uiop, ioflags, cred);
751 nh->nh_nextoff = uiop->uio_offset;
752 FREE((caddr_t)iv, M_TEMP);
759 * Common code for creating a regular file (plus special files for V2).
762 nfsvno_createsub(struct nfsrv_descript *nd, struct nameidata *ndp,
763 struct vnode **vpp, struct nfsvattr *nvap, int *exclusive_flagp,
764 int32_t *cverf, NFSDEV_T rdev, struct thread *p, struct nfsexstuff *exp)
769 error = nd->nd_repstat;
770 if (!error && ndp->ni_vp == NULL) {
771 if (nvap->na_type == VREG || nvap->na_type == VSOCK) {
772 vrele(ndp->ni_startdir);
773 error = VOP_CREATE(ndp->ni_dvp,
774 &ndp->ni_vp, &ndp->ni_cnd, &nvap->na_vattr);
776 nfsvno_relpathbuf(ndp);
778 if (*exclusive_flagp) {
779 *exclusive_flagp = 0;
780 NFSVNO_ATTRINIT(nvap);
781 nvap->na_atime.tv_sec = cverf[0];
782 nvap->na_atime.tv_nsec = cverf[1];
783 error = VOP_SETATTR(ndp->ni_vp,
784 &nvap->na_vattr, nd->nd_cred);
788 * NFS V2 Only. nfsrvd_mknod() does this for V3.
789 * (This implies, just get out on an error.)
791 } else if (nvap->na_type == VCHR || nvap->na_type == VBLK ||
792 nvap->na_type == VFIFO) {
793 if (nvap->na_type == VCHR && rdev == 0xffffffff)
794 nvap->na_type = VFIFO;
795 if (nvap->na_type != VFIFO &&
796 (error = priv_check_cred(nd->nd_cred,
797 PRIV_VFS_MKNOD_DEV, 0))) {
798 vrele(ndp->ni_startdir);
799 nfsvno_relpathbuf(ndp);
803 nvap->na_rdev = rdev;
804 error = VOP_MKNOD(ndp->ni_dvp, &ndp->ni_vp,
805 &ndp->ni_cnd, &nvap->na_vattr);
807 nfsvno_relpathbuf(ndp);
808 vrele(ndp->ni_startdir);
812 vrele(ndp->ni_startdir);
813 nfsvno_relpathbuf(ndp);
821 * Handle cases where error is already set and/or
823 * 1 - clean up the lookup
824 * 2 - iff !error and na_size set, truncate it
826 vrele(ndp->ni_startdir);
827 nfsvno_relpathbuf(ndp);
829 if (ndp->ni_dvp == *vpp)
833 if (!error && nvap->na_size != VNOVAL) {
834 error = nfsvno_accchk(*vpp, VWRITE,
835 nd->nd_cred, exp, p, NFSACCCHK_NOOVERRIDE,
836 NFSACCCHK_VPISLOCKED, NULL);
838 tempsize = nvap->na_size;
839 NFSVNO_ATTRINIT(nvap);
840 nvap->na_size = tempsize;
841 error = VOP_SETATTR(*vpp,
842 &nvap->na_vattr, nd->nd_cred);
855 * Do a mknod vnode op.
858 nfsvno_mknod(struct nameidata *ndp, struct nfsvattr *nvap, struct ucred *cred,
864 vtyp = nvap->na_type;
866 * Iff doesn't exist, create it.
869 vrele(ndp->ni_startdir);
870 nfsvno_relpathbuf(ndp);
876 if (vtyp != VCHR && vtyp != VBLK && vtyp != VSOCK && vtyp != VFIFO) {
877 vrele(ndp->ni_startdir);
878 nfsvno_relpathbuf(ndp);
880 error = NFSERR_BADTYPE;
884 vrele(ndp->ni_startdir);
885 error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp,
886 &ndp->ni_cnd, &nvap->na_vattr);
888 nfsvno_relpathbuf(ndp);
890 if (nvap->na_type != VFIFO &&
891 (error = priv_check_cred(cred, PRIV_VFS_MKNOD_DEV, 0))) {
892 vrele(ndp->ni_startdir);
893 nfsvno_relpathbuf(ndp);
897 error = VOP_MKNOD(ndp->ni_dvp, &ndp->ni_vp,
898 &ndp->ni_cnd, &nvap->na_vattr);
900 nfsvno_relpathbuf(ndp);
901 vrele(ndp->ni_startdir);
903 * Since VOP_MKNOD returns the ni_vp, I can't
904 * see any reason to do the lookup.
917 nfsvno_mkdir(struct nameidata *ndp, struct nfsvattr *nvap, uid_t saved_uid,
918 struct ucred *cred, struct thread *p, struct nfsexstuff *exp)
922 if (ndp->ni_vp != NULL) {
923 if (ndp->ni_dvp == ndp->ni_vp)
928 nfsvno_relpathbuf(ndp);
932 error = VOP_MKDIR(ndp->ni_dvp, &ndp->ni_vp, &ndp->ni_cnd,
935 nfsvno_relpathbuf(ndp);
946 nfsvno_symlink(struct nameidata *ndp, struct nfsvattr *nvap, char *pathcp,
947 int pathlen, int not_v2, uid_t saved_uid, struct ucred *cred, struct thread *p,
948 struct nfsexstuff *exp)
953 vrele(ndp->ni_startdir);
954 nfsvno_relpathbuf(ndp);
955 if (ndp->ni_dvp == ndp->ni_vp)
964 error = VOP_SYMLINK(ndp->ni_dvp, &ndp->ni_vp, &ndp->ni_cnd,
965 &nvap->na_vattr, pathcp);
967 vrele(ndp->ni_startdir);
968 nfsvno_relpathbuf(ndp);
970 * Although FreeBSD still had the lookup code in
971 * it for 7/current, there doesn't seem to be any
972 * point, since VOP_SYMLINK() returns the ni_vp.
973 * Just vput it for v2.
975 if (!not_v2 && !error)
984 * Parse symbolic link arguments.
985 * This function has an ugly side effect. It will MALLOC() an area for
986 * the symlink and set iov_base to point to it, only if it succeeds.
987 * So, if it returns with uiop->uio_iov->iov_base != NULL, that must
991 nfsvno_getsymlink(struct nfsrv_descript *nd, struct nfsvattr *nvap,
992 struct thread *p, char **pathcpp, int *lenp)
997 struct nfsv2_sattr *sp;
1001 if ((nd->nd_flag & ND_NFSV3) &&
1002 (error = nfsrv_sattr(nd, nvap, NULL, NULL, p)))
1004 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
1005 len = fxdr_unsigned(int, *tl);
1006 if (len > NFS_MAXPATHLEN || len <= 0) {
1010 MALLOC(pathcp, caddr_t, len + 1, M_TEMP, M_WAITOK);
1011 error = nfsrv_mtostr(nd, pathcp, len);
1014 if (nd->nd_flag & ND_NFSV2) {
1015 NFSM_DISSECT(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
1016 nvap->na_mode = fxdr_unsigned(u_int16_t, sp->sa_mode);
1020 NFSEXITCODE2(0, nd);
1024 free(pathcp, M_TEMP);
1025 NFSEXITCODE2(error, nd);
1030 * Remove a non-directory object.
1033 nfsvno_removesub(struct nameidata *ndp, int is_v4, struct ucred *cred,
1034 struct thread *p, struct nfsexstuff *exp)
1040 if (vp->v_type == VDIR)
1041 error = NFSERR_ISDIR;
1043 error = nfsrv_checkremove(vp, 1, p);
1045 error = VOP_REMOVE(ndp->ni_dvp, vp, &ndp->ni_cnd);
1046 if (ndp->ni_dvp == vp)
1051 if ((ndp->ni_cnd.cn_flags & SAVENAME) != 0)
1052 nfsvno_relpathbuf(ndp);
1058 * Remove a directory.
1061 nfsvno_rmdirsub(struct nameidata *ndp, int is_v4, struct ucred *cred,
1062 struct thread *p, struct nfsexstuff *exp)
1068 if (vp->v_type != VDIR) {
1073 * No rmdir "." please.
1075 if (ndp->ni_dvp == vp) {
1080 * The root of a mounted filesystem cannot be deleted.
1082 if (vp->v_vflag & VV_ROOT)
1086 error = VOP_RMDIR(ndp->ni_dvp, vp, &ndp->ni_cnd);
1087 if (ndp->ni_dvp == vp)
1092 if ((ndp->ni_cnd.cn_flags & SAVENAME) != 0)
1093 nfsvno_relpathbuf(ndp);
1102 nfsvno_rename(struct nameidata *fromndp, struct nameidata *tondp,
1103 u_int32_t ndstat, u_int32_t ndflag, struct ucred *cred, struct thread *p)
1105 struct vnode *fvp, *tvp, *tdvp;
1108 fvp = fromndp->ni_vp;
1110 vrele(fromndp->ni_dvp);
1115 tdvp = tondp->ni_dvp;
1118 if (fvp->v_type == VDIR && tvp->v_type != VDIR) {
1119 error = (ndflag & ND_NFSV2) ? EISDIR : EEXIST;
1121 } else if (fvp->v_type != VDIR && tvp->v_type == VDIR) {
1122 error = (ndflag & ND_NFSV2) ? ENOTDIR : EEXIST;
1125 if (tvp->v_type == VDIR && tvp->v_mountedhere) {
1126 error = (ndflag & ND_NFSV2) ? ENOTEMPTY : EXDEV;
1131 * A rename to '.' or '..' results in a prematurely
1132 * unlocked vnode on FreeBSD5, so I'm just going to fail that
1135 if ((tondp->ni_cnd.cn_namelen == 1 &&
1136 tondp->ni_cnd.cn_nameptr[0] == '.') ||
1137 (tondp->ni_cnd.cn_namelen == 2 &&
1138 tondp->ni_cnd.cn_nameptr[0] == '.' &&
1139 tondp->ni_cnd.cn_nameptr[1] == '.')) {
1144 if (fvp->v_type == VDIR && fvp->v_mountedhere) {
1145 error = (ndflag & ND_NFSV2) ? ENOTEMPTY : EXDEV;
1148 if (fvp->v_mount != tdvp->v_mount) {
1149 error = (ndflag & ND_NFSV2) ? ENOTEMPTY : EXDEV;
1153 error = (ndflag & ND_NFSV2) ? ENOTEMPTY : EINVAL;
1158 * If source and destination are the same, there is nothing to
1159 * do. Set error to -1 to indicate this.
1164 if (ndflag & ND_NFSV4) {
1165 if (NFSVOPLOCK(fvp, LK_EXCLUSIVE) == 0) {
1166 error = nfsrv_checkremove(fvp, 0, p);
1167 NFSVOPUNLOCK(fvp, 0);
1171 error = nfsrv_checkremove(tvp, 1, p);
1174 * For NFSv2 and NFSv3, try to get rid of the delegation, so
1175 * that the NFSv4 client won't be confused by the rename.
1176 * Since nfsd_recalldelegation() can only be called on an
1177 * unlocked vnode at this point and fvp is the file that will
1178 * still exist after the rename, just do fvp.
1180 nfsd_recalldelegation(fvp, p);
1184 error = VOP_RENAME(fromndp->ni_dvp, fromndp->ni_vp,
1185 &fromndp->ni_cnd, tondp->ni_dvp, tondp->ni_vp,
1194 vrele(fromndp->ni_dvp);
1199 vrele(tondp->ni_startdir);
1200 nfsvno_relpathbuf(tondp);
1202 vrele(fromndp->ni_startdir);
1203 nfsvno_relpathbuf(fromndp);
1212 nfsvno_link(struct nameidata *ndp, struct vnode *vp, struct ucred *cred,
1213 struct thread *p, struct nfsexstuff *exp)
1223 if (vp->v_mount != xp->v_mount)
1227 NFSVOPLOCK(vp, LK_EXCLUSIVE | LK_RETRY);
1228 if ((vp->v_iflag & VI_DOOMED) == 0)
1229 error = VOP_LINK(ndp->ni_dvp, vp, &ndp->ni_cnd);
1232 if (ndp->ni_dvp == vp)
1236 NFSVOPUNLOCK(vp, 0);
1238 if (ndp->ni_dvp == ndp->ni_vp)
1245 nfsvno_relpathbuf(ndp);
1251 * Do the fsync() appropriate for the commit.
1254 nfsvno_fsync(struct vnode *vp, u_int64_t off, int cnt, struct ucred *cred,
1260 * RFC 1813 3.3.21: if count is 0, a flush from offset to the end of
1261 * file is done. At this time VOP_FSYNC does not accept offset and
1262 * byte count parameters so call VOP_FSYNC the whole file for now.
1263 * The same is true for NFSv4: RFC 3530 Sec. 14.2.3.
1265 if (cnt == 0 || cnt > MAX_COMMIT_COUNT) {
1267 * Give up and do the whole thing
1270 (vp->v_object->flags & OBJ_MIGHTBEDIRTY)) {
1271 VM_OBJECT_LOCK(vp->v_object);
1272 vm_object_page_clean(vp->v_object, 0, 0, OBJPC_SYNC);
1273 VM_OBJECT_UNLOCK(vp->v_object);
1275 error = VOP_FSYNC(vp, MNT_WAIT, td);
1278 * Locate and synchronously write any buffers that fall
1279 * into the requested range. Note: we are assuming that
1280 * f_iosize is a power of 2.
1282 int iosize = vp->v_mount->mnt_stat.f_iosize;
1283 int iomask = iosize - 1;
1288 * Align to iosize boundry, super-align to page boundry.
1291 cnt += off & iomask;
1292 off &= ~(u_quad_t)iomask;
1294 if (off & PAGE_MASK) {
1295 cnt += off & PAGE_MASK;
1296 off &= ~(u_quad_t)PAGE_MASK;
1298 lblkno = off / iosize;
1301 (vp->v_object->flags & OBJ_MIGHTBEDIRTY)) {
1302 VM_OBJECT_LOCK(vp->v_object);
1303 vm_object_page_clean(vp->v_object, off, off + cnt,
1305 VM_OBJECT_UNLOCK(vp->v_object);
1314 * If we have a buffer and it is marked B_DELWRI we
1315 * have to lock and write it. Otherwise the prior
1316 * write is assumed to have already been committed.
1318 * gbincore() can return invalid buffers now so we
1319 * have to check that bit as well (though B_DELWRI
1320 * should not be set if B_INVAL is set there could be
1321 * a race here since we haven't locked the buffer).
1323 if ((bp = gbincore(&vp->v_bufobj, lblkno)) != NULL) {
1324 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_SLEEPFAIL |
1325 LK_INTERLOCK, BO_MTX(bo)) == ENOLCK) {
1327 continue; /* retry */
1329 if ((bp->b_flags & (B_DELWRI|B_INVAL)) ==
1332 bp->b_flags &= ~B_ASYNC;
1355 nfsvno_statfs(struct vnode *vp, struct statfs *sf)
1359 error = VFS_STATFS(vp->v_mount, sf);
1362 * Since NFS handles these values as unsigned on the
1363 * wire, there is no way to represent negative values,
1364 * so set them to 0. Without this, they will appear
1365 * to be very large positive values for clients like
1368 if (sf->f_bavail < 0)
1370 if (sf->f_ffree < 0)
1378 * Do the vnode op stuff for Open. Similar to nfsvno_createsub(), but
1379 * must handle nfsrv_opencheck() calls after any other access checks.
1382 nfsvno_open(struct nfsrv_descript *nd, struct nameidata *ndp,
1383 nfsquad_t clientid, nfsv4stateid_t *stateidp, struct nfsstate *stp,
1384 int *exclusive_flagp, struct nfsvattr *nvap, int32_t *cverf, int create,
1385 NFSACL_T *aclp, nfsattrbit_t *attrbitp, struct ucred *cred, struct thread *p,
1386 struct nfsexstuff *exp, struct vnode **vpp)
1388 struct vnode *vp = NULL;
1390 struct nfsexstuff nes;
1392 if (ndp->ni_vp == NULL)
1393 nd->nd_repstat = nfsrv_opencheck(clientid,
1394 stateidp, stp, NULL, nd, p, nd->nd_repstat);
1395 if (!nd->nd_repstat) {
1396 if (ndp->ni_vp == NULL) {
1397 vrele(ndp->ni_startdir);
1398 nd->nd_repstat = VOP_CREATE(ndp->ni_dvp,
1399 &ndp->ni_vp, &ndp->ni_cnd, &nvap->na_vattr);
1401 nfsvno_relpathbuf(ndp);
1402 if (!nd->nd_repstat) {
1403 if (*exclusive_flagp) {
1404 *exclusive_flagp = 0;
1405 NFSVNO_ATTRINIT(nvap);
1406 nvap->na_atime.tv_sec = cverf[0];
1407 nvap->na_atime.tv_nsec = cverf[1];
1408 nd->nd_repstat = VOP_SETATTR(ndp->ni_vp,
1409 &nvap->na_vattr, cred);
1411 nfsrv_fixattr(nd, ndp->ni_vp, nvap,
1412 aclp, p, attrbitp, exp);
1417 if (ndp->ni_startdir)
1418 vrele(ndp->ni_startdir);
1419 nfsvno_relpathbuf(ndp);
1421 if (create == NFSV4OPEN_CREATE) {
1422 if (ndp->ni_dvp == vp)
1427 if (NFSVNO_ISSETSIZE(nvap) && vp->v_type == VREG) {
1428 if (ndp->ni_cnd.cn_flags & RDONLY)
1429 NFSVNO_SETEXRDONLY(&nes);
1431 NFSVNO_EXINIT(&nes);
1432 nd->nd_repstat = nfsvno_accchk(vp,
1433 VWRITE, cred, &nes, p,
1434 NFSACCCHK_NOOVERRIDE,
1435 NFSACCCHK_VPISLOCKED, NULL);
1436 nd->nd_repstat = nfsrv_opencheck(clientid,
1437 stateidp, stp, vp, nd, p, nd->nd_repstat);
1438 if (!nd->nd_repstat) {
1439 tempsize = nvap->na_size;
1440 NFSVNO_ATTRINIT(nvap);
1441 nvap->na_size = tempsize;
1442 nd->nd_repstat = VOP_SETATTR(vp,
1443 &nvap->na_vattr, cred);
1445 } else if (vp->v_type == VREG) {
1446 nd->nd_repstat = nfsrv_opencheck(clientid,
1447 stateidp, stp, vp, nd, p, nd->nd_repstat);
1451 if (ndp->ni_cnd.cn_flags & HASBUF)
1452 nfsvno_relpathbuf(ndp);
1453 if (ndp->ni_startdir && create == NFSV4OPEN_CREATE) {
1454 vrele(ndp->ni_startdir);
1455 if (ndp->ni_dvp == ndp->ni_vp)
1465 NFSEXITCODE2(0, nd);
1469 * Updates the file rev and sets the mtime and ctime
1470 * to the current clock time, returning the va_filerev and va_Xtime
1474 nfsvno_updfilerev(struct vnode *vp, struct nfsvattr *nvap,
1475 struct ucred *cred, struct thread *p)
1480 vfs_timestamp(&va.va_mtime);
1481 (void) VOP_SETATTR(vp, &va, cred);
1482 (void) nfsvno_getattr(vp, nvap, cred, p, 1);
1486 * Glue routine to nfsv4_fillattr().
1489 nfsvno_fillattr(struct nfsrv_descript *nd, struct mount *mp, struct vnode *vp,
1490 struct nfsvattr *nvap, fhandle_t *fhp, int rderror, nfsattrbit_t *attrbitp,
1491 struct ucred *cred, struct thread *p, int isdgram, int reterr,
1492 int supports_nfsv4acls, int at_root, uint64_t mounted_on_fileno)
1496 error = nfsv4_fillattr(nd, mp, vp, NULL, &nvap->na_vattr, fhp, rderror,
1497 attrbitp, cred, p, isdgram, reterr, supports_nfsv4acls, at_root,
1499 NFSEXITCODE2(0, nd);
1503 /* Since the Readdir vnode ops vary, put the entire functions in here. */
1505 * nfs readdir service
1506 * - mallocs what it thinks is enough to read
1507 * count rounded up to a multiple of DIRBLKSIZ <= NFS_MAXREADDIR
1508 * - calls VOP_READDIR()
1509 * - loops around building the reply
1510 * if the output generated exceeds count break out of loop
1511 * The NFSM_CLGET macro is used here so that the reply will be packed
1512 * tightly in mbuf clusters.
1513 * - it trims out records with d_fileno == 0
1514 * this doesn't matter for Unix clients, but they might confuse clients
1516 * - it trims out records with d_type == DT_WHT
1517 * these cannot be seen through NFS (unless we extend the protocol)
1518 * The alternate call nfsrvd_readdirplus() does lookups as well.
1519 * PS: The NFS protocol spec. does not clarify what the "count" byte
1520 * argument is a count of.. just name strings and file id's or the
1521 * entire reply rpc or ...
1522 * I tried just file name and id sizes and it confused the Sun client,
1523 * so I am using the full rpc size now. The "paranoia.." comment refers
1524 * to including the status longwords that are not a part of the dir.
1525 * "entry" structures, but are in the rpc.
1528 nfsrvd_readdir(struct nfsrv_descript *nd, int isdgram,
1529 struct vnode *vp, struct thread *p, struct nfsexstuff *exp)
1534 char *cpos, *cend, *rbuf;
1536 int nlen, error = 0, getret = 1;
1537 int siz, cnt, fullsiz, eofflag, ncookies;
1538 u_int64_t off, toff, verf;
1539 u_long *cookies = NULL, *cookiep;
1544 if (nd->nd_repstat) {
1545 nfsrv_postopattr(nd, getret, &at);
1548 if (nd->nd_flag & ND_NFSV2) {
1549 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1550 off = fxdr_unsigned(u_quad_t, *tl++);
1552 NFSM_DISSECT(tl, u_int32_t *, 5 * NFSX_UNSIGNED);
1553 off = fxdr_hyper(tl);
1555 verf = fxdr_hyper(tl);
1559 cnt = fxdr_unsigned(int, *tl);
1560 if (cnt > NFS_SRVMAXDATA(nd) || cnt < 0)
1561 cnt = NFS_SRVMAXDATA(nd);
1562 siz = ((cnt + DIRBLKSIZ - 1) & ~(DIRBLKSIZ - 1));
1564 if (nd->nd_flag & ND_NFSV3) {
1565 nd->nd_repstat = getret = nfsvno_getattr(vp, &at, nd->nd_cred,
1569 * va_filerev is not sufficient as a cookie verifier,
1570 * since it is not supposed to change when entries are
1571 * removed/added unless that offset cookies returned to
1572 * the client are no longer valid.
1574 if (!nd->nd_repstat && toff && verf != at.na_filerev)
1575 nd->nd_repstat = NFSERR_BAD_COOKIE;
1578 if (!nd->nd_repstat && vp->v_type != VDIR)
1579 nd->nd_repstat = NFSERR_NOTDIR;
1580 if (nd->nd_repstat == 0 && cnt == 0) {
1581 if (nd->nd_flag & ND_NFSV2)
1582 /* NFSv2 does not have NFSERR_TOOSMALL */
1583 nd->nd_repstat = EPERM;
1585 nd->nd_repstat = NFSERR_TOOSMALL;
1587 if (!nd->nd_repstat)
1588 nd->nd_repstat = nfsvno_accchk(vp, VEXEC,
1589 nd->nd_cred, exp, p, NFSACCCHK_NOOVERRIDE,
1590 NFSACCCHK_VPISLOCKED, NULL);
1591 if (nd->nd_repstat) {
1593 if (nd->nd_flag & ND_NFSV3)
1594 nfsrv_postopattr(nd, getret, &at);
1597 not_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs");
1598 MALLOC(rbuf, caddr_t, siz, M_TEMP, M_WAITOK);
1602 free((caddr_t)cookies, M_TEMP);
1610 io.uio_offset = (off_t)off;
1612 io.uio_segflg = UIO_SYSSPACE;
1613 io.uio_rw = UIO_READ;
1615 nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag, &ncookies,
1617 off = (u_int64_t)io.uio_offset;
1619 siz -= io.uio_resid;
1621 if (!cookies && !nd->nd_repstat)
1622 nd->nd_repstat = NFSERR_PERM;
1623 if (nd->nd_flag & ND_NFSV3) {
1624 getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1);
1625 if (!nd->nd_repstat)
1626 nd->nd_repstat = getret;
1630 * Handles the failed cases. nd->nd_repstat == 0 past here.
1632 if (nd->nd_repstat) {
1634 free((caddr_t)rbuf, M_TEMP);
1636 free((caddr_t)cookies, M_TEMP);
1637 if (nd->nd_flag & ND_NFSV3)
1638 nfsrv_postopattr(nd, getret, &at);
1642 * If nothing read, return eof
1647 if (nd->nd_flag & ND_NFSV2) {
1648 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1650 nfsrv_postopattr(nd, getret, &at);
1651 NFSM_BUILD(tl, u_int32_t *, 4 * NFSX_UNSIGNED);
1652 txdr_hyper(at.na_filerev, tl);
1655 *tl++ = newnfs_false;
1657 FREE((caddr_t)rbuf, M_TEMP);
1658 FREE((caddr_t)cookies, M_TEMP);
1663 * Check for degenerate cases of nothing useful read.
1664 * If so go try again
1668 dp = (struct dirent *)cpos;
1672 * For some reason FreeBSD's ufs_readdir() chooses to back the
1673 * directory offset up to a block boundary, so it is necessary to
1674 * skip over the records that precede the requested offset. This
1675 * requires the assumption that file offset cookies monotonically
1677 * Since the offset cookies don't monotonically increase for ZFS,
1678 * this is not done when ZFS is the file system.
1680 while (cpos < cend && ncookies > 0 &&
1681 (dp->d_fileno == 0 || dp->d_type == DT_WHT ||
1682 (not_zfs != 0 && ((u_quad_t)(*cookiep)) <= toff))) {
1683 cpos += dp->d_reclen;
1684 dp = (struct dirent *)cpos;
1688 if (cpos >= cend || ncookies == 0) {
1696 * dirlen is the size of the reply, including all XDR and must
1697 * not exceed cnt. For NFSv2, RFC1094 didn't clearly indicate
1698 * if the XDR should be included in "count", but to be safe, we do.
1699 * (Include the two booleans at the end of the reply in dirlen now.)
1701 if (nd->nd_flag & ND_NFSV3) {
1702 nfsrv_postopattr(nd, getret, &at);
1703 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1704 txdr_hyper(at.na_filerev, tl);
1705 dirlen = NFSX_V3POSTOPATTR + NFSX_VERF + 2 * NFSX_UNSIGNED;
1707 dirlen = 2 * NFSX_UNSIGNED;
1710 /* Loop through the records and build reply */
1711 while (cpos < cend && ncookies > 0) {
1712 nlen = dp->d_namlen;
1713 if (dp->d_fileno != 0 && dp->d_type != DT_WHT &&
1714 nlen <= NFS_MAXNAMLEN) {
1715 if (nd->nd_flag & ND_NFSV3)
1716 dirlen += (6*NFSX_UNSIGNED + NFSM_RNDUP(nlen));
1718 dirlen += (4*NFSX_UNSIGNED + NFSM_RNDUP(nlen));
1725 * Build the directory record xdr from
1728 if (nd->nd_flag & ND_NFSV3) {
1729 NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
1730 *tl++ = newnfs_true;
1733 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1734 *tl++ = newnfs_true;
1736 *tl = txdr_unsigned(dp->d_fileno);
1737 (void) nfsm_strtom(nd, dp->d_name, nlen);
1738 if (nd->nd_flag & ND_NFSV3) {
1739 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1742 NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
1743 *tl = txdr_unsigned(*cookiep);
1745 cpos += dp->d_reclen;
1746 dp = (struct dirent *)cpos;
1752 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1753 *tl++ = newnfs_false;
1758 FREE((caddr_t)rbuf, M_TEMP);
1759 FREE((caddr_t)cookies, M_TEMP);
1762 NFSEXITCODE2(0, nd);
1766 NFSEXITCODE2(error, nd);
1771 * Readdirplus for V3 and Readdir for V4.
1774 nfsrvd_readdirplus(struct nfsrv_descript *nd, int isdgram,
1775 struct vnode *vp, struct thread *p, struct nfsexstuff *exp)
1780 char *cpos, *cend, *rbuf;
1783 struct nfsvattr nva, at, *nvap = &nva;
1784 struct mbuf *mb0, *mb1;
1785 struct nfsreferral *refp;
1786 int nlen, r, error = 0, getret = 1, usevget = 1;
1787 int siz, cnt, fullsiz, eofflag, ncookies, entrycnt;
1788 caddr_t bpos0, bpos1;
1789 u_int64_t off, toff, verf;
1790 u_long *cookies = NULL, *cookiep;
1791 nfsattrbit_t attrbits, rderrbits, savbits;
1794 struct componentname cn;
1795 int at_root, needs_unbusy, not_zfs, supports_nfsv4acls;
1796 struct mount *mp, *new_mp;
1797 uint64_t mounted_on_fileno;
1799 if (nd->nd_repstat) {
1800 nfsrv_postopattr(nd, getret, &at);
1803 NFSM_DISSECT(tl, u_int32_t *, 6 * NFSX_UNSIGNED);
1804 off = fxdr_hyper(tl);
1807 verf = fxdr_hyper(tl);
1809 siz = fxdr_unsigned(int, *tl++);
1810 cnt = fxdr_unsigned(int, *tl);
1813 * Use the server's maximum data transfer size as the upper bound
1816 if (cnt > NFS_SRVMAXDATA(nd) || cnt < 0)
1817 cnt = NFS_SRVMAXDATA(nd);
1820 * siz is a "hint" of how much directory information (name, fileid,
1821 * cookie) should be in the reply. At least one client "hints" 0,
1822 * so I set it to cnt for that case. I also round it up to the
1823 * next multiple of DIRBLKSIZ.
1827 siz = ((siz + DIRBLKSIZ - 1) & ~(DIRBLKSIZ - 1));
1829 if (nd->nd_flag & ND_NFSV4) {
1830 error = nfsrv_getattrbits(nd, &attrbits, NULL, NULL);
1833 NFSSET_ATTRBIT(&savbits, &attrbits);
1834 NFSCLRNOTFILLABLE_ATTRBIT(&attrbits);
1835 NFSZERO_ATTRBIT(&rderrbits);
1836 NFSSETBIT_ATTRBIT(&rderrbits, NFSATTRBIT_RDATTRERROR);
1838 NFSZERO_ATTRBIT(&attrbits);
1841 nd->nd_repstat = getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1);
1842 if (!nd->nd_repstat) {
1843 if (off && verf != at.na_filerev) {
1845 * va_filerev is not sufficient as a cookie verifier,
1846 * since it is not supposed to change when entries are
1847 * removed/added unless that offset cookies returned to
1848 * the client are no longer valid.
1851 if (nd->nd_flag & ND_NFSV4) {
1852 nd->nd_repstat = NFSERR_NOTSAME;
1854 nd->nd_repstat = NFSERR_BAD_COOKIE;
1857 } else if ((nd->nd_flag & ND_NFSV4) && off == 0 && verf != 0) {
1858 nd->nd_repstat = NFSERR_BAD_COOKIE;
1861 if (!nd->nd_repstat && vp->v_type != VDIR)
1862 nd->nd_repstat = NFSERR_NOTDIR;
1863 if (!nd->nd_repstat && cnt == 0)
1864 nd->nd_repstat = NFSERR_TOOSMALL;
1865 if (!nd->nd_repstat)
1866 nd->nd_repstat = nfsvno_accchk(vp, VEXEC,
1867 nd->nd_cred, exp, p, NFSACCCHK_NOOVERRIDE,
1868 NFSACCCHK_VPISLOCKED, NULL);
1869 if (nd->nd_repstat) {
1871 if (nd->nd_flag & ND_NFSV3)
1872 nfsrv_postopattr(nd, getret, &at);
1875 not_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs");
1877 MALLOC(rbuf, caddr_t, siz, M_TEMP, M_WAITOK);
1881 free((caddr_t)cookies, M_TEMP);
1889 io.uio_offset = (off_t)off;
1891 io.uio_segflg = UIO_SYSSPACE;
1892 io.uio_rw = UIO_READ;
1894 nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag, &ncookies,
1896 off = (u_int64_t)io.uio_offset;
1898 siz -= io.uio_resid;
1900 getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1);
1902 if (!cookies && !nd->nd_repstat)
1903 nd->nd_repstat = NFSERR_PERM;
1904 if (!nd->nd_repstat)
1905 nd->nd_repstat = getret;
1906 if (nd->nd_repstat) {
1909 free((caddr_t)cookies, M_TEMP);
1910 free((caddr_t)rbuf, M_TEMP);
1911 if (nd->nd_flag & ND_NFSV3)
1912 nfsrv_postopattr(nd, getret, &at);
1916 * If nothing read, return eof
1921 if (nd->nd_flag & ND_NFSV3)
1922 nfsrv_postopattr(nd, getret, &at);
1923 NFSM_BUILD(tl, u_int32_t *, 4 * NFSX_UNSIGNED);
1924 txdr_hyper(at.na_filerev, tl);
1926 *tl++ = newnfs_false;
1928 free((caddr_t)cookies, M_TEMP);
1929 free((caddr_t)rbuf, M_TEMP);
1934 * Check for degenerate cases of nothing useful read.
1935 * If so go try again
1939 dp = (struct dirent *)cpos;
1943 * For some reason FreeBSD's ufs_readdir() chooses to back the
1944 * directory offset up to a block boundary, so it is necessary to
1945 * skip over the records that precede the requested offset. This
1946 * requires the assumption that file offset cookies monotonically
1948 * Since the offset cookies don't monotonically increase for ZFS,
1949 * this is not done when ZFS is the file system.
1951 while (cpos < cend && ncookies > 0 &&
1952 (dp->d_fileno == 0 || dp->d_type == DT_WHT ||
1953 (not_zfs != 0 && ((u_quad_t)(*cookiep)) <= toff) ||
1954 ((nd->nd_flag & ND_NFSV4) &&
1955 ((dp->d_namlen == 1 && dp->d_name[0] == '.') ||
1956 (dp->d_namlen==2 && dp->d_name[0]=='.' && dp->d_name[1]=='.'))))) {
1957 cpos += dp->d_reclen;
1958 dp = (struct dirent *)cpos;
1962 if (cpos >= cend || ncookies == 0) {
1969 * Busy the file system so that the mount point won't go away
1970 * and, as such, VFS_VGET() can be used safely.
1974 NFSVOPUNLOCK(vp, 0);
1975 nd->nd_repstat = vfs_busy(mp, 0);
1977 if (nd->nd_repstat != 0) {
1979 free(cookies, M_TEMP);
1981 if (nd->nd_flag & ND_NFSV3)
1982 nfsrv_postopattr(nd, getret, &at);
1987 * Save this position, in case there is an error before one entry
1991 bpos0 = nd->nd_bpos;
1994 * Fill in the first part of the reply.
1995 * dirlen is the reply length in bytes and cannot exceed cnt.
1996 * (Include the two booleans at the end of the reply in dirlen now,
1997 * so we recognize when we have exceeded cnt.)
1999 if (nd->nd_flag & ND_NFSV3) {
2000 dirlen = NFSX_V3POSTOPATTR + NFSX_VERF + 2 * NFSX_UNSIGNED;
2001 nfsrv_postopattr(nd, getret, &at);
2003 dirlen = NFSX_VERF + 2 * NFSX_UNSIGNED;
2005 NFSM_BUILD(tl, u_int32_t *, NFSX_VERF);
2006 txdr_hyper(at.na_filerev, tl);
2009 * Save this position, in case there is an empty reply needed.
2012 bpos1 = nd->nd_bpos;
2014 /* Loop through the records and build reply */
2016 while (cpos < cend && ncookies > 0 && dirlen < cnt) {
2017 nlen = dp->d_namlen;
2018 if (dp->d_fileno != 0 && dp->d_type != DT_WHT &&
2019 nlen <= NFS_MAXNAMLEN &&
2020 ((nd->nd_flag & ND_NFSV3) || nlen > 2 ||
2021 (nlen==2 && (dp->d_name[0]!='.' || dp->d_name[1]!='.'))
2022 || (nlen == 1 && dp->d_name[0] != '.'))) {
2024 * Save the current position in the reply, in case
2025 * this entry exceeds cnt.
2028 bpos1 = nd->nd_bpos;
2031 * For readdir_and_lookup get the vnode using
2040 mounted_on_fileno = (uint64_t)dp->d_fileno;
2041 if ((nd->nd_flag & ND_NFSV3) ||
2042 NFSNONZERO_ATTRBIT(&savbits)) {
2043 if (nd->nd_flag & ND_NFSV4)
2044 refp = nfsv4root_getreferral(NULL,
2048 r = VFS_VGET(mp, dp->d_fileno,
2052 if (r == EOPNOTSUPP) {
2055 cn.cn_nameiop = LOOKUP;
2063 cn.cn_nameptr = dp->d_name;
2064 cn.cn_namelen = nlen;
2065 cn.cn_flags = ISLASTCN |
2066 NOFOLLOW | LOCKLEAF |
2069 dp->d_name[0] == '.' &&
2070 dp->d_name[1] == '.')
2073 if (NFSVOPLOCK(vp, LK_SHARED)
2075 nd->nd_repstat = EPERM;
2078 if ((vp->v_vflag & VV_ROOT) != 0
2079 && (cn.cn_flags & ISDOTDOT)
2085 r = VOP_LOOKUP(vp, &nvp,
2094 * For NFSv4, check to see if nvp is
2095 * a mount point and get the mount
2096 * point vnode, as required.
2099 nfsrv_enable_crossmntpt != 0 &&
2100 (nd->nd_flag & ND_NFSV4) != 0 &&
2101 nvp->v_type == VDIR &&
2102 nvp->v_mountedhere != NULL) {
2103 new_mp = nvp->v_mountedhere;
2104 r = vfs_busy(new_mp, 0);
2108 r = VFS_ROOT(new_mp,
2118 ((nd->nd_flag & ND_NFSV3) ||
2119 NFSNONZERO_ATTRBIT(&attrbits))) {
2120 r = nfsvno_getfh(nvp, &nfh, p);
2122 r = nfsvno_getattr(nvp, nvap,
2129 if (!NFSISSET_ATTRBIT(&attrbits,
2130 NFSATTRBIT_RDATTRERROR)) {
2133 if (needs_unbusy != 0)
2142 * Build the directory record xdr
2144 if (nd->nd_flag & ND_NFSV3) {
2145 NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
2146 *tl++ = newnfs_true;
2148 *tl = txdr_unsigned(dp->d_fileno);
2149 dirlen += nfsm_strtom(nd, dp->d_name, nlen);
2150 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2152 *tl = txdr_unsigned(*cookiep);
2153 nfsrv_postopattr(nd, 0, nvap);
2154 dirlen += nfsm_fhtom(nd,(u_int8_t *)&nfh,0,1);
2155 dirlen += (5*NFSX_UNSIGNED+NFSX_V3POSTOPATTR);
2159 NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
2160 *tl++ = newnfs_true;
2162 *tl = txdr_unsigned(*cookiep);
2163 dirlen += nfsm_strtom(nd, dp->d_name, nlen);
2165 supports_nfsv4acls =
2166 nfs_supportsnfsv4acls(nvp);
2167 NFSVOPUNLOCK(nvp, 0);
2169 supports_nfsv4acls = 0;
2171 dirlen += nfsrv_putreferralattr(nd,
2174 if (nd->nd_repstat) {
2177 if (needs_unbusy != 0)
2182 dirlen += nfsvno_fillattr(nd, new_mp,
2183 nvp, nvap, &nfh, r, &rderrbits,
2184 nd->nd_cred, p, isdgram, 0,
2185 supports_nfsv4acls, at_root,
2188 dirlen += nfsvno_fillattr(nd, new_mp,
2189 nvp, nvap, &nfh, r, &attrbits,
2190 nd->nd_cred, p, isdgram, 0,
2191 supports_nfsv4acls, at_root,
2196 dirlen += (3 * NFSX_UNSIGNED);
2198 if (needs_unbusy != 0)
2203 cpos += dp->d_reclen;
2204 dp = (struct dirent *)cpos;
2212 * If dirlen > cnt, we must strip off the last entry. If that
2213 * results in an empty reply, report NFSERR_TOOSMALL.
2215 if (dirlen > cnt || nd->nd_repstat) {
2216 if (!nd->nd_repstat && entrycnt == 0)
2217 nd->nd_repstat = NFSERR_TOOSMALL;
2219 newnfs_trimtrailing(nd, mb0, bpos0);
2221 newnfs_trimtrailing(nd, mb1, bpos1);
2223 } else if (cpos < cend)
2225 if (!nd->nd_repstat) {
2226 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2227 *tl++ = newnfs_false;
2233 FREE((caddr_t)cookies, M_TEMP);
2234 FREE((caddr_t)rbuf, M_TEMP);
2237 NFSEXITCODE2(0, nd);
2241 NFSEXITCODE2(error, nd);
2246 * Get the settable attributes out of the mbuf list.
2247 * (Return 0 or EBADRPC)
2250 nfsrv_sattr(struct nfsrv_descript *nd, struct nfsvattr *nvap,
2251 nfsattrbit_t *attrbitp, NFSACL_T *aclp, struct thread *p)
2254 struct nfsv2_sattr *sp;
2255 int error = 0, toclient = 0;
2257 switch (nd->nd_flag & (ND_NFSV2 | ND_NFSV3 | ND_NFSV4)) {
2259 NFSM_DISSECT(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
2261 * Some old clients didn't fill in the high order 16bits.
2262 * --> check the low order 2 bytes for 0xffff
2264 if ((fxdr_unsigned(int, sp->sa_mode) & 0xffff) != 0xffff)
2265 nvap->na_mode = nfstov_mode(sp->sa_mode);
2266 if (sp->sa_uid != newnfs_xdrneg1)
2267 nvap->na_uid = fxdr_unsigned(uid_t, sp->sa_uid);
2268 if (sp->sa_gid != newnfs_xdrneg1)
2269 nvap->na_gid = fxdr_unsigned(gid_t, sp->sa_gid);
2270 if (sp->sa_size != newnfs_xdrneg1)
2271 nvap->na_size = fxdr_unsigned(u_quad_t, sp->sa_size);
2272 if (sp->sa_atime.nfsv2_sec != newnfs_xdrneg1) {
2274 fxdr_nfsv2time(&sp->sa_atime, &nvap->na_atime);
2276 nvap->na_atime.tv_sec =
2277 fxdr_unsigned(u_int32_t,sp->sa_atime.nfsv2_sec);
2278 nvap->na_atime.tv_nsec = 0;
2281 if (sp->sa_mtime.nfsv2_sec != newnfs_xdrneg1)
2282 fxdr_nfsv2time(&sp->sa_mtime, &nvap->na_mtime);
2285 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2286 if (*tl == newnfs_true) {
2287 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2288 nvap->na_mode = nfstov_mode(*tl);
2290 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2291 if (*tl == newnfs_true) {
2292 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2293 nvap->na_uid = fxdr_unsigned(uid_t, *tl);
2295 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2296 if (*tl == newnfs_true) {
2297 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2298 nvap->na_gid = fxdr_unsigned(gid_t, *tl);
2300 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2301 if (*tl == newnfs_true) {
2302 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2303 nvap->na_size = fxdr_hyper(tl);
2305 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2306 switch (fxdr_unsigned(int, *tl)) {
2307 case NFSV3SATTRTIME_TOCLIENT:
2308 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2309 fxdr_nfsv3time(tl, &nvap->na_atime);
2312 case NFSV3SATTRTIME_TOSERVER:
2313 vfs_timestamp(&nvap->na_atime);
2314 nvap->na_vaflags |= VA_UTIMES_NULL;
2317 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2318 switch (fxdr_unsigned(int, *tl)) {
2319 case NFSV3SATTRTIME_TOCLIENT:
2320 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2321 fxdr_nfsv3time(tl, &nvap->na_mtime);
2322 nvap->na_vaflags &= ~VA_UTIMES_NULL;
2324 case NFSV3SATTRTIME_TOSERVER:
2325 vfs_timestamp(&nvap->na_mtime);
2327 nvap->na_vaflags |= VA_UTIMES_NULL;
2332 error = nfsv4_sattr(nd, nvap, attrbitp, aclp, p);
2335 NFSEXITCODE2(error, nd);
2340 * Handle the setable attributes for V4.
2341 * Returns NFSERR_BADXDR if it can't be parsed, 0 otherwise.
2344 nfsv4_sattr(struct nfsrv_descript *nd, struct nfsvattr *nvap,
2345 nfsattrbit_t *attrbitp, NFSACL_T *aclp, struct thread *p)
2350 int error, attrsize, bitpos, aclsize, aceerr, retnotsup = 0;
2352 u_char *cp, namestr[NFSV4_SMALLSTR + 1];
2356 error = nfsrv_getattrbits(nd, attrbitp, NULL, &retnotsup);
2359 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2360 attrsize = fxdr_unsigned(int, *tl);
2363 * Loop around getting the setable attributes. If an unsupported
2364 * one is found, set nd_repstat == NFSERR_ATTRNOTSUPP and return.
2367 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2368 bitpos = NFSATTRBIT_MAX;
2372 for (; bitpos < NFSATTRBIT_MAX; bitpos++) {
2373 if (attrsum > attrsize) {
2374 error = NFSERR_BADXDR;
2377 if (NFSISSET_ATTRBIT(attrbitp, bitpos))
2379 case NFSATTRBIT_SIZE:
2380 NFSM_DISSECT(tl, u_int32_t *, NFSX_HYPER);
2381 nvap->na_size = fxdr_hyper(tl);
2382 attrsum += NFSX_HYPER;
2384 case NFSATTRBIT_ACL:
2385 error = nfsrv_dissectacl(nd, aclp, &aceerr, &aclsize,
2389 if (aceerr && !nd->nd_repstat)
2390 nd->nd_repstat = aceerr;
2393 case NFSATTRBIT_ARCHIVE:
2394 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2395 if (!nd->nd_repstat)
2396 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2397 attrsum += NFSX_UNSIGNED;
2399 case NFSATTRBIT_HIDDEN:
2400 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2401 if (!nd->nd_repstat)
2402 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2403 attrsum += NFSX_UNSIGNED;
2405 case NFSATTRBIT_MIMETYPE:
2406 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2407 i = fxdr_unsigned(int, *tl);
2408 error = nfsm_advance(nd, NFSM_RNDUP(i), -1);
2411 if (!nd->nd_repstat)
2412 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2413 attrsum += (NFSX_UNSIGNED + NFSM_RNDUP(i));
2415 case NFSATTRBIT_MODE:
2416 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2417 nvap->na_mode = nfstov_mode(*tl);
2418 attrsum += NFSX_UNSIGNED;
2420 case NFSATTRBIT_OWNER:
2421 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2422 j = fxdr_unsigned(int, *tl);
2424 error = NFSERR_BADXDR;
2427 if (j > NFSV4_SMALLSTR)
2428 cp = malloc(j + 1, M_NFSSTRING, M_WAITOK);
2431 error = nfsrv_mtostr(nd, cp, j);
2433 if (j > NFSV4_SMALLSTR)
2434 free(cp, M_NFSSTRING);
2437 if (!nd->nd_repstat) {
2438 nd->nd_repstat = nfsv4_strtouid(nd, cp, j, &uid,
2440 if (!nd->nd_repstat)
2443 if (j > NFSV4_SMALLSTR)
2444 free(cp, M_NFSSTRING);
2445 attrsum += (NFSX_UNSIGNED + NFSM_RNDUP(j));
2447 case NFSATTRBIT_OWNERGROUP:
2448 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2449 j = fxdr_unsigned(int, *tl);
2451 error = NFSERR_BADXDR;
2454 if (j > NFSV4_SMALLSTR)
2455 cp = malloc(j + 1, M_NFSSTRING, M_WAITOK);
2458 error = nfsrv_mtostr(nd, cp, j);
2460 if (j > NFSV4_SMALLSTR)
2461 free(cp, M_NFSSTRING);
2464 if (!nd->nd_repstat) {
2465 nd->nd_repstat = nfsv4_strtogid(nd, cp, j, &gid,
2467 if (!nd->nd_repstat)
2470 if (j > NFSV4_SMALLSTR)
2471 free(cp, M_NFSSTRING);
2472 attrsum += (NFSX_UNSIGNED + NFSM_RNDUP(j));
2474 case NFSATTRBIT_SYSTEM:
2475 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2476 if (!nd->nd_repstat)
2477 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2478 attrsum += NFSX_UNSIGNED;
2480 case NFSATTRBIT_TIMEACCESSSET:
2481 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2482 attrsum += NFSX_UNSIGNED;
2483 if (fxdr_unsigned(int, *tl)==NFSV4SATTRTIME_TOCLIENT) {
2484 NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME);
2485 fxdr_nfsv4time(tl, &nvap->na_atime);
2487 attrsum += NFSX_V4TIME;
2489 vfs_timestamp(&nvap->na_atime);
2490 nvap->na_vaflags |= VA_UTIMES_NULL;
2493 case NFSATTRBIT_TIMEBACKUP:
2494 NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME);
2495 if (!nd->nd_repstat)
2496 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2497 attrsum += NFSX_V4TIME;
2499 case NFSATTRBIT_TIMECREATE:
2500 NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME);
2501 if (!nd->nd_repstat)
2502 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2503 attrsum += NFSX_V4TIME;
2505 case NFSATTRBIT_TIMEMODIFYSET:
2506 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2507 attrsum += NFSX_UNSIGNED;
2508 if (fxdr_unsigned(int, *tl)==NFSV4SATTRTIME_TOCLIENT) {
2509 NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME);
2510 fxdr_nfsv4time(tl, &nvap->na_mtime);
2511 nvap->na_vaflags &= ~VA_UTIMES_NULL;
2512 attrsum += NFSX_V4TIME;
2514 vfs_timestamp(&nvap->na_mtime);
2516 nvap->na_vaflags |= VA_UTIMES_NULL;
2520 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2522 * set bitpos so we drop out of the loop.
2524 bitpos = NFSATTRBIT_MAX;
2530 * some clients pad the attrlist, so we need to skip over the
2533 if (attrsum > attrsize) {
2534 error = NFSERR_BADXDR;
2536 attrsize = NFSM_RNDUP(attrsize);
2537 if (attrsum < attrsize)
2538 error = nfsm_advance(nd, attrsize - attrsum, -1);
2541 NFSEXITCODE2(error, nd);
2546 * Check/setup export credentials.
2549 nfsd_excred(struct nfsrv_descript *nd, struct nfsexstuff *exp,
2550 struct ucred *credanon)
2555 * Check/setup credentials.
2557 if (nd->nd_flag & ND_GSS)
2558 exp->nes_exflag &= ~MNT_EXPORTANON;
2561 * Check to see if the operation is allowed for this security flavor.
2562 * RFC2623 suggests that the NFSv3 Fsinfo RPC be allowed to
2563 * AUTH_NONE or AUTH_SYS for file systems requiring RPCSEC_GSS.
2564 * Also, allow Secinfo, so that it can acquire the correct flavor(s).
2566 if (nfsvno_testexp(nd, exp) &&
2567 nd->nd_procnum != NFSV4OP_SECINFO &&
2568 nd->nd_procnum != NFSPROC_FSINFO) {
2569 if (nd->nd_flag & ND_NFSV4)
2570 error = NFSERR_WRONGSEC;
2572 error = (NFSERR_AUTHERR | AUTH_TOOWEAK);
2577 * Check to see if the file system is exported V4 only.
2579 if (NFSVNO_EXV4ONLY(exp) && !(nd->nd_flag & ND_NFSV4)) {
2580 error = NFSERR_PROGNOTV4;
2585 * Now, map the user credentials.
2586 * (Note that ND_AUTHNONE will only be set for an NFSv3
2587 * Fsinfo RPC. If set for anything else, this code might need
2590 if (NFSVNO_EXPORTED(exp) &&
2591 ((!(nd->nd_flag & ND_GSS) && nd->nd_cred->cr_uid == 0) ||
2592 NFSVNO_EXPORTANON(exp) ||
2593 (nd->nd_flag & ND_AUTHNONE))) {
2594 nd->nd_cred->cr_uid = credanon->cr_uid;
2595 nd->nd_cred->cr_gid = credanon->cr_gid;
2596 crsetgroups(nd->nd_cred, credanon->cr_ngroups,
2597 credanon->cr_groups);
2601 NFSEXITCODE2(error, nd);
2609 nfsvno_checkexp(struct mount *mp, struct sockaddr *nam, struct nfsexstuff *exp,
2610 struct ucred **credp)
2612 int i, error, *secflavors;
2614 error = VFS_CHECKEXP(mp, nam, &exp->nes_exflag, credp,
2615 &exp->nes_numsecflavor, &secflavors);
2617 if (nfs_rootfhset) {
2618 exp->nes_exflag = 0;
2619 exp->nes_numsecflavor = 0;
2623 /* Copy the security flavors. */
2624 for (i = 0; i < exp->nes_numsecflavor; i++)
2625 exp->nes_secflavors[i] = secflavors[i];
2632 * Get a vnode for a file handle and export stuff.
2635 nfsvno_fhtovp(struct mount *mp, fhandle_t *fhp, struct sockaddr *nam,
2636 int lktype, struct vnode **vpp, struct nfsexstuff *exp,
2637 struct ucred **credp)
2639 int i, error, *secflavors;
2642 exp->nes_numsecflavor = 0;
2643 if (VFS_NEEDSGIANT(mp))
2646 error = VFS_FHTOVP(mp, &fhp->fh_fid, LK_EXCLUSIVE, vpp);
2648 /* Make sure the server replies ESTALE to the client. */
2650 if (nam && !error) {
2651 error = VFS_CHECKEXP(mp, nam, &exp->nes_exflag, credp,
2652 &exp->nes_numsecflavor, &secflavors);
2654 if (nfs_rootfhset) {
2655 exp->nes_exflag = 0;
2656 exp->nes_numsecflavor = 0;
2662 /* Copy the security flavors. */
2663 for (i = 0; i < exp->nes_numsecflavor; i++)
2664 exp->nes_secflavors[i] = secflavors[i];
2667 if (error == 0 && lktype == LK_SHARED)
2669 * It would be much better to pass lktype to VFS_FHTOVP(),
2670 * but this will have to do until VFS_FHTOVP() has a lock
2671 * type argument like VFS_VGET().
2673 NFSVOPLOCK(*vpp, LK_DOWNGRADE | LK_RETRY);
2680 * nfsd_fhtovp() - convert a fh to a vnode ptr
2681 * - look up fsid in mount list (if not found ret error)
2682 * - get vp and export rights by calling nfsvno_fhtovp()
2683 * - if cred->cr_uid == 0 or MNT_EXPORTANON set it to credanon
2685 * - if mpp != NULL, return the mount point so that it can
2686 * be used for vn_finished_write() by the caller
2689 nfsd_fhtovp(struct nfsrv_descript *nd, struct nfsrvfh *nfp, int lktype,
2690 struct vnode **vpp, struct nfsexstuff *exp,
2691 struct mount **mpp, int startwrite, struct thread *p)
2694 struct ucred *credanon;
2697 fhp = (fhandle_t *)nfp->nfsrvfh_data;
2699 * Check for the special case of the nfsv4root_fh.
2701 mp = vfs_busyfs(&fhp->fh_fsid);
2706 nd->nd_repstat = ESTALE;
2711 vn_start_write(NULL, mpp, V_WAIT);
2712 if (lktype == LK_SHARED && !(MNT_SHARED_WRITES(mp)))
2713 lktype = LK_EXCLUSIVE;
2715 nd->nd_repstat = nfsvno_fhtovp(mp, fhp, nd->nd_nam, lktype, vpp, exp,
2720 * For NFSv4 without a pseudo root fs, unexported file handles
2721 * can be returned, so that Lookup works everywhere.
2723 if (!nd->nd_repstat && exp->nes_exflag == 0 &&
2724 !(nd->nd_flag & ND_NFSV4)) {
2726 nd->nd_repstat = EACCES;
2730 * Personally, I've never seen any point in requiring a
2731 * reserved port#, since only in the rare case where the
2732 * clients are all boxes with secure system priviledges,
2733 * does it provide any enhanced security, but... some people
2734 * believe it to be useful and keep putting this code back in.
2735 * (There is also some "security checker" out there that
2736 * complains if the nfs server doesn't enforce this.)
2737 * However, note the following:
2738 * RFC3530 (NFSv4) specifies that a reserved port# not be
2740 * RFC2623 recommends that, if a reserved port# is checked for,
2741 * that there be a way to turn that off--> ifdef'd.
2743 #ifdef NFS_REQRSVPORT
2744 if (!nd->nd_repstat) {
2745 struct sockaddr_in *saddr;
2746 struct sockaddr_in6 *saddr6;
2748 saddr = NFSSOCKADDR(nd->nd_nam, struct sockaddr_in *);
2749 saddr6 = NFSSOCKADDR(nd->nd_nam, struct sockaddr_in6 *);
2750 if (!(nd->nd_flag & ND_NFSV4) &&
2751 ((saddr->sin_family == AF_INET &&
2752 ntohs(saddr->sin_port) >= IPPORT_RESERVED) ||
2753 (saddr6->sin6_family == AF_INET6 &&
2754 ntohs(saddr6->sin6_port) >= IPPORT_RESERVED))) {
2756 nd->nd_repstat = (NFSERR_AUTHERR | AUTH_TOOWEAK);
2759 #endif /* NFS_REQRSVPORT */
2762 * Check/setup credentials.
2764 if (!nd->nd_repstat) {
2765 nd->nd_saveduid = nd->nd_cred->cr_uid;
2766 nd->nd_repstat = nfsd_excred(nd, exp, credanon);
2770 if (credanon != NULL)
2772 if (nd->nd_repstat) {
2774 vn_finished_write(mp);
2781 NFSEXITCODE2(0, nd);
2788 fp_getfvp(struct thread *p, int fd, struct file **fpp, struct vnode **vpp)
2790 struct filedesc *fdp;
2794 fdp = p->td_proc->p_fd;
2795 if (fd >= fdp->fd_nfiles ||
2796 (fp = fdp->fd_ofiles[fd]) == NULL) {
2808 * Called from nfssvc() to update the exports list. Just call
2809 * vfs_export(). This has to be done, since the v4 root fake fs isn't
2810 * in the mount list.
2813 nfsrv_v4rootexport(void *argp, struct ucred *cred, struct thread *p)
2815 struct nfsex_args *nfsexargp = (struct nfsex_args *)argp;
2817 struct nameidata nd;
2820 error = vfs_export(&nfsv4root_mnt, &nfsexargp->export);
2821 if ((nfsexargp->export.ex_flags & MNT_DELEXPORT) != 0)
2823 else if (error == 0) {
2824 if (nfsexargp->fspec == NULL) {
2829 * If fspec != NULL, this is the v4root path.
2831 NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_USERSPACE,
2832 nfsexargp->fspec, p);
2833 if ((error = namei(&nd)) != 0)
2835 error = nfsvno_getfh(nd.ni_vp, &fh, p);
2838 nfs_rootfh.nfsrvfh_len = NFSX_MYFH;
2839 NFSBCOPY((caddr_t)&fh,
2840 nfs_rootfh.nfsrvfh_data,
2841 sizeof (fhandle_t));
2852 * Get the tcp socket sequence numbers we need.
2853 * (Maybe this should be moved to the tcp sources?)
2856 nfsrv_getsocksndseq(struct socket *so, tcp_seq *maxp, tcp_seq *unap)
2862 inp = sotoinpcb(so);
2863 KASSERT(inp != NULL, ("nfsrv_getsocksndseq: inp == NULL"));
2865 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
2870 tp = intotcpcb(inp);
2871 if (tp->t_state != TCPS_ESTABLISHED) {
2876 *maxp = tp->snd_max;
2877 *unap = tp->snd_una;
2886 * This function needs to test to see if the system is near its limit
2887 * for memory allocation via malloc() or mget() and return True iff
2888 * either of these resources are near their limit.
2889 * XXX (For now, this is just a stub.)
2891 int nfsrv_testmalloclimit = 0;
2893 nfsrv_mallocmget_limit(void)
2895 static int printmesg = 0;
2896 static int testval = 1;
2898 if (nfsrv_testmalloclimit && (testval++ % 1000) == 0) {
2899 if ((printmesg++ % 100) == 0)
2900 printf("nfsd: malloc/mget near limit\n");
2907 * BSD specific initialization of a mount point.
2912 static int inited = 0;
2917 nfsv4root_mnt.mnt_flag = (MNT_RDONLY | MNT_EXPORTED);
2918 TAILQ_INIT(&nfsv4root_mnt.mnt_nvnodelist);
2919 TAILQ_INIT(&nfsv4root_mnt.mnt_activevnodelist);
2920 nfsv4root_mnt.mnt_export = NULL;
2921 TAILQ_INIT(&nfsv4root_opt);
2922 TAILQ_INIT(&nfsv4root_newopt);
2923 nfsv4root_mnt.mnt_opt = &nfsv4root_opt;
2924 nfsv4root_mnt.mnt_optnew = &nfsv4root_newopt;
2925 nfsv4root_mnt.mnt_nvnodelistsize = 0;
2926 nfsv4root_mnt.mnt_activevnodelistsize = 0;
2930 * Get a vnode for a file handle, without checking exports, etc.
2933 nfsvno_getvp(fhandle_t *fhp)
2939 mp = vfs_busyfs(&fhp->fh_fsid);
2942 error = VFS_FHTOVP(mp, &fhp->fh_fid, LK_EXCLUSIVE, &vp);
2950 * Do a local VOP_ADVLOCK().
2953 nfsvno_advlock(struct vnode *vp, int ftype, u_int64_t first,
2954 u_int64_t end, struct thread *td)
2960 if (nfsrv_dolocallocks == 0)
2963 /* Check for VI_DOOMED here, so that VOP_ADVLOCK() isn't performed. */
2964 if ((vp->v_iflag & VI_DOOMED) != 0) {
2969 fl.l_whence = SEEK_SET;
2971 fl.l_start = (off_t)first;
2972 if (end == NFS64BITSSET) {
2976 fl.l_len = (off_t)tlen;
2979 * For FreeBSD8, the l_pid and l_sysid must be set to the same
2980 * values for all calls, so that all locks will be held by the
2981 * nfsd server. (The nfsd server handles conflicts between the
2983 * Since an NFSv4 lockowner is a ClientID plus an array of up to 1024
2984 * bytes, so it can't be put in l_sysid.
2986 if (nfsv4_sysid == 0)
2987 nfsv4_sysid = nlm_acquire_next_sysid();
2988 fl.l_pid = (pid_t)0;
2989 fl.l_sysid = (int)nfsv4_sysid;
2991 NFSVOPUNLOCK(vp, 0);
2992 if (ftype == F_UNLCK)
2993 error = VOP_ADVLOCK(vp, (caddr_t)td->td_proc, F_UNLCK, &fl,
2994 (F_POSIX | F_REMOTE));
2996 error = VOP_ADVLOCK(vp, (caddr_t)td->td_proc, F_SETLK, &fl,
2997 (F_POSIX | F_REMOTE));
2998 NFSVOPLOCK(vp, LK_EXCLUSIVE | LK_RETRY);
3006 * Check the nfsv4 root exports.
3009 nfsvno_v4rootexport(struct nfsrv_descript *nd)
3011 struct ucred *credanon;
3012 int exflags, error = 0, numsecflavor, *secflavors, i;
3014 error = vfs_stdcheckexp(&nfsv4root_mnt, nd->nd_nam, &exflags,
3015 &credanon, &numsecflavor, &secflavors);
3017 error = NFSERR_PROGUNAVAIL;
3020 if (credanon != NULL)
3022 for (i = 0; i < numsecflavor; i++) {
3023 if (secflavors[i] == AUTH_SYS)
3024 nd->nd_flag |= ND_EXAUTHSYS;
3025 else if (secflavors[i] == RPCSEC_GSS_KRB5)
3026 nd->nd_flag |= ND_EXGSS;
3027 else if (secflavors[i] == RPCSEC_GSS_KRB5I)
3028 nd->nd_flag |= ND_EXGSSINTEGRITY;
3029 else if (secflavors[i] == RPCSEC_GSS_KRB5P)
3030 nd->nd_flag |= ND_EXGSSPRIVACY;
3039 * Nfs server psuedo system call for the nfsd's
3045 nfssvc_nfsd(struct thread *td, struct nfssvc_args *uap)
3048 struct nfsd_addsock_args sockarg;
3049 struct nfsd_nfsd_args nfsdarg;
3052 if (uap->flag & NFSSVC_NFSDADDSOCK) {
3053 error = copyin(uap->argp, (caddr_t)&sockarg, sizeof (sockarg));
3057 * Since we don't know what rights might be required,
3058 * pretend that we need them all. It is better to be too
3059 * careful than too reckless.
3061 if ((error = fget(td, sockarg.sock, CAP_SOCK_ALL, &fp)) != 0)
3063 if (fp->f_type != DTYPE_SOCKET) {
3068 error = nfsrvd_addsock(fp);
3070 } else if (uap->flag & NFSSVC_NFSDNFSD) {
3071 if (uap->argp == NULL) {
3075 error = copyin(uap->argp, (caddr_t)&nfsdarg,
3079 error = nfsrvd_nfsd(td, &nfsdarg);
3081 error = nfssvc_srvcall(td, uap, td->td_ucred);
3090 nfssvc_srvcall(struct thread *p, struct nfssvc_args *uap, struct ucred *cred)
3092 struct nfsex_args export;
3093 struct file *fp = NULL;
3095 struct nfsd_clid adminrevoke;
3096 struct nfsd_dumplist dumplist;
3097 struct nfsd_dumpclients *dumpclients;
3098 struct nfsd_dumplocklist dumplocklist;
3099 struct nfsd_dumplocks *dumplocks;
3100 struct nameidata nd;
3102 int error = EINVAL, igotlock;
3104 static int suspend_nfsd = 0;
3106 if (uap->flag & NFSSVC_PUBLICFH) {
3107 NFSBZERO((caddr_t)&nfs_pubfh.nfsrvfh_data,
3108 sizeof (fhandle_t));
3109 error = copyin(uap->argp,
3110 &nfs_pubfh.nfsrvfh_data, sizeof (fhandle_t));
3113 } else if (uap->flag & NFSSVC_V4ROOTEXPORT) {
3114 error = copyin(uap->argp,(caddr_t)&export,
3115 sizeof (struct nfsex_args));
3117 error = nfsrv_v4rootexport(&export, cred, p);
3118 } else if (uap->flag & NFSSVC_NOPUBLICFH) {
3121 } else if (uap->flag & NFSSVC_STABLERESTART) {
3122 error = copyin(uap->argp, (caddr_t)&stablefd,
3125 error = fp_getfvp(p, stablefd, &fp, &vp);
3126 if (!error && (NFSFPFLAG(fp) & (FREAD | FWRITE)) != (FREAD | FWRITE))
3128 if (!error && newnfs_numnfsd != 0)
3131 nfsrv_stablefirst.nsf_fp = fp;
3132 nfsrv_setupstable(p);
3134 } else if (uap->flag & NFSSVC_ADMINREVOKE) {
3135 error = copyin(uap->argp, (caddr_t)&adminrevoke,
3136 sizeof (struct nfsd_clid));
3138 error = nfsrv_adminrevoke(&adminrevoke, p);
3139 } else if (uap->flag & NFSSVC_DUMPCLIENTS) {
3140 error = copyin(uap->argp, (caddr_t)&dumplist,
3141 sizeof (struct nfsd_dumplist));
3142 if (!error && (dumplist.ndl_size < 1 ||
3143 dumplist.ndl_size > NFSRV_MAXDUMPLIST))
3146 len = sizeof (struct nfsd_dumpclients) * dumplist.ndl_size;
3147 dumpclients = (struct nfsd_dumpclients *)malloc(len,
3149 nfsrv_dumpclients(dumpclients, dumplist.ndl_size);
3150 error = copyout(dumpclients,
3151 CAST_USER_ADDR_T(dumplist.ndl_list), len);
3152 free((caddr_t)dumpclients, M_TEMP);
3154 } else if (uap->flag & NFSSVC_DUMPLOCKS) {
3155 error = copyin(uap->argp, (caddr_t)&dumplocklist,
3156 sizeof (struct nfsd_dumplocklist));
3157 if (!error && (dumplocklist.ndllck_size < 1 ||
3158 dumplocklist.ndllck_size > NFSRV_MAXDUMPLIST))
3161 error = nfsrv_lookupfilename(&nd,
3162 dumplocklist.ndllck_fname, p);
3164 len = sizeof (struct nfsd_dumplocks) *
3165 dumplocklist.ndllck_size;
3166 dumplocks = (struct nfsd_dumplocks *)malloc(len,
3168 nfsrv_dumplocks(nd.ni_vp, dumplocks,
3169 dumplocklist.ndllck_size, p);
3171 error = copyout(dumplocks,
3172 CAST_USER_ADDR_T(dumplocklist.ndllck_list), len);
3173 free((caddr_t)dumplocks, M_TEMP);
3175 } else if (uap->flag & NFSSVC_BACKUPSTABLE) {
3178 nfsd_master_pid = procp->p_pid;
3179 bcopy(procp->p_comm, nfsd_master_comm, MAXCOMLEN + 1);
3180 nfsd_master_start = procp->p_stats->p_start;
3181 nfsd_master_proc = procp;
3183 } else if ((uap->flag & NFSSVC_SUSPENDNFSD) != 0) {
3184 NFSLOCKV4ROOTMUTEX();
3185 if (suspend_nfsd == 0) {
3186 /* Lock out all nfsd threads */
3188 igotlock = nfsv4_lock(&nfsd_suspend_lock, 1,
3189 NULL, NFSV4ROOTLOCKMUTEXPTR, NULL);
3190 } while (igotlock == 0 && suspend_nfsd == 0);
3193 NFSUNLOCKV4ROOTMUTEX();
3195 } else if ((uap->flag & NFSSVC_RESUMENFSD) != 0) {
3196 NFSLOCKV4ROOTMUTEX();
3197 if (suspend_nfsd != 0) {
3198 nfsv4_unlock(&nfsd_suspend_lock, 0);
3201 NFSUNLOCKV4ROOTMUTEX();
3211 * Returns 0 if ok, 1 otherwise.
3214 nfsvno_testexp(struct nfsrv_descript *nd, struct nfsexstuff *exp)
3219 * This seems odd, but allow the case where the security flavor
3220 * list is empty. This happens when NFSv4 is traversing non-exported
3221 * file systems. Exported file systems should always have a non-empty
3222 * security flavor list.
3224 if (exp->nes_numsecflavor == 0)
3227 for (i = 0; i < exp->nes_numsecflavor; i++) {
3229 * The tests for privacy and integrity must be first,
3230 * since ND_GSS is set for everything but AUTH_SYS.
3232 if (exp->nes_secflavors[i] == RPCSEC_GSS_KRB5P &&
3233 (nd->nd_flag & ND_GSSPRIVACY))
3235 if (exp->nes_secflavors[i] == RPCSEC_GSS_KRB5I &&
3236 (nd->nd_flag & ND_GSSINTEGRITY))
3238 if (exp->nes_secflavors[i] == RPCSEC_GSS_KRB5 &&
3239 (nd->nd_flag & ND_GSS))
3241 if (exp->nes_secflavors[i] == AUTH_SYS &&
3242 (nd->nd_flag & ND_GSS) == 0)
3249 * Calculate a hash value for the fid in a file handle.
3252 nfsrv_hashfh(fhandle_t *fhp)
3256 hashval = hash32_buf(&fhp->fh_fid, sizeof(struct fid), 0);
3261 * Signal the userland master nfsd to backup the stable restart file.
3264 nfsrv_backupstable(void)
3268 if (nfsd_master_proc != NULL) {
3269 procp = pfind(nfsd_master_pid);
3270 /* Try to make sure it is the correct process. */
3271 if (procp == nfsd_master_proc &&
3272 procp->p_stats->p_start.tv_sec ==
3273 nfsd_master_start.tv_sec &&
3274 procp->p_stats->p_start.tv_usec ==
3275 nfsd_master_start.tv_usec &&
3276 strcmp(procp->p_comm, nfsd_master_comm) == 0)
3277 kern_psignal(procp, SIGUSR2);
3279 nfsd_master_proc = NULL;
3286 extern int (*nfsd_call_nfsd)(struct thread *, struct nfssvc_args *);
3289 * Called once to initialize data structures...
3292 nfsd_modevent(module_t mod, int type, void *data)
3295 static int loaded = 0;
3302 mtx_init(&nfs_cache_mutex, "nfs_cache_mutex", NULL, MTX_DEF);
3303 mtx_init(&nfs_v4root_mutex, "nfs_v4root_mutex", NULL, MTX_DEF);
3304 mtx_init(&nfsv4root_mnt.mnt_mtx, "struct mount mtx", NULL,
3306 lockinit(&nfsv4root_mnt.mnt_explock, PVFS, "explock", 0, 0);
3313 #ifdef VV_DISABLEDELEG
3314 vn_deleg_ops.vndeleg_recall = nfsd_recalldelegation;
3315 vn_deleg_ops.vndeleg_disable = nfsd_disabledelegation;
3317 nfsd_call_servertimer = nfsrv_servertimer;
3318 nfsd_call_nfsd = nfssvc_nfsd;
3323 if (newnfs_numnfsd != 0) {
3328 #ifdef VV_DISABLEDELEG
3329 vn_deleg_ops.vndeleg_recall = NULL;
3330 vn_deleg_ops.vndeleg_disable = NULL;
3332 nfsd_call_servertimer = NULL;
3333 nfsd_call_nfsd = NULL;
3335 /* Clean out all NFSv4 state. */
3336 nfsrv_throwawayallstate(curthread);
3338 /* Clean the NFS server reply cache */
3339 nfsrvd_cleancache();
3341 /* Free up the krpc server pool. */
3342 if (nfsrvd_pool != NULL)
3343 svcpool_destroy(nfsrvd_pool);
3345 /* and get rid of the locks */
3346 mtx_destroy(&nfs_cache_mutex);
3347 mtx_destroy(&nfs_v4root_mutex);
3348 mtx_destroy(&nfsv4root_mnt.mnt_mtx);
3349 lockdestroy(&nfsv4root_mnt.mnt_explock);
3361 static moduledata_t nfsd_mod = {
3366 DECLARE_MODULE(nfsd, nfsd_mod, SI_SUB_VFS, SI_ORDER_ANY);
3368 /* So that loader and kldload(2) can find us, wherever we are.. */
3369 MODULE_VERSION(nfsd, 1);
3370 MODULE_DEPEND(nfsd, nfscommon, 1, 1, 1);
3371 MODULE_DEPEND(nfsd, nfslock, 1, 1, 1);
3372 MODULE_DEPEND(nfsd, nfslockd, 1, 1, 1);
3373 MODULE_DEPEND(nfsd, krpc, 1, 1, 1);
3374 MODULE_DEPEND(nfsd, nfssvc, 1, 1, 1);