Whamcloud - gitweb
7133abdb94f23481b7dc3ad0236ecf0bdf707cda
[fs/lustre-release.git] / lustre / include / lustre_fid.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
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/include/lustre_fid.h
37  *
38  * Author: Yury Umanets <umka@clusterfs.com>
39  */
40
41 #ifndef __LINUX_FID_H
42 #define __LINUX_FID_H
43
44 /*
45  * struct lu_fid
46  */
47 #include <lustre/lustre_idl.h>
48 #include <lustre_req_layout.h>
49 #include <lustre_mdt.h>
50
51 #include <libcfs/libcfs.h>
52
53 struct lu_site;
54 struct lu_context;
55
56 /* Whole sequences space range and zero range definitions */
57 extern const struct lu_range LUSTRE_SEQ_SPACE_RANGE;
58 extern const struct lu_range LUSTRE_SEQ_ZERO_RANGE;
59 extern const struct lu_fid LUSTRE_BFL_FID;
60
61 enum {
62         /*
63          * This is how may FIDs may be allocated in one sequence. 16384 for
64          * now.
65          */
66         LUSTRE_SEQ_MAX_WIDTH = 0x0000000000004000ULL,
67
68         /*
69          * How many sequences may be allocate for meta-sequence (this is 128
70          * sequences).
71          */
72         /* changed to 16 to avoid overflow in test11 */
73         LUSTRE_SEQ_META_WIDTH = 0x0000000000000010ULL,
74
75         /*
76          * This is how many sequences may be in one super-sequence allocated to
77          * MDTs.
78          */
79         LUSTRE_SEQ_SUPER_WIDTH = (LUSTRE_SEQ_META_WIDTH * LUSTRE_SEQ_META_WIDTH)
80 };
81
82 enum lu_mgr_type {
83         LUSTRE_SEQ_SERVER,
84         LUSTRE_SEQ_CONTROLLER
85 };
86
87 enum lu_cli_type {
88         LUSTRE_SEQ_METADATA,
89         LUSTRE_SEQ_DATA
90 };
91
92 struct lu_server_seq;
93
94 /* Client sequence manager interface. */
95 struct lu_client_seq {
96         /* Sequence-controller export. */
97         struct obd_export      *lcs_exp;
98         struct semaphore        lcs_sem;
99
100         /*
101          * Range of allowed for allocation sequeces. When using lu_client_seq on
102          * clients, this contains meta-sequence range. And for servers this
103          * contains super-sequence range.
104          */
105         struct lu_range         lcs_space;
106
107         /* Seq related proc */
108         cfs_proc_dir_entry_t   *lcs_proc_dir;
109
110         /* This holds last allocated fid in last obtained seq */
111         struct lu_fid           lcs_fid;
112
113         /* LUSTRE_SEQ_METADATA or LUSTRE_SEQ_DATA */
114         enum lu_cli_type        lcs_type;
115
116         /*
117          * Service uuid, passed from MDT + seq name to form unique seq name to
118          * use it with procfs.
119          */
120         char                    lcs_name[80];
121
122         /*
123          * Sequence width, that is how many objects may be allocated in one
124          * sequence. Default value for it is LUSTRE_SEQ_MAX_WIDTH.
125          */
126         __u64                   lcs_width;
127
128         /* Seq-server for direct talking */
129         struct lu_server_seq   *lcs_srv;
130 };
131
132 /* server sequence manager interface */
133 struct lu_server_seq {
134         /* Available sequences space */
135         struct lu_range         lss_space;
136
137         /*
138          * Device for server side seq manager needs (saving sequences to backing
139          * store).
140          */
141         struct dt_device       *lss_dev;
142
143         /* /seq file object device */
144         struct dt_object       *lss_obj;
145
146         /* Seq related proc */
147         cfs_proc_dir_entry_t   *lss_proc_dir;
148
149         /* LUSTRE_SEQ_SERVER or LUSTRE_SEQ_CONTROLLER */
150         enum lu_mgr_type       lss_type;
151
152         /* Client interafce to request controller */
153         struct lu_client_seq   *lss_cli;
154
155         /* Semaphore for protecting allocation */
156         struct semaphore        lss_sem;
157
158         /*
159          * Service uuid, passed from MDT + seq name to form unique seq name to
160          * use it with procfs.
161          */
162         char                    lss_name[80];
163
164         /*
165          * Allocation chunks for super and meta sequences. Default values are
166          * LUSTRE_SEQ_SUPER_WIDTH and LUSTRE_SEQ_META_WIDTH.
167          */
168         __u64                   lss_width;
169 };
170
171 int seq_query(struct com_thread_info *info);
172
173 /* Server methods */
174 int seq_server_init(struct lu_server_seq *seq,
175                     struct dt_device *dev,
176                     const char *prefix,
177                     enum lu_mgr_type type,
178                     const struct lu_env *env);
179
180 void seq_server_fini(struct lu_server_seq *seq,
181                      const struct lu_env *env);
182
183 int seq_server_alloc_super(struct lu_server_seq *seq,
184                            struct lu_range *in,
185                            struct lu_range *out,
186                            const struct lu_env *env);
187
188 int seq_server_alloc_meta(struct lu_server_seq *seq,
189                           struct lu_range *in,
190                           struct lu_range *out,
191                           const struct lu_env *env);
192
193 int seq_server_set_cli(struct lu_server_seq *seq,
194                        struct lu_client_seq *cli,
195                        const struct lu_env *env);
196
197 /* Client methods */
198 int seq_client_init(struct lu_client_seq *seq,
199                     struct obd_export *exp,
200                     enum lu_cli_type type,
201                     const char *prefix,
202                     struct lu_server_seq *srv);
203
204 void seq_client_fini(struct lu_client_seq *seq);
205
206 void seq_client_flush(struct lu_client_seq *seq);
207
208 int seq_client_alloc_fid(struct lu_client_seq *seq,
209                          struct lu_fid *fid);
210
211 /* Fids common stuff */
212 int fid_is_local(struct lu_site *site, const struct lu_fid *fid);
213
214 /* fid locking */
215
216 struct ldlm_namespace;
217
218 enum {
219         LUSTRE_RES_ID_SEQ_OFF = 0,
220         LUSTRE_RES_ID_OID_OFF = 1,
221         LUSTRE_RES_ID_VER_OFF = 2,
222         LUSTRE_RES_ID_HSH_OFF = 3
223 };
224
225 /*
226  * Build (DLM) resource name from fid.
227  */
228 static inline struct ldlm_res_id *
229 fid_build_reg_res_name(const struct lu_fid *f,
230                        struct ldlm_res_id *name)
231 {
232         memset(name, 0, sizeof *name);
233         name->name[LUSTRE_RES_ID_SEQ_OFF] = fid_seq(f);
234         name->name[LUSTRE_RES_ID_OID_OFF] = fid_oid(f);
235         name->name[LUSTRE_RES_ID_VER_OFF] = fid_ver(f);
236         return name;
237 }
238
239 /*
240  * Return true if resource is for object identified by fid.
241  */
242 static inline int fid_res_name_eq(const struct lu_fid *f,
243                                   const struct ldlm_res_id *name)
244 {
245         return
246                 name->name[LUSTRE_RES_ID_SEQ_OFF] == fid_seq(f) &&
247                 name->name[LUSTRE_RES_ID_OID_OFF] == fid_oid(f) &&
248                 name->name[LUSTRE_RES_ID_VER_OFF] == fid_ver(f);
249 }
250
251
252 static inline struct ldlm_res_id *
253 fid_build_pdo_res_name(const struct lu_fid *f,
254                        unsigned int hash,
255                        struct ldlm_res_id *name)
256 {
257         fid_build_reg_res_name(f, name);
258         name->name[LUSTRE_RES_ID_HSH_OFF] = hash;
259         return name;
260 }
261
262 static inline __u64 fid_flatten(const struct lu_fid *fid)
263 {
264         return (fid_seq(fid) - 1) * LUSTRE_SEQ_MAX_WIDTH + fid_oid(fid);
265 }
266
267 #define LUSTRE_SEQ_SRV_NAME "seq_srv"
268 #define LUSTRE_SEQ_CTL_NAME "seq_ctl"
269
270 /* Range common stuff */
271 void range_cpu_to_le(struct lu_range *dst, const struct lu_range *src);
272 void range_cpu_to_be(struct lu_range *dst, const struct lu_range *src);
273 void range_le_to_cpu(struct lu_range *dst, const struct lu_range *src);
274 void range_be_to_cpu(struct lu_range *dst, const struct lu_range *src);
275
276 #endif /* __LINUX_FID_H */