Whamcloud - gitweb
1c278c959d0d6f28fe3e823ae5b5fca6da0c1ae6
[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  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #ifndef __LINUX_FID_H
24 #define __LINUX_FID_H
25
26 /*
27  * struct lu_fid
28  */
29 #include <lustre/lustre_idl.h>
30
31 #include <libcfs/list.h>
32 #include <libcfs/kp30.h>
33
34 struct lu_site;
35 struct lu_context;
36
37 /* whole sequences space range and zero range definitions */
38 extern const struct lu_range LUSTRE_SEQ_SPACE_RANGE;
39 extern const struct lu_range LUSTRE_SEQ_ZERO_RANGE;
40
41 enum {
42         /* this is how may FIDs may be allocated in one sequence. 16384 for now */
43         LUSTRE_SEQ_MAX_WIDTH = 0x0000000000004000ULL,
44
45         /* how many sequences may be allocate for meta-sequence (this is 128
46          * sequences). */
47         LUSTRE_SEQ_META_WIDTH = 0x0000000000000080ULL,
48
49         /* this is how many sequences (128 * 128) may be in one
50          * super-sequence allocated to MDTs. */
51         LUSTRE_SEQ_SUPER_WIDTH = (LUSTRE_SEQ_META_WIDTH * LUSTRE_SEQ_META_WIDTH)
52 };
53
54 enum lu_mgr_type {
55         LUSTRE_SEQ_SERVER,
56         LUSTRE_SEQ_CONTROLLER
57 };
58
59 enum lu_cli_type {
60         LUSTRE_SEQ_METADATA,
61         LUSTRE_SEQ_DATA
62 };
63
64 /* client sequence manager interface */
65 struct lu_client_seq {
66         /* sequence-controller export. */
67         struct obd_export      *lcs_exp;
68         struct semaphore        lcs_sem;
69
70         /* range of allowed for allocation sequeces. When using lu_client_seq on
71          * clients, this contains meta-sequence range. And for servers this
72          * contains super-sequence range. */
73         struct lu_range         lcs_range;
74
75         /* seq related proc */
76         cfs_proc_dir_entry_t   *lcs_proc_dir;
77
78         /* this holds last allocated fid in last obtained seq */
79         struct lu_fid           lcs_fid;
80
81         /* LUSTRE_SEQ_METADATA or LUSTRE_SEQ_DATA */
82         enum lu_cli_type        lcs_type;
83
84         /* service uuid, passed from MDT + seq name to form unique seq name to
85          * use it with procfs. */
86         char                    lcs_name[80];
87
88         /* sequence width, that is how many objects may be allocated in one
89          * sequence. Default value for it is LUSTRE_SEQ_MAX_WIDTH. */
90         __u64                   lcs_width;
91 };
92
93 #ifdef __KERNEL__
94 /* server sequence manager interface */
95 struct lu_server_seq {
96         /* available sequence space */
97         struct lu_range         lss_space;
98
99         /* super-sequence range, all super-sequences for other servers are
100          * allocated from it. */
101         struct lu_range         lss_super;
102
103         /* device for server side seq manager needs (saving sequences to backing
104          * store). */
105         struct dt_device       *lss_dev;
106
107         /* /seq file object device */
108         struct dt_object       *lss_obj;
109
110         /* seq related proc */
111         cfs_proc_dir_entry_t   *lss_proc_entry;
112         cfs_proc_dir_entry_t   *lss_proc_dir;
113
114         /* LUSTRE_SEQ_SERVER or LUSTRE_SEQ_CONTROLLER */
115         enum lu_mgr_type       lss_type;
116
117         /* server side seq service for metadata stack */
118         struct ptlrpc_service  *lss_md_service;
119
120         /* server side seq service for data stack */
121         struct ptlrpc_service  *lss_dt_service;
122
123         /* client interafce to request controller */
124         struct lu_client_seq   *lss_cli;
125
126         /* semaphore for protecting allocation */
127         struct semaphore        lss_sem;
128
129         /* service uuid, passed from MDT + seq name to form unique seq name to
130          * use it with procfs. */
131         char                    lss_name[80];
132
133         /* allocation chunks for super and meta sequences. Default values are
134          * LUSTRE_SEQ_SUPER_WIDTH and LUSTRE_SEQ_META_WIDTH. */
135         __u64                   lss_super_width;
136         __u64                   lss_meta_width;
137 };
138 #endif
139
140 #ifdef __KERNEL__
141
142 int seq_server_init(struct lu_server_seq *seq,
143                     struct dt_device *dev,
144                     const char *uuid,
145                     enum lu_mgr_type type,
146                     const struct lu_context *ctx);
147
148 void seq_server_fini(struct lu_server_seq *seq,
149                      const struct lu_context *ctx);
150
151 int seq_server_set_cli(struct lu_server_seq *seq,
152                        struct lu_client_seq *cli,
153                        const struct lu_context *ctx);
154 #endif
155
156 int seq_client_init(struct lu_client_seq *seq,
157                     const char *uuid,
158                     struct obd_export *exp,
159                     enum lu_cli_type type);
160
161 void seq_client_fini(struct lu_client_seq *seq);
162
163 int seq_client_alloc_super(struct lu_client_seq *seq);
164 int seq_client_alloc_meta(struct lu_client_seq *seq);
165
166 int seq_client_alloc_seq(struct lu_client_seq *seq,
167                          seqno_t *seqnr);
168 int seq_client_alloc_fid(struct lu_client_seq *seq,
169                          struct lu_fid *fid);
170
171 /* Fids common stuff */
172 int fid_is_local(struct lu_site *site, const struct lu_fid *fid);
173 void fid_to_le(struct lu_fid *dst, const struct lu_fid *src);
174 void fid_to_be(struct lu_fid *dst, const struct lu_fid *src);
175
176 /* Range common stuff */
177 void range_to_le(struct lu_range *dst, const struct lu_range *src);
178 void range_to_be(struct lu_range *dst, const struct lu_range *src);
179
180 #endif /* __LINUX_OBD_CLASS_H */