Whamcloud - gitweb
Branch HEAD
[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  *  lustre/cmm/cmm_internal.h
5  *  Lustre Cluster Metadata Manager (cmm)
6  *
7  *  Copyright (C) 2006 Cluster File Systems, Inc.
8  *   Author: Mike Pershin <tappro@clusterfs.com>
9  *
10  *   This file is part of the Lustre file system, http://www.lustre.org
11  *   Lustre is a trademark of Cluster File Systems, Inc.
12  *
13  *   You may have signed or agreed to another license before downloading
14  *   this software.  If so, you are bound by the terms and conditions
15  *   of that agreement, and the following does not apply to you.  See the
16  *   LICENSE file included with this distribution for more information.
17  *
18  *   If you did not agree to a different license, then this copy of Lustre
19  *   is open source software; you can redistribute it and/or modify it
20  *   under the terms of version 2 of the GNU General Public License as
21  *   published by the Free Software Foundation.
22  *
23  *   In either case, Lustre is distributed in the hope that it will be
24  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  *   license text for more details.
27  */
28
29 #ifndef _CMM_INTERNAL_H
30 #define _CMM_INTERNAL_H
31
32 #if defined(__KERNEL__)
33
34 #include <obd.h>
35 #include <lustre_fld.h>
36 #include <md_object.h>
37 #include <linux/lustre_acl.h>
38
39
40 struct cmm_device {
41         struct md_device        cmm_md_dev;
42         /* device flags, taken from enum cmm_flags */
43         __u32                   cmm_flags;
44         /* underlaying device in MDS stack, usually MDD */
45         struct md_device       *cmm_child;
46         /* FLD client to talk to FLD */
47         struct lu_client_fld   *cmm_fld;
48         /* other MD servers in cluster */
49         mdsno_t                 cmm_local_num;
50         __u32                   cmm_tgt_count;
51         struct list_head        cmm_targets;
52         spinlock_t              cmm_tgt_guard;
53         cfs_proc_dir_entry_t   *cmm_proc_entry;
54         struct lprocfs_stats   *cmm_stats;
55 };
56
57 enum cmm_flags {
58         /*
59          * Device initialization complete.
60          */
61         CMM_INITIALIZED = 1 << 0
62 };
63
64 static inline struct md_device_operations *cmm_child_ops(struct cmm_device *d)
65 {
66         return (d->cmm_child->md_ops);
67 }
68
69 static inline struct cmm_device *md2cmm_dev(struct md_device *m)
70 {
71         return container_of0(m, struct cmm_device, cmm_md_dev);
72 }
73
74 static inline struct cmm_device *lu2cmm_dev(struct lu_device *d)
75 {
76         return container_of0(d, struct cmm_device, cmm_md_dev.md_lu_dev);
77 }
78
79 static inline struct lu_device *cmm2lu_dev(struct cmm_device *d)
80 {
81         return (&d->cmm_md_dev.md_lu_dev);
82 }
83
84 #ifdef HAVE_SPLIT_SUPPORT
85 enum cmm_split_state {
86         CMM_SPLIT_UNKNOWN,
87         CMM_SPLIT_NONE,
88         CMM_SPLIT_NEEDED,
89         CMM_SPLIT_DONE,
90         CMM_SPLIT_DENIED
91 };
92 #endif
93
94 struct cmm_object {
95         struct md_object cmo_obj;
96 };
97
98 /* local CMM object */
99 struct cml_object {
100         struct cmm_object    cmm_obj;
101 #ifdef HAVE_SPLIT_SUPPORT
102         /* split state of object (for dirs only)*/
103         enum cmm_split_state clo_split;
104 #endif
105 };
106
107 /* remote CMM object */
108 struct cmr_object {
109         struct cmm_object cmm_obj;
110         /* mds number where object is placed */
111         mdsno_t           cmo_num;
112 };
113
114 enum {
115         CMM_SPLIT_PAGE_COUNT = 1
116 };
117
118 struct cmm_thread_info {
119         struct md_attr        cmi_ma;
120         struct lu_buf         cmi_buf;
121         struct lu_fid         cmi_fid; /* used for le/cpu conversions */
122         struct lu_rdpg        cmi_rdpg;
123         /* pointers to pages for readpage. */
124         struct page          *cmi_pages[CMM_SPLIT_PAGE_COUNT];
125         struct md_op_spec     cmi_spec;
126         struct lmv_stripe_md  cmi_lmv;
127         char                  cmi_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
128
129         /* Ops object filename */
130         struct lu_name        cti_name;
131 };
132
133 static inline struct cmm_device *cmm_obj2dev(struct cmm_object *c)
134 {
135         return (md2cmm_dev(md_obj2dev(&c->cmo_obj)));
136 }
137
138 static inline struct cmm_object *lu2cmm_obj(struct lu_object *o)
139 {
140         //LASSERT(lu_device_is_cmm(o->lo_dev));
141         return container_of0(o, struct cmm_object, cmo_obj.mo_lu);
142 }
143
144 /* get cmm object from md_object */
145 static inline struct cmm_object *md2cmm_obj(struct md_object *o)
146 {
147         return container_of0(o, struct cmm_object, cmo_obj);
148 }
149 /* get lower-layer object */
150 static inline struct md_object *cmm2child_obj(struct cmm_object *o)
151 {
152         return (o ? lu2md(lu_object_next(&o->cmo_obj.mo_lu)) : NULL);
153 }
154
155 static inline struct lu_fid* cmm2fid(struct cmm_object *obj)
156 {
157        return &(obj->cmo_obj.mo_lu.lo_header->loh_fid);
158 }
159
160 struct cmm_thread_info *cmm_env_info(const struct lu_env *env);
161
162 /* cmm_object.c */
163 struct lu_object *cmm_object_alloc(const struct lu_env *env,
164                                    const struct lu_object_header *hdr,
165                                    struct lu_device *);
166
167 /*
168  * local CMM object operations. cml_...
169  */
170 static inline struct cml_object *lu2cml_obj(struct lu_object *o)
171 {
172         return container_of0(o, struct cml_object, cmm_obj.cmo_obj.mo_lu);
173 }
174 static inline struct cml_object *md2cml_obj(struct md_object *mo)
175 {
176         return container_of0(mo, struct cml_object, cmm_obj.cmo_obj);
177 }
178 static inline struct cml_object *cmm2cml_obj(struct cmm_object *co)
179 {
180         return container_of0(co, struct cml_object, cmm_obj);
181 }
182
183 int cmm_upcall(const struct lu_env *env, struct md_device *md,
184                enum md_upcall_event ev);
185
186 #ifdef HAVE_SPLIT_SUPPORT
187
188 #define CMM_MD_SIZE(stripes)  (sizeof(struct lmv_stripe_md) +  \
189                                (stripes) * sizeof(struct lu_fid))
190
191 /* cmm_split.c */
192 static inline struct lu_buf *cmm_buf_get(const struct lu_env *env,
193                                          void *area, ssize_t len)
194 {
195         struct lu_buf *buf;
196
197         buf = &cmm_env_info(env)->cmi_buf;
198         buf->lb_buf = area;
199         buf->lb_len = len;
200         return buf;
201 }
202
203 int cmm_split_check(const struct lu_env *env, struct md_object *mp,
204                     const char *name);
205
206 int cmm_split_expect(const struct lu_env *env, struct md_object *mo,
207                      struct md_attr *ma, int *split);
208
209 int cmm_split_dir(const struct lu_env *env, struct md_object *mo);
210
211 int cmm_split_access(const struct lu_env *env, struct md_object *mo,
212                      mdl_mode_t lm);
213 #endif
214
215 int cmm_fld_lookup(struct cmm_device *cm, const struct lu_fid *fid,
216                    mdsno_t *mds, const struct lu_env *env);
217
218 int cmm_procfs_init(struct cmm_device *cmm, const char *name);
219 int cmm_procfs_fini(struct cmm_device *cmm);
220
221 void cmm_lprocfs_time_start(const struct lu_env *env);
222 void cmm_lprocfs_time_end(const struct lu_env *env, struct cmm_device *cmm,
223                           int idx);
224
225 enum {
226         LPROC_CMM_SPLIT_CHECK,
227         LPROC_CMM_SPLIT,
228         LPROC_CMM_LOOKUP,
229         LPROC_CMM_CREATE,
230         LPROC_CMM_NR
231 };
232
233 #endif /* __KERNEL__ */
234 #endif /* _CMM_INTERNAL_H */
235