Whamcloud - gitweb
LU-1347 build: remove the vim/emacs modelines
[fs/lustre-release.git] / lustre / lmv / lmv_internal.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, Whamcloud, Inc.
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 #define LMV_MAX_TGT_COUNT 128
44
45 #define lmv_init_lock(lmv)   cfs_mutex_lock(&lmv->init_mutex);
46 #define lmv_init_unlock(lmv) cfs_mutex_unlock(&lmv->init_mutex);
47
48 #define LL_IT2STR(it)                                   \
49         ((it) ? ldlm_it2str((it)->it_op) : "0")
50
51 struct lmv_stripe {
52         /**
53          * Dir stripe fid.
54          */
55         struct lu_fid           ls_fid;
56         /**
57          * Cached home mds number for \a li_fid.
58          */
59         mdsno_t                 ls_mds;
60         /**
61          * Stripe object size.
62          */
63         unsigned long           ls_size;
64         /**
65          * Stripe flags.
66          */
67         int                     ls_flags;
68 };
69
70 #define O_FREEING               (1 << 0)
71
72 struct lmv_object {
73         /**
74          * Link to global objects list.
75          */
76         cfs_list_t              lo_list;
77         /**
78          * Sema for protecting fields.
79          */
80         cfs_mutex_t             lo_guard;
81         /**
82          * Object state like O_FREEING.
83          */
84         int                     lo_state;
85         /**
86          * Object ref counter.
87          */
88         cfs_atomic_t            lo_count;
89         /**
90          * Object master fid.
91          */
92         struct lu_fid           lo_fid;
93         /**
94          * Object hash type to find stripe by name.
95          */
96         __u32                   lo_hashtype;
97         /**
98          * Number of stripes.
99          */
100         int                     lo_objcount;
101         /**
102          * Array of sub-objs.
103          */
104         struct lmv_stripe      *lo_stripes;
105         /**
106          * Pointer to LMV obd.
107          */
108         struct obd_device      *lo_obd;
109 };
110
111 int lmv_object_setup(struct obd_device *obd);
112 void lmv_object_cleanup(struct obd_device *obd);
113
114 static inline void
115 lmv_object_lock(struct lmv_object *obj)
116 {
117         LASSERT(obj);
118         cfs_mutex_lock(&obj->lo_guard);
119 }
120
121 static inline void
122 lmv_object_unlock(struct lmv_object *obj)
123 {
124         LASSERT(obj);
125         cfs_mutex_unlock(&obj->lo_guard);
126 }
127
128 void lmv_object_add(struct lmv_object *obj);
129 void lmv_object_del(struct lmv_object *obj);
130
131 void lmv_object_put(struct lmv_object *obj);
132 void lmv_object_put_unlock(struct lmv_object *obj);
133 void lmv_object_free(struct lmv_object *obj);
134
135 struct lmv_object *lmv_object_get(struct lmv_object *obj);
136
137 struct lmv_object *lmv_object_find(struct obd_device *obd,
138                                    const struct lu_fid *fid);
139
140 struct lmv_object *lmv_object_find_lock(struct obd_device *obd,
141                                         const struct lu_fid *fid);
142
143 struct lmv_object *lmv_object_alloc(struct obd_device *obd,
144                                     const struct lu_fid *fid,
145                                     struct lmv_stripe_md *mea);
146
147 struct lmv_object *lmv_object_create(struct obd_export *exp,
148                                      const struct lu_fid *fid,
149                                      struct lmv_stripe_md *mea);
150
151 int lmv_object_delete(struct obd_export *exp,
152                       const struct lu_fid *fid);
153
154 int lmv_check_connect(struct obd_device *obd);
155
156 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
157                     void *lmm, int lmmsize, struct lookup_intent *it,
158                     int flags, struct ptlrpc_request **reqp,
159                     ldlm_blocking_callback cb_blocking,
160                     int extra_lock_flags);
161
162 int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
163                       void *lmm, int lmmsize, struct lookup_intent *it,
164                       int flags, struct ptlrpc_request **reqp,
165                       ldlm_blocking_callback cb_blocking,
166                       int extra_lock_flags);
167
168 int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
169                     void *lmm, int lmmsize, struct lookup_intent *it,
170                     int flags, struct ptlrpc_request **reqp,
171                     ldlm_blocking_callback cb_blocking,
172                     int extra_lock_flags);
173
174 int lmv_allocate_slaves(struct obd_device *obd, struct lu_fid *pid,
175                         struct md_op_data *op, struct lu_fid *fid);
176
177 int lmv_revalidate_slaves(struct obd_export *, struct ptlrpc_request **,
178                           const struct lu_fid *, struct lookup_intent *, int,
179                           ldlm_blocking_callback cb_blocking,
180                           int extra_lock_flags);
181
182 int lmv_handle_split(struct obd_export *, const struct lu_fid *);
183 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
184                      void *, int);
185 int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid,
186                    mdsno_t *mds);
187 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
188                     mdsno_t mds);
189 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
190                   struct md_op_data *op_data);
191
192 static inline struct lmv_stripe_md *lmv_get_mea(struct ptlrpc_request *req)
193 {
194         struct mdt_body         *body;
195         struct lmv_stripe_md    *mea;
196
197         LASSERT(req != NULL);
198
199         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
200
201         if (!body || !S_ISDIR(body->mode) || !body->eadatasize)
202                 return NULL;
203
204         mea = req_capsule_server_sized_get(&req->rq_pill, &RMF_MDT_MD,
205                                            body->eadatasize);
206         LASSERT(mea != NULL);
207
208         if (mea->mea_count == 0)
209                 return NULL;
210         if( mea->mea_magic != MEA_MAGIC_LAST_CHAR &&
211                 mea->mea_magic != MEA_MAGIC_ALL_CHARS &&
212                 mea->mea_magic != MEA_MAGIC_HASH_SEGMENT)
213                 return NULL;
214
215         return mea;
216 }
217
218 static inline int lmv_get_easize(struct lmv_obd *lmv)
219 {
220         return sizeof(struct lmv_stripe_md) +
221                 lmv->desc.ld_tgt_count *
222                 sizeof(struct lu_fid);
223 }
224
225 static inline struct lmv_tgt_desc *
226 lmv_get_target(struct lmv_obd *lmv, mdsno_t mds)
227 {
228         return &lmv->tgts[mds];
229 }
230
231 static inline struct lmv_tgt_desc *
232 lmv_find_target(struct lmv_obd *lmv, const struct lu_fid *fid)
233 {
234         mdsno_t mds = 0;
235         int rc;
236
237         if (lmv->desc.ld_tgt_count > 1) {
238                 rc = lmv_fld_lookup(lmv, fid, &mds);
239                 if (rc)
240                         return ERR_PTR(rc);
241         }
242
243         return lmv_get_target(lmv, mds);
244 }
245
246 /* lproc_lmv.c */
247 #ifdef LPROCFS
248 void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars);
249 #else
250 static inline void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars)
251 {
252         memset(lvars, 0, sizeof(*lvars));
253 }
254 #endif
255 extern struct file_operations lmv_proc_target_fops;
256
257 #endif