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: stable/11/sys/nfs/nfs_fha.h 322137 2017-08-07 07:02:51Z mav $ */ 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 34322137Smav#define FHA_DEF_READ 1 35322137Smav#define FHA_DEF_WRITE 1 36249592Sken#define FHA_DEF_BIN_SHIFT 22 /* 4MB */ 37249592Sken#define FHA_DEF_MAX_NFSDS_PER_FH 8 38249592Sken#define FHA_DEF_MAX_REQS_PER_NFSD 0 /* Unlimited */ 39249592Sken 40260097Smav#define FHA_HASH_SIZE 251 41249592Sken 42249592Skenstruct fha_ctls { 43249592Sken int enable; 44322137Smav int read; 45322137Smav int write; 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 { 65260097Smav struct mtx *mtx; 66249592Sken LIST_ENTRY(fha_hash_entry) link; 67249592Sken u_int64_t fh; 68249592Sken u_int32_t num_rw; 69249592Sken u_int32_t num_exclusive; 70249592Sken u_int8_t num_threads; 71249592Sken struct svcthread_list threads; 72249592Sken}; 73249592Sken 74249592SkenLIST_HEAD(fha_hash_entry_list, fha_hash_entry); 75249592Sken 76260097Smavstruct fha_hash_slot { 77260097Smav struct fha_hash_entry_list list; 78260097Smav struct mtx mtx; 79260097Smav}; 80260097Smav 81249592Sken/* A structure used for passing around data internally. */ 82249592Skenstruct fha_info { 83249592Sken u_int64_t fh; 84249592Sken off_t offset; 85249592Sken int locktype; 86322137Smav int read; 87322137Smav int write; 88249592Sken}; 89249592Sken 90249592Skenstruct fha_callbacks { 91249592Sken rpcproc_t (*get_procnum)(rpcproc_t procnum); 92249592Sken int (*realign)(struct mbuf **mb, int malloc_flags); 93259765Smav int (*get_fh)(uint64_t *fh, int v3, struct mbuf **md, caddr_t *dpos); 94249592Sken int (*is_read)(rpcproc_t procnum); 95249592Sken int (*is_write)(rpcproc_t procnum); 96249592Sken int (*get_offset)(struct mbuf **md, caddr_t *dpos, int v3, struct 97249592Sken fha_info *info); 98249592Sken int (*no_offset)(rpcproc_t procnum); 99249592Sken void (*set_locktype)(rpcproc_t procnum, struct fha_info *info); 100249592Sken int (*fhe_stats_sysctl)(SYSCTL_HANDLER_ARGS); 101249592Sken}; 102249592Sken 103249592Skenstruct fha_params { 104260097Smav struct fha_hash_slot fha_hash[FHA_HASH_SIZE]; 105249592Sken struct sysctl_ctx_list sysctl_ctx; 106249592Sken struct sysctl_oid *sysctl_tree; 107249592Sken struct fha_ctls ctls; 108249592Sken struct fha_callbacks callbacks; 109249592Sken char server_name[32]; 110249592Sken SVCPOOL **pool; 111249592Sken}; 112249592Sken 113184588Sdfrvoid fha_nd_complete(SVCTHREAD *, struct svc_req *); 114249592SkenSVCTHREAD *fha_assign(SVCTHREAD *, struct svc_req *, struct fha_params *); 115249592Skenvoid fha_init(struct fha_params *softc); 116249592Skenvoid fha_uninit(struct fha_params *softc); 117249592Skenint fhe_stats_sysctl(SYSCTL_HANDLER_ARGS, struct fha_params *softc); 118249592Sken 119249592Sken#endif /* _KERNEL */ 120249592Sken#endif /* _NFS_FHA_H_ */ 121