Linux-libre 4.10.3-gnu
[librecmc/linux-libre.git] / 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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2015, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/fld/fld_internal.h
33  *
34  * Subsystem Description:
35  * FLD is FID Location Database, which stores where (IE, on which MDT)
36  * FIDs are located.
37  * The database is basically a record file, each record consists of a FID
38  * sequence range, MDT/OST index, and flags. The FLD for the whole FS
39  * is only stored on the sequence controller(MDT0) right now, but each target
40  * also has its local FLD, which only stores the local sequence.
41  *
42  * The FLD subsystem usually has two tasks:
43  * 1. maintain the database, i.e. when the sequence controller allocates
44  * new sequence ranges to some nodes, it will call the FLD API to insert the
45  * location information <sequence_range, node_index> in FLDB.
46  *
47  * 2. Handle requests from other nodes, i.e. if client needs to know where
48  * the FID is located, if it can not find the information in the local cache,
49  * it will send a FLD lookup RPC to the FLD service, and the FLD service will
50  * look up the FLDB entry and return the location information to client.
51  *
52  *
53  * Author: Yury Umanets <umka@clusterfs.com>
54  * Author: Tom WangDi <wangdi@clusterfs.com>
55  */
56 #ifndef __FLD_INTERNAL_H
57 #define __FLD_INTERNAL_H
58
59 #include "../include/lustre/lustre_idl.h"
60
61 #include "../../include/linux/libcfs/libcfs.h"
62 #include "../include/lustre_req_layout.h"
63 #include "../include/lustre_fld.h"
64
65 struct fld_stats {
66         __u64   fst_count;
67         __u64   fst_cache;
68         __u64   fst_inflight;
69 };
70
71 struct lu_fld_hash {
72         const char            *fh_name;
73         int (*fh_hash_func)(struct lu_client_fld *, __u64);
74         struct lu_fld_target *(*fh_scan_func)(struct lu_client_fld *, __u64);
75 };
76
77 struct fld_cache_entry {
78         struct list_head               fce_lru;
79         struct list_head               fce_list;
80         /** fld cache entries are sorted on range->lsr_start field. */
81         struct lu_seq_range      fce_range;
82 };
83
84 struct fld_cache {
85         /**
86          * Cache guard, protects fci_hash mostly because others immutable after
87          * init is finished.
88          */
89         rwlock_t                 fci_lock;
90
91         /** Cache shrink threshold */
92         int                   fci_threshold;
93
94         /** Preferred number of cached entries */
95         int                   fci_cache_size;
96
97         /** Current number of cached entries. Protected by \a fci_lock */
98         int                   fci_cache_count;
99
100         /** LRU list fld entries. */
101         struct list_head               fci_lru;
102
103         /** sorted fld entries. */
104         struct list_head               fci_entries_head;
105
106         /** Cache statistics. */
107         struct fld_stats         fci_stat;
108
109         /** Cache name used for debug and messages. */
110         char                 fci_name[LUSTRE_MDT_MAXNAMELEN];
111         unsigned int             fci_no_shrink:1;
112 };
113
114 enum {
115         /* 4M of FLD cache will not hurt client a lot. */
116         FLD_SERVER_CACHE_SIZE      = (4 * 0x100000),
117
118         /* 1M of FLD cache will not hurt client a lot. */
119         FLD_CLIENT_CACHE_SIZE      = (1 * 0x100000)
120 };
121
122 enum {
123         /* Cache threshold is 10 percent of size. */
124         FLD_SERVER_CACHE_THRESHOLD = 10,
125
126         /* Cache threshold is 10 percent of size. */
127         FLD_CLIENT_CACHE_THRESHOLD = 10
128 };
129
130 extern struct lu_fld_hash fld_hash[];
131
132 int fld_client_rpc(struct obd_export *exp,
133                    struct lu_seq_range *range, __u32 fld_op,
134                    struct ptlrpc_request **reqp);
135
136 extern struct lprocfs_vars fld_client_debugfs_list[];
137
138 struct fld_cache *fld_cache_init(const char *name,
139                                  int cache_size, int cache_threshold);
140
141 void fld_cache_fini(struct fld_cache *cache);
142
143 void fld_cache_flush(struct fld_cache *cache);
144
145 int fld_cache_insert(struct fld_cache *cache,
146                      const struct lu_seq_range *range);
147
148 struct fld_cache_entry
149 *fld_cache_entry_create(const struct lu_seq_range *range);
150
151 int fld_cache_lookup(struct fld_cache *cache,
152                      const u64 seq, struct lu_seq_range *range);
153
154 struct fld_cache_entry*
155 fld_cache_entry_lookup(struct fld_cache *cache, struct lu_seq_range *range);
156
157 struct fld_cache_entry
158 *fld_cache_entry_lookup_nolock(struct fld_cache *cache,
159                               struct lu_seq_range *range);
160
161 static inline const char *
162 fld_target_name(struct lu_fld_target *tar)
163 {
164         if (tar->ft_srv)
165                 return tar->ft_srv->lsf_name;
166
167         return (const char *)tar->ft_exp->exp_obd->obd_name;
168 }
169
170 #endif /* __FLD_INTERNAL_H */