1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2006 Cluster File Systems, Inc.
5 * Author: Yury Umanets <umka@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <lustre/lustre_idl.h>
31 #include <lustre_req_layout.h>
32 #include <lustre_mdt.h>
34 #include <libcfs/list.h>
35 #include <libcfs/kp30.h>
40 /* Whole sequences space range and zero range definitions */
41 extern const struct lu_range LUSTRE_SEQ_SPACE_RANGE;
42 extern const struct lu_range LUSTRE_SEQ_ZERO_RANGE;
43 extern const struct lu_fid LUSTRE_BFL_FID;
47 * This is how may FIDs may be allocated in one sequence. 16384 for
50 LUSTRE_SEQ_MAX_WIDTH = 0x0000000000004000ULL,
53 * How many sequences may be allocate for meta-sequence (this is 128
56 /* changed to 16 to avoid overflow in test11 */
57 LUSTRE_SEQ_META_WIDTH = 0x0000000000000010ULL,
60 * This is how many sequences may be in one super-sequence allocated to
63 LUSTRE_SEQ_SUPER_WIDTH = (LUSTRE_SEQ_META_WIDTH * LUSTRE_SEQ_META_WIDTH)
78 /* Client sequence manager interface. */
79 struct lu_client_seq {
80 /* Sequence-controller export. */
81 struct obd_export *lcs_exp;
82 struct semaphore lcs_sem;
85 * Range of allowed for allocation sequeces. When using lu_client_seq on
86 * clients, this contains meta-sequence range. And for servers this
87 * contains super-sequence range.
89 struct lu_range lcs_space;
91 /* Seq related proc */
92 cfs_proc_dir_entry_t *lcs_proc_dir;
94 /* This holds last allocated fid in last obtained seq */
95 struct lu_fid lcs_fid;
97 /* LUSTRE_SEQ_METADATA or LUSTRE_SEQ_DATA */
98 enum lu_cli_type lcs_type;
101 * Service uuid, passed from MDT + seq name to form unique seq name to
102 * use it with procfs.
107 * Sequence width, that is how many objects may be allocated in one
108 * sequence. Default value for it is LUSTRE_SEQ_MAX_WIDTH.
112 /* Seq-server for direct talking */
113 struct lu_server_seq *lcs_srv;
116 /* server sequence manager interface */
117 struct lu_server_seq {
118 /* Available sequences space */
119 struct lu_range lss_space;
122 * Device for server side seq manager needs (saving sequences to backing
125 struct dt_device *lss_dev;
127 /* /seq file object device */
128 struct dt_object *lss_obj;
130 /* Seq related proc */
131 cfs_proc_dir_entry_t *lss_proc_dir;
133 /* LUSTRE_SEQ_SERVER or LUSTRE_SEQ_CONTROLLER */
134 enum lu_mgr_type lss_type;
136 /* Client interafce to request controller */
137 struct lu_client_seq *lss_cli;
139 /* Semaphore for protecting allocation */
140 struct semaphore lss_sem;
143 * Service uuid, passed from MDT + seq name to form unique seq name to
144 * use it with procfs.
149 * Allocation chunks for super and meta sequences. Default values are
150 * LUSTRE_SEQ_SUPER_WIDTH and LUSTRE_SEQ_META_WIDTH.
155 int seq_query(struct com_thread_info *info);
158 int seq_server_init(struct lu_server_seq *seq,
159 struct dt_device *dev,
161 enum lu_mgr_type type,
162 const struct lu_env *env);
164 void seq_server_fini(struct lu_server_seq *seq,
165 const struct lu_env *env);
167 int seq_server_alloc_super(struct lu_server_seq *seq,
169 struct lu_range *out,
170 const struct lu_env *env);
172 int seq_server_alloc_meta(struct lu_server_seq *seq,
174 struct lu_range *out,
175 const struct lu_env *env);
177 int seq_server_set_cli(struct lu_server_seq *seq,
178 struct lu_client_seq *cli,
179 const struct lu_env *env);
182 int seq_client_init(struct lu_client_seq *seq,
183 struct obd_export *exp,
184 enum lu_cli_type type,
186 struct lu_server_seq *srv);
188 void seq_client_fini(struct lu_client_seq *seq);
190 void seq_client_flush(struct lu_client_seq *seq);
192 int seq_client_alloc_fid(struct lu_client_seq *seq,
195 /* Fids common stuff */
196 int fid_is_local(struct lu_site *site, const struct lu_fid *fid);
200 struct ldlm_namespace;
203 LUSTRE_RES_ID_SEQ_OFF = 0,
204 LUSTRE_RES_ID_OID_OFF = 1,
205 LUSTRE_RES_ID_VER_OFF = 2,
206 LUSTRE_RES_ID_HSH_OFF = 3
210 * Build (DLM) resource name from fid.
212 static inline struct ldlm_res_id *
213 fid_build_reg_res_name(const struct lu_fid *f,
214 struct ldlm_res_id *name)
216 memset(name, 0, sizeof *name);
217 name->name[LUSTRE_RES_ID_SEQ_OFF] = fid_seq(f);
218 name->name[LUSTRE_RES_ID_OID_OFF] = fid_oid(f);
219 name->name[LUSTRE_RES_ID_VER_OFF] = fid_ver(f);
224 * Return true if resource is for object identified by fid.
226 static inline int fid_res_name_eq(const struct lu_fid *f,
227 const struct ldlm_res_id *name)
230 name->name[LUSTRE_RES_ID_SEQ_OFF] == fid_seq(f) &&
231 name->name[LUSTRE_RES_ID_OID_OFF] == fid_oid(f) &&
232 name->name[LUSTRE_RES_ID_VER_OFF] == fid_ver(f);
236 static inline struct ldlm_res_id *
237 fid_build_pdo_res_name(const struct lu_fid *f,
239 struct ldlm_res_id *name)
241 fid_build_reg_res_name(f, name);
242 name->name[LUSTRE_RES_ID_HSH_OFF] = hash;
246 static inline __u64 fid_flatten(const struct lu_fid *fid)
248 return (fid_seq(fid) - 1) * LUSTRE_SEQ_MAX_WIDTH + fid_oid(fid);
251 #define LUSTRE_SEQ_SRV_NAME "seq_srv"
252 #define LUSTRE_SEQ_CTL_NAME "seq_ctl"
254 /* Range common stuff */
255 void range_cpu_to_le(struct lu_range *dst, const struct lu_range *src);
256 void range_cpu_to_be(struct lu_range *dst, const struct lu_range *src);
257 void range_le_to_cpu(struct lu_range *dst, const struct lu_range *src);
258 void range_be_to_cpu(struct lu_range *dst, const struct lu_range *src);
260 #endif /* __LINUX_FID_H */