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