These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / staging / lustre / lustre / fld / fld_internal.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2013, Intel Corporation.
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 "../include/lustre/lustre_idl.h"
45
46 #include "../../include/linux/libcfs/libcfs.h"
47 #include "../include/lustre_req_layout.h"
48 #include "../include/lustre_fld.h"
49
50 enum {
51         LUSTRE_FLD_INIT = 1 << 0,
52         LUSTRE_FLD_RUN  = 1 << 1
53 };
54
55 struct fld_stats {
56         __u64   fst_count;
57         __u64   fst_cache;
58         __u64   fst_inflight;
59 };
60
61 typedef int (*fld_hash_func_t) (struct lu_client_fld *, __u64);
62
63 typedef struct lu_fld_target *
64 (*fld_scan_func_t) (struct lu_client_fld *, __u64);
65
66 struct lu_fld_hash {
67         const char            *fh_name;
68         fld_hash_func_t   fh_hash_func;
69         fld_scan_func_t   fh_scan_func;
70 };
71
72 struct fld_cache_entry {
73         struct list_head               fce_lru;
74         struct list_head               fce_list;
75         /**
76          * fld cache entries are sorted on range->lsr_start field. */
77         struct lu_seq_range      fce_range;
78 };
79
80 struct fld_cache {
81         /**
82          * Cache guard, protects fci_hash mostly because others immutable after
83          * init is finished.
84          */
85         rwlock_t                 fci_lock;
86
87         /**
88          * Cache shrink threshold */
89         int                   fci_threshold;
90
91         /**
92          * Preferred number of cached entries */
93         int                   fci_cache_size;
94
95         /**
96          * Current number of cached entries. Protected by \a fci_lock */
97         int                   fci_cache_count;
98
99         /**
100          * LRU list fld entries. */
101         struct list_head               fci_lru;
102
103         /**
104          * sorted fld entries. */
105         struct list_head               fci_entries_head;
106
107         /**
108          * Cache statistics. */
109         struct fld_stats         fci_stat;
110
111         /**
112          * Cache name used for debug and messages. */
113         char                 fci_name[LUSTRE_MDT_MAXNAMELEN];
114         unsigned int             fci_no_shrink:1;
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 int fld_client_rpc(struct obd_export *exp,
142                    struct lu_seq_range *range, __u32 fld_op);
143
144 extern struct lprocfs_vars fld_client_debugfs_list[];
145
146 struct fld_cache *fld_cache_init(const char *name,
147                                  int cache_size, int cache_threshold);
148
149 void fld_cache_fini(struct fld_cache *cache);
150
151 void fld_cache_flush(struct fld_cache *cache);
152
153 int fld_cache_insert(struct fld_cache *cache,
154                      const struct lu_seq_range *range);
155
156 struct fld_cache_entry
157 *fld_cache_entry_create(const struct lu_seq_range *range);
158
159 int fld_cache_insert_nolock(struct fld_cache *cache,
160                             struct fld_cache_entry *f_new);
161 void fld_cache_delete(struct fld_cache *cache,
162                       const struct lu_seq_range *range);
163 void fld_cache_delete_nolock(struct fld_cache *cache,
164                              const struct lu_seq_range *range);
165 int fld_cache_lookup(struct fld_cache *cache,
166                      const u64 seq, struct lu_seq_range *range);
167
168 struct fld_cache_entry*
169 fld_cache_entry_lookup(struct fld_cache *cache, struct lu_seq_range *range);
170 void fld_cache_entry_delete(struct fld_cache *cache,
171                             struct fld_cache_entry *node);
172 void fld_dump_cache_entries(struct fld_cache *cache);
173
174 struct fld_cache_entry
175 *fld_cache_entry_lookup_nolock(struct fld_cache *cache,
176                               struct lu_seq_range *range);
177
178 static inline const char *
179 fld_target_name(struct lu_fld_target *tar)
180 {
181         if (tar->ft_srv != NULL)
182                 return tar->ft_srv->lsf_name;
183
184         return (const char *)tar->ft_exp->exp_obd->obd_name;
185 }
186
187 #endif /* __FLD_INTERNAL_H */