nfs_commonport.c revision 194498
1191783Srmacklem/*- 2191783Srmacklem * Copyright (c) 1989, 1993 3191783Srmacklem * The Regents of the University of California. All rights reserved. 4191783Srmacklem * 5191783Srmacklem * This code is derived from software contributed to Berkeley by 6191783Srmacklem * Rick Macklem at The University of Guelph. 7191783Srmacklem * 8191783Srmacklem * Redistribution and use in source and binary forms, with or without 9191783Srmacklem * modification, are permitted provided that the following conditions 10191783Srmacklem * are met: 11191783Srmacklem * 1. Redistributions of source code must retain the above copyright 12191783Srmacklem * notice, this list of conditions and the following disclaimer. 13191783Srmacklem * 2. Redistributions in binary form must reproduce the above copyright 14191783Srmacklem * notice, this list of conditions and the following disclaimer in the 15191783Srmacklem * documentation and/or other materials provided with the distribution. 16191783Srmacklem * 4. Neither the name of the University nor the names of its contributors 17191783Srmacklem * may be used to endorse or promote products derived from this software 18191783Srmacklem * without specific prior written permission. 19191783Srmacklem * 20191783Srmacklem * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21191783Srmacklem * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22191783Srmacklem * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23191783Srmacklem * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24191783Srmacklem * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25191783Srmacklem * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26191783Srmacklem * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27191783Srmacklem * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28191783Srmacklem * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29191783Srmacklem * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30191783Srmacklem * SUCH DAMAGE. 31191783Srmacklem * 32191783Srmacklem */ 33191783Srmacklem 34191783Srmacklem#include <sys/cdefs.h> 35191783Srmacklem__FBSDID("$FreeBSD: head/sys/fs/nfs/nfs_commonport.c 194498 2009-06-19 17:10:35Z brooks $"); 36191783Srmacklem 37191783Srmacklem/* 38191783Srmacklem * Functions that need to be different for different versions of BSD 39191783Srmacklem * kernel should be kept here, along with any global storage specific 40191783Srmacklem * to this BSD variant. 41191783Srmacklem */ 42191783Srmacklem#include <fs/nfs/nfsport.h> 43191783Srmacklem#include <sys/sysctl.h> 44191783Srmacklem#include <vm/vm.h> 45191783Srmacklem#include <vm/vm_object.h> 46191783Srmacklem#include <vm/vm_page.h> 47191783Srmacklem#include <vm/vm_param.h> 48191783Srmacklem#include <vm/vm_map.h> 49191783Srmacklem#include <vm/vm_kern.h> 50191783Srmacklem#include <vm/vm_extern.h> 51191783Srmacklem#include <vm/uma.h> 52191783Srmacklem#include <vm/uma_int.h> 53191783Srmacklem 54191783Srmacklemextern int nfscl_ticks; 55191783Srmacklemextern int nfsrv_nfsuserd; 56191783Srmacklemextern struct nfssockreq nfsrv_nfsuserdsock; 57191783Srmacklemextern void (*nfsd_call_recall)(struct vnode *, int, struct ucred *, 58191783Srmacklem struct thread *); 59191783Srmacklemextern int nfsrv_useacl; 60191783Srmacklemstruct mount nfsv4root_mnt; 61191783Srmacklemint newnfs_numnfsd = 0; 62191783Srmacklemstruct nfsstats newnfsstats; 63191783Srmacklemint nfs_numnfscbd = 0; 64191783Srmacklemchar nfsv4_callbackaddr[INET6_ADDRSTRLEN]; 65191783Srmacklemstruct callout newnfsd_callout; 66191783Srmacklemvoid (*nfsd_call_servertimer)(void) = NULL; 67191783Srmacklemvoid (*ncl_call_invalcaches)(struct vnode *) = NULL; 68191783Srmacklem 69191783Srmacklemstatic int nfs_realign_test; 70191783Srmacklemstatic int nfs_realign_count; 71191783Srmacklem 72191783SrmacklemSYSCTL_NODE(_vfs, OID_AUTO, newnfs, CTLFLAG_RW, 0, "New NFS filesystem"); 73192695SrmacklemSYSCTL_INT(_vfs_newnfs, OID_AUTO, newnfs_realign_test, CTLFLAG_RW, &nfs_realign_test, 0, ""); 74192695SrmacklemSYSCTL_INT(_vfs_newnfs, OID_AUTO, newnfs_realign_count, CTLFLAG_RW, &nfs_realign_count, 0, ""); 75191783SrmacklemSYSCTL_INT(_vfs_newnfs, OID_AUTO, nfs4acl_enable, CTLFLAG_RW, &nfsrv_useacl, 0, ""); 76191783SrmacklemSYSCTL_STRING(_vfs_newnfs, OID_AUTO, callback_addr, CTLFLAG_RW, 77191783Srmacklem nfsv4_callbackaddr, sizeof(nfsv4_callbackaddr), ""); 78191783Srmacklem 79191783Srmacklem/* 80191783Srmacklem * Defines for malloc 81191783Srmacklem * (Here for FreeBSD, since they allocate storage.) 82191783Srmacklem */ 83191783SrmacklemMALLOC_DEFINE(M_NEWNFSRVCACHE, "NFSD srvcache", "NFSD Server Request Cache"); 84191783SrmacklemMALLOC_DEFINE(M_NEWNFSDCLIENT, "NFSD V4client", "NFSD V4 Client Id"); 85191783SrmacklemMALLOC_DEFINE(M_NEWNFSDSTATE, "NFSD V4state", "NFSD V4 State (Openowner, Open, Lockowner, Delegation"); 86191783SrmacklemMALLOC_DEFINE(M_NEWNFSDLOCK, "NFSD V4lock", "NFSD V4 byte range lock"); 87191783SrmacklemMALLOC_DEFINE(M_NEWNFSDLOCKFILE, "NFSD lckfile", "NFSD Open/Lock file"); 88191783SrmacklemMALLOC_DEFINE(M_NEWNFSSTRING, "NFSD string", "NFSD V4 long string"); 89191783SrmacklemMALLOC_DEFINE(M_NEWNFSUSERGROUP, "NFSD usrgroup", "NFSD V4 User/group map"); 90191783SrmacklemMALLOC_DEFINE(M_NEWNFSDREQ, "NFS req", "NFS request header"); 91191783SrmacklemMALLOC_DEFINE(M_NEWNFSFH, "NFS fh", "NFS file handle"); 92191783SrmacklemMALLOC_DEFINE(M_NEWNFSCLOWNER, "NFSCL owner", "NFSCL Open Owner"); 93191783SrmacklemMALLOC_DEFINE(M_NEWNFSCLOPEN, "NFSCL open", "NFSCL Open"); 94191783SrmacklemMALLOC_DEFINE(M_NEWNFSCLDELEG, "NFSCL deleg", "NFSCL Delegation"); 95191783SrmacklemMALLOC_DEFINE(M_NEWNFSCLCLIENT, "NFSCL client", "NFSCL Client"); 96191783SrmacklemMALLOC_DEFINE(M_NEWNFSCLLOCKOWNER, "NFSCL lckown", "NFSCL Lock Owner"); 97191783SrmacklemMALLOC_DEFINE(M_NEWNFSCLLOCK, "NFSCL lck", "NFSCL Lock"); 98191783SrmacklemMALLOC_DEFINE(M_NEWNFSV4NODE, "NEWNFSnode", "New nfs vnode"); 99191783SrmacklemMALLOC_DEFINE(M_NEWNFSDIRECTIO, "NEWdirectio", "New nfs Direct IO buffer"); 100191783SrmacklemMALLOC_DEFINE(M_NEWNFSDIROFF, "Newnfscl_diroff", "New NFS directory offset data"); 101191783Srmacklem 102191783Srmacklem/* 103191783Srmacklem * Definition of mutex locks. 104191783Srmacklem * newnfsd_mtx is used in nfsrvd_nfsd() to protect the nfs socket list 105191783Srmacklem * and assorted other nfsd structures. 106191783Srmacklem * Giant is used to protect the nfsd list and count, which is just 107191783Srmacklem * updated when nfsd's start/stop and is grabbed for nfsrvd_dorpc() 108191783Srmacklem * for the VFS ops. 109191783Srmacklem */ 110191783Srmacklemstruct mtx newnfsd_mtx; 111191783Srmacklemstruct mtx nfs_sockl_mutex; 112191783Srmacklemstruct mtx nfs_state_mutex; 113191783Srmacklemstruct mtx nfs_nameid_mutex; 114191783Srmacklemstruct mtx nfs_req_mutex; 115191783Srmacklemstruct mtx nfs_slock_mutex; 116191783Srmacklem 117191783Srmacklem/* local functions */ 118191783Srmacklemstatic int nfssvc_call(struct thread *, struct nfssvc_args *, struct ucred *); 119191783Srmacklem 120191783Srmacklem#if defined(__i386__) 121191783Srmacklem/* 122191783Srmacklem * These architectures don't need re-alignment, so just return. 123191783Srmacklem */ 124191783Srmacklemvoid 125191783Srmacklemnewnfs_realign(struct mbuf **pm) 126191783Srmacklem{ 127191783Srmacklem 128191783Srmacklem return; 129191783Srmacklem} 130191783Srmacklem#else 131191783Srmacklem/* 132192695Srmacklem * newnfs_realign: 133191783Srmacklem * 134191783Srmacklem * Check for badly aligned mbuf data and realign by copying the unaligned 135191783Srmacklem * portion of the data into a new mbuf chain and freeing the portions 136191783Srmacklem * of the old chain that were replaced. 137191783Srmacklem * 138191783Srmacklem * We cannot simply realign the data within the existing mbuf chain 139191783Srmacklem * because the underlying buffers may contain other rpc commands and 140191783Srmacklem * we cannot afford to overwrite them. 141191783Srmacklem * 142191783Srmacklem * We would prefer to avoid this situation entirely. The situation does 143191783Srmacklem * not occur with NFS/UDP and is supposed to only occassionally occur 144191783Srmacklem * with TCP. Use vfs.nfs.realign_count and realign_test to check this. 145192695Srmacklem * 146191783Srmacklem */ 147191783Srmacklemvoid 148191783Srmacklemnewnfs_realign(struct mbuf **pm) 149191783Srmacklem{ 150192695Srmacklem struct mbuf *m, *n; 151192695Srmacklem int off, space; 152191783Srmacklem 153191783Srmacklem ++nfs_realign_test; 154191783Srmacklem while ((m = *pm) != NULL) { 155191783Srmacklem if ((m->m_len & 0x3) || (mtod(m, intptr_t) & 0x3)) { 156192695Srmacklem /* 157192695Srmacklem * NB: we can't depend on m_pkthdr.len to help us 158192695Srmacklem * decide what to do here. May not be worth doing 159192695Srmacklem * the m_length calculation as m_copyback will 160192695Srmacklem * expand the mbuf chain below as needed. 161192695Srmacklem */ 162192695Srmacklem space = m_length(m, NULL); 163192695Srmacklem if (space >= MINCLSIZE) { 164192695Srmacklem /* NB: m_copyback handles space > MCLBYTES */ 165192695Srmacklem n = m_getcl(M_WAITOK, MT_DATA, 0); 166192695Srmacklem } else 167192695Srmacklem n = m_get(M_WAITOK, MT_DATA); 168192695Srmacklem if (n == NULL) 169192695Srmacklem return; 170192695Srmacklem /* 171192695Srmacklem * Align the remainder of the mbuf chain. 172192695Srmacklem */ 173192695Srmacklem n->m_len = 0; 174192695Srmacklem off = 0; 175192695Srmacklem while (m != NULL) { 176192695Srmacklem m_copyback(n, off, m->m_len, mtod(m, caddr_t)); 177192695Srmacklem off += m->m_len; 178192695Srmacklem m = m->m_next; 179191783Srmacklem } 180192695Srmacklem m_freem(*pm); 181192695Srmacklem *pm = n; 182192695Srmacklem ++nfs_realign_count; 183191783Srmacklem break; 184191783Srmacklem } 185191783Srmacklem pm = &m->m_next; 186191783Srmacklem } 187191783Srmacklem} 188192695Srmacklem#endif /* !__i386__ */ 189191783Srmacklem 190191783Srmacklem#ifdef notdef 191191783Srmacklemstatic void 192191783Srmacklemnfsrv_object_create(struct vnode *vp, struct thread *td) 193191783Srmacklem{ 194191783Srmacklem 195191783Srmacklem if (vp == NULL || vp->v_type != VREG) 196191783Srmacklem return; 197191783Srmacklem (void) vfs_object_create(vp, td, td->td_ucred); 198191783Srmacklem} 199191783Srmacklem#endif 200191783Srmacklem 201191783Srmacklem/* 202191783Srmacklem * Look up a file name. Basically just initialize stuff and call namei(). 203191783Srmacklem */ 204191783Srmacklemint 205191783Srmacklemnfsrv_lookupfilename(struct nameidata *ndp, char *fname, NFSPROC_T *p) 206191783Srmacklem{ 207191783Srmacklem int error; 208191783Srmacklem 209191783Srmacklem NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, fname, p); 210191783Srmacklem error = namei(ndp); 211191783Srmacklem if (!error) { 212191783Srmacklem NDFREE(ndp, NDF_ONLY_PNBUF); 213191783Srmacklem } 214191783Srmacklem return (error); 215191783Srmacklem} 216191783Srmacklem 217191783Srmacklem/* 218191783Srmacklem * Copy NFS uid, gids to the cred structure. 219191783Srmacklem */ 220191783Srmacklemvoid 221191783Srmacklemnewnfs_copycred(struct nfscred *nfscr, struct ucred *cr) 222191783Srmacklem{ 223191783Srmacklem 224191783Srmacklem cr->cr_uid = nfscr->nfsc_uid; 225194498Sbrooks crsetgroups(cr, nfscr->nfsc_ngroups, nfscr->nfsc_groups); 226191783Srmacklem} 227191783Srmacklem 228191783Srmacklem/* 229191783Srmacklem * Map args from nfsmsleep() to msleep(). 230191783Srmacklem */ 231191783Srmacklemint 232191783Srmacklemnfsmsleep(void *chan, void *mutex, int prio, const char *wmesg, 233191783Srmacklem struct timespec *ts) 234191783Srmacklem{ 235191783Srmacklem u_int64_t nsecval; 236191783Srmacklem int error, timeo; 237191783Srmacklem 238191783Srmacklem if (ts) { 239191783Srmacklem timeo = hz * ts->tv_sec; 240191783Srmacklem nsecval = (u_int64_t)ts->tv_nsec; 241191783Srmacklem nsecval = ((nsecval * ((u_int64_t)hz)) + 500000000) / 242191783Srmacklem 1000000000; 243191783Srmacklem timeo += (int)nsecval; 244191783Srmacklem } else { 245191783Srmacklem timeo = 0; 246191783Srmacklem } 247191783Srmacklem error = msleep(chan, (struct mtx *)mutex, prio, wmesg, timeo); 248191783Srmacklem return (error); 249191783Srmacklem} 250191783Srmacklem 251191783Srmacklem/* 252191783Srmacklem * Get the file system info for the server. For now, just assume FFS. 253191783Srmacklem */ 254191783Srmacklemvoid 255191783Srmacklemnfsvno_getfs(struct nfsfsinfo *sip, int isdgram) 256191783Srmacklem{ 257191783Srmacklem int pref; 258191783Srmacklem 259191783Srmacklem /* 260191783Srmacklem * XXX 261191783Srmacklem * There should be file system VFS OP(s) to get this information. 262191783Srmacklem * For now, assume ufs. 263191783Srmacklem */ 264191783Srmacklem if (isdgram) 265191783Srmacklem pref = NFS_MAXDGRAMDATA; 266191783Srmacklem else 267191783Srmacklem pref = NFS_MAXDATA; 268191783Srmacklem sip->fs_rtmax = NFS_MAXDATA; 269191783Srmacklem sip->fs_rtpref = pref; 270191783Srmacklem sip->fs_rtmult = NFS_FABLKSIZE; 271191783Srmacklem sip->fs_wtmax = NFS_MAXDATA; 272191783Srmacklem sip->fs_wtpref = pref; 273191783Srmacklem sip->fs_wtmult = NFS_FABLKSIZE; 274191783Srmacklem sip->fs_dtpref = pref; 275191783Srmacklem sip->fs_maxfilesize = 0xffffffffffffffffull; 276191783Srmacklem sip->fs_timedelta.tv_sec = 0; 277191783Srmacklem sip->fs_timedelta.tv_nsec = 1; 278191783Srmacklem sip->fs_properties = (NFSV3FSINFO_LINK | 279191783Srmacklem NFSV3FSINFO_SYMLINK | NFSV3FSINFO_HOMOGENEOUS | 280191783Srmacklem NFSV3FSINFO_CANSETTIME); 281191783Srmacklem} 282191783Srmacklem 283191783Srmacklem/* Fake nfsrv_atroot. Just return 0 */ 284191783Srmacklemint 285191783Srmacklemnfsrv_atroot(struct vnode *vp, long *retp) 286191783Srmacklem{ 287191783Srmacklem 288191783Srmacklem return (0); 289191783Srmacklem} 290191783Srmacklem 291191783Srmacklem/* 292191783Srmacklem * Set the credentials to refer to root. 293191783Srmacklem * If only the various BSDen could agree on whether cr_gid is a separate 294191783Srmacklem * field or cr_groups[0]... 295191783Srmacklem */ 296191783Srmacklemvoid 297191783Srmacklemnewnfs_setroot(struct ucred *cred) 298191783Srmacklem{ 299191783Srmacklem 300191783Srmacklem cred->cr_uid = 0; 301191783Srmacklem cred->cr_groups[0] = 0; 302191783Srmacklem cred->cr_ngroups = 1; 303191783Srmacklem} 304191783Srmacklem 305191783Srmacklem/* 306191783Srmacklem * Get the client credential. Used for Renew and recovery. 307191783Srmacklem */ 308191783Srmacklemstruct ucred * 309191783Srmacklemnewnfs_getcred(void) 310191783Srmacklem{ 311191783Srmacklem struct ucred *cred; 312191783Srmacklem struct thread *td = curthread; 313191783Srmacklem 314191783Srmacklem cred = crdup(td->td_ucred); 315191783Srmacklem newnfs_setroot(cred); 316191783Srmacklem return (cred); 317191783Srmacklem} 318191783Srmacklem 319191783Srmacklem/* 320191783Srmacklem * Nfs timer routine 321191783Srmacklem * Call the nfsd's timer function once/sec. 322191783Srmacklem */ 323191783Srmacklemvoid 324191783Srmacklemnewnfs_timer(void *arg) 325191783Srmacklem{ 326191783Srmacklem static time_t lasttime = 0; 327191783Srmacklem /* 328191783Srmacklem * Call the server timer, if set up. 329191783Srmacklem * The argument indicates if it is the next second and therefore 330191783Srmacklem * leases should be checked. 331191783Srmacklem */ 332191783Srmacklem if (lasttime != NFSD_MONOSEC) { 333191783Srmacklem lasttime = NFSD_MONOSEC; 334191783Srmacklem if (nfsd_call_servertimer != NULL) 335191783Srmacklem (*nfsd_call_servertimer)(); 336191783Srmacklem } 337191783Srmacklem callout_reset(&newnfsd_callout, nfscl_ticks, newnfs_timer, NULL); 338191783Srmacklem} 339191783Srmacklem 340191783Srmacklem 341191783Srmacklem/* 342191783Srmacklem * sleep for a short period of time. 343191783Srmacklem * Since lbolt doesn't exist in FreeBSD-CURRENT, just use a timeout on 344191783Srmacklem * an event that never gets a wakeup. Only return EINTR or 0. 345191783Srmacklem */ 346191783Srmacklemint 347191783Srmacklemnfs_catnap(int prio, const char *wmesg) 348191783Srmacklem{ 349191783Srmacklem static int non_event; 350191783Srmacklem int ret; 351191783Srmacklem 352191783Srmacklem ret = tsleep(&non_event, prio, wmesg, 1); 353191783Srmacklem if (ret != EINTR) 354191783Srmacklem ret = 0; 355191783Srmacklem return (ret); 356191783Srmacklem} 357191783Srmacklem 358191783Srmacklem/* 359191783Srmacklem * Get referral. For now, just fail. 360191783Srmacklem */ 361191783Srmacklemstruct nfsreferral * 362191783Srmacklemnfsv4root_getreferral(struct vnode *vp, struct vnode *dvp, u_int32_t fileno) 363191783Srmacklem{ 364191783Srmacklem 365191783Srmacklem return (NULL); 366191783Srmacklem} 367191783Srmacklem 368191783Srmacklemstatic int 369191783Srmacklemnfssvc_nfscommon(struct thread *td, struct nfssvc_args *uap) 370191783Srmacklem{ 371191783Srmacklem int error; 372191783Srmacklem 373191783Srmacklem error = nfssvc_call(td, uap, td->td_ucred); 374191783Srmacklem return (error); 375191783Srmacklem} 376191783Srmacklem 377191783Srmacklemstatic int 378191783Srmacklemnfssvc_call(struct thread *p, struct nfssvc_args *uap, struct ucred *cred) 379191783Srmacklem{ 380191783Srmacklem int error = EINVAL; 381191783Srmacklem struct nfsd_idargs nid; 382191783Srmacklem 383191783Srmacklem if (uap->flag & NFSSVC_IDNAME) { 384191783Srmacklem error = copyin(uap->argp, (caddr_t)&nid, sizeof (nid)); 385191783Srmacklem if (error) 386191783Srmacklem return (error); 387191783Srmacklem error = nfssvc_idname(&nid); 388191783Srmacklem return (error); 389191783Srmacklem } else if (uap->flag & NFSSVC_GETSTATS) { 390191783Srmacklem error = copyout(&newnfsstats, 391191783Srmacklem CAST_USER_ADDR_T(uap->argp), sizeof (newnfsstats)); 392191783Srmacklem return (error); 393191783Srmacklem } else if (uap->flag & NFSSVC_NFSUSERDPORT) { 394191783Srmacklem u_short sockport; 395191783Srmacklem 396191783Srmacklem error = copyin(uap->argp, (caddr_t)&sockport, 397191783Srmacklem sizeof (u_short)); 398191783Srmacklem if (!error) 399191783Srmacklem error = nfsrv_nfsuserdport(sockport, p); 400191783Srmacklem } else if (uap->flag & NFSSVC_NFSUSERDDELPORT) { 401191783Srmacklem nfsrv_nfsuserddelport(); 402191783Srmacklem error = 0; 403191783Srmacklem } 404191783Srmacklem return (error); 405191783Srmacklem} 406191783Srmacklem 407191783Srmacklem/* 408191783Srmacklem * called by all three modevent routines, so that it gets things 409191783Srmacklem * initialized soon enough. 410191783Srmacklem */ 411191783Srmacklemvoid 412191783Srmacklemnewnfs_portinit(void) 413191783Srmacklem{ 414191783Srmacklem static int inited = 0; 415191783Srmacklem 416191783Srmacklem if (inited) 417191783Srmacklem return; 418191783Srmacklem inited = 1; 419191783Srmacklem /* Initialize SMP locks used by both client and server. */ 420191783Srmacklem mtx_init(&newnfsd_mtx, "newnfsd_mtx", NULL, MTX_DEF); 421191783Srmacklem mtx_init(&nfs_state_mutex, "nfs_state_mutex", NULL, MTX_DEF); 422191783Srmacklem} 423191783Srmacklem 424192898Srmacklem#ifdef NFS4_ACL_EXTATTR_NAME 425192898Srmacklem/* 426192898Srmacklem * Determine if the file system supports NFSv4 ACLs. 427192898Srmacklem * Return 1 if it does, 0 otherwise. 428192898Srmacklem */ 429192898Srmacklemint 430192898Srmacklemnfs_supportsnfsv4acls(struct mount *mp) 431192898Srmacklem{ 432192898Srmacklem 433192898Srmacklem if (mp->mnt_stat.f_fstypename == NULL) 434192898Srmacklem return (0); 435192898Srmacklem if (strcmp(mp->mnt_stat.f_fstypename, "ufs") == 0) { 436192898Srmacklem /* Not yet */ 437192898Srmacklem return (0); 438192898Srmacklem } else if (strcmp(mp->mnt_stat.f_fstypename, "zfs") == 0) { 439192898Srmacklem /* Always supports them */ 440192898Srmacklem return (1); 441192898Srmacklem } 442192898Srmacklem return (0); 443192898Srmacklem} 444192898Srmacklem#endif /* NFS4_ACL_EXTATTR_NAME */ 445192898Srmacklem 446191783Srmacklemextern int (*nfsd_call_nfscommon)(struct thread *, struct nfssvc_args *); 447191783Srmacklem 448191783Srmacklem/* 449191783Srmacklem * Called once to initialize data structures... 450191783Srmacklem */ 451191783Srmacklemstatic int 452191783Srmacklemnfscommon_modevent(module_t mod, int type, void *data) 453191783Srmacklem{ 454191783Srmacklem int error = 0; 455191783Srmacklem static int loaded = 0; 456191783Srmacklem 457191783Srmacklem switch (type) { 458191783Srmacklem case MOD_LOAD: 459191783Srmacklem if (loaded) 460191783Srmacklem return (0); 461191783Srmacklem newnfs_portinit(); 462191783Srmacklem mtx_init(&nfs_nameid_mutex, "nfs_nameid_mutex", NULL, MTX_DEF); 463191783Srmacklem mtx_init(&nfs_sockl_mutex, "nfs_sockl_mutex", NULL, MTX_DEF); 464191783Srmacklem mtx_init(&nfs_slock_mutex, "nfs_slock_mutex", NULL, MTX_DEF); 465191783Srmacklem mtx_init(&nfs_req_mutex, "nfs_req_mutex", NULL, MTX_DEF); 466191783Srmacklem mtx_init(&nfsrv_nfsuserdsock.nr_mtx, "nfsuserd", NULL, 467191783Srmacklem MTX_DEF); 468191783Srmacklem callout_init(&newnfsd_callout, CALLOUT_MPSAFE); 469191783Srmacklem newnfs_init(); 470191783Srmacklem nfsd_call_nfscommon = nfssvc_nfscommon; 471191783Srmacklem loaded = 1; 472191783Srmacklem break; 473191783Srmacklem 474191783Srmacklem case MOD_UNLOAD: 475191783Srmacklem if (newnfs_numnfsd != 0 || nfsrv_nfsuserd != 0 || 476191783Srmacklem nfs_numnfscbd != 0) { 477191783Srmacklem error = EBUSY; 478191783Srmacklem break; 479191783Srmacklem } 480191783Srmacklem 481191783Srmacklem nfsd_call_nfscommon = NULL; 482191783Srmacklem callout_drain(&newnfsd_callout); 483191783Srmacklem /* and get rid of the mutexes */ 484191783Srmacklem mtx_destroy(&nfs_nameid_mutex); 485191783Srmacklem mtx_destroy(&newnfsd_mtx); 486191783Srmacklem mtx_destroy(&nfs_state_mutex); 487191783Srmacklem mtx_destroy(&nfs_sockl_mutex); 488191783Srmacklem mtx_destroy(&nfs_slock_mutex); 489191783Srmacklem mtx_destroy(&nfs_req_mutex); 490191783Srmacklem mtx_destroy(&nfsrv_nfsuserdsock.nr_mtx); 491191783Srmacklem loaded = 0; 492191783Srmacklem break; 493191783Srmacklem default: 494191783Srmacklem error = EOPNOTSUPP; 495191783Srmacklem break; 496191783Srmacklem } 497191783Srmacklem return error; 498191783Srmacklem} 499191783Srmacklemstatic moduledata_t nfscommon_mod = { 500191783Srmacklem "nfscommon", 501191783Srmacklem nfscommon_modevent, 502191783Srmacklem NULL, 503191783Srmacklem}; 504191783SrmacklemDECLARE_MODULE(nfscommon, nfscommon_mod, SI_SUB_VFS, SI_ORDER_ANY); 505191783Srmacklem 506191783Srmacklem/* So that loader and kldload(2) can find us, wherever we are.. */ 507191783SrmacklemMODULE_VERSION(nfscommon, 1); 508191783SrmacklemMODULE_DEPEND(nfscommon, nfssvc, 1, 1, 1); 509191783SrmacklemMODULE_DEPEND(nfscommon, krpc, 1, 1, 1); 510191783Srmacklem 511