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.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NFS_NFSPORT_H_
|
2010-05-08 14:50:12 +00:00
|
|
|
#define _NFS_NFSPORT_H_
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In general, I'm not fond of #includes in .h files, but this seems
|
|
|
|
* to be the cleanest way to handle #include files for the ports.
|
|
|
|
*/
|
|
|
|
#ifdef _KERNEL
|
|
|
|
#include <sys/unistd.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/dirent.h>
|
|
|
|
#include <sys/domain.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/filedesc.h>
|
2009-05-29 21:27:12 +00:00
|
|
|
#include <sys/jail.h>
|
2009-05-04 15:23:58 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/lockf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/mount.h>
|
2016-08-12 22:44:59 +00:00
|
|
|
#include <sys/mutex.h>
|
2009-05-04 15:23:58 +00:00
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/sysproto.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/bio.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/acl.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/sysent.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/priv.h>
|
|
|
|
#include <sys/kthread.h>
|
|
|
|
#include <sys/syscallsubr.h>
|
|
|
|
#include <net/if.h>
|
2013-10-26 17:58:36 +00:00
|
|
|
#include <net/if_var.h>
|
2009-05-04 15:23:58 +00:00
|
|
|
#include <net/radix.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_pcb.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_var.h>
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <netinet/tcp_fsm.h>
|
|
|
|
#include <netinet/tcp_seq.h>
|
|
|
|
#include <netinet/tcp_timer.h>
|
|
|
|
#include <netinet/tcp_var.h>
|
|
|
|
#include <machine/in_cksum.h>
|
|
|
|
#include <crypto/des/des.h>
|
|
|
|
#include <sys/md5.h>
|
|
|
|
#include <rpc/rpc.h>
|
|
|
|
#include <rpc/rpcsec_gss.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For Darwin, these functions should be "static" when built in a kext.
|
|
|
|
* (This is always defined as nil otherwise.)
|
|
|
|
*/
|
|
|
|
#define APPLESTATIC
|
|
|
|
#include <ufs/ufs/dir.h>
|
|
|
|
#include <ufs/ufs/quota.h>
|
|
|
|
#include <ufs/ufs/inode.h>
|
|
|
|
#include <ufs/ufs/extattr.h>
|
|
|
|
#include <ufs/ufs/ufsmount.h>
|
|
|
|
#include <vm/uma.h>
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_object.h>
|
|
|
|
#include <vm/vm_extern.h>
|
|
|
|
#include <nfs/nfssvc.h>
|
|
|
|
#include "opt_nfs.h"
|
|
|
|
#include "opt_ufs.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These types must be defined before the nfs includes.
|
|
|
|
*/
|
|
|
|
#define NFSSOCKADDR_T struct sockaddr *
|
|
|
|
#define NFSPROC_T struct thread
|
|
|
|
#define NFSDEV_T dev_t
|
|
|
|
#define NFSSVCARGS nfssvc_args
|
|
|
|
#define NFSACL_T struct acl
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These should be defined as the types used for the corresponding VOP's
|
|
|
|
* argument type.
|
|
|
|
*/
|
|
|
|
#define NFS_ACCESS_ARGS struct vop_access_args
|
|
|
|
#define NFS_OPEN_ARGS struct vop_open_args
|
|
|
|
#define NFS_GETATTR_ARGS struct vop_getattr_args
|
|
|
|
#define NFS_LOOKUP_ARGS struct vop_lookup_args
|
|
|
|
#define NFS_READDIR_ARGS struct vop_readdir_args
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate mbufs. Must succeed and never set the mbuf ptr to NULL.
|
|
|
|
*/
|
|
|
|
#define NFSMGET(m) do { \
|
2013-03-12 08:59:51 +00:00
|
|
|
MGET((m), M_WAITOK, MT_DATA); \
|
2009-05-04 15:23:58 +00:00
|
|
|
while ((m) == NULL ) { \
|
2010-04-24 22:52:14 +00:00
|
|
|
(void) nfs_catnap(PZERO, 0, "nfsmget"); \
|
2013-03-12 08:59:51 +00:00
|
|
|
MGET((m), M_WAITOK, MT_DATA); \
|
2009-05-04 15:23:58 +00:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#define NFSMGETHDR(m) do { \
|
2013-03-12 08:59:51 +00:00
|
|
|
MGETHDR((m), M_WAITOK, MT_DATA); \
|
2009-05-04 15:23:58 +00:00
|
|
|
while ((m) == NULL ) { \
|
2010-04-24 22:52:14 +00:00
|
|
|
(void) nfs_catnap(PZERO, 0, "nfsmget"); \
|
2013-03-12 08:59:51 +00:00
|
|
|
MGETHDR((m), M_WAITOK, MT_DATA); \
|
2009-05-04 15:23:58 +00:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#define NFSMCLGET(m, w) do { \
|
2013-03-12 08:59:51 +00:00
|
|
|
MGET((m), M_WAITOK, MT_DATA); \
|
2009-05-04 15:23:58 +00:00
|
|
|
while ((m) == NULL ) { \
|
2010-04-24 22:52:14 +00:00
|
|
|
(void) nfs_catnap(PZERO, 0, "nfsmget"); \
|
2013-03-12 08:59:51 +00:00
|
|
|
MGET((m), M_WAITOK, MT_DATA); \
|
2009-05-04 15:23:58 +00:00
|
|
|
} \
|
|
|
|
MCLGET((m), (w)); \
|
|
|
|
} while (0)
|
|
|
|
#define NFSMCLGETHDR(m, w) do { \
|
2013-03-12 08:59:51 +00:00
|
|
|
MGETHDR((m), M_WAITOK, MT_DATA); \
|
2009-05-04 15:23:58 +00:00
|
|
|
while ((m) == NULL ) { \
|
2010-04-24 22:52:14 +00:00
|
|
|
(void) nfs_catnap(PZERO, 0, "nfsmget"); \
|
2013-03-12 08:59:51 +00:00
|
|
|
MGETHDR((m), M_WAITOK, MT_DATA); \
|
2009-05-04 15:23:58 +00:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#define NFSMTOD mtod
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Client side constant for size of a lockowner name.
|
|
|
|
*/
|
|
|
|
#define NFSV4CL_LOCKNAMELEN 12
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Type for a mutex lock.
|
|
|
|
*/
|
|
|
|
#define NFSMUTEX_T struct mtx
|
|
|
|
|
2009-05-15 19:33:59 +00:00
|
|
|
#endif /* _KERNEL */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NFSv4 Operation numbers.
|
|
|
|
*/
|
|
|
|
#define NFSV4OP_ACCESS 3
|
|
|
|
#define NFSV4OP_CLOSE 4
|
|
|
|
#define NFSV4OP_COMMIT 5
|
|
|
|
#define NFSV4OP_CREATE 6
|
|
|
|
#define NFSV4OP_DELEGPURGE 7
|
|
|
|
#define NFSV4OP_DELEGRETURN 8
|
|
|
|
#define NFSV4OP_GETATTR 9
|
|
|
|
#define NFSV4OP_GETFH 10
|
|
|
|
#define NFSV4OP_LINK 11
|
|
|
|
#define NFSV4OP_LOCK 12
|
|
|
|
#define NFSV4OP_LOCKT 13
|
|
|
|
#define NFSV4OP_LOCKU 14
|
|
|
|
#define NFSV4OP_LOOKUP 15
|
|
|
|
#define NFSV4OP_LOOKUPP 16
|
|
|
|
#define NFSV4OP_NVERIFY 17
|
|
|
|
#define NFSV4OP_OPEN 18
|
|
|
|
#define NFSV4OP_OPENATTR 19
|
|
|
|
#define NFSV4OP_OPENCONFIRM 20
|
|
|
|
#define NFSV4OP_OPENDOWNGRADE 21
|
|
|
|
#define NFSV4OP_PUTFH 22
|
|
|
|
#define NFSV4OP_PUTPUBFH 23
|
|
|
|
#define NFSV4OP_PUTROOTFH 24
|
|
|
|
#define NFSV4OP_READ 25
|
|
|
|
#define NFSV4OP_READDIR 26
|
|
|
|
#define NFSV4OP_READLINK 27
|
|
|
|
#define NFSV4OP_REMOVE 28
|
|
|
|
#define NFSV4OP_RENAME 29
|
|
|
|
#define NFSV4OP_RENEW 30
|
|
|
|
#define NFSV4OP_RESTOREFH 31
|
|
|
|
#define NFSV4OP_SAVEFH 32
|
|
|
|
#define NFSV4OP_SECINFO 33
|
|
|
|
#define NFSV4OP_SETATTR 34
|
|
|
|
#define NFSV4OP_SETCLIENTID 35
|
|
|
|
#define NFSV4OP_SETCLIENTIDCFRM 36
|
|
|
|
#define NFSV4OP_VERIFY 37
|
|
|
|
#define NFSV4OP_WRITE 38
|
|
|
|
#define NFSV4OP_RELEASELCKOWN 39
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Must be one greater than the last Operation#.
|
|
|
|
*/
|
|
|
|
#define NFSV4OP_NOPS 40
|
|
|
|
|
2012-12-08 22:52:39 +00:00
|
|
|
/*
|
|
|
|
* Additional Ops for NFSv4.1.
|
|
|
|
*/
|
|
|
|
#define NFSV4OP_BACKCHANNELCTL 40
|
|
|
|
#define NFSV4OP_BINDCONNTOSESS 41
|
|
|
|
#define NFSV4OP_EXCHANGEID 42
|
|
|
|
#define NFSV4OP_CREATESESSION 43
|
|
|
|
#define NFSV4OP_DESTROYSESSION 44
|
|
|
|
#define NFSV4OP_FREESTATEID 45
|
|
|
|
#define NFSV4OP_GETDIRDELEG 46
|
|
|
|
#define NFSV4OP_GETDEVINFO 47
|
|
|
|
#define NFSV4OP_GETDEVLIST 48
|
|
|
|
#define NFSV4OP_LAYOUTCOMMIT 49
|
|
|
|
#define NFSV4OP_LAYOUTGET 50
|
|
|
|
#define NFSV4OP_LAYOUTRETURN 51
|
|
|
|
#define NFSV4OP_SECINFONONAME 52
|
|
|
|
#define NFSV4OP_SEQUENCE 53
|
|
|
|
#define NFSV4OP_SETSSV 54
|
|
|
|
#define NFSV4OP_TESTSTATEID 55
|
|
|
|
#define NFSV4OP_WANTDELEG 56
|
|
|
|
#define NFSV4OP_DESTROYCLIENTID 57
|
|
|
|
#define NFSV4OP_RECLAIMCOMPL 58
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Must be one more than last op#.
|
2016-08-12 22:44:59 +00:00
|
|
|
* NFSv4.2 isn't implemented yet, but define the op# limit for it.
|
2012-12-08 22:52:39 +00:00
|
|
|
*/
|
|
|
|
#define NFSV41_NOPS 59
|
2016-08-12 22:44:59 +00:00
|
|
|
#define NFSV42_NOPS 72
|
2012-12-08 22:52:39 +00:00
|
|
|
|
2009-05-26 01:16:09 +00:00
|
|
|
/* Quirky case if the illegal op code */
|
|
|
|
#define NFSV4OP_OPILLEGAL 10044
|
|
|
|
|
2009-05-15 19:33:59 +00:00
|
|
|
/*
|
2016-08-12 22:44:59 +00:00
|
|
|
* Fake NFSV4OP_xxx used for nfsstat. Start at NFSV42_NOPS.
|
2009-05-15 19:33:59 +00:00
|
|
|
*/
|
2016-08-12 22:44:59 +00:00
|
|
|
#define NFSV4OP_SYMLINK (NFSV42_NOPS)
|
|
|
|
#define NFSV4OP_MKDIR (NFSV42_NOPS + 1)
|
|
|
|
#define NFSV4OP_RMDIR (NFSV42_NOPS + 2)
|
|
|
|
#define NFSV4OP_READDIRPLUS (NFSV42_NOPS + 3)
|
|
|
|
#define NFSV4OP_MKNOD (NFSV42_NOPS + 4)
|
|
|
|
#define NFSV4OP_FSSTAT (NFSV42_NOPS + 5)
|
|
|
|
#define NFSV4OP_FSINFO (NFSV42_NOPS + 6)
|
|
|
|
#define NFSV4OP_PATHCONF (NFSV42_NOPS + 7)
|
|
|
|
#define NFSV4OP_V3CREATE (NFSV42_NOPS + 8)
|
2009-05-15 19:33:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the count of the fake operations listed above.
|
|
|
|
*/
|
|
|
|
#define NFSV4OP_FAKENOPS 9
|
|
|
|
|
|
|
|
/*
|
|
|
|
* and the Callback OPs
|
|
|
|
*/
|
|
|
|
#define NFSV4OP_CBGETATTR 3
|
|
|
|
#define NFSV4OP_CBRECALL 4
|
|
|
|
|
|
|
|
/*
|
2016-08-12 22:44:59 +00:00
|
|
|
* Must be one greater than the last Callback Operation# for NFSv4.0.
|
2009-05-15 19:33:59 +00:00
|
|
|
*/
|
|
|
|
#define NFSV4OP_CBNOPS 5
|
|
|
|
|
2012-12-08 22:52:39 +00:00
|
|
|
/*
|
2016-08-12 22:44:59 +00:00
|
|
|
* Additional Callback Ops for NFSv4.1 only.
|
2012-12-08 22:52:39 +00:00
|
|
|
*/
|
|
|
|
#define NFSV4OP_CBLAYOUTRECALL 5
|
|
|
|
#define NFSV4OP_CBNOTIFY 6
|
|
|
|
#define NFSV4OP_CBPUSHDELEG 7
|
|
|
|
#define NFSV4OP_CBRECALLANY 8
|
|
|
|
#define NFSV4OP_CBRECALLOBJAVAIL 9
|
|
|
|
#define NFSV4OP_CBRECALLSLOT 10
|
|
|
|
#define NFSV4OP_CBSEQUENCE 11
|
|
|
|
#define NFSV4OP_CBWANTCANCELLED 12
|
|
|
|
#define NFSV4OP_CBNOTIFYLOCK 13
|
|
|
|
#define NFSV4OP_CBNOTIFYDEVID 14
|
|
|
|
|
2016-08-12 22:44:59 +00:00
|
|
|
#define NFSV41_CBNOPS 15
|
|
|
|
#define NFSV42_CBNOPS 16
|
|
|
|
|
2009-05-15 19:33:59 +00:00
|
|
|
/*
|
|
|
|
* The lower numbers -> 21 are used by NFSv2 and v3. These define higher
|
|
|
|
* numbers used by NFSv4.
|
|
|
|
* NFS_V3NPROCS is one greater than the last V3 op and NFS_NPROCS is
|
|
|
|
* one greater than the last number.
|
|
|
|
*/
|
2011-06-18 23:02:53 +00:00
|
|
|
#ifndef NFS_V3NPROCS
|
2009-05-15 19:33:59 +00:00
|
|
|
#define NFS_V3NPROCS 22
|
|
|
|
|
|
|
|
#define NFSPROC_LOOKUPP 22
|
|
|
|
#define NFSPROC_SETCLIENTID 23
|
|
|
|
#define NFSPROC_SETCLIENTIDCFRM 24
|
|
|
|
#define NFSPROC_LOCK 25
|
|
|
|
#define NFSPROC_LOCKU 26
|
|
|
|
#define NFSPROC_OPEN 27
|
|
|
|
#define NFSPROC_CLOSE 28
|
|
|
|
#define NFSPROC_OPENCONFIRM 29
|
|
|
|
#define NFSPROC_LOCKT 30
|
|
|
|
#define NFSPROC_OPENDOWNGRADE 31
|
|
|
|
#define NFSPROC_RENEW 32
|
|
|
|
#define NFSPROC_PUTROOTFH 33
|
|
|
|
#define NFSPROC_RELEASELCKOWN 34
|
|
|
|
#define NFSPROC_DELEGRETURN 35
|
|
|
|
#define NFSPROC_RETDELEGREMOVE 36
|
|
|
|
#define NFSPROC_RETDELEGRENAME1 37
|
|
|
|
#define NFSPROC_RETDELEGRENAME2 38
|
|
|
|
#define NFSPROC_GETACL 39
|
|
|
|
#define NFSPROC_SETACL 40
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Must be defined as one higher than the last Proc# above.
|
|
|
|
*/
|
|
|
|
#define NFSV4_NPROCS 41
|
2012-12-08 22:52:39 +00:00
|
|
|
|
|
|
|
/* Additional procedures for NFSv4.1. */
|
|
|
|
#define NFSPROC_EXCHANGEID 41
|
|
|
|
#define NFSPROC_CREATESESSION 42
|
|
|
|
#define NFSPROC_DESTROYSESSION 43
|
|
|
|
#define NFSPROC_DESTROYCLIENT 44
|
|
|
|
#define NFSPROC_FREESTATEID 45
|
|
|
|
#define NFSPROC_LAYOUTGET 46
|
|
|
|
#define NFSPROC_GETDEVICEINFO 47
|
|
|
|
#define NFSPROC_LAYOUTCOMMIT 48
|
|
|
|
#define NFSPROC_LAYOUTRETURN 49
|
|
|
|
#define NFSPROC_RECLAIMCOMPL 50
|
|
|
|
#define NFSPROC_WRITEDS 51
|
|
|
|
#define NFSPROC_READDS 52
|
|
|
|
#define NFSPROC_COMMITDS 53
|
2017-06-24 20:01:21 +00:00
|
|
|
#define NFSPROC_OPENLAYGET 54
|
|
|
|
#define NFSPROC_CREATELAYGET 55
|
2012-12-08 22:52:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Must be defined as one higher than the last NFSv4.1 Proc# above.
|
|
|
|
*/
|
2017-06-24 20:01:21 +00:00
|
|
|
#define NFSV41_NPROCS 56
|
2012-12-08 22:52:39 +00:00
|
|
|
|
2011-06-18 23:02:53 +00:00
|
|
|
#endif /* NFS_V3NPROCS */
|
2009-05-15 19:33:59 +00:00
|
|
|
|
|
|
|
/*
|
2016-08-12 22:44:59 +00:00
|
|
|
* New stats structure.
|
|
|
|
* The vers field will be set to NFSSTATS_V1 by the caller.
|
|
|
|
*/
|
|
|
|
#define NFSSTATS_V1 1
|
|
|
|
struct nfsstatsv1 {
|
|
|
|
int vers; /* Set to version requested by caller. */
|
|
|
|
uint64_t attrcache_hits;
|
|
|
|
uint64_t attrcache_misses;
|
|
|
|
uint64_t lookupcache_hits;
|
|
|
|
uint64_t lookupcache_misses;
|
|
|
|
uint64_t direofcache_hits;
|
|
|
|
uint64_t direofcache_misses;
|
|
|
|
uint64_t accesscache_hits;
|
|
|
|
uint64_t accesscache_misses;
|
|
|
|
uint64_t biocache_reads;
|
|
|
|
uint64_t read_bios;
|
|
|
|
uint64_t read_physios;
|
|
|
|
uint64_t biocache_writes;
|
|
|
|
uint64_t write_bios;
|
|
|
|
uint64_t write_physios;
|
|
|
|
uint64_t biocache_readlinks;
|
|
|
|
uint64_t readlink_bios;
|
|
|
|
uint64_t biocache_readdirs;
|
|
|
|
uint64_t readdir_bios;
|
2017-06-24 20:01:21 +00:00
|
|
|
uint64_t rpccnt[NFSV41_NPROCS + 13];
|
2016-08-12 22:44:59 +00:00
|
|
|
uint64_t rpcretries;
|
|
|
|
uint64_t srvrpccnt[NFSV42_NOPS + NFSV4OP_FAKENOPS];
|
|
|
|
uint64_t srvrpc_errs;
|
|
|
|
uint64_t srv_errs;
|
|
|
|
uint64_t rpcrequests;
|
|
|
|
uint64_t rpctimeouts;
|
|
|
|
uint64_t rpcunexpected;
|
|
|
|
uint64_t rpcinvalid;
|
|
|
|
uint64_t srvcache_inproghits;
|
|
|
|
uint64_t srvcache_idemdonehits;
|
|
|
|
uint64_t srvcache_nonidemdonehits;
|
|
|
|
uint64_t srvcache_misses;
|
|
|
|
uint64_t srvcache_tcppeak;
|
|
|
|
int srvcache_size; /* Updated by atomic_xx_int(). */
|
|
|
|
uint64_t srvclients;
|
|
|
|
uint64_t srvopenowners;
|
|
|
|
uint64_t srvopens;
|
|
|
|
uint64_t srvlockowners;
|
|
|
|
uint64_t srvlocks;
|
|
|
|
uint64_t srvdelegates;
|
|
|
|
uint64_t cbrpccnt[NFSV42_CBNOPS];
|
|
|
|
uint64_t clopenowners;
|
|
|
|
uint64_t clopens;
|
|
|
|
uint64_t cllockowners;
|
|
|
|
uint64_t cllocks;
|
|
|
|
uint64_t cldelegates;
|
|
|
|
uint64_t cllocalopenowners;
|
|
|
|
uint64_t cllocalopens;
|
|
|
|
uint64_t cllocallockowners;
|
|
|
|
uint64_t cllocallocks;
|
|
|
|
uint64_t srvstartcnt;
|
|
|
|
uint64_t srvdonecnt;
|
|
|
|
uint64_t srvbytes[NFSV42_NOPS + NFSV4OP_FAKENOPS];
|
|
|
|
uint64_t srvops[NFSV42_NOPS + NFSV4OP_FAKENOPS];
|
|
|
|
struct bintime srvduration[NFSV42_NOPS + NFSV4OP_FAKENOPS];
|
|
|
|
struct bintime busyfrom;
|
|
|
|
struct bintime busytime;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Old stats structure.
|
2009-05-15 19:33:59 +00:00
|
|
|
*/
|
|
|
|
struct ext_nfsstats {
|
|
|
|
int attrcache_hits;
|
|
|
|
int attrcache_misses;
|
|
|
|
int lookupcache_hits;
|
|
|
|
int lookupcache_misses;
|
|
|
|
int direofcache_hits;
|
|
|
|
int direofcache_misses;
|
|
|
|
int accesscache_hits;
|
|
|
|
int accesscache_misses;
|
|
|
|
int biocache_reads;
|
|
|
|
int read_bios;
|
|
|
|
int read_physios;
|
|
|
|
int biocache_writes;
|
|
|
|
int write_bios;
|
|
|
|
int write_physios;
|
|
|
|
int biocache_readlinks;
|
|
|
|
int readlink_bios;
|
|
|
|
int biocache_readdirs;
|
|
|
|
int readdir_bios;
|
|
|
|
int rpccnt[NFSV4_NPROCS];
|
|
|
|
int rpcretries;
|
|
|
|
int srvrpccnt[NFSV4OP_NOPS + NFSV4OP_FAKENOPS];
|
|
|
|
int srvrpc_errs;
|
|
|
|
int srv_errs;
|
|
|
|
int rpcrequests;
|
|
|
|
int rpctimeouts;
|
|
|
|
int rpcunexpected;
|
|
|
|
int rpcinvalid;
|
|
|
|
int srvcache_inproghits;
|
|
|
|
int srvcache_idemdonehits;
|
|
|
|
int srvcache_nonidemdonehits;
|
|
|
|
int srvcache_misses;
|
|
|
|
int srvcache_tcppeak;
|
|
|
|
int srvcache_size;
|
|
|
|
int srvclients;
|
|
|
|
int srvopenowners;
|
|
|
|
int srvopens;
|
|
|
|
int srvlockowners;
|
|
|
|
int srvlocks;
|
|
|
|
int srvdelegates;
|
|
|
|
int cbrpccnt[NFSV4OP_CBNOPS];
|
|
|
|
int clopenowners;
|
|
|
|
int clopens;
|
|
|
|
int cllockowners;
|
|
|
|
int cllocks;
|
|
|
|
int cldelegates;
|
|
|
|
int cllocalopenowners;
|
|
|
|
int cllocalopens;
|
|
|
|
int cllocallockowners;
|
|
|
|
int cllocallocks;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
/*
|
|
|
|
* Define NFS_NPROCS as NFSV4_NPROCS for the experimental kernel code.
|
|
|
|
*/
|
2011-06-18 23:02:53 +00:00
|
|
|
#ifndef NFS_NPROCS
|
2009-05-15 19:33:59 +00:00
|
|
|
#define NFS_NPROCS NFSV4_NPROCS
|
2011-06-18 23:02:53 +00:00
|
|
|
#endif
|
2009-05-15 19:33:59 +00:00
|
|
|
|
2009-05-04 15:23:58 +00:00
|
|
|
#include <fs/nfs/nfskpiport.h>
|
|
|
|
#include <fs/nfs/nfsdport.h>
|
|
|
|
#include <fs/nfs/rpcv2.h>
|
|
|
|
#include <fs/nfs/nfsproto.h>
|
|
|
|
#include <fs/nfs/nfs.h>
|
2012-12-08 22:52:39 +00:00
|
|
|
#include <fs/nfs/nfsclstate.h>
|
2009-05-04 15:23:58 +00:00
|
|
|
#include <fs/nfs/nfs_var.h>
|
|
|
|
#include <fs/nfs/nfsm_subs.h>
|
|
|
|
#include <fs/nfs/nfsrvcache.h>
|
|
|
|
#include <fs/nfs/nfsrvstate.h>
|
|
|
|
#include <fs/nfs/xdr_subs.h>
|
|
|
|
#include <fs/nfs/nfscl.h>
|
2011-04-25 13:09:32 +00:00
|
|
|
#include <nfsclient/nfsargs.h>
|
2009-05-04 15:23:58 +00:00
|
|
|
#include <fs/nfsclient/nfsmount.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Just to keep nfs_var.h happy.
|
|
|
|
*/
|
|
|
|
struct nfs_vattr {
|
|
|
|
int junk;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nfsvattr {
|
|
|
|
struct vattr na_vattr;
|
|
|
|
nfsattrbit_t na_suppattr;
|
2017-06-18 21:48:31 +00:00
|
|
|
u_int64_t na_mntonfileno;
|
2009-05-04 15:23:58 +00:00
|
|
|
u_int64_t na_filesid[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
#define na_type na_vattr.va_type
|
|
|
|
#define na_mode na_vattr.va_mode
|
|
|
|
#define na_nlink na_vattr.va_nlink
|
|
|
|
#define na_uid na_vattr.va_uid
|
|
|
|
#define na_gid na_vattr.va_gid
|
|
|
|
#define na_fsid na_vattr.va_fsid
|
|
|
|
#define na_fileid na_vattr.va_fileid
|
|
|
|
#define na_size na_vattr.va_size
|
|
|
|
#define na_blocksize na_vattr.va_blocksize
|
|
|
|
#define na_atime na_vattr.va_atime
|
|
|
|
#define na_mtime na_vattr.va_mtime
|
|
|
|
#define na_ctime na_vattr.va_ctime
|
|
|
|
#define na_gen na_vattr.va_gen
|
|
|
|
#define na_flags na_vattr.va_flags
|
|
|
|
#define na_rdev na_vattr.va_rdev
|
|
|
|
#define na_bytes na_vattr.va_bytes
|
|
|
|
#define na_filerev na_vattr.va_filerev
|
|
|
|
#define na_vaflags na_vattr.va_vaflags
|
|
|
|
|
|
|
|
#include <fs/nfsclient/nfsnode.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the header structure used for the lists, etc. (It has the
|
|
|
|
* above record in it.
|
|
|
|
*/
|
|
|
|
struct nfsrv_stablefirst {
|
|
|
|
LIST_HEAD(, nfsrv_stable) nsf_head; /* Head of nfsrv_stable list */
|
|
|
|
time_t nsf_eograce; /* Time grace period ends */
|
|
|
|
time_t *nsf_bootvals; /* Previous boottime values */
|
|
|
|
struct file *nsf_fp; /* File table pointer */
|
|
|
|
u_char nsf_flags; /* NFSNSF_ flags */
|
|
|
|
struct nfsf_rec nsf_rec; /* and above first record */
|
|
|
|
};
|
|
|
|
#define nsf_lease nsf_rec.lease
|
|
|
|
#define nsf_numboots nsf_rec.numboots
|
|
|
|
|
|
|
|
/* NFSNSF_xxx flags */
|
|
|
|
#define NFSNSF_UPDATEDONE 0x01
|
|
|
|
#define NFSNSF_GRACEOVER 0x02
|
|
|
|
#define NFSNSF_NEEDLOCK 0x04
|
|
|
|
#define NFSNSF_EXPIREDCLIENT 0x08
|
|
|
|
#define NFSNSF_NOOPENS 0x10
|
|
|
|
#define NFSNSF_OK 0x20
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Maximum number of boot times allowed in record. Although there is
|
|
|
|
* really no need for a fixed upper bound, this serves as a sanity check
|
|
|
|
* for a corrupted file.
|
|
|
|
*/
|
|
|
|
#define NFSNSF_MAXNUMBOOTS 10000
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This structure defines the other records in the file. The
|
|
|
|
* nst_client array is actually the size of the client string name.
|
|
|
|
*/
|
|
|
|
struct nfst_rec {
|
|
|
|
u_int16_t len;
|
|
|
|
u_char flag;
|
|
|
|
u_char client[1];
|
|
|
|
};
|
|
|
|
/* and the values for flag */
|
|
|
|
#define NFSNST_NEWSTATE 0x1
|
|
|
|
#define NFSNST_REVOKE 0x2
|
|
|
|
#define NFSNST_GOTSTATE 0x4
|
2018-05-15 20:28:50 +00:00
|
|
|
#define NFSNST_RECLAIMED 0x8
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This structure is linked onto nfsrv_stablefirst for the duration of
|
|
|
|
* reclaim.
|
|
|
|
*/
|
|
|
|
struct nfsrv_stable {
|
|
|
|
LIST_ENTRY(nfsrv_stable) nst_list;
|
|
|
|
struct nfsclient *nst_clp;
|
|
|
|
struct nfst_rec nst_rec;
|
|
|
|
};
|
|
|
|
#define nst_timestamp nst_rec.timestamp
|
|
|
|
#define nst_len nst_rec.len
|
|
|
|
#define nst_flag nst_rec.flag
|
|
|
|
#define nst_client nst_rec.client
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At some point the server will run out of kernel storage for
|
|
|
|
* state structures. For FreeBSD5.2, this results in a panic
|
|
|
|
* kmem_map is full. It happens at well over 1000000 opens plus
|
|
|
|
* locks on a PIII-800 with 256Mbytes, so that is where I've set
|
|
|
|
* the limit. If your server panics due to too many opens/locks,
|
|
|
|
* decrease the size of NFSRV_V4STATELIMIT. If you find the server
|
|
|
|
* returning NFS4ERR_RESOURCE a lot and have lots of memory, try
|
|
|
|
* increasing it.
|
|
|
|
*/
|
|
|
|
#define NFSRV_V4STATELIMIT 500000 /* Max # of Opens + Locks */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The type required differs with BSDen (just the second arg).
|
|
|
|
*/
|
|
|
|
void nfsrvd_rcv(struct socket *, void *, int);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros for handling socket addresses. (Hopefully this makes the code
|
|
|
|
* more portable, since I've noticed some 'BSD don't have sockaddrs in
|
|
|
|
* mbufs any more.)
|
|
|
|
*/
|
|
|
|
#define NFSSOCKADDR(a, t) ((t)(a))
|
|
|
|
#define NFSSOCKADDRSIZE(a, s) ((a)->sa_len = (s))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These should be defined as a process or thread structure, as required
|
|
|
|
* for signal handling, etc.
|
|
|
|
*/
|
|
|
|
#define NFSNEWCRED(c) (crdup(c))
|
|
|
|
#define NFSPROCCRED(p) ((p)->td_ucred)
|
|
|
|
#define NFSFREECRED(c) (crfree(c))
|
|
|
|
#define NFSUIOPROC(u, p) ((u)->uio_td = NULL)
|
|
|
|
#define NFSPROCP(p) ((p)->td_proc)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define these so that cn_hash and its length is ignored.
|
|
|
|
*/
|
|
|
|
#define NFSCNHASHZERO(c)
|
|
|
|
#define NFSCNHASH(c, v)
|
|
|
|
#define NCHNAMLEN 9999999
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These macros are defined to initialize and set the timer routine.
|
|
|
|
*/
|
|
|
|
#define NFS_TIMERINIT \
|
|
|
|
newnfs_timer(NULL)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle SMP stuff:
|
|
|
|
*/
|
|
|
|
#define NFSSTATESPINLOCK extern struct mtx nfs_state_mutex
|
|
|
|
#define NFSLOCKSTATE() mtx_lock(&nfs_state_mutex)
|
|
|
|
#define NFSUNLOCKSTATE() mtx_unlock(&nfs_state_mutex)
|
2010-03-30 23:11:50 +00:00
|
|
|
#define NFSSTATEMUTEXPTR (&nfs_state_mutex)
|
2009-05-04 15:23:58 +00:00
|
|
|
#define NFSREQSPINLOCK extern struct mtx nfs_req_mutex
|
|
|
|
#define NFSLOCKREQ() mtx_lock(&nfs_req_mutex)
|
|
|
|
#define NFSUNLOCKREQ() mtx_unlock(&nfs_req_mutex)
|
|
|
|
#define NFSSOCKMUTEX extern struct mtx nfs_slock_mutex
|
|
|
|
#define NFSSOCKMUTEXPTR (&nfs_slock_mutex)
|
|
|
|
#define NFSLOCKSOCK() mtx_lock(&nfs_slock_mutex)
|
|
|
|
#define NFSUNLOCKSOCK() mtx_unlock(&nfs_slock_mutex)
|
|
|
|
#define NFSNAMEIDMUTEX extern struct mtx nfs_nameid_mutex
|
|
|
|
#define NFSLOCKNAMEID() mtx_lock(&nfs_nameid_mutex)
|
|
|
|
#define NFSUNLOCKNAMEID() mtx_unlock(&nfs_nameid_mutex)
|
|
|
|
#define NFSNAMEIDREQUIRED() mtx_assert(&nfs_nameid_mutex, MA_OWNED)
|
|
|
|
#define NFSCLSTATEMUTEX extern struct mtx nfs_clstate_mutex
|
|
|
|
#define NFSCLSTATEMUTEXPTR (&nfs_clstate_mutex)
|
|
|
|
#define NFSLOCKCLSTATE() mtx_lock(&nfs_clstate_mutex)
|
|
|
|
#define NFSUNLOCKCLSTATE() mtx_unlock(&nfs_clstate_mutex)
|
|
|
|
#define NFSDLOCKMUTEX extern struct mtx newnfsd_mtx
|
|
|
|
#define NFSDLOCKMUTEXPTR (&newnfsd_mtx)
|
|
|
|
#define NFSD_LOCK() mtx_lock(&newnfsd_mtx)
|
|
|
|
#define NFSD_UNLOCK() mtx_unlock(&newnfsd_mtx)
|
|
|
|
#define NFSD_LOCK_ASSERT() mtx_assert(&newnfsd_mtx, MA_OWNED)
|
|
|
|
#define NFSD_UNLOCK_ASSERT() mtx_assert(&newnfsd_mtx, MA_NOTOWNED)
|
|
|
|
#define NFSV4ROOTLOCKMUTEX extern struct mtx nfs_v4root_mutex
|
|
|
|
#define NFSV4ROOTLOCKMUTEXPTR (&nfs_v4root_mutex)
|
|
|
|
#define NFSLOCKV4ROOTMUTEX() mtx_lock(&nfs_v4root_mutex)
|
|
|
|
#define NFSUNLOCKV4ROOTMUTEX() mtx_unlock(&nfs_v4root_mutex)
|
|
|
|
#define NFSLOCKNODE(n) mtx_lock(&((n)->n_mtx))
|
|
|
|
#define NFSUNLOCKNODE(n) mtx_unlock(&((n)->n_mtx))
|
|
|
|
#define NFSLOCKMNT(m) mtx_lock(&((m)->nm_mtx))
|
|
|
|
#define NFSUNLOCKMNT(m) mtx_unlock(&((m)->nm_mtx))
|
|
|
|
#define NFSLOCKREQUEST(r) mtx_lock(&((r)->r_mtx))
|
|
|
|
#define NFSUNLOCKREQUEST(r) mtx_unlock(&((r)->r_mtx))
|
|
|
|
#define NFSLOCKSOCKREQ(r) mtx_lock(&((r)->nr_mtx))
|
|
|
|
#define NFSUNLOCKSOCKREQ(r) mtx_unlock(&((r)->nr_mtx))
|
2012-12-08 22:52:39 +00:00
|
|
|
#define NFSLOCKDS(d) mtx_lock(&((d)->nfsclds_mtx))
|
|
|
|
#define NFSUNLOCKDS(d) mtx_unlock(&((d)->nfsclds_mtx))
|
2014-07-01 20:47:16 +00:00
|
|
|
#define NFSSESSIONMUTEXPTR(s) (&((s)->mtx))
|
|
|
|
#define NFSLOCKSESSION(s) mtx_lock(&((s)->mtx))
|
|
|
|
#define NFSUNLOCKSESSION(s) mtx_unlock(&((s)->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
|
|
|
#define NFSLAYOUTMUTEXPTR(l) (&((l)->mtx))
|
2017-12-09 21:04:56 +00:00
|
|
|
#define NFSLOCKLAYOUT(l) mtx_lock(&((l)->mtx))
|
|
|
|
#define NFSUNLOCKLAYOUT(l) mtx_unlock(&((l)->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
|
|
|
#define NFSDDSMUTEXPTR (&nfsrv_dslock_mtx)
|
2017-12-09 21:04:56 +00:00
|
|
|
#define NFSDDSLOCK() mtx_lock(&nfsrv_dslock_mtx)
|
|
|
|
#define NFSDDSUNLOCK() mtx_unlock(&nfsrv_dslock_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
|
|
|
#define NFSDDONTLISTMUTEXPTR (&nfsrv_dontlistlock_mtx)
|
|
|
|
#define NFSDDONTLISTLOCK() mtx_lock(&nfsrv_dontlistlock_mtx)
|
|
|
|
#define NFSDDONTLISTUNLOCK() mtx_unlock(&nfsrv_dontlistlock_mtx)
|
|
|
|
#define NFSDRECALLMUTEXPTR (&nfsrv_recalllock_mtx)
|
|
|
|
#define NFSDRECALLLOCK() mtx_lock(&nfsrv_recalllock_mtx)
|
|
|
|
#define NFSDRECALLUNLOCK() mtx_unlock(&nfsrv_recalllock_mtx)
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Use these macros to initialize/free a mutex.
|
|
|
|
*/
|
|
|
|
#define NFSINITSOCKMUTEX(m) mtx_init((m), "nfssock", NULL, MTX_DEF)
|
|
|
|
#define NFSFREEMUTEX(m) mtx_destroy((m))
|
|
|
|
|
|
|
|
int nfsmsleep(void *, void *, int, const char *, struct timespec *);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* And weird vm stuff in the nfs server.
|
|
|
|
*/
|
|
|
|
#define PDIRUNLOCK 0x0
|
|
|
|
#define MAX_COMMIT_COUNT (1024 * 1024)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define these to handle the type of va_rdev.
|
|
|
|
*/
|
|
|
|
#define NFSMAKEDEV(m, n) makedev((m), (n))
|
|
|
|
#define NFSMAJOR(d) major(d)
|
|
|
|
#define NFSMINOR(d) minor(d)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The vnode tag for nfsv4root.
|
|
|
|
*/
|
|
|
|
#define VT_NFSV4ROOT "nfsv4root"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define whatever it takes to do a vn_rdwr().
|
|
|
|
*/
|
|
|
|
#define NFSD_RDWR(r, v, b, l, o, s, i, c, a, p) \
|
2009-06-16 13:52:21 +00:00
|
|
|
vn_rdwr((r), (v), (b), (l), (o), (s), (i), (c), NULL, (a), (p))
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros for handling memory for different BSDen.
|
|
|
|
* NFSBCOPY(src, dst, len) - copies len bytes, non-overlapping
|
|
|
|
* NFSOVBCOPY(src, dst, len) - ditto, but data areas might overlap
|
|
|
|
* NFSBCMP(cp1, cp2, len) - compare len bytes, return 0 if same
|
|
|
|
* NFSBZERO(cp, len) - set len bytes to 0x0
|
|
|
|
*/
|
|
|
|
#define NFSBCOPY(s, d, l) bcopy((s), (d), (l))
|
|
|
|
#define NFSOVBCOPY(s, d, l) ovbcopy((s), (d), (l))
|
|
|
|
#define NFSBCMP(s, d, l) bcmp((s), (d), (l))
|
|
|
|
#define NFSBZERO(s, l) bzero((s), (l))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some queue.h files don't have these dfined in them.
|
|
|
|
*/
|
|
|
|
#define LIST_END(head) NULL
|
|
|
|
#define SLIST_END(head) NULL
|
|
|
|
#define TAILQ_END(head) NULL
|
|
|
|
|
|
|
|
/*
|
2011-01-27 03:32:16 +00:00
|
|
|
* This must be defined to be a global variable that increments once
|
2009-05-04 15:23:58 +00:00
|
|
|
* per second, but never stops or goes backwards, even when a "date"
|
2011-01-27 03:32:16 +00:00
|
|
|
* command changes the TOD clock. It is used for delta times for
|
2009-05-04 15:23:58 +00:00
|
|
|
* leases, etc.
|
|
|
|
*/
|
|
|
|
#define NFSD_MONOSEC time_uptime
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Declare the malloc types.
|
|
|
|
*/
|
|
|
|
MALLOC_DECLARE(M_NEWNFSRVCACHE);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSDCLIENT);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSDSTATE);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSDLOCK);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSDLOCKFILE);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSSTRING);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSUSERGROUP);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSDREQ);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSFH);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSCLOWNER);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSCLOPEN);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSCLDELEG);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSCLCLIENT);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSCLLOCKOWNER);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSCLLOCK);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSDIROFF);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSV4NODE);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSDIRECTIO);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSMNT);
|
2010-03-30 23:11:50 +00:00
|
|
|
MALLOC_DECLARE(M_NEWNFSDROLLBACK);
|
2012-12-08 22:52:39 +00:00
|
|
|
MALLOC_DECLARE(M_NEWNFSLAYOUT);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSFLAYOUT);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSDEVINFO);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSSOCKREQ);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSCLDS);
|
|
|
|
MALLOC_DECLARE(M_NEWNFSLAYRECALL);
|
2014-07-01 20:47:16 +00:00
|
|
|
MALLOC_DECLARE(M_NEWNFSDSESSION);
|
2009-05-04 15:23:58 +00:00
|
|
|
#define M_NFSRVCACHE M_NEWNFSRVCACHE
|
|
|
|
#define M_NFSDCLIENT M_NEWNFSDCLIENT
|
|
|
|
#define M_NFSDSTATE M_NEWNFSDSTATE
|
|
|
|
#define M_NFSDLOCK M_NEWNFSDLOCK
|
|
|
|
#define M_NFSDLOCKFILE M_NEWNFSDLOCKFILE
|
|
|
|
#define M_NFSSTRING M_NEWNFSSTRING
|
|
|
|
#define M_NFSUSERGROUP M_NEWNFSUSERGROUP
|
|
|
|
#define M_NFSDREQ M_NEWNFSDREQ
|
|
|
|
#define M_NFSFH M_NEWNFSFH
|
|
|
|
#define M_NFSCLOWNER M_NEWNFSCLOWNER
|
|
|
|
#define M_NFSCLOPEN M_NEWNFSCLOPEN
|
|
|
|
#define M_NFSCLDELEG M_NEWNFSCLDELEG
|
|
|
|
#define M_NFSCLCLIENT M_NEWNFSCLCLIENT
|
|
|
|
#define M_NFSCLLOCKOWNER M_NEWNFSCLLOCKOWNER
|
|
|
|
#define M_NFSCLLOCK M_NEWNFSCLLOCK
|
|
|
|
#define M_NFSDIROFF M_NEWNFSDIROFF
|
|
|
|
#define M_NFSV4NODE M_NEWNFSV4NODE
|
|
|
|
#define M_NFSDIRECTIO M_NEWNFSDIRECTIO
|
2010-03-30 23:11:50 +00:00
|
|
|
#define M_NFSDROLLBACK M_NEWNFSDROLLBACK
|
2012-12-08 22:52:39 +00:00
|
|
|
#define M_NFSLAYOUT M_NEWNFSLAYOUT
|
|
|
|
#define M_NFSFLAYOUT M_NEWNFSFLAYOUT
|
|
|
|
#define M_NFSDEVINFO M_NEWNFSDEVINFO
|
|
|
|
#define M_NFSSOCKREQ M_NEWNFSSOCKREQ
|
|
|
|
#define M_NFSCLDS M_NEWNFSCLDS
|
|
|
|
#define M_NFSLAYRECALL M_NEWNFSLAYRECALL
|
2014-07-01 20:47:16 +00:00
|
|
|
#define M_NFSDSESSION M_NEWNFSDSESSION
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
#define NFSINT_SIGMASK(set) \
|
|
|
|
(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \
|
|
|
|
SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \
|
|
|
|
SIGISMEMBER(set, SIGQUIT))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a quota block count to byte count.
|
|
|
|
*/
|
|
|
|
#define NFSQUOTABLKTOBYTE(q, b) (q) *= (b)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define this as the largest file size supported. (It should probably
|
|
|
|
* be available via a VFS_xxx Op, but it isn't.
|
|
|
|
*/
|
|
|
|
#define NFSRV_MAXFILESIZE ((u_int64_t)0x800000000000)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set this macro to index() or strchr(), whichever is supported.
|
|
|
|
*/
|
2012-01-02 12:12:10 +00:00
|
|
|
#define STRCHR(s, c) strchr((s), (c))
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the n_time in the client write rpc, as required.
|
|
|
|
*/
|
2016-04-11 21:55:21 +00:00
|
|
|
#define NFSWRITERPC_SETTIME(w, n, a, v4) \
|
2009-05-04 15:23:58 +00:00
|
|
|
do { \
|
|
|
|
if (w) { \
|
2016-04-11 21:55:21 +00:00
|
|
|
mtx_lock(&((n)->n_mtx)); \
|
|
|
|
(n)->n_mtime = (a)->na_mtime; \
|
2009-05-04 15:23:58 +00:00
|
|
|
if (v4) \
|
2016-04-11 21:55:21 +00:00
|
|
|
(n)->n_change = (a)->na_filerev; \
|
|
|
|
mtx_unlock(&((n)->n_mtx)); \
|
2009-05-04 15:23:58 +00:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fake value, just to make the client work.
|
|
|
|
*/
|
|
|
|
#define NFS_LATTR_NOSHRINK 1
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prototypes for functions where the arguments vary for different ports.
|
|
|
|
*/
|
|
|
|
int nfscl_loadattrcache(struct vnode **, struct nfsvattr *, void *, void *,
|
|
|
|
int, int);
|
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 **, int);
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the port runs on an SMP box that can enforce Atomic ops with low
|
|
|
|
* overheads, define these as atomic increments/decrements. If not,
|
|
|
|
* don't worry about it, since these are used for stats that can be
|
|
|
|
* "out by one" without disastrous consequences.
|
|
|
|
*/
|
|
|
|
#define NFSINCRGLOBAL(a) ((a)++)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assorted funky stuff to make things work under Darwin8.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* These macros checks for a field in vattr being set.
|
|
|
|
*/
|
|
|
|
#define NFSATTRISSET(t, v, a) ((v)->a != (t)VNOVAL)
|
|
|
|
#define NFSATTRISSETTIME(v, a) ((v)->a.tv_sec != VNOVAL)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Manipulate mount flags.
|
|
|
|
*/
|
|
|
|
#define NFSSTA_HASWRITEVERF 0x00040000 /* Has write verifier */
|
|
|
|
#define NFSSTA_GOTFSINFO 0x00100000 /* Got the fsinfo */
|
2017-04-23 21:51:28 +00:00
|
|
|
#define NFSSTA_OPENMODE 0x00200000 /* Must use correct open mode */
|
2017-09-28 23:05:08 +00:00
|
|
|
#define NFSSTA_FLEXFILE 0x00800000 /* Use Flex File Layout */
|
2012-12-08 22:52:39 +00:00
|
|
|
#define NFSSTA_NOLAYOUTCOMMIT 0x04000000 /* Don't do LayoutCommit */
|
|
|
|
#define NFSSTA_SESSPERSIST 0x08000000 /* Has a persistent session */
|
2009-05-04 15:23:58 +00:00
|
|
|
#define NFSSTA_TIMEO 0x10000000 /* Experiencing a timeout */
|
|
|
|
#define NFSSTA_LOCKTIMEO 0x20000000 /* Experiencing a lockd timeout */
|
|
|
|
#define NFSSTA_HASSETFSID 0x40000000 /* Has set the fsid */
|
2012-12-08 22:52:39 +00:00
|
|
|
#define NFSSTA_PNFS 0x80000000 /* pNFS is enabled */
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
#define NFSHASNFSV3(n) ((n)->nm_flag & NFSMNT_NFSV3)
|
|
|
|
#define NFSHASNFSV4(n) ((n)->nm_flag & NFSMNT_NFSV4)
|
2012-12-08 22:52:39 +00:00
|
|
|
#define NFSHASNFSV4N(n) ((n)->nm_minorvers > 0)
|
2009-05-04 15:23:58 +00:00
|
|
|
#define NFSHASNFSV3OR4(n) ((n)->nm_flag & (NFSMNT_NFSV3 | NFSMNT_NFSV4))
|
|
|
|
#define NFSHASGOTFSINFO(n) ((n)->nm_state & NFSSTA_GOTFSINFO)
|
|
|
|
#define NFSHASHASSETFSID(n) ((n)->nm_state & NFSSTA_HASSETFSID)
|
|
|
|
#define NFSHASSTRICT3530(n) ((n)->nm_flag & NFSMNT_STRICT3530)
|
|
|
|
#define NFSHASWRITEVERF(n) ((n)->nm_state & NFSSTA_HASWRITEVERF)
|
|
|
|
#define NFSHASINT(n) ((n)->nm_flag & NFSMNT_INT)
|
|
|
|
#define NFSHASSOFT(n) ((n)->nm_flag & NFSMNT_SOFT)
|
|
|
|
#define NFSHASINTORSOFT(n) ((n)->nm_flag & (NFSMNT_INT | NFSMNT_SOFT))
|
|
|
|
#define NFSHASDUMBTIMR(n) ((n)->nm_flag & NFSMNT_DUMBTIMR)
|
|
|
|
#define NFSHASNOCONN(n) ((n)->nm_flag & NFSMNT_MNTD)
|
|
|
|
#define NFSHASKERB(n) ((n)->nm_flag & NFSMNT_KERB)
|
|
|
|
#define NFSHASALLGSSNAME(n) ((n)->nm_flag & NFSMNT_ALLGSSNAME)
|
|
|
|
#define NFSHASINTEGRITY(n) ((n)->nm_flag & NFSMNT_INTEGRITY)
|
|
|
|
#define NFSHASPRIVACY(n) ((n)->nm_flag & NFSMNT_PRIVACY)
|
|
|
|
#define NFSSETWRITEVERF(n) ((n)->nm_state |= NFSSTA_HASWRITEVERF)
|
|
|
|
#define NFSSETHASSETFSID(n) ((n)->nm_state |= NFSSTA_HASSETFSID)
|
2012-12-08 22:52:39 +00:00
|
|
|
#define NFSHASPNFSOPT(n) ((n)->nm_flag & NFSMNT_PNFS)
|
|
|
|
#define NFSHASNOLAYOUTCOMMIT(n) ((n)->nm_state & NFSSTA_NOLAYOUTCOMMIT)
|
|
|
|
#define NFSHASSESSPERSIST(n) ((n)->nm_state & NFSSTA_SESSPERSIST)
|
|
|
|
#define NFSHASPNFS(n) ((n)->nm_state & NFSSTA_PNFS)
|
2017-09-28 23:05:08 +00:00
|
|
|
#define NFSHASFLEXFILE(n) ((n)->nm_state & NFSSTA_FLEXFILE)
|
2017-04-23 21:51:28 +00:00
|
|
|
#define NFSHASOPENMODE(n) ((n)->nm_state & NFSSTA_OPENMODE)
|
2017-04-13 21:54:19 +00:00
|
|
|
#define NFSHASONEOPENOWN(n) (((n)->nm_flag & NFSMNT_ONEOPENOWN) != 0 && \
|
|
|
|
(n)->nm_minorvers > 0)
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets the stats field out of the mount structure.
|
|
|
|
*/
|
|
|
|
#define vfs_statfs(m) (&((m)->mnt_stat))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set boottime.
|
|
|
|
*/
|
2016-07-27 11:08:59 +00:00
|
|
|
#define NFSSETBOOTTIME(b) (getboottime(&b))
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The size of directory blocks in the buffer cache.
|
|
|
|
* MUST BE in the range of PAGE_SIZE <= NFS_DIRBLKSIZ <= MAXBSIZE!!
|
|
|
|
*/
|
|
|
|
#define NFS_DIRBLKSIZ (16 * DIRBLKSIZ) /* Must be a multiple of DIRBLKSIZ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define these macros to access mnt_flag fields.
|
|
|
|
*/
|
|
|
|
#define NFSMNT_RDONLY(m) ((m)->mnt_flag & MNT_RDONLY)
|
|
|
|
#endif /* _KERNEL */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define a structure similar to ufs_args for use in exporting the V4 root.
|
|
|
|
*/
|
|
|
|
struct nfsex_args {
|
|
|
|
char *fspec;
|
|
|
|
struct export_args export;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These export flags should be defined, but there are no bits left.
|
|
|
|
* Maybe a separate mnt_exflag field could be added or the mnt_flag
|
|
|
|
* field increased to 64 bits?
|
|
|
|
*/
|
|
|
|
#ifndef MNT_EXSTRICTACCESS
|
|
|
|
#define MNT_EXSTRICTACCESS 0x0
|
|
|
|
#endif
|
|
|
|
#ifndef MNT_EXV4ONLY
|
|
|
|
#define MNT_EXV4ONLY 0x0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
/*
|
|
|
|
* Define this to invalidate the attribute cache for the nfs node.
|
|
|
|
*/
|
|
|
|
#define NFSINVALATTRCACHE(n) ((n)->n_attrstamp = 0)
|
|
|
|
|
|
|
|
/* Used for FreeBSD only */
|
|
|
|
void nfsd_mntinit(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define these for vnode lock/unlock ops.
|
2011-07-16 08:05:26 +00:00
|
|
|
*
|
|
|
|
* These are good abstractions to macro out, so that they can be added to
|
|
|
|
* later, for debugging or stats, etc.
|
2009-05-04 15:23:58 +00:00
|
|
|
*/
|
2011-07-16 08:05:26 +00:00
|
|
|
#define NFSVOPLOCK(v, f) vn_lock((v), (f))
|
|
|
|
#define NFSVOPUNLOCK(v, f) VOP_UNLOCK((v), (f))
|
|
|
|
#define NFSVOPISLOCKED(v) VOP_ISLOCKED((v))
|
2009-05-04 15:23:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Define ncl_hash().
|
|
|
|
*/
|
|
|
|
#define ncl_hash(f, l) (fnv_32_buf((f), (l), FNV1_32_INIT))
|
|
|
|
|
|
|
|
int newnfs_iosize(struct nfsmount *);
|
|
|
|
|
|
|
|
int newnfs_vncmpf(struct vnode *, void *);
|
|
|
|
|
|
|
|
#ifndef NFS_MINDIRATTRTIMO
|
|
|
|
#define NFS_MINDIRATTRTIMO 3 /* VDIR attrib cache timeout in sec */
|
|
|
|
#endif
|
|
|
|
#ifndef NFS_MAXDIRATTRTIMO
|
|
|
|
#define NFS_MAXDIRATTRTIMO 60
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Nfs outstanding request list element
|
|
|
|
*/
|
|
|
|
struct nfsreq {
|
|
|
|
TAILQ_ENTRY(nfsreq) r_chain;
|
|
|
|
u_int32_t r_flags; /* flags on request, see below */
|
|
|
|
struct nfsmount *r_nmp; /* Client mnt ptr */
|
|
|
|
struct mtx r_mtx; /* Mutex lock for this structure */
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef NFS_MAXBSIZE
|
2017-06-17 22:24:19 +00:00
|
|
|
#define NFS_MAXBSIZE (maxbcachebuf)
|
2009-05-04 15:23:58 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This macro checks to see if issuing of delegations is allowed for this
|
|
|
|
* vnode.
|
|
|
|
*/
|
|
|
|
#ifdef VV_DISABLEDELEG
|
|
|
|
#define NFSVNO_DELEGOK(v) \
|
|
|
|
((v) == NULL || ((v)->v_vflag & VV_DISABLEDELEG) == 0)
|
|
|
|
#else
|
|
|
|
#define NFSVNO_DELEGOK(v) (1)
|
|
|
|
#endif
|
|
|
|
|
2015-11-29 21:01:02 +00:00
|
|
|
/*
|
|
|
|
* Name used by getnewvnode() to describe filesystem, "nfs".
|
2016-04-29 16:07:25 +00:00
|
|
|
* For performance reasons it is useful to have the same string
|
2015-11-29 21:01:02 +00:00
|
|
|
* used in both places that call getnewvnode().
|
|
|
|
*/
|
|
|
|
extern const char nfs_vnode_tag[];
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
* Check for the errors that indicate a DS should be disabled.
|
|
|
|
* ENXIO indicates that the krpc cannot do an RPC on the DS.
|
|
|
|
* EIO is returned by the RPC as an indication of I/O problems on the
|
|
|
|
* server.
|
|
|
|
* Are there other fatal errors?
|
|
|
|
*/
|
|
|
|
#define nfsds_failerr(e) ((e) == ENXIO || (e) == EIO)
|
|
|
|
|
2018-06-14 10:00:19 +00:00
|
|
|
/*
|
|
|
|
* Get a pointer to the MDS session, which is always the first element
|
|
|
|
* in the list.
|
|
|
|
* This macro can only be safely used when the NFSLOCKMNT() lock is held.
|
|
|
|
* The inline function can be used when the lock isn't held.
|
|
|
|
*/
|
|
|
|
#define NFSMNT_MDSSESSION(m) (&(TAILQ_FIRST(&((m)->nm_sess))->nfsclds_sess))
|
|
|
|
|
|
|
|
static __inline struct nfsclsession *
|
|
|
|
nfsmnt_mdssession(struct nfsmount *nmp)
|
|
|
|
{
|
|
|
|
struct nfsclsession *tsep;
|
|
|
|
|
|
|
|
tsep = NULL;
|
|
|
|
mtx_lock(&nmp->nm_mtx);
|
|
|
|
if (TAILQ_FIRST(&nmp->nm_sess) != NULL)
|
|
|
|
tsep = NFSMNT_MDSSESSION(nmp);
|
|
|
|
mtx_unlock(&nmp->nm_mtx);
|
|
|
|
return (tsep);
|
|
|
|
}
|
|
|
|
|
2009-05-04 15:23:58 +00:00
|
|
|
#endif /* _KERNEL */
|
|
|
|
|
2010-05-08 14:50:12 +00:00
|
|
|
#endif /* _NFS_NFSPORT_H */
|