Whamcloud - gitweb
LU-5478 style: get rid of seqno_t and mdsno_t typedefs
[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  * Subsystem Description:
39  * FLD is FID Location Database, which stores where (IE, on which MDT)
40  * FIDs are located.
41  * The database is basically a record file, each record consists of a FID
42  * sequence range, MDT/OST index, and flags. The FLD for the whole FS
43  * is only stored on the sequence controller(MDT0) right now, but each target
44  * also has its local FLD, which only stores the local sequence.
45  *
46  * The FLD subsystem usually has two tasks:
47  * 1. maintain the database, i.e. when the sequence controller allocates
48  * new sequence ranges to some nodes, it will call the FLD API to insert the
49  * location information <sequence_range, node_index> in FLDB.
50  *
51  * 2. Handle requests from other nodes, i.e. if client needs to know where
52  * the FID is located, if it can not find the information in the local cache,
53  * it will send a FLD lookup RPC to the FLD service, and the FLD service will
54  * look up the FLDB entry and return the location information to client.
55  *
56  * Author: Yury Umanets <umka@clusterfs.com>
57  * Author: Tom WangDi <wangdi@clusterfs.com>
58  */
59 #ifndef __FLD_INTERNAL_H
60 #define __FLD_INTERNAL_H
61
62 #include <obd.h>
63 #include <lustre/lustre_idl.h>
64 #include <libcfs/libcfs.h>
65 #include <lustre_fld.h>
66
67 enum {
68         LUSTRE_FLD_INIT = 1 << 0,
69         LUSTRE_FLD_RUN  = 1 << 1
70 };
71
72 struct fld_stats {
73         __u64   fst_count;
74         __u64   fst_cache;
75 };
76
77 typedef int (*fld_hash_func_t) (struct lu_client_fld *, __u64);
78
79 typedef struct lu_fld_target *
80 (*fld_scan_func_t) (struct lu_client_fld *, __u64);
81
82 struct lu_fld_hash {
83         const char              *fh_name;
84         fld_hash_func_t          fh_hash_func;
85         fld_scan_func_t          fh_scan_func;
86 };
87
88 struct fld_cache_entry {
89         struct list_head        fce_lru;
90         struct list_head        fce_list;
91         /**
92          * fld cache entries are sorted on range->lsr_start field. */
93         struct lu_seq_range     fce_range;
94 };
95
96 struct fld_cache {
97         /**
98          * Cache guard, protects fci_hash mostly because others immutable after
99          * init is finished.
100          */
101         rwlock_t                 fci_lock;
102
103         /**
104          * Cache shrink threshold */
105         int                      fci_threshold;
106
107         /**
108          * Prefered number of cached entries */
109         int                      fci_cache_size;
110
111         /**
112          * Current number of cached entries. Protected by \a fci_lock */
113         int                      fci_cache_count;
114
115         /**
116          * LRU list fld entries. */
117         struct list_head        fci_lru;
118
119         /**
120          * sorted fld entries. */
121         struct list_head        fci_entries_head;
122
123         /**
124          * Cache statistics. */
125         struct fld_stats         fci_stat;
126
127         /**
128          * Cache name used for debug and messages. */
129         char                     fci_name[80];
130         unsigned int             fci_no_shrink:1;
131 };
132
133 enum {
134         /* 4M of FLD cache will not hurt client a lot. */
135         FLD_SERVER_CACHE_SIZE      = (4 * 0x100000),
136
137         /* 1M of FLD cache will not hurt client a lot. */
138         FLD_CLIENT_CACHE_SIZE      = (1 * 0x100000)
139 };
140
141 enum {
142         /* Cache threshold is 10 percent of size. */
143         FLD_SERVER_CACHE_THRESHOLD = 10,
144
145         /* Cache threshold is 10 percent of size. */
146         FLD_CLIENT_CACHE_THRESHOLD = 10
147 };
148
149 extern struct lu_fld_hash fld_hash[];
150
151 #ifdef __KERNEL__
152
153 #ifdef LPROCFS
154 extern struct proc_dir_entry *fld_type_proc_dir;
155 extern struct lprocfs_seq_vars fld_client_proc_list[];
156 #endif
157
158 # ifdef HAVE_SERVER_SUPPORT
159 struct fld_thread_info {
160         struct lu_seq_range fti_rec;
161         struct lu_seq_range fti_lrange;
162         struct lu_seq_range fti_irange;
163 };
164
165 extern struct lu_context_key fld_thread_key;
166
167 struct dt_device;
168 int fld_index_init(const struct lu_env *env, struct lu_server_fld *fld,
169                    struct dt_device *dt, int type);
170
171 void fld_index_fini(const struct lu_env *env, struct lu_server_fld *fld);
172
173 int fld_declare_index_create(const struct lu_env *env,
174                              struct lu_server_fld *fld,
175                              const struct lu_seq_range *new_range,
176                              struct thandle *th);
177
178 int fld_index_create(const struct lu_env *env, struct lu_server_fld *fld,
179                      const struct lu_seq_range *new_range, struct thandle *th);
180
181 int fld_index_lookup(const struct lu_env *env, struct lu_server_fld *fld,
182                      u64 seq, struct lu_seq_range *range);
183
184 int fld_name_to_index(const char *name, __u32 *index);
185 int fld_server_mod_init(void);
186
187 void fld_server_mod_exit(void);
188
189 int fld_server_read(const struct lu_env *env, struct lu_server_fld *fld,
190                     struct lu_seq_range *range, void *data, int data_len);
191 #ifdef LPROCFS
192 extern const struct file_operations fld_proc_seq_fops;
193 extern struct lprocfs_seq_vars fld_server_proc_list[];
194 #endif
195
196 # endif /* HAVE_SERVER_SUPPORT */
197
198 int fld_client_rpc(struct obd_export *exp,
199                    struct lu_seq_range *range, __u32 fld_op,
200                    struct ptlrpc_request **reqp);
201 #endif /* __KERNEL__ */
202
203 struct fld_cache *fld_cache_init(const char *name,
204                                  int cache_size, int cache_threshold);
205
206 void fld_cache_fini(struct fld_cache *cache);
207
208 void fld_cache_flush(struct fld_cache *cache);
209
210 int fld_cache_insert(struct fld_cache *cache,
211                      const struct lu_seq_range *range);
212
213 struct fld_cache_entry
214 *fld_cache_entry_create(const struct lu_seq_range *range);
215
216 int fld_cache_insert_nolock(struct fld_cache *cache,
217                             struct fld_cache_entry *f_new);
218 void fld_cache_delete(struct fld_cache *cache,
219                       const struct lu_seq_range *range);
220 void fld_cache_delete_nolock(struct fld_cache *cache,
221                              const struct lu_seq_range *range);
222 int fld_cache_lookup(struct fld_cache *cache,
223                      const u64 seq, struct lu_seq_range *range);
224
225 struct fld_cache_entry *
226 fld_cache_entry_lookup(struct fld_cache *cache,
227                        const struct lu_seq_range *range);
228
229 void fld_cache_entry_delete(struct fld_cache *cache,
230                             struct fld_cache_entry *node);
231
232 struct fld_cache_entry *
233 fld_cache_entry_lookup_nolock(struct fld_cache *cache,
234                               const struct lu_seq_range *range);
235
236 static inline const char *
237 fld_target_name(const struct lu_fld_target *tar)
238 {
239 #ifdef HAVE_SERVER_SUPPORT
240         if (tar->ft_srv != NULL)
241                 return tar->ft_srv->lsf_name;
242 #endif
243
244         return tar->ft_exp->exp_obd->obd_name;
245 }
246
247 #endif /* __FLD_INTERNAL_H */