Whamcloud - gitweb
507439302bcaa5a0a5f3355894bec1b764236bc1
[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  * Sequence space, starts from 0x400 to have first 0x400 sequences used for
48  * special purposes. This means that if we have seq-with 10000 fids, we have
49  * ~10M fids reserved for special purposes (igifs, etc.).
50  */
51 const struct lu_range LUSTRE_SEQ_SPACE_RANGE = {
52         (0x400),
53         ((__u64)~0ULL)
54 };
55 EXPORT_SYMBOL(LUSTRE_SEQ_SPACE_RANGE);
56
57 /* Zero range, used for init and other purposes. */
58 const struct lu_range LUSTRE_SEQ_ZERO_RANGE = {
59         0,
60         0
61 };
62 EXPORT_SYMBOL(LUSTRE_SEQ_ZERO_RANGE);
63
64 /* Lustre Big Fs Lock fid. */
65 const struct lu_fid LUSTRE_BFL_FID = { .f_seq = 0x0000000000000003,
66                                        .f_oid = 0x0000000000000001,
67                                        .f_ver = 0x0000000000000000 };
68 EXPORT_SYMBOL(LUSTRE_BFL_FID);
69
70 void fid_cpu_to_le(struct lu_fid *dst, const struct lu_fid *src)
71 {
72         /* check that all fields are converted */
73         CLASSERT(sizeof *src ==
74                  sizeof fid_seq(src) +
75                  sizeof fid_oid(src) + sizeof fid_ver(src));
76         LASSERTF(fid_is_igif(src) || fid_ver(src) == 0, DFID"\n", PFID(src));
77         dst->f_seq = cpu_to_le64(fid_seq(src));
78         dst->f_oid = cpu_to_le32(fid_oid(src));
79         dst->f_ver = cpu_to_le32(fid_ver(src));
80 }
81 EXPORT_SYMBOL(fid_cpu_to_le);
82
83 void fid_le_to_cpu(struct lu_fid *dst, const struct lu_fid *src)
84 {
85         /* check that all fields are converted */
86         CLASSERT(sizeof *src ==
87                  sizeof fid_seq(src) +
88                  sizeof fid_oid(src) + sizeof fid_ver(src));
89         dst->f_seq = le64_to_cpu(fid_seq(src));
90         dst->f_oid = le32_to_cpu(fid_oid(src));
91         dst->f_ver = le32_to_cpu(fid_ver(src));
92         LASSERTF(fid_is_igif(dst) || fid_ver(dst) == 0, DFID"\n", PFID(dst));
93 }
94 EXPORT_SYMBOL(fid_le_to_cpu);
95
96 void range_cpu_to_le(struct lu_range *dst, const struct lu_range *src)
97 {
98         /* check that all fields are converted */
99         CLASSERT(sizeof *src ==
100                  sizeof src->lr_start +
101                  sizeof src->lr_end);
102         dst->lr_start = cpu_to_le64(src->lr_start);
103         dst->lr_end = cpu_to_le64(src->lr_end);
104 }
105 EXPORT_SYMBOL(range_cpu_to_le);
106
107 void range_le_to_cpu(struct lu_range *dst, const struct lu_range *src)
108 {
109         /* check that all fields are converted */
110         CLASSERT(sizeof *src ==
111                  sizeof src->lr_start +
112                  sizeof src->lr_end);
113         dst->lr_start = le64_to_cpu(src->lr_start);
114         dst->lr_end = le64_to_cpu(src->lr_end);
115 }
116 EXPORT_SYMBOL(range_le_to_cpu);
117
118 #ifdef __KERNEL__
119 void range_cpu_to_be(struct lu_range *dst, const struct lu_range *src)
120 {
121         /* check that all fields are converted */
122         CLASSERT(sizeof *src ==
123                  sizeof src->lr_start +
124                  sizeof src->lr_end);
125         dst->lr_start = cpu_to_be64(src->lr_start);
126         dst->lr_end = cpu_to_be64(src->lr_end);
127 }
128 EXPORT_SYMBOL(range_cpu_to_be);
129
130 void range_be_to_cpu(struct lu_range *dst, const struct lu_range *src)
131 {
132         /* check that all fields are converted */
133         CLASSERT(sizeof *src ==
134                  sizeof src->lr_start +
135                  sizeof src->lr_end);
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