Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / include / lustre_fld.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef __LINUX_FLD_H
38 #define __LINUX_FLD_H
39
40 #include <lustre/lustre_idl.h>
41 #include <lustre_mdt.h>
42 #include <dt_object.h>
43
44 #include <libcfs/libcfs.h>
45
46 struct lu_client_fld;
47 struct lu_server_fld;
48
49 extern const struct dt_index_features fld_index_features;
50 extern const char fld_index_name[];
51
52
53 struct fld_stats {
54         __u64   fst_count;
55         __u64   fst_cache;
56         __u64   fst_inflight;
57 };
58
59 /*
60  * FLD (Fid Location Database) interface.
61  */
62 enum {
63         LUSTRE_CLI_FLD_HASH_DHT = 0,
64         LUSTRE_CLI_FLD_HASH_RRB
65 };
66
67 struct lu_server_fld;
68
69 struct lu_fld_target {
70         struct list_head         ft_chain;
71         struct obd_export       *ft_exp;
72         struct lu_server_fld    *ft_srv;
73         __u64                    ft_idx;
74 };
75
76 typedef int
77 (*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 hlist_node        fce_list;
90         struct list_head         fce_lru;
91         mdsno_t                  fce_mds;
92         seqno_t                  fce_seq;
93         cfs_waitq_t              fce_waitq;
94         __u32                    fce_inflight:1,
95                                  fce_invalid:1;
96 };
97
98 struct fld_cache {
99         /*
100          * Cache guard, protects fci_hash mostly because others immutable after
101          * init is finished.
102          */
103         spinlock_t               fci_lock;
104
105         /* Cache shrink threshold */
106         int                      fci_threshold;
107
108         /* Prefered number of cached entries */
109         int                      fci_cache_size;
110
111         /* Current number of cached entries. Protected by @fci_lock */
112         int                      fci_cache_count;
113
114         /* Hash table size (number of collision lists) */
115         int                      fci_hash_size;
116
117         /* Hash table mask */
118         int                      fci_hash_mask;
119
120         /* Hash table for all collision lists */
121         struct hlist_head       *fci_hash_table;
122
123         /* Lru list */
124         struct list_head         fci_lru;
125
126         /* Cache statistics. */
127         struct fld_stats         fci_stat;
128         
129         /* Cache name used for debug and messages. */
130         char                     fci_name[80];
131 };
132
133 struct lu_server_fld {
134         /* Fld dir proc entry. */
135         cfs_proc_dir_entry_t    *lsf_proc_dir;
136
137         /* /fld file object device */
138         struct dt_object        *lsf_obj;
139
140         /* Client FLD cache. */
141         struct fld_cache        *lsf_cache;
142
143         /* Protect index modifications */
144         struct semaphore         lsf_sem;
145
146         /* Fld service name in form "fld-srv-lustre-MDTXXX" */
147         char                     lsf_name[80];
148 };
149
150 enum {
151         LUSTRE_FLD_INIT = 1 << 0,
152         LUSTRE_FLD_RUN  = 1 << 1
153 };
154
155 struct lu_client_fld {
156         /* Client side proc entry. */
157         cfs_proc_dir_entry_t    *lcf_proc_dir;
158
159         /* List of exports client FLD knows about. */
160         struct list_head         lcf_targets;
161
162         /* Current hash to be used to chose an export. */
163         struct lu_fld_hash      *lcf_hash;
164
165         /* Exports count. */
166         int                      lcf_count;
167
168         /* Lock protecting exports list and fld_hash. */
169         spinlock_t               lcf_lock;
170
171         /* Client FLD cache. */
172         struct fld_cache        *lcf_cache;
173
174         /* Client fld proc entry name. */
175         char                     lcf_name[80];
176
177         const struct lu_context *lcf_ctx;
178         
179         int                      lcf_flags;
180 };
181
182 int fld_query(struct com_thread_info *info);
183
184 /* Server methods */
185 int fld_server_init(struct lu_server_fld *fld,
186                     struct dt_device *dt,
187                     const char *prefix,
188                     const struct lu_env *env);
189
190 void fld_server_fini(struct lu_server_fld *fld,
191                      const struct lu_env *env);
192
193 int fld_server_create(struct lu_server_fld *fld,
194                       const struct lu_env *env,
195                       seqno_t seq, mdsno_t mds);
196
197 int fld_server_delete(struct lu_server_fld *fld,
198                       const struct lu_env *env,
199                       seqno_t seq);
200
201 int fld_server_lookup(struct lu_server_fld *fld,
202                       const struct lu_env *env,
203                       seqno_t seq, mdsno_t *mds);
204
205 /* Client methods */
206 int fld_client_init(struct lu_client_fld *fld,
207                     const char *prefix, int hash);
208
209 void fld_client_fini(struct lu_client_fld *fld);
210
211 void fld_client_flush(struct lu_client_fld *fld);
212
213 int fld_client_lookup(struct lu_client_fld *fld,
214                       seqno_t seq, mdsno_t *mds,
215                       const struct lu_env *env);
216
217 int fld_client_create(struct lu_client_fld *fld,
218                       seqno_t seq, mdsno_t mds,
219                       const struct lu_env *env);
220
221 int fld_client_delete(struct lu_client_fld *fld,
222                       seqno_t seq,
223                       const struct lu_env *env);
224
225 int fld_client_add_target(struct lu_client_fld *fld,
226                           struct lu_fld_target *tar);
227
228 int fld_client_del_target(struct lu_client_fld *fld,
229                           __u64 idx);
230
231 /* Cache methods */
232 struct fld_cache *fld_cache_init(const char *name,
233                                  int hash_size,
234                                  int cache_size,
235                                  int cache_threshold);
236
237 void fld_cache_fini(struct fld_cache *cache);
238
239 void fld_cache_flush(struct fld_cache *cache);
240
241 int fld_cache_insert(struct fld_cache *cache,
242                      seqno_t seq, mdsno_t mds);
243
244 int fld_cache_insert_inflight(struct fld_cache *cache,
245                               seqno_t seq);
246
247 void fld_cache_delete(struct fld_cache *cache,
248                       seqno_t seq);
249
250 int
251 fld_cache_lookup(struct fld_cache *cache,
252                  seqno_t seq, mdsno_t *mds);
253
254 #endif