Whamcloud - gitweb
6179b3ee86b531b4fcf28ba1864b566aeb9f5131
[fs/lustre-release.git] / lustre / fld / fld_internal.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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  * Copyright (c) 2011 Whamcloud, Inc.
32  */
33 /*
34  * This file is part of Lustre, http://www.lustre.org/
35  * Lustre is a trademark of Sun Microsystems, Inc.
36  *
37  * lustre/fld/fld_internal.h
38  *
39  * Author: Yury Umanets <umka@clusterfs.com>
40  * Author: Tom WangDi <wangdi@clusterfs.com>
41  */
42 #ifndef __FLD_INTERNAL_H
43 #define __FLD_INTERNAL_H
44
45 #include <lustre/lustre_idl.h>
46 #include <dt_object.h>
47
48 #include <libcfs/libcfs.h>
49 #include <lustre_req_layout.h>
50 #include <lustre_fld.h>
51
52 enum {
53         LUSTRE_FLD_INIT = 1 << 0,
54         LUSTRE_FLD_RUN  = 1 << 1
55 };
56
57 struct fld_stats {
58         __u64   fst_count;
59         __u64   fst_cache;
60         __u64   fst_inflight;
61 };
62
63 typedef int (*fld_hash_func_t) (struct lu_client_fld *, __u64);
64
65 typedef struct lu_fld_target *
66 (*fld_scan_func_t) (struct lu_client_fld *, __u64);
67
68 struct lu_fld_hash {
69         const char              *fh_name;
70         fld_hash_func_t          fh_hash_func;
71         fld_scan_func_t          fh_scan_func;
72 };
73
74 struct fld_cache_entry {
75         cfs_list_t               fce_lru;
76         cfs_list_t               fce_list;
77         /**
78          * fld cache entries are sorted on range->lsr_start field. */
79         struct lu_seq_range      fce_range;
80 };
81
82 struct fld_cache {
83         /**
84          * Cache guard, protects fci_hash mostly because others immutable after
85          * init is finished.
86          */
87         cfs_spinlock_t           fci_lock;
88
89         /**
90          * Cache shrink threshold */
91         int                      fci_threshold;
92
93         /**
94          * Prefered number of cached entries */
95         int                      fci_cache_size;
96
97         /**
98          * Current number of cached entries. Protected by \a fci_lock */
99         int                      fci_cache_count;
100
101         /**
102          * LRU list fld entries. */
103         cfs_list_t               fci_lru;
104
105         /**
106          * sorted fld entries. */
107         cfs_list_t               fci_entries_head;
108
109         /**
110          * Cache statistics. */
111         struct fld_stats         fci_stat;
112
113         /**
114          * Cache name used for debug and messages. */
115         char                     fci_name[80];
116 };
117
118 enum fld_op {
119         FLD_CREATE = 0,
120         FLD_DELETE = 1,
121         FLD_LOOKUP = 2
122 };
123
124 enum {
125         /* 4M of FLD cache will not hurt client a lot. */
126         FLD_SERVER_CACHE_SIZE      = (4 * 0x100000),
127
128         /* 1M of FLD cache will not hurt client a lot. */
129         FLD_CLIENT_CACHE_SIZE      = (1 * 0x100000)
130 };
131
132 enum {
133         /* Cache threshold is 10 percent of size. */
134         FLD_SERVER_CACHE_THRESHOLD = 10,
135
136         /* Cache threshold is 10 percent of size. */
137         FLD_CLIENT_CACHE_THRESHOLD = 10
138 };
139
140 extern struct lu_fld_hash fld_hash[];
141
142 #ifdef __KERNEL__
143
144 struct fld_thread_info {
145         struct req_capsule *fti_pill;
146         __u64               fti_key;
147         struct lu_seq_range fti_rec;
148         struct lu_seq_range fti_lrange;
149         struct lu_seq_range fti_irange;
150 };
151
152
153 struct thandle *fld_trans_create(struct lu_server_fld *fld,
154                                 const struct lu_env *env);
155 int fld_trans_start(struct lu_server_fld *fld,
156                     const struct lu_env *env, struct thandle *th);
157
158 void fld_trans_stop(struct lu_server_fld *fld,
159                     const struct lu_env *env, struct thandle* th);
160
161 int fld_index_init(struct lu_server_fld *fld,
162                    const struct lu_env *env,
163                    struct dt_device *dt);
164
165 void fld_index_fini(struct lu_server_fld *fld,
166                     const struct lu_env *env);
167
168 int fld_index_create(struct lu_server_fld *fld,
169                      const struct lu_env *env,
170                      const struct lu_seq_range *range,
171                      struct thandle *th);
172
173 int fld_index_delete(struct lu_server_fld *fld,
174                      const struct lu_env *env,
175                      struct lu_seq_range *range,
176                      struct thandle *th);
177
178 int fld_index_lookup(struct lu_server_fld *fld,
179                      const struct lu_env *env,
180                      seqno_t seq, struct lu_seq_range *range);
181
182 int fld_client_rpc(struct obd_export *exp,
183                    struct lu_seq_range *range, __u32 fld_op);
184
185 #ifdef LPROCFS
186 extern struct lprocfs_vars fld_server_proc_list[];
187 extern struct lprocfs_vars fld_client_proc_list[];
188 #endif
189
190 #endif
191
192 struct fld_cache *fld_cache_init(const char *name,
193                                  int cache_size, int cache_threshold);
194
195 void fld_cache_fini(struct fld_cache *cache);
196
197 void fld_cache_flush(struct fld_cache *cache);
198
199 void fld_cache_insert(struct fld_cache *cache,
200                       const struct lu_seq_range *range);
201
202 void fld_cache_delete(struct fld_cache *cache,
203                       const struct lu_seq_range *range);
204
205 int fld_cache_lookup(struct fld_cache *cache,
206                      const seqno_t seq, struct lu_seq_range *range);
207
208 static inline const char *
209 fld_target_name(struct lu_fld_target *tar)
210 {
211         if (tar->ft_srv != NULL)
212                 return tar->ft_srv->lsf_name;
213
214         return (const char *)tar->ft_exp->exp_obd->obd_name;
215 }
216
217 extern cfs_proc_dir_entry_t *fld_type_proc_dir;
218
219 #endif /* __FLD_INTERNAL_H */