1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011, 2012, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lustre/include/lustre_fid.h
40 * Author: Yury Umanets <umka@clusterfs.com>
54 #include <libcfs/libcfs.h>
55 #include <lustre/lustre_idl.h>
56 #include <lustre_req_layout.h>
57 #include <lustre_mdt.h>
63 /* Whole sequences space range and zero range definitions */
64 extern const struct lu_seq_range LUSTRE_SEQ_SPACE_RANGE;
65 extern const struct lu_seq_range LUSTRE_SEQ_ZERO_RANGE;
66 extern const struct lu_fid LUSTRE_BFL_FID;
67 extern const struct lu_fid LU_OBF_FID;
68 extern const struct lu_fid LU_DOT_LUSTRE_FID;
72 * This is how may FIDs may be allocated in one sequence(128k)
74 LUSTRE_SEQ_MAX_WIDTH = 0x0000000000020000ULL,
77 * How many sequences to allocate to a client at once.
79 LUSTRE_SEQ_META_WIDTH = 0x0000000000000001ULL,
82 * seq allocation pool size.
84 LUSTRE_SEQ_BATCH_WIDTH = LUSTRE_SEQ_META_WIDTH * 1000,
87 * This is how many sequences may be in one super-sequence allocated to
90 LUSTRE_SEQ_SUPER_WIDTH = ((1ULL << 30ULL) * LUSTRE_SEQ_META_WIDTH)
94 /** 2^6 FIDs for OI containers */
95 OSD_OI_FID_OID_BITS = 6,
96 /** reserve enough FIDs in case we want more in the future */
97 OSD_OI_FID_OID_BITS_MAX = 10,
100 /** special OID for local objects */
102 /** \see fld_mod_init */
104 /** \see fid_mod_init */
105 FID_SEQ_CTL_OID = 4UL,
106 FID_SEQ_SRV_OID = 5UL,
107 /** \see mdd_mod_init */
108 MDD_ROOT_INDEX_OID = 6UL,
109 MDD_ORPHAN_OID = 7UL,
110 MDD_LOV_OBJ_OID = 8UL,
111 MDD_CAPA_KEYS_OID = 9UL,
112 MDD_OBJECTS_OID = 10UL,
113 /** \see mdt_mod_init */
114 MDT_LAST_RECV_OID = 11UL,
115 /** \see osd_mod_init */
116 OSD_REM_OBJ_DIR_OID = 12UL,
117 OSD_FS_ROOT_OID = 13UL,
118 ACCT_USER_OID = 15UL,
119 ACCT_GROUP_OID = 16UL,
120 OFD_LAST_RECV_OID = 19UL,
121 OFD_GROUP0_LAST_OID = 20UL,
122 OFD_GROUP4K_LAST_OID = 20UL+4096,
123 OFD_LAST_GROUP_OID = 4117UL,
124 LLOG_CATALOGS_OID = 4118UL,
125 MGS_CONFIGS_OID = 4119UL,
126 OFD_HEALTH_CHECK_OID = 4120UL,
128 /** first OID for first OI fid */
129 OSD_OI_FID_OID_FIRST = 5000UL,
130 /** reserve enough in case we want to have more in the future */
131 OSD_OI_FID_OID_MAX = OSD_OI_FID_OID_FIRST +
132 (1UL << OSD_OI_FID_OID_BITS_MAX),
135 static inline void lu_local_obj_fid(struct lu_fid *fid, __u32 oid)
137 fid->f_seq = FID_SEQ_LOCAL_FILE;
144 LUSTRE_SEQ_CONTROLLER
152 struct lu_server_seq;
154 /* Client sequence manager interface. */
155 struct lu_client_seq {
156 /* Sequence-controller export. */
157 struct obd_export *lcs_exp;
158 cfs_semaphore_t lcs_sem;
161 * Range of allowed for allocation sequeces. When using lu_client_seq on
162 * clients, this contains meta-sequence range. And for servers this
163 * contains super-sequence range.
165 struct lu_seq_range lcs_space;
167 /* Seq related proc */
168 cfs_proc_dir_entry_t *lcs_proc_dir;
170 /* This holds last allocated fid in last obtained seq */
171 struct lu_fid lcs_fid;
173 /* LUSTRE_SEQ_METADATA or LUSTRE_SEQ_DATA */
174 enum lu_cli_type lcs_type;
177 * Service uuid, passed from MDT + seq name to form unique seq name to
178 * use it with procfs.
183 * Sequence width, that is how many objects may be allocated in one
184 * sequence. Default value for it is LUSTRE_SEQ_MAX_WIDTH.
188 /* Seq-server for direct talking */
189 struct lu_server_seq *lcs_srv;
191 /* wait queue for fid allocation and update indicator */
192 cfs_waitq_t lcs_waitq;
196 /* server sequence manager interface */
197 struct lu_server_seq {
198 /* Available sequences space */
199 struct lu_seq_range lss_space;
201 /* keeps highwater in lsr_end for seq allocation algorithm */
202 struct lu_seq_range lss_lowater_set;
203 struct lu_seq_range lss_hiwater_set;
206 * Device for server side seq manager needs (saving sequences to backing
209 struct dt_device *lss_dev;
211 /* /seq file object device */
212 struct dt_object *lss_obj;
214 /* Seq related proc */
215 cfs_proc_dir_entry_t *lss_proc_dir;
217 /* LUSTRE_SEQ_SERVER or LUSTRE_SEQ_CONTROLLER */
218 enum lu_mgr_type lss_type;
220 /* Client interafce to request controller */
221 struct lu_client_seq *lss_cli;
223 /* Semaphore for protecting allocation */
224 cfs_semaphore_t lss_sem;
227 * Service uuid, passed from MDT + seq name to form unique seq name to
228 * use it with procfs.
233 * Allocation chunks for super and meta sequences. Default values are
234 * LUSTRE_SEQ_SUPER_WIDTH and LUSTRE_SEQ_META_WIDTH.
239 * minimum lss_alloc_set size that should be allocated from
244 /* sync is needed for update operation */
247 * Pointer to site object, required to access site fld.
249 struct md_site *lss_site;
252 int seq_query(struct com_thread_info *info);
255 int seq_server_init(struct lu_server_seq *seq,
256 struct dt_device *dev,
258 enum lu_mgr_type type,
260 const struct lu_env *env);
262 void seq_server_fini(struct lu_server_seq *seq,
263 const struct lu_env *env);
265 int seq_server_alloc_super(struct lu_server_seq *seq,
266 struct lu_seq_range *out,
267 const struct lu_env *env);
269 int seq_server_alloc_meta(struct lu_server_seq *seq,
270 struct lu_seq_range *out,
271 const struct lu_env *env);
273 int seq_server_set_cli(struct lu_server_seq *seq,
274 struct lu_client_seq *cli,
275 const struct lu_env *env);
278 int seq_client_init(struct lu_client_seq *seq,
279 struct obd_export *exp,
280 enum lu_cli_type type,
282 struct lu_server_seq *srv);
284 void seq_client_fini(struct lu_client_seq *seq);
286 void seq_client_flush(struct lu_client_seq *seq);
288 int seq_client_alloc_fid(const struct lu_env *env, struct lu_client_seq *seq,
290 int seq_client_get_seq(const struct lu_env *env, struct lu_client_seq *seq,
293 /* Fids common stuff */
294 int fid_is_local(const struct lu_env *env,
295 struct lu_site *site, const struct lu_fid *fid);
299 struct ldlm_namespace;
302 LUSTRE_RES_ID_SEQ_OFF = 0,
303 LUSTRE_RES_ID_OID_OFF = 1,
304 LUSTRE_RES_ID_VER_OFF = 2,
305 LUSTRE_RES_ID_HSH_OFF = 3
309 * Build (DLM) resource name from fid.
311 static inline struct ldlm_res_id *
312 fid_build_reg_res_name(const struct lu_fid *f,
313 struct ldlm_res_id *name)
315 memset(name, 0, sizeof *name);
316 name->name[LUSTRE_RES_ID_SEQ_OFF] = fid_seq(f);
317 name->name[LUSTRE_RES_ID_OID_OFF] = fid_oid(f);
318 name->name[LUSTRE_RES_ID_VER_OFF] = fid_ver(f);
323 * Return true if resource is for object identified by fid.
325 static inline int fid_res_name_eq(const struct lu_fid *f,
326 const struct ldlm_res_id *name)
329 name->name[LUSTRE_RES_ID_SEQ_OFF] == fid_seq(f) &&
330 name->name[LUSTRE_RES_ID_OID_OFF] == fid_oid(f) &&
331 name->name[LUSTRE_RES_ID_VER_OFF] == fid_ver(f);
335 static inline struct ldlm_res_id *
336 fid_build_pdo_res_name(const struct lu_fid *f,
338 struct ldlm_res_id *name)
340 fid_build_reg_res_name(f, name);
341 name->name[LUSTRE_RES_ID_HSH_OFF] = hash;
347 * Flatten 128-bit FID values into a 64-bit value for use as an inode number.
348 * For non-IGIF FIDs this starts just over 2^32, and continues without
349 * conflict until 2^64, at which point we wrap the high 24 bits of the SEQ
350 * into the range where there may not be many OID values in use, to minimize
351 * the risk of conflict.
353 * Suppose LUSTRE_SEQ_MAX_WIDTH less than (1 << 24) which is currently true,
354 * the time between re-used inode numbers is very long - 2^40 SEQ numbers,
355 * or about 2^40 client mounts, if clients create less than 2^24 files/mount.
357 static inline __u64 fid_flatten(const struct lu_fid *fid)
362 if (fid_is_igif(fid)) {
363 ino = lu_igif_ino(fid);
369 ino = (seq << 24) + ((seq >> 24) & 0xffffff0000ULL) + fid_oid(fid);
371 RETURN(ino ? ino : fid_oid(fid));
374 static inline __u32 fid_hash(const struct lu_fid *f, int bits)
376 /* all objects with same id and different versions will belong to same
377 * collisions list. */
378 return cfs_hash_long(fid_flatten(f), bits);
382 * map fid to 32 bit value for ino on 32bit systems. */
383 static inline __u32 fid_flatten32(const struct lu_fid *fid)
388 if (fid_is_igif(fid)) {
389 ino = lu_igif_ino(fid);
393 seq = fid_seq(fid) - FID_SEQ_START;
395 /* Map the high bits of the OID into higher bits of the inode number so
396 * that inodes generated at about the same time have a reduced chance
397 * of collisions. This will give a period of 2^12 = 1024 unique clients
398 * (from SEQ) and up to min(LUSTRE_SEQ_MAX_WIDTH, 2^20) = 128k objects
399 * (from OID), or up to 128M inodes without collisions for new files. */
400 ino = ((seq & 0x000fffffULL) << 12) + ((seq >> 8) & 0xfffff000) +
401 (seq >> (64 - (40-8)) & 0xffffff00) +
402 (fid_oid(fid) & 0xff000fff) + ((fid_oid(fid) & 0x00fff000) << 8);
404 RETURN(ino ? ino : fid_oid(fid));
407 #define LUSTRE_SEQ_SRV_NAME "seq_srv"
408 #define LUSTRE_SEQ_CTL_NAME "seq_ctl"
410 /* Range common stuff */
411 static inline void range_cpu_to_le(struct lu_seq_range *dst, const struct lu_seq_range *src)
413 dst->lsr_start = cpu_to_le64(src->lsr_start);
414 dst->lsr_end = cpu_to_le64(src->lsr_end);
415 dst->lsr_index = cpu_to_le32(src->lsr_index);
416 dst->lsr_flags = cpu_to_le32(src->lsr_flags);
419 static inline void range_le_to_cpu(struct lu_seq_range *dst, const struct lu_seq_range *src)
421 dst->lsr_start = le64_to_cpu(src->lsr_start);
422 dst->lsr_end = le64_to_cpu(src->lsr_end);
423 dst->lsr_index = le32_to_cpu(src->lsr_index);
424 dst->lsr_flags = le32_to_cpu(src->lsr_flags);
427 static inline void range_cpu_to_be(struct lu_seq_range *dst, const struct lu_seq_range *src)
429 dst->lsr_start = cpu_to_be64(src->lsr_start);
430 dst->lsr_end = cpu_to_be64(src->lsr_end);
431 dst->lsr_index = cpu_to_be32(src->lsr_index);
432 dst->lsr_flags = cpu_to_be32(src->lsr_flags);
435 static inline void range_be_to_cpu(struct lu_seq_range *dst, const struct lu_seq_range *src)
437 dst->lsr_start = be64_to_cpu(src->lsr_start);
438 dst->lsr_end = be64_to_cpu(src->lsr_end);
439 dst->lsr_index = be32_to_cpu(src->lsr_index);
440 dst->lsr_flags = be32_to_cpu(src->lsr_flags);
445 #endif /* __LINUX_FID_H */