Whamcloud - gitweb
- adjust client FLD cache a bit. It should use hashtable one page size;
[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 };
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 };
76
77 struct fld_cache {
78         /*
79          * Cache guard, protects fci_hash mostly because others immutable after
80          * init is finished.
81          */
82         spinlock_t               fci_lock;
83
84         /* Cache shrink threshold */
85         int                      fci_threshold;
86
87         /* Prefered number of cached entries */
88         int                      fci_cache_size;
89
90         /* Current number of cached entries. Protected by @fci_lock */
91         int                      fci_cache_count;
92
93         /* Hash table size (number of collision lists) */
94         int                      fci_hash_size;
95
96         /* Hash table mask */
97         int                      fci_hash_mask;
98
99         /* Hash table for all collision lists */
100         struct hlist_head       *fci_hash_table;
101
102         /* Lru list */
103         struct list_head         fci_lru;
104
105         /* Cache name used for debug and messages. */
106         char                     fci_name[80];
107 };
108
109 struct lu_server_fld {
110         /* Fld dir proc entry. */
111         cfs_proc_dir_entry_t    *lsf_proc_dir;
112
113         /* /fld file object device */
114         struct dt_object        *lsf_obj;
115
116         /* Client FLD cache. */
117         struct fld_cache        *lsf_cache;
118
119         /* Protect index modifications */
120         struct semaphore         lsf_sem;
121
122         /* Server cache statistics. */
123         struct fld_stats         lsf_stat;
124         
125         /* Fld service name in form "fld-srv-lustre-MDTXXX" */
126         char                     lsf_name[80];
127 };
128
129 struct lu_client_fld {
130         /* Client side proc entry. */
131         cfs_proc_dir_entry_t    *lcf_proc_dir;
132
133         /* List of exports client FLD knows about. */
134         struct list_head         lcf_targets;
135
136         /* Current hash to be used to chose an export. */
137         struct lu_fld_hash      *lcf_hash;
138
139         /* Exports count. */
140         int                      lcf_count;
141
142         /* Lock protecting exports list and fld_hash. */
143         spinlock_t               lcf_lock;
144
145         /* Client cache statistics. */
146         struct fld_stats         lcf_stat;
147         
148         /* Protect fld req + cache modification. */
149         struct semaphore         lcf_sem;
150
151         /* Client FLD cache. */
152         struct fld_cache        *lcf_cache;
153
154         /* Client fld proc entry name. */
155         char                     lcf_name[80];
156
157         const struct lu_context *lcf_ctx;
158 };
159
160 int fld_query(struct com_thread_info *info);
161
162 /* Server methods */
163 int fld_server_init(struct lu_server_fld *fld,
164                     struct dt_device *dt,
165                     const char *prefix,
166                     const struct lu_env *env);
167
168 void fld_server_fini(struct lu_server_fld *fld,
169                      const struct lu_env *env);
170
171 int fld_server_create(struct lu_server_fld *fld,
172                       const struct lu_env *env,
173                       seqno_t seq, mdsno_t mds);
174
175 int fld_server_delete(struct lu_server_fld *fld,
176                       const struct lu_env *env,
177                       seqno_t seq);
178
179 int fld_server_lookup(struct lu_server_fld *fld,
180                       const struct lu_env *env,
181                       seqno_t seq, mdsno_t *mds);
182
183 /* Client methods */
184 int fld_client_init(struct lu_client_fld *fld,
185                     const char *prefix, int hash);
186
187 void fld_client_fini(struct lu_client_fld *fld);
188
189 int fld_client_lookup(struct lu_client_fld *fld,
190                       seqno_t seq, mdsno_t *mds,
191                       const struct lu_env *env);
192
193 int fld_client_create(struct lu_client_fld *fld,
194                       seqno_t seq, mdsno_t mds,
195                       const struct lu_env *env);
196
197 int fld_client_delete(struct lu_client_fld *fld,
198                       seqno_t seq,
199                       const struct lu_env *env);
200
201 int fld_client_add_target(struct lu_client_fld *fld,
202                           struct lu_fld_target *tar);
203
204 int fld_client_del_target(struct lu_client_fld *fld,
205                           __u64 idx);
206
207 /* Cache methods */
208 struct fld_cache *fld_cache_init(const char *name,
209                                  int hash_size,
210                                  int cache_size,
211                                  int cache_threshold);
212
213 void fld_cache_fini(struct fld_cache *cache);
214
215 void fld_cache_flush(struct fld_cache *cache);
216
217 int fld_cache_insert(struct fld_cache *cache,
218                      seqno_t seq, mdsno_t mds);
219
220 void fld_cache_delete(struct fld_cache *cache,
221                       seqno_t seq);
222
223 int
224 fld_cache_lookup(struct fld_cache *cache,
225                  seqno_t seq, mdsno_t *mds);
226
227 #endif