Whamcloud - gitweb
Branch HEAD
[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  *  Copyright (C) 2006 Cluster File Systems, Inc.
5  *   Author: Yury Umanets <umka@clusterfs.com>
6  *
7  *   This file is part of Lustre, http://www.lustre.org.
8  *
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.
12  *
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.
17  *
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.
21  *
22  */
23
24 #ifndef __LINUX_FID_H
25 #define __LINUX_FID_H
26
27 /*
28  * struct lu_fid
29  */
30 #include <lustre/lustre_idl.h>
31 #include <lustre_req_layout.h>
32 #include <lustre_mdt.h>
33
34 #include <libcfs/list.h>
35 #include <libcfs/kp30.h>
36
37 struct lu_site;
38 struct lu_context;
39
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;
44
45 enum {
46         /*
47          * This is how may FIDs may be allocated in one sequence. 16384 for
48          * now.
49          */
50         LUSTRE_SEQ_MAX_WIDTH = 0x0000000000004000ULL,
51
52         /*
53          * How many sequences may be allocate for meta-sequence (this is 128
54          * sequences).
55          */
56         /* changed to 16 to avoid overflow in test11 */
57         LUSTRE_SEQ_META_WIDTH = 0x0000000000000010ULL,
58
59         /*
60          * This is how many sequences may be in one super-sequence allocated to
61          * MDTs.
62          */
63         LUSTRE_SEQ_SUPER_WIDTH = (LUSTRE_SEQ_META_WIDTH * LUSTRE_SEQ_META_WIDTH)
64 };
65
66 enum lu_mgr_type {
67         LUSTRE_SEQ_SERVER,
68         LUSTRE_SEQ_CONTROLLER
69 };
70
71 enum lu_cli_type {
72         LUSTRE_SEQ_METADATA,
73         LUSTRE_SEQ_DATA
74 };
75
76 struct lu_server_seq;
77
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;
83
84         /*
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.
88          */
89         struct lu_range         lcs_space;
90
91         /* Seq related proc */
92         cfs_proc_dir_entry_t   *lcs_proc_dir;
93
94         /* This holds last allocated fid in last obtained seq */
95         struct lu_fid           lcs_fid;
96
97         /* LUSTRE_SEQ_METADATA or LUSTRE_SEQ_DATA */
98         enum lu_cli_type        lcs_type;
99
100         /*
101          * Service uuid, passed from MDT + seq name to form unique seq name to
102          * use it with procfs.
103          */
104         char                    lcs_name[80];
105
106         /*
107          * Sequence width, that is how many objects may be allocated in one
108          * sequence. Default value for it is LUSTRE_SEQ_MAX_WIDTH.
109          */
110         __u64                   lcs_width;
111
112         /* Seq-server for direct talking */
113         struct lu_server_seq   *lcs_srv;
114 };
115
116 /* server sequence manager interface */
117 struct lu_server_seq {
118         /* Available sequences space */
119         struct lu_range         lss_space;
120
121         /*
122          * Device for server side seq manager needs (saving sequences to backing
123          * store).
124          */
125         struct dt_device       *lss_dev;
126
127         /* /seq file object device */
128         struct dt_object       *lss_obj;
129
130         /* Seq related proc */
131         cfs_proc_dir_entry_t   *lss_proc_dir;
132
133         /* LUSTRE_SEQ_SERVER or LUSTRE_SEQ_CONTROLLER */
134         enum lu_mgr_type       lss_type;
135
136         /* Client interafce to request controller */
137         struct lu_client_seq   *lss_cli;
138
139         /* Semaphore for protecting allocation */
140         struct semaphore        lss_sem;
141
142         /*
143          * Service uuid, passed from MDT + seq name to form unique seq name to
144          * use it with procfs.
145          */
146         char                    lss_name[80];
147
148         /*
149          * Allocation chunks for super and meta sequences. Default values are
150          * LUSTRE_SEQ_SUPER_WIDTH and LUSTRE_SEQ_META_WIDTH.
151          */
152         __u64                   lss_width;
153 };
154
155 int seq_query(struct com_thread_info *info);
156
157 /* Server methods */
158 int seq_server_init(struct lu_server_seq *seq,
159                     struct dt_device *dev,
160                     const char *prefix,
161                     enum lu_mgr_type type,
162                     const struct lu_env *env);
163
164 void seq_server_fini(struct lu_server_seq *seq,
165                      const struct lu_env *env);
166
167 int seq_server_alloc_super(struct lu_server_seq *seq,
168                            struct lu_range *in,
169                            struct lu_range *out,
170                            const struct lu_env *env);
171
172 int seq_server_alloc_meta(struct lu_server_seq *seq,
173                           struct lu_range *in,
174                           struct lu_range *out,
175                           const struct lu_env *env);
176
177 int seq_server_set_cli(struct lu_server_seq *seq,
178                        struct lu_client_seq *cli,
179                        const struct lu_env *env);
180
181 /* Client methods */
182 int seq_client_init(struct lu_client_seq *seq,
183                     struct obd_export *exp,
184                     enum lu_cli_type type,
185                     const char *prefix,
186                     struct lu_server_seq *srv);
187
188 void seq_client_fini(struct lu_client_seq *seq);
189
190 void seq_client_flush(struct lu_client_seq *seq);
191
192 int seq_client_alloc_fid(struct lu_client_seq *seq,
193                          struct lu_fid *fid);
194
195 /* Fids common stuff */
196 int fid_is_local(struct lu_site *site, const struct lu_fid *fid);
197
198 /* fid locking */
199
200 struct ldlm_namespace;
201
202 enum {
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
207 };
208
209 /*
210  * Build (DLM) resource name from fid.
211  */
212 static inline struct ldlm_res_id *
213 fid_build_reg_res_name(const struct lu_fid *f,
214                        struct ldlm_res_id *name)
215 {
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);
220         return name;
221 }
222
223 /*
224  * Return true if resource is for object identified by fid.
225  */
226 static inline int fid_res_name_eq(const struct lu_fid *f,
227                                   const struct ldlm_res_id *name)
228 {
229         return
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);
233 }
234
235
236 static inline struct ldlm_res_id *
237 fid_build_pdo_res_name(const struct lu_fid *f,
238                        unsigned int hash,
239                        struct ldlm_res_id *name)
240 {
241         fid_build_reg_res_name(f, name);
242         name->name[LUSTRE_RES_ID_HSH_OFF] = hash;
243         return name;
244 }
245
246 static inline __u64 fid_flatten(const struct lu_fid *fid)
247 {
248         return (fid_seq(fid) - 1) * LUSTRE_SEQ_MAX_WIDTH + fid_oid(fid);
249 }
250
251 #define LUSTRE_SEQ_SRV_NAME "seq_srv"
252 #define LUSTRE_SEQ_CTL_NAME "seq_ctl"
253
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);
259
260 #endif /* __LINUX_FID_H */