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 2016 Cray Inc, all rights reserved.
31 * all fid manipulation functions go here
33 * FIDS are globally unique within a Lustre filessytem, and are made up
34 * of three parts: sequence, Object ID, and version.
37 #ifndef _UAPI_LUSTRE_FID_H_
38 #define _UAPI_LUSTRE_FID_H_
41 * This is due to us being out of kernel and the way the OpenSFS branch
45 # include <uapi/linux/lustre/lustre_idl.h>
47 # include <linux/lustre/lustre_idl.h>
50 /** returns fid object sequence */
51 static inline __u64 fid_seq(const struct lu_fid *fid)
56 /** returns fid object id */
57 static inline __u32 fid_oid(const struct lu_fid *fid)
62 /** returns fid object version */
63 static inline __u32 fid_ver(const struct lu_fid *fid)
68 static inline void fid_zero(struct lu_fid *fid)
70 memset(fid, 0, sizeof(*fid));
73 static inline __u64 fid_ver_oid(const struct lu_fid *fid)
75 return (__u64)fid_ver(fid) << 32 | fid_oid(fid);
78 static inline bool fid_seq_is_mdt0(__u64 seq)
80 return seq == FID_SEQ_OST_MDT0;
83 static inline bool fid_seq_is_mdt(__u64 seq)
85 return seq == FID_SEQ_OST_MDT0 || seq >= FID_SEQ_NORMAL;
88 static inline bool fid_seq_is_echo(__u64 seq)
90 return seq == FID_SEQ_ECHO;
93 static inline bool fid_is_echo(const struct lu_fid *fid)
95 return fid_seq_is_echo(fid_seq(fid));
98 static inline bool fid_seq_is_llog(__u64 seq)
100 return seq == FID_SEQ_LLOG;
103 static inline bool fid_is_llog(const struct lu_fid *fid)
105 /* file with OID == 0 is not llog but contains last oid */
106 return fid_seq_is_llog(fid_seq(fid)) && fid_oid(fid) > 0;
109 static inline bool fid_seq_is_rsvd(__u64 seq)
111 return seq > FID_SEQ_OST_MDT0 && seq <= FID_SEQ_RSVD;
114 static inline bool fid_seq_is_special(__u64 seq)
116 return seq == FID_SEQ_SPECIAL;
119 static inline bool fid_seq_is_local_file(__u64 seq)
121 return seq == FID_SEQ_LOCAL_FILE ||
122 seq == FID_SEQ_LOCAL_NAME;
125 static inline bool fid_seq_is_root(__u64 seq)
127 return seq == FID_SEQ_ROOT;
130 static inline bool fid_seq_is_dot(__u64 seq)
132 return seq == FID_SEQ_DOT_LUSTRE;
135 static inline bool fid_seq_is_default(__u64 seq)
137 return seq == FID_SEQ_LOV_DEFAULT;
140 static inline bool fid_is_mdt0(const struct lu_fid *fid)
142 return fid_seq_is_mdt0(fid_seq(fid));
145 static inline void lu_root_fid(struct lu_fid *fid)
147 fid->f_seq = FID_SEQ_ROOT;
148 fid->f_oid = FID_OID_ROOT;
152 static inline void lu_echo_root_fid(struct lu_fid *fid)
154 fid->f_seq = FID_SEQ_ROOT;
155 fid->f_oid = FID_OID_ECHO_ROOT;
159 static inline void lu_update_log_fid(struct lu_fid *fid, __u32 index)
161 fid->f_seq = FID_SEQ_UPDATE_LOG;
166 static inline void lu_update_log_dir_fid(struct lu_fid *fid, __u32 index)
168 fid->f_seq = FID_SEQ_UPDATE_LOG_DIR;
174 * Check if a fid is igif or not.
175 * \param fid the fid to be tested.
176 * \return true if the fid is an igif; otherwise false.
178 static inline bool fid_seq_is_igif(__u64 seq)
180 return seq >= FID_SEQ_IGIF && seq <= FID_SEQ_IGIF_MAX;
183 static inline bool fid_is_igif(const struct lu_fid *fid)
185 return fid_seq_is_igif(fid_seq(fid));
189 * Check if a fid is idif or not.
190 * \param fid the fid to be tested.
191 * \return true if the fid is an idif; otherwise false.
193 static inline bool fid_seq_is_idif(__u64 seq)
195 return seq >= FID_SEQ_IDIF && seq <= FID_SEQ_IDIF_MAX;
198 static inline bool fid_is_idif(const struct lu_fid *fid)
200 return fid_seq_is_idif(fid_seq(fid));
203 static inline bool fid_is_local_file(const struct lu_fid *fid)
205 return fid_seq_is_local_file(fid_seq(fid));
208 static inline bool fid_seq_is_norm(__u64 seq)
210 return (seq >= FID_SEQ_NORMAL);
213 static inline bool fid_is_norm(const struct lu_fid *fid)
215 return fid_seq_is_norm(fid_seq(fid));
218 static inline int fid_is_layout_rbtree(const struct lu_fid *fid)
220 return fid_seq(fid) == FID_SEQ_LAYOUT_RBTREE;
223 static inline bool fid_seq_is_update_log(__u64 seq)
225 return seq == FID_SEQ_UPDATE_LOG;
228 static inline bool fid_is_update_log(const struct lu_fid *fid)
230 return fid_seq_is_update_log(fid_seq(fid));
233 static inline bool fid_seq_is_update_log_dir(__u64 seq)
235 return seq == FID_SEQ_UPDATE_LOG_DIR;
238 static inline bool fid_is_update_log_dir(const struct lu_fid *fid)
240 return fid_seq_is_update_log_dir(fid_seq(fid));
243 /* convert an OST objid into an IDIF FID SEQ number */
244 static inline __u64 fid_idif_seq(__u64 id, __u32 ost_idx)
246 return FID_SEQ_IDIF | (ost_idx << 16) | ((id >> 32) & 0xffff);
249 /* convert a packed IDIF FID into an OST objid */
250 static inline __u64 fid_idif_id(__u64 seq, __u32 oid, __u32 ver)
252 return ((__u64)ver << 48) | ((seq & 0xffff) << 32) | oid;
255 static inline __u32 idif_ost_idx(__u64 seq)
257 return (seq >> 16) & 0xffff;
260 /* extract ost index from IDIF FID */
261 static inline __u32 fid_idif_ost_idx(const struct lu_fid *fid)
263 return idif_ost_idx(fid_seq(fid));
266 /* Check whether the fid is for LAST_ID */
267 static inline bool fid_is_last_id(const struct lu_fid *fid)
269 if (fid_oid(fid) != 0)
272 if (fid_is_idif(fid) && ((fid_seq(fid) & 0xFFFF) != 0))
275 if (fid_seq(fid) == FID_SEQ_UPDATE_LOG ||
276 fid_seq(fid) == FID_SEQ_UPDATE_LOG_DIR)
283 * Get inode number from an igif.
284 * \param fid an igif to get inode number from.
285 * \return inode number for the igif.
287 static inline ino_t lu_igif_ino(const struct lu_fid *fid)
293 * Get inode generation from an igif.
294 * \param fid an igif to get inode generation from.
295 * \return inode generation for the igif.
297 static inline __u32 lu_igif_gen(const struct lu_fid *fid)
303 * Build igif from the inode number/generation.
305 static inline void lu_igif_build(struct lu_fid *fid, __u32 ino, __u32 gen)
313 * Fids are transmitted across network (in the sender byte-ordering),
314 * and stored on disk in big-endian order.
316 static inline void fid_cpu_to_le(struct lu_fid *dst, const struct lu_fid *src)
318 dst->f_seq = __cpu_to_le64(fid_seq(src));
319 dst->f_oid = __cpu_to_le32(fid_oid(src));
320 dst->f_ver = __cpu_to_le32(fid_ver(src));
323 static inline void fid_le_to_cpu(struct lu_fid *dst, const struct lu_fid *src)
325 dst->f_seq = __le64_to_cpu(fid_seq(src));
326 dst->f_oid = __le32_to_cpu(fid_oid(src));
327 dst->f_ver = __le32_to_cpu(fid_ver(src));
330 static inline void fid_cpu_to_be(struct lu_fid *dst, const struct lu_fid *src)
332 dst->f_seq = __cpu_to_be64(fid_seq(src));
333 dst->f_oid = __cpu_to_be32(fid_oid(src));
334 dst->f_ver = __cpu_to_be32(fid_ver(src));
337 static inline void fid_be_to_cpu(struct lu_fid *dst, const struct lu_fid *src)
339 dst->f_seq = __be64_to_cpu(fid_seq(src));
340 dst->f_oid = __be32_to_cpu(fid_oid(src));
341 dst->f_ver = __be32_to_cpu(fid_ver(src));
344 static inline bool fid_is_sane(const struct lu_fid *fid)
346 return fid && ((fid_seq(fid) >= FID_SEQ_START && !fid_ver(fid)) ||
347 fid_is_igif(fid) || fid_is_idif(fid) ||
348 fid_seq_is_rsvd(fid_seq(fid)));
351 static inline bool lu_fid_eq(const struct lu_fid *f0, const struct lu_fid *f1)
353 return !memcmp(f0, f1, sizeof(*f0));
356 static inline int lu_fid_cmp(const struct lu_fid *f0,
357 const struct lu_fid *f1)
359 if (fid_seq(f0) != fid_seq(f1))
360 return fid_seq(f0) > fid_seq(f1) ? 1 : -1;
362 if (fid_oid(f0) != fid_oid(f1))
363 return fid_oid(f0) > fid_oid(f1) ? 1 : -1;
365 if (fid_ver(f0) != fid_ver(f1))
366 return fid_ver(f0) > fid_ver(f1) ? 1 : -1;