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