Whamcloud - gitweb
On a server, a file system object is uniquely identified by a fid, which is
[fs/lustre-release.git] / lustre / cmm / cmm_internal.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/cmm/cmm_internal.h
37  *
38  * Lustre Cluster Metadata Manager (cmm)
39  *
40  * Author: Mike Pershin <tappro@clusterfs.com>
41  */
42
43 #ifndef _CMM_INTERNAL_H
44 #define _CMM_INTERNAL_H
45
46 #if defined(__KERNEL__)
47
48 #include <obd.h>
49 #include <lustre_fld.h>
50 #include <md_object.h>
51 #include <lustre_acl.h>
52
53
54 struct cmm_device {
55         struct md_device        cmm_md_dev;
56         /* device flags, taken from enum cmm_flags */
57         __u32                   cmm_flags;
58         /* underlaying device in MDS stack, usually MDD */
59         struct md_device       *cmm_child;
60         /* FLD client to talk to FLD */
61         struct lu_client_fld   *cmm_fld;
62         /* other MD servers in cluster */
63         mdsno_t                 cmm_local_num;
64         __u32                   cmm_tgt_count;
65         struct list_head        cmm_targets;
66         spinlock_t              cmm_tgt_guard;
67         cfs_proc_dir_entry_t   *cmm_proc_entry;
68         struct lprocfs_stats   *cmm_stats;
69 };
70
71 enum cmm_flags {
72         /*
73          * Device initialization complete.
74          */
75         CMM_INITIALIZED = 1 << 0
76 };
77
78 static inline struct md_device_operations *cmm_child_ops(struct cmm_device *d)
79 {
80         return (d->cmm_child->md_ops);
81 }
82
83 static inline struct cmm_device *md2cmm_dev(struct md_device *m)
84 {
85         return container_of0(m, struct cmm_device, cmm_md_dev);
86 }
87
88 static inline struct cmm_device *lu2cmm_dev(struct lu_device *d)
89 {
90         return container_of0(d, struct cmm_device, cmm_md_dev.md_lu_dev);
91 }
92
93 static inline struct lu_device *cmm2lu_dev(struct cmm_device *d)
94 {
95         return (&d->cmm_md_dev.md_lu_dev);
96 }
97
98 #ifdef HAVE_SPLIT_SUPPORT
99 enum cmm_split_state {
100         CMM_SPLIT_UNKNOWN,
101         CMM_SPLIT_NONE,
102         CMM_SPLIT_NEEDED,
103         CMM_SPLIT_DONE,
104         CMM_SPLIT_DENIED
105 };
106 #endif
107
108 struct cmm_object {
109         struct md_object cmo_obj;
110 };
111
112 /* local CMM object */
113 struct cml_object {
114         struct cmm_object    cmm_obj;
115 #ifdef HAVE_SPLIT_SUPPORT
116         /* split state of object (for dirs only)*/
117         enum cmm_split_state clo_split;
118 #endif
119 };
120
121 /* remote CMM object */
122 struct cmr_object {
123         struct cmm_object cmm_obj;
124         /* mds number where object is placed */
125         mdsno_t           cmo_num;
126 };
127
128 enum {
129         CMM_SPLIT_PAGE_COUNT = 1
130 };
131
132 struct cmm_thread_info {
133         struct md_attr        cmi_ma;
134         struct lu_buf         cmi_buf;
135         struct lu_fid         cmi_fid; /* used for le/cpu conversions */
136         struct lu_rdpg        cmi_rdpg;
137         /* pointers to pages for readpage. */
138         struct page          *cmi_pages[CMM_SPLIT_PAGE_COUNT];
139         struct md_op_spec     cmi_spec;
140         struct lmv_stripe_md  cmi_lmv;
141         char                  cmi_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
142
143         /* Ops object filename */
144         struct lu_name        cti_name;
145 };
146
147 static inline struct cmm_device *cmm_obj2dev(struct cmm_object *c)
148 {
149         return (md2cmm_dev(md_obj2dev(&c->cmo_obj)));
150 }
151
152 static inline struct cmm_object *lu2cmm_obj(struct lu_object *o)
153 {
154         //LASSERT(lu_device_is_cmm(o->lo_dev));
155         return container_of0(o, struct cmm_object, cmo_obj.mo_lu);
156 }
157
158 /* get cmm object from md_object */
159 static inline struct cmm_object *md2cmm_obj(struct md_object *o)
160 {
161         return container_of0(o, struct cmm_object, cmo_obj);
162 }
163 /* get lower-layer object */
164 static inline struct md_object *cmm2child_obj(struct cmm_object *o)
165 {
166         return (o ? lu2md(lu_object_next(&o->cmo_obj.mo_lu)) : NULL);
167 }
168
169 static inline struct lu_fid* cmm2fid(struct cmm_object *obj)
170 {
171        return &(obj->cmo_obj.mo_lu.lo_header->loh_fid);
172 }
173
174 struct cmm_thread_info *cmm_env_info(const struct lu_env *env);
175
176 /* cmm_object.c */
177 struct lu_object *cmm_object_alloc(const struct lu_env *env,
178                                    const struct lu_object_header *hdr,
179                                    struct lu_device *);
180
181 /*
182  * local CMM object operations. cml_...
183  */
184 static inline struct cml_object *lu2cml_obj(struct lu_object *o)
185 {
186         return container_of0(o, struct cml_object, cmm_obj.cmo_obj.mo_lu);
187 }
188 static inline struct cml_object *md2cml_obj(struct md_object *mo)
189 {
190         return container_of0(mo, struct cml_object, cmm_obj.cmo_obj);
191 }
192 static inline struct cml_object *cmm2cml_obj(struct cmm_object *co)
193 {
194         return container_of0(co, struct cml_object, cmm_obj);
195 }
196
197 int cmm_upcall(const struct lu_env *env, struct md_device *md,
198                enum md_upcall_event ev);
199
200 #ifdef HAVE_SPLIT_SUPPORT
201
202 #define CMM_MD_SIZE(stripes)  (sizeof(struct lmv_stripe_md) +  \
203                                (stripes) * sizeof(struct lu_fid))
204
205 /* cmm_split.c */
206 static inline struct lu_buf *cmm_buf_get(const struct lu_env *env,
207                                          void *area, ssize_t len)
208 {
209         struct lu_buf *buf;
210
211         buf = &cmm_env_info(env)->cmi_buf;
212         buf->lb_buf = area;
213         buf->lb_len = len;
214         return buf;
215 }
216
217 int cmm_split_check(const struct lu_env *env, struct md_object *mp,
218                     const char *name);
219
220 int cmm_split_expect(const struct lu_env *env, struct md_object *mo,
221                      struct md_attr *ma, int *split);
222
223 int cmm_split_dir(const struct lu_env *env, struct md_object *mo);
224
225 int cmm_split_access(const struct lu_env *env, struct md_object *mo,
226                      mdl_mode_t lm);
227 #endif
228
229 int cmm_fld_lookup(struct cmm_device *cm, const struct lu_fid *fid,
230                    mdsno_t *mds, const struct lu_env *env);
231
232 int cmm_procfs_init(struct cmm_device *cmm, const char *name);
233 int cmm_procfs_fini(struct cmm_device *cmm);
234
235 void cmm_lprocfs_time_start(const struct lu_env *env);
236 void cmm_lprocfs_time_end(const struct lu_env *env, struct cmm_device *cmm,
237                           int idx);
238
239 enum {
240         LPROC_CMM_SPLIT_CHECK,
241         LPROC_CMM_SPLIT,
242         LPROC_CMM_LOOKUP,
243         LPROC_CMM_CREATE,
244         LPROC_CMM_NR
245 };
246
247 #endif /* __KERNEL__ */
248 #endif /* _CMM_INTERNAL_H */