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