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