4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/fld/fld_internal.h
38 * Author: Yury Umanets <umka@clusterfs.com>
39 * Author: Tom WangDi <wangdi@clusterfs.com>
41 #ifndef __FLD_INTERNAL_H
42 #define __FLD_INTERNAL_H
45 #include <lustre/lustre_idl.h>
46 #include <libcfs/libcfs.h>
47 #include <lustre_fld.h>
50 LUSTRE_FLD_INIT = 1 << 0,
51 LUSTRE_FLD_RUN = 1 << 1
59 typedef int (*fld_hash_func_t) (struct lu_client_fld *, __u64);
61 typedef struct lu_fld_target *
62 (*fld_scan_func_t) (struct lu_client_fld *, __u64);
66 fld_hash_func_t fh_hash_func;
67 fld_scan_func_t fh_scan_func;
70 struct fld_cache_entry {
74 * fld cache entries are sorted on range->lsr_start field. */
75 struct lu_seq_range fce_range;
80 * Cache guard, protects fci_hash mostly because others immutable after
86 * Cache shrink threshold */
90 * Prefered number of cached entries */
94 * Current number of cached entries. Protected by \a fci_lock */
98 * LRU list fld entries. */
102 * sorted fld entries. */
103 cfs_list_t fci_entries_head;
106 * Cache statistics. */
107 struct fld_stats fci_stat;
110 * Cache name used for debug and messages. */
112 unsigned int fci_no_shrink:1;
116 /* 4M of FLD cache will not hurt client a lot. */
117 FLD_SERVER_CACHE_SIZE = (4 * 0x100000),
119 /* 1M of FLD cache will not hurt client a lot. */
120 FLD_CLIENT_CACHE_SIZE = (1 * 0x100000)
124 /* Cache threshold is 10 percent of size. */
125 FLD_SERVER_CACHE_THRESHOLD = 10,
127 /* Cache threshold is 10 percent of size. */
128 FLD_CLIENT_CACHE_THRESHOLD = 10
131 extern struct lu_fld_hash fld_hash[];
136 extern struct proc_dir_entry *fld_type_proc_dir;
137 extern struct lprocfs_seq_vars fld_client_proc_list[];
140 # ifdef HAVE_SERVER_SUPPORT
141 struct fld_thread_info {
142 struct lu_seq_range fti_rec;
143 struct lu_seq_range fti_lrange;
144 struct lu_seq_range fti_irange;
147 extern struct lu_context_key fld_thread_key;
150 int fld_index_init(const struct lu_env *env, struct lu_server_fld *fld,
151 struct dt_device *dt, int type);
153 void fld_index_fini(const struct lu_env *env, struct lu_server_fld *fld);
155 int fld_declare_index_create(const struct lu_env *env,
156 struct lu_server_fld *fld,
157 const struct lu_seq_range *new_range,
160 int fld_index_create(const struct lu_env *env, struct lu_server_fld *fld,
161 const struct lu_seq_range *new_range, struct thandle *th);
163 int fld_index_lookup(const struct lu_env *env, struct lu_server_fld *fld,
164 seqno_t seq, struct lu_seq_range *range);
166 int fld_name_to_index(const char *name, __u32 *index);
167 int fld_server_mod_init(void);
169 void fld_server_mod_exit(void);
171 int fld_server_read(const struct lu_env *env, struct lu_server_fld *fld,
172 struct lu_seq_range *range, void *data, int data_len);
174 extern const struct file_operations fld_proc_seq_fops;
175 extern struct lprocfs_seq_vars fld_server_proc_list[];
178 # endif /* HAVE_SERVER_SUPPORT */
180 int fld_client_rpc(struct obd_export *exp,
181 struct lu_seq_range *range, __u32 fld_op,
182 struct ptlrpc_request **reqp);
183 #endif /* __KERNEL__ */
185 struct fld_cache *fld_cache_init(const char *name,
186 int cache_size, int cache_threshold);
188 void fld_cache_fini(struct fld_cache *cache);
190 void fld_cache_flush(struct fld_cache *cache);
192 int fld_cache_insert(struct fld_cache *cache,
193 const struct lu_seq_range *range);
195 struct fld_cache_entry
196 *fld_cache_entry_create(const struct lu_seq_range *range);
198 int fld_cache_insert_nolock(struct fld_cache *cache,
199 struct fld_cache_entry *f_new);
200 void fld_cache_delete(struct fld_cache *cache,
201 const struct lu_seq_range *range);
202 void fld_cache_delete_nolock(struct fld_cache *cache,
203 const struct lu_seq_range *range);
204 int fld_cache_lookup(struct fld_cache *cache,
205 const seqno_t seq, struct lu_seq_range *range);
207 struct fld_cache_entry *
208 fld_cache_entry_lookup(struct fld_cache *cache,
209 const struct lu_seq_range *range);
211 void fld_cache_entry_delete(struct fld_cache *cache,
212 struct fld_cache_entry *node);
214 struct fld_cache_entry *
215 fld_cache_entry_lookup_nolock(struct fld_cache *cache,
216 const struct lu_seq_range *range);
218 static inline const char *
219 fld_target_name(const struct lu_fld_target *tar)
221 #ifdef HAVE_SERVER_SUPPORT
222 if (tar->ft_srv != NULL)
223 return tar->ft_srv->lsf_name;
226 return tar->ft_exp->exp_obd->obd_name;
229 #endif /* __FLD_INTERNAL_H */