Whamcloud - gitweb
LU-807 utils: remove old service tags support
[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 (c) 2007, 2010, Oracle and/or its affiliates. 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 /** \defgroup fid fid
45  *
46  * @{
47  */
48
49 /*
50  * struct lu_fid
51  */
52 #include <libcfs/libcfs.h>
53 #include <lustre/lustre_idl.h>
54 #include <lustre_req_layout.h>
55 #include <lustre_mdt.h>
56
57
58 struct lu_site;
59 struct lu_context;
60
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;
67
68 enum {
69         /*
70          * This is how may FIDs may be allocated in one sequence(128k)
71          */
72         LUSTRE_SEQ_MAX_WIDTH = 0x0000000000020000ULL,
73
74         /*
75          * How many sequences to allocate to a client at once.
76          */
77         LUSTRE_SEQ_META_WIDTH = 0x0000000000000001ULL,
78
79          /*
80           * seq allocation pool size.
81           */
82         LUSTRE_SEQ_BATCH_WIDTH = LUSTRE_SEQ_META_WIDTH * 1000,
83
84         /*
85          * This is how many sequences may be in one super-sequence allocated to
86          * MDTs.
87          */
88         LUSTRE_SEQ_SUPER_WIDTH = ((1ULL << 30ULL) * LUSTRE_SEQ_META_WIDTH)
89 };
90
91 enum {
92         /** 2^6 FIDs for OI containers */
93         OSD_OI_FID_OID_BITS     = 6,
94         /** reserve enough FIDs in case we want more in the future */
95         OSD_OI_FID_OID_BITS_MAX = 10,
96 };
97
98 /** special OID for local objects */
99 enum local_oid {
100         /** \see fld_mod_init */
101         FLD_INDEX_OID           = 3UL,
102         /** \see fid_mod_init */
103         FID_SEQ_CTL_OID         = 4UL,
104         FID_SEQ_SRV_OID         = 5UL,
105         /** \see mdd_mod_init */
106         MDD_ROOT_INDEX_OID      = 6UL,
107         MDD_ORPHAN_OID          = 7UL,
108         MDD_LOV_OBJ_OID         = 8UL,
109         MDD_CAPA_KEYS_OID       = 9UL,
110         MDD_OBJECTS_OID         = 10UL,
111         /** \see mdt_mod_init */
112         MDT_LAST_RECV_OID       = 11UL,
113         /** \see osd_mod_init */
114         OSD_REM_OBJ_DIR_OID     = 12UL,
115         OSD_FS_ROOT_OID         = 13UL,
116         ACCT_USER_OID           = 15UL,
117         ACCT_GROUP_OID          = 16UL,
118         OFD_LAST_RECV_OID       = 19UL,
119         OFD_GROUP0_LAST_OID     = 20UL,
120         OFD_GROUP4K_LAST_OID    = 20UL+4096,
121         OFD_LAST_GROUP_OID      = 4117UL,
122         LLOG_CATALOGS_OID       = 4118UL,
123         MGS_CONFIGS_OID         = 4119UL,
124         OFD_HEALTH_CHECK_OID    = 4120UL,
125
126         /** first OID for first OI fid */
127         OSD_OI_FID_OID_FIRST    = 5000UL,
128         /** reserve enough in case we want to have more in the future */
129         OSD_OI_FID_OID_MAX      = OSD_OI_FID_OID_FIRST +
130                                   (1UL << OSD_OI_FID_OID_BITS_MAX),
131 };
132
133 static inline void lu_local_obj_fid(struct lu_fid *fid, __u32 oid)
134 {
135         fid->f_seq = FID_SEQ_LOCAL_FILE;
136         fid->f_oid = oid;
137         fid->f_ver = 0;
138 }
139
140 enum lu_mgr_type {
141         LUSTRE_SEQ_SERVER,
142         LUSTRE_SEQ_CONTROLLER
143 };
144
145 enum lu_cli_type {
146         LUSTRE_SEQ_METADATA,
147         LUSTRE_SEQ_DATA
148 };
149
150 struct lu_server_seq;
151
152 /* Client sequence manager interface. */
153 struct lu_client_seq {
154         /* Sequence-controller export. */
155         struct obd_export      *lcs_exp;
156         cfs_semaphore_t         lcs_sem;
157
158         /*
159          * Range of allowed for allocation sequeces. When using lu_client_seq on
160          * clients, this contains meta-sequence range. And for servers this
161          * contains super-sequence range.
162          */
163         struct lu_seq_range         lcs_space;
164
165         /* Seq related proc */
166         cfs_proc_dir_entry_t   *lcs_proc_dir;
167
168         /* This holds last allocated fid in last obtained seq */
169         struct lu_fid           lcs_fid;
170
171         /* LUSTRE_SEQ_METADATA or LUSTRE_SEQ_DATA */
172         enum lu_cli_type        lcs_type;
173
174         /*
175          * Service uuid, passed from MDT + seq name to form unique seq name to
176          * use it with procfs.
177          */
178         char                    lcs_name[80];
179
180         /*
181          * Sequence width, that is how many objects may be allocated in one
182          * sequence. Default value for it is LUSTRE_SEQ_MAX_WIDTH.
183          */
184         __u64                   lcs_width;
185
186         /* Seq-server for direct talking */
187         struct lu_server_seq   *lcs_srv;
188
189         /* wait queue for fid allocation and update indicator */
190         cfs_waitq_t             lcs_waitq;
191         int                     lcs_update;
192 };
193
194 /* server sequence manager interface */
195 struct lu_server_seq {
196         /* Available sequences space */
197         struct lu_seq_range         lss_space;
198
199         /* keeps highwater in lsr_end for seq allocation algorithm */
200         struct lu_seq_range         lss_lowater_set;
201         struct lu_seq_range         lss_hiwater_set;
202
203         /*
204          * Device for server side seq manager needs (saving sequences to backing
205          * store).
206          */
207         struct dt_device       *lss_dev;
208
209         /* /seq file object device */
210         struct dt_object       *lss_obj;
211
212         /* Seq related proc */
213         cfs_proc_dir_entry_t   *lss_proc_dir;
214
215         /* LUSTRE_SEQ_SERVER or LUSTRE_SEQ_CONTROLLER */
216         enum lu_mgr_type       lss_type;
217
218         /* Client interafce to request controller */
219         struct lu_client_seq   *lss_cli;
220
221         /* Semaphore for protecting allocation */
222         cfs_semaphore_t         lss_sem;
223
224         /*
225          * Service uuid, passed from MDT + seq name to form unique seq name to
226          * use it with procfs.
227          */
228         char                    lss_name[80];
229
230         /*
231          * Allocation chunks for super and meta sequences. Default values are
232          * LUSTRE_SEQ_SUPER_WIDTH and LUSTRE_SEQ_META_WIDTH.
233          */
234         __u64                   lss_width;
235
236         /*
237          * minimum lss_alloc_set size that should be allocated from
238          * lss_space
239          */
240         __u64                   lss_set_width;
241
242         /* sync is needed for update operation */
243         __u32                   lss_need_sync;
244         /**
245          * Pointer to site object, required to access site fld.
246          */
247         struct md_site         *lss_site;
248 };
249
250 int seq_query(struct com_thread_info *info);
251
252 /* Server methods */
253 int seq_server_init(struct lu_server_seq *seq,
254                     struct dt_device *dev,
255                     const char *prefix,
256                     enum lu_mgr_type type,
257                     struct md_site *ls,
258                     const struct lu_env *env);
259
260 void seq_server_fini(struct lu_server_seq *seq,
261                      const struct lu_env *env);
262
263 int seq_server_alloc_super(struct lu_server_seq *seq,
264                            struct lu_seq_range *out,
265                            const struct lu_env *env);
266
267 int seq_server_alloc_meta(struct lu_server_seq *seq,
268                           struct lu_seq_range *out,
269                           const struct lu_env *env);
270
271 int seq_server_set_cli(struct lu_server_seq *seq,
272                        struct lu_client_seq *cli,
273                        const struct lu_env *env);
274
275 /* Client methods */
276 int seq_client_init(struct lu_client_seq *seq,
277                     struct obd_export *exp,
278                     enum lu_cli_type type,
279                     const char *prefix,
280                     struct lu_server_seq *srv);
281
282 void seq_client_fini(struct lu_client_seq *seq);
283
284 void seq_client_flush(struct lu_client_seq *seq);
285
286 int seq_client_alloc_fid(const struct lu_env *env, struct lu_client_seq *seq,
287                          struct lu_fid *fid);
288 int seq_client_get_seq(const struct lu_env *env, struct lu_client_seq *seq,
289                        seqno_t *seqnr);
290
291 /* Fids common stuff */
292 int fid_is_local(const struct lu_env *env,
293                  struct lu_site *site, const struct lu_fid *fid);
294
295 /* fid locking */
296
297 struct ldlm_namespace;
298
299 enum {
300         LUSTRE_RES_ID_SEQ_OFF = 0,
301         LUSTRE_RES_ID_OID_OFF = 1,
302         LUSTRE_RES_ID_VER_OFF = 2,
303         LUSTRE_RES_ID_HSH_OFF = 3
304 };
305
306 /*
307  * Build (DLM) resource name from fid.
308  */
309 static inline struct ldlm_res_id *
310 fid_build_reg_res_name(const struct lu_fid *f,
311                        struct ldlm_res_id *name)
312 {
313         memset(name, 0, sizeof *name);
314         name->name[LUSTRE_RES_ID_SEQ_OFF] = fid_seq(f);
315         name->name[LUSTRE_RES_ID_OID_OFF] = fid_oid(f);
316         name->name[LUSTRE_RES_ID_VER_OFF] = fid_ver(f);
317         return name;
318 }
319
320 /*
321  * Return true if resource is for object identified by fid.
322  */
323 static inline int fid_res_name_eq(const struct lu_fid *f,
324                                   const struct ldlm_res_id *name)
325 {
326         return
327                 name->name[LUSTRE_RES_ID_SEQ_OFF] == fid_seq(f) &&
328                 name->name[LUSTRE_RES_ID_OID_OFF] == fid_oid(f) &&
329                 name->name[LUSTRE_RES_ID_VER_OFF] == fid_ver(f);
330 }
331
332
333 static inline struct ldlm_res_id *
334 fid_build_pdo_res_name(const struct lu_fid *f,
335                        unsigned int hash,
336                        struct ldlm_res_id *name)
337 {
338         fid_build_reg_res_name(f, name);
339         name->name[LUSTRE_RES_ID_HSH_OFF] = hash;
340         return name;
341 }
342
343
344 /**
345  * Flatten 128-bit FID values into a 64-bit value for use as an inode number.
346  * For non-IGIF FIDs this starts just over 2^32, and continues without
347  * conflict until 2^64, at which point we wrap the high 24 bits of the SEQ
348  * into the range where there may not be many OID values in use, to minimize
349  * the risk of conflict.
350  *
351  * Suppose LUSTRE_SEQ_MAX_WIDTH less than (1 << 24) which is currently true,
352  * the time between re-used inode numbers is very long - 2^40 SEQ numbers,
353  * or about 2^40 client mounts, if clients create less than 2^24 files/mount.
354  */
355 static inline __u64 fid_flatten(const struct lu_fid *fid)
356 {
357         __u64 ino;
358         __u64 seq;
359
360         if (fid_is_igif(fid)) {
361                 ino = lu_igif_ino(fid);
362                 RETURN(ino);
363         }
364
365         seq = fid_seq(fid);
366
367         ino = (seq << 24) + ((seq >> 24) & 0xffffff0000ULL) + fid_oid(fid);
368
369         RETURN(ino ? ino : fid_oid(fid));
370 }
371
372 static inline __u32 fid_hash(const struct lu_fid *f, int bits)
373 {
374         /* all objects with same id and different versions will belong to same
375          * collisions list. */
376         return cfs_hash_long(fid_flatten(f), bits);
377 }
378
379 /**
380  * map fid to 32 bit value for ino on 32bit systems. */
381 static inline __u32 fid_flatten32(const struct lu_fid *fid)
382 {
383         __u32 ino;
384         __u64 seq;
385
386         if (fid_is_igif(fid)) {
387                 ino = lu_igif_ino(fid);
388                 RETURN(ino);
389         }
390
391         seq = fid_seq(fid) - FID_SEQ_START;
392
393         /* Map the high bits of the OID into higher bits of the inode number so
394          * that inodes generated at about the same time have a reduced chance
395          * of collisions. This will give a period of 2^12 = 1024 unique clients
396          * (from SEQ) and up to min(LUSTRE_SEQ_MAX_WIDTH, 2^20) = 128k objects
397          * (from OID), or up to 128M inodes without collisions for new files. */
398         ino = ((seq & 0x000fffffULL) << 12) + ((seq >> 8) & 0xfffff000) +
399                (seq >> (64 - (40-8)) & 0xffffff00) +
400                (fid_oid(fid) & 0xff000fff) + ((fid_oid(fid) & 0x00fff000) << 8);
401
402         RETURN(ino ? ino : fid_oid(fid));
403 }
404
405 #define LUSTRE_SEQ_SRV_NAME "seq_srv"
406 #define LUSTRE_SEQ_CTL_NAME "seq_ctl"
407
408 /* Range common stuff */
409 static inline void range_cpu_to_le(struct lu_seq_range *dst, const struct lu_seq_range *src)
410 {
411         dst->lsr_start = cpu_to_le64(src->lsr_start);
412         dst->lsr_end = cpu_to_le64(src->lsr_end);
413         dst->lsr_index = cpu_to_le32(src->lsr_index);
414         dst->lsr_flags = cpu_to_le32(src->lsr_flags);
415 }
416
417 static inline void range_le_to_cpu(struct lu_seq_range *dst, const struct lu_seq_range *src)
418 {
419         dst->lsr_start = le64_to_cpu(src->lsr_start);
420         dst->lsr_end = le64_to_cpu(src->lsr_end);
421         dst->lsr_index = le32_to_cpu(src->lsr_index);
422         dst->lsr_flags = le32_to_cpu(src->lsr_flags);
423 }
424
425 static inline void range_cpu_to_be(struct lu_seq_range *dst, const struct lu_seq_range *src)
426 {
427         dst->lsr_start = cpu_to_be64(src->lsr_start);
428         dst->lsr_end = cpu_to_be64(src->lsr_end);
429         dst->lsr_index = cpu_to_be32(src->lsr_index);
430         dst->lsr_flags = cpu_to_be32(src->lsr_flags);
431 }
432
433 static inline void range_be_to_cpu(struct lu_seq_range *dst, const struct lu_seq_range *src)
434 {
435         dst->lsr_start = be64_to_cpu(src->lsr_start);
436         dst->lsr_end = be64_to_cpu(src->lsr_end);
437         dst->lsr_index = be32_to_cpu(src->lsr_index);
438         dst->lsr_flags = be32_to_cpu(src->lsr_flags);
439 }
440
441 /** @} fid */
442
443 #endif /* __LINUX_FID_H */