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]; 7084be7e09SRick Macklem int nfsrv_lughashsize = 100; 7190d2dfabSRick Macklem struct mtx nfsrv_dslock_mtx; 7290d2dfabSRick Macklem struct nfsdevicehead nfsrv_devidhead; 7390d2dfabSRick Macklem volatile int nfsrv_devidcnt = 0; 749ec7b004SRick Macklem void (*ncl_call_invalcaches)(struct vnode *) = NULL; 758de97f39SRick Macklem vop_advlock_t *nfs_advlock_p = NULL; 768de97f39SRick Macklem vop_reclaim_t *nfs_reclaim_p = NULL; 77ee29e6f3SRick Macklem uint32_t nfs_srvmaxio = NFS_SRVMAXIO; 789ec7b004SRick Macklem 79f49c813cSRick Macklem int nfs_pnfsio(task_fn_t *, void *); 80f49c813cSRick Macklem 819ec7b004SRick Macklem static int nfs_realign_test; 829ec7b004SRick Macklem static int nfs_realign_count; 831b819cf2SRick Macklem static struct ext_nfsstats oldnfsstats; 84c057a378SRick Macklem static struct nfsstatsov1 nfsstatsov1; 859ec7b004SRick Macklem 867029da5cSPawel Biernacki SYSCTL_NODE(_vfs, OID_AUTO, nfs, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 877029da5cSPawel Biernacki "NFS filesystem"); 881f376590SRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_test, CTLFLAG_RW, &nfs_realign_test, 890a9f005dSRick Macklem 0, "Number of realign tests done"); 901f376590SRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_count, CTLFLAG_RW, &nfs_realign_count, 910a9f005dSRick Macklem 0, "Number of mbuf realignments done"); 921f376590SRick Macklem SYSCTL_STRING(_vfs_nfs, OID_AUTO, callback_addr, CTLFLAG_RW, 930a9f005dSRick Macklem nfsv4_callbackaddr, sizeof(nfsv4_callbackaddr), 940a9f005dSRick Macklem "NFSv4 callback addr for server to use"); 95f4e2c07eSRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, debuglevel, CTLFLAG_RW, &nfscl_debuglevel, 9650a220c6SEdward Tomasz Napierala 0, "Debug level for NFS client"); 9784be7e09SRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, userhashsize, CTLFLAG_RDTUN, &nfsrv_lughashsize, 9884be7e09SRick Macklem 0, "Size of hash tables for uid/name mapping"); 99dec8894bSRick Macklem int nfs_pnfsiothreads = -1; 100f49c813cSRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, pnfsiothreads, CTLFLAG_RW, &nfs_pnfsiothreads, 101f49c813cSRick Macklem 0, "Number of pNFS mirror I/O threads"); 1029ec7b004SRick Macklem 1039ec7b004SRick Macklem /* 1049ec7b004SRick Macklem * Defines for malloc 1059ec7b004SRick Macklem * (Here for FreeBSD, since they allocate storage.) 1069ec7b004SRick Macklem */ 1079ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSRVCACHE, "NFSD srvcache", "NFSD Server Request Cache"); 1089ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSDCLIENT, "NFSD V4client", "NFSD V4 Client Id"); 109a43fcbe3SRick Macklem MALLOC_DEFINE(M_NEWNFSDSTATE, "NFSD V4state", 110a43fcbe3SRick Macklem "NFSD V4 State (Openowner, Open, Lockowner, Delegation"); 1119ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSDLOCK, "NFSD V4lock", "NFSD V4 byte range lock"); 1129ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSDLOCKFILE, "NFSD lckfile", "NFSD Open/Lock file"); 1139ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSSTRING, "NFSD string", "NFSD V4 long string"); 1149ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSUSERGROUP, "NFSD usrgroup", "NFSD V4 User/group map"); 1159ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSDREQ, "NFS req", "NFS request header"); 1169ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSFH, "NFS fh", "NFS file handle"); 1179ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLOWNER, "NFSCL owner", "NFSCL Open Owner"); 1189ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLOPEN, "NFSCL open", "NFSCL Open"); 1199ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLDELEG, "NFSCL deleg", "NFSCL Delegation"); 1209ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLCLIENT, "NFSCL client", "NFSCL Client"); 1219ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLLOCKOWNER, "NFSCL lckown", "NFSCL Lock Owner"); 1229ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLLOCK, "NFSCL lck", "NFSCL Lock"); 12350a220c6SEdward Tomasz Napierala MALLOC_DEFINE(M_NEWNFSV4NODE, "NEWNFSnode", "NFS vnode"); 12450a220c6SEdward Tomasz Napierala MALLOC_DEFINE(M_NEWNFSDIRECTIO, "NEWdirectio", "NFS Direct IO buffer"); 125d0103273SAlexander Motin MALLOC_DEFINE(M_NEWNFSDIROFF, "NFSCL diroff", 12650a220c6SEdward Tomasz Napierala "NFS directory offset data"); 127a43fcbe3SRick Macklem MALLOC_DEFINE(M_NEWNFSDROLLBACK, "NFSD rollback", 12850a220c6SEdward Tomasz Napierala "NFS local lock rollback"); 1291f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSLAYOUT, "NFSCL layout", "NFSv4.1 Layout"); 1301f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSFLAYOUT, "NFSCL flayout", "NFSv4.1 File Layout"); 1311f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSDEVINFO, "NFSCL devinfo", "NFSv4.1 Device Info"); 1321f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSSOCKREQ, "NFSCL sockreq", "NFS Sock Req"); 1331f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSCLDS, "NFSCL session", "NFSv4.1 Session"); 1341f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSLAYRECALL, "NFSCL layrecall", "NFSv4.1 Layout Recall"); 135c59e4cc3SRick Macklem MALLOC_DEFINE(M_NEWNFSDSESSION, "NFSD session", "NFSD Session for a client"); 1369ec7b004SRick Macklem 1379ec7b004SRick Macklem /* 1389ec7b004SRick Macklem * Definition of mutex locks. 1399ec7b004SRick Macklem * newnfsd_mtx is used in nfsrvd_nfsd() to protect the nfs socket list 1409ec7b004SRick Macklem * and assorted other nfsd structures. 1419ec7b004SRick Macklem */ 1429ec7b004SRick Macklem struct mtx newnfsd_mtx; 1439ec7b004SRick Macklem struct mtx nfs_sockl_mutex; 1449ec7b004SRick Macklem struct mtx nfs_state_mutex; 1459ec7b004SRick Macklem struct mtx nfs_nameid_mutex; 1469ec7b004SRick Macklem struct mtx nfs_req_mutex; 1479ec7b004SRick Macklem struct mtx nfs_slock_mutex; 148b2fc0141SRick Macklem struct mtx nfs_clstate_mutex; 1499ec7b004SRick Macklem 1509ec7b004SRick Macklem /* local functions */ 1519ec7b004SRick Macklem static int nfssvc_call(struct thread *, struct nfssvc_args *, struct ucred *); 1529ec7b004SRick Macklem 1533dfe81c6SRick Macklem #ifdef __NO_STRICT_ALIGNMENT 1549ec7b004SRick Macklem /* 1559ec7b004SRick Macklem * These architectures don't need re-alignment, so just return. 1569ec7b004SRick Macklem */ 157d96b98a3SKenneth D. Merry int 158d96b98a3SKenneth D. Merry newnfs_realign(struct mbuf **pm, int how) 1599ec7b004SRick Macklem { 1609ec7b004SRick Macklem 161d96b98a3SKenneth D. Merry return (0); 1629ec7b004SRick Macklem } 1633dfe81c6SRick Macklem #else /* !__NO_STRICT_ALIGNMENT */ 1649ec7b004SRick Macklem /* 16505c965a2SRick Macklem * newnfs_realign: 1669ec7b004SRick Macklem * 1679ec7b004SRick Macklem * Check for badly aligned mbuf data and realign by copying the unaligned 1689ec7b004SRick Macklem * portion of the data into a new mbuf chain and freeing the portions 1699ec7b004SRick Macklem * of the old chain that were replaced. 1709ec7b004SRick Macklem * 1719ec7b004SRick Macklem * We cannot simply realign the data within the existing mbuf chain 1729ec7b004SRick Macklem * because the underlying buffers may contain other rpc commands and 1739ec7b004SRick Macklem * we cannot afford to overwrite them. 1749ec7b004SRick Macklem * 1759ec7b004SRick Macklem * We would prefer to avoid this situation entirely. The situation does 176a96c9b30SPedro F. Giffuni * not occur with NFS/UDP and is supposed to only occasionally occur 1779ec7b004SRick Macklem * with TCP. Use vfs.nfs.realign_count and realign_test to check this. 17805c965a2SRick Macklem * 1799ec7b004SRick Macklem */ 180d96b98a3SKenneth D. Merry int 181d96b98a3SKenneth D. Merry newnfs_realign(struct mbuf **pm, int how) 1829ec7b004SRick Macklem { 18305c965a2SRick Macklem struct mbuf *m, *n; 18405c965a2SRick Macklem int off, space; 1859ec7b004SRick Macklem 1869ec7b004SRick Macklem ++nfs_realign_test; 1879ec7b004SRick Macklem while ((m = *pm) != NULL) { 1889ec7b004SRick Macklem if ((m->m_len & 0x3) || (mtod(m, intptr_t) & 0x3)) { 1899ec7b004SRick Macklem /* 19005c965a2SRick Macklem * NB: we can't depend on m_pkthdr.len to help us 19105c965a2SRick Macklem * decide what to do here. May not be worth doing 19205c965a2SRick Macklem * the m_length calculation as m_copyback will 19305c965a2SRick Macklem * expand the mbuf chain below as needed. 1949ec7b004SRick Macklem */ 19505c965a2SRick Macklem space = m_length(m, NULL); 19605c965a2SRick Macklem if (space >= MINCLSIZE) { 19705c965a2SRick Macklem /* NB: m_copyback handles space > MCLBYTES */ 198d96b98a3SKenneth D. Merry n = m_getcl(how, MT_DATA, 0); 19905c965a2SRick Macklem } else 200d96b98a3SKenneth D. Merry n = m_get(how, MT_DATA); 20105c965a2SRick Macklem if (n == NULL) 202d96b98a3SKenneth D. Merry return (ENOMEM); 20305c965a2SRick Macklem /* 20405c965a2SRick Macklem * Align the remainder of the mbuf chain. 20505c965a2SRick Macklem */ 20605c965a2SRick Macklem n->m_len = 0; 20705c965a2SRick Macklem off = 0; 20805c965a2SRick Macklem while (m != NULL) { 2099ec7b004SRick Macklem m_copyback(n, off, m->m_len, mtod(m, caddr_t)); 2109ec7b004SRick Macklem off += m->m_len; 2119ec7b004SRick Macklem m = m->m_next; 2129ec7b004SRick Macklem } 2139ec7b004SRick Macklem m_freem(*pm); 2149ec7b004SRick Macklem *pm = n; 21505c965a2SRick Macklem ++nfs_realign_count; 21605c965a2SRick Macklem break; 21705c965a2SRick Macklem } 21805c965a2SRick Macklem pm = &m->m_next; 2199ec7b004SRick Macklem } 220d96b98a3SKenneth D. Merry 221d96b98a3SKenneth D. Merry return (0); 2229ec7b004SRick Macklem } 2233dfe81c6SRick Macklem #endif /* __NO_STRICT_ALIGNMENT */ 2249ec7b004SRick Macklem 2259ec7b004SRick Macklem #ifdef notdef 2269ec7b004SRick Macklem static void 2279ec7b004SRick Macklem nfsrv_object_create(struct vnode *vp, struct thread *td) 2289ec7b004SRick Macklem { 2299ec7b004SRick Macklem 2309ec7b004SRick Macklem if (vp == NULL || vp->v_type != VREG) 2319ec7b004SRick Macklem return; 2329ec7b004SRick Macklem (void) vfs_object_create(vp, td, td->td_ucred); 2339ec7b004SRick Macklem } 2349ec7b004SRick Macklem #endif 2359ec7b004SRick Macklem 2369ec7b004SRick Macklem /* 2379ec7b004SRick Macklem * Look up a file name. Basically just initialize stuff and call namei(). 2389ec7b004SRick Macklem */ 2399ec7b004SRick Macklem int 2407e1d3eefSMateusz Guzik nfsrv_lookupfilename(struct nameidata *ndp, char *fname, NFSPROC_T *p __unused) 2419ec7b004SRick Macklem { 2429ec7b004SRick Macklem int error; 2439ec7b004SRick Macklem 2447e1d3eefSMateusz Guzik NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, fname); 2459ec7b004SRick Macklem error = namei(ndp); 2469ec7b004SRick Macklem if (!error) { 247*bb92cd7bSMateusz Guzik NDFREE_PNBUF(ndp); 2489ec7b004SRick Macklem } 2499ec7b004SRick Macklem return (error); 2509ec7b004SRick Macklem } 2519ec7b004SRick Macklem 2529ec7b004SRick Macklem /* 2539ec7b004SRick Macklem * Copy NFS uid, gids to the cred structure. 2549ec7b004SRick Macklem */ 2559ec7b004SRick Macklem void 2569ec7b004SRick Macklem newnfs_copycred(struct nfscred *nfscr, struct ucred *cr) 2579ec7b004SRick Macklem { 2589ec7b004SRick Macklem 25955909abfSRick Macklem KASSERT(nfscr->nfsc_ngroups >= 0, 26055909abfSRick Macklem ("newnfs_copycred: negative nfsc_ngroups")); 2619ec7b004SRick Macklem cr->cr_uid = nfscr->nfsc_uid; 262838d9858SBrooks Davis crsetgroups(cr, nfscr->nfsc_ngroups, nfscr->nfsc_groups); 2639ec7b004SRick Macklem } 2649ec7b004SRick Macklem 2659ec7b004SRick Macklem /* 2669ec7b004SRick Macklem * Map args from nfsmsleep() to msleep(). 2679ec7b004SRick Macklem */ 2689ec7b004SRick Macklem int 2699ec7b004SRick Macklem nfsmsleep(void *chan, void *mutex, int prio, const char *wmesg, 2709ec7b004SRick Macklem struct timespec *ts) 2719ec7b004SRick Macklem { 2729ec7b004SRick Macklem u_int64_t nsecval; 2739ec7b004SRick Macklem int error, timeo; 2749ec7b004SRick Macklem 2759ec7b004SRick Macklem if (ts) { 2769ec7b004SRick Macklem timeo = hz * ts->tv_sec; 2779ec7b004SRick Macklem nsecval = (u_int64_t)ts->tv_nsec; 2789ec7b004SRick Macklem nsecval = ((nsecval * ((u_int64_t)hz)) + 500000000) / 2799ec7b004SRick Macklem 1000000000; 2809ec7b004SRick Macklem timeo += (int)nsecval; 2819ec7b004SRick Macklem } else { 2829ec7b004SRick Macklem timeo = 0; 2839ec7b004SRick Macklem } 2849ec7b004SRick Macklem error = msleep(chan, (struct mtx *)mutex, prio, wmesg, timeo); 2859ec7b004SRick Macklem return (error); 2869ec7b004SRick Macklem } 2879ec7b004SRick Macklem 2889ec7b004SRick Macklem /* 2899ec7b004SRick Macklem * Get the file system info for the server. For now, just assume FFS. 2909ec7b004SRick Macklem */ 2919ec7b004SRick Macklem void 2929ec7b004SRick Macklem nfsvno_getfs(struct nfsfsinfo *sip, int isdgram) 2939ec7b004SRick Macklem { 2949ec7b004SRick Macklem int pref; 2959ec7b004SRick Macklem 2969ec7b004SRick Macklem /* 2979ec7b004SRick Macklem * XXX 2989ec7b004SRick Macklem * There should be file system VFS OP(s) to get this information. 2999ec7b004SRick Macklem * For now, assume ufs. 3009ec7b004SRick Macklem */ 3019ec7b004SRick Macklem if (isdgram) 3029ec7b004SRick Macklem pref = NFS_MAXDGRAMDATA; 3039ec7b004SRick Macklem else 304ee29e6f3SRick Macklem pref = nfs_srvmaxio; 305ee29e6f3SRick Macklem sip->fs_rtmax = nfs_srvmaxio; 3069ec7b004SRick Macklem sip->fs_rtpref = pref; 3079ec7b004SRick Macklem sip->fs_rtmult = NFS_FABLKSIZE; 308ee29e6f3SRick Macklem sip->fs_wtmax = nfs_srvmaxio; 3099ec7b004SRick Macklem sip->fs_wtpref = pref; 3109ec7b004SRick Macklem sip->fs_wtmult = NFS_FABLKSIZE; 3119ec7b004SRick Macklem sip->fs_dtpref = pref; 3129ec7b004SRick Macklem sip->fs_maxfilesize = 0xffffffffffffffffull; 3139ec7b004SRick Macklem sip->fs_timedelta.tv_sec = 0; 3149ec7b004SRick Macklem sip->fs_timedelta.tv_nsec = 1; 3159ec7b004SRick Macklem sip->fs_properties = (NFSV3FSINFO_LINK | 3169ec7b004SRick Macklem NFSV3FSINFO_SYMLINK | NFSV3FSINFO_HOMOGENEOUS | 3179ec7b004SRick Macklem NFSV3FSINFO_CANSETTIME); 3189ec7b004SRick Macklem } 3199ec7b004SRick Macklem 32040435b74SZack Kirsch /* 32140435b74SZack Kirsch * Do the pathconf vnode op. 32240435b74SZack Kirsch */ 32340435b74SZack Kirsch int 324b1288166SJohn Baldwin nfsvno_pathconf(struct vnode *vp, int flag, long *retf, 32540435b74SZack Kirsch struct ucred *cred, struct thread *p) 32640435b74SZack Kirsch { 32740435b74SZack Kirsch int error; 32840435b74SZack Kirsch 32940435b74SZack Kirsch error = VOP_PATHCONF(vp, flag, retf); 33040435b74SZack Kirsch if (error == EOPNOTSUPP || error == EINVAL) { 33140435b74SZack Kirsch /* 33240435b74SZack Kirsch * Some file systems return EINVAL for name arguments not 33340435b74SZack Kirsch * supported and some return EOPNOTSUPP for this case. 33440435b74SZack Kirsch * So the NFSv3 Pathconf RPC doesn't fail for these cases, 33540435b74SZack Kirsch * just fake them. 33640435b74SZack Kirsch */ 33740435b74SZack Kirsch switch (flag) { 33840435b74SZack Kirsch case _PC_LINK_MAX: 339a0a073b1SJohn Baldwin *retf = NFS_LINK_MAX; 34040435b74SZack Kirsch break; 34140435b74SZack Kirsch case _PC_NAME_MAX: 34240435b74SZack Kirsch *retf = NAME_MAX; 34340435b74SZack Kirsch break; 34440435b74SZack Kirsch case _PC_CHOWN_RESTRICTED: 34540435b74SZack Kirsch *retf = 1; 34640435b74SZack Kirsch break; 34740435b74SZack Kirsch case _PC_NO_TRUNC: 34840435b74SZack Kirsch *retf = 1; 34940435b74SZack Kirsch break; 35040435b74SZack Kirsch default: 35140435b74SZack Kirsch /* 35240435b74SZack Kirsch * Only happens if a _PC_xxx is added to the server, 35340435b74SZack Kirsch * but this isn't updated. 35440435b74SZack Kirsch */ 35540435b74SZack Kirsch *retf = 0; 35640435b74SZack Kirsch printf("nfsrvd pathconf flag=%d not supp\n", flag); 35774b8d63dSPedro F. Giffuni } 35840435b74SZack Kirsch error = 0; 35940435b74SZack Kirsch } 360a9285ae5SZack Kirsch NFSEXITCODE(error); 36140435b74SZack Kirsch return (error); 36240435b74SZack Kirsch } 36340435b74SZack Kirsch 3649ec7b004SRick Macklem /* Fake nfsrv_atroot. Just return 0 */ 3659ec7b004SRick Macklem int 36695ac7f1aSRick Macklem nfsrv_atroot(struct vnode *vp, uint64_t *retp) 3679ec7b004SRick Macklem { 3689ec7b004SRick Macklem 3699ec7b004SRick Macklem return (0); 3709ec7b004SRick Macklem } 3719ec7b004SRick Macklem 3729ec7b004SRick Macklem /* 3739ec7b004SRick Macklem * Set the credentials to refer to root. 3749ec7b004SRick Macklem * If only the various BSDen could agree on whether cr_gid is a separate 3759ec7b004SRick Macklem * field or cr_groups[0]... 3769ec7b004SRick Macklem */ 3779ec7b004SRick Macklem void 3789ec7b004SRick Macklem newnfs_setroot(struct ucred *cred) 3799ec7b004SRick Macklem { 3809ec7b004SRick Macklem 3819ec7b004SRick Macklem cred->cr_uid = 0; 3829ec7b004SRick Macklem cred->cr_groups[0] = 0; 3839ec7b004SRick Macklem cred->cr_ngroups = 1; 3849ec7b004SRick Macklem } 3859ec7b004SRick Macklem 3869ec7b004SRick Macklem /* 3879ec7b004SRick Macklem * Get the client credential. Used for Renew and recovery. 3889ec7b004SRick Macklem */ 3899ec7b004SRick Macklem struct ucred * 3909ec7b004SRick Macklem newnfs_getcred(void) 3919ec7b004SRick Macklem { 3929ec7b004SRick Macklem struct ucred *cred; 3939ec7b004SRick Macklem struct thread *td = curthread; 3949ec7b004SRick Macklem 3959ec7b004SRick Macklem cred = crdup(td->td_ucred); 3969ec7b004SRick Macklem newnfs_setroot(cred); 3979ec7b004SRick Macklem return (cred); 3989ec7b004SRick Macklem } 3999ec7b004SRick Macklem 4009ec7b004SRick Macklem /* 40123f929dfSRick Macklem * Sleep for a short period of time unless errval == NFSERR_GRACE, where 40223f929dfSRick Macklem * the sleep should be for 5 seconds. 4039ec7b004SRick Macklem * Since lbolt doesn't exist in FreeBSD-CURRENT, just use a timeout on 4049ec7b004SRick Macklem * an event that never gets a wakeup. Only return EINTR or 0. 4059ec7b004SRick Macklem */ 4069ec7b004SRick Macklem int 40723f929dfSRick Macklem nfs_catnap(int prio, int errval, const char *wmesg) 4089ec7b004SRick Macklem { 4099ec7b004SRick Macklem static int non_event; 4109ec7b004SRick Macklem int ret; 4119ec7b004SRick Macklem 41223f929dfSRick Macklem if (errval == NFSERR_GRACE) 41323f929dfSRick Macklem ret = tsleep(&non_event, prio, wmesg, 5 * hz); 41423f929dfSRick Macklem else 4159ec7b004SRick Macklem ret = tsleep(&non_event, prio, wmesg, 1); 4169ec7b004SRick Macklem if (ret != EINTR) 4179ec7b004SRick Macklem ret = 0; 4189ec7b004SRick Macklem return (ret); 4199ec7b004SRick Macklem } 4209ec7b004SRick Macklem 4219ec7b004SRick Macklem /* 4229ec7b004SRick Macklem * Get referral. For now, just fail. 4239ec7b004SRick Macklem */ 4249ec7b004SRick Macklem struct nfsreferral * 4259ec7b004SRick Macklem nfsv4root_getreferral(struct vnode *vp, struct vnode *dvp, u_int32_t fileno) 4269ec7b004SRick Macklem { 4279ec7b004SRick Macklem 4289ec7b004SRick Macklem return (NULL); 4299ec7b004SRick Macklem } 4309ec7b004SRick Macklem 4319ec7b004SRick Macklem static int 4329ec7b004SRick Macklem nfssvc_nfscommon(struct thread *td, struct nfssvc_args *uap) 4339ec7b004SRick Macklem { 4349ec7b004SRick Macklem int error; 4359ec7b004SRick Macklem 4369ec7b004SRick Macklem error = nfssvc_call(td, uap, td->td_ucred); 437a9285ae5SZack Kirsch NFSEXITCODE(error); 4389ec7b004SRick Macklem return (error); 4399ec7b004SRick Macklem } 4409ec7b004SRick Macklem 4419ec7b004SRick Macklem static int 4429ec7b004SRick Macklem nfssvc_call(struct thread *p, struct nfssvc_args *uap, struct ucred *cred) 4439ec7b004SRick Macklem { 4441b819cf2SRick Macklem int error = EINVAL, i, j; 4459ec7b004SRick Macklem struct nfsd_idargs nid; 44684be7e09SRick Macklem struct nfsd_oidargs onid; 4471b819cf2SRick Macklem struct { 4481b819cf2SRick Macklem int vers; /* Just the first field of nfsstats. */ 4491b819cf2SRick Macklem } nfsstatver; 4509ec7b004SRick Macklem 4519ec7b004SRick Macklem if (uap->flag & NFSSVC_IDNAME) { 45284be7e09SRick Macklem if ((uap->flag & NFSSVC_NEWSTRUCT) != 0) 45384be7e09SRick Macklem error = copyin(uap->argp, &nid, sizeof(nid)); 45484be7e09SRick Macklem else { 45584be7e09SRick Macklem error = copyin(uap->argp, &onid, sizeof(onid)); 45684be7e09SRick Macklem if (error == 0) { 45784be7e09SRick Macklem nid.nid_flag = onid.nid_flag; 45884be7e09SRick Macklem nid.nid_uid = onid.nid_uid; 45984be7e09SRick Macklem nid.nid_gid = onid.nid_gid; 46084be7e09SRick Macklem nid.nid_usermax = onid.nid_usermax; 46184be7e09SRick Macklem nid.nid_usertimeout = onid.nid_usertimeout; 46284be7e09SRick Macklem nid.nid_name = onid.nid_name; 46384be7e09SRick Macklem nid.nid_namelen = onid.nid_namelen; 46484be7e09SRick Macklem nid.nid_ngroup = 0; 46584be7e09SRick Macklem nid.nid_grps = NULL; 46684be7e09SRick Macklem } 46784be7e09SRick Macklem } 4689ec7b004SRick Macklem if (error) 469a9285ae5SZack Kirsch goto out; 4709ec7b004SRick Macklem error = nfssvc_idname(&nid); 471a9285ae5SZack Kirsch goto out; 4729ec7b004SRick Macklem } else if (uap->flag & NFSSVC_GETSTATS) { 4731b819cf2SRick Macklem if ((uap->flag & NFSSVC_NEWSTRUCT) == 0) { 4741b819cf2SRick Macklem /* Copy fields to the old ext_nfsstat structure. */ 4751b819cf2SRick Macklem oldnfsstats.attrcache_hits = 4761b819cf2SRick Macklem nfsstatsv1.attrcache_hits; 4771b819cf2SRick Macklem oldnfsstats.attrcache_misses = 4781b819cf2SRick Macklem nfsstatsv1.attrcache_misses; 4791b819cf2SRick Macklem oldnfsstats.lookupcache_hits = 4801b819cf2SRick Macklem nfsstatsv1.lookupcache_hits; 4811b819cf2SRick Macklem oldnfsstats.lookupcache_misses = 4821b819cf2SRick Macklem nfsstatsv1.lookupcache_misses; 4831b819cf2SRick Macklem oldnfsstats.direofcache_hits = 4841b819cf2SRick Macklem nfsstatsv1.direofcache_hits; 4851b819cf2SRick Macklem oldnfsstats.direofcache_misses = 4861b819cf2SRick Macklem nfsstatsv1.direofcache_misses; 4871b819cf2SRick Macklem oldnfsstats.accesscache_hits = 4881b819cf2SRick Macklem nfsstatsv1.accesscache_hits; 4891b819cf2SRick Macklem oldnfsstats.accesscache_misses = 4901b819cf2SRick Macklem nfsstatsv1.accesscache_misses; 4911b819cf2SRick Macklem oldnfsstats.biocache_reads = 4921b819cf2SRick Macklem nfsstatsv1.biocache_reads; 4931b819cf2SRick Macklem oldnfsstats.read_bios = 4941b819cf2SRick Macklem nfsstatsv1.read_bios; 4951b819cf2SRick Macklem oldnfsstats.read_physios = 4961b819cf2SRick Macklem nfsstatsv1.read_physios; 4971b819cf2SRick Macklem oldnfsstats.biocache_writes = 4981b819cf2SRick Macklem nfsstatsv1.biocache_writes; 4991b819cf2SRick Macklem oldnfsstats.write_bios = 5001b819cf2SRick Macklem nfsstatsv1.write_bios; 5011b819cf2SRick Macklem oldnfsstats.write_physios = 5021b819cf2SRick Macklem nfsstatsv1.write_physios; 5031b819cf2SRick Macklem oldnfsstats.biocache_readlinks = 5041b819cf2SRick Macklem nfsstatsv1.biocache_readlinks; 5051b819cf2SRick Macklem oldnfsstats.readlink_bios = 5061b819cf2SRick Macklem nfsstatsv1.readlink_bios; 5071b819cf2SRick Macklem oldnfsstats.biocache_readdirs = 5081b819cf2SRick Macklem nfsstatsv1.biocache_readdirs; 5091b819cf2SRick Macklem oldnfsstats.readdir_bios = 5101b819cf2SRick Macklem nfsstatsv1.readdir_bios; 5111b819cf2SRick Macklem for (i = 0; i < NFSV4_NPROCS; i++) 5121b819cf2SRick Macklem oldnfsstats.rpccnt[i] = nfsstatsv1.rpccnt[i]; 5131b819cf2SRick Macklem oldnfsstats.rpcretries = nfsstatsv1.rpcretries; 5141b819cf2SRick Macklem for (i = 0; i < NFSV4OP_NOPS; i++) 5151b819cf2SRick Macklem oldnfsstats.srvrpccnt[i] = 5161b819cf2SRick Macklem nfsstatsv1.srvrpccnt[i]; 5171b819cf2SRick Macklem for (i = NFSV42_NOPS, j = NFSV4OP_NOPS; 5181b819cf2SRick Macklem i < NFSV42_NOPS + NFSV4OP_FAKENOPS; i++, j++) 5191b819cf2SRick Macklem oldnfsstats.srvrpccnt[j] = 5201b819cf2SRick Macklem nfsstatsv1.srvrpccnt[i]; 521ac8c4a61SAlan Somers oldnfsstats.reserved_0 = 0; 522ac8c4a61SAlan Somers oldnfsstats.reserved_1 = 0; 5231b819cf2SRick Macklem oldnfsstats.rpcrequests = nfsstatsv1.rpcrequests; 5241b819cf2SRick Macklem oldnfsstats.rpctimeouts = nfsstatsv1.rpctimeouts; 5251b819cf2SRick Macklem oldnfsstats.rpcunexpected = nfsstatsv1.rpcunexpected; 5261b819cf2SRick Macklem oldnfsstats.rpcinvalid = nfsstatsv1.rpcinvalid; 5271b819cf2SRick Macklem oldnfsstats.srvcache_inproghits = 5281b819cf2SRick Macklem nfsstatsv1.srvcache_inproghits; 529ac8c4a61SAlan Somers oldnfsstats.reserved_2 = 0; 5301b819cf2SRick Macklem oldnfsstats.srvcache_nonidemdonehits = 5311b819cf2SRick Macklem nfsstatsv1.srvcache_nonidemdonehits; 5321b819cf2SRick Macklem oldnfsstats.srvcache_misses = 5331b819cf2SRick Macklem nfsstatsv1.srvcache_misses; 5341b819cf2SRick Macklem oldnfsstats.srvcache_tcppeak = 5351b819cf2SRick Macklem nfsstatsv1.srvcache_tcppeak; 5361b819cf2SRick Macklem oldnfsstats.srvcache_size = nfsstatsv1.srvcache_size; 5371b819cf2SRick Macklem oldnfsstats.srvclients = nfsstatsv1.srvclients; 5381b819cf2SRick Macklem oldnfsstats.srvopenowners = nfsstatsv1.srvopenowners; 5391b819cf2SRick Macklem oldnfsstats.srvopens = nfsstatsv1.srvopens; 5401b819cf2SRick Macklem oldnfsstats.srvlockowners = nfsstatsv1.srvlockowners; 5411b819cf2SRick Macklem oldnfsstats.srvlocks = nfsstatsv1.srvlocks; 5421b819cf2SRick Macklem oldnfsstats.srvdelegates = nfsstatsv1.srvdelegates; 5431b819cf2SRick Macklem for (i = 0; i < NFSV4OP_CBNOPS; i++) 5441b819cf2SRick Macklem oldnfsstats.cbrpccnt[i] = 5451b819cf2SRick Macklem nfsstatsv1.cbrpccnt[i]; 5461b819cf2SRick Macklem oldnfsstats.clopenowners = nfsstatsv1.clopenowners; 5471b819cf2SRick Macklem oldnfsstats.clopens = nfsstatsv1.clopens; 5481b819cf2SRick Macklem oldnfsstats.cllockowners = nfsstatsv1.cllockowners; 5491b819cf2SRick Macklem oldnfsstats.cllocks = nfsstatsv1.cllocks; 5501b819cf2SRick Macklem oldnfsstats.cldelegates = nfsstatsv1.cldelegates; 5511b819cf2SRick Macklem oldnfsstats.cllocalopenowners = 5521b819cf2SRick Macklem nfsstatsv1.cllocalopenowners; 5531b819cf2SRick Macklem oldnfsstats.cllocalopens = nfsstatsv1.cllocalopens; 5541b819cf2SRick Macklem oldnfsstats.cllocallockowners = 5551b819cf2SRick Macklem nfsstatsv1.cllocallockowners; 5561b819cf2SRick Macklem oldnfsstats.cllocallocks = nfsstatsv1.cllocallocks; 5571b819cf2SRick Macklem error = copyout(&oldnfsstats, uap->argp, 5581b819cf2SRick Macklem sizeof (oldnfsstats)); 5591b819cf2SRick Macklem } else { 5601b819cf2SRick Macklem error = copyin(uap->argp, &nfsstatver, 5611b819cf2SRick Macklem sizeof(nfsstatver)); 562c057a378SRick Macklem if (error == 0) { 563c057a378SRick Macklem if (nfsstatver.vers == NFSSTATS_OV1) { 564c057a378SRick Macklem /* Copy nfsstatsv1 to nfsstatsov1. */ 565c057a378SRick Macklem nfsstatsov1.attrcache_hits = 566c057a378SRick Macklem nfsstatsv1.attrcache_hits; 567c057a378SRick Macklem nfsstatsov1.attrcache_misses = 568c057a378SRick Macklem nfsstatsv1.attrcache_misses; 569c057a378SRick Macklem nfsstatsov1.lookupcache_hits = 570c057a378SRick Macklem nfsstatsv1.lookupcache_hits; 571c057a378SRick Macklem nfsstatsov1.lookupcache_misses = 572c057a378SRick Macklem nfsstatsv1.lookupcache_misses; 573c057a378SRick Macklem nfsstatsov1.direofcache_hits = 574c057a378SRick Macklem nfsstatsv1.direofcache_hits; 575c057a378SRick Macklem nfsstatsov1.direofcache_misses = 576c057a378SRick Macklem nfsstatsv1.direofcache_misses; 577c057a378SRick Macklem nfsstatsov1.accesscache_hits = 578c057a378SRick Macklem nfsstatsv1.accesscache_hits; 579c057a378SRick Macklem nfsstatsov1.accesscache_misses = 580c057a378SRick Macklem nfsstatsv1.accesscache_misses; 581c057a378SRick Macklem nfsstatsov1.biocache_reads = 582c057a378SRick Macklem nfsstatsv1.biocache_reads; 583c057a378SRick Macklem nfsstatsov1.read_bios = 584c057a378SRick Macklem nfsstatsv1.read_bios; 585c057a378SRick Macklem nfsstatsov1.read_physios = 586c057a378SRick Macklem nfsstatsv1.read_physios; 587c057a378SRick Macklem nfsstatsov1.biocache_writes = 588c057a378SRick Macklem nfsstatsv1.biocache_writes; 589c057a378SRick Macklem nfsstatsov1.write_bios = 590c057a378SRick Macklem nfsstatsv1.write_bios; 591c057a378SRick Macklem nfsstatsov1.write_physios = 592c057a378SRick Macklem nfsstatsv1.write_physios; 593c057a378SRick Macklem nfsstatsov1.biocache_readlinks = 594c057a378SRick Macklem nfsstatsv1.biocache_readlinks; 595c057a378SRick Macklem nfsstatsov1.readlink_bios = 596c057a378SRick Macklem nfsstatsv1.readlink_bios; 597c057a378SRick Macklem nfsstatsov1.biocache_readdirs = 598c057a378SRick Macklem nfsstatsv1.biocache_readdirs; 599c057a378SRick Macklem nfsstatsov1.readdir_bios = 600c057a378SRick Macklem nfsstatsv1.readdir_bios; 601c057a378SRick Macklem for (i = 0; i < NFSV42_NPROCS; i++) 602c057a378SRick Macklem nfsstatsov1.rpccnt[i] = 603c057a378SRick Macklem nfsstatsv1.rpccnt[i]; 604c057a378SRick Macklem nfsstatsov1.rpcretries = 605c057a378SRick Macklem nfsstatsv1.rpcretries; 606c057a378SRick Macklem for (i = 0; i < NFSV42_PURENOPS; i++) 607c057a378SRick Macklem nfsstatsov1.srvrpccnt[i] = 608c057a378SRick Macklem nfsstatsv1.srvrpccnt[i]; 609c057a378SRick Macklem for (i = NFSV42_NOPS, 610c057a378SRick Macklem j = NFSV42_PURENOPS; 611c057a378SRick Macklem i < NFSV42_NOPS + NFSV4OP_FAKENOPS; 612c057a378SRick Macklem i++, j++) 613c057a378SRick Macklem nfsstatsov1.srvrpccnt[j] = 614c057a378SRick Macklem nfsstatsv1.srvrpccnt[i]; 615ac8c4a61SAlan Somers nfsstatsov1.reserved_0 = 0; 616ac8c4a61SAlan Somers nfsstatsov1.reserved_1 = 0; 617c057a378SRick Macklem nfsstatsov1.rpcrequests = 618c057a378SRick Macklem nfsstatsv1.rpcrequests; 619c057a378SRick Macklem nfsstatsov1.rpctimeouts = 620c057a378SRick Macklem nfsstatsv1.rpctimeouts; 621c057a378SRick Macklem nfsstatsov1.rpcunexpected = 622c057a378SRick Macklem nfsstatsv1.rpcunexpected; 623c057a378SRick Macklem nfsstatsov1.rpcinvalid = 624c057a378SRick Macklem nfsstatsv1.rpcinvalid; 625c057a378SRick Macklem nfsstatsov1.srvcache_inproghits = 626c057a378SRick Macklem nfsstatsv1.srvcache_inproghits; 627ac8c4a61SAlan Somers nfsstatsov1.reserved_2 = 0; 628c057a378SRick Macklem nfsstatsov1.srvcache_nonidemdonehits = 629c057a378SRick Macklem nfsstatsv1.srvcache_nonidemdonehits; 630c057a378SRick Macklem nfsstatsov1.srvcache_misses = 631c057a378SRick Macklem nfsstatsv1.srvcache_misses; 632c057a378SRick Macklem nfsstatsov1.srvcache_tcppeak = 633c057a378SRick Macklem nfsstatsv1.srvcache_tcppeak; 634c057a378SRick Macklem nfsstatsov1.srvcache_size = 635c057a378SRick Macklem nfsstatsv1.srvcache_size; 636c057a378SRick Macklem nfsstatsov1.srvclients = 637c057a378SRick Macklem nfsstatsv1.srvclients; 638c057a378SRick Macklem nfsstatsov1.srvopenowners = 639c057a378SRick Macklem nfsstatsv1.srvopenowners; 640c057a378SRick Macklem nfsstatsov1.srvopens = 641c057a378SRick Macklem nfsstatsv1.srvopens; 642c057a378SRick Macklem nfsstatsov1.srvlockowners = 643c057a378SRick Macklem nfsstatsv1.srvlockowners; 644c057a378SRick Macklem nfsstatsov1.srvlocks = 645c057a378SRick Macklem nfsstatsv1.srvlocks; 646c057a378SRick Macklem nfsstatsov1.srvdelegates = 647c057a378SRick Macklem nfsstatsv1.srvdelegates; 648c057a378SRick Macklem for (i = 0; i < NFSV42_CBNOPS; i++) 649c057a378SRick Macklem nfsstatsov1.cbrpccnt[i] = 650c057a378SRick Macklem nfsstatsv1.cbrpccnt[i]; 651c057a378SRick Macklem nfsstatsov1.clopenowners = 652c057a378SRick Macklem nfsstatsv1.clopenowners; 653c057a378SRick Macklem nfsstatsov1.clopens = 654c057a378SRick Macklem nfsstatsv1.clopens; 655c057a378SRick Macklem nfsstatsov1.cllockowners = 656c057a378SRick Macklem nfsstatsv1.cllockowners; 657c057a378SRick Macklem nfsstatsov1.cllocks = 658c057a378SRick Macklem nfsstatsv1.cllocks; 659c057a378SRick Macklem nfsstatsov1.cldelegates = 660c057a378SRick Macklem nfsstatsv1.cldelegates; 661c057a378SRick Macklem nfsstatsov1.cllocalopenowners = 662c057a378SRick Macklem nfsstatsv1.cllocalopenowners; 663c057a378SRick Macklem nfsstatsov1.cllocalopens = 664c057a378SRick Macklem nfsstatsv1.cllocalopens; 665c057a378SRick Macklem nfsstatsov1.cllocallockowners = 666c057a378SRick Macklem nfsstatsv1.cllocallockowners; 667c057a378SRick Macklem nfsstatsov1.cllocallocks = 668c057a378SRick Macklem nfsstatsv1.cllocallocks; 669c057a378SRick Macklem nfsstatsov1.srvstartcnt = 670c057a378SRick Macklem nfsstatsv1.srvstartcnt; 671c057a378SRick Macklem nfsstatsov1.srvdonecnt = 672c057a378SRick Macklem nfsstatsv1.srvdonecnt; 673c057a378SRick Macklem for (i = NFSV42_NOPS, 674c057a378SRick Macklem j = NFSV42_PURENOPS; 675c057a378SRick Macklem i < NFSV42_NOPS + NFSV4OP_FAKENOPS; 676c057a378SRick Macklem i++, j++) { 677c057a378SRick Macklem nfsstatsov1.srvbytes[j] = 678c057a378SRick Macklem nfsstatsv1.srvbytes[i]; 679c057a378SRick Macklem nfsstatsov1.srvops[j] = 680c057a378SRick Macklem nfsstatsv1.srvops[i]; 681c057a378SRick Macklem nfsstatsov1.srvduration[j] = 682c057a378SRick Macklem nfsstatsv1.srvduration[i]; 683c057a378SRick Macklem } 684c057a378SRick Macklem nfsstatsov1.busyfrom = 685c057a378SRick Macklem nfsstatsv1.busyfrom; 686c057a378SRick Macklem nfsstatsov1.busyfrom = 687c057a378SRick Macklem nfsstatsv1.busyfrom; 688c057a378SRick Macklem error = copyout(&nfsstatsov1, uap->argp, 689c057a378SRick Macklem sizeof(nfsstatsov1)); 690c057a378SRick Macklem } else if (nfsstatver.vers != NFSSTATS_V1) 6911b819cf2SRick Macklem error = EPERM; 692c057a378SRick Macklem else 6931b819cf2SRick Macklem error = copyout(&nfsstatsv1, uap->argp, 6941b819cf2SRick Macklem sizeof(nfsstatsv1)); 6951b819cf2SRick Macklem } 696c057a378SRick Macklem } 6972e3b981aSRick Macklem if (error == 0) { 6982e3b981aSRick Macklem if ((uap->flag & NFSSVC_ZEROCLTSTATS) != 0) { 6991b819cf2SRick Macklem nfsstatsv1.attrcache_hits = 0; 7001b819cf2SRick Macklem nfsstatsv1.attrcache_misses = 0; 7011b819cf2SRick Macklem nfsstatsv1.lookupcache_hits = 0; 7021b819cf2SRick Macklem nfsstatsv1.lookupcache_misses = 0; 7031b819cf2SRick Macklem nfsstatsv1.direofcache_hits = 0; 7041b819cf2SRick Macklem nfsstatsv1.direofcache_misses = 0; 7051b819cf2SRick Macklem nfsstatsv1.accesscache_hits = 0; 7061b819cf2SRick Macklem nfsstatsv1.accesscache_misses = 0; 7071b819cf2SRick Macklem nfsstatsv1.biocache_reads = 0; 7081b819cf2SRick Macklem nfsstatsv1.read_bios = 0; 7091b819cf2SRick Macklem nfsstatsv1.read_physios = 0; 7101b819cf2SRick Macklem nfsstatsv1.biocache_writes = 0; 7111b819cf2SRick Macklem nfsstatsv1.write_bios = 0; 7121b819cf2SRick Macklem nfsstatsv1.write_physios = 0; 7131b819cf2SRick Macklem nfsstatsv1.biocache_readlinks = 0; 7141b819cf2SRick Macklem nfsstatsv1.readlink_bios = 0; 7151b819cf2SRick Macklem nfsstatsv1.biocache_readdirs = 0; 7161b819cf2SRick Macklem nfsstatsv1.readdir_bios = 0; 7171b819cf2SRick Macklem nfsstatsv1.rpcretries = 0; 7181b819cf2SRick Macklem nfsstatsv1.rpcrequests = 0; 7191b819cf2SRick Macklem nfsstatsv1.rpctimeouts = 0; 7201b819cf2SRick Macklem nfsstatsv1.rpcunexpected = 0; 7211b819cf2SRick Macklem nfsstatsv1.rpcinvalid = 0; 7221b819cf2SRick Macklem bzero(nfsstatsv1.rpccnt, 7231b819cf2SRick Macklem sizeof(nfsstatsv1.rpccnt)); 7242e3b981aSRick Macklem } 7252e3b981aSRick Macklem if ((uap->flag & NFSSVC_ZEROSRVSTATS) != 0) { 7261b819cf2SRick Macklem nfsstatsv1.srvcache_inproghits = 0; 7271b819cf2SRick Macklem nfsstatsv1.srvcache_nonidemdonehits = 0; 7281b819cf2SRick Macklem nfsstatsv1.srvcache_misses = 0; 7291b819cf2SRick Macklem nfsstatsv1.srvcache_tcppeak = 0; 7301b819cf2SRick Macklem bzero(nfsstatsv1.srvrpccnt, 7311b819cf2SRick Macklem sizeof(nfsstatsv1.srvrpccnt)); 7321b819cf2SRick Macklem bzero(nfsstatsv1.cbrpccnt, 7331b819cf2SRick Macklem sizeof(nfsstatsv1.cbrpccnt)); 7342e3b981aSRick Macklem } 7352e3b981aSRick Macklem } 736a9285ae5SZack Kirsch goto out; 7379ec7b004SRick Macklem } else if (uap->flag & NFSSVC_NFSUSERDPORT) { 7389ec7b004SRick Macklem u_short sockport; 73980405bcfSRick Macklem struct nfsuserd_args nargs; 7409ec7b004SRick Macklem 74180405bcfSRick Macklem if ((uap->flag & NFSSVC_NEWSTRUCT) == 0) { 7429ec7b004SRick Macklem error = copyin(uap->argp, (caddr_t)&sockport, 7439ec7b004SRick Macklem sizeof (u_short)); 74480405bcfSRick Macklem if (error == 0) { 74580405bcfSRick Macklem nargs.nuserd_family = AF_INET; 74680405bcfSRick Macklem nargs.nuserd_port = sockport; 74780405bcfSRick Macklem } 74880405bcfSRick Macklem } else { 74980405bcfSRick Macklem /* 75080405bcfSRick Macklem * New nfsuserd_args structure, which indicates 75180405bcfSRick Macklem * which IP version to use along with the port#. 75280405bcfSRick Macklem */ 75380405bcfSRick Macklem error = copyin(uap->argp, &nargs, sizeof(nargs)); 75480405bcfSRick Macklem } 75502c8dd7dSRick Macklem if (!error) 75680405bcfSRick Macklem error = nfsrv_nfsuserdport(&nargs, p); 7579ec7b004SRick Macklem } else if (uap->flag & NFSSVC_NFSUSERDDELPORT) { 7589ec7b004SRick Macklem nfsrv_nfsuserddelport(); 7599ec7b004SRick Macklem error = 0; 7609ec7b004SRick Macklem } 761a9285ae5SZack Kirsch 762a9285ae5SZack Kirsch out: 763a9285ae5SZack Kirsch NFSEXITCODE(error); 7649ec7b004SRick Macklem return (error); 7659ec7b004SRick Macklem } 7669ec7b004SRick Macklem 7679ec7b004SRick Macklem /* 7689ec7b004SRick Macklem * called by all three modevent routines, so that it gets things 7699ec7b004SRick Macklem * initialized soon enough. 7709ec7b004SRick Macklem */ 7719ec7b004SRick Macklem void 7729ec7b004SRick Macklem newnfs_portinit(void) 7739ec7b004SRick Macklem { 7749ec7b004SRick Macklem static int inited = 0; 7759ec7b004SRick Macklem 7769ec7b004SRick Macklem if (inited) 7779ec7b004SRick Macklem return; 7789ec7b004SRick Macklem inited = 1; 7799ec7b004SRick Macklem /* Initialize SMP locks used by both client and server. */ 7809ec7b004SRick Macklem mtx_init(&newnfsd_mtx, "newnfsd_mtx", NULL, MTX_DEF); 7819ec7b004SRick Macklem mtx_init(&nfs_state_mutex, "nfs_state_mutex", NULL, MTX_DEF); 782b2fc0141SRick Macklem mtx_init(&nfs_clstate_mutex, "nfs_clstate_mutex", NULL, MTX_DEF); 7839ec7b004SRick Macklem } 7849ec7b004SRick Macklem 785ee1c1433SRick Macklem /* 786ee1c1433SRick Macklem * Determine if the file system supports NFSv4 ACLs. 787ee1c1433SRick Macklem * Return 1 if it does, 0 otherwise. 788ee1c1433SRick Macklem */ 789ee1c1433SRick Macklem int 790a09001a8SRick Macklem nfs_supportsnfsv4acls(struct vnode *vp) 791ee1c1433SRick Macklem { 792a09001a8SRick Macklem int error; 793b1288166SJohn Baldwin long retval; 794ee1c1433SRick Macklem 795a09001a8SRick Macklem ASSERT_VOP_LOCKED(vp, "nfs supports nfsv4acls"); 796a09001a8SRick Macklem 797a09001a8SRick Macklem if (nfsrv_useacl == 0) 798ee1c1433SRick Macklem return (0); 799061c683cSZack Kirsch error = VOP_PATHCONF(vp, _PC_ACL_NFS4, &retval); 800a09001a8SRick Macklem if (error == 0 && retval != 0) 801ee1c1433SRick Macklem return (1); 802ee1c1433SRick Macklem return (0); 803ee1c1433SRick Macklem } 804ee1c1433SRick Macklem 805f49c813cSRick Macklem /* 806f49c813cSRick Macklem * These are the first fields of all the context structures passed into 807f49c813cSRick Macklem * nfs_pnfsio(). 808f49c813cSRick Macklem */ 809f49c813cSRick Macklem struct pnfsio { 810f49c813cSRick Macklem int done; 811f49c813cSRick Macklem int inprog; 812f49c813cSRick Macklem struct task tsk; 813f49c813cSRick Macklem }; 814f49c813cSRick Macklem 815f49c813cSRick Macklem /* 816f49c813cSRick Macklem * Do a mirror I/O on a pNFS thread. 817f49c813cSRick Macklem */ 818f49c813cSRick Macklem int 819f49c813cSRick Macklem nfs_pnfsio(task_fn_t *func, void *context) 820f49c813cSRick Macklem { 821f49c813cSRick Macklem struct pnfsio *pio; 822f49c813cSRick Macklem int ret; 823f49c813cSRick Macklem static struct taskqueue *pnfsioq = NULL; 824f49c813cSRick Macklem 825f49c813cSRick Macklem pio = (struct pnfsio *)context; 826f49c813cSRick Macklem if (pnfsioq == NULL) { 827f49c813cSRick Macklem if (nfs_pnfsiothreads == 0) 828dec8894bSRick Macklem return (EPERM); 829dec8894bSRick Macklem if (nfs_pnfsiothreads < 0) 830f49c813cSRick Macklem nfs_pnfsiothreads = mp_ncpus * 4; 831f49c813cSRick Macklem pnfsioq = taskqueue_create("pnfsioq", M_WAITOK, 832f49c813cSRick Macklem taskqueue_thread_enqueue, &pnfsioq); 833f49c813cSRick Macklem if (pnfsioq == NULL) 834f49c813cSRick Macklem return (ENOMEM); 835f49c813cSRick Macklem ret = taskqueue_start_threads(&pnfsioq, nfs_pnfsiothreads, 836f49c813cSRick Macklem 0, "pnfsiot"); 837f49c813cSRick Macklem if (ret != 0) { 838f49c813cSRick Macklem taskqueue_free(pnfsioq); 839f49c813cSRick Macklem pnfsioq = NULL; 840f49c813cSRick Macklem return (ret); 841f49c813cSRick Macklem } 842f49c813cSRick Macklem } 843f49c813cSRick Macklem pio->inprog = 1; 844f49c813cSRick Macklem TASK_INIT(&pio->tsk, 0, func, context); 845f49c813cSRick Macklem ret = taskqueue_enqueue(pnfsioq, &pio->tsk); 846f49c813cSRick Macklem if (ret != 0) 847f49c813cSRick Macklem pio->inprog = 0; 848f49c813cSRick Macklem return (ret); 849f49c813cSRick Macklem } 850f49c813cSRick Macklem 8519ec7b004SRick Macklem extern int (*nfsd_call_nfscommon)(struct thread *, struct nfssvc_args *); 8529ec7b004SRick Macklem 8539ec7b004SRick Macklem /* 8549ec7b004SRick Macklem * Called once to initialize data structures... 8559ec7b004SRick Macklem */ 8569ec7b004SRick Macklem static int 8579ec7b004SRick Macklem nfscommon_modevent(module_t mod, int type, void *data) 8589ec7b004SRick Macklem { 8599ec7b004SRick Macklem int error = 0; 8609ec7b004SRick Macklem static int loaded = 0; 8619ec7b004SRick Macklem 8629ec7b004SRick Macklem switch (type) { 8639ec7b004SRick Macklem case MOD_LOAD: 8649ec7b004SRick Macklem if (loaded) 865a9285ae5SZack Kirsch goto out; 8669ec7b004SRick Macklem newnfs_portinit(); 8679ec7b004SRick Macklem mtx_init(&nfs_nameid_mutex, "nfs_nameid_mutex", NULL, MTX_DEF); 8689ec7b004SRick Macklem mtx_init(&nfs_sockl_mutex, "nfs_sockl_mutex", NULL, MTX_DEF); 8699ec7b004SRick Macklem mtx_init(&nfs_slock_mutex, "nfs_slock_mutex", NULL, MTX_DEF); 8709ec7b004SRick Macklem mtx_init(&nfs_req_mutex, "nfs_req_mutex", NULL, MTX_DEF); 8719ec7b004SRick Macklem mtx_init(&nfsrv_nfsuserdsock.nr_mtx, "nfsuserd", NULL, 8729ec7b004SRick Macklem MTX_DEF); 87390d2dfabSRick Macklem mtx_init(&nfsrv_dslock_mtx, "nfs4ds", NULL, MTX_DEF); 87490d2dfabSRick Macklem TAILQ_INIT(&nfsrv_devidhead); 8759ec7b004SRick Macklem newnfs_init(); 8769ec7b004SRick Macklem nfsd_call_nfscommon = nfssvc_nfscommon; 8779ec7b004SRick Macklem loaded = 1; 8789ec7b004SRick Macklem break; 8799ec7b004SRick Macklem 8809ec7b004SRick Macklem case MOD_UNLOAD: 881e1cda5eeSRick Macklem if (newnfs_numnfsd != 0 || nfsrv_nfsuserd != NOTRUNNING || 8829ec7b004SRick Macklem nfs_numnfscbd != 0) { 8839ec7b004SRick Macklem error = EBUSY; 8849ec7b004SRick Macklem break; 8859ec7b004SRick Macklem } 8869ec7b004SRick Macklem 8879ec7b004SRick Macklem nfsd_call_nfscommon = NULL; 88865171ebbSRick Macklem /* Clean out the name<-->id cache. */ 88965171ebbSRick Macklem nfsrv_cleanusergroup(); 8909ec7b004SRick Macklem /* and get rid of the mutexes */ 8919ec7b004SRick Macklem mtx_destroy(&nfs_nameid_mutex); 8929ec7b004SRick Macklem mtx_destroy(&newnfsd_mtx); 8939ec7b004SRick Macklem mtx_destroy(&nfs_state_mutex); 894b2fc0141SRick Macklem mtx_destroy(&nfs_clstate_mutex); 8959ec7b004SRick Macklem mtx_destroy(&nfs_sockl_mutex); 8969ec7b004SRick Macklem mtx_destroy(&nfs_slock_mutex); 8979ec7b004SRick Macklem mtx_destroy(&nfs_req_mutex); 8989ec7b004SRick Macklem mtx_destroy(&nfsrv_nfsuserdsock.nr_mtx); 89990d2dfabSRick Macklem mtx_destroy(&nfsrv_dslock_mtx); 9009ec7b004SRick Macklem loaded = 0; 9019ec7b004SRick Macklem break; 9029ec7b004SRick Macklem default: 9039ec7b004SRick Macklem error = EOPNOTSUPP; 9049ec7b004SRick Macklem break; 9059ec7b004SRick Macklem } 906a9285ae5SZack Kirsch 907a9285ae5SZack Kirsch out: 908a9285ae5SZack Kirsch NFSEXITCODE(error); 9099ec7b004SRick Macklem return error; 9109ec7b004SRick Macklem } 9119ec7b004SRick Macklem static moduledata_t nfscommon_mod = { 9129ec7b004SRick Macklem "nfscommon", 9139ec7b004SRick Macklem nfscommon_modevent, 9149ec7b004SRick Macklem NULL, 9159ec7b004SRick Macklem }; 9169ec7b004SRick Macklem DECLARE_MODULE(nfscommon, nfscommon_mod, SI_SUB_VFS, SI_ORDER_ANY); 9179ec7b004SRick Macklem 9189ec7b004SRick Macklem /* So that loader and kldload(2) can find us, wherever we are.. */ 9199ec7b004SRick Macklem MODULE_VERSION(nfscommon, 1); 9209ec7b004SRick Macklem MODULE_DEPEND(nfscommon, nfssvc, 1, 1, 1); 9219ec7b004SRick Macklem MODULE_DEPEND(nfscommon, krpc, 1, 1, 1); 922