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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/include/lustre_fid.h
38 * Author: Yury Umanets <umka@clusterfs.com>
52 #include <libcfs/libcfs.h>
53 #include <lustre/lustre_idl.h>
54 #include <lustre_req_layout.h>
55 #include <lustre_mdt.h>
61 /* Whole sequences space range and zero range definitions */
62 extern const struct lu_seq_range LUSTRE_SEQ_SPACE_RANGE;
63 extern const struct lu_seq_range LUSTRE_SEQ_ZERO_RANGE;
64 extern const struct lu_fid LUSTRE_BFL_FID;
65 extern const struct lu_fid LU_OBF_FID;
66 extern const struct lu_fid LU_DOT_LUSTRE_FID;
70 * This is how may FIDs may be allocated in one sequence(128k)
72 LUSTRE_SEQ_MAX_WIDTH = 0x0000000000020000ULL,
75 * How many sequences to allocate to a client at once.
77 LUSTRE_SEQ_META_WIDTH = 0x0000000000000001ULL,
80 * seq allocation pool size.
82 LUSTRE_SEQ_BATCH_WIDTH = LUSTRE_SEQ_META_WIDTH * 1000,
85 * This is how many sequences may be in one super-sequence allocated to
88 LUSTRE_SEQ_SUPER_WIDTH = ((1ULL << 30ULL) * LUSTRE_SEQ_META_WIDTH)
92 /** 2^6 FIDs for OI containers */
93 OSD_OI_FID_OID_BITS = 6,
94 /** reserve enough FIDs in case we want more in the future */
95 OSD_OI_FID_OID_BITS_MAX = 10,
98 /** special OID for local objects */
100 /** \see fld_mod_init */
102 /** \see fid_mod_init */
103 FID_SEQ_CTL_OID = 4UL,
104 FID_SEQ_SRV_OID = 5UL,
105 /** \see mdd_mod_init */
106 MDD_ROOT_INDEX_OID = 6UL,
107 MDD_ORPHAN_OID = 7UL,
108 MDD_LOV_OBJ_OID = 8UL,
109 MDD_CAPA_KEYS_OID = 9UL,
110 /** \see mdt_mod_init */
111 MDT_LAST_RECV_OID = 11UL,
112 OSD_FS_ROOT_OID = 13UL,
113 ACCT_USER_OID = 15UL,
114 ACCT_GROUP_OID = 16UL,
115 LFSCK_BOOKMARK_OID = 17UL,
116 OTABLE_IT_OID = 18UL,
117 OFD_LAST_RECV_OID = 19UL,
118 OFD_GROUP0_LAST_OID = 20UL,
119 OFD_GROUP4K_LAST_OID = 20UL+4096,
120 OFD_LAST_GROUP_OID = 4117UL,
121 LLOG_CATALOGS_OID = 4118UL,
122 MGS_CONFIGS_OID = 4119UL,
123 OFD_HEALTH_CHECK_OID = 4120UL,
126 static inline void lu_local_obj_fid(struct lu_fid *fid, __u32 oid)
128 fid->f_seq = FID_SEQ_LOCAL_FILE;
133 static inline void lu_local_name_obj_fid(struct lu_fid *fid, __u32 oid)
135 fid->f_seq = FID_SEQ_LOCAL_NAME;
140 static inline int fid_is_otable_it(const struct lu_fid *fid)
142 return unlikely(fid_seq(fid) == FID_SEQ_LOCAL_FILE &&
143 fid_oid(fid) == OTABLE_IT_OID);
146 static inline int fid_is_acct(const struct lu_fid *fid)
148 return fid_seq(fid) == FID_SEQ_LOCAL_FILE &&
149 (fid_oid(fid) == ACCT_USER_OID ||
150 fid_oid(fid) == ACCT_GROUP_OID);
153 static inline int fid_is_quota(const struct lu_fid *fid)
155 return fid_seq(fid) == FID_SEQ_QUOTA ||
156 fid_seq(fid) == FID_SEQ_QUOTA_GLB;
161 LUSTRE_SEQ_CONTROLLER
169 struct lu_server_seq;
171 /* Client sequence manager interface. */
172 struct lu_client_seq {
173 /* Sequence-controller export. */
174 struct obd_export *lcs_exp;
175 cfs_mutex_t lcs_mutex;
178 * Range of allowed for allocation sequeces. When using lu_client_seq on
179 * clients, this contains meta-sequence range. And for servers this
180 * contains super-sequence range.
182 struct lu_seq_range lcs_space;
184 /* Seq related proc */
185 cfs_proc_dir_entry_t *lcs_proc_dir;
187 /* This holds last allocated fid in last obtained seq */
188 struct lu_fid lcs_fid;
190 /* LUSTRE_SEQ_METADATA or LUSTRE_SEQ_DATA */
191 enum lu_cli_type lcs_type;
194 * Service uuid, passed from MDT + seq name to form unique seq name to
195 * use it with procfs.
200 * Sequence width, that is how many objects may be allocated in one
201 * sequence. Default value for it is LUSTRE_SEQ_MAX_WIDTH.
205 /* Seq-server for direct talking */
206 struct lu_server_seq *lcs_srv;
208 /* wait queue for fid allocation and update indicator */
209 cfs_waitq_t lcs_waitq;
213 /* server sequence manager interface */
214 struct lu_server_seq {
215 /* Available sequences space */
216 struct lu_seq_range lss_space;
218 /* keeps highwater in lsr_end for seq allocation algorithm */
219 struct lu_seq_range lss_lowater_set;
220 struct lu_seq_range lss_hiwater_set;
223 * Device for server side seq manager needs (saving sequences to backing
226 struct dt_device *lss_dev;
228 /* /seq file object device */
229 struct dt_object *lss_obj;
231 /* Seq related proc */
232 cfs_proc_dir_entry_t *lss_proc_dir;
234 /* LUSTRE_SEQ_SERVER or LUSTRE_SEQ_CONTROLLER */
235 enum lu_mgr_type lss_type;
237 /* Client interafce to request controller */
238 struct lu_client_seq *lss_cli;
240 /* Mutex for protecting allocation */
241 cfs_mutex_t lss_mutex;
244 * Service uuid, passed from MDT + seq name to form unique seq name to
245 * use it with procfs.
250 * Allocation chunks for super and meta sequences. Default values are
251 * LUSTRE_SEQ_SUPER_WIDTH and LUSTRE_SEQ_META_WIDTH.
256 * minimum lss_alloc_set size that should be allocated from
261 /* sync is needed for update operation */
264 * Pointer to site object, required to access site fld.
266 struct md_site *lss_site;
269 int seq_query(struct com_thread_info *info);
272 int seq_server_init(struct lu_server_seq *seq,
273 struct dt_device *dev,
275 enum lu_mgr_type type,
277 const struct lu_env *env);
279 void seq_server_fini(struct lu_server_seq *seq,
280 const struct lu_env *env);
282 int seq_server_alloc_super(struct lu_server_seq *seq,
283 struct lu_seq_range *out,
284 const struct lu_env *env);
286 int seq_server_alloc_meta(struct lu_server_seq *seq,
287 struct lu_seq_range *out,
288 const struct lu_env *env);
290 int seq_server_set_cli(struct lu_server_seq *seq,
291 struct lu_client_seq *cli,
292 const struct lu_env *env);
295 int seq_client_init(struct lu_client_seq *seq,
296 struct obd_export *exp,
297 enum lu_cli_type type,
299 struct lu_server_seq *srv);
301 void seq_client_fini(struct lu_client_seq *seq);
303 void seq_client_flush(struct lu_client_seq *seq);
305 int seq_client_alloc_fid(const struct lu_env *env, struct lu_client_seq *seq,
307 int seq_client_get_seq(const struct lu_env *env, struct lu_client_seq *seq,
310 /* Fids common stuff */
311 int fid_is_local(const struct lu_env *env,
312 struct lu_site *site, const struct lu_fid *fid);
316 struct ldlm_namespace;
319 * Build (DLM) resource name from FID.
321 * NOTE: until Lustre 1.8.7/2.1.1 the fid_ver() was packed into name[2],
322 * but was moved into name[1] along with the OID to avoid consuming the
323 * renaming name[2,3] fields that need to be used for the quota identifier.
325 static inline struct ldlm_res_id *
326 fid_build_reg_res_name(const struct lu_fid *f,
327 struct ldlm_res_id *name)
329 memset(name, 0, sizeof *name);
330 name->name[LUSTRE_RES_ID_SEQ_OFF] = fid_seq(f);
331 name->name[LUSTRE_RES_ID_VER_OID_OFF] = fid_ver_oid(f);
336 * Return true if resource is for object identified by fid.
338 static inline int fid_res_name_eq(const struct lu_fid *f,
339 const struct ldlm_res_id *name)
341 return name->name[LUSTRE_RES_ID_SEQ_OFF] == fid_seq(f) &&
342 name->name[LUSTRE_RES_ID_VER_OID_OFF] == fid_ver_oid(f);
346 static inline struct ldlm_res_id *
347 fid_build_pdo_res_name(const struct lu_fid *f,
349 struct ldlm_res_id *name)
351 fid_build_reg_res_name(f, name);
352 name->name[LUSTRE_RES_ID_HSH_OFF] = hash;
358 * Flatten 128-bit FID values into a 64-bit value for use as an inode number.
359 * For non-IGIF FIDs this starts just over 2^32, and continues without
360 * conflict until 2^64, at which point we wrap the high 24 bits of the SEQ
361 * into the range where there may not be many OID values in use, to minimize
362 * the risk of conflict.
364 * Suppose LUSTRE_SEQ_MAX_WIDTH less than (1 << 24) which is currently true,
365 * the time between re-used inode numbers is very long - 2^40 SEQ numbers,
366 * or about 2^40 client mounts, if clients create less than 2^24 files/mount.
368 static inline __u64 fid_flatten(const struct lu_fid *fid)
373 if (fid_is_igif(fid)) {
374 ino = lu_igif_ino(fid);
380 ino = (seq << 24) + ((seq >> 24) & 0xffffff0000ULL) + fid_oid(fid);
382 RETURN(ino ? ino : fid_oid(fid));
385 static inline __u32 fid_hash(const struct lu_fid *f, int bits)
387 /* all objects with same id and different versions will belong to same
388 * collisions list. */
389 return cfs_hash_long(fid_flatten(f), bits);
393 * map fid to 32 bit value for ino on 32bit systems. */
394 static inline __u32 fid_flatten32(const struct lu_fid *fid)
399 if (fid_is_igif(fid)) {
400 ino = lu_igif_ino(fid);
404 seq = fid_seq(fid) - FID_SEQ_START;
406 /* Map the high bits of the OID into higher bits of the inode number so
407 * that inodes generated at about the same time have a reduced chance
408 * of collisions. This will give a period of 2^12 = 1024 unique clients
409 * (from SEQ) and up to min(LUSTRE_SEQ_MAX_WIDTH, 2^20) = 128k objects
410 * (from OID), or up to 128M inodes without collisions for new files. */
411 ino = ((seq & 0x000fffffULL) << 12) + ((seq >> 8) & 0xfffff000) +
412 (seq >> (64 - (40-8)) & 0xffffff00) +
413 (fid_oid(fid) & 0xff000fff) + ((fid_oid(fid) & 0x00fff000) << 8);
415 RETURN(ino ? ino : fid_oid(fid));
418 #define LUSTRE_SEQ_SRV_NAME "seq_srv"
419 #define LUSTRE_SEQ_CTL_NAME "seq_ctl"
421 /* Range common stuff */
422 static inline void range_cpu_to_le(struct lu_seq_range *dst, const struct lu_seq_range *src)
424 dst->lsr_start = cpu_to_le64(src->lsr_start);
425 dst->lsr_end = cpu_to_le64(src->lsr_end);
426 dst->lsr_index = cpu_to_le32(src->lsr_index);
427 dst->lsr_flags = cpu_to_le32(src->lsr_flags);
430 static inline void range_le_to_cpu(struct lu_seq_range *dst, const struct lu_seq_range *src)
432 dst->lsr_start = le64_to_cpu(src->lsr_start);
433 dst->lsr_end = le64_to_cpu(src->lsr_end);
434 dst->lsr_index = le32_to_cpu(src->lsr_index);
435 dst->lsr_flags = le32_to_cpu(src->lsr_flags);
438 static inline void range_cpu_to_be(struct lu_seq_range *dst, const struct lu_seq_range *src)
440 dst->lsr_start = cpu_to_be64(src->lsr_start);
441 dst->lsr_end = cpu_to_be64(src->lsr_end);
442 dst->lsr_index = cpu_to_be32(src->lsr_index);
443 dst->lsr_flags = cpu_to_be32(src->lsr_flags);
446 static inline void range_be_to_cpu(struct lu_seq_range *dst, const struct lu_seq_range *src)
448 dst->lsr_start = be64_to_cpu(src->lsr_start);
449 dst->lsr_end = be64_to_cpu(src->lsr_end);
450 dst->lsr_index = be32_to_cpu(src->lsr_index);
451 dst->lsr_flags = be32_to_cpu(src->lsr_flags);
456 #endif /* __LINUX_FID_H */