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/libcfs.h>
39 /* Whole sequences space range and zero range definitions */
40 extern const struct lu_range LUSTRE_SEQ_SPACE_RANGE;
41 extern const struct lu_range LUSTRE_SEQ_ZERO_RANGE;
42 extern const struct lu_fid LUSTRE_BFL_FID;
46 * This is how may FIDs may be allocated in one sequence. 16384 for
49 LUSTRE_SEQ_MAX_WIDTH = 0x0000000000004000ULL,
52 * How many sequences may be allocate for meta-sequence (this is 128
55 /* changed to 16 to avoid overflow in test11 */
56 LUSTRE_SEQ_META_WIDTH = 0x0000000000000010ULL,
59 * This is how many sequences may be in one super-sequence allocated to
62 LUSTRE_SEQ_SUPER_WIDTH = (LUSTRE_SEQ_META_WIDTH * LUSTRE_SEQ_META_WIDTH)
77 /* Client sequence manager interface. */
78 struct lu_client_seq {
79 /* Sequence-controller export. */
80 struct obd_export *lcs_exp;
81 struct semaphore lcs_sem;
84 * Range of allowed for allocation sequeces. When using lu_client_seq on
85 * clients, this contains meta-sequence range. And for servers this
86 * contains super-sequence range.
88 struct lu_range lcs_space;
90 /* Seq related proc */
91 cfs_proc_dir_entry_t *lcs_proc_dir;
93 /* This holds last allocated fid in last obtained seq */
94 struct lu_fid lcs_fid;
96 /* LUSTRE_SEQ_METADATA or LUSTRE_SEQ_DATA */
97 enum lu_cli_type lcs_type;
100 * Service uuid, passed from MDT + seq name to form unique seq name to
101 * use it with procfs.
106 * Sequence width, that is how many objects may be allocated in one
107 * sequence. Default value for it is LUSTRE_SEQ_MAX_WIDTH.
111 /* Seq-server for direct talking */
112 struct lu_server_seq *lcs_srv;
115 /* server sequence manager interface */
116 struct lu_server_seq {
117 /* Available sequences space */
118 struct lu_range lss_space;
121 * Device for server side seq manager needs (saving sequences to backing
124 struct dt_device *lss_dev;
126 /* /seq file object device */
127 struct dt_object *lss_obj;
129 /* Seq related proc */
130 cfs_proc_dir_entry_t *lss_proc_dir;
132 /* LUSTRE_SEQ_SERVER or LUSTRE_SEQ_CONTROLLER */
133 enum lu_mgr_type lss_type;
135 /* Client interafce to request controller */
136 struct lu_client_seq *lss_cli;
138 /* Semaphore for protecting allocation */
139 struct semaphore lss_sem;
142 * Service uuid, passed from MDT + seq name to form unique seq name to
143 * use it with procfs.
148 * Allocation chunks for super and meta sequences. Default values are
149 * LUSTRE_SEQ_SUPER_WIDTH and LUSTRE_SEQ_META_WIDTH.
154 int seq_query(struct com_thread_info *info);
157 int seq_server_init(struct lu_server_seq *seq,
158 struct dt_device *dev,
160 enum lu_mgr_type type,
161 const struct lu_env *env);
163 void seq_server_fini(struct lu_server_seq *seq,
164 const struct lu_env *env);
166 int seq_server_alloc_super(struct lu_server_seq *seq,
168 struct lu_range *out,
169 const struct lu_env *env);
171 int seq_server_alloc_meta(struct lu_server_seq *seq,
173 struct lu_range *out,
174 const struct lu_env *env);
176 int seq_server_set_cli(struct lu_server_seq *seq,
177 struct lu_client_seq *cli,
178 const struct lu_env *env);
181 int seq_client_init(struct lu_client_seq *seq,
182 struct obd_export *exp,
183 enum lu_cli_type type,
185 struct lu_server_seq *srv);
187 void seq_client_fini(struct lu_client_seq *seq);
189 void seq_client_flush(struct lu_client_seq *seq);
191 int seq_client_alloc_fid(struct lu_client_seq *seq,
194 /* Fids common stuff */
195 int fid_is_local(struct lu_site *site, const struct lu_fid *fid);
199 struct ldlm_namespace;
202 LUSTRE_RES_ID_SEQ_OFF = 0,
203 LUSTRE_RES_ID_OID_OFF = 1,
204 LUSTRE_RES_ID_VER_OFF = 2,
205 LUSTRE_RES_ID_HSH_OFF = 3
209 * Build (DLM) resource name from fid.
211 static inline struct ldlm_res_id *
212 fid_build_reg_res_name(const struct lu_fid *f,
213 struct ldlm_res_id *name)
215 memset(name, 0, sizeof *name);
216 name->name[LUSTRE_RES_ID_SEQ_OFF] = fid_seq(f);
217 name->name[LUSTRE_RES_ID_OID_OFF] = fid_oid(f);
218 name->name[LUSTRE_RES_ID_VER_OFF] = fid_ver(f);
223 * Return true if resource is for object identified by fid.
225 static inline int fid_res_name_eq(const struct lu_fid *f,
226 const struct ldlm_res_id *name)
229 name->name[LUSTRE_RES_ID_SEQ_OFF] == fid_seq(f) &&
230 name->name[LUSTRE_RES_ID_OID_OFF] == fid_oid(f) &&
231 name->name[LUSTRE_RES_ID_VER_OFF] == fid_ver(f);
235 static inline struct ldlm_res_id *
236 fid_build_pdo_res_name(const struct lu_fid *f,
238 struct ldlm_res_id *name)
240 fid_build_reg_res_name(f, name);
241 name->name[LUSTRE_RES_ID_HSH_OFF] = hash;
245 static inline __u64 fid_flatten(const struct lu_fid *fid)
247 return (fid_seq(fid) - 1) * LUSTRE_SEQ_MAX_WIDTH + fid_oid(fid);
250 #define LUSTRE_SEQ_SRV_NAME "seq_srv"
251 #define LUSTRE_SEQ_CTL_NAME "seq_ctl"
253 /* Range common stuff */
254 void range_cpu_to_le(struct lu_range *dst, const struct lu_range *src);
255 void range_cpu_to_be(struct lu_range *dst, const struct lu_range *src);
256 void range_le_to_cpu(struct lu_range *dst, const struct lu_range *src);
257 void range_be_to_cpu(struct lu_range *dst, const struct lu_range *src);
259 #endif /* __LINUX_FID_H */