Whamcloud - gitweb
7c8085f8385cd429024afa21bf8dcc8af3e02746
[fs/lustre-release.git] / lustre / include / lustre_fid.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
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.
11  *
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).
17  *
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
21  *
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
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/include/lustre_fid.h
37  *
38  * Author: Yury Umanets <umka@clusterfs.com>
39  */
40
41 #ifndef __LINUX_FID_H
42 #define __LINUX_FID_H
43
44 /*
45  * struct lu_fid
46  */
47 #include <lustre/lustre_idl.h>
48 #include <lustre_req_layout.h>
49 #include <lustre_mdt.h>
50
51 #include <libcfs/libcfs.h>
52
53 struct lu_site;
54 struct lu_context;
55
56 /* Whole sequences space range and zero range definitions */
57 extern const struct lu_seq_range LUSTRE_SEQ_SPACE_RANGE;
58 extern const struct lu_seq_range LUSTRE_SEQ_ZERO_RANGE;
59 extern const struct lu_fid LUSTRE_BFL_FID;
60
61 enum {
62         /*
63          * This is how may FIDs may be allocated in one sequence. 16384 for
64          * now.
65          */
66         LUSTRE_SEQ_MAX_WIDTH = 0x0000000000000400ULL,
67
68         /*
69          * How many sequences may be allocate for meta-sequence (this is 128
70          * sequences).
71          */
72         /* changed to 16 to avoid overflow in test11 */
73         LUSTRE_SEQ_META_WIDTH = 0x0000000000000010ULL,
74
75         /*
76          * This is how many sequences may be in one super-sequence allocated to
77          * MDTs.
78          */
79         LUSTRE_SEQ_SUPER_WIDTH = (LUSTRE_SEQ_META_WIDTH * LUSTRE_SEQ_META_WIDTH)
80 };
81
82 /** special fid seq: used for local object create. */
83 #define FID_SEQ_LOCAL_FILE      (FID_SEQ_START + 1)
84
85 /** special OID for local objects */
86 enum {
87         /** \see osd_oi_index_create */
88         OSD_OI_FID_SMALL_OID    = 1UL,
89         OSD_OI_FID_OTHER_OID    = 2UL,
90         /** \see fld_mod_init */
91         FLD_INDEX_OID           = 3UL,
92         /** \see fid_mod_init */
93         FID_SEQ_CTL_OID         = 4UL,
94         FID_SEQ_SRV_OID         = 5UL,
95         /** \see mdd_mod_init */
96         MDD_ROOT_INDEX_OID      = 6UL,
97         MDD_ORPHAN_OID          = 7UL,
98         MDD_LOV_OBJ_OID         = 8UL,
99         MDD_CAPA_KEYS_OID       = 9UL,
100         MDD_OBJECTS_OID         = 10UL,
101         /** \see mdt_mod_init */
102         MDT_LAST_RECV_OID       = 11UL,
103         /** \see osd_mod_init */
104         OSD_REM_OBJ_DIR_OID     = 12UL,
105 };
106
107 static inline void lu_local_obj_fid(struct lu_fid *fid, __u32 oid)
108 {
109         fid->f_seq = FID_SEQ_LOCAL_FILE;
110         fid->f_oid = oid;
111         fid->f_ver = 0;
112 }
113
114 enum lu_mgr_type {
115         LUSTRE_SEQ_SERVER,
116         LUSTRE_SEQ_CONTROLLER
117 };
118
119 enum lu_cli_type {
120         LUSTRE_SEQ_METADATA,
121         LUSTRE_SEQ_DATA
122 };
123
124 struct lu_server_seq;
125
126 /* Client sequence manager interface. */
127 struct lu_client_seq {
128         /* Sequence-controller export. */
129         struct obd_export      *lcs_exp;
130         struct semaphore        lcs_sem;
131
132         /*
133          * Range of allowed for allocation sequeces. When using lu_client_seq on
134          * clients, this contains meta-sequence range. And for servers this
135          * contains super-sequence range.
136          */
137         struct lu_seq_range         lcs_space;
138
139         /* Seq related proc */
140         cfs_proc_dir_entry_t   *lcs_proc_dir;
141
142         /* This holds last allocated fid in last obtained seq */
143         struct lu_fid           lcs_fid;
144
145         /* LUSTRE_SEQ_METADATA or LUSTRE_SEQ_DATA */
146         enum lu_cli_type        lcs_type;
147
148         /*
149          * Service uuid, passed from MDT + seq name to form unique seq name to
150          * use it with procfs.
151          */
152         char                    lcs_name[80];
153
154         /*
155          * Sequence width, that is how many objects may be allocated in one
156          * sequence. Default value for it is LUSTRE_SEQ_MAX_WIDTH.
157          */
158         __u64                   lcs_width;
159
160         /* Seq-server for direct talking */
161         struct lu_server_seq   *lcs_srv;
162 };
163
164 /* server sequence manager interface */
165 struct lu_server_seq {
166         /* Available sequences space */
167         struct lu_seq_range         lss_space;
168
169         /*
170          * Device for server side seq manager needs (saving sequences to backing
171          * store).
172          */
173         struct dt_device       *lss_dev;
174
175         /* /seq file object device */
176         struct dt_object       *lss_obj;
177
178         /* Seq related proc */
179         cfs_proc_dir_entry_t   *lss_proc_dir;
180
181         /* LUSTRE_SEQ_SERVER or LUSTRE_SEQ_CONTROLLER */
182         enum lu_mgr_type       lss_type;
183
184         /* Client interafce to request controller */
185         struct lu_client_seq   *lss_cli;
186
187         /* Semaphore for protecting allocation */
188         struct semaphore        lss_sem;
189
190         /*
191          * Service uuid, passed from MDT + seq name to form unique seq name to
192          * use it with procfs.
193          */
194         char                    lss_name[80];
195
196         /*
197          * Allocation chunks for super and meta sequences. Default values are
198          * LUSTRE_SEQ_SUPER_WIDTH and LUSTRE_SEQ_META_WIDTH.
199          */
200         __u64                   lss_width;
201
202         /**
203          * Pointer to site object, required to access site fld.
204          */
205         struct md_site         *lss_site;
206 };
207
208 int seq_query(struct com_thread_info *info);
209
210 /* Server methods */
211 int seq_server_init(struct lu_server_seq *seq,
212                     struct dt_device *dev,
213                     const char *prefix,
214                     enum lu_mgr_type type,
215                     struct md_site *ls,
216                     const struct lu_env *env);
217
218 void seq_server_fini(struct lu_server_seq *seq,
219                      const struct lu_env *env);
220
221 int seq_server_alloc_super(struct lu_server_seq *seq,
222                            struct lu_seq_range *in,
223                            struct lu_seq_range *out,
224                            const struct lu_env *env);
225
226 int seq_server_alloc_meta(struct lu_server_seq *seq,
227                           struct lu_seq_range *in,
228                           struct lu_seq_range *out,
229                           const struct lu_env *env);
230
231 int seq_server_set_cli(struct lu_server_seq *seq,
232                        struct lu_client_seq *cli,
233                        const struct lu_env *env);
234
235 /* Client methods */
236 int seq_client_init(struct lu_client_seq *seq,
237                     struct obd_export *exp,
238                     enum lu_cli_type type,
239                     const char *prefix,
240                     struct lu_server_seq *srv);
241
242 void seq_client_fini(struct lu_client_seq *seq);
243
244 void seq_client_flush(struct lu_client_seq *seq);
245
246 int seq_client_alloc_fid(struct lu_client_seq *seq,
247                          struct lu_fid *fid);
248
249 /* Fids common stuff */
250 int fid_is_local(const struct lu_env *env,
251                  struct lu_site *site, const struct lu_fid *fid);
252
253 /* fid locking */
254
255 struct ldlm_namespace;
256
257 enum {
258         LUSTRE_RES_ID_SEQ_OFF = 0,
259         LUSTRE_RES_ID_OID_OFF = 1,
260         LUSTRE_RES_ID_VER_OFF = 2,
261         LUSTRE_RES_ID_HSH_OFF = 3
262 };
263
264 /*
265  * Build (DLM) resource name from fid.
266  */
267 static inline struct ldlm_res_id *
268 fid_build_reg_res_name(const struct lu_fid *f,
269                        struct ldlm_res_id *name)
270 {
271         memset(name, 0, sizeof *name);
272         name->name[LUSTRE_RES_ID_SEQ_OFF] = fid_seq(f);
273         name->name[LUSTRE_RES_ID_OID_OFF] = fid_oid(f);
274         name->name[LUSTRE_RES_ID_VER_OFF] = fid_ver(f);
275         return name;
276 }
277
278 /*
279  * Return true if resource is for object identified by fid.
280  */
281 static inline int fid_res_name_eq(const struct lu_fid *f,
282                                   const struct ldlm_res_id *name)
283 {
284         return
285                 name->name[LUSTRE_RES_ID_SEQ_OFF] == fid_seq(f) &&
286                 name->name[LUSTRE_RES_ID_OID_OFF] == fid_oid(f) &&
287                 name->name[LUSTRE_RES_ID_VER_OFF] == fid_ver(f);
288 }
289
290
291 static inline struct ldlm_res_id *
292 fid_build_pdo_res_name(const struct lu_fid *f,
293                        unsigned int hash,
294                        struct ldlm_res_id *name)
295 {
296         fid_build_reg_res_name(f, name);
297         name->name[LUSTRE_RES_ID_HSH_OFF] = hash;
298         return name;
299 }
300
301 static inline __u64 fid_flatten(const struct lu_fid *fid)
302 {
303         return (fid_seq(fid) - 1) * LUSTRE_SEQ_MAX_WIDTH + fid_oid(fid);
304 }
305
306 #define LUSTRE_SEQ_SRV_NAME "seq_srv"
307 #define LUSTRE_SEQ_CTL_NAME "seq_ctl"
308
309 /* Range common stuff */
310 static inline void range_cpu_to_le(struct lu_seq_range *dst, const struct lu_seq_range *src)
311 {
312         dst->lsr_start = cpu_to_le64(src->lsr_start);
313         dst->lsr_end = cpu_to_le64(src->lsr_end);
314         dst->lsr_mdt = cpu_to_le32(src->lsr_mdt);
315 }
316
317 static inline void range_le_to_cpu(struct lu_seq_range *dst, const struct lu_seq_range *src)
318 {
319         dst->lsr_start = le64_to_cpu(src->lsr_start);
320         dst->lsr_end = le64_to_cpu(src->lsr_end);
321         dst->lsr_mdt = le32_to_cpu(src->lsr_mdt);
322 }
323
324 static inline void range_cpu_to_be(struct lu_seq_range *dst, const struct lu_seq_range *src)
325 {
326         dst->lsr_start = cpu_to_be64(src->lsr_start);
327         dst->lsr_end = cpu_to_be64(src->lsr_end);
328         dst->lsr_mdt = cpu_to_be32(src->lsr_mdt);
329 }
330
331 static inline void range_be_to_cpu(struct lu_seq_range *dst, const struct lu_seq_range *src)
332 {
333         dst->lsr_start = be64_to_cpu(src->lsr_start);
334         dst->lsr_end = be64_to_cpu(src->lsr_end);
335         dst->lsr_mdt = be32_to_cpu(src->lsr_mdt);
336 }
337
338 #endif /* __LINUX_FID_H */