d96b98a360
it will work with either the old or new server. The FHA code keeps a cache of currently active file handles for NFSv2 and v3 requests, so that read and write requests for the same file are directed to the same group of threads (reads) or thread (writes). It does not currently work for NFSv4 requests. They are more complex, and will take more work to support. This improves read-ahead performance, especially with ZFS, if the FHA tuning parameters are configured appropriately. Without the FHA code, concurrent reads that are part of a sequential read from a file will be directed to separate NFS threads. This has the effect of confusing the ZFS zfetch (prefetch) code and makes sequential reads significantly slower with clients like Linux that do a lot of prefetching. The FHA code has also been updated to direct write requests to nearby file offsets to the same thread in the same way it batches reads, and the FHA code will now also send writes to multiple threads when needed. This improves sequential write performance in ZFS, because writes to a file are now more ordered. Since NFS writes (generally less than 64K) are smaller than the typical ZFS record size (usually 128K), out of order NFS writes to the same block can trigger a read in ZFS. Sending them down the same thread increases the odds of their being in order. In order for multiple write threads per file in the FHA code to be useful, writes in the NFS server have been changed to use a LK_SHARED vnode lock, and upgrade that to LK_EXCLUSIVE if the filesystem doesn't allow multiple writers to a file at once. ZFS is currently the only filesystem that allows multiple writers to a file, because it has internal file range locking. This change does not affect the NFSv4 code. This improves random write performance to a single file in ZFS, since we can now have multiple writers inside ZFS at one time. I have changed the default tuning parameters to a 22 bit (4MB) window size (from 256K) and unlimited commands per thread as a result of my benchmarking with ZFS. The FHA code has been updated to allow configuring the tuning parameters from loader tunable variables in addition to sysctl variables. The read offset window calculation has been slightly modified as well. Instead of having separate bins, each file handle has a rolling window of bin_shift size. This minimizes glitches in throughput when shifting from one bin to another. sys/conf/files: Add nfs_fha_new.c and nfs_fha_old.c. Compile nfs_fha.c when either the old or the new NFS server is built. sys/fs/nfs/nfsport.h, sys/fs/nfs/nfs_commonport.c: Bring in changes from Rick Macklem to newnfs_realign that allow it to operate in blocking (M_WAITOK) or non-blocking (M_NOWAIT) mode. sys/fs/nfs/nfs_commonsubs.c, sys/fs/nfs/nfs_var.h: Bring in a change from Rick Macklem to allow telling nfsm_dissect() whether or not to wait for mallocs. sys/fs/nfs/nfsm_subs.h: Bring in changes from Rick Macklem to create a new nfsm_dissect_nonblock() inline function and NFSM_DISSECT_NONBLOCK() macro. sys/fs/nfs/nfs_commonkrpc.c, sys/fs/nfsclient/nfs_clkrpc.c: Add the malloc wait flag to a newnfs_realign() call. sys/fs/nfsserver/nfs_nfsdkrpc.c: Setup the new NFS server's RPC thread pool so that it will call the FHA code. Add the malloc flag argument to newnfs_realign(). Unstaticize newnfs_nfsv3_procid[] so that we can use it in the FHA code. sys/fs/nfsserver/nfs_nfsdsocket.c: In nfsrvd_dorpc(), add NFSPROC_WRITE to the list of RPC types that use the LK_SHARED lock type. sys/fs/nfsserver/nfs_nfsdport.c: In nfsd_fhtovp(), if we're starting a write, check to see whether the underlying filesystem supports shared writes. If not, upgrade the lock type from LK_SHARED to LK_EXCLUSIVE. sys/nfsserver/nfs_fha.c: Remove all code that is specific to the NFS server implementation. Anything that is server-specific is now accessed through a callback supplied by that server's FHA shim in the new softc. There are now separate sysctls and tunables for the FHA implementations for the old and new NFS servers. The new NFS server has its tunables under vfs.nfsd.fha, the old NFS server's tunables are under vfs.nfsrv.fha as before. In fha_extract_info(), use callouts for all server-specific code. Getting file handles and offsets is now done in the individual server's shim module. In fha_hash_entry_choose_thread(), change the way we decide whether two reads are in proximity to each other. Previously, the calculation was a simple shift operation to see whether the offsets were in the same power of 2 bucket. The issue was that there would be a bucket (and therefore thread) transition, even if the reads were in close proximity. When there is a thread transition, reads wind up going somewhat out of order, and ZFS gets confused. The new calculation simply tries to see whether the offsets are within 1 << bin_shift of each other. If they are, the reads will be sent to the same thread. The effect of this change is that for sequential reads, if the client doesn't exceed the max_reqs_per_nfsd parameter and the bin_shift is set to a reasonable value (22, or 4MB works well in my tests), the reads in any sequential stream will largely be confined to a single thread. Change fha_assign() so that it takes a softc argument. It is now called from the individual server's shim code, which will pass in the softc. Change fhe_stats_sysctl() so that it takes a softc parameter. It is now called from the individual server's shim code. Add the current offset to the list of things printed out about each active thread. Change the num_reads and num_writes counters in the fha_hash_entry structure to 32-bit values, and rename them num_rw and num_exclusive, respectively, to reflect their changed usage. Add an enable sysctl and tunable that allows the user to disable the FHA code (when vfs.XXX.fha.enable = 0). This is useful for before/after performance comparisons. nfs_fha.h: Move most structure definitions out of nfs_fha.c and into the header file, so that the individual server shims can see them. Change the default bin_shift to 22 (4MB) instead of 18 (256K). Allow unlimited commands per thread. sys/nfsserver/nfs_fha_old.c, sys/nfsserver/nfs_fha_old.h, sys/fs/nfsserver/nfs_fha_new.c, sys/fs/nfsserver/nfs_fha_new.h: Add shims for the old and new NFS servers to interface with the FHA code, and callbacks for the The shims contain all of the code and definitions that are specific to the NFS servers. They setup the server-specific callbacks and set the server name for the sysctl and loader tunable variables. sys/nfsserver/nfs_srvkrpc.c: Configure the RPC code to call fhaold_assign() instead of fha_assign(). sys/modules/nfsd/Makefile: Add nfs_fha.c and nfs_fha_new.c. sys/modules/nfsserver/Makefile: Add nfs_fha_old.c. Reviewed by: rmacklem Sponsored by: Spectra Logic MFC after: 2 weeks
543 lines
13 KiB
C
543 lines
13 KiB
C
/*-
|
|
* Copyright (c) 1989, 1993
|
|
* The Regents of the University of California. All rights reserved.
|
|
*
|
|
* This code is derived from software contributed to Berkeley by
|
|
* Rick Macklem at The University of Guelph.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
* may be used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*
|
|
* @(#)nfs_syscalls.c 8.5 (Berkeley) 3/30/95
|
|
*/
|
|
|
|
#include <sys/cdefs.h>
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
#include "opt_inet6.h"
|
|
#include "opt_kgssapi.h"
|
|
|
|
#include <sys/param.h>
|
|
#include <sys/capability.h>
|
|
#include <sys/systm.h>
|
|
#include <sys/sysproto.h>
|
|
#include <sys/kernel.h>
|
|
#include <sys/sysctl.h>
|
|
#include <sys/file.h>
|
|
#include <sys/filedesc.h>
|
|
#include <sys/jail.h>
|
|
#include <sys/vnode.h>
|
|
#include <sys/malloc.h>
|
|
#include <sys/mount.h>
|
|
#include <sys/priv.h>
|
|
#include <sys/proc.h>
|
|
#include <sys/bio.h>
|
|
#include <sys/buf.h>
|
|
#include <sys/mbuf.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/socketvar.h>
|
|
#include <sys/domain.h>
|
|
#include <sys/protosw.h>
|
|
#include <sys/namei.h>
|
|
#include <sys/fcntl.h>
|
|
#include <sys/lockf.h>
|
|
#include <sys/eventhandler.h>
|
|
|
|
#include <netinet/in.h>
|
|
#include <netinet/tcp.h>
|
|
#ifdef INET6
|
|
#include <net/if.h>
|
|
#include <netinet6/in6_var.h>
|
|
#endif
|
|
|
|
#include <rpc/rpc.h>
|
|
#include <rpc/rpcsec_gss.h>
|
|
#include <rpc/replay.h>
|
|
|
|
#include <nfs/xdr_subs.h>
|
|
#include <nfs/nfsproto.h>
|
|
#include <nfsserver/nfs.h>
|
|
#include <nfsserver/nfsm_subs.h>
|
|
#include <nfsserver/nfsrvcache.h>
|
|
#include <nfsserver/nfs_fha.h>
|
|
#include <nfsserver/nfs_fha_old.h>
|
|
|
|
#include <security/mac/mac_framework.h>
|
|
|
|
static MALLOC_DEFINE(M_NFSSVC, "nfss_srvsock", "Nfs server structure");
|
|
|
|
MALLOC_DEFINE(M_NFSRVDESC, "nfss_srvdesc", "NFS server socket descriptor");
|
|
MALLOC_DEFINE(M_NFSD, "nfss_daemon", "Nfs server daemon structure");
|
|
|
|
#define TRUE 1
|
|
#define FALSE 0
|
|
|
|
SYSCTL_DECL(_vfs_nfsrv);
|
|
|
|
SVCPOOL *nfsrv_pool;
|
|
int nfsd_waiting = 0;
|
|
int nfsrv_numnfsd = 0;
|
|
struct callout nfsrv_callout;
|
|
static eventhandler_tag nfsrv_nmbclusters_tag;
|
|
|
|
static int nfs_privport = 0;
|
|
SYSCTL_INT(_vfs_nfsrv, NFS_NFSPRIVPORT, nfs_privport, CTLFLAG_RW,
|
|
&nfs_privport, 0,
|
|
"Only allow clients using a privileged port");
|
|
SYSCTL_INT(_vfs_nfsrv, OID_AUTO, gatherdelay, CTLFLAG_RW,
|
|
&nfsrvw_procrastinate, 0,
|
|
"Delay value for write gathering");
|
|
SYSCTL_INT(_vfs_nfsrv, OID_AUTO, gatherdelay_v3, CTLFLAG_RW,
|
|
&nfsrvw_procrastinate_v3, 0,
|
|
"Delay in seconds for NFSv3 write gathering");
|
|
|
|
static int nfssvc_addsock(struct file *, struct thread *);
|
|
static int nfssvc_nfsd(struct thread *, struct nfsd_nfsd_args *);
|
|
|
|
extern u_long sb_max_adj;
|
|
|
|
int32_t (*nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *nd,
|
|
struct nfssvc_sock *slp, struct mbuf **mreqp) = {
|
|
nfsrv_null,
|
|
nfsrv_getattr,
|
|
nfsrv_setattr,
|
|
nfsrv_lookup,
|
|
nfsrv3_access,
|
|
nfsrv_readlink,
|
|
nfsrv_read,
|
|
nfsrv_write,
|
|
nfsrv_create,
|
|
nfsrv_mkdir,
|
|
nfsrv_symlink,
|
|
nfsrv_mknod,
|
|
nfsrv_remove,
|
|
nfsrv_rmdir,
|
|
nfsrv_rename,
|
|
nfsrv_link,
|
|
nfsrv_readdir,
|
|
nfsrv_readdirplus,
|
|
nfsrv_statfs,
|
|
nfsrv_fsinfo,
|
|
nfsrv_pathconf,
|
|
nfsrv_commit,
|
|
nfsrv_noop
|
|
};
|
|
|
|
/*
|
|
* NFS server system calls
|
|
*/
|
|
/*
|
|
* This is now called from nfssvc() in nfs/nfs_nfssvc.c.
|
|
*/
|
|
|
|
/*
|
|
* Nfs server psuedo system call for the nfsd's
|
|
* Based on the flag value it either:
|
|
* - adds a socket to the selection list
|
|
* - remains in the kernel as an nfsd
|
|
* - remains in the kernel as an nfsiod
|
|
* For INET6 we suppose that nfsd provides only IN6P_IPV6_V6ONLY sockets
|
|
* and that mountd provides
|
|
* - sockaddr with no IPv4-mapped addresses
|
|
* - mask for both INET and INET6 families if there is IPv4-mapped overlap
|
|
*/
|
|
int
|
|
nfssvc_nfsserver(struct thread *td, struct nfssvc_args *uap)
|
|
{
|
|
struct file *fp;
|
|
struct nfsd_addsock_args addsockarg;
|
|
struct nfsd_nfsd_args nfsdarg;
|
|
int error;
|
|
|
|
if (uap->flag & NFSSVC_ADDSOCK) {
|
|
error = copyin(uap->argp, (caddr_t)&addsockarg,
|
|
sizeof(addsockarg));
|
|
if (error)
|
|
return (error);
|
|
error = fget(td, addsockarg.sock, CAP_SOCK_SERVER, &fp);
|
|
if (error)
|
|
return (error);
|
|
if (fp->f_type != DTYPE_SOCKET) {
|
|
fdrop(fp, td);
|
|
return (error); /* XXXRW: Should be EINVAL? */
|
|
}
|
|
error = nfssvc_addsock(fp, td);
|
|
fdrop(fp, td);
|
|
} else if (uap->flag & NFSSVC_OLDNFSD)
|
|
error = nfssvc_nfsd(td, NULL);
|
|
else if (uap->flag & NFSSVC_NFSD) {
|
|
if (!uap->argp)
|
|
return (EINVAL);
|
|
error = copyin(uap->argp, (caddr_t)&nfsdarg,
|
|
sizeof(nfsdarg));
|
|
if (error)
|
|
return (error);
|
|
error = nfssvc_nfsd(td, &nfsdarg);
|
|
} else
|
|
error = ENXIO;
|
|
return (error);
|
|
}
|
|
|
|
/*
|
|
* Generate the rpc reply header
|
|
* siz arg. is used to decide if adding a cluster is worthwhile
|
|
*/
|
|
struct mbuf *
|
|
nfs_rephead(int siz, struct nfsrv_descript *nd, int err,
|
|
struct mbuf **mbp, caddr_t *bposp)
|
|
{
|
|
u_int32_t *tl;
|
|
struct mbuf *mreq;
|
|
caddr_t bpos;
|
|
struct mbuf *mb;
|
|
|
|
if (err == EBADRPC)
|
|
return (NULL);
|
|
|
|
nd->nd_repstat = err;
|
|
if (err && (nd->nd_flag & ND_NFSV3) == 0) /* XXX recheck */
|
|
siz = 0;
|
|
|
|
MGET(mreq, M_WAITOK, MT_DATA);
|
|
|
|
/*
|
|
* If this is a big reply, use a cluster
|
|
*/
|
|
mreq->m_len = 0;
|
|
if (siz >= MINCLSIZE) {
|
|
MCLGET(mreq, M_WAITOK);
|
|
}
|
|
mb = mreq;
|
|
bpos = mtod(mb, caddr_t);
|
|
|
|
if (err != NFSERR_RETVOID) {
|
|
tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED);
|
|
if (err)
|
|
*tl = txdr_unsigned(nfsrv_errmap(nd, err));
|
|
else
|
|
*tl = 0;
|
|
}
|
|
|
|
*mbp = mb;
|
|
*bposp = bpos;
|
|
if (err != 0 && err != NFSERR_RETVOID)
|
|
nfsrvstats.srvrpc_errs++;
|
|
|
|
return (mreq);
|
|
}
|
|
|
|
static void
|
|
nfssvc_program(struct svc_req *rqst, SVCXPRT *xprt)
|
|
{
|
|
rpcproc_t procnum;
|
|
int32_t (*proc)(struct nfsrv_descript *nd, struct nfssvc_sock *slp,
|
|
struct mbuf **mreqp);
|
|
int flag;
|
|
struct nfsrv_descript nd;
|
|
struct mbuf *mreq, *mrep;
|
|
int error;
|
|
|
|
if (rqst->rq_vers == NFS_VER2) {
|
|
if (rqst->rq_proc > NFSV2PROC_STATFS) {
|
|
svcerr_noproc(rqst);
|
|
svc_freereq(rqst);
|
|
return;
|
|
}
|
|
procnum = nfsrv_nfsv3_procid[rqst->rq_proc];
|
|
flag = 0;
|
|
} else {
|
|
if (rqst->rq_proc >= NFS_NPROCS) {
|
|
svcerr_noproc(rqst);
|
|
svc_freereq(rqst);
|
|
return;
|
|
}
|
|
procnum = rqst->rq_proc;
|
|
flag = ND_NFSV3;
|
|
}
|
|
proc = nfsrv3_procs[procnum];
|
|
|
|
mreq = mrep = NULL;
|
|
mreq = rqst->rq_args;
|
|
rqst->rq_args = NULL;
|
|
(void)nfs_realign(&mreq, M_WAITOK);
|
|
|
|
/*
|
|
* Note: we want rq_addr, not svc_getrpccaller for nd_nam2 -
|
|
* NFS_SRVMAXDATA uses a NULL value for nd_nam2 to detect TCP
|
|
* mounts.
|
|
*/
|
|
memset(&nd, 0, sizeof(nd));
|
|
nd.nd_md = nd.nd_mrep = mreq;
|
|
nd.nd_dpos = mtod(mreq, caddr_t);
|
|
nd.nd_nam = svc_getrpccaller(rqst);
|
|
nd.nd_nam2 = rqst->rq_addr;
|
|
nd.nd_procnum = procnum;
|
|
nd.nd_cr = NULL;
|
|
nd.nd_flag = flag;
|
|
|
|
if (nfs_privport) {
|
|
/* Check if source port is privileged */
|
|
u_short port;
|
|
struct sockaddr *nam = nd.nd_nam;
|
|
struct sockaddr_in *sin;
|
|
|
|
sin = (struct sockaddr_in *)nam;
|
|
/*
|
|
* INET/INET6 - same code:
|
|
* sin_port and sin6_port are at same offset
|
|
*/
|
|
port = ntohs(sin->sin_port);
|
|
if (port >= IPPORT_RESERVED &&
|
|
nd.nd_procnum != NFSPROC_NULL) {
|
|
#ifdef INET6
|
|
char b6[INET6_ADDRSTRLEN];
|
|
#if defined(KLD_MODULE)
|
|
/* Do not use ip6_sprintf: the nfs module should work without INET6. */
|
|
#define ip6_sprintf(buf, a) \
|
|
(sprintf((buf), "%x:%x:%x:%x:%x:%x:%x:%x", \
|
|
(a)->s6_addr16[0], (a)->s6_addr16[1], \
|
|
(a)->s6_addr16[2], (a)->s6_addr16[3], \
|
|
(a)->s6_addr16[4], (a)->s6_addr16[5], \
|
|
(a)->s6_addr16[6], (a)->s6_addr16[7]), \
|
|
(buf))
|
|
#endif
|
|
#endif
|
|
printf("NFS request from unprivileged port (%s:%d)\n",
|
|
#ifdef INET6
|
|
sin->sin_family == AF_INET6 ?
|
|
ip6_sprintf(b6, &satosin6(sin)->sin6_addr) :
|
|
#if defined(KLD_MODULE)
|
|
#undef ip6_sprintf
|
|
#endif
|
|
#endif
|
|
inet_ntoa(sin->sin_addr), port);
|
|
m_freem(mreq);
|
|
svcerr_weakauth(rqst);
|
|
svc_freereq(rqst);
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (proc != nfsrv_null) {
|
|
if (!svc_getcred(rqst, &nd.nd_cr, &nd.nd_credflavor)) {
|
|
m_freem(mreq);
|
|
svcerr_weakauth(rqst);
|
|
svc_freereq(rqst);
|
|
return;
|
|
}
|
|
#ifdef MAC
|
|
mac_cred_associate_nfsd(nd.nd_cr);
|
|
#endif
|
|
}
|
|
nfsrvstats.srvrpccnt[nd.nd_procnum]++;
|
|
|
|
error = proc(&nd, NULL, &mrep);
|
|
|
|
if (nd.nd_cr)
|
|
crfree(nd.nd_cr);
|
|
|
|
if (mrep == NULL) {
|
|
svcerr_decode(rqst);
|
|
svc_freereq(rqst);
|
|
return;
|
|
}
|
|
if (error && error != NFSERR_RETVOID) {
|
|
svcerr_systemerr(rqst);
|
|
svc_freereq(rqst);
|
|
return;
|
|
}
|
|
if (nd.nd_repstat & NFSERR_AUTHERR) {
|
|
svcerr_auth(rqst, nd.nd_repstat & ~NFSERR_AUTHERR);
|
|
m_freem(mrep);
|
|
} else {
|
|
if (!svc_sendreply_mbuf(rqst, mrep))
|
|
svcerr_systemerr(rqst);
|
|
}
|
|
svc_freereq(rqst);
|
|
}
|
|
|
|
/*
|
|
* Adds a socket to the list for servicing by nfsds.
|
|
*/
|
|
static int
|
|
nfssvc_addsock(struct file *fp, struct thread *td)
|
|
{
|
|
int siz;
|
|
struct socket *so;
|
|
int error;
|
|
SVCXPRT *xprt;
|
|
|
|
so = fp->f_data;
|
|
|
|
siz = sb_max_adj;
|
|
error = soreserve(so, siz, siz);
|
|
if (error)
|
|
return (error);
|
|
|
|
/*
|
|
* Steal the socket from userland so that it doesn't close
|
|
* unexpectedly.
|
|
*/
|
|
if (so->so_type == SOCK_DGRAM)
|
|
xprt = svc_dg_create(nfsrv_pool, so, 0, 0);
|
|
else
|
|
xprt = svc_vc_create(nfsrv_pool, so, 0, 0);
|
|
if (xprt) {
|
|
fp->f_ops = &badfileops;
|
|
fp->f_data = NULL;
|
|
svc_reg(xprt, NFS_PROG, NFS_VER2, nfssvc_program, NULL);
|
|
svc_reg(xprt, NFS_PROG, NFS_VER3, nfssvc_program, NULL);
|
|
SVC_RELEASE(xprt);
|
|
}
|
|
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* Called by nfssvc() for nfsds. Just loops around servicing rpc requests
|
|
* until it is killed by a signal.
|
|
*/
|
|
static int
|
|
nfssvc_nfsd(struct thread *td, struct nfsd_nfsd_args *args)
|
|
{
|
|
char principal[128];
|
|
int error;
|
|
|
|
if (args) {
|
|
error = copyinstr(args->principal, principal,
|
|
sizeof(principal), NULL);
|
|
if (error)
|
|
return (error);
|
|
} else {
|
|
memcpy(principal, "nfs@", 4);
|
|
getcredhostname(td->td_ucred, principal + 4,
|
|
sizeof(principal) - 4);
|
|
}
|
|
|
|
/*
|
|
* Only the first nfsd actually does any work. The RPC code
|
|
* adds threads to it as needed. Any extra processes offered
|
|
* by nfsd just exit. If nfsd is new enough, it will call us
|
|
* once with a structure that specifies how many threads to
|
|
* use.
|
|
*/
|
|
NFSD_LOCK();
|
|
if (nfsrv_numnfsd == 0) {
|
|
nfsrv_numnfsd++;
|
|
|
|
NFSD_UNLOCK();
|
|
|
|
rpc_gss_set_svc_name_call(principal, "kerberosv5",
|
|
GSS_C_INDEFINITE, NFS_PROG, NFS_VER2);
|
|
rpc_gss_set_svc_name_call(principal, "kerberosv5",
|
|
GSS_C_INDEFINITE, NFS_PROG, NFS_VER3);
|
|
|
|
if (args) {
|
|
nfsrv_pool->sp_minthreads = args->minthreads;
|
|
nfsrv_pool->sp_maxthreads = args->maxthreads;
|
|
} else {
|
|
nfsrv_pool->sp_minthreads = 4;
|
|
nfsrv_pool->sp_maxthreads = 4;
|
|
}
|
|
|
|
svc_run(nfsrv_pool);
|
|
|
|
rpc_gss_clear_svc_name_call(NFS_PROG, NFS_VER2);
|
|
rpc_gss_clear_svc_name_call(NFS_PROG, NFS_VER3);
|
|
|
|
NFSD_LOCK();
|
|
nfsrv_numnfsd--;
|
|
nfsrv_init(TRUE);
|
|
}
|
|
NFSD_UNLOCK();
|
|
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* Size the NFS server's duplicate request cache at 1/2 the
|
|
* nmbclusters, floating within a (64, 2048) range. This is to
|
|
* prevent all mbuf clusters being tied up in the NFS dupreq
|
|
* cache for small values of nmbclusters.
|
|
*/
|
|
static size_t
|
|
nfsrv_replay_size(void)
|
|
{
|
|
size_t replaysiz;
|
|
|
|
replaysiz = nmbclusters / 2;
|
|
if (replaysiz > NFSRVCACHE_MAX_SIZE)
|
|
replaysiz = NFSRVCACHE_MAX_SIZE;
|
|
if (replaysiz < NFSRVCACHE_MIN_SIZE)
|
|
replaysiz = NFSRVCACHE_MIN_SIZE;
|
|
replaysiz *= MCLBYTES;
|
|
|
|
return (replaysiz);
|
|
}
|
|
|
|
/*
|
|
* Called when nmbclusters changes - we resize the replay cache
|
|
* accordingly.
|
|
*/
|
|
static void
|
|
nfsrv_nmbclusters_change(void *tag)
|
|
{
|
|
|
|
if (nfsrv_pool)
|
|
replay_setsize(nfsrv_pool->sp_rcache, nfsrv_replay_size());
|
|
}
|
|
|
|
/*
|
|
* Initialize the data structures for the server.
|
|
* Handshake with any new nfsds starting up to avoid any chance of
|
|
* corruption.
|
|
*/
|
|
void
|
|
nfsrv_init(int terminating)
|
|
{
|
|
|
|
NFSD_LOCK_ASSERT();
|
|
|
|
if (terminating) {
|
|
NFSD_UNLOCK();
|
|
EVENTHANDLER_DEREGISTER(nmbclusters_change,
|
|
nfsrv_nmbclusters_tag);
|
|
svcpool_destroy(nfsrv_pool);
|
|
nfsrv_pool = NULL;
|
|
NFSD_LOCK();
|
|
} else
|
|
nfs_pub.np_valid = 0;
|
|
|
|
NFSD_UNLOCK();
|
|
|
|
nfsrv_pool = svcpool_create("nfsd", SYSCTL_STATIC_CHILDREN(_vfs_nfsrv));
|
|
nfsrv_pool->sp_rcache = replay_newcache(nfsrv_replay_size());
|
|
nfsrv_pool->sp_assign = fhaold_assign;
|
|
nfsrv_pool->sp_done = fha_nd_complete;
|
|
nfsrv_nmbclusters_tag = EVENTHANDLER_REGISTER(nmbclusters_change,
|
|
nfsrv_nmbclusters_change, NULL, EVENTHANDLER_PRI_FIRST);
|
|
|
|
NFSD_LOCK();
|
|
}
|