Whamcloud - gitweb
48856d3fddff3ce810c10b8a13325315f92557fd
[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.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) 2011, 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
37 #ifndef __LINUX_FLD_H
38 #define __LINUX_FLD_H
39
40 /** \defgroup fld fld
41  *
42  * @{
43  */
44
45 #include <lustre/lustre_idl.h>
46 #include <libcfs/libcfs.h>
47
48 struct lu_env;
49 struct lu_client_fld;
50 struct lu_server_fld;
51 struct lu_fld_hash;
52 struct fld_cache;
53 struct thandle;
54 struct dt_device;
55 struct dt_object;
56
57 /*
58  * FLD (Fid Location Database) interface.
59  */
60 enum {
61         LUSTRE_CLI_FLD_HASH_DHT = 0,
62         LUSTRE_CLI_FLD_HASH_RRB
63 };
64
65 struct lu_fld_target {
66         cfs_list_t              ft_chain;
67         struct obd_export      *ft_exp;
68         struct lu_server_fld   *ft_srv;
69         __u64                   ft_idx;
70 };
71
72 struct lu_server_fld {
73         /**
74          * Fld dir proc entry. */
75         cfs_proc_dir_entry_t    *lsf_proc_dir;
76
77         /**
78          * /fld file object device */
79         struct dt_object        *lsf_obj;
80
81         /**
82          * super sequence controller export, needed to forward fld
83          * lookup  request. */
84         struct obd_export       *lsf_control_exp;
85
86         /**
87          * Client FLD cache. */
88         struct fld_cache        *lsf_cache;
89
90         /**
91          * Protect index modifications */
92         struct mutex            lsf_lock;
93
94         /**
95          * Fld service name in form "fld-srv-lustre-MDTXXX" */
96         char                     lsf_name[80];
97
98 };
99
100 struct lu_client_fld {
101         /**
102          * Client side proc entry. */
103         cfs_proc_dir_entry_t    *lcf_proc_dir;
104
105         /**
106          * List of exports client FLD knows about. */
107         cfs_list_t               lcf_targets;
108
109         /**
110          * Current hash to be used to chose an export. */
111         struct lu_fld_hash      *lcf_hash;
112
113         /**
114          * Exports count. */
115         int                      lcf_count;
116
117         /**
118          * Lock protecting exports list and fld_hash. */
119         spinlock_t               lcf_lock;
120
121         /**
122          * Client FLD cache. */
123         struct fld_cache        *lcf_cache;
124
125         /**
126          * Client fld proc entry name. */
127         char                     lcf_name[80];
128
129         int                      lcf_flags;
130 };
131
132 /* Server methods */
133 int fld_server_init(const struct lu_env *env, struct lu_server_fld *fld,
134                     struct dt_device *dt, const char *prefix, int mds_node_id,
135                     int type);
136
137 void fld_server_fini(const struct lu_env *env, struct lu_server_fld *fld);
138
139 int fld_declare_server_create(const struct lu_env *env,
140                               struct lu_server_fld *fld,
141                               const struct lu_seq_range *range,
142                               struct thandle *th);
143
144 int fld_server_create(const struct lu_env *env,
145                       struct lu_server_fld *fld,
146                       const struct lu_seq_range *add_range,
147                       struct thandle *th);
148
149 int fld_insert_entry(const struct lu_env *env,
150                      struct lu_server_fld *fld,
151                      const struct lu_seq_range *range);
152
153 int fld_server_lookup(const struct lu_env *env, struct lu_server_fld *fld,
154                       seqno_t seq, struct lu_seq_range *range);
155
156 /* Client methods */
157 int fld_client_init(struct lu_client_fld *fld,
158                     const char *prefix, int hash);
159
160 void fld_client_fini(struct lu_client_fld *fld);
161
162 void fld_client_flush(struct lu_client_fld *fld);
163
164 int fld_client_lookup(struct lu_client_fld *fld, seqno_t seq, mdsno_t *mds,
165                       __u32 flags, const struct lu_env *env);
166
167 int fld_client_create(struct lu_client_fld *fld,
168                       struct lu_seq_range *range,
169                       const struct lu_env *env);
170
171 int fld_client_delete(struct lu_client_fld *fld,
172                       seqno_t seq,
173                       const struct lu_env *env);
174
175 int fld_client_add_target(struct lu_client_fld *fld,
176                           struct lu_fld_target *tar);
177
178 int fld_client_del_target(struct lu_client_fld *fld,
179                           __u64 idx);
180
181 void fld_client_proc_fini(struct lu_client_fld *fld);
182
183 /** @} fld */
184
185 #endif