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