Whamcloud - gitweb
b=16461
[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  * 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/fid/fid_lib.c
37  *
38  * Miscellaneous fid functions.
39  *
40  * Author: Nikita Danilov <nikita@clusterfs.com>
41  * Author: Yury Umanets <umka@clusterfs.com>
42  */
43
44 #ifndef EXPORT_SYMTAB
45 # define EXPORT_SYMTAB
46 #endif
47 #define DEBUG_SUBSYSTEM S_FID
48
49 #ifdef __KERNEL__
50 # include <libcfs/libcfs.h>
51 # include <linux/module.h>
52 #else /* __KERNEL__ */
53 # include <liblustre.h>
54 #endif
55
56 #include <obd.h>
57 #include <lu_object.h>
58 #include <lustre_fid.h>
59
60 /**
61  * A cluster-wide range from which fid-sequences are granted to servers and
62  * then clients.
63  *
64  * Fid namespace:
65  * <pre>
66  * Normal FID:        seq:64 [2^33,2^64-1]      oid:32          ver:32
67  * IGIF      :        0:32, ino:32              gen:32          0:32
68  * IDIF      :        0:31, 1:1, ost-index:16,  objd:48         0:32
69  * </pre>
70  *
71  * The first 0x400 sequences of normal FID are reserved for special purpose.
72  */
73 const struct lu_range LUSTRE_SEQ_SPACE_RANGE = {
74         FID_SEQ_START + 0x400ULL,
75         (__u64)~0ULL
76 };
77 EXPORT_SYMBOL(LUSTRE_SEQ_SPACE_RANGE);
78
79 /* Zero range, used for init and other purposes. */
80 const struct lu_range LUSTRE_SEQ_ZERO_RANGE = {
81         0,
82         0
83 };
84 EXPORT_SYMBOL(LUSTRE_SEQ_ZERO_RANGE);
85
86 /* Lustre Big Fs Lock fid. */
87 const struct lu_fid LUSTRE_BFL_FID = { .f_seq = 0x0000000000000003,
88                                        .f_oid = 0x0000000000000001,
89                                        .f_ver = 0x0000000000000000 };
90 EXPORT_SYMBOL(LUSTRE_BFL_FID);
91
92 void range_cpu_to_le(struct lu_range *dst, const struct lu_range *src)
93 {
94         /* check that all fields are converted */
95         CLASSERT(sizeof(*src) ==
96                  sizeof(src->lr_start) +
97                  sizeof(src->lr_end) +
98                  sizeof(src->lr_padding));
99         dst->lr_start = cpu_to_le64(src->lr_start);
100         dst->lr_end = cpu_to_le64(src->lr_end);
101 }
102 EXPORT_SYMBOL(range_cpu_to_le);
103
104 void range_le_to_cpu(struct lu_range *dst, const struct lu_range *src)
105 {
106         /* check that all fields are converted */
107         CLASSERT(sizeof(*src) ==
108                  sizeof(src->lr_start) +
109                  sizeof(src->lr_end) +
110                  sizeof(src->lr_padding));
111         dst->lr_start = le64_to_cpu(src->lr_start);
112         dst->lr_end = le64_to_cpu(src->lr_end);
113 }
114 EXPORT_SYMBOL(range_le_to_cpu);
115
116 #ifdef __KERNEL__
117 void range_cpu_to_be(struct lu_range *dst, const struct lu_range *src)
118 {
119         /* check that all fields are converted */
120         CLASSERT(sizeof(*src) ==
121                  sizeof(src->lr_start) +
122                  sizeof(src->lr_end) +
123                  sizeof(src->lr_padding));
124         dst->lr_start = cpu_to_be64(src->lr_start);
125         dst->lr_end = cpu_to_be64(src->lr_end);
126 }
127 EXPORT_SYMBOL(range_cpu_to_be);
128
129 void range_be_to_cpu(struct lu_range *dst, const struct lu_range *src)
130 {
131         /* check that all fields are converted */
132         CLASSERT(sizeof(*src) ==
133                  sizeof(src->lr_start) +
134                  sizeof(src->lr_end) +
135                  sizeof(src->lr_padding));
136         dst->lr_start = be64_to_cpu(src->lr_start);
137         dst->lr_end = be64_to_cpu(src->lr_end);
138 }
139 EXPORT_SYMBOL(range_be_to_cpu);
140
141 #endif