1184588Sdfr/*-
2184588Sdfr * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
3184588Sdfr *
4184588Sdfr * Redistribution and use in source and binary forms, with or without
5184588Sdfr * modification, are permitted provided that the following conditions
6184588Sdfr * are met:
7184588Sdfr * 1. Redistributions of source code must retain the above copyright
8184588Sdfr *    notice, this list of conditions and the following disclaimer.
9184588Sdfr * 2. Redistributions in binary form must reproduce the above copyright
10184588Sdfr *    notice, this list of conditions and the following disclaimer in the
11184588Sdfr *    documentation and/or other materials provided with the distribution.
12184588Sdfr *
13184588Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14184588Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15184588Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16184588Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17184588Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18184588Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19184588Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20184588Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21184588Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22184588Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23184588Sdfr * SUCH DAMAGE.
24184588Sdfr */
25184588Sdfr/* $FreeBSD$ */
26184588Sdfr
27249592Sken#ifndef	_NFS_FHA_H
28249592Sken#define	_NFS_FHA_H 1
29249592Sken
30249592Sken#ifdef	_KERNEL
31249592Sken
32249592Sken/* Sysctl defaults. */
33249592Sken#define FHA_DEF_ENABLE			1
34249592Sken#define FHA_DEF_BIN_SHIFT		22 /* 4MB */
35249592Sken#define FHA_DEF_MAX_NFSDS_PER_FH	8
36249592Sken#define FHA_DEF_MAX_REQS_PER_NFSD	0  /* Unlimited */
37249592Sken
38261054Smav#define FHA_HASH_SIZE	251
39249592Sken
40249592Skenstruct fha_ctls {
41249592Sken	int	 enable;
42249592Sken	uint32_t bin_shift;
43249592Sken	uint32_t max_nfsds_per_fh;
44249592Sken	uint32_t max_reqs_per_nfsd;
45249592Sken};
46249592Sken
47249592Sken/*
48249592Sken * These are the entries in the filehandle hash.  They talk about a specific
49249592Sken * file, requests against which are being handled by one or more nfsds.  We
50249592Sken * keep a chain of nfsds against the file. We only have more than one if reads
51249592Sken * are ongoing, and then only if the reads affect disparate regions of the
52249592Sken * file.
53249592Sken *
54249592Sken * In general, we want to assign a new request to an existing nfsd if it is
55249592Sken * going to contend with work happening already on that nfsd, or if the
56249592Sken * operation is a read and the nfsd is already handling a proximate read.  We
57249592Sken * do this to avoid jumping around in the read stream unnecessarily, and to
58249592Sken * avoid contention between threads over single files.
59249592Sken */
60249592Skenstruct fha_hash_entry {
61261054Smav	struct mtx *mtx;
62249592Sken	LIST_ENTRY(fha_hash_entry) link;
63249592Sken	u_int64_t fh;
64249592Sken	u_int32_t num_rw;
65249592Sken	u_int32_t num_exclusive;
66249592Sken	u_int8_t num_threads;
67249592Sken	struct svcthread_list threads;
68249592Sken};
69249592Sken
70249592SkenLIST_HEAD(fha_hash_entry_list, fha_hash_entry);
71249592Sken
72261054Smavstruct fha_hash_slot {
73261054Smav	struct fha_hash_entry_list list;
74261054Smav	struct mtx mtx;
75261054Smav};
76261054Smav
77249592Sken/* A structure used for passing around data internally. */
78249592Skenstruct fha_info {
79249592Sken	u_int64_t fh;
80249592Sken	off_t offset;
81249592Sken	int locktype;
82249592Sken};
83249592Sken
84249592Skenstruct fha_callbacks {
85249592Sken	rpcproc_t (*get_procnum)(rpcproc_t procnum);
86249592Sken	int (*realign)(struct mbuf **mb, int malloc_flags);
87261049Smav	int (*get_fh)(uint64_t *fh, int v3, struct mbuf **md, caddr_t *dpos);
88249592Sken	int (*is_read)(rpcproc_t procnum);
89249592Sken	int (*is_write)(rpcproc_t procnum);
90249592Sken	int (*get_offset)(struct mbuf **md, caddr_t *dpos, int v3, struct
91249592Sken			  fha_info *info);
92249592Sken	int (*no_offset)(rpcproc_t procnum);
93249592Sken	void (*set_locktype)(rpcproc_t procnum, struct fha_info *info);
94249592Sken	int (*fhe_stats_sysctl)(SYSCTL_HANDLER_ARGS);
95249592Sken};
96249592Sken
97249592Skenstruct fha_params {
98261054Smav	struct fha_hash_slot fha_hash[FHA_HASH_SIZE];
99249592Sken	struct sysctl_ctx_list sysctl_ctx;
100249592Sken	struct sysctl_oid *sysctl_tree;
101249592Sken	struct fha_ctls ctls;
102249592Sken	struct fha_callbacks callbacks;
103249592Sken	char server_name[32];
104249592Sken	SVCPOOL **pool;
105249592Sken};
106249592Sken
107184588Sdfrvoid fha_nd_complete(SVCTHREAD *, struct svc_req *);
108249592SkenSVCTHREAD *fha_assign(SVCTHREAD *, struct svc_req *, struct fha_params *);
109249592Skenvoid fha_init(struct fha_params *softc);
110249592Skenvoid fha_uninit(struct fha_params *softc);
111249592Skenint fhe_stats_sysctl(SYSCTL_HANDLER_ARGS, struct fha_params *softc);
112249592Sken
113249592Sken#endif /* _KERNEL */
114249592Sken#endif /* _NFS_FHA_H_ */
115