nfs_fha.h revision 249592
1132720Skan/*-
2132720Skan * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
3132720Skan *
4132720Skan * Redistribution and use in source and binary forms, with or without
5132720Skan * modification, are permitted provided that the following conditions
6132720Skan * are met:
7132720Skan * 1. Redistributions of source code must retain the above copyright
8132720Skan *    notice, this list of conditions and the following disclaimer.
9132720Skan * 2. Redistributions in binary form must reproduce the above copyright
10132720Skan *    notice, this list of conditions and the following disclaimer in the
11132720Skan *    documentation and/or other materials provided with the distribution.
12132720Skan *
13132720Skan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14132720Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15132720Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16132720Skan * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17132720Skan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18132720Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19132720Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20169691Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21169691Skan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22132720Skan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23132720Skan * SUCH DAMAGE.
24132720Skan */
25132720Skan/* $FreeBSD: head/sys/nfsserver/nfs_fha.h 249592 2013-04-17 21:00:22Z ken $ */
26132720Skan
27132720Skan#ifndef	_NFS_FHA_H
28132720Skan#define	_NFS_FHA_H 1
29132720Skan
30132720Skan#ifdef	_KERNEL
31132720Skan
32132720Skan/* Sysctl defaults. */
33169691Skan#define FHA_DEF_ENABLE			1
34169691Skan#define FHA_DEF_BIN_SHIFT		22 /* 4MB */
35169691Skan#define FHA_DEF_MAX_NFSDS_PER_FH	8
36132720Skan#define FHA_DEF_MAX_REQS_PER_NFSD	0  /* Unlimited */
37132720Skan
38132720Skan/* This is the global structure that represents the state of the fha system. */
39132720Skanstruct fha_global {
40132720Skan	struct fha_hash_entry_list *hashtable;
41132720Skan	u_long hashmask;
42169691Skan};
43169691Skan
44169691Skanstruct fha_ctls {
45132720Skan	int	 enable;
46132720Skan	uint32_t bin_shift;
47132720Skan	uint32_t max_nfsds_per_fh;
48132720Skan	uint32_t max_reqs_per_nfsd;
49132720Skan};
50132720Skan
51132720Skan/*
52132720Skan * These are the entries in the filehandle hash.  They talk about a specific
53132720Skan * file, requests against which are being handled by one or more nfsds.  We
54132720Skan * keep a chain of nfsds against the file. We only have more than one if reads
55132720Skan * are ongoing, and then only if the reads affect disparate regions of the
56132720Skan * file.
57132720Skan *
58132720Skan * In general, we want to assign a new request to an existing nfsd if it is
59132720Skan * going to contend with work happening already on that nfsd, or if the
60132720Skan * operation is a read and the nfsd is already handling a proximate read.  We
61132720Skan * do this to avoid jumping around in the read stream unnecessarily, and to
62132720Skan * avoid contention between threads over single files.
63132720Skan */
64132720Skanstruct fha_hash_entry {
65132720Skan	LIST_ENTRY(fha_hash_entry) link;
66132720Skan	u_int64_t fh;
67132720Skan	u_int32_t num_rw;
68132720Skan	u_int32_t num_exclusive;
69132720Skan	u_int8_t num_threads;
70169691Skan	struct svcthread_list threads;
71169691Skan};
72169691Skan
73169691SkanLIST_HEAD(fha_hash_entry_list, fha_hash_entry);
74132720Skan
75132720Skan/* A structure used for passing around data internally. */
76132720Skanstruct fha_info {
77132720Skan	u_int64_t fh;
78169691Skan	off_t offset;
79169691Skan	int locktype;
80132720Skan};
81132720Skan
82132720Skanstruct fha_callbacks {
83132720Skan	rpcproc_t (*get_procnum)(rpcproc_t procnum);
84132720Skan	int (*realign)(struct mbuf **mb, int malloc_flags);
85169691Skan	int (*get_fh)(fhandle_t *fh, int v3, struct mbuf **md, caddr_t *dpos);
86169691Skan	int (*is_read)(rpcproc_t procnum);
87169691Skan	int (*is_write)(rpcproc_t procnum);
88132720Skan	int (*get_offset)(struct mbuf **md, caddr_t *dpos, int v3, struct
89132720Skan			  fha_info *info);
90132720Skan	int (*no_offset)(rpcproc_t procnum);
91132720Skan	void (*set_locktype)(rpcproc_t procnum, struct fha_info *info);
92132720Skan	int (*fhe_stats_sysctl)(SYSCTL_HANDLER_ARGS);
93132720Skan};
94132720Skan
95169691Skanstruct fha_params {
96132720Skan	struct fha_global g_fha;
97132720Skan	struct sysctl_ctx_list sysctl_ctx;
98132720Skan	struct sysctl_oid *sysctl_tree;
99132720Skan	struct fha_ctls ctls;
100132720Skan	struct fha_callbacks callbacks;
101132720Skan	char server_name[32];
102132720Skan	SVCPOOL **pool;
103132720Skan};
104132720Skan
105132720Skanvoid fha_nd_complete(SVCTHREAD *, struct svc_req *);
106132720SkanSVCTHREAD *fha_assign(SVCTHREAD *, struct svc_req *, struct fha_params *);
107169691Skanvoid fha_init(struct fha_params *softc);
108132720Skanvoid fha_uninit(struct fha_params *softc);
109132720Skanint fhe_stats_sysctl(SYSCTL_HANDLER_ARGS, struct fha_params *softc);
110169691Skan
111169691Skan#endif /* _KERNEL */
112169691Skan#endif /* _NFS_FHA_H_ */
113169691Skan