Whamcloud - gitweb
b=14149
[fs/lustre-release.git] / lustre / lmv / lmv_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2002, 2003, 2004, 2005, 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 #ifndef _LMV_INTERNAL_H_
23 #define _LMV_INTERNAL_H_
24
25 #include <lustre/lustre_idl.h>
26 #include <obd.h>
27
28 #ifndef __KERNEL__
29 /* XXX: dirty hack, needs to be fixed more clever way. */
30 struct qstr {
31         const char *name;
32         size_t      len;
33         unsigned    hashval;
34 };
35 #endif
36
37 #define LMV_MAX_TGT_COUNT 128
38
39 #define lmv_init_lock(lmv)   down(&lmv->init_sem);
40 #define lmv_init_unlock(lmv) up(&lmv->init_sem);
41
42 #define LL_IT2STR(it)                                   \
43         ((it) ? ldlm_it2str((it)->it_op) : "0")
44
45 struct lmv_inode {
46         struct lu_fid      li_fid;        /* id of dirobj */
47         mdsno_t            li_mds;        /* cached mdsno where @li_fid lives */
48         unsigned long      li_size;       /* slave size value */
49         int                li_flags;
50 };
51
52 #define O_FREEING          (1 << 0)
53
54 struct lmv_obj {
55         struct list_head   lo_list;
56         struct semaphore   lo_guard;
57         int                lo_state;      /* object state. */
58         atomic_t           lo_count;      /* ref counter. */
59         struct lu_fid      lo_fid;        /* master id of dir */
60         void              *lo_update;     /* bitmap of status (up-to-date) */
61         __u32              lo_hashtype;
62         int                lo_objcount;   /* number of slaves */
63         struct lmv_inode  *lo_inodes;     /* array of sub-objs */
64         struct obd_device *lo_obd;        /* pointer to LMV itself */
65 };
66
67 int lmv_obj_setup(struct obd_device *obd);
68 void lmv_obj_cleanup(struct obd_device *obd);
69
70 static inline void
71 lmv_obj_lock(struct lmv_obj *obj)
72 {
73         LASSERT(obj);
74         down(&obj->lo_guard);
75 }
76
77 static inline void
78 lmv_obj_unlock(struct lmv_obj *obj)
79 {
80         LASSERT(obj);
81         up(&obj->lo_guard);
82 }
83
84 void lmv_obj_add(struct lmv_obj *obj);
85 void lmv_obj_del(struct lmv_obj *obj);
86
87 void lmv_obj_put(struct lmv_obj *obj);
88 void lmv_obj_free(struct lmv_obj *obj);
89
90 struct lmv_obj *lmv_obj_get(struct lmv_obj *obj);
91
92 struct lmv_obj *lmv_obj_grab(struct obd_device *obd,
93                              const struct lu_fid *fid);
94
95 struct lmv_obj *lmv_obj_alloc(struct obd_device *obd,
96                               const struct lu_fid *fid,
97                               struct lmv_stripe_md *mea);
98
99 struct lmv_obj *lmv_obj_create(struct obd_export *exp,
100                                const struct lu_fid *fid,
101                                struct lmv_stripe_md *mea);
102
103 int lmv_obj_delete(struct obd_export *exp,
104                    const struct lu_fid *fid);
105
106 int lmv_check_connect(struct obd_device *obd);
107
108 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
109                     void *lmm, int lmmsize, struct lookup_intent *it,
110                     int flags, struct ptlrpc_request **reqp,
111                     ldlm_blocking_callback cb_blocking,
112                     int extra_lock_flags);
113
114 int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
115                       void *lmm, int lmmsize, struct lookup_intent *it,
116                       int flags, struct ptlrpc_request **reqp,
117                       ldlm_blocking_callback cb_blocking,
118                       int extra_lock_flags);
119
120 int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
121                     void *lmm, int lmmsize, struct lookup_intent *it,
122                     int flags, struct ptlrpc_request **reqp,
123                     ldlm_blocking_callback cb_blocking,
124                     int extra_lock_flags);
125
126 int lmv_intent_getattr(struct obd_export *exp, struct md_op_data *op_data,
127                        void *lmm, int lmmsize, struct lookup_intent *it,
128                        int flags, struct ptlrpc_request **reqp,
129                        ldlm_blocking_callback cb_blocking,
130                        int extra_lock_flags);
131
132 int lmv_revalidate_slaves(struct obd_export *, struct ptlrpc_request **,
133                           const struct lu_fid *, struct lookup_intent *, int,
134                           ldlm_blocking_callback cb_blocking,
135                           int extra_lock_flags);
136
137 int lmv_handle_split(struct obd_export *, const struct lu_fid *);
138 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
139                      void *, int);
140 int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid,
141                    mdsno_t *mds);
142 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
143                     mdsno_t mds);
144 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
145                   struct md_op_data *op_data);
146 int lmv_alloc_slave_fids(struct obd_device *obd, struct lu_fid *pid,
147                          struct md_op_data *op, struct lu_fid *fid);
148
149 static inline struct lmv_stripe_md * 
150 lmv_get_mea(struct ptlrpc_request *req)
151 {
152         struct mdt_body *body;
153         struct lmv_stripe_md *mea;
154
155         LASSERT(req);
156
157         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
158
159         if (!body || !S_ISDIR(body->mode) || !body->eadatasize)
160                 return NULL;
161
162         mea = req_capsule_server_sized_get(&req->rq_pill, &RMF_MDT_MD,
163                                            body->eadatasize);
164         LASSERT(mea != NULL);
165
166         if (mea->mea_count == 0)
167                 return NULL;
168         if( mea->mea_magic != MEA_MAGIC_LAST_CHAR &&
169                 mea->mea_magic != MEA_MAGIC_ALL_CHARS &&
170                 mea->mea_magic != MEA_MAGIC_HASH_SEGMENT)
171                 return NULL;
172         
173         return mea;
174 }
175
176 static inline int lmv_get_easize(struct lmv_obd *lmv)
177 {
178         return sizeof(struct lmv_stripe_md) +
179                 lmv->desc.ld_tgt_count *
180                 sizeof(struct lu_fid);
181 }
182
183 static inline struct lmv_tgt_desc *
184 lmv_get_target(struct lmv_obd *lmv, mdsno_t mds)
185 {
186         return &lmv->tgts[mds];
187 }
188
189 static inline struct obd_export *
190 lmv_get_export(struct lmv_obd *lmv, mdsno_t mds)
191 {
192         return lmv_get_target(lmv, mds)->ltd_exp;
193 }
194
195 static inline struct lmv_tgt_desc *
196 lmv_find_target(struct lmv_obd *lmv, const struct lu_fid *fid)
197 {
198         mdsno_t mds;
199         int rc;
200         
201         rc = lmv_fld_lookup(lmv, fid, &mds);
202         if (rc)
203                 return ERR_PTR(rc);
204
205         return lmv_get_target(lmv, mds);
206 }
207
208 static inline struct obd_export *
209 lmv_find_export(struct lmv_obd *lmv, const struct lu_fid *fid)
210 {
211         struct lmv_tgt_desc *tgt = lmv_find_target(lmv, fid);
212         if (IS_ERR(tgt))
213                 return (struct obd_export *)tgt;
214         return tgt->ltd_exp;
215 }
216
217 static inline void lmv_update_body(struct mdt_body *body, 
218                                    struct lmv_inode *lino)
219 {
220         /* update object size */
221         body->size += lino->li_size;
222 }
223
224 /* lproc_lmv.c */
225 #ifdef LPROCFS
226 void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars);
227 #else
228 static inline void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars)
229 {
230         memset(lvars, 0, sizeof(*lvars));
231 }
232 #endif
233 extern struct file_operations lmv_proc_target_fops;
234
235 #endif
236