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