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 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
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 <lustre/lustre_idl.h>
53 #include <lustre_req_layout.h>
54 #include <lustre_mdt.h>
56 #include <libcfs/libcfs.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. 16384 for
73 LUSTRE_SEQ_MAX_WIDTH = 0x0000000000000400ULL,
76 * How many sequences may be allocate for meta-sequence (this is 128
79 /* changed to 16 to avoid overflow in test11 */
80 LUSTRE_SEQ_META_WIDTH = 0x0000000000000010ULL,
83 * This is how many sequences may be in one super-sequence allocated to
86 LUSTRE_SEQ_SUPER_WIDTH = ((1ULL << 30ULL) * LUSTRE_SEQ_META_WIDTH)
89 /** special fid seq: used for local object create. */
90 #define FID_SEQ_LOCAL_FILE (FID_SEQ_START + 1)
92 /** special fid seq: used for .lustre objects. */
93 #define LU_DOT_LUSTRE_SEQ (FID_SEQ_START + 0x02ULL)
95 /* Note that reserved SEQ numbers below 12 will conflict with ldiskfs
96 * inodes in the IGIF namespace, so these reserved SEQ numbers must be
97 * used sparingly until ldiskfs-based MDT backends and/or IGIF FIDs
98 * have been completely removed. */
100 /** fid sequence for distributed fs objects */
101 #define FID_SEQ_DISTRIBUTED_START (FID_SEQ_START + 0x400ULL)
103 /** special OID for local objects */
105 /** \see osd_oi_index_create */
106 OSD_OI_FID_16_OID = 2UL,
107 /** \see fld_mod_init */
109 /** \see fid_mod_init */
110 FID_SEQ_CTL_OID = 4UL,
111 FID_SEQ_SRV_OID = 5UL,
112 /** \see mdd_mod_init */
113 MDD_ROOT_INDEX_OID = 6UL,
114 MDD_ORPHAN_OID = 7UL,
115 MDD_LOV_OBJ_OID = 8UL,
116 MDD_CAPA_KEYS_OID = 9UL,
117 MDD_OBJECTS_OID = 10UL,
118 /** \see mdt_mod_init */
119 MDT_LAST_RECV_OID = 11UL,
120 /** \see osd_mod_init */
121 OSD_REM_OBJ_DIR_OID = 12UL,
124 static inline void lu_local_obj_fid(struct lu_fid *fid, __u32 oid)
126 fid->f_seq = FID_SEQ_LOCAL_FILE;
133 LUSTRE_SEQ_CONTROLLER
141 struct lu_server_seq;
143 /* Client sequence manager interface. */
144 struct lu_client_seq {
145 /* Sequence-controller export. */
146 struct obd_export *lcs_exp;
147 cfs_semaphore_t lcs_sem;
150 * Range of allowed for allocation sequeces. When using lu_client_seq on
151 * clients, this contains meta-sequence range. And for servers this
152 * contains super-sequence range.
154 struct lu_seq_range lcs_space;
156 /* Seq related proc */
157 cfs_proc_dir_entry_t *lcs_proc_dir;
159 /* This holds last allocated fid in last obtained seq */
160 struct lu_fid lcs_fid;
162 /* LUSTRE_SEQ_METADATA or LUSTRE_SEQ_DATA */
163 enum lu_cli_type lcs_type;
166 * Service uuid, passed from MDT + seq name to form unique seq name to
167 * use it with procfs.
172 * Sequence width, that is how many objects may be allocated in one
173 * sequence. Default value for it is LUSTRE_SEQ_MAX_WIDTH.
177 /* Seq-server for direct talking */
178 struct lu_server_seq *lcs_srv;
181 /* server sequence manager interface */
182 struct lu_server_seq {
183 /* Available sequences space */
184 struct lu_seq_range lss_space;
187 * Device for server side seq manager needs (saving sequences to backing
190 struct dt_device *lss_dev;
192 /* /seq file object device */
193 struct dt_object *lss_obj;
195 /* Seq related proc */
196 cfs_proc_dir_entry_t *lss_proc_dir;
198 /* LUSTRE_SEQ_SERVER or LUSTRE_SEQ_CONTROLLER */
199 enum lu_mgr_type lss_type;
201 /* Client interafce to request controller */
202 struct lu_client_seq *lss_cli;
204 /* Semaphore for protecting allocation */
205 cfs_semaphore_t lss_sem;
208 * Service uuid, passed from MDT + seq name to form unique seq name to
209 * use it with procfs.
214 * Allocation chunks for super and meta sequences. Default values are
215 * LUSTRE_SEQ_SUPER_WIDTH and LUSTRE_SEQ_META_WIDTH.
220 * Pointer to site object, required to access site fld.
222 struct md_site *lss_site;
225 int seq_query(struct com_thread_info *info);
228 int seq_server_init(struct lu_server_seq *seq,
229 struct dt_device *dev,
231 enum lu_mgr_type type,
233 const struct lu_env *env);
235 void seq_server_fini(struct lu_server_seq *seq,
236 const struct lu_env *env);
238 int seq_server_alloc_super(struct lu_server_seq *seq,
239 struct lu_seq_range *in,
240 struct lu_seq_range *out,
241 const struct lu_env *env);
243 int seq_server_alloc_meta(struct lu_server_seq *seq,
244 struct lu_seq_range *in,
245 struct lu_seq_range *out,
246 const struct lu_env *env);
248 int seq_server_set_cli(struct lu_server_seq *seq,
249 struct lu_client_seq *cli,
250 const struct lu_env *env);
253 int seq_client_init(struct lu_client_seq *seq,
254 struct obd_export *exp,
255 enum lu_cli_type type,
257 struct lu_server_seq *srv);
259 void seq_client_fini(struct lu_client_seq *seq);
261 void seq_client_flush(struct lu_client_seq *seq);
263 int seq_client_alloc_fid(struct lu_client_seq *seq,
266 /* Fids common stuff */
267 int fid_is_local(const struct lu_env *env,
268 struct lu_site *site, const struct lu_fid *fid);
272 struct ldlm_namespace;
275 LUSTRE_RES_ID_SEQ_OFF = 0,
276 LUSTRE_RES_ID_OID_OFF = 1,
277 LUSTRE_RES_ID_VER_OFF = 2,
278 LUSTRE_RES_ID_HSH_OFF = 3
282 * Build (DLM) resource name from fid.
284 static inline struct ldlm_res_id *
285 fid_build_reg_res_name(const struct lu_fid *f,
286 struct ldlm_res_id *name)
288 memset(name, 0, sizeof *name);
289 name->name[LUSTRE_RES_ID_SEQ_OFF] = fid_seq(f);
290 name->name[LUSTRE_RES_ID_OID_OFF] = fid_oid(f);
291 name->name[LUSTRE_RES_ID_VER_OFF] = fid_ver(f);
296 * Return true if resource is for object identified by fid.
298 static inline int fid_res_name_eq(const struct lu_fid *f,
299 const struct ldlm_res_id *name)
302 name->name[LUSTRE_RES_ID_SEQ_OFF] == fid_seq(f) &&
303 name->name[LUSTRE_RES_ID_OID_OFF] == fid_oid(f) &&
304 name->name[LUSTRE_RES_ID_VER_OFF] == fid_ver(f);
308 static inline struct ldlm_res_id *
309 fid_build_pdo_res_name(const struct lu_fid *f,
311 struct ldlm_res_id *name)
313 fid_build_reg_res_name(f, name);
314 name->name[LUSTRE_RES_ID_HSH_OFF] = hash;
318 static inline __u64 fid_flatten(const struct lu_fid *fid)
320 return (fid_seq(fid) - 1) * LUSTRE_SEQ_MAX_WIDTH + fid_oid(fid);
323 #define LUSTRE_SEQ_SRV_NAME "seq_srv"
324 #define LUSTRE_SEQ_CTL_NAME "seq_ctl"
326 /* Range common stuff */
327 static inline void range_cpu_to_le(struct lu_seq_range *dst, const struct lu_seq_range *src)
329 dst->lsr_start = cpu_to_le64(src->lsr_start);
330 dst->lsr_end = cpu_to_le64(src->lsr_end);
331 dst->lsr_mdt = cpu_to_le32(src->lsr_mdt);
334 static inline void range_le_to_cpu(struct lu_seq_range *dst, const struct lu_seq_range *src)
336 dst->lsr_start = le64_to_cpu(src->lsr_start);
337 dst->lsr_end = le64_to_cpu(src->lsr_end);
338 dst->lsr_mdt = le32_to_cpu(src->lsr_mdt);
341 static inline void range_cpu_to_be(struct lu_seq_range *dst, const struct lu_seq_range *src)
343 dst->lsr_start = cpu_to_be64(src->lsr_start);
344 dst->lsr_end = cpu_to_be64(src->lsr_end);
345 dst->lsr_mdt = cpu_to_be32(src->lsr_mdt);
348 static inline void range_be_to_cpu(struct lu_seq_range *dst, const struct lu_seq_range *src)
350 dst->lsr_start = be64_to_cpu(src->lsr_start);
351 dst->lsr_end = be64_to_cpu(src->lsr_end);
352 dst->lsr_mdt = be32_to_cpu(src->lsr_mdt);
357 #endif /* __LINUX_FID_H */