Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[fs/lustre-release.git] / lustre / include / lustre_fld.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) 2011, 2015, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31
32 #ifndef __LINUX_FLD_H
33 #define __LINUX_FLD_H
34
35 /** \defgroup fld fld
36  *
37  * @{
38  */
39
40 #include <uapi/linux/lustre/lustre_idl.h>
41 #include <libcfs/libcfs.h>
42 #include <seq_range.h>
43 #include <lustre_fid.h>
44
45 struct lu_env;
46 struct lu_client_fld;
47 struct lu_server_fld;
48 struct lu_fld_hash;
49 struct fld_cache;
50 struct thandle;
51 struct dt_device;
52 struct dt_object;
53
54 /* FLD (Fid Location Database) interface. */
55 enum {
56         LUSTRE_CLI_FLD_HASH_DHT = 0,
57         LUSTRE_CLI_FLD_HASH_RRB
58 };
59
60 struct lu_fld_target {
61         struct list_head        ft_chain;
62         struct obd_export      *ft_exp;
63         struct lu_server_fld   *ft_srv;
64         __u64                   ft_idx;
65 };
66
67 struct lu_server_fld {
68         /* Fld dir debugfs entry. */
69         struct dentry           *lsf_debugfs_entry;
70
71         /* /fld file object device */
72         struct dt_object        *lsf_obj;
73
74         /* super seq controller export, needed for forward fld lookup */
75         struct obd_export       *lsf_control_exp;
76
77         /* Client FLD cache. */
78         struct fld_cache        *lsf_cache;
79
80         /* Protect index modifications */
81         struct mutex            lsf_lock;
82
83         /* Fld service name in form "fld-srv-lustre-MDTXXX" */
84         char                    lsf_name[LUSTRE_MDT_MAXNAMELEN];
85
86         int (*lsf_seq_lookup)(const struct lu_env *env,
87                               struct lu_server_fld *fld, u64 seq,
88                               struct lu_seq_range *range);
89
90         /**
91          * Just reformatted or upgraded, and this flag is being
92          * used to check whether the local FLDB is needs to be
93          * synced with global FLDB(in MDT0), and it is only needed
94          * if the MDT is upgraded from < 2.6 to 2.6, i.e. when the
95          * local FLDB is being invited
96          */
97         unsigned int             lsf_new:1;
98
99 };
100
101 struct lu_client_fld {
102         /* Client side debugfs entry. */
103         struct dentry           *lcf_debugfs_entry;
104
105         /* List of exports client FLD knows about. */
106         struct list_head        lcf_targets;
107
108         /* Current hash to be used to chose an export. */
109         struct lu_fld_hash      *lcf_hash;
110
111         /* Exports count. */
112         int                      lcf_count;
113
114         /* Lock protecting exports list and fld_hash. */
115         spinlock_t               lcf_lock;
116
117         /* Client FLD cache. */
118         struct fld_cache        *lcf_cache;
119
120         /* Client fld debugfs entry name. */
121         char                    lcf_name[LUSTRE_MDT_MAXNAMELEN];
122 };
123
124 /* Server methods */
125 int fld_server_init(const struct lu_env *env, struct lu_server_fld *fld,
126                     struct dt_device *dt, const char *prefix, int type);
127
128 void fld_server_fini(const struct lu_env *env, struct lu_server_fld *fld);
129
130 int fld_declare_server_create(const struct lu_env *env,
131                               struct lu_server_fld *fld,
132                               const struct lu_seq_range *range,
133                               struct thandle *th);
134
135 int fld_server_create(const struct lu_env *env,
136                       struct lu_server_fld *fld,
137                       const struct lu_seq_range *add_range,
138                       struct thandle *th);
139
140 int fld_insert_entry(const struct lu_env *env,
141                      struct lu_server_fld *fld,
142                      const struct lu_seq_range *range);
143
144 int fld_server_lookup(const struct lu_env *env, struct lu_server_fld *fld,
145                       u64 seq, struct lu_seq_range *range);
146
147 int fld_local_lookup(const struct lu_env *env, struct lu_server_fld *fld,
148                      u64 seq, struct lu_seq_range *range);
149
150 int fld_update_from_controller(const struct lu_env *env,
151                                struct lu_server_fld *fld);
152
153 /* Client methods */
154 int fld_client_init(struct lu_client_fld *fld, const char *prefix,
155                     int hash);
156
157 void fld_client_fini(struct lu_client_fld *fld);
158
159 void fld_client_flush(struct lu_client_fld *fld);
160
161 int fld_client_lookup(struct lu_client_fld *fld, u64 seq, u32 *mds,
162                       __u32 flags, const struct lu_env *env);
163
164 int fld_client_create(struct lu_client_fld *fld, struct lu_seq_range *range,
165                       const struct lu_env *env);
166
167 int fld_client_delete(struct lu_client_fld *fld, u64 seq,
168                       const struct lu_env *env);
169
170 int fld_client_add_target(struct lu_client_fld *fld,
171                           struct lu_fld_target *tar);
172
173 int fld_client_del_target(struct lu_client_fld *fld, __u64 idx);
174
175 void fld_client_debugfs_fini(struct lu_client_fld *fld);
176
177 /** @} fld */
178
179 #endif