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