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