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 struct vfsoptlist nfsv4root_opt, nfsv4root_newopt;
62 struct mtx nfs_cache_mutex;
63 struct mtx nfs_v4root_mutex;
64 struct nfsrvfh nfs_rootfh, nfs_pubfh;
65 int nfs_pubfhset = 0, nfs_rootfhset = 0;
66 struct proc *nfsd_master_proc = NULL;
67 static pid_t nfsd_master_pid = (pid_t)-1;
68 static char nfsd_master_comm[MAXCOMLEN + 1];
69 static struct timeval nfsd_master_start;
70 static uint32_t nfsv4_sysid = 0;
72 static int nfssvc_srvcall(struct thread *, struct nfssvc_args *,
75 int nfsrv_enable_crossmntpt = 1;
76 static int nfs_commit_blks;
77 static int nfs_commit_miss;
78 extern int nfsrv_issuedelegs;
79 extern int nfsrv_dolocallocks;
81 SYSCTL_NODE(_vfs, OID_AUTO, nfsd, CTLFLAG_RW, 0, "New NFS server");
82 SYSCTL_INT(_vfs_nfsd, OID_AUTO, mirrormnt, CTLFLAG_RW,
83 &nfsrv_enable_crossmntpt, 0, "Enable nfsd to cross mount points");
84 SYSCTL_INT(_vfs_nfsd, OID_AUTO, commit_blks, CTLFLAG_RW, &nfs_commit_blks,
86 SYSCTL_INT(_vfs_nfsd, OID_AUTO, commit_miss, CTLFLAG_RW, &nfs_commit_miss,
88 SYSCTL_INT(_vfs_nfsd, OID_AUTO, issue_delegations, CTLFLAG_RW,
89 &nfsrv_issuedelegs, 0, "Enable nfsd to issue delegations");
90 SYSCTL_INT(_vfs_nfsd, OID_AUTO, enable_locallocks, CTLFLAG_RW,
91 &nfsrv_dolocallocks, 0, "Enable nfsd to acquire local locks on files");
93 #define MAX_REORDERED_RPC 16
94 #define NUM_HEURISTIC 1031
97 #define NHUSE_MAX 2048
99 static struct nfsheur {
100 struct vnode *nh_vp; /* vp to match (unreferenced pointer) */
101 off_t nh_nextoff; /* next offset for sequential detection */
102 int nh_use; /* use count for selection */
103 int nh_seqcount; /* heuristic */
104 } nfsheur[NUM_HEURISTIC];
108 * Heuristic to detect sequential operation.
110 static struct nfsheur *
111 nfsrv_sequential_heuristic(struct uio *uio, struct vnode *vp)
116 /* Locate best candidate. */
118 hi = ((int)(vm_offset_t)vp / sizeof(struct vnode)) % NUM_HEURISTIC;
121 if (nfsheur[hi].nh_vp == vp) {
125 if (nfsheur[hi].nh_use > 0)
126 --nfsheur[hi].nh_use;
127 hi = (hi + 1) % NUM_HEURISTIC;
128 if (nfsheur[hi].nh_use < nh->nh_use)
132 /* Initialize hint if this is a new file. */
133 if (nh->nh_vp != vp) {
135 nh->nh_nextoff = uio->uio_offset;
136 nh->nh_use = NHUSE_INIT;
137 if (uio->uio_offset == 0)
143 /* Calculate heuristic. */
144 if ((uio->uio_offset == 0 && nh->nh_seqcount > 0) ||
145 uio->uio_offset == nh->nh_nextoff) {
146 /* See comments in vfs_vnops.c:sequential_heuristic(). */
147 nh->nh_seqcount += howmany(uio->uio_resid, 16384);
148 if (nh->nh_seqcount > IO_SEQMAX)
149 nh->nh_seqcount = IO_SEQMAX;
150 } else if (qabs(uio->uio_offset - nh->nh_nextoff) <= MAX_REORDERED_RPC *
151 imax(vp->v_mount->mnt_stat.f_iosize, uio->uio_resid)) {
152 /* Probably a reordered RPC, leave seqcount alone. */
153 } else if (nh->nh_seqcount > 1) {
154 nh->nh_seqcount /= 2;
158 nh->nh_use += NHUSE_INC;
159 if (nh->nh_use > NHUSE_MAX)
160 nh->nh_use = NHUSE_MAX;
165 * Get attributes into nfsvattr structure.
168 nfsvno_getattr(struct vnode *vp, struct nfsvattr *nvap, struct ucred *cred,
169 struct thread *p, int vpislocked)
171 int error, lockedit = 0;
173 if (vpislocked == 0) {
175 * When vpislocked == 0, the vnode is either exclusively
176 * locked by this thread or not locked by this thread.
177 * As such, shared lock it, if not exclusively locked.
179 if (NFSVOPISLOCKED(vp) != LK_EXCLUSIVE) {
181 NFSVOPLOCK(vp, LK_SHARED | LK_RETRY);
184 error = VOP_GETATTR(vp, &nvap->na_vattr, cred);
193 * Get a file handle for a vnode.
196 nfsvno_getfh(struct vnode *vp, fhandle_t *fhp, struct thread *p)
200 NFSBZERO((caddr_t)fhp, sizeof(fhandle_t));
201 fhp->fh_fsid = vp->v_mount->mnt_stat.f_fsid;
202 error = VOP_VPTOFH(vp, &fhp->fh_fid);
209 * Perform access checking for vnodes obtained from file handles that would
210 * refer to files already opened by a Unix client. You cannot just use
211 * vn_writechk() and VOP_ACCESSX() for two reasons.
212 * 1 - You must check for exported rdonly as well as MNT_RDONLY for the write
214 * 2 - The owner is to be given access irrespective of mode bits for some
215 * operations, so that processes that chmod after opening a file don't
219 nfsvno_accchk(struct vnode *vp, accmode_t accmode, struct ucred *cred,
220 struct nfsexstuff *exp, struct thread *p, int override, int vpislocked,
221 u_int32_t *supportedtypep)
224 int error = 0, getret = 0;
226 if (vpislocked == 0) {
227 if (NFSVOPLOCK(vp, LK_SHARED) != 0) {
232 if (accmode & VWRITE) {
233 /* Just vn_writechk() changed to check rdonly */
235 * Disallow write attempts on read-only file systems;
236 * unless the file is a socket or a block or character
237 * device resident on the file system.
239 if (NFSVNO_EXRDONLY(exp) ||
240 (vp->v_mount->mnt_flag & MNT_RDONLY)) {
241 switch (vp->v_type) {
251 * If there's shared text associated with
252 * the inode, try to free it up once. If
253 * we fail, we can't allow writing.
255 if ((vp->v_vflag & VV_TEXT) != 0 && error == 0)
265 * Should the override still be applied when ACLs are enabled?
267 error = VOP_ACCESSX(vp, accmode, cred, p);
268 if (error != 0 && (accmode & (VDELETE | VDELETE_CHILD))) {
270 * Try again with VEXPLICIT_DENY, to see if the test for
271 * deletion is supported.
273 error = VOP_ACCESSX(vp, accmode | VEXPLICIT_DENY, cred, p);
275 if (vp->v_type == VDIR) {
276 accmode &= ~(VDELETE | VDELETE_CHILD);
278 error = VOP_ACCESSX(vp, accmode, cred, p);
279 } else if (supportedtypep != NULL) {
280 *supportedtypep &= ~NFSACCESS_DELETE;
286 * Allow certain operations for the owner (reads and writes
287 * on files that are already open).
289 if (override != NFSACCCHK_NOOVERRIDE &&
290 (error == EPERM || error == EACCES)) {
291 if (cred->cr_uid == 0 && (override & NFSACCCHK_ALLOWROOT))
293 else if (override & NFSACCCHK_ALLOWOWNER) {
294 getret = VOP_GETATTR(vp, &vattr, cred);
295 if (getret == 0 && cred->cr_uid == vattr.va_uid)
308 * Set attribute(s) vnop.
311 nfsvno_setattr(struct vnode *vp, struct nfsvattr *nvap, struct ucred *cred,
312 struct thread *p, struct nfsexstuff *exp)
316 error = VOP_SETATTR(vp, &nvap->na_vattr, cred);
322 * Set up nameidata for a lookup() call and do it
323 * For the cases where we are crossing mount points
324 * (looking up the public fh path or the v4 root path when
325 * not using a pseudo-root fs), set/release the Giant lock,
329 nfsvno_namei(struct nfsrv_descript *nd, struct nameidata *ndp,
330 struct vnode *dp, int islocked, struct nfsexstuff *exp, struct thread *p,
331 struct vnode **retdirp)
333 struct componentname *cnp = &ndp->ni_cnd;
337 int lockleaf = (cnp->cn_flags & LOCKLEAF) != 0, linklen;
338 int error = 0, crossmnt;
342 cnp->cn_nameptr = cnp->cn_pnbuf;
343 ndp->ni_strictrelative = 0;
345 * Extract and set starting directory.
347 if (dp->v_type != VDIR) {
352 nfsvno_relpathbuf(ndp);
360 if (NFSVNO_EXRDONLY(exp))
361 cnp->cn_flags |= RDONLY;
362 ndp->ni_segflg = UIO_SYSSPACE;
365 if (nd->nd_flag & ND_PUBLOOKUP) {
367 if (cnp->cn_pnbuf[0] == '/') {
370 * Check for degenerate pathnames here, since lookup()
373 for (i = 1; i < ndp->ni_pathlen; i++)
374 if (cnp->cn_pnbuf[i] != '/')
376 if (i == ndp->ni_pathlen) {
377 error = NFSERR_ACCES;
383 } else if ((nfsrv_enable_crossmntpt == 0 && NFSVNO_EXPORTED(exp)) ||
384 (nd->nd_flag & ND_NFSV4) == 0) {
386 * Only cross mount points for NFSv4 when doing a
387 * mount while traversing the file system above
388 * the mount point, unless nfsrv_enable_crossmntpt is set.
390 cnp->cn_flags |= NOCROSSMOUNT;
395 * Initialize for scan, set ni_startdir and bump ref on dp again
396 * becuase lookup() will dereference ni_startdir.
400 ndp->ni_startdir = dp;
401 ndp->ni_rootdir = rootvnode;
404 cnp->cn_flags |= LOCKLEAF;
406 cnp->cn_nameptr = cnp->cn_pnbuf;
408 * Call lookup() to do the real work. If an error occurs,
409 * ndp->ni_vp and ni_dvp are left uninitialized or NULL and
410 * we do not have to dereference anything before returning.
411 * In either case ni_startdir will be dereferenced and NULLed
419 * Check for encountering a symbolic link. Trivial
420 * termination occurs if no symlink encountered.
422 if ((cnp->cn_flags & ISSYMLINK) == 0) {
423 if ((cnp->cn_flags & (SAVENAME | SAVESTART)) == 0)
424 nfsvno_relpathbuf(ndp);
425 if (ndp->ni_vp && !lockleaf)
426 NFSVOPUNLOCK(ndp->ni_vp, 0);
433 if ((cnp->cn_flags & LOCKPARENT) && ndp->ni_pathlen == 1)
434 NFSVOPUNLOCK(ndp->ni_dvp, 0);
435 if (!(nd->nd_flag & ND_PUBLOOKUP)) {
440 if (ndp->ni_loopcnt++ >= MAXSYMLINKS) {
444 if (ndp->ni_pathlen > 1)
445 cp = uma_zalloc(namei_zone, M_WAITOK);
449 aiov.iov_len = MAXPATHLEN;
450 auio.uio_iov = &aiov;
453 auio.uio_rw = UIO_READ;
454 auio.uio_segflg = UIO_SYSSPACE;
456 auio.uio_resid = MAXPATHLEN;
457 error = VOP_READLINK(ndp->ni_vp, &auio, cnp->cn_cred);
460 if (ndp->ni_pathlen > 1)
461 uma_zfree(namei_zone, cp);
467 linklen = MAXPATHLEN - auio.uio_resid;
472 if (linklen + ndp->ni_pathlen >= MAXPATHLEN) {
473 error = ENAMETOOLONG;
478 * Adjust or replace path
480 if (ndp->ni_pathlen > 1) {
481 NFSBCOPY(ndp->ni_next, cp + linklen, ndp->ni_pathlen);
482 uma_zfree(namei_zone, cnp->cn_pnbuf);
485 cnp->cn_pnbuf[linklen] = '\0';
486 ndp->ni_pathlen += linklen;
489 * Cleanup refs for next loop and check if root directory
490 * should replace current directory. Normally ni_dvp
491 * becomes the new base directory and is cleaned up when
492 * we loop. Explicitly null pointers after invalidation
493 * to clarify operation.
498 if (cnp->cn_pnbuf[0] == '/') {
500 ndp->ni_dvp = ndp->ni_rootdir;
503 ndp->ni_startdir = ndp->ni_dvp;
507 cnp->cn_flags &= ~LOCKLEAF;
511 uma_zfree(namei_zone, cnp->cn_pnbuf);
514 ndp->ni_startdir = NULL;
515 cnp->cn_flags &= ~HASBUF;
516 } else if ((ndp->ni_cnd.cn_flags & (WANTPARENT|LOCKPARENT)) == 0) {
521 NFSEXITCODE2(error, nd);
526 * Set up a pathname buffer and return a pointer to it and, optionally
527 * set a hash pointer.
530 nfsvno_setpathbuf(struct nameidata *ndp, char **bufpp, u_long **hashpp)
532 struct componentname *cnp = &ndp->ni_cnd;
534 cnp->cn_flags |= (NOMACCHECK | HASBUF);
535 cnp->cn_pnbuf = uma_zalloc(namei_zone, M_WAITOK);
538 *bufpp = cnp->cn_pnbuf;
542 * Release the above path buffer, if not released by nfsvno_namei().
545 nfsvno_relpathbuf(struct nameidata *ndp)
548 if ((ndp->ni_cnd.cn_flags & HASBUF) == 0)
550 uma_zfree(namei_zone, ndp->ni_cnd.cn_pnbuf);
551 ndp->ni_cnd.cn_flags &= ~HASBUF;
555 * Readlink vnode op into an mbuf list.
558 nfsvno_readlink(struct vnode *vp, struct ucred *cred, struct thread *p,
559 struct mbuf **mpp, struct mbuf **mpendp, int *lenp)
561 struct iovec iv[(NFS_MAXPATHLEN+MLEN-1)/MLEN];
562 struct iovec *ivp = iv;
563 struct uio io, *uiop = &io;
564 struct mbuf *mp, *mp2 = NULL, *mp3 = NULL;
565 int i, len, tlen, error = 0;
569 while (len < NFS_MAXPATHLEN) {
572 mp->m_len = NFSMSIZ(mp);
579 if ((len + mp->m_len) > NFS_MAXPATHLEN) {
580 mp->m_len = NFS_MAXPATHLEN - len;
581 len = NFS_MAXPATHLEN;
585 ivp->iov_base = mtod(mp, caddr_t);
586 ivp->iov_len = mp->m_len;
591 uiop->uio_iovcnt = i;
592 uiop->uio_offset = 0;
593 uiop->uio_resid = len;
594 uiop->uio_rw = UIO_READ;
595 uiop->uio_segflg = UIO_SYSSPACE;
597 error = VOP_READLINK(vp, uiop, cred);
603 if (uiop->uio_resid > 0) {
604 len -= uiop->uio_resid;
605 tlen = NFSM_RNDUP(len);
606 nfsrv_adj(mp3, NFS_MAXPATHLEN - tlen, tlen - len);
618 * Read vnode op call into mbuf list.
621 nfsvno_read(struct vnode *vp, off_t off, int cnt, struct ucred *cred,
622 struct thread *p, struct mbuf **mpp, struct mbuf **mpendp)
628 int error = 0, len, left, siz, tlen, ioflag = 0;
629 struct mbuf *m2 = NULL, *m3;
630 struct uio io, *uiop = &io;
633 len = left = NFSM_RNDUP(cnt);
636 * Generate the mbuf list with the uio_iov ref. to it.
643 siz = min(M_TRAILINGSPACE(m), left);
652 MALLOC(iv, struct iovec *, i * sizeof (struct iovec),
654 uiop->uio_iov = iv2 = iv;
660 panic("nfsvno_read iov");
661 siz = min(M_TRAILINGSPACE(m), left);
663 iv->iov_base = mtod(m, caddr_t) + m->m_len;
672 uiop->uio_iovcnt = i;
673 uiop->uio_offset = off;
674 uiop->uio_resid = len;
675 uiop->uio_rw = UIO_READ;
676 uiop->uio_segflg = UIO_SYSSPACE;
677 nh = nfsrv_sequential_heuristic(uiop, vp);
678 ioflag |= nh->nh_seqcount << IO_SEQSHIFT;
679 error = VOP_READ(vp, uiop, IO_NODELOCKED | ioflag, cred);
680 FREE((caddr_t)iv2, M_TEMP);
686 nh->nh_nextoff = uiop->uio_offset;
687 tlen = len - uiop->uio_resid;
688 cnt = cnt < tlen ? cnt : tlen;
689 tlen = NFSM_RNDUP(cnt);
693 } else if (len != tlen || tlen != cnt)
694 nfsrv_adj(m3, len - tlen, tlen - cnt);
704 * Write vnode op from an mbuf list.
707 nfsvno_write(struct vnode *vp, off_t off, int retlen, int cnt, int stable,
708 struct mbuf *mp, char *cp, struct ucred *cred, struct thread *p)
714 struct uio io, *uiop = &io;
717 MALLOC(ivp, struct iovec *, cnt * sizeof (struct iovec), M_TEMP,
719 uiop->uio_iov = iv = ivp;
720 uiop->uio_iovcnt = cnt;
721 i = mtod(mp, caddr_t) + mp->m_len - cp;
725 panic("nfsvno_write");
736 cp = mtod(mp, caddr_t);
740 if (stable == NFSWRITE_UNSTABLE)
741 ioflags = IO_NODELOCKED;
743 ioflags = (IO_SYNC | IO_NODELOCKED);
744 uiop->uio_resid = retlen;
745 uiop->uio_rw = UIO_WRITE;
746 uiop->uio_segflg = UIO_SYSSPACE;
748 uiop->uio_offset = off;
749 nh = nfsrv_sequential_heuristic(uiop, vp);
750 ioflags |= nh->nh_seqcount << IO_SEQSHIFT;
751 error = VOP_WRITE(vp, uiop, ioflags, cred);
753 nh->nh_nextoff = uiop->uio_offset;
754 FREE((caddr_t)iv, M_TEMP);
761 * Common code for creating a regular file (plus special files for V2).
764 nfsvno_createsub(struct nfsrv_descript *nd, struct nameidata *ndp,
765 struct vnode **vpp, struct nfsvattr *nvap, int *exclusive_flagp,
766 int32_t *cverf, NFSDEV_T rdev, struct thread *p, struct nfsexstuff *exp)
771 error = nd->nd_repstat;
772 if (!error && ndp->ni_vp == NULL) {
773 if (nvap->na_type == VREG || nvap->na_type == VSOCK) {
774 vrele(ndp->ni_startdir);
775 error = VOP_CREATE(ndp->ni_dvp,
776 &ndp->ni_vp, &ndp->ni_cnd, &nvap->na_vattr);
778 nfsvno_relpathbuf(ndp);
780 if (*exclusive_flagp) {
781 *exclusive_flagp = 0;
782 NFSVNO_ATTRINIT(nvap);
783 nvap->na_atime.tv_sec = cverf[0];
784 nvap->na_atime.tv_nsec = cverf[1];
785 error = VOP_SETATTR(ndp->ni_vp,
786 &nvap->na_vattr, nd->nd_cred);
790 * NFS V2 Only. nfsrvd_mknod() does this for V3.
791 * (This implies, just get out on an error.)
793 } else if (nvap->na_type == VCHR || nvap->na_type == VBLK ||
794 nvap->na_type == VFIFO) {
795 if (nvap->na_type == VCHR && rdev == 0xffffffff)
796 nvap->na_type = VFIFO;
797 if (nvap->na_type != VFIFO &&
798 (error = priv_check_cred(nd->nd_cred,
799 PRIV_VFS_MKNOD_DEV, 0))) {
800 vrele(ndp->ni_startdir);
801 nfsvno_relpathbuf(ndp);
805 nvap->na_rdev = rdev;
806 error = VOP_MKNOD(ndp->ni_dvp, &ndp->ni_vp,
807 &ndp->ni_cnd, &nvap->na_vattr);
809 nfsvno_relpathbuf(ndp);
810 vrele(ndp->ni_startdir);
814 vrele(ndp->ni_startdir);
815 nfsvno_relpathbuf(ndp);
823 * Handle cases where error is already set and/or
825 * 1 - clean up the lookup
826 * 2 - iff !error and na_size set, truncate it
828 vrele(ndp->ni_startdir);
829 nfsvno_relpathbuf(ndp);
831 if (ndp->ni_dvp == *vpp)
835 if (!error && nvap->na_size != VNOVAL) {
836 error = nfsvno_accchk(*vpp, VWRITE,
837 nd->nd_cred, exp, p, NFSACCCHK_NOOVERRIDE,
838 NFSACCCHK_VPISLOCKED, NULL);
840 tempsize = nvap->na_size;
841 NFSVNO_ATTRINIT(nvap);
842 nvap->na_size = tempsize;
843 error = VOP_SETATTR(*vpp,
844 &nvap->na_vattr, nd->nd_cred);
857 * Do a mknod vnode op.
860 nfsvno_mknod(struct nameidata *ndp, struct nfsvattr *nvap, struct ucred *cred,
866 vtyp = nvap->na_type;
868 * Iff doesn't exist, create it.
871 vrele(ndp->ni_startdir);
872 nfsvno_relpathbuf(ndp);
878 if (vtyp != VCHR && vtyp != VBLK && vtyp != VSOCK && vtyp != VFIFO) {
879 vrele(ndp->ni_startdir);
880 nfsvno_relpathbuf(ndp);
882 error = NFSERR_BADTYPE;
886 vrele(ndp->ni_startdir);
887 error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp,
888 &ndp->ni_cnd, &nvap->na_vattr);
890 nfsvno_relpathbuf(ndp);
892 if (nvap->na_type != VFIFO &&
893 (error = priv_check_cred(cred, PRIV_VFS_MKNOD_DEV, 0))) {
894 vrele(ndp->ni_startdir);
895 nfsvno_relpathbuf(ndp);
899 error = VOP_MKNOD(ndp->ni_dvp, &ndp->ni_vp,
900 &ndp->ni_cnd, &nvap->na_vattr);
902 nfsvno_relpathbuf(ndp);
903 vrele(ndp->ni_startdir);
905 * Since VOP_MKNOD returns the ni_vp, I can't
906 * see any reason to do the lookup.
919 nfsvno_mkdir(struct nameidata *ndp, struct nfsvattr *nvap, uid_t saved_uid,
920 struct ucred *cred, struct thread *p, struct nfsexstuff *exp)
924 if (ndp->ni_vp != NULL) {
925 if (ndp->ni_dvp == ndp->ni_vp)
930 nfsvno_relpathbuf(ndp);
934 error = VOP_MKDIR(ndp->ni_dvp, &ndp->ni_vp, &ndp->ni_cnd,
937 nfsvno_relpathbuf(ndp);
948 nfsvno_symlink(struct nameidata *ndp, struct nfsvattr *nvap, char *pathcp,
949 int pathlen, int not_v2, uid_t saved_uid, struct ucred *cred, struct thread *p,
950 struct nfsexstuff *exp)
955 vrele(ndp->ni_startdir);
956 nfsvno_relpathbuf(ndp);
957 if (ndp->ni_dvp == ndp->ni_vp)
966 error = VOP_SYMLINK(ndp->ni_dvp, &ndp->ni_vp, &ndp->ni_cnd,
967 &nvap->na_vattr, pathcp);
969 vrele(ndp->ni_startdir);
970 nfsvno_relpathbuf(ndp);
972 * Although FreeBSD still had the lookup code in
973 * it for 7/current, there doesn't seem to be any
974 * point, since VOP_SYMLINK() returns the ni_vp.
975 * Just vput it for v2.
977 if (!not_v2 && !error)
986 * Parse symbolic link arguments.
987 * This function has an ugly side effect. It will MALLOC() an area for
988 * the symlink and set iov_base to point to it, only if it succeeds.
989 * So, if it returns with uiop->uio_iov->iov_base != NULL, that must
993 nfsvno_getsymlink(struct nfsrv_descript *nd, struct nfsvattr *nvap,
994 struct thread *p, char **pathcpp, int *lenp)
999 struct nfsv2_sattr *sp;
1003 if ((nd->nd_flag & ND_NFSV3) &&
1004 (error = nfsrv_sattr(nd, nvap, NULL, NULL, p)))
1006 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
1007 len = fxdr_unsigned(int, *tl);
1008 if (len > NFS_MAXPATHLEN || len <= 0) {
1012 MALLOC(pathcp, caddr_t, len + 1, M_TEMP, M_WAITOK);
1013 error = nfsrv_mtostr(nd, pathcp, len);
1016 if (nd->nd_flag & ND_NFSV2) {
1017 NFSM_DISSECT(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
1018 nvap->na_mode = fxdr_unsigned(u_int16_t, sp->sa_mode);
1022 NFSEXITCODE2(0, nd);
1026 free(pathcp, M_TEMP);
1027 NFSEXITCODE2(error, nd);
1032 * Remove a non-directory object.
1035 nfsvno_removesub(struct nameidata *ndp, int is_v4, struct ucred *cred,
1036 struct thread *p, struct nfsexstuff *exp)
1042 if (vp->v_type == VDIR)
1043 error = NFSERR_ISDIR;
1045 error = nfsrv_checkremove(vp, 1, p);
1047 error = VOP_REMOVE(ndp->ni_dvp, vp, &ndp->ni_cnd);
1048 if (ndp->ni_dvp == vp)
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)
1100 nfsvno_rename(struct nameidata *fromndp, struct nameidata *tondp,
1101 u_int32_t ndstat, u_int32_t ndflag, struct ucred *cred, struct thread *p)
1103 struct vnode *fvp, *tvp, *tdvp;
1106 fvp = fromndp->ni_vp;
1108 vrele(fromndp->ni_dvp);
1113 tdvp = tondp->ni_dvp;
1116 if (fvp->v_type == VDIR && tvp->v_type != VDIR) {
1117 error = (ndflag & ND_NFSV2) ? EISDIR : EEXIST;
1119 } else if (fvp->v_type != VDIR && tvp->v_type == VDIR) {
1120 error = (ndflag & ND_NFSV2) ? ENOTDIR : EEXIST;
1123 if (tvp->v_type == VDIR && tvp->v_mountedhere) {
1124 error = (ndflag & ND_NFSV2) ? ENOTEMPTY : EXDEV;
1129 * A rename to '.' or '..' results in a prematurely
1130 * unlocked vnode on FreeBSD5, so I'm just going to fail that
1133 if ((tondp->ni_cnd.cn_namelen == 1 &&
1134 tondp->ni_cnd.cn_nameptr[0] == '.') ||
1135 (tondp->ni_cnd.cn_namelen == 2 &&
1136 tondp->ni_cnd.cn_nameptr[0] == '.' &&
1137 tondp->ni_cnd.cn_nameptr[1] == '.')) {
1142 if (fvp->v_type == VDIR && fvp->v_mountedhere) {
1143 error = (ndflag & ND_NFSV2) ? ENOTEMPTY : EXDEV;
1146 if (fvp->v_mount != tdvp->v_mount) {
1147 error = (ndflag & ND_NFSV2) ? ENOTEMPTY : EXDEV;
1151 error = (ndflag & ND_NFSV2) ? ENOTEMPTY : EINVAL;
1156 * If source and destination are the same, there is nothing to
1157 * do. Set error to -1 to indicate this.
1162 if (ndflag & ND_NFSV4) {
1163 if (NFSVOPLOCK(fvp, LK_EXCLUSIVE) == 0) {
1164 error = nfsrv_checkremove(fvp, 0, p);
1165 NFSVOPUNLOCK(fvp, 0);
1169 error = nfsrv_checkremove(tvp, 1, p);
1172 * For NFSv2 and NFSv3, try to get rid of the delegation, so
1173 * that the NFSv4 client won't be confused by the rename.
1174 * Since nfsd_recalldelegation() can only be called on an
1175 * unlocked vnode at this point and fvp is the file that will
1176 * still exist after the rename, just do fvp.
1178 nfsd_recalldelegation(fvp, p);
1182 error = VOP_RENAME(fromndp->ni_dvp, fromndp->ni_vp,
1183 &fromndp->ni_cnd, tondp->ni_dvp, tondp->ni_vp,
1192 vrele(fromndp->ni_dvp);
1197 vrele(tondp->ni_startdir);
1198 nfsvno_relpathbuf(tondp);
1200 vrele(fromndp->ni_startdir);
1201 nfsvno_relpathbuf(fromndp);
1210 nfsvno_link(struct nameidata *ndp, struct vnode *vp, struct ucred *cred,
1211 struct thread *p, struct nfsexstuff *exp)
1221 if (vp->v_mount != xp->v_mount)
1225 NFSVOPLOCK(vp, LK_EXCLUSIVE | LK_RETRY);
1226 if ((vp->v_iflag & VI_DOOMED) == 0)
1227 error = VOP_LINK(ndp->ni_dvp, vp, &ndp->ni_cnd);
1230 if (ndp->ni_dvp == vp)
1234 NFSVOPUNLOCK(vp, 0);
1236 if (ndp->ni_dvp == ndp->ni_vp)
1243 nfsvno_relpathbuf(ndp);
1249 * Do the fsync() appropriate for the commit.
1252 nfsvno_fsync(struct vnode *vp, u_int64_t off, int cnt, struct ucred *cred,
1258 * RFC 1813 3.3.21: if count is 0, a flush from offset to the end of
1259 * file is done. At this time VOP_FSYNC does not accept offset and
1260 * byte count parameters so call VOP_FSYNC the whole file for now.
1261 * The same is true for NFSv4: RFC 3530 Sec. 14.2.3.
1263 if (cnt == 0 || cnt > MAX_COMMIT_COUNT) {
1265 * Give up and do the whole thing
1268 (vp->v_object->flags & OBJ_MIGHTBEDIRTY)) {
1269 VM_OBJECT_LOCK(vp->v_object);
1270 vm_object_page_clean(vp->v_object, 0, 0, OBJPC_SYNC);
1271 VM_OBJECT_UNLOCK(vp->v_object);
1273 error = VOP_FSYNC(vp, MNT_WAIT, td);
1276 * Locate and synchronously write any buffers that fall
1277 * into the requested range. Note: we are assuming that
1278 * f_iosize is a power of 2.
1280 int iosize = vp->v_mount->mnt_stat.f_iosize;
1281 int iomask = iosize - 1;
1286 * Align to iosize boundry, super-align to page boundry.
1289 cnt += off & iomask;
1290 off &= ~(u_quad_t)iomask;
1292 if (off & PAGE_MASK) {
1293 cnt += off & PAGE_MASK;
1294 off &= ~(u_quad_t)PAGE_MASK;
1296 lblkno = off / iosize;
1299 (vp->v_object->flags & OBJ_MIGHTBEDIRTY)) {
1300 VM_OBJECT_LOCK(vp->v_object);
1301 vm_object_page_clean(vp->v_object, off, off + cnt,
1303 VM_OBJECT_UNLOCK(vp->v_object);
1312 * If we have a buffer and it is marked B_DELWRI we
1313 * have to lock and write it. Otherwise the prior
1314 * write is assumed to have already been committed.
1316 * gbincore() can return invalid buffers now so we
1317 * have to check that bit as well (though B_DELWRI
1318 * should not be set if B_INVAL is set there could be
1319 * a race here since we haven't locked the buffer).
1321 if ((bp = gbincore(&vp->v_bufobj, lblkno)) != NULL) {
1322 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_SLEEPFAIL |
1323 LK_INTERLOCK, BO_MTX(bo)) == ENOLCK) {
1325 continue; /* retry */
1327 if ((bp->b_flags & (B_DELWRI|B_INVAL)) ==
1330 bp->b_flags &= ~B_ASYNC;
1353 nfsvno_statfs(struct vnode *vp, struct statfs *sf)
1357 error = VFS_STATFS(vp->v_mount, sf);
1360 * Since NFS handles these values as unsigned on the
1361 * wire, there is no way to represent negative values,
1362 * so set them to 0. Without this, they will appear
1363 * to be very large positive values for clients like
1366 if (sf->f_bavail < 0)
1368 if (sf->f_ffree < 0)
1376 * Do the vnode op stuff for Open. Similar to nfsvno_createsub(), but
1377 * must handle nfsrv_opencheck() calls after any other access checks.
1380 nfsvno_open(struct nfsrv_descript *nd, struct nameidata *ndp,
1381 nfsquad_t clientid, nfsv4stateid_t *stateidp, struct nfsstate *stp,
1382 int *exclusive_flagp, struct nfsvattr *nvap, int32_t *cverf, int create,
1383 NFSACL_T *aclp, nfsattrbit_t *attrbitp, struct ucred *cred, struct thread *p,
1384 struct nfsexstuff *exp, struct vnode **vpp)
1386 struct vnode *vp = NULL;
1388 struct nfsexstuff nes;
1390 if (ndp->ni_vp == NULL)
1391 nd->nd_repstat = nfsrv_opencheck(clientid,
1392 stateidp, stp, NULL, nd, p, nd->nd_repstat);
1393 if (!nd->nd_repstat) {
1394 if (ndp->ni_vp == NULL) {
1395 vrele(ndp->ni_startdir);
1396 nd->nd_repstat = VOP_CREATE(ndp->ni_dvp,
1397 &ndp->ni_vp, &ndp->ni_cnd, &nvap->na_vattr);
1399 nfsvno_relpathbuf(ndp);
1400 if (!nd->nd_repstat) {
1401 if (*exclusive_flagp) {
1402 *exclusive_flagp = 0;
1403 NFSVNO_ATTRINIT(nvap);
1404 nvap->na_atime.tv_sec = cverf[0];
1405 nvap->na_atime.tv_nsec = cverf[1];
1406 nd->nd_repstat = VOP_SETATTR(ndp->ni_vp,
1407 &nvap->na_vattr, cred);
1409 nfsrv_fixattr(nd, ndp->ni_vp, nvap,
1410 aclp, p, attrbitp, exp);
1415 if (ndp->ni_startdir)
1416 vrele(ndp->ni_startdir);
1417 nfsvno_relpathbuf(ndp);
1419 if (create == NFSV4OPEN_CREATE) {
1420 if (ndp->ni_dvp == vp)
1425 if (NFSVNO_ISSETSIZE(nvap) && vp->v_type == VREG) {
1426 if (ndp->ni_cnd.cn_flags & RDONLY)
1427 NFSVNO_SETEXRDONLY(&nes);
1429 NFSVNO_EXINIT(&nes);
1430 nd->nd_repstat = nfsvno_accchk(vp,
1431 VWRITE, cred, &nes, p,
1432 NFSACCCHK_NOOVERRIDE,
1433 NFSACCCHK_VPISLOCKED, NULL);
1434 nd->nd_repstat = nfsrv_opencheck(clientid,
1435 stateidp, stp, vp, nd, p, nd->nd_repstat);
1436 if (!nd->nd_repstat) {
1437 tempsize = nvap->na_size;
1438 NFSVNO_ATTRINIT(nvap);
1439 nvap->na_size = tempsize;
1440 nd->nd_repstat = VOP_SETATTR(vp,
1441 &nvap->na_vattr, cred);
1443 } else if (vp->v_type == VREG) {
1444 nd->nd_repstat = nfsrv_opencheck(clientid,
1445 stateidp, stp, vp, nd, p, nd->nd_repstat);
1449 if (ndp->ni_cnd.cn_flags & HASBUF)
1450 nfsvno_relpathbuf(ndp);
1451 if (ndp->ni_startdir && create == NFSV4OPEN_CREATE) {
1452 vrele(ndp->ni_startdir);
1453 if (ndp->ni_dvp == ndp->ni_vp)
1463 NFSEXITCODE2(0, nd);
1467 * Updates the file rev and sets the mtime and ctime
1468 * to the current clock time, returning the va_filerev and va_Xtime
1472 nfsvno_updfilerev(struct vnode *vp, struct nfsvattr *nvap,
1473 struct ucred *cred, struct thread *p)
1478 getnanotime(&va.va_mtime);
1479 (void) VOP_SETATTR(vp, &va, cred);
1480 (void) nfsvno_getattr(vp, nvap, cred, p, 1);
1484 * Glue routine to nfsv4_fillattr().
1487 nfsvno_fillattr(struct nfsrv_descript *nd, struct mount *mp, struct vnode *vp,
1488 struct nfsvattr *nvap, fhandle_t *fhp, int rderror, nfsattrbit_t *attrbitp,
1489 struct ucred *cred, struct thread *p, int isdgram, int reterr,
1490 int supports_nfsv4acls, int at_root, uint64_t mounted_on_fileno)
1494 error = nfsv4_fillattr(nd, mp, vp, NULL, &nvap->na_vattr, fhp, rderror,
1495 attrbitp, cred, p, isdgram, reterr, supports_nfsv4acls, at_root,
1497 NFSEXITCODE2(0, nd);
1501 /* Since the Readdir vnode ops vary, put the entire functions in here. */
1503 * nfs readdir service
1504 * - mallocs what it thinks is enough to read
1505 * count rounded up to a multiple of DIRBLKSIZ <= NFS_MAXREADDIR
1506 * - calls VOP_READDIR()
1507 * - loops around building the reply
1508 * if the output generated exceeds count break out of loop
1509 * The NFSM_CLGET macro is used here so that the reply will be packed
1510 * tightly in mbuf clusters.
1511 * - it trims out records with d_fileno == 0
1512 * this doesn't matter for Unix clients, but they might confuse clients
1514 * - it trims out records with d_type == DT_WHT
1515 * these cannot be seen through NFS (unless we extend the protocol)
1516 * The alternate call nfsrvd_readdirplus() does lookups as well.
1517 * PS: The NFS protocol spec. does not clarify what the "count" byte
1518 * argument is a count of.. just name strings and file id's or the
1519 * entire reply rpc or ...
1520 * I tried just file name and id sizes and it confused the Sun client,
1521 * so I am using the full rpc size now. The "paranoia.." comment refers
1522 * to including the status longwords that are not a part of the dir.
1523 * "entry" structures, but are in the rpc.
1526 nfsrvd_readdir(struct nfsrv_descript *nd, int isdgram,
1527 struct vnode *vp, struct thread *p, struct nfsexstuff *exp)
1532 char *cpos, *cend, *rbuf;
1534 int nlen, error = 0, getret = 1;
1535 int siz, cnt, fullsiz, eofflag, ncookies;
1536 u_int64_t off, toff, verf;
1537 u_long *cookies = NULL, *cookiep;
1542 if (nd->nd_repstat) {
1543 nfsrv_postopattr(nd, getret, &at);
1546 if (nd->nd_flag & ND_NFSV2) {
1547 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1548 off = fxdr_unsigned(u_quad_t, *tl++);
1550 NFSM_DISSECT(tl, u_int32_t *, 5 * NFSX_UNSIGNED);
1551 off = fxdr_hyper(tl);
1553 verf = fxdr_hyper(tl);
1557 cnt = fxdr_unsigned(int, *tl);
1558 if (cnt > NFS_SRVMAXDATA(nd) || cnt < 0)
1559 cnt = NFS_SRVMAXDATA(nd);
1560 siz = ((cnt + DIRBLKSIZ - 1) & ~(DIRBLKSIZ - 1));
1562 if (nd->nd_flag & ND_NFSV3) {
1563 nd->nd_repstat = getret = nfsvno_getattr(vp, &at, nd->nd_cred,
1567 * va_filerev is not sufficient as a cookie verifier,
1568 * since it is not supposed to change when entries are
1569 * removed/added unless that offset cookies returned to
1570 * the client are no longer valid.
1572 if (!nd->nd_repstat && toff && verf != at.na_filerev)
1573 nd->nd_repstat = NFSERR_BAD_COOKIE;
1576 if (nd->nd_repstat == 0 && cnt == 0) {
1577 if (nd->nd_flag & ND_NFSV2)
1578 /* NFSv2 does not have NFSERR_TOOSMALL */
1579 nd->nd_repstat = EPERM;
1581 nd->nd_repstat = NFSERR_TOOSMALL;
1583 if (!nd->nd_repstat)
1584 nd->nd_repstat = nfsvno_accchk(vp, VEXEC,
1585 nd->nd_cred, exp, p, NFSACCCHK_NOOVERRIDE,
1586 NFSACCCHK_VPISLOCKED, NULL);
1587 if (nd->nd_repstat) {
1589 if (nd->nd_flag & ND_NFSV3)
1590 nfsrv_postopattr(nd, getret, &at);
1593 not_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs");
1594 MALLOC(rbuf, caddr_t, siz, M_TEMP, M_WAITOK);
1598 free((caddr_t)cookies, M_TEMP);
1606 io.uio_offset = (off_t)off;
1608 io.uio_segflg = UIO_SYSSPACE;
1609 io.uio_rw = UIO_READ;
1611 nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag, &ncookies,
1613 off = (u_int64_t)io.uio_offset;
1615 siz -= io.uio_resid;
1617 if (!cookies && !nd->nd_repstat)
1618 nd->nd_repstat = NFSERR_PERM;
1619 if (nd->nd_flag & ND_NFSV3) {
1620 getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1);
1621 if (!nd->nd_repstat)
1622 nd->nd_repstat = getret;
1626 * Handles the failed cases. nd->nd_repstat == 0 past here.
1628 if (nd->nd_repstat) {
1630 free((caddr_t)rbuf, M_TEMP);
1632 free((caddr_t)cookies, M_TEMP);
1633 if (nd->nd_flag & ND_NFSV3)
1634 nfsrv_postopattr(nd, getret, &at);
1638 * If nothing read, return eof
1643 if (nd->nd_flag & ND_NFSV2) {
1644 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1646 nfsrv_postopattr(nd, getret, &at);
1647 NFSM_BUILD(tl, u_int32_t *, 4 * NFSX_UNSIGNED);
1648 txdr_hyper(at.na_filerev, tl);
1651 *tl++ = newnfs_false;
1653 FREE((caddr_t)rbuf, M_TEMP);
1654 FREE((caddr_t)cookies, M_TEMP);
1659 * Check for degenerate cases of nothing useful read.
1660 * If so go try again
1664 dp = (struct dirent *)cpos;
1668 * For some reason FreeBSD's ufs_readdir() chooses to back the
1669 * directory offset up to a block boundary, so it is necessary to
1670 * skip over the records that precede the requested offset. This
1671 * requires the assumption that file offset cookies monotonically
1673 * Since the offset cookies don't monotonically increase for ZFS,
1674 * this is not done when ZFS is the file system.
1676 while (cpos < cend && ncookies > 0 &&
1677 (dp->d_fileno == 0 || dp->d_type == DT_WHT ||
1678 (not_zfs != 0 && ((u_quad_t)(*cookiep)) <= toff))) {
1679 cpos += dp->d_reclen;
1680 dp = (struct dirent *)cpos;
1684 if (cpos >= cend || ncookies == 0) {
1692 * dirlen is the size of the reply, including all XDR and must
1693 * not exceed cnt. For NFSv2, RFC1094 didn't clearly indicate
1694 * if the XDR should be included in "count", but to be safe, we do.
1695 * (Include the two booleans at the end of the reply in dirlen now.)
1697 if (nd->nd_flag & ND_NFSV3) {
1698 nfsrv_postopattr(nd, getret, &at);
1699 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1700 txdr_hyper(at.na_filerev, tl);
1701 dirlen = NFSX_V3POSTOPATTR + NFSX_VERF + 2 * NFSX_UNSIGNED;
1703 dirlen = 2 * NFSX_UNSIGNED;
1706 /* Loop through the records and build reply */
1707 while (cpos < cend && ncookies > 0) {
1708 nlen = dp->d_namlen;
1709 if (dp->d_fileno != 0 && dp->d_type != DT_WHT &&
1710 nlen <= NFS_MAXNAMLEN) {
1711 if (nd->nd_flag & ND_NFSV3)
1712 dirlen += (6*NFSX_UNSIGNED + NFSM_RNDUP(nlen));
1714 dirlen += (4*NFSX_UNSIGNED + NFSM_RNDUP(nlen));
1721 * Build the directory record xdr from
1724 if (nd->nd_flag & ND_NFSV3) {
1725 NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
1726 *tl++ = newnfs_true;
1729 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1730 *tl++ = newnfs_true;
1732 *tl = txdr_unsigned(dp->d_fileno);
1733 (void) nfsm_strtom(nd, dp->d_name, nlen);
1734 if (nd->nd_flag & ND_NFSV3) {
1735 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1738 NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
1739 *tl = txdr_unsigned(*cookiep);
1741 cpos += dp->d_reclen;
1742 dp = (struct dirent *)cpos;
1748 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
1749 *tl++ = newnfs_false;
1754 FREE((caddr_t)rbuf, M_TEMP);
1755 FREE((caddr_t)cookies, M_TEMP);
1758 NFSEXITCODE2(0, nd);
1762 NFSEXITCODE2(error, nd);
1767 * Readdirplus for V3 and Readdir for V4.
1770 nfsrvd_readdirplus(struct nfsrv_descript *nd, int isdgram,
1771 struct vnode *vp, struct thread *p, struct nfsexstuff *exp)
1776 char *cpos, *cend, *rbuf;
1779 struct nfsvattr nva, at, *nvap = &nva;
1780 struct mbuf *mb0, *mb1;
1781 struct nfsreferral *refp;
1782 int nlen, r, error = 0, getret = 1, usevget = 1;
1783 int siz, cnt, fullsiz, eofflag, ncookies, entrycnt;
1784 caddr_t bpos0, bpos1;
1785 u_int64_t off, toff, verf;
1786 u_long *cookies = NULL, *cookiep;
1787 nfsattrbit_t attrbits, rderrbits, savbits;
1790 struct componentname cn;
1791 int at_root, needs_unbusy, not_zfs, supports_nfsv4acls;
1792 struct mount *mp, *new_mp;
1793 uint64_t mounted_on_fileno;
1795 if (nd->nd_repstat) {
1796 nfsrv_postopattr(nd, getret, &at);
1799 NFSM_DISSECT(tl, u_int32_t *, 6 * NFSX_UNSIGNED);
1800 off = fxdr_hyper(tl);
1803 verf = fxdr_hyper(tl);
1805 siz = fxdr_unsigned(int, *tl++);
1806 cnt = fxdr_unsigned(int, *tl);
1809 * Use the server's maximum data transfer size as the upper bound
1812 if (cnt > NFS_SRVMAXDATA(nd) || cnt < 0)
1813 cnt = NFS_SRVMAXDATA(nd);
1816 * siz is a "hint" of how much directory information (name, fileid,
1817 * cookie) should be in the reply. At least one client "hints" 0,
1818 * so I set it to cnt for that case. I also round it up to the
1819 * next multiple of DIRBLKSIZ.
1823 siz = ((siz + DIRBLKSIZ - 1) & ~(DIRBLKSIZ - 1));
1825 if (nd->nd_flag & ND_NFSV4) {
1826 error = nfsrv_getattrbits(nd, &attrbits, NULL, NULL);
1829 NFSSET_ATTRBIT(&savbits, &attrbits);
1830 NFSCLRNOTFILLABLE_ATTRBIT(&attrbits);
1831 NFSZERO_ATTRBIT(&rderrbits);
1832 NFSSETBIT_ATTRBIT(&rderrbits, NFSATTRBIT_RDATTRERROR);
1834 NFSZERO_ATTRBIT(&attrbits);
1837 nd->nd_repstat = getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1);
1838 if (!nd->nd_repstat) {
1839 if (off && verf != at.na_filerev) {
1841 * va_filerev is not sufficient as a cookie verifier,
1842 * since it is not supposed to change when entries are
1843 * removed/added unless that offset cookies returned to
1844 * the client are no longer valid.
1847 if (nd->nd_flag & ND_NFSV4) {
1848 nd->nd_repstat = NFSERR_NOTSAME;
1850 nd->nd_repstat = NFSERR_BAD_COOKIE;
1853 } else if ((nd->nd_flag & ND_NFSV4) && off == 0 && verf != 0) {
1854 nd->nd_repstat = NFSERR_BAD_COOKIE;
1857 if (!nd->nd_repstat && vp->v_type != VDIR)
1858 nd->nd_repstat = NFSERR_NOTDIR;
1859 if (!nd->nd_repstat && cnt == 0)
1860 nd->nd_repstat = NFSERR_TOOSMALL;
1861 if (!nd->nd_repstat)
1862 nd->nd_repstat = nfsvno_accchk(vp, VEXEC,
1863 nd->nd_cred, exp, p, NFSACCCHK_NOOVERRIDE,
1864 NFSACCCHK_VPISLOCKED, NULL);
1865 if (nd->nd_repstat) {
1867 if (nd->nd_flag & ND_NFSV3)
1868 nfsrv_postopattr(nd, getret, &at);
1871 not_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs");
1873 MALLOC(rbuf, caddr_t, siz, M_TEMP, M_WAITOK);
1877 free((caddr_t)cookies, M_TEMP);
1885 io.uio_offset = (off_t)off;
1887 io.uio_segflg = UIO_SYSSPACE;
1888 io.uio_rw = UIO_READ;
1890 nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag, &ncookies,
1892 off = (u_int64_t)io.uio_offset;
1894 siz -= io.uio_resid;
1896 getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1);
1898 if (!cookies && !nd->nd_repstat)
1899 nd->nd_repstat = NFSERR_PERM;
1900 if (!nd->nd_repstat)
1901 nd->nd_repstat = getret;
1902 if (nd->nd_repstat) {
1905 free((caddr_t)cookies, M_TEMP);
1906 free((caddr_t)rbuf, M_TEMP);
1907 if (nd->nd_flag & ND_NFSV3)
1908 nfsrv_postopattr(nd, getret, &at);
1912 * If nothing read, return eof
1917 if (nd->nd_flag & ND_NFSV3)
1918 nfsrv_postopattr(nd, getret, &at);
1919 NFSM_BUILD(tl, u_int32_t *, 4 * NFSX_UNSIGNED);
1920 txdr_hyper(at.na_filerev, tl);
1922 *tl++ = newnfs_false;
1924 free((caddr_t)cookies, M_TEMP);
1925 free((caddr_t)rbuf, M_TEMP);
1930 * Check for degenerate cases of nothing useful read.
1931 * If so go try again
1935 dp = (struct dirent *)cpos;
1939 * For some reason FreeBSD's ufs_readdir() chooses to back the
1940 * directory offset up to a block boundary, so it is necessary to
1941 * skip over the records that precede the requested offset. This
1942 * requires the assumption that file offset cookies monotonically
1944 * Since the offset cookies don't monotonically increase for ZFS,
1945 * this is not done when ZFS is the file system.
1947 while (cpos < cend && ncookies > 0 &&
1948 (dp->d_fileno == 0 || dp->d_type == DT_WHT ||
1949 (not_zfs != 0 && ((u_quad_t)(*cookiep)) <= toff) ||
1950 ((nd->nd_flag & ND_NFSV4) &&
1951 ((dp->d_namlen == 1 && dp->d_name[0] == '.') ||
1952 (dp->d_namlen==2 && dp->d_name[0]=='.' && dp->d_name[1]=='.'))))) {
1953 cpos += dp->d_reclen;
1954 dp = (struct dirent *)cpos;
1958 if (cpos >= cend || ncookies == 0) {
1965 * Busy the file system so that the mount point won't go away
1966 * and, as such, VFS_VGET() can be used safely.
1970 NFSVOPUNLOCK(vp, 0);
1971 nd->nd_repstat = vfs_busy(mp, 0);
1973 if (nd->nd_repstat != 0) {
1975 free(cookies, M_TEMP);
1977 if (nd->nd_flag & ND_NFSV3)
1978 nfsrv_postopattr(nd, getret, &at);
1983 * Save this position, in case there is an error before one entry
1987 bpos0 = nd->nd_bpos;
1990 * Fill in the first part of the reply.
1991 * dirlen is the reply length in bytes and cannot exceed cnt.
1992 * (Include the two booleans at the end of the reply in dirlen now,
1993 * so we recognize when we have exceeded cnt.)
1995 if (nd->nd_flag & ND_NFSV3) {
1996 dirlen = NFSX_V3POSTOPATTR + NFSX_VERF + 2 * NFSX_UNSIGNED;
1997 nfsrv_postopattr(nd, getret, &at);
1999 dirlen = NFSX_VERF + 2 * NFSX_UNSIGNED;
2001 NFSM_BUILD(tl, u_int32_t *, NFSX_VERF);
2002 txdr_hyper(at.na_filerev, tl);
2005 * Save this position, in case there is an empty reply needed.
2008 bpos1 = nd->nd_bpos;
2010 /* Loop through the records and build reply */
2012 while (cpos < cend && ncookies > 0 && dirlen < cnt) {
2013 nlen = dp->d_namlen;
2014 if (dp->d_fileno != 0 && dp->d_type != DT_WHT &&
2015 nlen <= NFS_MAXNAMLEN &&
2016 ((nd->nd_flag & ND_NFSV3) || nlen > 2 ||
2017 (nlen==2 && (dp->d_name[0]!='.' || dp->d_name[1]!='.'))
2018 || (nlen == 1 && dp->d_name[0] != '.'))) {
2020 * Save the current position in the reply, in case
2021 * this entry exceeds cnt.
2024 bpos1 = nd->nd_bpos;
2027 * For readdir_and_lookup get the vnode using
2036 mounted_on_fileno = (uint64_t)dp->d_fileno;
2037 if ((nd->nd_flag & ND_NFSV3) ||
2038 NFSNONZERO_ATTRBIT(&savbits)) {
2039 if (nd->nd_flag & ND_NFSV4)
2040 refp = nfsv4root_getreferral(NULL,
2044 r = VFS_VGET(mp, dp->d_fileno,
2048 if (r == EOPNOTSUPP) {
2051 cn.cn_nameiop = LOOKUP;
2059 cn.cn_nameptr = dp->d_name;
2060 cn.cn_namelen = nlen;
2061 cn.cn_flags = ISLASTCN |
2062 NOFOLLOW | LOCKLEAF |
2065 dp->d_name[0] == '.' &&
2066 dp->d_name[1] == '.')
2069 if (NFSVOPLOCK(vp, LK_SHARED)
2071 nd->nd_repstat = EPERM;
2074 if ((vp->v_vflag & VV_ROOT) != 0
2075 && (cn.cn_flags & ISDOTDOT)
2081 r = VOP_LOOKUP(vp, &nvp,
2090 * For NFSv4, check to see if nvp is
2091 * a mount point and get the mount
2092 * point vnode, as required.
2095 nfsrv_enable_crossmntpt != 0 &&
2096 (nd->nd_flag & ND_NFSV4) != 0 &&
2097 nvp->v_type == VDIR &&
2098 nvp->v_mountedhere != NULL) {
2099 new_mp = nvp->v_mountedhere;
2100 r = vfs_busy(new_mp, 0);
2104 r = VFS_ROOT(new_mp,
2114 ((nd->nd_flag & ND_NFSV3) ||
2115 NFSNONZERO_ATTRBIT(&attrbits))) {
2116 r = nfsvno_getfh(nvp, &nfh, p);
2118 r = nfsvno_getattr(nvp, nvap,
2125 if (!NFSISSET_ATTRBIT(&attrbits,
2126 NFSATTRBIT_RDATTRERROR)) {
2129 if (needs_unbusy != 0)
2138 * Build the directory record xdr
2140 if (nd->nd_flag & ND_NFSV3) {
2141 NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
2142 *tl++ = newnfs_true;
2144 *tl = txdr_unsigned(dp->d_fileno);
2145 dirlen += nfsm_strtom(nd, dp->d_name, nlen);
2146 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2148 *tl = txdr_unsigned(*cookiep);
2149 nfsrv_postopattr(nd, 0, nvap);
2150 dirlen += nfsm_fhtom(nd,(u_int8_t *)&nfh,0,1);
2151 dirlen += (5*NFSX_UNSIGNED+NFSX_V3POSTOPATTR);
2155 NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
2156 *tl++ = newnfs_true;
2158 *tl = txdr_unsigned(*cookiep);
2159 dirlen += nfsm_strtom(nd, dp->d_name, nlen);
2161 supports_nfsv4acls =
2162 nfs_supportsnfsv4acls(nvp);
2163 NFSVOPUNLOCK(nvp, 0);
2165 supports_nfsv4acls = 0;
2167 dirlen += nfsrv_putreferralattr(nd,
2170 if (nd->nd_repstat) {
2173 if (needs_unbusy != 0)
2178 dirlen += nfsvno_fillattr(nd, new_mp,
2179 nvp, nvap, &nfh, r, &rderrbits,
2180 nd->nd_cred, p, isdgram, 0,
2181 supports_nfsv4acls, at_root,
2184 dirlen += nfsvno_fillattr(nd, new_mp,
2185 nvp, nvap, &nfh, r, &attrbits,
2186 nd->nd_cred, p, isdgram, 0,
2187 supports_nfsv4acls, at_root,
2192 dirlen += (3 * NFSX_UNSIGNED);
2194 if (needs_unbusy != 0)
2199 cpos += dp->d_reclen;
2200 dp = (struct dirent *)cpos;
2208 * If dirlen > cnt, we must strip off the last entry. If that
2209 * results in an empty reply, report NFSERR_TOOSMALL.
2211 if (dirlen > cnt || nd->nd_repstat) {
2212 if (!nd->nd_repstat && entrycnt == 0)
2213 nd->nd_repstat = NFSERR_TOOSMALL;
2215 newnfs_trimtrailing(nd, mb0, bpos0);
2217 newnfs_trimtrailing(nd, mb1, bpos1);
2219 } else if (cpos < cend)
2221 if (!nd->nd_repstat) {
2222 NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2223 *tl++ = newnfs_false;
2229 FREE((caddr_t)cookies, M_TEMP);
2230 FREE((caddr_t)rbuf, M_TEMP);
2233 NFSEXITCODE2(0, nd);
2237 NFSEXITCODE2(error, nd);
2242 * Get the settable attributes out of the mbuf list.
2243 * (Return 0 or EBADRPC)
2246 nfsrv_sattr(struct nfsrv_descript *nd, struct nfsvattr *nvap,
2247 nfsattrbit_t *attrbitp, NFSACL_T *aclp, struct thread *p)
2250 struct nfsv2_sattr *sp;
2251 struct timeval curtime;
2252 int error = 0, toclient = 0;
2254 switch (nd->nd_flag & (ND_NFSV2 | ND_NFSV3 | ND_NFSV4)) {
2256 NFSM_DISSECT(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
2258 * Some old clients didn't fill in the high order 16bits.
2259 * --> check the low order 2 bytes for 0xffff
2261 if ((fxdr_unsigned(int, sp->sa_mode) & 0xffff) != 0xffff)
2262 nvap->na_mode = nfstov_mode(sp->sa_mode);
2263 if (sp->sa_uid != newnfs_xdrneg1)
2264 nvap->na_uid = fxdr_unsigned(uid_t, sp->sa_uid);
2265 if (sp->sa_gid != newnfs_xdrneg1)
2266 nvap->na_gid = fxdr_unsigned(gid_t, sp->sa_gid);
2267 if (sp->sa_size != newnfs_xdrneg1)
2268 nvap->na_size = fxdr_unsigned(u_quad_t, sp->sa_size);
2269 if (sp->sa_atime.nfsv2_sec != newnfs_xdrneg1) {
2271 fxdr_nfsv2time(&sp->sa_atime, &nvap->na_atime);
2273 nvap->na_atime.tv_sec =
2274 fxdr_unsigned(u_int32_t,sp->sa_atime.nfsv2_sec);
2275 nvap->na_atime.tv_nsec = 0;
2278 if (sp->sa_mtime.nfsv2_sec != newnfs_xdrneg1)
2279 fxdr_nfsv2time(&sp->sa_mtime, &nvap->na_mtime);
2282 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2283 if (*tl == newnfs_true) {
2284 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2285 nvap->na_mode = nfstov_mode(*tl);
2287 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2288 if (*tl == newnfs_true) {
2289 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2290 nvap->na_uid = fxdr_unsigned(uid_t, *tl);
2292 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2293 if (*tl == newnfs_true) {
2294 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2295 nvap->na_gid = fxdr_unsigned(gid_t, *tl);
2297 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2298 if (*tl == newnfs_true) {
2299 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2300 nvap->na_size = fxdr_hyper(tl);
2302 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2303 switch (fxdr_unsigned(int, *tl)) {
2304 case NFSV3SATTRTIME_TOCLIENT:
2305 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2306 fxdr_nfsv3time(tl, &nvap->na_atime);
2309 case NFSV3SATTRTIME_TOSERVER:
2310 NFSGETTIME(&curtime);
2311 nvap->na_atime.tv_sec = curtime.tv_sec;
2312 nvap->na_atime.tv_nsec = curtime.tv_usec * 1000;
2313 nvap->na_vaflags |= VA_UTIMES_NULL;
2316 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2317 switch (fxdr_unsigned(int, *tl)) {
2318 case NFSV3SATTRTIME_TOCLIENT:
2319 NFSM_DISSECT(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
2320 fxdr_nfsv3time(tl, &nvap->na_mtime);
2321 nvap->na_vaflags &= ~VA_UTIMES_NULL;
2323 case NFSV3SATTRTIME_TOSERVER:
2324 NFSGETTIME(&curtime);
2325 nvap->na_mtime.tv_sec = curtime.tv_sec;
2326 nvap->na_mtime.tv_nsec = curtime.tv_usec * 1000;
2328 nvap->na_vaflags |= VA_UTIMES_NULL;
2333 error = nfsv4_sattr(nd, nvap, attrbitp, aclp, p);
2336 NFSEXITCODE2(error, nd);
2341 * Handle the setable attributes for V4.
2342 * Returns NFSERR_BADXDR if it can't be parsed, 0 otherwise.
2345 nfsv4_sattr(struct nfsrv_descript *nd, struct nfsvattr *nvap,
2346 nfsattrbit_t *attrbitp, NFSACL_T *aclp, struct thread *p)
2351 int error, attrsize, bitpos, aclsize, aceerr, retnotsup = 0;
2353 u_char *cp, namestr[NFSV4_SMALLSTR + 1];
2356 struct timeval curtime;
2358 error = nfsrv_getattrbits(nd, attrbitp, NULL, &retnotsup);
2361 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2362 attrsize = fxdr_unsigned(int, *tl);
2365 * Loop around getting the setable attributes. If an unsupported
2366 * one is found, set nd_repstat == NFSERR_ATTRNOTSUPP and return.
2369 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2370 bitpos = NFSATTRBIT_MAX;
2374 for (; bitpos < NFSATTRBIT_MAX; bitpos++) {
2375 if (attrsum > attrsize) {
2376 error = NFSERR_BADXDR;
2379 if (NFSISSET_ATTRBIT(attrbitp, bitpos))
2381 case NFSATTRBIT_SIZE:
2382 NFSM_DISSECT(tl, u_int32_t *, NFSX_HYPER);
2383 nvap->na_size = fxdr_hyper(tl);
2384 attrsum += NFSX_HYPER;
2386 case NFSATTRBIT_ACL:
2387 error = nfsrv_dissectacl(nd, aclp, &aceerr, &aclsize,
2391 if (aceerr && !nd->nd_repstat)
2392 nd->nd_repstat = aceerr;
2395 case NFSATTRBIT_ARCHIVE:
2396 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2397 if (!nd->nd_repstat)
2398 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2399 attrsum += NFSX_UNSIGNED;
2401 case NFSATTRBIT_HIDDEN:
2402 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2403 if (!nd->nd_repstat)
2404 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2405 attrsum += NFSX_UNSIGNED;
2407 case NFSATTRBIT_MIMETYPE:
2408 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2409 i = fxdr_unsigned(int, *tl);
2410 error = nfsm_advance(nd, NFSM_RNDUP(i), -1);
2413 if (!nd->nd_repstat)
2414 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2415 attrsum += (NFSX_UNSIGNED + NFSM_RNDUP(i));
2417 case NFSATTRBIT_MODE:
2418 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2419 nvap->na_mode = nfstov_mode(*tl);
2420 attrsum += NFSX_UNSIGNED;
2422 case NFSATTRBIT_OWNER:
2423 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2424 j = fxdr_unsigned(int, *tl);
2426 error = NFSERR_BADXDR;
2429 if (j > NFSV4_SMALLSTR)
2430 cp = malloc(j + 1, M_NFSSTRING, M_WAITOK);
2433 error = nfsrv_mtostr(nd, cp, j);
2435 if (j > NFSV4_SMALLSTR)
2436 free(cp, M_NFSSTRING);
2439 if (!nd->nd_repstat) {
2440 nd->nd_repstat = nfsv4_strtouid(cp,j,&uid,p);
2441 if (!nd->nd_repstat)
2444 if (j > NFSV4_SMALLSTR)
2445 free(cp, M_NFSSTRING);
2446 attrsum += (NFSX_UNSIGNED + NFSM_RNDUP(j));
2448 case NFSATTRBIT_OWNERGROUP:
2449 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2450 j = fxdr_unsigned(int, *tl);
2452 error = NFSERR_BADXDR;
2455 if (j > NFSV4_SMALLSTR)
2456 cp = malloc(j + 1, M_NFSSTRING, M_WAITOK);
2459 error = nfsrv_mtostr(nd, cp, j);
2461 if (j > NFSV4_SMALLSTR)
2462 free(cp, M_NFSSTRING);
2465 if (!nd->nd_repstat) {
2466 nd->nd_repstat = nfsv4_strtogid(cp,j,&gid,p);
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 NFSGETTIME(&curtime);
2490 nvap->na_atime.tv_sec = curtime.tv_sec;
2491 nvap->na_atime.tv_nsec = curtime.tv_usec * 1000;
2492 nvap->na_vaflags |= VA_UTIMES_NULL;
2495 case NFSATTRBIT_TIMEBACKUP:
2496 NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME);
2497 if (!nd->nd_repstat)
2498 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2499 attrsum += NFSX_V4TIME;
2501 case NFSATTRBIT_TIMECREATE:
2502 NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME);
2503 if (!nd->nd_repstat)
2504 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2505 attrsum += NFSX_V4TIME;
2507 case NFSATTRBIT_TIMEMODIFYSET:
2508 NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
2509 attrsum += NFSX_UNSIGNED;
2510 if (fxdr_unsigned(int, *tl)==NFSV4SATTRTIME_TOCLIENT) {
2511 NFSM_DISSECT(tl, u_int32_t *, NFSX_V4TIME);
2512 fxdr_nfsv4time(tl, &nvap->na_mtime);
2513 nvap->na_vaflags &= ~VA_UTIMES_NULL;
2514 attrsum += NFSX_V4TIME;
2516 NFSGETTIME(&curtime);
2517 nvap->na_mtime.tv_sec = curtime.tv_sec;
2518 nvap->na_mtime.tv_nsec = curtime.tv_usec * 1000;
2520 nvap->na_vaflags |= VA_UTIMES_NULL;
2524 nd->nd_repstat = NFSERR_ATTRNOTSUPP;
2526 * set bitpos so we drop out of the loop.
2528 bitpos = NFSATTRBIT_MAX;
2534 * some clients pad the attrlist, so we need to skip over the
2537 if (attrsum > attrsize) {
2538 error = NFSERR_BADXDR;
2540 attrsize = NFSM_RNDUP(attrsize);
2541 if (attrsum < attrsize)
2542 error = nfsm_advance(nd, attrsize - attrsum, -1);
2545 NFSEXITCODE2(error, nd);
2550 * Check/setup export credentials.
2553 nfsd_excred(struct nfsrv_descript *nd, struct nfsexstuff *exp,
2554 struct ucred *credanon)
2559 * Check/setup credentials.
2561 if (nd->nd_flag & ND_GSS)
2562 exp->nes_exflag &= ~MNT_EXPORTANON;
2565 * Check to see if the operation is allowed for this security flavor.
2566 * RFC2623 suggests that the NFSv3 Fsinfo RPC be allowed to
2567 * AUTH_NONE or AUTH_SYS for file systems requiring RPCSEC_GSS.
2568 * Also, allow Secinfo, so that it can acquire the correct flavor(s).
2570 if (nfsvno_testexp(nd, exp) &&
2571 nd->nd_procnum != NFSV4OP_SECINFO &&
2572 nd->nd_procnum != NFSPROC_FSINFO) {
2573 if (nd->nd_flag & ND_NFSV4)
2574 error = NFSERR_WRONGSEC;
2576 error = (NFSERR_AUTHERR | AUTH_TOOWEAK);
2581 * Check to see if the file system is exported V4 only.
2583 if (NFSVNO_EXV4ONLY(exp) && !(nd->nd_flag & ND_NFSV4)) {
2584 error = NFSERR_PROGNOTV4;
2589 * Now, map the user credentials.
2590 * (Note that ND_AUTHNONE will only be set for an NFSv3
2591 * Fsinfo RPC. If set for anything else, this code might need
2594 if (NFSVNO_EXPORTED(exp) &&
2595 ((!(nd->nd_flag & ND_GSS) && nd->nd_cred->cr_uid == 0) ||
2596 NFSVNO_EXPORTANON(exp) ||
2597 (nd->nd_flag & ND_AUTHNONE))) {
2598 nd->nd_cred->cr_uid = credanon->cr_uid;
2599 nd->nd_cred->cr_gid = credanon->cr_gid;
2600 crsetgroups(nd->nd_cred, credanon->cr_ngroups,
2601 credanon->cr_groups);
2605 NFSEXITCODE2(error, nd);
2613 nfsvno_checkexp(struct mount *mp, struct sockaddr *nam, struct nfsexstuff *exp,
2614 struct ucred **credp)
2616 int i, error, *secflavors;
2618 error = VFS_CHECKEXP(mp, nam, &exp->nes_exflag, credp,
2619 &exp->nes_numsecflavor, &secflavors);
2621 if (nfs_rootfhset) {
2622 exp->nes_exflag = 0;
2623 exp->nes_numsecflavor = 0;
2627 /* Copy the security flavors. */
2628 for (i = 0; i < exp->nes_numsecflavor; i++)
2629 exp->nes_secflavors[i] = secflavors[i];
2636 * Get a vnode for a file handle and export stuff.
2639 nfsvno_fhtovp(struct mount *mp, fhandle_t *fhp, struct sockaddr *nam,
2640 int lktype, struct vnode **vpp, struct nfsexstuff *exp,
2641 struct ucred **credp)
2643 int i, error, *secflavors;
2646 exp->nes_numsecflavor = 0;
2647 if (VFS_NEEDSGIANT(mp))
2650 error = VFS_FHTOVP(mp, &fhp->fh_fid, lktype, vpp);
2652 /* Make sure the server replies ESTALE to the client. */
2654 if (nam && !error) {
2655 error = VFS_CHECKEXP(mp, nam, &exp->nes_exflag, credp,
2656 &exp->nes_numsecflavor, &secflavors);
2658 if (nfs_rootfhset) {
2659 exp->nes_exflag = 0;
2660 exp->nes_numsecflavor = 0;
2666 /* Copy the security flavors. */
2667 for (i = 0; i < exp->nes_numsecflavor; i++)
2668 exp->nes_secflavors[i] = secflavors[i];
2676 * nfsd_fhtovp() - convert a fh to a vnode ptr
2677 * - look up fsid in mount list (if not found ret error)
2678 * - get vp and export rights by calling nfsvno_fhtovp()
2679 * - if cred->cr_uid == 0 or MNT_EXPORTANON set it to credanon
2681 * - if mpp != NULL, return the mount point so that it can
2682 * be used for vn_finished_write() by the caller
2685 nfsd_fhtovp(struct nfsrv_descript *nd, struct nfsrvfh *nfp, int lktype,
2686 struct vnode **vpp, struct nfsexstuff *exp,
2687 struct mount **mpp, int startwrite, struct thread *p)
2690 struct ucred *credanon;
2693 fhp = (fhandle_t *)nfp->nfsrvfh_data;
2695 * Check for the special case of the nfsv4root_fh.
2697 mp = vfs_busyfs(&fhp->fh_fsid);
2702 nd->nd_repstat = ESTALE;
2707 vn_start_write(NULL, mpp, V_WAIT);
2709 nd->nd_repstat = nfsvno_fhtovp(mp, fhp, nd->nd_nam, lktype, vpp, exp,
2714 * For NFSv4 without a pseudo root fs, unexported file handles
2715 * can be returned, so that Lookup works everywhere.
2717 if (!nd->nd_repstat && exp->nes_exflag == 0 &&
2718 !(nd->nd_flag & ND_NFSV4)) {
2720 nd->nd_repstat = EACCES;
2724 * Personally, I've never seen any point in requiring a
2725 * reserved port#, since only in the rare case where the
2726 * clients are all boxes with secure system priviledges,
2727 * does it provide any enhanced security, but... some people
2728 * believe it to be useful and keep putting this code back in.
2729 * (There is also some "security checker" out there that
2730 * complains if the nfs server doesn't enforce this.)
2731 * However, note the following:
2732 * RFC3530 (NFSv4) specifies that a reserved port# not be
2734 * RFC2623 recommends that, if a reserved port# is checked for,
2735 * that there be a way to turn that off--> ifdef'd.
2737 #ifdef NFS_REQRSVPORT
2738 if (!nd->nd_repstat) {
2739 struct sockaddr_in *saddr;
2740 struct sockaddr_in6 *saddr6;
2742 saddr = NFSSOCKADDR(nd->nd_nam, struct sockaddr_in *);
2743 saddr6 = NFSSOCKADDR(nd->nd_nam, struct sockaddr_in6 *);
2744 if (!(nd->nd_flag & ND_NFSV4) &&
2745 ((saddr->sin_family == AF_INET &&
2746 ntohs(saddr->sin_port) >= IPPORT_RESERVED) ||
2747 (saddr6->sin6_family == AF_INET6 &&
2748 ntohs(saddr6->sin6_port) >= IPPORT_RESERVED))) {
2750 nd->nd_repstat = (NFSERR_AUTHERR | AUTH_TOOWEAK);
2753 #endif /* NFS_REQRSVPORT */
2756 * Check/setup credentials.
2758 if (!nd->nd_repstat) {
2759 nd->nd_saveduid = nd->nd_cred->cr_uid;
2760 nd->nd_repstat = nfsd_excred(nd, exp, credanon);
2764 if (credanon != NULL)
2766 if (nd->nd_repstat) {
2768 vn_finished_write(mp);
2775 NFSEXITCODE2(0, nd);
2782 fp_getfvp(struct thread *p, int fd, struct file **fpp, struct vnode **vpp)
2784 struct filedesc *fdp;
2788 fdp = p->td_proc->p_fd;
2789 if (fd >= fdp->fd_nfiles ||
2790 (fp = fdp->fd_ofiles[fd]) == NULL) {
2802 * Called from nfssvc() to update the exports list. Just call
2803 * vfs_export(). This has to be done, since the v4 root fake fs isn't
2804 * in the mount list.
2807 nfsrv_v4rootexport(void *argp, struct ucred *cred, struct thread *p)
2809 struct nfsex_args *nfsexargp = (struct nfsex_args *)argp;
2811 struct nameidata nd;
2814 error = vfs_export(&nfsv4root_mnt, &nfsexargp->export);
2815 if ((nfsexargp->export.ex_flags & MNT_DELEXPORT) != 0)
2817 else if (error == 0) {
2818 if (nfsexargp->fspec == NULL) {
2823 * If fspec != NULL, this is the v4root path.
2825 NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_USERSPACE,
2826 nfsexargp->fspec, p);
2827 if ((error = namei(&nd)) != 0)
2829 error = nfsvno_getfh(nd.ni_vp, &fh, p);
2832 nfs_rootfh.nfsrvfh_len = NFSX_MYFH;
2833 NFSBCOPY((caddr_t)&fh,
2834 nfs_rootfh.nfsrvfh_data,
2835 sizeof (fhandle_t));
2846 * Get the tcp socket sequence numbers we need.
2847 * (Maybe this should be moved to the tcp sources?)
2850 nfsrv_getsocksndseq(struct socket *so, tcp_seq *maxp, tcp_seq *unap)
2856 inp = sotoinpcb(so);
2857 KASSERT(inp != NULL, ("nfsrv_getsocksndseq: inp == NULL"));
2859 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
2864 tp = intotcpcb(inp);
2865 if (tp->t_state != TCPS_ESTABLISHED) {
2870 *maxp = tp->snd_max;
2871 *unap = tp->snd_una;
2880 * This function needs to test to see if the system is near its limit
2881 * for memory allocation via malloc() or mget() and return True iff
2882 * either of these resources are near their limit.
2883 * XXX (For now, this is just a stub.)
2885 int nfsrv_testmalloclimit = 0;
2887 nfsrv_mallocmget_limit(void)
2889 static int printmesg = 0;
2890 static int testval = 1;
2892 if (nfsrv_testmalloclimit && (testval++ % 1000) == 0) {
2893 if ((printmesg++ % 100) == 0)
2894 printf("nfsd: malloc/mget near limit\n");
2901 * BSD specific initialization of a mount point.
2906 static int inited = 0;
2911 nfsv4root_mnt.mnt_flag = (MNT_RDONLY | MNT_EXPORTED);
2912 TAILQ_INIT(&nfsv4root_mnt.mnt_nvnodelist);
2913 nfsv4root_mnt.mnt_export = NULL;
2914 TAILQ_INIT(&nfsv4root_opt);
2915 TAILQ_INIT(&nfsv4root_newopt);
2916 nfsv4root_mnt.mnt_opt = &nfsv4root_opt;
2917 nfsv4root_mnt.mnt_optnew = &nfsv4root_newopt;
2918 nfsv4root_mnt.mnt_nvnodelistsize = 0;
2922 * Get a vnode for a file handle, without checking exports, etc.
2925 nfsvno_getvp(fhandle_t *fhp)
2931 mp = vfs_busyfs(&fhp->fh_fsid);
2934 error = VFS_FHTOVP(mp, &fhp->fh_fid, LK_EXCLUSIVE, &vp);
2942 * Do a local VOP_ADVLOCK().
2945 nfsvno_advlock(struct vnode *vp, int ftype, u_int64_t first,
2946 u_int64_t end, struct thread *td)
2952 if (nfsrv_dolocallocks == 0)
2955 /* Check for VI_DOOMED here, so that VOP_ADVLOCK() isn't performed. */
2956 if ((vp->v_iflag & VI_DOOMED) != 0) {
2961 fl.l_whence = SEEK_SET;
2963 fl.l_start = (off_t)first;
2964 if (end == NFS64BITSSET) {
2968 fl.l_len = (off_t)tlen;
2971 * For FreeBSD8, the l_pid and l_sysid must be set to the same
2972 * values for all calls, so that all locks will be held by the
2973 * nfsd server. (The nfsd server handles conflicts between the
2975 * Since an NFSv4 lockowner is a ClientID plus an array of up to 1024
2976 * bytes, so it can't be put in l_sysid.
2978 if (nfsv4_sysid == 0)
2979 nfsv4_sysid = nlm_acquire_next_sysid();
2980 fl.l_pid = (pid_t)0;
2981 fl.l_sysid = (int)nfsv4_sysid;
2983 NFSVOPUNLOCK(vp, 0);
2984 if (ftype == F_UNLCK)
2985 error = VOP_ADVLOCK(vp, (caddr_t)td->td_proc, F_UNLCK, &fl,
2986 (F_POSIX | F_REMOTE));
2988 error = VOP_ADVLOCK(vp, (caddr_t)td->td_proc, F_SETLK, &fl,
2989 (F_POSIX | F_REMOTE));
2990 NFSVOPLOCK(vp, LK_EXCLUSIVE | LK_RETRY);
2998 * Check the nfsv4 root exports.
3001 nfsvno_v4rootexport(struct nfsrv_descript *nd)
3003 struct ucred *credanon;
3004 int exflags, error = 0, numsecflavor, *secflavors, i;
3006 error = vfs_stdcheckexp(&nfsv4root_mnt, nd->nd_nam, &exflags,
3007 &credanon, &numsecflavor, &secflavors);
3009 error = NFSERR_PROGUNAVAIL;
3012 if (credanon != NULL)
3014 for (i = 0; i < numsecflavor; i++) {
3015 if (secflavors[i] == AUTH_SYS)
3016 nd->nd_flag |= ND_EXAUTHSYS;
3017 else if (secflavors[i] == RPCSEC_GSS_KRB5)
3018 nd->nd_flag |= ND_EXGSS;
3019 else if (secflavors[i] == RPCSEC_GSS_KRB5I)
3020 nd->nd_flag |= ND_EXGSSINTEGRITY;
3021 else if (secflavors[i] == RPCSEC_GSS_KRB5P)
3022 nd->nd_flag |= ND_EXGSSPRIVACY;
3031 * Nfs server psuedo system call for the nfsd's
3037 nfssvc_nfsd(struct thread *td, struct nfssvc_args *uap)
3040 struct nfsd_addsock_args sockarg;
3041 struct nfsd_nfsd_args nfsdarg;
3044 if (uap->flag & NFSSVC_NFSDADDSOCK) {
3045 error = copyin(uap->argp, (caddr_t)&sockarg, sizeof (sockarg));
3049 * Since we don't know what rights might be required,
3050 * pretend that we need them all. It is better to be too
3051 * careful than too reckless.
3053 if ((error = fget(td, sockarg.sock, CAP_SOCK_ALL, &fp)) != 0)
3055 if (fp->f_type != DTYPE_SOCKET) {
3060 error = nfsrvd_addsock(fp);
3062 } else if (uap->flag & NFSSVC_NFSDNFSD) {
3063 if (uap->argp == NULL) {
3067 error = copyin(uap->argp, (caddr_t)&nfsdarg,
3071 error = nfsrvd_nfsd(td, &nfsdarg);
3073 error = nfssvc_srvcall(td, uap, td->td_ucred);
3082 nfssvc_srvcall(struct thread *p, struct nfssvc_args *uap, struct ucred *cred)
3084 struct nfsex_args export;
3085 struct file *fp = NULL;
3087 struct nfsd_clid adminrevoke;
3088 struct nfsd_dumplist dumplist;
3089 struct nfsd_dumpclients *dumpclients;
3090 struct nfsd_dumplocklist dumplocklist;
3091 struct nfsd_dumplocks *dumplocks;
3092 struct nameidata nd;
3097 if (uap->flag & NFSSVC_PUBLICFH) {
3098 NFSBZERO((caddr_t)&nfs_pubfh.nfsrvfh_data,
3099 sizeof (fhandle_t));
3100 error = copyin(uap->argp,
3101 &nfs_pubfh.nfsrvfh_data, sizeof (fhandle_t));
3104 } else if (uap->flag & NFSSVC_V4ROOTEXPORT) {
3105 error = copyin(uap->argp,(caddr_t)&export,
3106 sizeof (struct nfsex_args));
3108 error = nfsrv_v4rootexport(&export, cred, p);
3109 } else if (uap->flag & NFSSVC_NOPUBLICFH) {
3112 } else if (uap->flag & NFSSVC_STABLERESTART) {
3113 error = copyin(uap->argp, (caddr_t)&stablefd,
3116 error = fp_getfvp(p, stablefd, &fp, &vp);
3117 if (!error && (NFSFPFLAG(fp) & (FREAD | FWRITE)) != (FREAD | FWRITE))
3119 if (!error && newnfs_numnfsd != 0)
3122 nfsrv_stablefirst.nsf_fp = fp;
3123 nfsrv_setupstable(p);
3125 } else if (uap->flag & NFSSVC_ADMINREVOKE) {
3126 error = copyin(uap->argp, (caddr_t)&adminrevoke,
3127 sizeof (struct nfsd_clid));
3129 error = nfsrv_adminrevoke(&adminrevoke, p);
3130 } else if (uap->flag & NFSSVC_DUMPCLIENTS) {
3131 error = copyin(uap->argp, (caddr_t)&dumplist,
3132 sizeof (struct nfsd_dumplist));
3133 if (!error && (dumplist.ndl_size < 1 ||
3134 dumplist.ndl_size > NFSRV_MAXDUMPLIST))
3137 len = sizeof (struct nfsd_dumpclients) * dumplist.ndl_size;
3138 dumpclients = (struct nfsd_dumpclients *)malloc(len,
3140 nfsrv_dumpclients(dumpclients, dumplist.ndl_size);
3141 error = copyout(dumpclients,
3142 CAST_USER_ADDR_T(dumplist.ndl_list), len);
3143 free((caddr_t)dumpclients, M_TEMP);
3145 } else if (uap->flag & NFSSVC_DUMPLOCKS) {
3146 error = copyin(uap->argp, (caddr_t)&dumplocklist,
3147 sizeof (struct nfsd_dumplocklist));
3148 if (!error && (dumplocklist.ndllck_size < 1 ||
3149 dumplocklist.ndllck_size > NFSRV_MAXDUMPLIST))
3152 error = nfsrv_lookupfilename(&nd,
3153 dumplocklist.ndllck_fname, p);
3155 len = sizeof (struct nfsd_dumplocks) *
3156 dumplocklist.ndllck_size;
3157 dumplocks = (struct nfsd_dumplocks *)malloc(len,
3159 nfsrv_dumplocks(nd.ni_vp, dumplocks,
3160 dumplocklist.ndllck_size, p);
3162 error = copyout(dumplocks,
3163 CAST_USER_ADDR_T(dumplocklist.ndllck_list), len);
3164 free((caddr_t)dumplocks, M_TEMP);
3166 } else if (uap->flag & NFSSVC_BACKUPSTABLE) {
3169 nfsd_master_pid = procp->p_pid;
3170 bcopy(procp->p_comm, nfsd_master_comm, MAXCOMLEN + 1);
3171 nfsd_master_start = procp->p_stats->p_start;
3172 nfsd_master_proc = procp;
3182 * Returns 0 if ok, 1 otherwise.
3185 nfsvno_testexp(struct nfsrv_descript *nd, struct nfsexstuff *exp)
3190 * This seems odd, but allow the case where the security flavor
3191 * list is empty. This happens when NFSv4 is traversing non-exported
3192 * file systems. Exported file systems should always have a non-empty
3193 * security flavor list.
3195 if (exp->nes_numsecflavor == 0)
3198 for (i = 0; i < exp->nes_numsecflavor; i++) {
3200 * The tests for privacy and integrity must be first,
3201 * since ND_GSS is set for everything but AUTH_SYS.
3203 if (exp->nes_secflavors[i] == RPCSEC_GSS_KRB5P &&
3204 (nd->nd_flag & ND_GSSPRIVACY))
3206 if (exp->nes_secflavors[i] == RPCSEC_GSS_KRB5I &&
3207 (nd->nd_flag & ND_GSSINTEGRITY))
3209 if (exp->nes_secflavors[i] == RPCSEC_GSS_KRB5 &&
3210 (nd->nd_flag & ND_GSS))
3212 if (exp->nes_secflavors[i] == AUTH_SYS &&
3213 (nd->nd_flag & ND_GSS) == 0)
3220 * Calculate a hash value for the fid in a file handle.
3223 nfsrv_hashfh(fhandle_t *fhp)
3227 hashval = hash32_buf(&fhp->fh_fid, sizeof(struct fid), 0);
3232 * Signal the userland master nfsd to backup the stable restart file.
3235 nfsrv_backupstable(void)
3239 if (nfsd_master_proc != NULL) {
3240 procp = pfind(nfsd_master_pid);
3241 /* Try to make sure it is the correct process. */
3242 if (procp == nfsd_master_proc &&
3243 procp->p_stats->p_start.tv_sec ==
3244 nfsd_master_start.tv_sec &&
3245 procp->p_stats->p_start.tv_usec ==
3246 nfsd_master_start.tv_usec &&
3247 strcmp(procp->p_comm, nfsd_master_comm) == 0)
3248 kern_psignal(procp, SIGUSR2);
3250 nfsd_master_proc = NULL;
3257 extern int (*nfsd_call_nfsd)(struct thread *, struct nfssvc_args *);
3260 * Called once to initialize data structures...
3263 nfsd_modevent(module_t mod, int type, void *data)
3266 static int loaded = 0;
3273 mtx_init(&nfs_cache_mutex, "nfs_cache_mutex", NULL, MTX_DEF);
3274 mtx_init(&nfs_v4root_mutex, "nfs_v4root_mutex", NULL, MTX_DEF);
3275 mtx_init(&nfsv4root_mnt.mnt_mtx, "struct mount mtx", NULL,
3277 lockinit(&nfsv4root_mnt.mnt_explock, PVFS, "explock", 0, 0);
3284 #ifdef VV_DISABLEDELEG
3285 vn_deleg_ops.vndeleg_recall = nfsd_recalldelegation;
3286 vn_deleg_ops.vndeleg_disable = nfsd_disabledelegation;
3288 nfsd_call_servertimer = nfsrv_servertimer;
3289 nfsd_call_nfsd = nfssvc_nfsd;
3294 if (newnfs_numnfsd != 0) {
3299 #ifdef VV_DISABLEDELEG
3300 vn_deleg_ops.vndeleg_recall = NULL;
3301 vn_deleg_ops.vndeleg_disable = NULL;
3303 nfsd_call_servertimer = NULL;
3304 nfsd_call_nfsd = NULL;
3306 /* Clean out all NFSv4 state. */
3307 nfsrv_throwawayallstate(curthread);
3309 /* Clean the NFS server reply cache */
3310 nfsrvd_cleancache();
3312 /* Free up the krpc server pool. */
3313 if (nfsrvd_pool != NULL)
3314 svcpool_destroy(nfsrvd_pool);
3316 /* and get rid of the locks */
3317 mtx_destroy(&nfs_cache_mutex);
3318 mtx_destroy(&nfs_v4root_mutex);
3319 mtx_destroy(&nfsv4root_mnt.mnt_mtx);
3320 lockdestroy(&nfsv4root_mnt.mnt_explock);
3332 static moduledata_t nfsd_mod = {
3337 DECLARE_MODULE(nfsd, nfsd_mod, SI_SUB_VFS, SI_ORDER_ANY);
3339 /* So that loader and kldload(2) can find us, wherever we are.. */
3340 MODULE_VERSION(nfsd, 1);
3341 MODULE_DEPEND(nfsd, nfscommon, 1, 1, 1);
3342 MODULE_DEPEND(nfsd, nfslock, 1, 1, 1);
3343 MODULE_DEPEND(nfsd, nfslockd, 1, 1, 1);
3344 MODULE_DEPEND(nfsd, krpc, 1, 1, 1);
3345 MODULE_DEPEND(nfsd, nfssvc, 1, 1, 1);