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