Whamcloud - gitweb
LU-1330 fld: prepare FLD module for client server split
[fs/lustre-release.git] / lustre / fld / fld_internal.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2013, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/fld/fld_internal.h
37  *
38  * Author: Yury Umanets <umka@clusterfs.com>
39  * Author: Tom WangDi <wangdi@clusterfs.com>
40  */
41 #ifndef __FLD_INTERNAL_H
42 #define __FLD_INTERNAL_H
43
44 #include <obd.h>
45 #include <lustre/lustre_idl.h>
46 #include <libcfs/libcfs.h>
47 #include <lustre_fld.h>
48
49 enum {
50         LUSTRE_FLD_INIT = 1 << 0,
51         LUSTRE_FLD_RUN  = 1 << 1
52 };
53
54 struct fld_stats {
55         __u64   fst_count;
56         __u64   fst_cache;
57 };
58
59 typedef int (*fld_hash_func_t) (struct lu_client_fld *, __u64);
60
61 typedef struct lu_fld_target *
62 (*fld_scan_func_t) (struct lu_client_fld *, __u64);
63
64 struct lu_fld_hash {
65         const char              *fh_name;
66         fld_hash_func_t          fh_hash_func;
67         fld_scan_func_t          fh_scan_func;
68 };
69
70 struct fld_cache_entry {
71         cfs_list_t               fce_lru;
72         cfs_list_t               fce_list;
73         /**
74          * fld cache entries are sorted on range->lsr_start field. */
75         struct lu_seq_range      fce_range;
76 };
77
78 struct fld_cache {
79         /**
80          * Cache guard, protects fci_hash mostly because others immutable after
81          * init is finished.
82          */
83         rwlock_t                 fci_lock;
84
85         /**
86          * Cache shrink threshold */
87         int                      fci_threshold;
88
89         /**
90          * Prefered number of cached entries */
91         int                      fci_cache_size;
92
93         /**
94          * Current number of cached entries. Protected by \a fci_lock */
95         int                      fci_cache_count;
96
97         /**
98          * LRU list fld entries. */
99         cfs_list_t               fci_lru;
100
101         /**
102          * sorted fld entries. */
103         cfs_list_t               fci_entries_head;
104
105         /**
106          * Cache statistics. */
107         struct fld_stats         fci_stat;
108
109         /**
110          * Cache name used for debug and messages. */
111         char                     fci_name[80];
112         unsigned int             fci_no_shrink:1;
113 };
114
115 enum fld_op {
116         FLD_CREATE = 0,
117         FLD_DELETE = 1,
118         FLD_LOOKUP = 2
119 };
120
121 enum {
122         /* 4M of FLD cache will not hurt client a lot. */
123         FLD_SERVER_CACHE_SIZE      = (4 * 0x100000),
124
125         /* 1M of FLD cache will not hurt client a lot. */
126         FLD_CLIENT_CACHE_SIZE      = (1 * 0x100000)
127 };
128
129 enum {
130         /* Cache threshold is 10 percent of size. */
131         FLD_SERVER_CACHE_THRESHOLD = 10,
132
133         /* Cache threshold is 10 percent of size. */
134         FLD_CLIENT_CACHE_THRESHOLD = 10
135 };
136
137 extern struct lu_fld_hash fld_hash[];
138
139 #ifdef __KERNEL__
140
141 # ifdef LPROCFS
142 extern struct proc_dir_entry *fld_type_proc_dir;
143 extern struct lprocfs_vars fld_client_proc_list[];
144 # endif
145
146 # ifdef HAVE_SERVER_SUPPORT
147 struct req_capsule;
148 struct fld_thread_info {
149         struct req_capsule *fti_pill;
150         struct lu_seq_range fti_rec;
151         struct lu_seq_range fti_lrange;
152         struct lu_seq_range fti_irange;
153 };
154
155 extern struct lu_context_key fld_thread_key;
156
157 struct dt_device;
158 int fld_index_init(const struct lu_env *env, struct lu_server_fld *fld,
159                    struct dt_device *dt);
160
161 void fld_index_fini(const struct lu_env *env, struct lu_server_fld *fld);
162
163 int fld_declare_index_create(const struct lu_env *env,
164                              struct lu_server_fld *fld,
165                              const struct lu_seq_range *new_range,
166                              struct thandle *th);
167
168 int fld_index_create(const struct lu_env *env, struct lu_server_fld *fld,
169                      const struct lu_seq_range *new_range, struct thandle *th);
170
171 int fld_index_lookup(const struct lu_env *env, struct lu_server_fld *fld,
172                      seqno_t seq, struct lu_seq_range *range);
173
174 int fld_server_mod_init(void);
175
176 void fld_server_mod_exit(void);
177
178 # ifdef LPROCFS
179 extern const struct file_operations fld_proc_seq_fops;
180 extern struct lprocfs_vars fld_server_proc_list[];
181 # endif
182
183 # endif /* HAVE_SERVER_SUPPORT */
184
185 int fld_client_rpc(struct obd_export *exp,
186                    struct lu_seq_range *range, __u32 fld_op);
187
188 #endif /* __KERNEL__ */
189
190 struct fld_cache *fld_cache_init(const char *name,
191                                  int cache_size, int cache_threshold);
192
193 void fld_cache_fini(struct fld_cache *cache);
194
195 void fld_cache_flush(struct fld_cache *cache);
196
197 int fld_cache_insert(struct fld_cache *cache,
198                      const struct lu_seq_range *range);
199
200 struct fld_cache_entry
201 *fld_cache_entry_create(const struct lu_seq_range *range);
202
203 int fld_cache_insert_nolock(struct fld_cache *cache,
204                             struct fld_cache_entry *f_new);
205 void fld_cache_delete(struct fld_cache *cache,
206                       const struct lu_seq_range *range);
207 void fld_cache_delete_nolock(struct fld_cache *cache,
208                              const struct lu_seq_range *range);
209 int fld_cache_lookup(struct fld_cache *cache,
210                      const seqno_t seq, struct lu_seq_range *range);
211
212 struct fld_cache_entry *
213 fld_cache_entry_lookup(struct fld_cache *cache,
214                        const struct lu_seq_range *range);
215
216 void fld_cache_entry_delete(struct fld_cache *cache,
217                             struct fld_cache_entry *node);
218
219 struct fld_cache_entry *
220 fld_cache_entry_lookup_nolock(struct fld_cache *cache,
221                               const struct lu_seq_range *range);
222
223 static inline const char *
224 fld_target_name(const struct lu_fld_target *tar)
225 {
226 #ifdef HAVE_SERVER_SUPPORT
227         if (tar->ft_srv != NULL)
228                 return tar->ft_srv->lsf_name;
229 #endif
230
231         return tar->ft_exp->exp_obd->obd_name;
232 }
233
234 #endif /* __FLD_INTERNAL_H */