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