nfs_fha.h revision 249592
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: head/sys/nfsserver/nfs_fha.h 249592 2013-04-17 21:00:22Z ken $ */
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
38249592Sken/* This is the global structure that represents the state of the fha system. */
39249592Skenstruct fha_global {
40249592Sken	struct fha_hash_entry_list *hashtable;
41249592Sken	u_long hashmask;
42249592Sken};
43249592Sken
44249592Skenstruct fha_ctls {
45249592Sken	int	 enable;
46249592Sken	uint32_t bin_shift;
47249592Sken	uint32_t max_nfsds_per_fh;
48249592Sken	uint32_t max_reqs_per_nfsd;
49249592Sken};
50249592Sken
51249592Sken/*
52249592Sken * These are the entries in the filehandle hash.  They talk about a specific
53249592Sken * file, requests against which are being handled by one or more nfsds.  We
54249592Sken * keep a chain of nfsds against the file. We only have more than one if reads
55249592Sken * are ongoing, and then only if the reads affect disparate regions of the
56249592Sken * file.
57249592Sken *
58249592Sken * In general, we want to assign a new request to an existing nfsd if it is
59249592Sken * going to contend with work happening already on that nfsd, or if the
60249592Sken * operation is a read and the nfsd is already handling a proximate read.  We
61249592Sken * do this to avoid jumping around in the read stream unnecessarily, and to
62249592Sken * avoid contention between threads over single files.
63249592Sken */
64249592Skenstruct fha_hash_entry {
65249592Sken	LIST_ENTRY(fha_hash_entry) link;
66249592Sken	u_int64_t fh;
67249592Sken	u_int32_t num_rw;
68249592Sken	u_int32_t num_exclusive;
69249592Sken	u_int8_t num_threads;
70249592Sken	struct svcthread_list threads;
71249592Sken};
72249592Sken
73249592SkenLIST_HEAD(fha_hash_entry_list, fha_hash_entry);
74249592Sken
75249592Sken/* A structure used for passing around data internally. */
76249592Skenstruct fha_info {
77249592Sken	u_int64_t fh;
78249592Sken	off_t offset;
79249592Sken	int locktype;
80249592Sken};
81249592Sken
82249592Skenstruct fha_callbacks {
83249592Sken	rpcproc_t (*get_procnum)(rpcproc_t procnum);
84249592Sken	int (*realign)(struct mbuf **mb, int malloc_flags);
85249592Sken	int (*get_fh)(fhandle_t *fh, int v3, struct mbuf **md, caddr_t *dpos);
86249592Sken	int (*is_read)(rpcproc_t procnum);
87249592Sken	int (*is_write)(rpcproc_t procnum);
88249592Sken	int (*get_offset)(struct mbuf **md, caddr_t *dpos, int v3, struct
89249592Sken			  fha_info *info);
90249592Sken	int (*no_offset)(rpcproc_t procnum);
91249592Sken	void (*set_locktype)(rpcproc_t procnum, struct fha_info *info);
92249592Sken	int (*fhe_stats_sysctl)(SYSCTL_HANDLER_ARGS);
93249592Sken};
94249592Sken
95249592Skenstruct fha_params {
96249592Sken	struct fha_global g_fha;
97249592Sken	struct sysctl_ctx_list sysctl_ctx;
98249592Sken	struct sysctl_oid *sysctl_tree;
99249592Sken	struct fha_ctls ctls;
100249592Sken	struct fha_callbacks callbacks;
101249592Sken	char server_name[32];
102249592Sken	SVCPOOL **pool;
103249592Sken};
104249592Sken
105184588Sdfrvoid fha_nd_complete(SVCTHREAD *, struct svc_req *);
106249592SkenSVCTHREAD *fha_assign(SVCTHREAD *, struct svc_req *, struct fha_params *);
107249592Skenvoid fha_init(struct fha_params *softc);
108249592Skenvoid fha_uninit(struct fha_params *softc);
109249592Skenint fhe_stats_sysctl(SYSCTL_HANDLER_ARGS, struct fha_params *softc);
110249592Sken
111249592Sken#endif /* _KERNEL */
112249592Sken#endif /* _NFS_FHA_H_ */
113