2009-05-04 15:23:58 +00:00
|
|
|
/*-
|
2017-11-20 19:43:44 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2009-05-04 15:23:58 +00:00
|
|
|
* 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.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2009-05-04 15:23:58 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions that need to be different for different versions of BSD
|
|
|
|
* kernel should be kept here, along with any global storage specific
|
|
|
|
* to this BSD variant.
|
|
|
|
*/
|
|
|
|
#include <fs/nfs/nfsport.h>
|
2017-10-16 23:28:12 +00:00
|
|
|
#include <sys/smp.h>
|
2009-05-04 15:23:58 +00:00
|
|
|
#include <sys/sysctl.h>
|
2017-10-16 23:28:12 +00:00
|
|
|
#include <sys/taskqueue.h>
|
2017-07-06 00:53:12 +00:00
|
|
|
#include <rpc/rpc_com.h>
|
2009-05-04 15:23:58 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_object.h>
|
|
|
|
#include <vm/vm_page.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/vm_map.h>
|
|
|
|
#include <vm/vm_kern.h>
|
|
|
|
#include <vm/vm_extern.h>
|
|
|
|
#include <vm/uma.h>
|
|
|
|
|
|
|
|
extern int nfscl_ticks;
|
2019-11-28 23:34:23 +00:00
|
|
|
extern nfsuserd_state nfsrv_nfsuserd;
|
2009-05-04 15:23:58 +00:00
|
|
|
extern struct nfssockreq nfsrv_nfsuserdsock;
|
|
|
|
extern void (*nfsd_call_recall)(struct vnode *, int, struct ucred *,
|
|
|
|
struct thread *);
|
|
|
|
extern int nfsrv_useacl;
|
|
|
|
struct mount nfsv4root_mnt;
|
|
|
|
int newnfs_numnfsd = 0;
|
2016-08-12 22:44:59 +00:00
|
|
|
struct nfsstatsv1 nfsstatsv1;
|
2009-05-04 15:23:58 +00:00
|
|
|
int nfs_numnfscbd = 0;
|
2012-09-09 21:00:45 +00:00
|
|
|
int nfscl_debuglevel = 0;
|
2009-05-04 15:23:58 +00:00
|
|
|
char nfsv4_callbackaddr[INET6_ADDRSTRLEN];
|
|
|
|
struct callout newnfsd_callout;
|
2015-11-30 21:54:27 +00:00
|
|
|
int nfsrv_lughashsize = 100;
|
Merge the pNFS server code from projects/pnfs-planb-server into head.
This code merge adds a pNFS service to the NFSv4.1 server. Although it is
a large commit it should not affect behaviour for a non-pNFS NFS server.
Some documentation on how this works can be found at:
http://people.freebsd.org/~rmacklem/pnfs-planb-setup.txt
and will hopefully be turned into a proper document soon.
This is a merge of the kernel code. Userland and man page changes will
come soon, once the dust settles on this merge.
It has passed a "make universe", so I hope it will not cause build problems.
It also adds NFSv4.1 server support for the "current stateid".
Here is a brief overview of the pNFS service:
A pNFS service separates the Read/Write oeprations from all the other NFSv4.1
Metadata operations. It is hoped that this separation allows a pNFS service
to be configured that exceeds the limits of a single NFS server for either
storage capacity and/or I/O bandwidth.
It is possible to configure mirroring within the data servers (DSs) so that
the data storage file for an MDS file will be mirrored on two or more of
the DSs.
When this is used, failure of a DS will not stop the pNFS service and a
failed DS can be recovered once repaired while the pNFS service continues
to operate. Although two way mirroring would be the norm, it is possible
to set a mirroring level of up to four or the number of DSs, whichever is
less.
The Metadata server will always be a single point of failure,
just as a single NFS server is.
A Plan B pNFS service consists of a single MetaData Server (MDS) and K
Data Servers (DS), all of which are recent FreeBSD systems.
Clients will mount the MDS as they would a single NFS server.
When files are created, the MDS creates a file tree identical to what a
single NFS server creates, except that all the regular (VREG) files will
be empty. As such, if you look at the exported tree on the MDS directly
on the MDS server (not via an NFS mount), the files will all be of size 0.
Each of these files will also have two extended attributes in the system
attribute name space:
pnfsd.dsfile - This extended attrbute stores the information that
the MDS needs to find the data storage file(s) on DS(s) for this file.
pnfsd.dsattr - This extended attribute stores the Size, AccessTime, ModifyTime
and Change attributes for the file, so that the MDS doesn't need to
acquire the attributes from the DS for every Getattr operation.
For each regular (VREG) file, the MDS creates a data storage file on one
(or more if mirroring is enabled) of the DSs in one of the "dsNN"
subdirectories. The name of this file is the file handle
of the file on the MDS in hexadecimal so that the name is unique.
The DSs use subdirectories named "ds0" to "dsN" so that no one directory
gets too large. The value of "N" is set via the sysctl vfs.nfsd.dsdirsize
on the MDS, with the default being 20.
For production servers that will store a lot of files, this value should
probably be much larger.
It can be increased when the "nfsd" daemon is not running on the MDS,
once the "dsK" directories are created.
For pNFS aware NFSv4.1 clients, the FreeBSD server will return two pieces
of information to the client that allows it to do I/O directly to the DS.
DeviceInfo - This is relatively static information that defines what a DS
is. The critical bits of information returned by the FreeBSD
server is the IP address of the DS and, for the Flexible
File layout, that NFSv4.1 is to be used and that it is
"tightly coupled".
There is a "deviceid" which identifies the DeviceInfo.
Layout - This is per file and can be recalled by the server when it
is no longer valid. For the FreeBSD server, there is support
for two types of layout, call File and Flexible File layout.
Both allow the client to do I/O on the DS via NFSv4.1 I/O
operations. The Flexible File layout is a more recent variant
that allows specification of mirrors, where the client is
expected to do writes to all mirrors to maintain them in a
consistent state. The Flexible File layout also allows the
client to report I/O errors for a DS back to the MDS.
The Flexible File layout supports two variants referred to as
"tightly coupled" vs "loosely coupled". The FreeBSD server always
uses the "tightly coupled" variant where the client uses the
same credentials to do I/O on the DS as it would on the MDS.
For the "loosely coupled" variant, the layout specifies a
synthetic user/group that the client uses to do I/O on the DS.
The FreeBSD server does not do striping and always returns
layouts for the entire file. The critical information in a layout
is Read vs Read/Writea and DeviceID(s) that identify which
DS(s) the data is stored on.
At this time, the MDS generates File Layout layouts to NFSv4.1 clients
that know how to do pNFS for the non-mirrored DS case unless the sysctl
vfs.nfsd.default_flexfile is set non-zero, in which case Flexible File
layouts are generated.
The mirrored DS configuration always generates Flexible File layouts.
For NFS clients that do not support NFSv4.1 pNFS, all I/O operations
are done against the MDS which acts as a proxy for the appropriate DS(s).
When the MDS receives an I/O RPC, it will do the RPC on the DS as a proxy.
If the DS is on the same machine, the MDS/DS will do the RPC on the DS as
a proxy and so on, until the machine runs out of some resource, such as
session slots or mbufs.
As such, DSs must be separate systems from the MDS.
Tested by: james.rose@framestore.com
Relnotes: yes
2018-06-12 19:36:32 +00:00
|
|
|
struct mtx nfsrv_dslock_mtx;
|
|
|
|
struct nfsdevicehead nfsrv_devidhead;
|
|
|
|
volatile int nfsrv_devidcnt = 0;
|
2009-05-04 15:23:58 +00:00
|
|
|
void (*nfsd_call_servertimer)(void) = NULL;
|
|
|
|
void (*ncl_call_invalcaches)(struct vnode *) = NULL;
|
|
|
|
|
2017-10-16 23:28:12 +00:00
|
|
|
int nfs_pnfsio(task_fn_t *, void *);
|
|
|
|
|
2009-05-04 15:23:58 +00:00
|
|
|
static int nfs_realign_test;
|
|
|
|
static int nfs_realign_count;
|
2016-08-12 22:44:59 +00:00
|
|
|
static struct ext_nfsstats oldnfsstats;
|
2009-05-04 15:23:58 +00:00
|
|
|
|
2015-04-19 06:18:41 +00:00
|
|
|
SYSCTL_NODE(_vfs, OID_AUTO, nfs, CTLFLAG_RW, 0, "NFS filesystem");
|
2011-05-15 20:52:43 +00:00
|
|
|
SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_test, CTLFLAG_RW, &nfs_realign_test,
|
2011-04-17 18:56:17 +00:00
|
|
|
0, "Number of realign tests done");
|
2011-05-15 20:52:43 +00:00
|
|
|
SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_count, CTLFLAG_RW, &nfs_realign_count,
|
2011-04-17 18:56:17 +00:00
|
|
|
0, "Number of mbuf realignments done");
|
2011-05-15 20:52:43 +00:00
|
|
|
SYSCTL_STRING(_vfs_nfs, OID_AUTO, callback_addr, CTLFLAG_RW,
|
2011-04-17 18:56:17 +00:00
|
|
|
nfsv4_callbackaddr, sizeof(nfsv4_callbackaddr),
|
|
|
|
"NFSv4 callback addr for server to use");
|
2012-09-09 21:00:45 +00:00
|
|
|
SYSCTL_INT(_vfs_nfs, OID_AUTO, debuglevel, CTLFLAG_RW, &nfscl_debuglevel,
|
2015-04-19 06:18:41 +00:00
|
|
|
0, "Debug level for NFS client");
|
2015-11-30 21:54:27 +00:00
|
|
|
SYSCTL_INT(_vfs_nfs, OID_AUTO, userhashsize, CTLFLAG_RDTUN, &nfsrv_lughashsize,
|
|
|
|
0, "Size of hash tables for uid/name mapping");
|
2018-06-02 00:11:26 +00:00
|
|
|
int nfs_pnfsiothreads = -1;
|
2017-10-16 23:28:12 +00:00
|
|
|
SYSCTL_INT(_vfs_nfs, OID_AUTO, pnfsiothreads, CTLFLAG_RW, &nfs_pnfsiothreads,
|
|
|
|
0, "Number of pNFS mirror I/O threads");
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Defines for malloc
|
|
|
|
* (Here for FreeBSD, since they allocate storage.)
|
|
|
|
*/
|
|
|
|
MALLOC_DEFINE(M_NEWNFSRVCACHE, "NFSD srvcache", "NFSD Server Request Cache");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSDCLIENT, "NFSD V4client", "NFSD V4 Client Id");
|
2010-03-30 23:11:50 +00:00
|
|
|
MALLOC_DEFINE(M_NEWNFSDSTATE, "NFSD V4state",
|
|
|
|
"NFSD V4 State (Openowner, Open, Lockowner, Delegation");
|
2009-05-04 15:23:58 +00:00
|
|
|
MALLOC_DEFINE(M_NEWNFSDLOCK, "NFSD V4lock", "NFSD V4 byte range lock");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSDLOCKFILE, "NFSD lckfile", "NFSD Open/Lock file");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSSTRING, "NFSD string", "NFSD V4 long string");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSUSERGROUP, "NFSD usrgroup", "NFSD V4 User/group map");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSDREQ, "NFS req", "NFS request header");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSFH, "NFS fh", "NFS file handle");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSCLOWNER, "NFSCL owner", "NFSCL Open Owner");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSCLOPEN, "NFSCL open", "NFSCL Open");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSCLDELEG, "NFSCL deleg", "NFSCL Delegation");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSCLCLIENT, "NFSCL client", "NFSCL Client");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSCLLOCKOWNER, "NFSCL lckown", "NFSCL Lock Owner");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSCLLOCK, "NFSCL lck", "NFSCL Lock");
|
2015-04-19 06:18:41 +00:00
|
|
|
MALLOC_DEFINE(M_NEWNFSV4NODE, "NEWNFSnode", "NFS vnode");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSDIRECTIO, "NEWdirectio", "NFS Direct IO buffer");
|
2010-03-30 23:11:50 +00:00
|
|
|
MALLOC_DEFINE(M_NEWNFSDIROFF, "NFSCL diroffdiroff",
|
2015-04-19 06:18:41 +00:00
|
|
|
"NFS directory offset data");
|
2010-03-30 23:11:50 +00:00
|
|
|
MALLOC_DEFINE(M_NEWNFSDROLLBACK, "NFSD rollback",
|
2015-04-19 06:18:41 +00:00
|
|
|
"NFS local lock rollback");
|
2012-12-08 22:52:39 +00:00
|
|
|
MALLOC_DEFINE(M_NEWNFSLAYOUT, "NFSCL layout", "NFSv4.1 Layout");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSFLAYOUT, "NFSCL flayout", "NFSv4.1 File Layout");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSDEVINFO, "NFSCL devinfo", "NFSv4.1 Device Info");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSSOCKREQ, "NFSCL sockreq", "NFS Sock Req");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSCLDS, "NFSCL session", "NFSv4.1 Session");
|
|
|
|
MALLOC_DEFINE(M_NEWNFSLAYRECALL, "NFSCL layrecall", "NFSv4.1 Layout Recall");
|
2014-07-01 20:47:16 +00:00
|
|
|
MALLOC_DEFINE(M_NEWNFSDSESSION, "NFSD session", "NFSD Session for a client");
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Definition of mutex locks.
|
|
|
|
* newnfsd_mtx is used in nfsrvd_nfsd() to protect the nfs socket list
|
|
|
|
* and assorted other nfsd structures.
|
|
|
|
*/
|
|
|
|
struct mtx newnfsd_mtx;
|
|
|
|
struct mtx nfs_sockl_mutex;
|
|
|
|
struct mtx nfs_state_mutex;
|
|
|
|
struct mtx nfs_nameid_mutex;
|
|
|
|
struct mtx nfs_req_mutex;
|
|
|
|
struct mtx nfs_slock_mutex;
|
Fix NFSv4.1 client recovery from NFS4ERR_BAD_SESSION errors.
For most NFSv4.1 servers, a NFS4ERR_BAD_SESSION error is a rare failure
that indicates that the server has lost session/open/lock state.
However, recent testing by cperciva@ against the AmazonEFS server found
several problems with client recovery from this due to it generating this
failure frequently.
Briefly, the problems fixed are:
- If all session slots were in use at the time of the failure, some processes
would continue to loop waiting for a slot on the old session forever.
- If an RPC that doesn't use open/lock state failed with NFS4ERR_BAD_SESSION,
it would fail the RPC/syscall instead of initiating recovery and then
looping to retry the RPC.
- If a successful reply to an RPC for an old session wasn't processed
until after a new session was created for a NFS4ERR_BAD_SESSION error,
it would erroneously update the new session and corrupt it.
- The use of the first element of the session list in the nfs mount
structure (which is always the current metadata session) was slightly
racey. With changes for the above problems it became more racey, so all
uses of this head pointer was wrapped with a NFSLOCKMNT()/NFSUNLOCKMNT().
- Although the kernel malloc() usually allocates more bytes than requested
and, as such, this wouldn't have caused problems, the allocation of a
session structure was 1 byte smaller than it should have been.
(Null termination byte for the string not included in byte count.)
There are probably still problems with a pNFS data server that fails
with NFS4ERR_BAD_SESSION, but I have no server that does this to test
against (the AmazonEFS server doesn't do pNFS), so I can't fix these yet.
Although this patch is fairly large, it should only affect the handling
of NFS4ERR_BAD_SESSION error replies from an NFSv4.1 server.
Thanks go to cperciva@ for the extension testing he did to help isolate/fix
these problems.
Reported by: cperciva
Tested by: cperciva
MFC after: 3 months
Differential Revision: https://reviews.freebsd.org/D8745
2016-12-23 23:14:53 +00:00
|
|
|
struct mtx nfs_clstate_mutex;
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
/* local functions */
|
|
|
|
static int nfssvc_call(struct thread *, struct nfssvc_args *, struct ucred *);
|
|
|
|
|
2010-03-24 02:02:02 +00:00
|
|
|
#ifdef __NO_STRICT_ALIGNMENT
|
2009-05-04 15:23:58 +00:00
|
|
|
/*
|
|
|
|
* These architectures don't need re-alignment, so just return.
|
|
|
|
*/
|
Revamp the old NFS server's File Handle Affinity (FHA) code so that
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
2013-04-17 21:00:22 +00:00
|
|
|
int
|
|
|
|
newnfs_realign(struct mbuf **pm, int how)
|
2009-05-04 15:23:58 +00:00
|
|
|
{
|
|
|
|
|
Revamp the old NFS server's File Handle Affinity (FHA) code so that
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
2013-04-17 21:00:22 +00:00
|
|
|
return (0);
|
2009-05-04 15:23:58 +00:00
|
|
|
}
|
2010-03-24 02:02:02 +00:00
|
|
|
#else /* !__NO_STRICT_ALIGNMENT */
|
2009-05-04 15:23:58 +00:00
|
|
|
/*
|
2009-05-24 19:46:12 +00:00
|
|
|
* newnfs_realign:
|
2009-05-04 15:23:58 +00:00
|
|
|
*
|
|
|
|
* Check for badly aligned mbuf data and realign by copying the unaligned
|
|
|
|
* portion of the data into a new mbuf chain and freeing the portions
|
|
|
|
* of the old chain that were replaced.
|
|
|
|
*
|
|
|
|
* We cannot simply realign the data within the existing mbuf chain
|
|
|
|
* because the underlying buffers may contain other rpc commands and
|
|
|
|
* we cannot afford to overwrite them.
|
|
|
|
*
|
|
|
|
* We would prefer to avoid this situation entirely. The situation does
|
2016-04-29 16:07:25 +00:00
|
|
|
* not occur with NFS/UDP and is supposed to only occasionally occur
|
2009-05-04 15:23:58 +00:00
|
|
|
* with TCP. Use vfs.nfs.realign_count and realign_test to check this.
|
2009-05-24 19:46:12 +00:00
|
|
|
*
|
2009-05-04 15:23:58 +00:00
|
|
|
*/
|
Revamp the old NFS server's File Handle Affinity (FHA) code so that
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
2013-04-17 21:00:22 +00:00
|
|
|
int
|
|
|
|
newnfs_realign(struct mbuf **pm, int how)
|
2009-05-04 15:23:58 +00:00
|
|
|
{
|
2009-05-24 19:46:12 +00:00
|
|
|
struct mbuf *m, *n;
|
|
|
|
int off, space;
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
++nfs_realign_test;
|
|
|
|
while ((m = *pm) != NULL) {
|
|
|
|
if ((m->m_len & 0x3) || (mtod(m, intptr_t) & 0x3)) {
|
2009-05-24 19:46:12 +00:00
|
|
|
/*
|
|
|
|
* NB: we can't depend on m_pkthdr.len to help us
|
|
|
|
* decide what to do here. May not be worth doing
|
|
|
|
* the m_length calculation as m_copyback will
|
|
|
|
* expand the mbuf chain below as needed.
|
|
|
|
*/
|
|
|
|
space = m_length(m, NULL);
|
|
|
|
if (space >= MINCLSIZE) {
|
|
|
|
/* NB: m_copyback handles space > MCLBYTES */
|
Revamp the old NFS server's File Handle Affinity (FHA) code so that
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
2013-04-17 21:00:22 +00:00
|
|
|
n = m_getcl(how, MT_DATA, 0);
|
2009-05-24 19:46:12 +00:00
|
|
|
} else
|
Revamp the old NFS server's File Handle Affinity (FHA) code so that
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
2013-04-17 21:00:22 +00:00
|
|
|
n = m_get(how, MT_DATA);
|
2009-05-24 19:46:12 +00:00
|
|
|
if (n == NULL)
|
Revamp the old NFS server's File Handle Affinity (FHA) code so that
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
2013-04-17 21:00:22 +00:00
|
|
|
return (ENOMEM);
|
2009-05-24 19:46:12 +00:00
|
|
|
/*
|
|
|
|
* Align the remainder of the mbuf chain.
|
|
|
|
*/
|
2009-05-04 15:23:58 +00:00
|
|
|
n->m_len = 0;
|
2009-05-24 19:46:12 +00:00
|
|
|
off = 0;
|
|
|
|
while (m != NULL) {
|
|
|
|
m_copyback(n, off, m->m_len, mtod(m, caddr_t));
|
|
|
|
off += m->m_len;
|
|
|
|
m = m->m_next;
|
|
|
|
}
|
|
|
|
m_freem(*pm);
|
|
|
|
*pm = n;
|
|
|
|
++nfs_realign_count;
|
2009-05-04 15:23:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
pm = &m->m_next;
|
|
|
|
}
|
Revamp the old NFS server's File Handle Affinity (FHA) code so that
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
2013-04-17 21:00:22 +00:00
|
|
|
|
|
|
|
return (0);
|
2009-05-04 15:23:58 +00:00
|
|
|
}
|
2010-03-24 02:02:02 +00:00
|
|
|
#endif /* __NO_STRICT_ALIGNMENT */
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
#ifdef notdef
|
|
|
|
static void
|
|
|
|
nfsrv_object_create(struct vnode *vp, struct thread *td)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (vp == NULL || vp->v_type != VREG)
|
|
|
|
return;
|
|
|
|
(void) vfs_object_create(vp, td, td->td_ucred);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look up a file name. Basically just initialize stuff and call namei().
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
nfsrv_lookupfilename(struct nameidata *ndp, char *fname, NFSPROC_T *p)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2012-10-22 17:50:54 +00:00
|
|
|
NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, fname,
|
2010-07-19 23:33:42 +00:00
|
|
|
p);
|
2009-05-04 15:23:58 +00:00
|
|
|
error = namei(ndp);
|
|
|
|
if (!error) {
|
|
|
|
NDFREE(ndp, NDF_ONLY_PNBUF);
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy NFS uid, gids to the cred structure.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
newnfs_copycred(struct nfscred *nfscr, struct ucred *cr)
|
|
|
|
{
|
|
|
|
|
2010-04-15 22:57:30 +00:00
|
|
|
KASSERT(nfscr->nfsc_ngroups >= 0,
|
|
|
|
("newnfs_copycred: negative nfsc_ngroups"));
|
2009-05-04 15:23:58 +00:00
|
|
|
cr->cr_uid = nfscr->nfsc_uid;
|
2009-06-19 17:10:35 +00:00
|
|
|
crsetgroups(cr, nfscr->nfsc_ngroups, nfscr->nfsc_groups);
|
2009-05-04 15:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map args from nfsmsleep() to msleep().
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
nfsmsleep(void *chan, void *mutex, int prio, const char *wmesg,
|
|
|
|
struct timespec *ts)
|
|
|
|
{
|
|
|
|
u_int64_t nsecval;
|
|
|
|
int error, timeo;
|
|
|
|
|
|
|
|
if (ts) {
|
|
|
|
timeo = hz * ts->tv_sec;
|
|
|
|
nsecval = (u_int64_t)ts->tv_nsec;
|
|
|
|
nsecval = ((nsecval * ((u_int64_t)hz)) + 500000000) /
|
|
|
|
1000000000;
|
|
|
|
timeo += (int)nsecval;
|
|
|
|
} else {
|
|
|
|
timeo = 0;
|
|
|
|
}
|
|
|
|
error = msleep(chan, (struct mtx *)mutex, prio, wmesg, timeo);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the file system info for the server. For now, just assume FFS.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nfsvno_getfs(struct nfsfsinfo *sip, int isdgram)
|
|
|
|
{
|
|
|
|
int pref;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* There should be file system VFS OP(s) to get this information.
|
|
|
|
* For now, assume ufs.
|
|
|
|
*/
|
|
|
|
if (isdgram)
|
|
|
|
pref = NFS_MAXDGRAMDATA;
|
|
|
|
else
|
2015-04-16 22:35:15 +00:00
|
|
|
pref = NFS_SRVMAXIO;
|
|
|
|
sip->fs_rtmax = NFS_SRVMAXIO;
|
2009-05-04 15:23:58 +00:00
|
|
|
sip->fs_rtpref = pref;
|
|
|
|
sip->fs_rtmult = NFS_FABLKSIZE;
|
2015-04-16 22:35:15 +00:00
|
|
|
sip->fs_wtmax = NFS_SRVMAXIO;
|
2009-05-04 15:23:58 +00:00
|
|
|
sip->fs_wtpref = pref;
|
|
|
|
sip->fs_wtmult = NFS_FABLKSIZE;
|
|
|
|
sip->fs_dtpref = pref;
|
|
|
|
sip->fs_maxfilesize = 0xffffffffffffffffull;
|
|
|
|
sip->fs_timedelta.tv_sec = 0;
|
|
|
|
sip->fs_timedelta.tv_nsec = 1;
|
|
|
|
sip->fs_properties = (NFSV3FSINFO_LINK |
|
|
|
|
NFSV3FSINFO_SYMLINK | NFSV3FSINFO_HOMOGENEOUS |
|
|
|
|
NFSV3FSINFO_CANSETTIME);
|
|
|
|
}
|
|
|
|
|
2011-07-16 08:05:17 +00:00
|
|
|
/*
|
|
|
|
* Do the pathconf vnode op.
|
|
|
|
*/
|
|
|
|
int
|
2018-01-17 22:36:58 +00:00
|
|
|
nfsvno_pathconf(struct vnode *vp, int flag, long *retf,
|
2011-07-16 08:05:17 +00:00
|
|
|
struct ucred *cred, struct thread *p)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = VOP_PATHCONF(vp, flag, retf);
|
|
|
|
if (error == EOPNOTSUPP || error == EINVAL) {
|
|
|
|
/*
|
|
|
|
* Some file systems return EINVAL for name arguments not
|
|
|
|
* supported and some return EOPNOTSUPP for this case.
|
|
|
|
* So the NFSv3 Pathconf RPC doesn't fail for these cases,
|
|
|
|
* just fake them.
|
|
|
|
*/
|
|
|
|
switch (flag) {
|
|
|
|
case _PC_LINK_MAX:
|
2017-12-19 19:18:48 +00:00
|
|
|
*retf = NFS_LINK_MAX;
|
2011-07-16 08:05:17 +00:00
|
|
|
break;
|
|
|
|
case _PC_NAME_MAX:
|
|
|
|
*retf = NAME_MAX;
|
|
|
|
break;
|
|
|
|
case _PC_CHOWN_RESTRICTED:
|
|
|
|
*retf = 1;
|
|
|
|
break;
|
|
|
|
case _PC_NO_TRUNC:
|
|
|
|
*retf = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Only happens if a _PC_xxx is added to the server,
|
|
|
|
* but this isn't updated.
|
|
|
|
*/
|
|
|
|
*retf = 0;
|
|
|
|
printf("nfsrvd pathconf flag=%d not supp\n", flag);
|
2016-04-10 23:07:00 +00:00
|
|
|
}
|
2011-07-16 08:05:17 +00:00
|
|
|
error = 0;
|
|
|
|
}
|
2011-07-16 08:51:09 +00:00
|
|
|
NFSEXITCODE(error);
|
2011-07-16 08:05:17 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2009-05-04 15:23:58 +00:00
|
|
|
/* Fake nfsrv_atroot. Just return 0 */
|
|
|
|
int
|
2017-06-18 21:48:31 +00:00
|
|
|
nfsrv_atroot(struct vnode *vp, uint64_t *retp)
|
2009-05-04 15:23:58 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the credentials to refer to root.
|
|
|
|
* If only the various BSDen could agree on whether cr_gid is a separate
|
|
|
|
* field or cr_groups[0]...
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
newnfs_setroot(struct ucred *cred)
|
|
|
|
{
|
|
|
|
|
|
|
|
cred->cr_uid = 0;
|
|
|
|
cred->cr_groups[0] = 0;
|
|
|
|
cred->cr_ngroups = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the client credential. Used for Renew and recovery.
|
|
|
|
*/
|
|
|
|
struct ucred *
|
|
|
|
newnfs_getcred(void)
|
|
|
|
{
|
|
|
|
struct ucred *cred;
|
|
|
|
struct thread *td = curthread;
|
|
|
|
|
|
|
|
cred = crdup(td->td_ucred);
|
|
|
|
newnfs_setroot(cred);
|
|
|
|
return (cred);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Nfs timer routine
|
|
|
|
* Call the nfsd's timer function once/sec.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
newnfs_timer(void *arg)
|
|
|
|
{
|
|
|
|
static time_t lasttime = 0;
|
|
|
|
/*
|
|
|
|
* Call the server timer, if set up.
|
|
|
|
* The argument indicates if it is the next second and therefore
|
|
|
|
* leases should be checked.
|
|
|
|
*/
|
|
|
|
if (lasttime != NFSD_MONOSEC) {
|
|
|
|
lasttime = NFSD_MONOSEC;
|
|
|
|
if (nfsd_call_servertimer != NULL)
|
|
|
|
(*nfsd_call_servertimer)();
|
|
|
|
}
|
|
|
|
callout_reset(&newnfsd_callout, nfscl_ticks, newnfs_timer, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2010-04-24 22:52:14 +00:00
|
|
|
* Sleep for a short period of time unless errval == NFSERR_GRACE, where
|
|
|
|
* the sleep should be for 5 seconds.
|
2009-05-04 15:23:58 +00:00
|
|
|
* Since lbolt doesn't exist in FreeBSD-CURRENT, just use a timeout on
|
|
|
|
* an event that never gets a wakeup. Only return EINTR or 0.
|
|
|
|
*/
|
|
|
|
int
|
2010-04-24 22:52:14 +00:00
|
|
|
nfs_catnap(int prio, int errval, const char *wmesg)
|
2009-05-04 15:23:58 +00:00
|
|
|
{
|
|
|
|
static int non_event;
|
|
|
|
int ret;
|
|
|
|
|
2010-04-24 22:52:14 +00:00
|
|
|
if (errval == NFSERR_GRACE)
|
|
|
|
ret = tsleep(&non_event, prio, wmesg, 5 * hz);
|
|
|
|
else
|
|
|
|
ret = tsleep(&non_event, prio, wmesg, 1);
|
2009-05-04 15:23:58 +00:00
|
|
|
if (ret != EINTR)
|
|
|
|
ret = 0;
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get referral. For now, just fail.
|
|
|
|
*/
|
|
|
|
struct nfsreferral *
|
|
|
|
nfsv4root_getreferral(struct vnode *vp, struct vnode *dvp, u_int32_t fileno)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfssvc_nfscommon(struct thread *td, struct nfssvc_args *uap)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = nfssvc_call(td, uap, td->td_ucred);
|
2011-07-16 08:51:09 +00:00
|
|
|
NFSEXITCODE(error);
|
2009-05-04 15:23:58 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfssvc_call(struct thread *p, struct nfssvc_args *uap, struct ucred *cred)
|
|
|
|
{
|
2016-08-12 22:44:59 +00:00
|
|
|
int error = EINVAL, i, j;
|
2009-05-04 15:23:58 +00:00
|
|
|
struct nfsd_idargs nid;
|
2015-11-30 21:54:27 +00:00
|
|
|
struct nfsd_oidargs onid;
|
2016-08-12 22:44:59 +00:00
|
|
|
struct {
|
|
|
|
int vers; /* Just the first field of nfsstats. */
|
|
|
|
} nfsstatver;
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
if (uap->flag & NFSSVC_IDNAME) {
|
2015-11-30 21:54:27 +00:00
|
|
|
if ((uap->flag & NFSSVC_NEWSTRUCT) != 0)
|
|
|
|
error = copyin(uap->argp, &nid, sizeof(nid));
|
|
|
|
else {
|
|
|
|
error = copyin(uap->argp, &onid, sizeof(onid));
|
|
|
|
if (error == 0) {
|
|
|
|
nid.nid_flag = onid.nid_flag;
|
|
|
|
nid.nid_uid = onid.nid_uid;
|
|
|
|
nid.nid_gid = onid.nid_gid;
|
|
|
|
nid.nid_usermax = onid.nid_usermax;
|
|
|
|
nid.nid_usertimeout = onid.nid_usertimeout;
|
|
|
|
nid.nid_name = onid.nid_name;
|
|
|
|
nid.nid_namelen = onid.nid_namelen;
|
|
|
|
nid.nid_ngroup = 0;
|
|
|
|
nid.nid_grps = NULL;
|
|
|
|
}
|
|
|
|
}
|
2009-05-04 15:23:58 +00:00
|
|
|
if (error)
|
2011-07-16 08:51:09 +00:00
|
|
|
goto out;
|
2009-05-04 15:23:58 +00:00
|
|
|
error = nfssvc_idname(&nid);
|
2011-07-16 08:51:09 +00:00
|
|
|
goto out;
|
2009-05-04 15:23:58 +00:00
|
|
|
} else if (uap->flag & NFSSVC_GETSTATS) {
|
2016-08-12 22:44:59 +00:00
|
|
|
if ((uap->flag & NFSSVC_NEWSTRUCT) == 0) {
|
|
|
|
/* Copy fields to the old ext_nfsstat structure. */
|
|
|
|
oldnfsstats.attrcache_hits =
|
|
|
|
nfsstatsv1.attrcache_hits;
|
|
|
|
oldnfsstats.attrcache_misses =
|
|
|
|
nfsstatsv1.attrcache_misses;
|
|
|
|
oldnfsstats.lookupcache_hits =
|
|
|
|
nfsstatsv1.lookupcache_hits;
|
|
|
|
oldnfsstats.lookupcache_misses =
|
|
|
|
nfsstatsv1.lookupcache_misses;
|
|
|
|
oldnfsstats.direofcache_hits =
|
|
|
|
nfsstatsv1.direofcache_hits;
|
|
|
|
oldnfsstats.direofcache_misses =
|
|
|
|
nfsstatsv1.direofcache_misses;
|
|
|
|
oldnfsstats.accesscache_hits =
|
|
|
|
nfsstatsv1.accesscache_hits;
|
|
|
|
oldnfsstats.accesscache_misses =
|
|
|
|
nfsstatsv1.accesscache_misses;
|
|
|
|
oldnfsstats.biocache_reads =
|
|
|
|
nfsstatsv1.biocache_reads;
|
|
|
|
oldnfsstats.read_bios =
|
|
|
|
nfsstatsv1.read_bios;
|
|
|
|
oldnfsstats.read_physios =
|
|
|
|
nfsstatsv1.read_physios;
|
|
|
|
oldnfsstats.biocache_writes =
|
|
|
|
nfsstatsv1.biocache_writes;
|
|
|
|
oldnfsstats.write_bios =
|
|
|
|
nfsstatsv1.write_bios;
|
|
|
|
oldnfsstats.write_physios =
|
|
|
|
nfsstatsv1.write_physios;
|
|
|
|
oldnfsstats.biocache_readlinks =
|
|
|
|
nfsstatsv1.biocache_readlinks;
|
|
|
|
oldnfsstats.readlink_bios =
|
|
|
|
nfsstatsv1.readlink_bios;
|
|
|
|
oldnfsstats.biocache_readdirs =
|
|
|
|
nfsstatsv1.biocache_readdirs;
|
|
|
|
oldnfsstats.readdir_bios =
|
|
|
|
nfsstatsv1.readdir_bios;
|
|
|
|
for (i = 0; i < NFSV4_NPROCS; i++)
|
|
|
|
oldnfsstats.rpccnt[i] = nfsstatsv1.rpccnt[i];
|
|
|
|
oldnfsstats.rpcretries = nfsstatsv1.rpcretries;
|
|
|
|
for (i = 0; i < NFSV4OP_NOPS; i++)
|
|
|
|
oldnfsstats.srvrpccnt[i] =
|
|
|
|
nfsstatsv1.srvrpccnt[i];
|
|
|
|
for (i = NFSV42_NOPS, j = NFSV4OP_NOPS;
|
|
|
|
i < NFSV42_NOPS + NFSV4OP_FAKENOPS; i++, j++)
|
|
|
|
oldnfsstats.srvrpccnt[j] =
|
|
|
|
nfsstatsv1.srvrpccnt[i];
|
|
|
|
oldnfsstats.srvrpc_errs = nfsstatsv1.srvrpc_errs;
|
|
|
|
oldnfsstats.srv_errs = nfsstatsv1.srv_errs;
|
|
|
|
oldnfsstats.rpcrequests = nfsstatsv1.rpcrequests;
|
|
|
|
oldnfsstats.rpctimeouts = nfsstatsv1.rpctimeouts;
|
|
|
|
oldnfsstats.rpcunexpected = nfsstatsv1.rpcunexpected;
|
|
|
|
oldnfsstats.rpcinvalid = nfsstatsv1.rpcinvalid;
|
|
|
|
oldnfsstats.srvcache_inproghits =
|
|
|
|
nfsstatsv1.srvcache_inproghits;
|
|
|
|
oldnfsstats.srvcache_idemdonehits =
|
|
|
|
nfsstatsv1.srvcache_idemdonehits;
|
|
|
|
oldnfsstats.srvcache_nonidemdonehits =
|
|
|
|
nfsstatsv1.srvcache_nonidemdonehits;
|
|
|
|
oldnfsstats.srvcache_misses =
|
|
|
|
nfsstatsv1.srvcache_misses;
|
|
|
|
oldnfsstats.srvcache_tcppeak =
|
|
|
|
nfsstatsv1.srvcache_tcppeak;
|
|
|
|
oldnfsstats.srvcache_size = nfsstatsv1.srvcache_size;
|
|
|
|
oldnfsstats.srvclients = nfsstatsv1.srvclients;
|
|
|
|
oldnfsstats.srvopenowners = nfsstatsv1.srvopenowners;
|
|
|
|
oldnfsstats.srvopens = nfsstatsv1.srvopens;
|
|
|
|
oldnfsstats.srvlockowners = nfsstatsv1.srvlockowners;
|
|
|
|
oldnfsstats.srvlocks = nfsstatsv1.srvlocks;
|
|
|
|
oldnfsstats.srvdelegates = nfsstatsv1.srvdelegates;
|
|
|
|
for (i = 0; i < NFSV4OP_CBNOPS; i++)
|
|
|
|
oldnfsstats.cbrpccnt[i] =
|
|
|
|
nfsstatsv1.cbrpccnt[i];
|
|
|
|
oldnfsstats.clopenowners = nfsstatsv1.clopenowners;
|
|
|
|
oldnfsstats.clopens = nfsstatsv1.clopens;
|
|
|
|
oldnfsstats.cllockowners = nfsstatsv1.cllockowners;
|
|
|
|
oldnfsstats.cllocks = nfsstatsv1.cllocks;
|
|
|
|
oldnfsstats.cldelegates = nfsstatsv1.cldelegates;
|
|
|
|
oldnfsstats.cllocalopenowners =
|
|
|
|
nfsstatsv1.cllocalopenowners;
|
|
|
|
oldnfsstats.cllocalopens = nfsstatsv1.cllocalopens;
|
|
|
|
oldnfsstats.cllocallockowners =
|
|
|
|
nfsstatsv1.cllocallockowners;
|
|
|
|
oldnfsstats.cllocallocks = nfsstatsv1.cllocallocks;
|
|
|
|
error = copyout(&oldnfsstats, uap->argp,
|
|
|
|
sizeof (oldnfsstats));
|
|
|
|
} else {
|
|
|
|
error = copyin(uap->argp, &nfsstatver,
|
|
|
|
sizeof(nfsstatver));
|
|
|
|
if (error == 0 && nfsstatver.vers != NFSSTATS_V1)
|
|
|
|
error = EPERM;
|
|
|
|
if (error == 0)
|
|
|
|
error = copyout(&nfsstatsv1, uap->argp,
|
|
|
|
sizeof (nfsstatsv1));
|
|
|
|
}
|
2011-05-04 13:36:18 +00:00
|
|
|
if (error == 0) {
|
|
|
|
if ((uap->flag & NFSSVC_ZEROCLTSTATS) != 0) {
|
2016-08-12 22:44:59 +00:00
|
|
|
nfsstatsv1.attrcache_hits = 0;
|
|
|
|
nfsstatsv1.attrcache_misses = 0;
|
|
|
|
nfsstatsv1.lookupcache_hits = 0;
|
|
|
|
nfsstatsv1.lookupcache_misses = 0;
|
|
|
|
nfsstatsv1.direofcache_hits = 0;
|
|
|
|
nfsstatsv1.direofcache_misses = 0;
|
|
|
|
nfsstatsv1.accesscache_hits = 0;
|
|
|
|
nfsstatsv1.accesscache_misses = 0;
|
|
|
|
nfsstatsv1.biocache_reads = 0;
|
|
|
|
nfsstatsv1.read_bios = 0;
|
|
|
|
nfsstatsv1.read_physios = 0;
|
|
|
|
nfsstatsv1.biocache_writes = 0;
|
|
|
|
nfsstatsv1.write_bios = 0;
|
|
|
|
nfsstatsv1.write_physios = 0;
|
|
|
|
nfsstatsv1.biocache_readlinks = 0;
|
|
|
|
nfsstatsv1.readlink_bios = 0;
|
|
|
|
nfsstatsv1.biocache_readdirs = 0;
|
|
|
|
nfsstatsv1.readdir_bios = 0;
|
|
|
|
nfsstatsv1.rpcretries = 0;
|
|
|
|
nfsstatsv1.rpcrequests = 0;
|
|
|
|
nfsstatsv1.rpctimeouts = 0;
|
|
|
|
nfsstatsv1.rpcunexpected = 0;
|
|
|
|
nfsstatsv1.rpcinvalid = 0;
|
|
|
|
bzero(nfsstatsv1.rpccnt,
|
|
|
|
sizeof(nfsstatsv1.rpccnt));
|
2011-05-04 13:36:18 +00:00
|
|
|
}
|
|
|
|
if ((uap->flag & NFSSVC_ZEROSRVSTATS) != 0) {
|
2016-08-12 22:44:59 +00:00
|
|
|
nfsstatsv1.srvrpc_errs = 0;
|
|
|
|
nfsstatsv1.srv_errs = 0;
|
|
|
|
nfsstatsv1.srvcache_inproghits = 0;
|
|
|
|
nfsstatsv1.srvcache_idemdonehits = 0;
|
|
|
|
nfsstatsv1.srvcache_nonidemdonehits = 0;
|
|
|
|
nfsstatsv1.srvcache_misses = 0;
|
|
|
|
nfsstatsv1.srvcache_tcppeak = 0;
|
|
|
|
bzero(nfsstatsv1.srvrpccnt,
|
|
|
|
sizeof(nfsstatsv1.srvrpccnt));
|
|
|
|
bzero(nfsstatsv1.cbrpccnt,
|
|
|
|
sizeof(nfsstatsv1.cbrpccnt));
|
2011-05-04 13:36:18 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-16 08:51:09 +00:00
|
|
|
goto out;
|
2009-05-04 15:23:58 +00:00
|
|
|
} else if (uap->flag & NFSSVC_NFSUSERDPORT) {
|
|
|
|
u_short sockport;
|
2019-04-06 21:53:46 +00:00
|
|
|
struct nfsuserd_args nargs;
|
2019-04-04 23:30:27 +00:00
|
|
|
|
2019-04-06 21:53:46 +00:00
|
|
|
if ((uap->flag & NFSSVC_NEWSTRUCT) == 0) {
|
2017-07-06 00:53:12 +00:00
|
|
|
error = copyin(uap->argp, (caddr_t)&sockport,
|
|
|
|
sizeof (u_short));
|
2019-04-06 21:53:46 +00:00
|
|
|
if (error == 0) {
|
|
|
|
nargs.nuserd_family = AF_INET;
|
|
|
|
nargs.nuserd_port = sockport;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* New nfsuserd_args structure, which indicates
|
|
|
|
* which IP version to use along with the port#.
|
|
|
|
*/
|
|
|
|
error = copyin(uap->argp, &nargs, sizeof(nargs));
|
|
|
|
}
|
2019-04-04 23:30:27 +00:00
|
|
|
if (!error)
|
2019-04-06 21:53:46 +00:00
|
|
|
error = nfsrv_nfsuserdport(&nargs, p);
|
2009-05-04 15:23:58 +00:00
|
|
|
} else if (uap->flag & NFSSVC_NFSUSERDDELPORT) {
|
|
|
|
nfsrv_nfsuserddelport();
|
|
|
|
error = 0;
|
|
|
|
}
|
2011-07-16 08:51:09 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
NFSEXITCODE(error);
|
2009-05-04 15:23:58 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* called by all three modevent routines, so that it gets things
|
|
|
|
* initialized soon enough.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
newnfs_portinit(void)
|
|
|
|
{
|
|
|
|
static int inited = 0;
|
|
|
|
|
|
|
|
if (inited)
|
|
|
|
return;
|
|
|
|
inited = 1;
|
|
|
|
/* Initialize SMP locks used by both client and server. */
|
|
|
|
mtx_init(&newnfsd_mtx, "newnfsd_mtx", NULL, MTX_DEF);
|
|
|
|
mtx_init(&nfs_state_mutex, "nfs_state_mutex", NULL, MTX_DEF);
|
Fix NFSv4.1 client recovery from NFS4ERR_BAD_SESSION errors.
For most NFSv4.1 servers, a NFS4ERR_BAD_SESSION error is a rare failure
that indicates that the server has lost session/open/lock state.
However, recent testing by cperciva@ against the AmazonEFS server found
several problems with client recovery from this due to it generating this
failure frequently.
Briefly, the problems fixed are:
- If all session slots were in use at the time of the failure, some processes
would continue to loop waiting for a slot on the old session forever.
- If an RPC that doesn't use open/lock state failed with NFS4ERR_BAD_SESSION,
it would fail the RPC/syscall instead of initiating recovery and then
looping to retry the RPC.
- If a successful reply to an RPC for an old session wasn't processed
until after a new session was created for a NFS4ERR_BAD_SESSION error,
it would erroneously update the new session and corrupt it.
- The use of the first element of the session list in the nfs mount
structure (which is always the current metadata session) was slightly
racey. With changes for the above problems it became more racey, so all
uses of this head pointer was wrapped with a NFSLOCKMNT()/NFSUNLOCKMNT().
- Although the kernel malloc() usually allocates more bytes than requested
and, as such, this wouldn't have caused problems, the allocation of a
session structure was 1 byte smaller than it should have been.
(Null termination byte for the string not included in byte count.)
There are probably still problems with a pNFS data server that fails
with NFS4ERR_BAD_SESSION, but I have no server that does this to test
against (the AmazonEFS server doesn't do pNFS), so I can't fix these yet.
Although this patch is fairly large, it should only affect the handling
of NFS4ERR_BAD_SESSION error replies from an NFSv4.1 server.
Thanks go to cperciva@ for the extension testing he did to help isolate/fix
these problems.
Reported by: cperciva
Tested by: cperciva
MFC after: 3 months
Differential Revision: https://reviews.freebsd.org/D8745
2016-12-23 23:14:53 +00:00
|
|
|
mtx_init(&nfs_clstate_mutex, "nfs_clstate_mutex", NULL, MTX_DEF);
|
2009-05-04 15:23:58 +00:00
|
|
|
}
|
|
|
|
|
2009-05-27 15:16:56 +00:00
|
|
|
/*
|
|
|
|
* Determine if the file system supports NFSv4 ACLs.
|
|
|
|
* Return 1 if it does, 0 otherwise.
|
|
|
|
*/
|
|
|
|
int
|
2011-04-14 23:46:15 +00:00
|
|
|
nfs_supportsnfsv4acls(struct vnode *vp)
|
2009-05-27 15:16:56 +00:00
|
|
|
{
|
2011-04-14 23:46:15 +00:00
|
|
|
int error;
|
2018-01-17 22:36:58 +00:00
|
|
|
long retval;
|
2009-05-27 15:16:56 +00:00
|
|
|
|
2011-04-14 23:46:15 +00:00
|
|
|
ASSERT_VOP_LOCKED(vp, "nfs supports nfsv4acls");
|
|
|
|
|
|
|
|
if (nfsrv_useacl == 0)
|
2009-05-27 15:16:56 +00:00
|
|
|
return (0);
|
2011-07-17 03:44:05 +00:00
|
|
|
error = VOP_PATHCONF(vp, _PC_ACL_NFS4, &retval);
|
2011-04-14 23:46:15 +00:00
|
|
|
if (error == 0 && retval != 0)
|
2009-05-27 15:16:56 +00:00
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2017-10-16 23:28:12 +00:00
|
|
|
/*
|
|
|
|
* These are the first fields of all the context structures passed into
|
|
|
|
* nfs_pnfsio().
|
|
|
|
*/
|
|
|
|
struct pnfsio {
|
|
|
|
int done;
|
|
|
|
int inprog;
|
|
|
|
struct task tsk;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do a mirror I/O on a pNFS thread.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
nfs_pnfsio(task_fn_t *func, void *context)
|
|
|
|
{
|
|
|
|
struct pnfsio *pio;
|
|
|
|
int ret;
|
|
|
|
static struct taskqueue *pnfsioq = NULL;
|
|
|
|
|
|
|
|
pio = (struct pnfsio *)context;
|
|
|
|
if (pnfsioq == NULL) {
|
|
|
|
if (nfs_pnfsiothreads == 0)
|
2018-06-02 00:11:26 +00:00
|
|
|
return (EPERM);
|
|
|
|
if (nfs_pnfsiothreads < 0)
|
2017-10-16 23:28:12 +00:00
|
|
|
nfs_pnfsiothreads = mp_ncpus * 4;
|
|
|
|
pnfsioq = taskqueue_create("pnfsioq", M_WAITOK,
|
|
|
|
taskqueue_thread_enqueue, &pnfsioq);
|
|
|
|
if (pnfsioq == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
ret = taskqueue_start_threads(&pnfsioq, nfs_pnfsiothreads,
|
|
|
|
0, "pnfsiot");
|
|
|
|
if (ret != 0) {
|
|
|
|
taskqueue_free(pnfsioq);
|
|
|
|
pnfsioq = NULL;
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pio->inprog = 1;
|
|
|
|
TASK_INIT(&pio->tsk, 0, func, context);
|
|
|
|
ret = taskqueue_enqueue(pnfsioq, &pio->tsk);
|
|
|
|
if (ret != 0)
|
|
|
|
pio->inprog = 0;
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2009-05-04 15:23:58 +00:00
|
|
|
extern int (*nfsd_call_nfscommon)(struct thread *, struct nfssvc_args *);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called once to initialize data structures...
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
nfscommon_modevent(module_t mod, int type, void *data)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
static int loaded = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
if (loaded)
|
2011-07-16 08:51:09 +00:00
|
|
|
goto out;
|
2009-05-04 15:23:58 +00:00
|
|
|
newnfs_portinit();
|
|
|
|
mtx_init(&nfs_nameid_mutex, "nfs_nameid_mutex", NULL, MTX_DEF);
|
|
|
|
mtx_init(&nfs_sockl_mutex, "nfs_sockl_mutex", NULL, MTX_DEF);
|
|
|
|
mtx_init(&nfs_slock_mutex, "nfs_slock_mutex", NULL, MTX_DEF);
|
|
|
|
mtx_init(&nfs_req_mutex, "nfs_req_mutex", NULL, MTX_DEF);
|
|
|
|
mtx_init(&nfsrv_nfsuserdsock.nr_mtx, "nfsuserd", NULL,
|
|
|
|
MTX_DEF);
|
Merge the pNFS server code from projects/pnfs-planb-server into head.
This code merge adds a pNFS service to the NFSv4.1 server. Although it is
a large commit it should not affect behaviour for a non-pNFS NFS server.
Some documentation on how this works can be found at:
http://people.freebsd.org/~rmacklem/pnfs-planb-setup.txt
and will hopefully be turned into a proper document soon.
This is a merge of the kernel code. Userland and man page changes will
come soon, once the dust settles on this merge.
It has passed a "make universe", so I hope it will not cause build problems.
It also adds NFSv4.1 server support for the "current stateid".
Here is a brief overview of the pNFS service:
A pNFS service separates the Read/Write oeprations from all the other NFSv4.1
Metadata operations. It is hoped that this separation allows a pNFS service
to be configured that exceeds the limits of a single NFS server for either
storage capacity and/or I/O bandwidth.
It is possible to configure mirroring within the data servers (DSs) so that
the data storage file for an MDS file will be mirrored on two or more of
the DSs.
When this is used, failure of a DS will not stop the pNFS service and a
failed DS can be recovered once repaired while the pNFS service continues
to operate. Although two way mirroring would be the norm, it is possible
to set a mirroring level of up to four or the number of DSs, whichever is
less.
The Metadata server will always be a single point of failure,
just as a single NFS server is.
A Plan B pNFS service consists of a single MetaData Server (MDS) and K
Data Servers (DS), all of which are recent FreeBSD systems.
Clients will mount the MDS as they would a single NFS server.
When files are created, the MDS creates a file tree identical to what a
single NFS server creates, except that all the regular (VREG) files will
be empty. As such, if you look at the exported tree on the MDS directly
on the MDS server (not via an NFS mount), the files will all be of size 0.
Each of these files will also have two extended attributes in the system
attribute name space:
pnfsd.dsfile - This extended attrbute stores the information that
the MDS needs to find the data storage file(s) on DS(s) for this file.
pnfsd.dsattr - This extended attribute stores the Size, AccessTime, ModifyTime
and Change attributes for the file, so that the MDS doesn't need to
acquire the attributes from the DS for every Getattr operation.
For each regular (VREG) file, the MDS creates a data storage file on one
(or more if mirroring is enabled) of the DSs in one of the "dsNN"
subdirectories. The name of this file is the file handle
of the file on the MDS in hexadecimal so that the name is unique.
The DSs use subdirectories named "ds0" to "dsN" so that no one directory
gets too large. The value of "N" is set via the sysctl vfs.nfsd.dsdirsize
on the MDS, with the default being 20.
For production servers that will store a lot of files, this value should
probably be much larger.
It can be increased when the "nfsd" daemon is not running on the MDS,
once the "dsK" directories are created.
For pNFS aware NFSv4.1 clients, the FreeBSD server will return two pieces
of information to the client that allows it to do I/O directly to the DS.
DeviceInfo - This is relatively static information that defines what a DS
is. The critical bits of information returned by the FreeBSD
server is the IP address of the DS and, for the Flexible
File layout, that NFSv4.1 is to be used and that it is
"tightly coupled".
There is a "deviceid" which identifies the DeviceInfo.
Layout - This is per file and can be recalled by the server when it
is no longer valid. For the FreeBSD server, there is support
for two types of layout, call File and Flexible File layout.
Both allow the client to do I/O on the DS via NFSv4.1 I/O
operations. The Flexible File layout is a more recent variant
that allows specification of mirrors, where the client is
expected to do writes to all mirrors to maintain them in a
consistent state. The Flexible File layout also allows the
client to report I/O errors for a DS back to the MDS.
The Flexible File layout supports two variants referred to as
"tightly coupled" vs "loosely coupled". The FreeBSD server always
uses the "tightly coupled" variant where the client uses the
same credentials to do I/O on the DS as it would on the MDS.
For the "loosely coupled" variant, the layout specifies a
synthetic user/group that the client uses to do I/O on the DS.
The FreeBSD server does not do striping and always returns
layouts for the entire file. The critical information in a layout
is Read vs Read/Writea and DeviceID(s) that identify which
DS(s) the data is stored on.
At this time, the MDS generates File Layout layouts to NFSv4.1 clients
that know how to do pNFS for the non-mirrored DS case unless the sysctl
vfs.nfsd.default_flexfile is set non-zero, in which case Flexible File
layouts are generated.
The mirrored DS configuration always generates Flexible File layouts.
For NFS clients that do not support NFSv4.1 pNFS, all I/O operations
are done against the MDS which acts as a proxy for the appropriate DS(s).
When the MDS receives an I/O RPC, it will do the RPC on the DS as a proxy.
If the DS is on the same machine, the MDS/DS will do the RPC on the DS as
a proxy and so on, until the machine runs out of some resource, such as
session slots or mbufs.
As such, DSs must be separate systems from the MDS.
Tested by: james.rose@framestore.com
Relnotes: yes
2018-06-12 19:36:32 +00:00
|
|
|
mtx_init(&nfsrv_dslock_mtx, "nfs4ds", NULL, MTX_DEF);
|
|
|
|
TAILQ_INIT(&nfsrv_devidhead);
|
2015-05-22 17:05:21 +00:00
|
|
|
callout_init(&newnfsd_callout, 1);
|
2009-05-04 15:23:58 +00:00
|
|
|
newnfs_init();
|
|
|
|
nfsd_call_nfscommon = nfssvc_nfscommon;
|
|
|
|
loaded = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOD_UNLOAD:
|
2019-11-28 23:34:23 +00:00
|
|
|
if (newnfs_numnfsd != 0 || nfsrv_nfsuserd != NOTRUNNING ||
|
2009-05-04 15:23:58 +00:00
|
|
|
nfs_numnfscbd != 0) {
|
|
|
|
error = EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nfsd_call_nfscommon = NULL;
|
|
|
|
callout_drain(&newnfsd_callout);
|
2015-12-02 02:47:13 +00:00
|
|
|
/* Clean out the name<-->id cache. */
|
|
|
|
nfsrv_cleanusergroup();
|
2009-05-04 15:23:58 +00:00
|
|
|
/* and get rid of the mutexes */
|
|
|
|
mtx_destroy(&nfs_nameid_mutex);
|
|
|
|
mtx_destroy(&newnfsd_mtx);
|
|
|
|
mtx_destroy(&nfs_state_mutex);
|
Fix NFSv4.1 client recovery from NFS4ERR_BAD_SESSION errors.
For most NFSv4.1 servers, a NFS4ERR_BAD_SESSION error is a rare failure
that indicates that the server has lost session/open/lock state.
However, recent testing by cperciva@ against the AmazonEFS server found
several problems with client recovery from this due to it generating this
failure frequently.
Briefly, the problems fixed are:
- If all session slots were in use at the time of the failure, some processes
would continue to loop waiting for a slot on the old session forever.
- If an RPC that doesn't use open/lock state failed with NFS4ERR_BAD_SESSION,
it would fail the RPC/syscall instead of initiating recovery and then
looping to retry the RPC.
- If a successful reply to an RPC for an old session wasn't processed
until after a new session was created for a NFS4ERR_BAD_SESSION error,
it would erroneously update the new session and corrupt it.
- The use of the first element of the session list in the nfs mount
structure (which is always the current metadata session) was slightly
racey. With changes for the above problems it became more racey, so all
uses of this head pointer was wrapped with a NFSLOCKMNT()/NFSUNLOCKMNT().
- Although the kernel malloc() usually allocates more bytes than requested
and, as such, this wouldn't have caused problems, the allocation of a
session structure was 1 byte smaller than it should have been.
(Null termination byte for the string not included in byte count.)
There are probably still problems with a pNFS data server that fails
with NFS4ERR_BAD_SESSION, but I have no server that does this to test
against (the AmazonEFS server doesn't do pNFS), so I can't fix these yet.
Although this patch is fairly large, it should only affect the handling
of NFS4ERR_BAD_SESSION error replies from an NFSv4.1 server.
Thanks go to cperciva@ for the extension testing he did to help isolate/fix
these problems.
Reported by: cperciva
Tested by: cperciva
MFC after: 3 months
Differential Revision: https://reviews.freebsd.org/D8745
2016-12-23 23:14:53 +00:00
|
|
|
mtx_destroy(&nfs_clstate_mutex);
|
2009-05-04 15:23:58 +00:00
|
|
|
mtx_destroy(&nfs_sockl_mutex);
|
|
|
|
mtx_destroy(&nfs_slock_mutex);
|
|
|
|
mtx_destroy(&nfs_req_mutex);
|
|
|
|
mtx_destroy(&nfsrv_nfsuserdsock.nr_mtx);
|
Merge the pNFS server code from projects/pnfs-planb-server into head.
This code merge adds a pNFS service to the NFSv4.1 server. Although it is
a large commit it should not affect behaviour for a non-pNFS NFS server.
Some documentation on how this works can be found at:
http://people.freebsd.org/~rmacklem/pnfs-planb-setup.txt
and will hopefully be turned into a proper document soon.
This is a merge of the kernel code. Userland and man page changes will
come soon, once the dust settles on this merge.
It has passed a "make universe", so I hope it will not cause build problems.
It also adds NFSv4.1 server support for the "current stateid".
Here is a brief overview of the pNFS service:
A pNFS service separates the Read/Write oeprations from all the other NFSv4.1
Metadata operations. It is hoped that this separation allows a pNFS service
to be configured that exceeds the limits of a single NFS server for either
storage capacity and/or I/O bandwidth.
It is possible to configure mirroring within the data servers (DSs) so that
the data storage file for an MDS file will be mirrored on two or more of
the DSs.
When this is used, failure of a DS will not stop the pNFS service and a
failed DS can be recovered once repaired while the pNFS service continues
to operate. Although two way mirroring would be the norm, it is possible
to set a mirroring level of up to four or the number of DSs, whichever is
less.
The Metadata server will always be a single point of failure,
just as a single NFS server is.
A Plan B pNFS service consists of a single MetaData Server (MDS) and K
Data Servers (DS), all of which are recent FreeBSD systems.
Clients will mount the MDS as they would a single NFS server.
When files are created, the MDS creates a file tree identical to what a
single NFS server creates, except that all the regular (VREG) files will
be empty. As such, if you look at the exported tree on the MDS directly
on the MDS server (not via an NFS mount), the files will all be of size 0.
Each of these files will also have two extended attributes in the system
attribute name space:
pnfsd.dsfile - This extended attrbute stores the information that
the MDS needs to find the data storage file(s) on DS(s) for this file.
pnfsd.dsattr - This extended attribute stores the Size, AccessTime, ModifyTime
and Change attributes for the file, so that the MDS doesn't need to
acquire the attributes from the DS for every Getattr operation.
For each regular (VREG) file, the MDS creates a data storage file on one
(or more if mirroring is enabled) of the DSs in one of the "dsNN"
subdirectories. The name of this file is the file handle
of the file on the MDS in hexadecimal so that the name is unique.
The DSs use subdirectories named "ds0" to "dsN" so that no one directory
gets too large. The value of "N" is set via the sysctl vfs.nfsd.dsdirsize
on the MDS, with the default being 20.
For production servers that will store a lot of files, this value should
probably be much larger.
It can be increased when the "nfsd" daemon is not running on the MDS,
once the "dsK" directories are created.
For pNFS aware NFSv4.1 clients, the FreeBSD server will return two pieces
of information to the client that allows it to do I/O directly to the DS.
DeviceInfo - This is relatively static information that defines what a DS
is. The critical bits of information returned by the FreeBSD
server is the IP address of the DS and, for the Flexible
File layout, that NFSv4.1 is to be used and that it is
"tightly coupled".
There is a "deviceid" which identifies the DeviceInfo.
Layout - This is per file and can be recalled by the server when it
is no longer valid. For the FreeBSD server, there is support
for two types of layout, call File and Flexible File layout.
Both allow the client to do I/O on the DS via NFSv4.1 I/O
operations. The Flexible File layout is a more recent variant
that allows specification of mirrors, where the client is
expected to do writes to all mirrors to maintain them in a
consistent state. The Flexible File layout also allows the
client to report I/O errors for a DS back to the MDS.
The Flexible File layout supports two variants referred to as
"tightly coupled" vs "loosely coupled". The FreeBSD server always
uses the "tightly coupled" variant where the client uses the
same credentials to do I/O on the DS as it would on the MDS.
For the "loosely coupled" variant, the layout specifies a
synthetic user/group that the client uses to do I/O on the DS.
The FreeBSD server does not do striping and always returns
layouts for the entire file. The critical information in a layout
is Read vs Read/Writea and DeviceID(s) that identify which
DS(s) the data is stored on.
At this time, the MDS generates File Layout layouts to NFSv4.1 clients
that know how to do pNFS for the non-mirrored DS case unless the sysctl
vfs.nfsd.default_flexfile is set non-zero, in which case Flexible File
layouts are generated.
The mirrored DS configuration always generates Flexible File layouts.
For NFS clients that do not support NFSv4.1 pNFS, all I/O operations
are done against the MDS which acts as a proxy for the appropriate DS(s).
When the MDS receives an I/O RPC, it will do the RPC on the DS as a proxy.
If the DS is on the same machine, the MDS/DS will do the RPC on the DS as
a proxy and so on, until the machine runs out of some resource, such as
session slots or mbufs.
As such, DSs must be separate systems from the MDS.
Tested by: james.rose@framestore.com
Relnotes: yes
2018-06-12 19:36:32 +00:00
|
|
|
mtx_destroy(&nfsrv_dslock_mtx);
|
2009-05-04 15:23:58 +00:00
|
|
|
loaded = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
2011-07-16 08:51:09 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
NFSEXITCODE(error);
|
2009-05-04 15:23:58 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
static moduledata_t nfscommon_mod = {
|
|
|
|
"nfscommon",
|
|
|
|
nfscommon_modevent,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
DECLARE_MODULE(nfscommon, nfscommon_mod, SI_SUB_VFS, SI_ORDER_ANY);
|
|
|
|
|
|
|
|
/* So that loader and kldload(2) can find us, wherever we are.. */
|
|
|
|
MODULE_VERSION(nfscommon, 1);
|
|
|
|
MODULE_DEPEND(nfscommon, nfssvc, 1, 1, 1);
|
|
|
|
MODULE_DEPEND(nfscommon, krpc, 1, 1, 1);
|
|
|
|
|