1 /* $NetBSD: nfs_fha.h,v 1.3 2016/11/18 08:31:30 pgoyette Exp $ */ 2 /*- 3 * Copyright (c) 2008 Isilon Inc http://www.isilon.com/ 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 /* FreeBSD: head/sys/nfs/nfs_fha.h 260097 2013-12-30 20:23:15Z mav */ 27 /* $NetBSD: nfs_fha.h,v 1.3 2016/11/18 08:31:30 pgoyette Exp $ */ 28 29 #ifndef _NFS_FHA_H 30 #define _NFS_FHA_H 1 31 32 #ifdef _KERNEL 33 34 /* Sysctl defaults. */ 35 #define FHA_DEF_ENABLE 1 36 #define FHA_DEF_BIN_SHIFT 22 /* 4MB */ 37 #define FHA_DEF_MAX_NFSDS_PER_FH 8 38 #define FHA_DEF_MAX_REQS_PER_NFSD 0 /* Unlimited */ 39 40 #define FHA_HASH_SIZE 251 41 42 struct fha_ctls { 43 int enable; 44 uint32_t bin_shift; 45 uint32_t max_nfsds_per_fh; 46 uint32_t max_reqs_per_nfsd; 47 }; 48 49 /* 50 * These are the entries in the filehandle hash. They talk about a specific 51 * file, requests against which are being handled by one or more nfsds. We 52 * keep a chain of nfsds against the file. We only have more than one if reads 53 * are ongoing, and then only if the reads affect disparate regions of the 54 * file. 55 * 56 * In general, we want to assign a new request to an existing nfsd if it is 57 * going to contend with work happening already on that nfsd, or if the 58 * operation is a read and the nfsd is already handling a proximate read. We 59 * do this to avoid jumping around in the read stream unnecessarily, and to 60 * avoid contention between threads over single files. 61 */ 62 struct fha_hash_entry { 63 struct mtx *mtx; 64 LIST_ENTRY(fha_hash_entry) link; 65 u_int64_t fh; 66 u_int32_t num_rw; 67 u_int32_t num_exclusive; 68 u_int8_t num_threads; 69 struct svcthread_list threads; 70 }; 71 72 LIST_HEAD(fha_hash_entry_list, fha_hash_entry); 73 74 struct fha_hash_slot { 75 struct fha_hash_entry_list list; 76 struct mtx mtx; 77 }; 78 79 /* A structure used for passing around data internally. */ 80 struct fha_info { 81 u_int64_t fh; 82 off_t offset; 83 int locktype; 84 }; 85 86 struct fha_callbacks { 87 rpcproc_t (*get_procnum)(rpcproc_t procnum); 88 int (*realign)(struct mbuf **mb, int malloc_flags); 89 int (*get_fh)(uint64_t *fh, int v3, struct mbuf **md, caddr_t *dpos); 90 int (*is_read)(rpcproc_t procnum); 91 int (*is_write)(rpcproc_t procnum); 92 int (*get_offset)(struct mbuf **md, caddr_t *dpos, int v3, struct 93 fha_info *info); 94 int (*no_offset)(rpcproc_t procnum); 95 void (*set_locktype)(rpcproc_t procnum, struct fha_info *info); 96 int (*fhe_stats_sysctl)(SYSCTL_HANDLER_ARGS); 97 }; 98 99 struct fha_params { 100 struct fha_hash_slot fha_hash[FHA_HASH_SIZE]; 101 struct sysctl_ctx_list sysctl_ctx; 102 struct sysctl_oid *sysctl_tree; 103 struct fha_ctls ctls; 104 struct fha_callbacks callbacks; 105 char server_name[32]; 106 SVCPOOL **pool; 107 }; 108 109 void fha_nd_complete(SVCTHREAD *, struct svc_req *); 110 SVCTHREAD *fha_assign(SVCTHREAD *, struct svc_req *, struct fha_params *); 111 void fha_init(struct fha_params *softc); 112 void fha_uninit(struct fha_params *softc); 113 int fhe_stats_sysctl(SYSCTL_HANDLER_ARGS, struct fha_params *softc); 114 115 #endif /* _KERNEL */ 116 #endif /* _NFS_FHA_H_ */ 117