nfs_fha.h revision 322137
12116Sjkh/*-
22116Sjkh * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
32116Sjkh *
42116Sjkh * Redistribution and use in source and binary forms, with or without
52116Sjkh * modification, are permitted provided that the following conditions
62116Sjkh * are met:
78870Srgrimes * 1. Redistributions of source code must retain the above copyright
82116Sjkh *    notice, this list of conditions and the following disclaimer.
92116Sjkh * 2. Redistributions in binary form must reproduce the above copyright
102116Sjkh *    notice, this list of conditions and the following disclaimer in the
112116Sjkh *    documentation and/or other materials provided with the distribution.
122116Sjkh *
132116Sjkh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1450476Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
152116Sjkh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
162116Sjkh * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
172116Sjkh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1887805Sphantom * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
192116Sjkh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20130264Sdas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21110566Smike * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22130713Sstefanf * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23110566Smike * SUCH DAMAGE.
242116Sjkh */
252116Sjkh/* $FreeBSD: stable/11/sys/nfs/nfs_fha.h 322137 2017-08-07 07:02:51Z mav $ */
262116Sjkh
27106268Sarchie#ifndef	_NFS_FHA_H
28106268Sarchie#define	_NFS_FHA_H 1
29106268Sarchie
30106268Sarchie#ifdef	_KERNEL
31110566Smike
32110566Smike/* Sysctl defaults. */
33110566Smike#define FHA_DEF_ENABLE			1
34110566Smike#define FHA_DEF_READ			1
35110566Smike#define FHA_DEF_WRITE			1
36110566Smike#define FHA_DEF_BIN_SHIFT		22 /* 4MB */
37135360Sdas#define FHA_DEF_MAX_NFSDS_PER_FH	8
38131851Sdas#define FHA_DEF_MAX_REQS_PER_NFSD	0  /* Unlimited */
39131851Sdas
40131851Sdas#define FHA_HASH_SIZE	251
41135360Sdas
42131851Sdasstruct fha_ctls {
43131851Sdas	int	 enable;
44131851Sdas	int	 read;
45131851Sdas	int	 write;
46131851Sdas	uint32_t bin_shift;
47131851Sdas	uint32_t max_nfsds_per_fh;
48128628Sdas	uint32_t max_reqs_per_nfsd;
49131851Sdas};
50128628Sdas
51128628Sdas/*
52130713Sstefanf * These are the entries in the filehandle hash.  They talk about a specific
53130713Sstefanf * file, requests against which are being handled by one or more nfsds.  We
54131851Sdas * keep a chain of nfsds against the file. We only have more than one if reads
55131851Sdas * are ongoing, and then only if the reads affect disparate regions of the
56131851Sdas * file.
57131851Sdas *
58186886Sdas * In general, we want to assign a new request to an existing nfsd if it is
59186886Sdas * going to contend with work happening already on that nfsd, or if the
60131851Sdas * operation is a read and the nfsd is already handling a proximate read.  We
61110566Smike * do this to avoid jumping around in the read stream unnecessarily, and to
62110566Smike * avoid contention between threads over single files.
63110566Smike */
64110566Smikestruct fha_hash_entry {
65131851Sdas	struct mtx *mtx;
662116Sjkh	LIST_ENTRY(fha_hash_entry) link;
67126871Sbde	u_int64_t fh;
68126871Sbde	u_int32_t num_rw;
69140265Sdas	u_int32_t num_exclusive;
70126871Sbde	u_int8_t num_threads;
71226374Sdas	struct svcthread_list threads;
72140609Sdas};
73110566Smike
74110769SmikeLIST_HEAD(fha_hash_entry_list, fha_hash_entry);
75110769Smike
76110769Smikestruct fha_hash_slot {
77110769Smike	struct fha_hash_entry_list list;
78110769Smike	struct mtx mtx;
79253215Stheraven};
80369606Sgit2svn
81369606Sgit2svn/* A structure used for passing around data internally. */
82253319Stheravenstruct fha_info {
83253319Stheraven	u_int64_t fh;
84253766Stheraven	off_t offset;
85253766Stheraven	int locktype;
86253766Stheraven	int read;
87253766Stheraven	int write;
88253766Stheraven};
89253766Stheraven
90253766Stheravenstruct fha_callbacks {
91253766Stheraven	rpcproc_t (*get_procnum)(rpcproc_t procnum);
92253766Stheraven	int (*realign)(struct mbuf **mb, int malloc_flags);
93253766Stheraven	int (*get_fh)(uint64_t *fh, int v3, struct mbuf **md, caddr_t *dpos);
94253260Stheraven	int (*is_read)(rpcproc_t procnum);
95253319Stheraven	int (*is_write)(rpcproc_t procnum);
96253319Stheraven	int (*get_offset)(struct mbuf **md, caddr_t *dpos, int v3, struct
97253319Stheraven			  fha_info *info);
98253319Stheraven	int (*no_offset)(rpcproc_t procnum);
99253319Stheraven	void (*set_locktype)(rpcproc_t procnum, struct fha_info *info);
100253319Stheraven	int (*fhe_stats_sysctl)(SYSCTL_HANDLER_ARGS);
101253215Stheraven};
102253319Stheraven
103253319Stheravenstruct fha_params {
104253319Stheraven	struct fha_hash_slot fha_hash[FHA_HASH_SIZE];
105253319Stheraven	struct sysctl_ctx_list sysctl_ctx;
106253215Stheraven	struct sysctl_oid *sysctl_tree;
107253215Stheraven	struct fha_ctls ctls;
108110566Smike	struct fha_callbacks callbacks;
109253219Stheraven	char server_name[32];
110253215Stheraven	SVCPOOL **pool;
111253215Stheraven};
112253215Stheraven
113253215Stheravenvoid fha_nd_complete(SVCTHREAD *, struct svc_req *);
114253215StheravenSVCTHREAD *fha_assign(SVCTHREAD *, struct svc_req *, struct fha_params *);
115110769Smikevoid fha_init(struct fha_params *softc);
116131851Sdasvoid fha_uninit(struct fha_params *softc);
117131851Sdasint fhe_stats_sysctl(SYSCTL_HANDLER_ARGS, struct fha_params *softc);
118131851Sdas
119131851Sdas#endif /* _KERNEL */
120131851Sdas#endif /* _NFS_FHA_H_ */
121131851Sdas