Whamcloud - gitweb
b=21571 stacksize and locking fixes for loadgen patch from umka
[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_seq_range LUSTRE_SEQ_SPACE_RANGE;
58 extern const struct lu_seq_range LUSTRE_SEQ_ZERO_RANGE;
59 extern const struct lu_fid LUSTRE_BFL_FID;
60 extern const struct lu_fid LU_OBF_FID;
61 extern const struct lu_fid LU_DOT_LUSTRE_FID;
62
63 enum {
64         /*
65          * This is how may FIDs may be allocated in one sequence. 16384 for
66          * now.
67          */
68         LUSTRE_SEQ_MAX_WIDTH = 0x0000000000000400ULL,
69
70         /*
71          * How many sequences may be allocate for meta-sequence (this is 128
72          * sequences).
73          */
74         /* changed to 16 to avoid overflow in test11 */
75         LUSTRE_SEQ_META_WIDTH = 0x0000000000000010ULL,
76
77         /*
78          * This is how many sequences may be in one super-sequence allocated to
79          * MDTs.
80          */
81         LUSTRE_SEQ_SUPER_WIDTH = (LUSTRE_SEQ_META_WIDTH * LUSTRE_SEQ_META_WIDTH)
82 };
83
84 /** special fid seq: used for local object create. */
85 #define FID_SEQ_LOCAL_FILE      (FID_SEQ_START + 1)
86
87 /** special fid seq: used for .lustre objects. */
88 #define LU_DOT_LUSTRE_SEQ       (FID_SEQ_START + 0x02ULL)
89
90 /* Note that reserved SEQ numbers below 12 will conflict with ldiskfs
91  * inodes in the IGIF namespace, so these reserved SEQ numbers must be
92  * used sparingly until ldiskfs-based MDT backends and/or IGIF FIDs 
93  * have been completely removed. */
94
95 /** special OID for local objects */
96 enum {
97         /** \see osd_oi_index_create */
98         OSD_OI_FID_16_OID       = 2UL,
99         /** \see fld_mod_init */
100         FLD_INDEX_OID           = 3UL,
101         /** \see fid_mod_init */
102         FID_SEQ_CTL_OID         = 4UL,
103         FID_SEQ_SRV_OID         = 5UL,
104         /** \see mdd_mod_init */
105         MDD_ROOT_INDEX_OID      = 6UL,
106         MDD_ORPHAN_OID          = 7UL,
107         MDD_LOV_OBJ_OID         = 8UL,
108         MDD_CAPA_KEYS_OID       = 9UL,
109         MDD_OBJECTS_OID         = 10UL,
110         /** \see mdt_mod_init */
111         MDT_LAST_RECV_OID       = 11UL,
112         /** \see osd_mod_init */
113         OSD_REM_OBJ_DIR_OID     = 12UL,
114 };
115
116 static inline void lu_local_obj_fid(struct lu_fid *fid, __u32 oid)
117 {
118         fid->f_seq = FID_SEQ_LOCAL_FILE;
119         fid->f_oid = oid;
120         fid->f_ver = 0;
121 }
122
123 enum lu_mgr_type {
124         LUSTRE_SEQ_SERVER,
125         LUSTRE_SEQ_CONTROLLER
126 };
127
128 enum lu_cli_type {
129         LUSTRE_SEQ_METADATA,
130         LUSTRE_SEQ_DATA
131 };
132
133 struct lu_server_seq;
134
135 /* Client sequence manager interface. */
136 struct lu_client_seq {
137         /* Sequence-controller export. */
138         struct obd_export      *lcs_exp;
139         struct semaphore        lcs_sem;
140
141         /*
142          * Range of allowed for allocation sequeces. When using lu_client_seq on
143          * clients, this contains meta-sequence range. And for servers this
144          * contains super-sequence range.
145          */
146         struct lu_seq_range         lcs_space;
147
148         /* Seq related proc */
149         cfs_proc_dir_entry_t   *lcs_proc_dir;
150
151         /* This holds last allocated fid in last obtained seq */
152         struct lu_fid           lcs_fid;
153
154         /* LUSTRE_SEQ_METADATA or LUSTRE_SEQ_DATA */
155         enum lu_cli_type        lcs_type;
156
157         /*
158          * Service uuid, passed from MDT + seq name to form unique seq name to
159          * use it with procfs.
160          */
161         char                    lcs_name[80];
162
163         /*
164          * Sequence width, that is how many objects may be allocated in one
165          * sequence. Default value for it is LUSTRE_SEQ_MAX_WIDTH.
166          */
167         __u64                   lcs_width;
168
169         /* Seq-server for direct talking */
170         struct lu_server_seq   *lcs_srv;
171 };
172
173 /* server sequence manager interface */
174 struct lu_server_seq {
175         /* Available sequences space */
176         struct lu_seq_range         lss_space;
177
178         /*
179          * Device for server side seq manager needs (saving sequences to backing
180          * store).
181          */
182         struct dt_device       *lss_dev;
183
184         /* /seq file object device */
185         struct dt_object       *lss_obj;
186
187         /* Seq related proc */
188         cfs_proc_dir_entry_t   *lss_proc_dir;
189
190         /* LUSTRE_SEQ_SERVER or LUSTRE_SEQ_CONTROLLER */
191         enum lu_mgr_type       lss_type;
192
193         /* Client interafce to request controller */
194         struct lu_client_seq   *lss_cli;
195
196         /* Semaphore for protecting allocation */
197         struct semaphore        lss_sem;
198
199         /*
200          * Service uuid, passed from MDT + seq name to form unique seq name to
201          * use it with procfs.
202          */
203         char                    lss_name[80];
204
205         /*
206          * Allocation chunks for super and meta sequences. Default values are
207          * LUSTRE_SEQ_SUPER_WIDTH and LUSTRE_SEQ_META_WIDTH.
208          */
209         __u64                   lss_width;
210
211         /**
212          * Pointer to site object, required to access site fld.
213          */
214         struct md_site         *lss_site;
215 };
216
217 int seq_query(struct com_thread_info *info);
218
219 /* Server methods */
220 int seq_server_init(struct lu_server_seq *seq,
221                     struct dt_device *dev,
222                     const char *prefix,
223                     enum lu_mgr_type type,
224                     struct md_site *ls,
225                     const struct lu_env *env);
226
227 void seq_server_fini(struct lu_server_seq *seq,
228                      const struct lu_env *env);
229
230 int seq_server_alloc_super(struct lu_server_seq *seq,
231                            struct lu_seq_range *in,
232                            struct lu_seq_range *out,
233                            const struct lu_env *env);
234
235 int seq_server_alloc_meta(struct lu_server_seq *seq,
236                           struct lu_seq_range *in,
237                           struct lu_seq_range *out,
238                           const struct lu_env *env);
239
240 int seq_server_set_cli(struct lu_server_seq *seq,
241                        struct lu_client_seq *cli,
242                        const struct lu_env *env);
243
244 /* Client methods */
245 int seq_client_init(struct lu_client_seq *seq,
246                     struct obd_export *exp,
247                     enum lu_cli_type type,
248                     const char *prefix,
249                     struct lu_server_seq *srv);
250
251 void seq_client_fini(struct lu_client_seq *seq);
252
253 void seq_client_flush(struct lu_client_seq *seq);
254
255 int seq_client_alloc_fid(struct lu_client_seq *seq,
256                          struct lu_fid *fid);
257
258 /* Fids common stuff */
259 int fid_is_local(const struct lu_env *env,
260                  struct lu_site *site, const struct lu_fid *fid);
261
262 /* fid locking */
263
264 struct ldlm_namespace;
265
266 enum {
267         LUSTRE_RES_ID_SEQ_OFF = 0,
268         LUSTRE_RES_ID_OID_OFF = 1,
269         LUSTRE_RES_ID_VER_OFF = 2,
270         LUSTRE_RES_ID_HSH_OFF = 3
271 };
272
273 /*
274  * Build (DLM) resource name from fid.
275  */
276 static inline struct ldlm_res_id *
277 fid_build_reg_res_name(const struct lu_fid *f,
278                        struct ldlm_res_id *name)
279 {
280         memset(name, 0, sizeof *name);
281         name->name[LUSTRE_RES_ID_SEQ_OFF] = fid_seq(f);
282         name->name[LUSTRE_RES_ID_OID_OFF] = fid_oid(f);
283         name->name[LUSTRE_RES_ID_VER_OFF] = fid_ver(f);
284         return name;
285 }
286
287 /*
288  * Return true if resource is for object identified by fid.
289  */
290 static inline int fid_res_name_eq(const struct lu_fid *f,
291                                   const struct ldlm_res_id *name)
292 {
293         return
294                 name->name[LUSTRE_RES_ID_SEQ_OFF] == fid_seq(f) &&
295                 name->name[LUSTRE_RES_ID_OID_OFF] == fid_oid(f) &&
296                 name->name[LUSTRE_RES_ID_VER_OFF] == fid_ver(f);
297 }
298
299
300 static inline struct ldlm_res_id *
301 fid_build_pdo_res_name(const struct lu_fid *f,
302                        unsigned int hash,
303                        struct ldlm_res_id *name)
304 {
305         fid_build_reg_res_name(f, name);
306         name->name[LUSTRE_RES_ID_HSH_OFF] = hash;
307         return name;
308 }
309
310 static inline __u64 fid_flatten(const struct lu_fid *fid)
311 {
312         return (fid_seq(fid) - 1) * LUSTRE_SEQ_MAX_WIDTH + fid_oid(fid);
313 }
314
315 #define LUSTRE_SEQ_SRV_NAME "seq_srv"
316 #define LUSTRE_SEQ_CTL_NAME "seq_ctl"
317
318 /* Range common stuff */
319 static inline void range_cpu_to_le(struct lu_seq_range *dst, const struct lu_seq_range *src)
320 {
321         dst->lsr_start = cpu_to_le64(src->lsr_start);
322         dst->lsr_end = cpu_to_le64(src->lsr_end);
323         dst->lsr_mdt = cpu_to_le32(src->lsr_mdt);
324 }
325
326 static inline void range_le_to_cpu(struct lu_seq_range *dst, const struct lu_seq_range *src)
327 {
328         dst->lsr_start = le64_to_cpu(src->lsr_start);
329         dst->lsr_end = le64_to_cpu(src->lsr_end);
330         dst->lsr_mdt = le32_to_cpu(src->lsr_mdt);
331 }
332
333 static inline void range_cpu_to_be(struct lu_seq_range *dst, const struct lu_seq_range *src)
334 {
335         dst->lsr_start = cpu_to_be64(src->lsr_start);
336         dst->lsr_end = cpu_to_be64(src->lsr_end);
337         dst->lsr_mdt = cpu_to_be32(src->lsr_mdt);
338 }
339
340 static inline void range_be_to_cpu(struct lu_seq_range *dst, const struct lu_seq_range *src)
341 {
342         dst->lsr_start = be64_to_cpu(src->lsr_start);
343         dst->lsr_end = be64_to_cpu(src->lsr_end);
344         dst->lsr_mdt = be32_to_cpu(src->lsr_mdt);
345 }
346
347 #endif /* __LINUX_FID_H */