4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
28 * Copyright 2015 Cray Inc, all rights reserved.
31 * Define ost_id associated functions
34 #ifndef _UAPI_LUSTRE_OSTID_H_
35 #define _UAPI_LUSTRE_OSTID_H_
37 #include <linux/errno.h>
38 #include <linux/types.h>
40 * This is due to us being out of kernel and the way the OpenSFS branch
44 #include <uapi/linux/lustre/lustre_fid.h>
46 #include <linux/lustre/lustre_fid.h>
49 static inline __u64 lmm_oi_id(const struct ost_id *oi)
54 static inline __u64 lmm_oi_seq(const struct ost_id *oi)
59 static inline void lmm_oi_set_seq(struct ost_id *oi, __u64 seq)
64 static inline void lmm_oi_set_id(struct ost_id *oi, __u64 oid)
69 static inline void lmm_oi_le_to_cpu(struct ost_id *dst_oi,
70 const struct ost_id *src_oi)
72 dst_oi->oi.oi_id = __le64_to_cpu(src_oi->oi.oi_id);
73 dst_oi->oi.oi_seq = __le64_to_cpu(src_oi->oi.oi_seq);
76 static inline void lmm_oi_cpu_to_le(struct ost_id *dst_oi,
77 const struct ost_id *src_oi)
79 dst_oi->oi.oi_id = __cpu_to_le64(src_oi->oi.oi_id);
80 dst_oi->oi.oi_seq = __cpu_to_le64(src_oi->oi.oi_seq);
83 /* extract OST sequence (group) from a wire ost_id (id/seq) pair */
84 static inline __u64 ostid_seq(const struct ost_id *ostid)
86 if (fid_seq_is_mdt0(ostid->oi.oi_seq))
87 return FID_SEQ_OST_MDT0;
89 if (fid_seq_is_default(ostid->oi.oi_seq))
90 return FID_SEQ_LOV_DEFAULT;
92 if (fid_is_idif(&ostid->oi_fid))
93 return FID_SEQ_OST_MDT0;
95 return fid_seq(&ostid->oi_fid);
98 /* extract OST objid from a wire ost_id (id/seq) pair */
99 static inline __u64 ostid_id(const struct ost_id *ostid)
101 if (fid_seq_is_mdt0(ostid->oi.oi_seq))
102 return ostid->oi.oi_id & IDIF_OID_MASK;
104 if (fid_seq_is_default(ostid->oi.oi_seq))
105 return ostid->oi.oi_id;
107 if (fid_is_idif(&ostid->oi_fid))
108 return fid_idif_id(fid_seq(&ostid->oi_fid),
109 fid_oid(&ostid->oi_fid), 0);
111 return fid_oid(&ostid->oi_fid);
114 static inline void ostid_set_seq(struct ost_id *oi, __u64 seq)
116 if (fid_seq_is_mdt0(seq) || fid_seq_is_default(seq)) {
119 oi->oi_fid.f_seq = seq;
121 * Note: if f_oid + f_ver is zero, we need init it
122 * to be 1, otherwise, ostid_seq will treat this
123 * as old ostid (oi_seq == 0)
125 if (!oi->oi_fid.f_oid && !oi->oi_fid.f_ver)
126 oi->oi_fid.f_oid = LUSTRE_FID_INIT_OID;
130 static inline void ostid_set_seq_mdt0(struct ost_id *oi)
132 ostid_set_seq(oi, FID_SEQ_OST_MDT0);
135 static inline void ostid_set_seq_echo(struct ost_id *oi)
137 ostid_set_seq(oi, FID_SEQ_ECHO);
140 static inline void ostid_set_seq_llog(struct ost_id *oi)
142 ostid_set_seq(oi, FID_SEQ_LLOG);
145 static inline void ostid_cpu_to_le(const struct ost_id *src_oi,
146 struct ost_id *dst_oi)
148 if (fid_seq_is_mdt0(src_oi->oi.oi_seq)) {
149 dst_oi->oi.oi_id = __cpu_to_le64(src_oi->oi.oi_id);
150 dst_oi->oi.oi_seq = __cpu_to_le64(src_oi->oi.oi_seq);
152 fid_cpu_to_le(&dst_oi->oi_fid, &src_oi->oi_fid);
156 static inline void ostid_le_to_cpu(const struct ost_id *src_oi,
157 struct ost_id *dst_oi)
159 if (fid_seq_is_mdt0(src_oi->oi.oi_seq)) {
160 dst_oi->oi.oi_id = __le64_to_cpu(src_oi->oi.oi_id);
161 dst_oi->oi.oi_seq = __le64_to_cpu(src_oi->oi.oi_seq);
163 fid_le_to_cpu(&dst_oi->oi_fid, &src_oi->oi_fid);
168 * Sigh, because pre-2.4 uses
169 * struct lov_mds_md_v1 {
171 * __u64 lmm_object_id;
172 * __u64 lmm_object_seq;
175 * to identify the LOV(MDT) object, and lmm_object_seq will
176 * be normal_fid, which make it hard to combine these conversion
177 * to ostid_to FID. so we will do lmm_oi/fid conversion separately
179 * We can tell the lmm_oi by this way,
180 * 1.8: lmm_object_id = {inode}, lmm_object_gr = 0
181 * 2.1: lmm_object_id = {oid < 128k}, lmm_object_seq = FID_SEQ_NORMAL
182 * 2.4: lmm_oi.f_seq = FID_SEQ_NORMAL, lmm_oi.f_oid = {oid < 128k},
185 * But currently lmm_oi/lsm_oi does not have any "real" usages,
186 * except for printing some information, and the user can always
187 * get the real FID from LMA, besides this multiple case check might
188 * make swab more complicate. So we will keep using id/seq for lmm_oi.
191 static inline void fid_to_lmm_oi(const struct lu_fid *fid,
194 oi->oi.oi_id = fid_oid(fid);
195 oi->oi.oi_seq = fid_seq(fid);
199 * Unpack an OST object id/seq (group) into a FID. This is needed for
200 * converting all obdo, lmm, lsm, etc. 64-bit id/seq pairs into proper
201 * FIDs. Note that if an id/seq is already in FID/IDIF format it will
202 * be passed through unchanged. Only legacy OST objects in "group 0"
203 * will be mapped into the IDIF namespace so that they can fit into the
204 * struct lu_fid fields without loss.
206 static inline int ostid_to_fid(struct lu_fid *fid, const struct ost_id *ostid,
209 __u64 seq = ostid_seq(ostid);
211 if (ost_idx > 0xffff)
214 if (fid_seq_is_mdt0(seq)) {
215 __u64 oid = ostid_id(ostid);
217 /* This is a "legacy" (old 1.x/2.early) OST object in "group 0"
218 * that we map into the IDIF namespace. It allows up to 2^48
219 * objects per OST, as this is the object namespace that has
220 * been in production for years. This can handle create rates
221 * of 1M objects/s/OST for 9 years, or combinations thereof.
223 if (oid >= IDIF_MAX_OID)
226 fid->f_seq = fid_idif_seq(oid, ost_idx);
227 /* truncate to 32 bits by assignment */
229 /* in theory, not currently used */
230 fid->f_ver = oid >> 48;
231 } else if (!fid_seq_is_default(seq)) {
232 /* This is either an IDIF object, which identifies objects
233 * across all OSTs, or a regular FID. The IDIF namespace
234 * maps legacy OST objects into the FID namespace. In both
235 * cases, we just pass the FID through, no conversion needed.
237 if (ostid->oi_fid.f_ver)
240 *fid = ostid->oi_fid;
245 #endif /* _UAPI_LUSTRE_OSTID_H_ */