xref: /netbsd-src/sys/fs/nfs/common/nfs_fha.h (revision 2d39560c47b8faa0bdccc77937d8364c2346cc82)
1*2d39560cSpgoyette /*	$NetBSD: nfs_fha.h,v 1.3 2016/11/18 08:31:30 pgoyette Exp $	*/
26ca35587Sdholland /*-
36ca35587Sdholland  * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
46ca35587Sdholland  *
56ca35587Sdholland  * Redistribution and use in source and binary forms, with or without
66ca35587Sdholland  * modification, are permitted provided that the following conditions
76ca35587Sdholland  * are met:
86ca35587Sdholland  * 1. Redistributions of source code must retain the above copyright
96ca35587Sdholland  *    notice, this list of conditions and the following disclaimer.
106ca35587Sdholland  * 2. Redistributions in binary form must reproduce the above copyright
116ca35587Sdholland  *    notice, this list of conditions and the following disclaimer in the
126ca35587Sdholland  *    documentation and/or other materials provided with the distribution.
136ca35587Sdholland  *
146ca35587Sdholland  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
156ca35587Sdholland  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
166ca35587Sdholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
176ca35587Sdholland  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
186ca35587Sdholland  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
196ca35587Sdholland  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
206ca35587Sdholland  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
216ca35587Sdholland  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
226ca35587Sdholland  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
236ca35587Sdholland  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
246ca35587Sdholland  * SUCH DAMAGE.
256ca35587Sdholland  */
26*2d39560cSpgoyette /* FreeBSD: head/sys/nfs/nfs_fha.h 260097 2013-12-30 20:23:15Z mav  */
27*2d39560cSpgoyette /* $NetBSD: nfs_fha.h,v 1.3 2016/11/18 08:31:30 pgoyette Exp $ */
286ca35587Sdholland 
296ca35587Sdholland #ifndef	_NFS_FHA_H
306ca35587Sdholland #define	_NFS_FHA_H 1
316ca35587Sdholland 
326ca35587Sdholland #ifdef	_KERNEL
336ca35587Sdholland 
346ca35587Sdholland /* Sysctl defaults. */
356ca35587Sdholland #define FHA_DEF_ENABLE			1
366ca35587Sdholland #define FHA_DEF_BIN_SHIFT		22 /* 4MB */
376ca35587Sdholland #define FHA_DEF_MAX_NFSDS_PER_FH	8
386ca35587Sdholland #define FHA_DEF_MAX_REQS_PER_NFSD	0  /* Unlimited */
396ca35587Sdholland 
40*2d39560cSpgoyette #define FHA_HASH_SIZE	251
416ca35587Sdholland 
426ca35587Sdholland struct fha_ctls {
436ca35587Sdholland 	int	 enable;
446ca35587Sdholland 	uint32_t bin_shift;
456ca35587Sdholland 	uint32_t max_nfsds_per_fh;
466ca35587Sdholland 	uint32_t max_reqs_per_nfsd;
476ca35587Sdholland };
486ca35587Sdholland 
496ca35587Sdholland /*
506ca35587Sdholland  * These are the entries in the filehandle hash.  They talk about a specific
516ca35587Sdholland  * file, requests against which are being handled by one or more nfsds.  We
526ca35587Sdholland  * keep a chain of nfsds against the file. We only have more than one if reads
536ca35587Sdholland  * are ongoing, and then only if the reads affect disparate regions of the
546ca35587Sdholland  * file.
556ca35587Sdholland  *
566ca35587Sdholland  * In general, we want to assign a new request to an existing nfsd if it is
576ca35587Sdholland  * going to contend with work happening already on that nfsd, or if the
586ca35587Sdholland  * operation is a read and the nfsd is already handling a proximate read.  We
596ca35587Sdholland  * do this to avoid jumping around in the read stream unnecessarily, and to
606ca35587Sdholland  * avoid contention between threads over single files.
616ca35587Sdholland  */
626ca35587Sdholland struct fha_hash_entry {
63*2d39560cSpgoyette 	struct mtx *mtx;
646ca35587Sdholland 	LIST_ENTRY(fha_hash_entry) link;
656ca35587Sdholland 	u_int64_t fh;
666ca35587Sdholland 	u_int32_t num_rw;
676ca35587Sdholland 	u_int32_t num_exclusive;
686ca35587Sdholland 	u_int8_t num_threads;
696ca35587Sdholland 	struct svcthread_list threads;
706ca35587Sdholland };
716ca35587Sdholland 
726ca35587Sdholland LIST_HEAD(fha_hash_entry_list, fha_hash_entry);
736ca35587Sdholland 
74*2d39560cSpgoyette struct fha_hash_slot {
75*2d39560cSpgoyette 	struct fha_hash_entry_list list;
76*2d39560cSpgoyette 	struct mtx mtx;
77*2d39560cSpgoyette };
78*2d39560cSpgoyette 
796ca35587Sdholland /* A structure used for passing around data internally. */
806ca35587Sdholland struct fha_info {
816ca35587Sdholland 	u_int64_t fh;
826ca35587Sdholland 	off_t offset;
836ca35587Sdholland 	int locktype;
846ca35587Sdholland };
856ca35587Sdholland 
866ca35587Sdholland struct fha_callbacks {
876ca35587Sdholland 	rpcproc_t (*get_procnum)(rpcproc_t procnum);
886ca35587Sdholland 	int (*realign)(struct mbuf **mb, int malloc_flags);
89*2d39560cSpgoyette 	int (*get_fh)(uint64_t *fh, int v3, struct mbuf **md, caddr_t *dpos);
906ca35587Sdholland 	int (*is_read)(rpcproc_t procnum);
916ca35587Sdholland 	int (*is_write)(rpcproc_t procnum);
926ca35587Sdholland 	int (*get_offset)(struct mbuf **md, caddr_t *dpos, int v3, struct
936ca35587Sdholland 			  fha_info *info);
946ca35587Sdholland 	int (*no_offset)(rpcproc_t procnum);
956ca35587Sdholland 	void (*set_locktype)(rpcproc_t procnum, struct fha_info *info);
966ca35587Sdholland 	int (*fhe_stats_sysctl)(SYSCTL_HANDLER_ARGS);
976ca35587Sdholland };
986ca35587Sdholland 
996ca35587Sdholland struct fha_params {
100*2d39560cSpgoyette 	struct fha_hash_slot fha_hash[FHA_HASH_SIZE];
1016ca35587Sdholland 	struct sysctl_ctx_list sysctl_ctx;
1026ca35587Sdholland 	struct sysctl_oid *sysctl_tree;
1036ca35587Sdholland 	struct fha_ctls ctls;
1046ca35587Sdholland 	struct fha_callbacks callbacks;
1056ca35587Sdholland 	char server_name[32];
1066ca35587Sdholland 	SVCPOOL **pool;
1076ca35587Sdholland };
1086ca35587Sdholland 
1096ca35587Sdholland void fha_nd_complete(SVCTHREAD *, struct svc_req *);
1106ca35587Sdholland SVCTHREAD *fha_assign(SVCTHREAD *, struct svc_req *, struct fha_params *);
1116ca35587Sdholland void fha_init(struct fha_params *softc);
1126ca35587Sdholland void fha_uninit(struct fha_params *softc);
1136ca35587Sdholland int fhe_stats_sysctl(SYSCTL_HANDLER_ARGS, struct fha_params *softc);
1146ca35587Sdholland 
1156ca35587Sdholland #endif /* _KERNEL */
1166ca35587Sdholland #endif /* _NFS_FHA_H_ */
117