19ec7b004SRick Macklem /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 49ec7b004SRick Macklem * Copyright (c) 1989, 1993 59ec7b004SRick Macklem * The Regents of the University of California. All rights reserved. 69ec7b004SRick Macklem * 79ec7b004SRick Macklem * This code is derived from software contributed to Berkeley by 89ec7b004SRick Macklem * Rick Macklem at The University of Guelph. 99ec7b004SRick Macklem * 109ec7b004SRick Macklem * Redistribution and use in source and binary forms, with or without 119ec7b004SRick Macklem * modification, are permitted provided that the following conditions 129ec7b004SRick Macklem * are met: 139ec7b004SRick Macklem * 1. Redistributions of source code must retain the above copyright 149ec7b004SRick Macklem * notice, this list of conditions and the following disclaimer. 159ec7b004SRick Macklem * 2. Redistributions in binary form must reproduce the above copyright 169ec7b004SRick Macklem * notice, this list of conditions and the following disclaimer in the 179ec7b004SRick Macklem * documentation and/or other materials provided with the distribution. 18fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 199ec7b004SRick Macklem * may be used to endorse or promote products derived from this software 209ec7b004SRick Macklem * without specific prior written permission. 219ec7b004SRick Macklem * 229ec7b004SRick Macklem * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 239ec7b004SRick Macklem * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 249ec7b004SRick Macklem * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 259ec7b004SRick Macklem * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 269ec7b004SRick Macklem * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 279ec7b004SRick Macklem * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 289ec7b004SRick Macklem * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 299ec7b004SRick Macklem * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 309ec7b004SRick Macklem * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 319ec7b004SRick Macklem * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 329ec7b004SRick Macklem * SUCH DAMAGE. 339ec7b004SRick Macklem * 349ec7b004SRick Macklem */ 359ec7b004SRick Macklem 369ec7b004SRick Macklem #include <sys/cdefs.h> 379ec7b004SRick Macklem __FBSDID("$FreeBSD$"); 389ec7b004SRick Macklem 399ec7b004SRick Macklem /* 409ec7b004SRick Macklem * Functions that need to be different for different versions of BSD 419ec7b004SRick Macklem * kernel should be kept here, along with any global storage specific 429ec7b004SRick Macklem * to this BSD variant. 439ec7b004SRick Macklem */ 449ec7b004SRick Macklem #include <fs/nfs/nfsport.h> 45f49c813cSRick Macklem #include <sys/smp.h> 469ec7b004SRick Macklem #include <sys/sysctl.h> 47f49c813cSRick Macklem #include <sys/taskqueue.h> 4825d694a6SRick Macklem #include <rpc/rpc_com.h> 499ec7b004SRick Macklem #include <vm/vm.h> 509ec7b004SRick Macklem #include <vm/vm_object.h> 519ec7b004SRick Macklem #include <vm/vm_page.h> 529ec7b004SRick Macklem #include <vm/vm_param.h> 539ec7b004SRick Macklem #include <vm/vm_map.h> 549ec7b004SRick Macklem #include <vm/vm_kern.h> 559ec7b004SRick Macklem #include <vm/vm_extern.h> 569ec7b004SRick Macklem #include <vm/uma.h> 579ec7b004SRick Macklem 589ec7b004SRick Macklem extern int nfscl_ticks; 59e1cda5eeSRick Macklem extern nfsuserd_state nfsrv_nfsuserd; 609ec7b004SRick Macklem extern struct nfssockreq nfsrv_nfsuserdsock; 619ec7b004SRick Macklem extern void (*nfsd_call_recall)(struct vnode *, int, struct ucred *, 629ec7b004SRick Macklem struct thread *); 639ec7b004SRick Macklem extern int nfsrv_useacl; 649ec7b004SRick Macklem struct mount nfsv4root_mnt; 659ec7b004SRick Macklem int newnfs_numnfsd = 0; 661b819cf2SRick Macklem struct nfsstatsv1 nfsstatsv1; 679ec7b004SRick Macklem int nfs_numnfscbd = 0; 68f4e2c07eSRick Macklem int nfscl_debuglevel = 0; 699ec7b004SRick Macklem char nfsv4_callbackaddr[INET6_ADDRSTRLEN]; 709ec7b004SRick Macklem struct callout newnfsd_callout; 7184be7e09SRick Macklem int nfsrv_lughashsize = 100; 7290d2dfabSRick Macklem struct mtx nfsrv_dslock_mtx; 7390d2dfabSRick Macklem struct nfsdevicehead nfsrv_devidhead; 7490d2dfabSRick Macklem volatile int nfsrv_devidcnt = 0; 759ec7b004SRick Macklem void (*nfsd_call_servertimer)(void) = NULL; 769ec7b004SRick Macklem void (*ncl_call_invalcaches)(struct vnode *) = NULL; 779ec7b004SRick Macklem 78f49c813cSRick Macklem int nfs_pnfsio(task_fn_t *, void *); 79f49c813cSRick Macklem 809ec7b004SRick Macklem static int nfs_realign_test; 819ec7b004SRick Macklem static int nfs_realign_count; 821b819cf2SRick Macklem static struct ext_nfsstats oldnfsstats; 83*c057a378SRick Macklem static struct nfsstatsov1 nfsstatsov1; 849ec7b004SRick Macklem 8550a220c6SEdward Tomasz Napierala SYSCTL_NODE(_vfs, OID_AUTO, nfs, CTLFLAG_RW, 0, "NFS filesystem"); 861f376590SRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_test, CTLFLAG_RW, &nfs_realign_test, 870a9f005dSRick Macklem 0, "Number of realign tests done"); 881f376590SRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_count, CTLFLAG_RW, &nfs_realign_count, 890a9f005dSRick Macklem 0, "Number of mbuf realignments done"); 901f376590SRick Macklem SYSCTL_STRING(_vfs_nfs, OID_AUTO, callback_addr, CTLFLAG_RW, 910a9f005dSRick Macklem nfsv4_callbackaddr, sizeof(nfsv4_callbackaddr), 920a9f005dSRick Macklem "NFSv4 callback addr for server to use"); 93f4e2c07eSRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, debuglevel, CTLFLAG_RW, &nfscl_debuglevel, 9450a220c6SEdward Tomasz Napierala 0, "Debug level for NFS client"); 9584be7e09SRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, userhashsize, CTLFLAG_RDTUN, &nfsrv_lughashsize, 9684be7e09SRick Macklem 0, "Size of hash tables for uid/name mapping"); 97dec8894bSRick Macklem int nfs_pnfsiothreads = -1; 98f49c813cSRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, pnfsiothreads, CTLFLAG_RW, &nfs_pnfsiothreads, 99f49c813cSRick Macklem 0, "Number of pNFS mirror I/O threads"); 1009ec7b004SRick Macklem 1019ec7b004SRick Macklem /* 1029ec7b004SRick Macklem * Defines for malloc 1039ec7b004SRick Macklem * (Here for FreeBSD, since they allocate storage.) 1049ec7b004SRick Macklem */ 1059ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSRVCACHE, "NFSD srvcache", "NFSD Server Request Cache"); 1069ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSDCLIENT, "NFSD V4client", "NFSD V4 Client Id"); 107a43fcbe3SRick Macklem MALLOC_DEFINE(M_NEWNFSDSTATE, "NFSD V4state", 108a43fcbe3SRick Macklem "NFSD V4 State (Openowner, Open, Lockowner, Delegation"); 1099ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSDLOCK, "NFSD V4lock", "NFSD V4 byte range lock"); 1109ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSDLOCKFILE, "NFSD lckfile", "NFSD Open/Lock file"); 1119ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSSTRING, "NFSD string", "NFSD V4 long string"); 1129ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSUSERGROUP, "NFSD usrgroup", "NFSD V4 User/group map"); 1139ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSDREQ, "NFS req", "NFS request header"); 1149ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSFH, "NFS fh", "NFS file handle"); 1159ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLOWNER, "NFSCL owner", "NFSCL Open Owner"); 1169ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLOPEN, "NFSCL open", "NFSCL Open"); 1179ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLDELEG, "NFSCL deleg", "NFSCL Delegation"); 1189ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLCLIENT, "NFSCL client", "NFSCL Client"); 1199ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLLOCKOWNER, "NFSCL lckown", "NFSCL Lock Owner"); 1209ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLLOCK, "NFSCL lck", "NFSCL Lock"); 12150a220c6SEdward Tomasz Napierala MALLOC_DEFINE(M_NEWNFSV4NODE, "NEWNFSnode", "NFS vnode"); 12250a220c6SEdward Tomasz Napierala MALLOC_DEFINE(M_NEWNFSDIRECTIO, "NEWdirectio", "NFS Direct IO buffer"); 123a43fcbe3SRick Macklem MALLOC_DEFINE(M_NEWNFSDIROFF, "NFSCL diroffdiroff", 12450a220c6SEdward Tomasz Napierala "NFS directory offset data"); 125a43fcbe3SRick Macklem MALLOC_DEFINE(M_NEWNFSDROLLBACK, "NFSD rollback", 12650a220c6SEdward Tomasz Napierala "NFS local lock rollback"); 1271f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSLAYOUT, "NFSCL layout", "NFSv4.1 Layout"); 1281f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSFLAYOUT, "NFSCL flayout", "NFSv4.1 File Layout"); 1291f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSDEVINFO, "NFSCL devinfo", "NFSv4.1 Device Info"); 1301f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSSOCKREQ, "NFSCL sockreq", "NFS Sock Req"); 1311f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSCLDS, "NFSCL session", "NFSv4.1 Session"); 1321f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSLAYRECALL, "NFSCL layrecall", "NFSv4.1 Layout Recall"); 133c59e4cc3SRick Macklem MALLOC_DEFINE(M_NEWNFSDSESSION, "NFSD session", "NFSD Session for a client"); 1349ec7b004SRick Macklem 1359ec7b004SRick Macklem /* 1369ec7b004SRick Macklem * Definition of mutex locks. 1379ec7b004SRick Macklem * newnfsd_mtx is used in nfsrvd_nfsd() to protect the nfs socket list 1389ec7b004SRick Macklem * and assorted other nfsd structures. 1399ec7b004SRick Macklem */ 1409ec7b004SRick Macklem struct mtx newnfsd_mtx; 1419ec7b004SRick Macklem struct mtx nfs_sockl_mutex; 1429ec7b004SRick Macklem struct mtx nfs_state_mutex; 1439ec7b004SRick Macklem struct mtx nfs_nameid_mutex; 1449ec7b004SRick Macklem struct mtx nfs_req_mutex; 1459ec7b004SRick Macklem struct mtx nfs_slock_mutex; 146b2fc0141SRick Macklem struct mtx nfs_clstate_mutex; 1479ec7b004SRick Macklem 1489ec7b004SRick Macklem /* local functions */ 1499ec7b004SRick Macklem static int nfssvc_call(struct thread *, struct nfssvc_args *, struct ucred *); 1509ec7b004SRick Macklem 1513dfe81c6SRick Macklem #ifdef __NO_STRICT_ALIGNMENT 1529ec7b004SRick Macklem /* 1539ec7b004SRick Macklem * These architectures don't need re-alignment, so just return. 1549ec7b004SRick Macklem */ 155d96b98a3SKenneth D. Merry int 156d96b98a3SKenneth D. Merry newnfs_realign(struct mbuf **pm, int how) 1579ec7b004SRick Macklem { 1589ec7b004SRick Macklem 159d96b98a3SKenneth D. Merry return (0); 1609ec7b004SRick Macklem } 1613dfe81c6SRick Macklem #else /* !__NO_STRICT_ALIGNMENT */ 1629ec7b004SRick Macklem /* 16305c965a2SRick Macklem * newnfs_realign: 1649ec7b004SRick Macklem * 1659ec7b004SRick Macklem * Check for badly aligned mbuf data and realign by copying the unaligned 1669ec7b004SRick Macklem * portion of the data into a new mbuf chain and freeing the portions 1679ec7b004SRick Macklem * of the old chain that were replaced. 1689ec7b004SRick Macklem * 1699ec7b004SRick Macklem * We cannot simply realign the data within the existing mbuf chain 1709ec7b004SRick Macklem * because the underlying buffers may contain other rpc commands and 1719ec7b004SRick Macklem * we cannot afford to overwrite them. 1729ec7b004SRick Macklem * 1739ec7b004SRick Macklem * We would prefer to avoid this situation entirely. The situation does 174a96c9b30SPedro F. Giffuni * not occur with NFS/UDP and is supposed to only occasionally occur 1759ec7b004SRick Macklem * with TCP. Use vfs.nfs.realign_count and realign_test to check this. 17605c965a2SRick Macklem * 1779ec7b004SRick Macklem */ 178d96b98a3SKenneth D. Merry int 179d96b98a3SKenneth D. Merry newnfs_realign(struct mbuf **pm, int how) 1809ec7b004SRick Macklem { 18105c965a2SRick Macklem struct mbuf *m, *n; 18205c965a2SRick Macklem int off, space; 1839ec7b004SRick Macklem 1849ec7b004SRick Macklem ++nfs_realign_test; 1859ec7b004SRick Macklem while ((m = *pm) != NULL) { 1869ec7b004SRick Macklem if ((m->m_len & 0x3) || (mtod(m, intptr_t) & 0x3)) { 1879ec7b004SRick Macklem /* 18805c965a2SRick Macklem * NB: we can't depend on m_pkthdr.len to help us 18905c965a2SRick Macklem * decide what to do here. May not be worth doing 19005c965a2SRick Macklem * the m_length calculation as m_copyback will 19105c965a2SRick Macklem * expand the mbuf chain below as needed. 1929ec7b004SRick Macklem */ 19305c965a2SRick Macklem space = m_length(m, NULL); 19405c965a2SRick Macklem if (space >= MINCLSIZE) { 19505c965a2SRick Macklem /* NB: m_copyback handles space > MCLBYTES */ 196d96b98a3SKenneth D. Merry n = m_getcl(how, MT_DATA, 0); 19705c965a2SRick Macklem } else 198d96b98a3SKenneth D. Merry n = m_get(how, MT_DATA); 19905c965a2SRick Macklem if (n == NULL) 200d96b98a3SKenneth D. Merry return (ENOMEM); 20105c965a2SRick Macklem /* 20205c965a2SRick Macklem * Align the remainder of the mbuf chain. 20305c965a2SRick Macklem */ 20405c965a2SRick Macklem n->m_len = 0; 20505c965a2SRick Macklem off = 0; 20605c965a2SRick Macklem while (m != NULL) { 2079ec7b004SRick Macklem m_copyback(n, off, m->m_len, mtod(m, caddr_t)); 2089ec7b004SRick Macklem off += m->m_len; 2099ec7b004SRick Macklem m = m->m_next; 2109ec7b004SRick Macklem } 2119ec7b004SRick Macklem m_freem(*pm); 2129ec7b004SRick Macklem *pm = n; 21305c965a2SRick Macklem ++nfs_realign_count; 21405c965a2SRick Macklem break; 21505c965a2SRick Macklem } 21605c965a2SRick Macklem pm = &m->m_next; 2179ec7b004SRick Macklem } 218d96b98a3SKenneth D. Merry 219d96b98a3SKenneth D. Merry return (0); 2209ec7b004SRick Macklem } 2213dfe81c6SRick Macklem #endif /* __NO_STRICT_ALIGNMENT */ 2229ec7b004SRick Macklem 2239ec7b004SRick Macklem #ifdef notdef 2249ec7b004SRick Macklem static void 2259ec7b004SRick Macklem nfsrv_object_create(struct vnode *vp, struct thread *td) 2269ec7b004SRick Macklem { 2279ec7b004SRick Macklem 2289ec7b004SRick Macklem if (vp == NULL || vp->v_type != VREG) 2299ec7b004SRick Macklem return; 2309ec7b004SRick Macklem (void) vfs_object_create(vp, td, td->td_ucred); 2319ec7b004SRick Macklem } 2329ec7b004SRick Macklem #endif 2339ec7b004SRick Macklem 2349ec7b004SRick Macklem /* 2359ec7b004SRick Macklem * Look up a file name. Basically just initialize stuff and call namei(). 2369ec7b004SRick Macklem */ 2379ec7b004SRick Macklem int 2389ec7b004SRick Macklem nfsrv_lookupfilename(struct nameidata *ndp, char *fname, NFSPROC_T *p) 2399ec7b004SRick Macklem { 2409ec7b004SRick Macklem int error; 2419ec7b004SRick Macklem 2425050aa86SKonstantin Belousov NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, fname, 24366c0f45aSRick Macklem p); 2449ec7b004SRick Macklem error = namei(ndp); 2459ec7b004SRick Macklem if (!error) { 2469ec7b004SRick Macklem NDFREE(ndp, NDF_ONLY_PNBUF); 2479ec7b004SRick Macklem } 2489ec7b004SRick Macklem return (error); 2499ec7b004SRick Macklem } 2509ec7b004SRick Macklem 2519ec7b004SRick Macklem /* 2529ec7b004SRick Macklem * Copy NFS uid, gids to the cred structure. 2539ec7b004SRick Macklem */ 2549ec7b004SRick Macklem void 2559ec7b004SRick Macklem newnfs_copycred(struct nfscred *nfscr, struct ucred *cr) 2569ec7b004SRick Macklem { 2579ec7b004SRick Macklem 25855909abfSRick Macklem KASSERT(nfscr->nfsc_ngroups >= 0, 25955909abfSRick Macklem ("newnfs_copycred: negative nfsc_ngroups")); 2609ec7b004SRick Macklem cr->cr_uid = nfscr->nfsc_uid; 261838d9858SBrooks Davis crsetgroups(cr, nfscr->nfsc_ngroups, nfscr->nfsc_groups); 2629ec7b004SRick Macklem } 2639ec7b004SRick Macklem 2649ec7b004SRick Macklem /* 2659ec7b004SRick Macklem * Map args from nfsmsleep() to msleep(). 2669ec7b004SRick Macklem */ 2679ec7b004SRick Macklem int 2689ec7b004SRick Macklem nfsmsleep(void *chan, void *mutex, int prio, const char *wmesg, 2699ec7b004SRick Macklem struct timespec *ts) 2709ec7b004SRick Macklem { 2719ec7b004SRick Macklem u_int64_t nsecval; 2729ec7b004SRick Macklem int error, timeo; 2739ec7b004SRick Macklem 2749ec7b004SRick Macklem if (ts) { 2759ec7b004SRick Macklem timeo = hz * ts->tv_sec; 2769ec7b004SRick Macklem nsecval = (u_int64_t)ts->tv_nsec; 2779ec7b004SRick Macklem nsecval = ((nsecval * ((u_int64_t)hz)) + 500000000) / 2789ec7b004SRick Macklem 1000000000; 2799ec7b004SRick Macklem timeo += (int)nsecval; 2809ec7b004SRick Macklem } else { 2819ec7b004SRick Macklem timeo = 0; 2829ec7b004SRick Macklem } 2839ec7b004SRick Macklem error = msleep(chan, (struct mtx *)mutex, prio, wmesg, timeo); 2849ec7b004SRick Macklem return (error); 2859ec7b004SRick Macklem } 2869ec7b004SRick Macklem 2879ec7b004SRick Macklem /* 2889ec7b004SRick Macklem * Get the file system info for the server. For now, just assume FFS. 2899ec7b004SRick Macklem */ 2909ec7b004SRick Macklem void 2919ec7b004SRick Macklem nfsvno_getfs(struct nfsfsinfo *sip, int isdgram) 2929ec7b004SRick Macklem { 2939ec7b004SRick Macklem int pref; 2949ec7b004SRick Macklem 2959ec7b004SRick Macklem /* 2969ec7b004SRick Macklem * XXX 2979ec7b004SRick Macklem * There should be file system VFS OP(s) to get this information. 2989ec7b004SRick Macklem * For now, assume ufs. 2999ec7b004SRick Macklem */ 3009ec7b004SRick Macklem if (isdgram) 3019ec7b004SRick Macklem pref = NFS_MAXDGRAMDATA; 3029ec7b004SRick Macklem else 30366e80f77SRick Macklem pref = NFS_SRVMAXIO; 30466e80f77SRick Macklem sip->fs_rtmax = NFS_SRVMAXIO; 3059ec7b004SRick Macklem sip->fs_rtpref = pref; 3069ec7b004SRick Macklem sip->fs_rtmult = NFS_FABLKSIZE; 30766e80f77SRick Macklem sip->fs_wtmax = NFS_SRVMAXIO; 3089ec7b004SRick Macklem sip->fs_wtpref = pref; 3099ec7b004SRick Macklem sip->fs_wtmult = NFS_FABLKSIZE; 3109ec7b004SRick Macklem sip->fs_dtpref = pref; 3119ec7b004SRick Macklem sip->fs_maxfilesize = 0xffffffffffffffffull; 3129ec7b004SRick Macklem sip->fs_timedelta.tv_sec = 0; 3139ec7b004SRick Macklem sip->fs_timedelta.tv_nsec = 1; 3149ec7b004SRick Macklem sip->fs_properties = (NFSV3FSINFO_LINK | 3159ec7b004SRick Macklem NFSV3FSINFO_SYMLINK | NFSV3FSINFO_HOMOGENEOUS | 3169ec7b004SRick Macklem NFSV3FSINFO_CANSETTIME); 3179ec7b004SRick Macklem } 3189ec7b004SRick Macklem 31940435b74SZack Kirsch /* 32040435b74SZack Kirsch * Do the pathconf vnode op. 32140435b74SZack Kirsch */ 32240435b74SZack Kirsch int 323b1288166SJohn Baldwin nfsvno_pathconf(struct vnode *vp, int flag, long *retf, 32440435b74SZack Kirsch struct ucred *cred, struct thread *p) 32540435b74SZack Kirsch { 32640435b74SZack Kirsch int error; 32740435b74SZack Kirsch 32840435b74SZack Kirsch error = VOP_PATHCONF(vp, flag, retf); 32940435b74SZack Kirsch if (error == EOPNOTSUPP || error == EINVAL) { 33040435b74SZack Kirsch /* 33140435b74SZack Kirsch * Some file systems return EINVAL for name arguments not 33240435b74SZack Kirsch * supported and some return EOPNOTSUPP for this case. 33340435b74SZack Kirsch * So the NFSv3 Pathconf RPC doesn't fail for these cases, 33440435b74SZack Kirsch * just fake them. 33540435b74SZack Kirsch */ 33640435b74SZack Kirsch switch (flag) { 33740435b74SZack Kirsch case _PC_LINK_MAX: 338a0a073b1SJohn Baldwin *retf = NFS_LINK_MAX; 33940435b74SZack Kirsch break; 34040435b74SZack Kirsch case _PC_NAME_MAX: 34140435b74SZack Kirsch *retf = NAME_MAX; 34240435b74SZack Kirsch break; 34340435b74SZack Kirsch case _PC_CHOWN_RESTRICTED: 34440435b74SZack Kirsch *retf = 1; 34540435b74SZack Kirsch break; 34640435b74SZack Kirsch case _PC_NO_TRUNC: 34740435b74SZack Kirsch *retf = 1; 34840435b74SZack Kirsch break; 34940435b74SZack Kirsch default: 35040435b74SZack Kirsch /* 35140435b74SZack Kirsch * Only happens if a _PC_xxx is added to the server, 35240435b74SZack Kirsch * but this isn't updated. 35340435b74SZack Kirsch */ 35440435b74SZack Kirsch *retf = 0; 35540435b74SZack Kirsch printf("nfsrvd pathconf flag=%d not supp\n", flag); 35674b8d63dSPedro F. Giffuni } 35740435b74SZack Kirsch error = 0; 35840435b74SZack Kirsch } 359a9285ae5SZack Kirsch NFSEXITCODE(error); 36040435b74SZack Kirsch return (error); 36140435b74SZack Kirsch } 36240435b74SZack Kirsch 3639ec7b004SRick Macklem /* Fake nfsrv_atroot. Just return 0 */ 3649ec7b004SRick Macklem int 36595ac7f1aSRick Macklem nfsrv_atroot(struct vnode *vp, uint64_t *retp) 3669ec7b004SRick Macklem { 3679ec7b004SRick Macklem 3689ec7b004SRick Macklem return (0); 3699ec7b004SRick Macklem } 3709ec7b004SRick Macklem 3719ec7b004SRick Macklem /* 3729ec7b004SRick Macklem * Set the credentials to refer to root. 3739ec7b004SRick Macklem * If only the various BSDen could agree on whether cr_gid is a separate 3749ec7b004SRick Macklem * field or cr_groups[0]... 3759ec7b004SRick Macklem */ 3769ec7b004SRick Macklem void 3779ec7b004SRick Macklem newnfs_setroot(struct ucred *cred) 3789ec7b004SRick Macklem { 3799ec7b004SRick Macklem 3809ec7b004SRick Macklem cred->cr_uid = 0; 3819ec7b004SRick Macklem cred->cr_groups[0] = 0; 3829ec7b004SRick Macklem cred->cr_ngroups = 1; 3839ec7b004SRick Macklem } 3849ec7b004SRick Macklem 3859ec7b004SRick Macklem /* 3869ec7b004SRick Macklem * Get the client credential. Used for Renew and recovery. 3879ec7b004SRick Macklem */ 3889ec7b004SRick Macklem struct ucred * 3899ec7b004SRick Macklem newnfs_getcred(void) 3909ec7b004SRick Macklem { 3919ec7b004SRick Macklem struct ucred *cred; 3929ec7b004SRick Macklem struct thread *td = curthread; 3939ec7b004SRick Macklem 3949ec7b004SRick Macklem cred = crdup(td->td_ucred); 3959ec7b004SRick Macklem newnfs_setroot(cred); 3969ec7b004SRick Macklem return (cred); 3979ec7b004SRick Macklem } 3989ec7b004SRick Macklem 3999ec7b004SRick Macklem /* 4009ec7b004SRick Macklem * Nfs timer routine 4019ec7b004SRick Macklem * Call the nfsd's timer function once/sec. 4029ec7b004SRick Macklem */ 4039ec7b004SRick Macklem void 4049ec7b004SRick Macklem newnfs_timer(void *arg) 4059ec7b004SRick Macklem { 4069ec7b004SRick Macklem static time_t lasttime = 0; 4079ec7b004SRick Macklem /* 4089ec7b004SRick Macklem * Call the server timer, if set up. 4099ec7b004SRick Macklem * The argument indicates if it is the next second and therefore 4109ec7b004SRick Macklem * leases should be checked. 4119ec7b004SRick Macklem */ 4129ec7b004SRick Macklem if (lasttime != NFSD_MONOSEC) { 4139ec7b004SRick Macklem lasttime = NFSD_MONOSEC; 4149ec7b004SRick Macklem if (nfsd_call_servertimer != NULL) 4159ec7b004SRick Macklem (*nfsd_call_servertimer)(); 4169ec7b004SRick Macklem } 4179ec7b004SRick Macklem callout_reset(&newnfsd_callout, nfscl_ticks, newnfs_timer, NULL); 4189ec7b004SRick Macklem } 4199ec7b004SRick Macklem 4209ec7b004SRick Macklem 4219ec7b004SRick Macklem /* 42223f929dfSRick Macklem * Sleep for a short period of time unless errval == NFSERR_GRACE, where 42323f929dfSRick Macklem * the sleep should be for 5 seconds. 4249ec7b004SRick Macklem * Since lbolt doesn't exist in FreeBSD-CURRENT, just use a timeout on 4259ec7b004SRick Macklem * an event that never gets a wakeup. Only return EINTR or 0. 4269ec7b004SRick Macklem */ 4279ec7b004SRick Macklem int 42823f929dfSRick Macklem nfs_catnap(int prio, int errval, const char *wmesg) 4299ec7b004SRick Macklem { 4309ec7b004SRick Macklem static int non_event; 4319ec7b004SRick Macklem int ret; 4329ec7b004SRick Macklem 43323f929dfSRick Macklem if (errval == NFSERR_GRACE) 43423f929dfSRick Macklem ret = tsleep(&non_event, prio, wmesg, 5 * hz); 43523f929dfSRick Macklem else 4369ec7b004SRick Macklem ret = tsleep(&non_event, prio, wmesg, 1); 4379ec7b004SRick Macklem if (ret != EINTR) 4389ec7b004SRick Macklem ret = 0; 4399ec7b004SRick Macklem return (ret); 4409ec7b004SRick Macklem } 4419ec7b004SRick Macklem 4429ec7b004SRick Macklem /* 4439ec7b004SRick Macklem * Get referral. For now, just fail. 4449ec7b004SRick Macklem */ 4459ec7b004SRick Macklem struct nfsreferral * 4469ec7b004SRick Macklem nfsv4root_getreferral(struct vnode *vp, struct vnode *dvp, u_int32_t fileno) 4479ec7b004SRick Macklem { 4489ec7b004SRick Macklem 4499ec7b004SRick Macklem return (NULL); 4509ec7b004SRick Macklem } 4519ec7b004SRick Macklem 4529ec7b004SRick Macklem static int 4539ec7b004SRick Macklem nfssvc_nfscommon(struct thread *td, struct nfssvc_args *uap) 4549ec7b004SRick Macklem { 4559ec7b004SRick Macklem int error; 4569ec7b004SRick Macklem 4579ec7b004SRick Macklem error = nfssvc_call(td, uap, td->td_ucred); 458a9285ae5SZack Kirsch NFSEXITCODE(error); 4599ec7b004SRick Macklem return (error); 4609ec7b004SRick Macklem } 4619ec7b004SRick Macklem 4629ec7b004SRick Macklem static int 4639ec7b004SRick Macklem nfssvc_call(struct thread *p, struct nfssvc_args *uap, struct ucred *cred) 4649ec7b004SRick Macklem { 4651b819cf2SRick Macklem int error = EINVAL, i, j; 4669ec7b004SRick Macklem struct nfsd_idargs nid; 46784be7e09SRick Macklem struct nfsd_oidargs onid; 4681b819cf2SRick Macklem struct { 4691b819cf2SRick Macklem int vers; /* Just the first field of nfsstats. */ 4701b819cf2SRick Macklem } nfsstatver; 4719ec7b004SRick Macklem 4729ec7b004SRick Macklem if (uap->flag & NFSSVC_IDNAME) { 47384be7e09SRick Macklem if ((uap->flag & NFSSVC_NEWSTRUCT) != 0) 47484be7e09SRick Macklem error = copyin(uap->argp, &nid, sizeof(nid)); 47584be7e09SRick Macklem else { 47684be7e09SRick Macklem error = copyin(uap->argp, &onid, sizeof(onid)); 47784be7e09SRick Macklem if (error == 0) { 47884be7e09SRick Macklem nid.nid_flag = onid.nid_flag; 47984be7e09SRick Macklem nid.nid_uid = onid.nid_uid; 48084be7e09SRick Macklem nid.nid_gid = onid.nid_gid; 48184be7e09SRick Macklem nid.nid_usermax = onid.nid_usermax; 48284be7e09SRick Macklem nid.nid_usertimeout = onid.nid_usertimeout; 48384be7e09SRick Macklem nid.nid_name = onid.nid_name; 48484be7e09SRick Macklem nid.nid_namelen = onid.nid_namelen; 48584be7e09SRick Macklem nid.nid_ngroup = 0; 48684be7e09SRick Macklem nid.nid_grps = NULL; 48784be7e09SRick Macklem } 48884be7e09SRick Macklem } 4899ec7b004SRick Macklem if (error) 490a9285ae5SZack Kirsch goto out; 4919ec7b004SRick Macklem error = nfssvc_idname(&nid); 492a9285ae5SZack Kirsch goto out; 4939ec7b004SRick Macklem } else if (uap->flag & NFSSVC_GETSTATS) { 4941b819cf2SRick Macklem if ((uap->flag & NFSSVC_NEWSTRUCT) == 0) { 4951b819cf2SRick Macklem /* Copy fields to the old ext_nfsstat structure. */ 4961b819cf2SRick Macklem oldnfsstats.attrcache_hits = 4971b819cf2SRick Macklem nfsstatsv1.attrcache_hits; 4981b819cf2SRick Macklem oldnfsstats.attrcache_misses = 4991b819cf2SRick Macklem nfsstatsv1.attrcache_misses; 5001b819cf2SRick Macklem oldnfsstats.lookupcache_hits = 5011b819cf2SRick Macklem nfsstatsv1.lookupcache_hits; 5021b819cf2SRick Macklem oldnfsstats.lookupcache_misses = 5031b819cf2SRick Macklem nfsstatsv1.lookupcache_misses; 5041b819cf2SRick Macklem oldnfsstats.direofcache_hits = 5051b819cf2SRick Macklem nfsstatsv1.direofcache_hits; 5061b819cf2SRick Macklem oldnfsstats.direofcache_misses = 5071b819cf2SRick Macklem nfsstatsv1.direofcache_misses; 5081b819cf2SRick Macklem oldnfsstats.accesscache_hits = 5091b819cf2SRick Macklem nfsstatsv1.accesscache_hits; 5101b819cf2SRick Macklem oldnfsstats.accesscache_misses = 5111b819cf2SRick Macklem nfsstatsv1.accesscache_misses; 5121b819cf2SRick Macklem oldnfsstats.biocache_reads = 5131b819cf2SRick Macklem nfsstatsv1.biocache_reads; 5141b819cf2SRick Macklem oldnfsstats.read_bios = 5151b819cf2SRick Macklem nfsstatsv1.read_bios; 5161b819cf2SRick Macklem oldnfsstats.read_physios = 5171b819cf2SRick Macklem nfsstatsv1.read_physios; 5181b819cf2SRick Macklem oldnfsstats.biocache_writes = 5191b819cf2SRick Macklem nfsstatsv1.biocache_writes; 5201b819cf2SRick Macklem oldnfsstats.write_bios = 5211b819cf2SRick Macklem nfsstatsv1.write_bios; 5221b819cf2SRick Macklem oldnfsstats.write_physios = 5231b819cf2SRick Macklem nfsstatsv1.write_physios; 5241b819cf2SRick Macklem oldnfsstats.biocache_readlinks = 5251b819cf2SRick Macklem nfsstatsv1.biocache_readlinks; 5261b819cf2SRick Macklem oldnfsstats.readlink_bios = 5271b819cf2SRick Macklem nfsstatsv1.readlink_bios; 5281b819cf2SRick Macklem oldnfsstats.biocache_readdirs = 5291b819cf2SRick Macklem nfsstatsv1.biocache_readdirs; 5301b819cf2SRick Macklem oldnfsstats.readdir_bios = 5311b819cf2SRick Macklem nfsstatsv1.readdir_bios; 5321b819cf2SRick Macklem for (i = 0; i < NFSV4_NPROCS; i++) 5331b819cf2SRick Macklem oldnfsstats.rpccnt[i] = nfsstatsv1.rpccnt[i]; 5341b819cf2SRick Macklem oldnfsstats.rpcretries = nfsstatsv1.rpcretries; 5351b819cf2SRick Macklem for (i = 0; i < NFSV4OP_NOPS; i++) 5361b819cf2SRick Macklem oldnfsstats.srvrpccnt[i] = 5371b819cf2SRick Macklem nfsstatsv1.srvrpccnt[i]; 5381b819cf2SRick Macklem for (i = NFSV42_NOPS, j = NFSV4OP_NOPS; 5391b819cf2SRick Macklem i < NFSV42_NOPS + NFSV4OP_FAKENOPS; i++, j++) 5401b819cf2SRick Macklem oldnfsstats.srvrpccnt[j] = 5411b819cf2SRick Macklem nfsstatsv1.srvrpccnt[i]; 5421b819cf2SRick Macklem oldnfsstats.srvrpc_errs = nfsstatsv1.srvrpc_errs; 5431b819cf2SRick Macklem oldnfsstats.srv_errs = nfsstatsv1.srv_errs; 5441b819cf2SRick Macklem oldnfsstats.rpcrequests = nfsstatsv1.rpcrequests; 5451b819cf2SRick Macklem oldnfsstats.rpctimeouts = nfsstatsv1.rpctimeouts; 5461b819cf2SRick Macklem oldnfsstats.rpcunexpected = nfsstatsv1.rpcunexpected; 5471b819cf2SRick Macklem oldnfsstats.rpcinvalid = nfsstatsv1.rpcinvalid; 5481b819cf2SRick Macklem oldnfsstats.srvcache_inproghits = 5491b819cf2SRick Macklem nfsstatsv1.srvcache_inproghits; 5501b819cf2SRick Macklem oldnfsstats.srvcache_idemdonehits = 5511b819cf2SRick Macklem nfsstatsv1.srvcache_idemdonehits; 5521b819cf2SRick Macklem oldnfsstats.srvcache_nonidemdonehits = 5531b819cf2SRick Macklem nfsstatsv1.srvcache_nonidemdonehits; 5541b819cf2SRick Macklem oldnfsstats.srvcache_misses = 5551b819cf2SRick Macklem nfsstatsv1.srvcache_misses; 5561b819cf2SRick Macklem oldnfsstats.srvcache_tcppeak = 5571b819cf2SRick Macklem nfsstatsv1.srvcache_tcppeak; 5581b819cf2SRick Macklem oldnfsstats.srvcache_size = nfsstatsv1.srvcache_size; 5591b819cf2SRick Macklem oldnfsstats.srvclients = nfsstatsv1.srvclients; 5601b819cf2SRick Macklem oldnfsstats.srvopenowners = nfsstatsv1.srvopenowners; 5611b819cf2SRick Macklem oldnfsstats.srvopens = nfsstatsv1.srvopens; 5621b819cf2SRick Macklem oldnfsstats.srvlockowners = nfsstatsv1.srvlockowners; 5631b819cf2SRick Macklem oldnfsstats.srvlocks = nfsstatsv1.srvlocks; 5641b819cf2SRick Macklem oldnfsstats.srvdelegates = nfsstatsv1.srvdelegates; 5651b819cf2SRick Macklem for (i = 0; i < NFSV4OP_CBNOPS; i++) 5661b819cf2SRick Macklem oldnfsstats.cbrpccnt[i] = 5671b819cf2SRick Macklem nfsstatsv1.cbrpccnt[i]; 5681b819cf2SRick Macklem oldnfsstats.clopenowners = nfsstatsv1.clopenowners; 5691b819cf2SRick Macklem oldnfsstats.clopens = nfsstatsv1.clopens; 5701b819cf2SRick Macklem oldnfsstats.cllockowners = nfsstatsv1.cllockowners; 5711b819cf2SRick Macklem oldnfsstats.cllocks = nfsstatsv1.cllocks; 5721b819cf2SRick Macklem oldnfsstats.cldelegates = nfsstatsv1.cldelegates; 5731b819cf2SRick Macklem oldnfsstats.cllocalopenowners = 5741b819cf2SRick Macklem nfsstatsv1.cllocalopenowners; 5751b819cf2SRick Macklem oldnfsstats.cllocalopens = nfsstatsv1.cllocalopens; 5761b819cf2SRick Macklem oldnfsstats.cllocallockowners = 5771b819cf2SRick Macklem nfsstatsv1.cllocallockowners; 5781b819cf2SRick Macklem oldnfsstats.cllocallocks = nfsstatsv1.cllocallocks; 5791b819cf2SRick Macklem error = copyout(&oldnfsstats, uap->argp, 5801b819cf2SRick Macklem sizeof (oldnfsstats)); 5811b819cf2SRick Macklem } else { 5821b819cf2SRick Macklem error = copyin(uap->argp, &nfsstatver, 5831b819cf2SRick Macklem sizeof(nfsstatver)); 584*c057a378SRick Macklem if (error == 0) { 585*c057a378SRick Macklem if (nfsstatver.vers == NFSSTATS_OV1) { 586*c057a378SRick Macklem /* Copy nfsstatsv1 to nfsstatsov1. */ 587*c057a378SRick Macklem nfsstatsov1.attrcache_hits = 588*c057a378SRick Macklem nfsstatsv1.attrcache_hits; 589*c057a378SRick Macklem nfsstatsov1.attrcache_misses = 590*c057a378SRick Macklem nfsstatsv1.attrcache_misses; 591*c057a378SRick Macklem nfsstatsov1.lookupcache_hits = 592*c057a378SRick Macklem nfsstatsv1.lookupcache_hits; 593*c057a378SRick Macklem nfsstatsov1.lookupcache_misses = 594*c057a378SRick Macklem nfsstatsv1.lookupcache_misses; 595*c057a378SRick Macklem nfsstatsov1.direofcache_hits = 596*c057a378SRick Macklem nfsstatsv1.direofcache_hits; 597*c057a378SRick Macklem nfsstatsov1.direofcache_misses = 598*c057a378SRick Macklem nfsstatsv1.direofcache_misses; 599*c057a378SRick Macklem nfsstatsov1.accesscache_hits = 600*c057a378SRick Macklem nfsstatsv1.accesscache_hits; 601*c057a378SRick Macklem nfsstatsov1.accesscache_misses = 602*c057a378SRick Macklem nfsstatsv1.accesscache_misses; 603*c057a378SRick Macklem nfsstatsov1.biocache_reads = 604*c057a378SRick Macklem nfsstatsv1.biocache_reads; 605*c057a378SRick Macklem nfsstatsov1.read_bios = 606*c057a378SRick Macklem nfsstatsv1.read_bios; 607*c057a378SRick Macklem nfsstatsov1.read_physios = 608*c057a378SRick Macklem nfsstatsv1.read_physios; 609*c057a378SRick Macklem nfsstatsov1.biocache_writes = 610*c057a378SRick Macklem nfsstatsv1.biocache_writes; 611*c057a378SRick Macklem nfsstatsov1.write_bios = 612*c057a378SRick Macklem nfsstatsv1.write_bios; 613*c057a378SRick Macklem nfsstatsov1.write_physios = 614*c057a378SRick Macklem nfsstatsv1.write_physios; 615*c057a378SRick Macklem nfsstatsov1.biocache_readlinks = 616*c057a378SRick Macklem nfsstatsv1.biocache_readlinks; 617*c057a378SRick Macklem nfsstatsov1.readlink_bios = 618*c057a378SRick Macklem nfsstatsv1.readlink_bios; 619*c057a378SRick Macklem nfsstatsov1.biocache_readdirs = 620*c057a378SRick Macklem nfsstatsv1.biocache_readdirs; 621*c057a378SRick Macklem nfsstatsov1.readdir_bios = 622*c057a378SRick Macklem nfsstatsv1.readdir_bios; 623*c057a378SRick Macklem for (i = 0; i < NFSV42_NPROCS; i++) 624*c057a378SRick Macklem nfsstatsov1.rpccnt[i] = 625*c057a378SRick Macklem nfsstatsv1.rpccnt[i]; 626*c057a378SRick Macklem nfsstatsov1.rpcretries = 627*c057a378SRick Macklem nfsstatsv1.rpcretries; 628*c057a378SRick Macklem for (i = 0; i < NFSV42_PURENOPS; i++) 629*c057a378SRick Macklem nfsstatsov1.srvrpccnt[i] = 630*c057a378SRick Macklem nfsstatsv1.srvrpccnt[i]; 631*c057a378SRick Macklem for (i = NFSV42_NOPS, 632*c057a378SRick Macklem j = NFSV42_PURENOPS; 633*c057a378SRick Macklem i < NFSV42_NOPS + NFSV4OP_FAKENOPS; 634*c057a378SRick Macklem i++, j++) 635*c057a378SRick Macklem nfsstatsov1.srvrpccnt[j] = 636*c057a378SRick Macklem nfsstatsv1.srvrpccnt[i]; 637*c057a378SRick Macklem nfsstatsov1.srvrpc_errs = 638*c057a378SRick Macklem nfsstatsv1.srvrpc_errs; 639*c057a378SRick Macklem nfsstatsov1.srv_errs = 640*c057a378SRick Macklem nfsstatsv1.srv_errs; 641*c057a378SRick Macklem nfsstatsov1.rpcrequests = 642*c057a378SRick Macklem nfsstatsv1.rpcrequests; 643*c057a378SRick Macklem nfsstatsov1.rpctimeouts = 644*c057a378SRick Macklem nfsstatsv1.rpctimeouts; 645*c057a378SRick Macklem nfsstatsov1.rpcunexpected = 646*c057a378SRick Macklem nfsstatsv1.rpcunexpected; 647*c057a378SRick Macklem nfsstatsov1.rpcinvalid = 648*c057a378SRick Macklem nfsstatsv1.rpcinvalid; 649*c057a378SRick Macklem nfsstatsov1.srvcache_inproghits = 650*c057a378SRick Macklem nfsstatsv1.srvcache_inproghits; 651*c057a378SRick Macklem nfsstatsov1.srvcache_idemdonehits = 652*c057a378SRick Macklem nfsstatsv1.srvcache_idemdonehits; 653*c057a378SRick Macklem nfsstatsov1.srvcache_nonidemdonehits = 654*c057a378SRick Macklem nfsstatsv1.srvcache_nonidemdonehits; 655*c057a378SRick Macklem nfsstatsov1.srvcache_misses = 656*c057a378SRick Macklem nfsstatsv1.srvcache_misses; 657*c057a378SRick Macklem nfsstatsov1.srvcache_tcppeak = 658*c057a378SRick Macklem nfsstatsv1.srvcache_tcppeak; 659*c057a378SRick Macklem nfsstatsov1.srvcache_size = 660*c057a378SRick Macklem nfsstatsv1.srvcache_size; 661*c057a378SRick Macklem nfsstatsov1.srvclients = 662*c057a378SRick Macklem nfsstatsv1.srvclients; 663*c057a378SRick Macklem nfsstatsov1.srvopenowners = 664*c057a378SRick Macklem nfsstatsv1.srvopenowners; 665*c057a378SRick Macklem nfsstatsov1.srvopens = 666*c057a378SRick Macklem nfsstatsv1.srvopens; 667*c057a378SRick Macklem nfsstatsov1.srvlockowners = 668*c057a378SRick Macklem nfsstatsv1.srvlockowners; 669*c057a378SRick Macklem nfsstatsov1.srvlocks = 670*c057a378SRick Macklem nfsstatsv1.srvlocks; 671*c057a378SRick Macklem nfsstatsov1.srvdelegates = 672*c057a378SRick Macklem nfsstatsv1.srvdelegates; 673*c057a378SRick Macklem for (i = 0; i < NFSV42_CBNOPS; i++) 674*c057a378SRick Macklem nfsstatsov1.cbrpccnt[i] = 675*c057a378SRick Macklem nfsstatsv1.cbrpccnt[i]; 676*c057a378SRick Macklem nfsstatsov1.clopenowners = 677*c057a378SRick Macklem nfsstatsv1.clopenowners; 678*c057a378SRick Macklem nfsstatsov1.clopens = 679*c057a378SRick Macklem nfsstatsv1.clopens; 680*c057a378SRick Macklem nfsstatsov1.cllockowners = 681*c057a378SRick Macklem nfsstatsv1.cllockowners; 682*c057a378SRick Macklem nfsstatsov1.cllocks = 683*c057a378SRick Macklem nfsstatsv1.cllocks; 684*c057a378SRick Macklem nfsstatsov1.cldelegates = 685*c057a378SRick Macklem nfsstatsv1.cldelegates; 686*c057a378SRick Macklem nfsstatsov1.cllocalopenowners = 687*c057a378SRick Macklem nfsstatsv1.cllocalopenowners; 688*c057a378SRick Macklem nfsstatsov1.cllocalopens = 689*c057a378SRick Macklem nfsstatsv1.cllocalopens; 690*c057a378SRick Macklem nfsstatsov1.cllocallockowners = 691*c057a378SRick Macklem nfsstatsv1.cllocallockowners; 692*c057a378SRick Macklem nfsstatsov1.cllocallocks = 693*c057a378SRick Macklem nfsstatsv1.cllocallocks; 694*c057a378SRick Macklem nfsstatsov1.srvstartcnt = 695*c057a378SRick Macklem nfsstatsv1.srvstartcnt; 696*c057a378SRick Macklem nfsstatsov1.srvdonecnt = 697*c057a378SRick Macklem nfsstatsv1.srvdonecnt; 698*c057a378SRick Macklem for (i = NFSV42_NOPS, 699*c057a378SRick Macklem j = NFSV42_PURENOPS; 700*c057a378SRick Macklem i < NFSV42_NOPS + NFSV4OP_FAKENOPS; 701*c057a378SRick Macklem i++, j++) { 702*c057a378SRick Macklem nfsstatsov1.srvbytes[j] = 703*c057a378SRick Macklem nfsstatsv1.srvbytes[i]; 704*c057a378SRick Macklem nfsstatsov1.srvops[j] = 705*c057a378SRick Macklem nfsstatsv1.srvops[i]; 706*c057a378SRick Macklem nfsstatsov1.srvduration[j] = 707*c057a378SRick Macklem nfsstatsv1.srvduration[i]; 708*c057a378SRick Macklem } 709*c057a378SRick Macklem nfsstatsov1.busyfrom = 710*c057a378SRick Macklem nfsstatsv1.busyfrom; 711*c057a378SRick Macklem nfsstatsov1.busyfrom = 712*c057a378SRick Macklem nfsstatsv1.busyfrom; 713*c057a378SRick Macklem error = copyout(&nfsstatsov1, uap->argp, 714*c057a378SRick Macklem sizeof(nfsstatsov1)); 715*c057a378SRick Macklem } else if (nfsstatver.vers != NFSSTATS_V1) 7161b819cf2SRick Macklem error = EPERM; 717*c057a378SRick Macklem else 7181b819cf2SRick Macklem error = copyout(&nfsstatsv1, uap->argp, 7191b819cf2SRick Macklem sizeof(nfsstatsv1)); 7201b819cf2SRick Macklem } 721*c057a378SRick Macklem } 7222e3b981aSRick Macklem if (error == 0) { 7232e3b981aSRick Macklem if ((uap->flag & NFSSVC_ZEROCLTSTATS) != 0) { 7241b819cf2SRick Macklem nfsstatsv1.attrcache_hits = 0; 7251b819cf2SRick Macklem nfsstatsv1.attrcache_misses = 0; 7261b819cf2SRick Macklem nfsstatsv1.lookupcache_hits = 0; 7271b819cf2SRick Macklem nfsstatsv1.lookupcache_misses = 0; 7281b819cf2SRick Macklem nfsstatsv1.direofcache_hits = 0; 7291b819cf2SRick Macklem nfsstatsv1.direofcache_misses = 0; 7301b819cf2SRick Macklem nfsstatsv1.accesscache_hits = 0; 7311b819cf2SRick Macklem nfsstatsv1.accesscache_misses = 0; 7321b819cf2SRick Macklem nfsstatsv1.biocache_reads = 0; 7331b819cf2SRick Macklem nfsstatsv1.read_bios = 0; 7341b819cf2SRick Macklem nfsstatsv1.read_physios = 0; 7351b819cf2SRick Macklem nfsstatsv1.biocache_writes = 0; 7361b819cf2SRick Macklem nfsstatsv1.write_bios = 0; 7371b819cf2SRick Macklem nfsstatsv1.write_physios = 0; 7381b819cf2SRick Macklem nfsstatsv1.biocache_readlinks = 0; 7391b819cf2SRick Macklem nfsstatsv1.readlink_bios = 0; 7401b819cf2SRick Macklem nfsstatsv1.biocache_readdirs = 0; 7411b819cf2SRick Macklem nfsstatsv1.readdir_bios = 0; 7421b819cf2SRick Macklem nfsstatsv1.rpcretries = 0; 7431b819cf2SRick Macklem nfsstatsv1.rpcrequests = 0; 7441b819cf2SRick Macklem nfsstatsv1.rpctimeouts = 0; 7451b819cf2SRick Macklem nfsstatsv1.rpcunexpected = 0; 7461b819cf2SRick Macklem nfsstatsv1.rpcinvalid = 0; 7471b819cf2SRick Macklem bzero(nfsstatsv1.rpccnt, 7481b819cf2SRick Macklem sizeof(nfsstatsv1.rpccnt)); 7492e3b981aSRick Macklem } 7502e3b981aSRick Macklem if ((uap->flag & NFSSVC_ZEROSRVSTATS) != 0) { 7511b819cf2SRick Macklem nfsstatsv1.srvrpc_errs = 0; 7521b819cf2SRick Macklem nfsstatsv1.srv_errs = 0; 7531b819cf2SRick Macklem nfsstatsv1.srvcache_inproghits = 0; 7541b819cf2SRick Macklem nfsstatsv1.srvcache_idemdonehits = 0; 7551b819cf2SRick Macklem nfsstatsv1.srvcache_nonidemdonehits = 0; 7561b819cf2SRick Macklem nfsstatsv1.srvcache_misses = 0; 7571b819cf2SRick Macklem nfsstatsv1.srvcache_tcppeak = 0; 7581b819cf2SRick Macklem bzero(nfsstatsv1.srvrpccnt, 7591b819cf2SRick Macklem sizeof(nfsstatsv1.srvrpccnt)); 7601b819cf2SRick Macklem bzero(nfsstatsv1.cbrpccnt, 7611b819cf2SRick Macklem sizeof(nfsstatsv1.cbrpccnt)); 7622e3b981aSRick Macklem } 7632e3b981aSRick Macklem } 764a9285ae5SZack Kirsch goto out; 7659ec7b004SRick Macklem } else if (uap->flag & NFSSVC_NFSUSERDPORT) { 7669ec7b004SRick Macklem u_short sockport; 76780405bcfSRick Macklem struct nfsuserd_args nargs; 7689ec7b004SRick Macklem 76980405bcfSRick Macklem if ((uap->flag & NFSSVC_NEWSTRUCT) == 0) { 7709ec7b004SRick Macklem error = copyin(uap->argp, (caddr_t)&sockport, 7719ec7b004SRick Macklem sizeof (u_short)); 77280405bcfSRick Macklem if (error == 0) { 77380405bcfSRick Macklem nargs.nuserd_family = AF_INET; 77480405bcfSRick Macklem nargs.nuserd_port = sockport; 77580405bcfSRick Macklem } 77680405bcfSRick Macklem } else { 77780405bcfSRick Macklem /* 77880405bcfSRick Macklem * New nfsuserd_args structure, which indicates 77980405bcfSRick Macklem * which IP version to use along with the port#. 78080405bcfSRick Macklem */ 78180405bcfSRick Macklem error = copyin(uap->argp, &nargs, sizeof(nargs)); 78280405bcfSRick Macklem } 78302c8dd7dSRick Macklem if (!error) 78480405bcfSRick Macklem error = nfsrv_nfsuserdport(&nargs, p); 7859ec7b004SRick Macklem } else if (uap->flag & NFSSVC_NFSUSERDDELPORT) { 7869ec7b004SRick Macklem nfsrv_nfsuserddelport(); 7879ec7b004SRick Macklem error = 0; 7889ec7b004SRick Macklem } 789a9285ae5SZack Kirsch 790a9285ae5SZack Kirsch out: 791a9285ae5SZack Kirsch NFSEXITCODE(error); 7929ec7b004SRick Macklem return (error); 7939ec7b004SRick Macklem } 7949ec7b004SRick Macklem 7959ec7b004SRick Macklem /* 7969ec7b004SRick Macklem * called by all three modevent routines, so that it gets things 7979ec7b004SRick Macklem * initialized soon enough. 7989ec7b004SRick Macklem */ 7999ec7b004SRick Macklem void 8009ec7b004SRick Macklem newnfs_portinit(void) 8019ec7b004SRick Macklem { 8029ec7b004SRick Macklem static int inited = 0; 8039ec7b004SRick Macklem 8049ec7b004SRick Macklem if (inited) 8059ec7b004SRick Macklem return; 8069ec7b004SRick Macklem inited = 1; 8079ec7b004SRick Macklem /* Initialize SMP locks used by both client and server. */ 8089ec7b004SRick Macklem mtx_init(&newnfsd_mtx, "newnfsd_mtx", NULL, MTX_DEF); 8099ec7b004SRick Macklem mtx_init(&nfs_state_mutex, "nfs_state_mutex", NULL, MTX_DEF); 810b2fc0141SRick Macklem mtx_init(&nfs_clstate_mutex, "nfs_clstate_mutex", NULL, MTX_DEF); 8119ec7b004SRick Macklem } 8129ec7b004SRick Macklem 813ee1c1433SRick Macklem /* 814ee1c1433SRick Macklem * Determine if the file system supports NFSv4 ACLs. 815ee1c1433SRick Macklem * Return 1 if it does, 0 otherwise. 816ee1c1433SRick Macklem */ 817ee1c1433SRick Macklem int 818a09001a8SRick Macklem nfs_supportsnfsv4acls(struct vnode *vp) 819ee1c1433SRick Macklem { 820a09001a8SRick Macklem int error; 821b1288166SJohn Baldwin long retval; 822ee1c1433SRick Macklem 823a09001a8SRick Macklem ASSERT_VOP_LOCKED(vp, "nfs supports nfsv4acls"); 824a09001a8SRick Macklem 825a09001a8SRick Macklem if (nfsrv_useacl == 0) 826ee1c1433SRick Macklem return (0); 827061c683cSZack Kirsch error = VOP_PATHCONF(vp, _PC_ACL_NFS4, &retval); 828a09001a8SRick Macklem if (error == 0 && retval != 0) 829ee1c1433SRick Macklem return (1); 830ee1c1433SRick Macklem return (0); 831ee1c1433SRick Macklem } 832ee1c1433SRick Macklem 833f49c813cSRick Macklem /* 834f49c813cSRick Macklem * These are the first fields of all the context structures passed into 835f49c813cSRick Macklem * nfs_pnfsio(). 836f49c813cSRick Macklem */ 837f49c813cSRick Macklem struct pnfsio { 838f49c813cSRick Macklem int done; 839f49c813cSRick Macklem int inprog; 840f49c813cSRick Macklem struct task tsk; 841f49c813cSRick Macklem }; 842f49c813cSRick Macklem 843f49c813cSRick Macklem /* 844f49c813cSRick Macklem * Do a mirror I/O on a pNFS thread. 845f49c813cSRick Macklem */ 846f49c813cSRick Macklem int 847f49c813cSRick Macklem nfs_pnfsio(task_fn_t *func, void *context) 848f49c813cSRick Macklem { 849f49c813cSRick Macklem struct pnfsio *pio; 850f49c813cSRick Macklem int ret; 851f49c813cSRick Macklem static struct taskqueue *pnfsioq = NULL; 852f49c813cSRick Macklem 853f49c813cSRick Macklem pio = (struct pnfsio *)context; 854f49c813cSRick Macklem if (pnfsioq == NULL) { 855f49c813cSRick Macklem if (nfs_pnfsiothreads == 0) 856dec8894bSRick Macklem return (EPERM); 857dec8894bSRick Macklem if (nfs_pnfsiothreads < 0) 858f49c813cSRick Macklem nfs_pnfsiothreads = mp_ncpus * 4; 859f49c813cSRick Macklem pnfsioq = taskqueue_create("pnfsioq", M_WAITOK, 860f49c813cSRick Macklem taskqueue_thread_enqueue, &pnfsioq); 861f49c813cSRick Macklem if (pnfsioq == NULL) 862f49c813cSRick Macklem return (ENOMEM); 863f49c813cSRick Macklem ret = taskqueue_start_threads(&pnfsioq, nfs_pnfsiothreads, 864f49c813cSRick Macklem 0, "pnfsiot"); 865f49c813cSRick Macklem if (ret != 0) { 866f49c813cSRick Macklem taskqueue_free(pnfsioq); 867f49c813cSRick Macklem pnfsioq = NULL; 868f49c813cSRick Macklem return (ret); 869f49c813cSRick Macklem } 870f49c813cSRick Macklem } 871f49c813cSRick Macklem pio->inprog = 1; 872f49c813cSRick Macklem TASK_INIT(&pio->tsk, 0, func, context); 873f49c813cSRick Macklem ret = taskqueue_enqueue(pnfsioq, &pio->tsk); 874f49c813cSRick Macklem if (ret != 0) 875f49c813cSRick Macklem pio->inprog = 0; 876f49c813cSRick Macklem return (ret); 877f49c813cSRick Macklem } 878f49c813cSRick Macklem 8799ec7b004SRick Macklem extern int (*nfsd_call_nfscommon)(struct thread *, struct nfssvc_args *); 8809ec7b004SRick Macklem 8819ec7b004SRick Macklem /* 8829ec7b004SRick Macklem * Called once to initialize data structures... 8839ec7b004SRick Macklem */ 8849ec7b004SRick Macklem static int 8859ec7b004SRick Macklem nfscommon_modevent(module_t mod, int type, void *data) 8869ec7b004SRick Macklem { 8879ec7b004SRick Macklem int error = 0; 8889ec7b004SRick Macklem static int loaded = 0; 8899ec7b004SRick Macklem 8909ec7b004SRick Macklem switch (type) { 8919ec7b004SRick Macklem case MOD_LOAD: 8929ec7b004SRick Macklem if (loaded) 893a9285ae5SZack Kirsch goto out; 8949ec7b004SRick Macklem newnfs_portinit(); 8959ec7b004SRick Macklem mtx_init(&nfs_nameid_mutex, "nfs_nameid_mutex", NULL, MTX_DEF); 8969ec7b004SRick Macklem mtx_init(&nfs_sockl_mutex, "nfs_sockl_mutex", NULL, MTX_DEF); 8979ec7b004SRick Macklem mtx_init(&nfs_slock_mutex, "nfs_slock_mutex", NULL, MTX_DEF); 8989ec7b004SRick Macklem mtx_init(&nfs_req_mutex, "nfs_req_mutex", NULL, MTX_DEF); 8999ec7b004SRick Macklem mtx_init(&nfsrv_nfsuserdsock.nr_mtx, "nfsuserd", NULL, 9009ec7b004SRick Macklem MTX_DEF); 90190d2dfabSRick Macklem mtx_init(&nfsrv_dslock_mtx, "nfs4ds", NULL, MTX_DEF); 90290d2dfabSRick Macklem TAILQ_INIT(&nfsrv_devidhead); 903fd90e2edSJung-uk Kim callout_init(&newnfsd_callout, 1); 9049ec7b004SRick Macklem newnfs_init(); 9059ec7b004SRick Macklem nfsd_call_nfscommon = nfssvc_nfscommon; 9069ec7b004SRick Macklem loaded = 1; 9079ec7b004SRick Macklem break; 9089ec7b004SRick Macklem 9099ec7b004SRick Macklem case MOD_UNLOAD: 910e1cda5eeSRick Macklem if (newnfs_numnfsd != 0 || nfsrv_nfsuserd != NOTRUNNING || 9119ec7b004SRick Macklem nfs_numnfscbd != 0) { 9129ec7b004SRick Macklem error = EBUSY; 9139ec7b004SRick Macklem break; 9149ec7b004SRick Macklem } 9159ec7b004SRick Macklem 9169ec7b004SRick Macklem nfsd_call_nfscommon = NULL; 9179ec7b004SRick Macklem callout_drain(&newnfsd_callout); 91865171ebbSRick Macklem /* Clean out the name<-->id cache. */ 91965171ebbSRick Macklem nfsrv_cleanusergroup(); 9209ec7b004SRick Macklem /* and get rid of the mutexes */ 9219ec7b004SRick Macklem mtx_destroy(&nfs_nameid_mutex); 9229ec7b004SRick Macklem mtx_destroy(&newnfsd_mtx); 9239ec7b004SRick Macklem mtx_destroy(&nfs_state_mutex); 924b2fc0141SRick Macklem mtx_destroy(&nfs_clstate_mutex); 9259ec7b004SRick Macklem mtx_destroy(&nfs_sockl_mutex); 9269ec7b004SRick Macklem mtx_destroy(&nfs_slock_mutex); 9279ec7b004SRick Macklem mtx_destroy(&nfs_req_mutex); 9289ec7b004SRick Macklem mtx_destroy(&nfsrv_nfsuserdsock.nr_mtx); 92990d2dfabSRick Macklem mtx_destroy(&nfsrv_dslock_mtx); 9309ec7b004SRick Macklem loaded = 0; 9319ec7b004SRick Macklem break; 9329ec7b004SRick Macklem default: 9339ec7b004SRick Macklem error = EOPNOTSUPP; 9349ec7b004SRick Macklem break; 9359ec7b004SRick Macklem } 936a9285ae5SZack Kirsch 937a9285ae5SZack Kirsch out: 938a9285ae5SZack Kirsch NFSEXITCODE(error); 9399ec7b004SRick Macklem return error; 9409ec7b004SRick Macklem } 9419ec7b004SRick Macklem static moduledata_t nfscommon_mod = { 9429ec7b004SRick Macklem "nfscommon", 9439ec7b004SRick Macklem nfscommon_modevent, 9449ec7b004SRick Macklem NULL, 9459ec7b004SRick Macklem }; 9469ec7b004SRick Macklem DECLARE_MODULE(nfscommon, nfscommon_mod, SI_SUB_VFS, SI_ORDER_ANY); 9479ec7b004SRick Macklem 9489ec7b004SRick Macklem /* So that loader and kldload(2) can find us, wherever we are.. */ 9499ec7b004SRick Macklem MODULE_VERSION(nfscommon, 1); 9509ec7b004SRick Macklem MODULE_DEPEND(nfscommon, nfssvc, 1, 1, 1); 9519ec7b004SRick Macklem MODULE_DEPEND(nfscommon, krpc, 1, 1, 1); 9529ec7b004SRick Macklem 953