Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / fid / fid_lib.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/fid/fid_lib.c
5  *  Miscellaneous fid functions.
6  *
7  *  Copyright (c) 2006 Cluster File Systems, Inc.
8  *   Author: Nikita Danilov <nikita@clusterfs.com>
9  *           Yury Umanets <umka@clusterfs.com>
10  *
11  *   This file is part of the Lustre file system, http://www.lustre.org
12  *   Lustre is a trademark of Cluster File Systems, Inc.
13  *
14  *   You may have signed or agreed to another license before downloading
15  *   this software.  If so, you are bound by the terms and conditions
16  *   of that agreement, and the following does not apply to you.  See the
17  *   LICENSE file included with this distribution for more information.
18  *
19  *   If you did not agree to a different license, then this copy of Lustre
20  *   is open source software; you can redistribute it and/or modify it
21  *   under the terms of version 2 of the GNU General Public License as
22  *   published by the Free Software Foundation.
23  *
24  *   In either case, Lustre is distributed in the hope that it will be
25  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
26  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  *   license text for more details.
28  */
29
30 #ifndef EXPORT_SYMTAB
31 # define EXPORT_SYMTAB
32 #endif
33 #define DEBUG_SUBSYSTEM S_FID
34
35 #ifdef __KERNEL__
36 # include <libcfs/libcfs.h>
37 # include <linux/module.h>
38 #else /* __KERNEL__ */
39 # include <liblustre.h>
40 #endif
41
42 #include <obd.h>
43 #include <lu_object.h>
44 #include <lustre_fid.h>
45
46 /**
47  * A cluster-wide range from which fid-sequences are granted to servers and
48  * then clients.
49  *
50  * Fid namespace:
51  * <pre>
52  * Normal FID:        seq:64 [2^33,2^64-1]      oid:32          ver:32
53  * IGIF      :        0:32, ino:32              gen:32          0:32
54  * IDIF      :        0:31, 1:1, ost-index:16,  objd:48         0:32
55  * </pre>
56  *
57  * The first 0x400 sequences of normal FID are reserved for special purpose.
58  */
59 const struct lu_range LUSTRE_SEQ_SPACE_RANGE = {
60         FID_SEQ_START + 0x400ULL,
61         (__u64)~0ULL
62 };
63 EXPORT_SYMBOL(LUSTRE_SEQ_SPACE_RANGE);
64
65 /* Zero range, used for init and other purposes. */
66 const struct lu_range LUSTRE_SEQ_ZERO_RANGE = {
67         0,
68         0
69 };
70 EXPORT_SYMBOL(LUSTRE_SEQ_ZERO_RANGE);
71
72 /* Lustre Big Fs Lock fid. */
73 const struct lu_fid LUSTRE_BFL_FID = { .f_seq = 0x0000000000000003,
74                                        .f_oid = 0x0000000000000001,
75                                        .f_ver = 0x0000000000000000 };
76 EXPORT_SYMBOL(LUSTRE_BFL_FID);
77
78 void range_cpu_to_le(struct lu_range *dst, const struct lu_range *src)
79 {
80         /* check that all fields are converted */
81         CLASSERT(sizeof *src ==
82                  sizeof src->lr_start +
83                  sizeof src->lr_end);
84         dst->lr_start = cpu_to_le64(src->lr_start);
85         dst->lr_end = cpu_to_le64(src->lr_end);
86 }
87 EXPORT_SYMBOL(range_cpu_to_le);
88
89 void range_le_to_cpu(struct lu_range *dst, const struct lu_range *src)
90 {
91         /* check that all fields are converted */
92         CLASSERT(sizeof *src ==
93                  sizeof src->lr_start +
94                  sizeof src->lr_end);
95         dst->lr_start = le64_to_cpu(src->lr_start);
96         dst->lr_end = le64_to_cpu(src->lr_end);
97 }
98 EXPORT_SYMBOL(range_le_to_cpu);
99
100 #ifdef __KERNEL__
101 void range_cpu_to_be(struct lu_range *dst, const struct lu_range *src)
102 {
103         /* check that all fields are converted */
104         CLASSERT(sizeof *src ==
105                  sizeof src->lr_start +
106                  sizeof src->lr_end);
107         dst->lr_start = cpu_to_be64(src->lr_start);
108         dst->lr_end = cpu_to_be64(src->lr_end);
109 }
110 EXPORT_SYMBOL(range_cpu_to_be);
111
112 void range_be_to_cpu(struct lu_range *dst, const struct lu_range *src)
113 {
114         /* check that all fields are converted */
115         CLASSERT(sizeof *src ==
116                  sizeof src->lr_start +
117                  sizeof src->lr_end);
118         dst->lr_start = be64_to_cpu(src->lr_start);
119         dst->lr_end = be64_to_cpu(src->lr_end);
120 }
121 EXPORT_SYMBOL(range_be_to_cpu);
122
123 #endif