Whamcloud - gitweb
b=16776
[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 struct fld_stats {
50         __u64   fst_count;
51         __u64   fst_cache;
52         __u64   fst_inflight;
53 };
54
55 /*
56  * FLD (Fid Location Database) interface.
57  */
58 enum {
59         LUSTRE_CLI_FLD_HASH_DHT = 0,
60         LUSTRE_CLI_FLD_HASH_RRB
61 };
62
63 struct lu_server_fld;
64
65 struct lu_fld_target {
66         struct list_head         ft_chain;
67         struct obd_export       *ft_exp;
68         struct lu_server_fld    *ft_srv;
69         __u64                    ft_idx;
70 };
71
72 typedef int
73 (*fld_hash_func_t) (struct lu_client_fld *, __u64);
74
75 typedef struct lu_fld_target *
76 (*fld_scan_func_t) (struct lu_client_fld *, __u64);
77
78 struct lu_fld_hash {
79         const char              *fh_name;
80         fld_hash_func_t          fh_hash_func;
81         fld_scan_func_t          fh_scan_func;
82 };
83
84 struct fld_cache_entry {
85         struct hlist_node        fce_list;
86         struct list_head         fce_lru;
87         mdsno_t                  fce_mds;
88         seqno_t                  fce_seq;
89         cfs_waitq_t              fce_waitq;
90         __u32                    fce_inflight:1,
91                                  fce_invalid:1;
92 };
93
94 struct fld_cache {
95         /*
96          * Cache guard, protects fci_hash mostly because others immutable after
97          * init is finished.
98          */
99         spinlock_t               fci_lock;
100
101         /* Cache shrink threshold */
102         int                      fci_threshold;
103
104         /* Prefered number of cached entries */
105         int                      fci_cache_size;
106
107         /* Current number of cached entries. Protected by @fci_lock */
108         int                      fci_cache_count;
109
110         /* Hash table size (number of collision lists) */
111         int                      fci_hash_size;
112
113         /* Hash table mask */
114         int                      fci_hash_mask;
115
116         /* Hash table for all collision lists */
117         struct hlist_head       *fci_hash_table;
118
119         /* Lru list */
120         struct list_head         fci_lru;
121
122         /* Cache statistics. */
123         struct fld_stats         fci_stat;
124         
125         /* Cache name used for debug and messages. */
126         char                     fci_name[80];
127 };
128
129 struct lu_server_fld {
130         /* Fld dir proc entry. */
131         cfs_proc_dir_entry_t    *lsf_proc_dir;
132
133         /* /fld file object device */
134         struct dt_object        *lsf_obj;
135
136         /* Client FLD cache. */
137         struct fld_cache        *lsf_cache;
138
139         /* Protect index modifications */
140         struct semaphore         lsf_sem;
141
142         /* Fld service name in form "fld-srv-lustre-MDTXXX" */
143         char                     lsf_name[80];
144 };
145
146 enum {
147         LUSTRE_FLD_INIT = 1 << 0,
148         LUSTRE_FLD_RUN  = 1 << 1
149 };
150
151 struct lu_client_fld {
152         /* Client side proc entry. */
153         cfs_proc_dir_entry_t    *lcf_proc_dir;
154
155         /* List of exports client FLD knows about. */
156         struct list_head         lcf_targets;
157
158         /* Current hash to be used to chose an export. */
159         struct lu_fld_hash      *lcf_hash;
160
161         /* Exports count. */
162         int                      lcf_count;
163
164         /* Lock protecting exports list and fld_hash. */
165         spinlock_t               lcf_lock;
166
167         /* Client FLD cache. */
168         struct fld_cache        *lcf_cache;
169
170         /* Client fld proc entry name. */
171         char                     lcf_name[80];
172
173         const struct lu_context *lcf_ctx;
174         
175         int                      lcf_flags;
176 };
177
178 int fld_query(struct com_thread_info *info);
179
180 /* Server methods */
181 int fld_server_init(struct lu_server_fld *fld,
182                     struct dt_device *dt,
183                     const char *prefix,
184                     const struct lu_env *env);
185
186 void fld_server_fini(struct lu_server_fld *fld,
187                      const struct lu_env *env);
188
189 int fld_server_create(struct lu_server_fld *fld,
190                       const struct lu_env *env,
191                       seqno_t seq, mdsno_t mds);
192
193 int fld_server_delete(struct lu_server_fld *fld,
194                       const struct lu_env *env,
195                       seqno_t seq);
196
197 int fld_server_lookup(struct lu_server_fld *fld,
198                       const struct lu_env *env,
199                       seqno_t seq, mdsno_t *mds);
200
201 /* Client methods */
202 int fld_client_init(struct lu_client_fld *fld,
203                     const char *prefix, int hash);
204
205 void fld_client_fini(struct lu_client_fld *fld);
206
207 void fld_client_flush(struct lu_client_fld *fld);
208
209 int fld_client_lookup(struct lu_client_fld *fld,
210                       seqno_t seq, mdsno_t *mds,
211                       const struct lu_env *env);
212
213 int fld_client_create(struct lu_client_fld *fld,
214                       seqno_t seq, mdsno_t mds,
215                       const struct lu_env *env);
216
217 int fld_client_delete(struct lu_client_fld *fld,
218                       seqno_t seq,
219                       const struct lu_env *env);
220
221 int fld_client_add_target(struct lu_client_fld *fld,
222                           struct lu_fld_target *tar);
223
224 int fld_client_del_target(struct lu_client_fld *fld,
225                           __u64 idx);
226
227 /* Cache methods */
228 struct fld_cache *fld_cache_init(const char *name,
229                                  int hash_size,
230                                  int cache_size,
231                                  int cache_threshold);
232
233 void fld_cache_fini(struct fld_cache *cache);
234
235 void fld_cache_flush(struct fld_cache *cache);
236
237 int fld_cache_insert(struct fld_cache *cache,
238                      seqno_t seq, mdsno_t mds);
239
240 int fld_cache_insert_inflight(struct fld_cache *cache,
241                               seqno_t seq);
242
243 void fld_cache_delete(struct fld_cache *cache,
244                       seqno_t seq);
245
246 int
247 fld_cache_lookup(struct fld_cache *cache,
248                  seqno_t seq, mdsno_t *mds);
249
250 #endif