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