Whamcloud - gitweb
ORNL-23 avoid unnecessary CMD lock contention in LMV
[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 (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * Copyright (c) 2011 Whamcloud, Inc.
34  */
35 /*
36  * This file is part of Lustre, http://www.lustre.org/
37  * Lustre is a trademark of Sun Microsystems, Inc.
38  */
39
40 #ifndef _LMV_INTERNAL_H_
41 #define _LMV_INTERNAL_H_
42
43 #include <lustre/lustre_idl.h>
44 #include <obd.h>
45
46 #define LMV_MAX_TGT_COUNT 128
47
48 #define lmv_init_lock(lmv)   cfs_down(&lmv->init_sem);
49 #define lmv_init_unlock(lmv) cfs_up(&lmv->init_sem);
50
51 #define LL_IT2STR(it)                                   \
52         ((it) ? ldlm_it2str((it)->it_op) : "0")
53
54 struct lmv_stripe {
55         /**
56          * Dir stripe fid.
57          */
58         struct lu_fid           ls_fid;
59         /**
60          * Cached home mds number for \a li_fid.
61          */
62         mdsno_t                 ls_mds;
63         /**
64          * Stripe object size.
65          */
66         unsigned long           ls_size;
67         /**
68          * Stripe flags.
69          */
70         int                     ls_flags;
71 };
72
73 #define O_FREEING               (1 << 0)
74
75 struct lmv_object {
76         /**
77          * Link to global objects list.
78          */
79         cfs_list_t              lo_list;
80         /**
81          * Sema for protecting fields.
82          */
83         cfs_semaphore_t         lo_guard;
84         /**
85          * Object state like O_FREEING.
86          */
87         int                     lo_state;
88         /**
89          * Object ref counter.
90          */
91         cfs_atomic_t            lo_count;
92         /**
93          * Object master fid.
94          */
95         struct lu_fid           lo_fid;
96         /**
97          * Object hash type to find stripe by name.
98          */
99         __u32                   lo_hashtype;
100         /**
101          * Number of stripes.
102          */
103         int                     lo_objcount;
104         /**
105          * Array of sub-objs.
106          */
107         struct lmv_stripe      *lo_stripes;
108         /**
109          * Pointer to LMV obd.
110          */
111         struct obd_device      *lo_obd;
112 };
113
114 int lmv_object_setup(struct obd_device *obd);
115 void lmv_object_cleanup(struct obd_device *obd);
116
117 static inline void
118 lmv_object_lock(struct lmv_object *obj)
119 {
120         LASSERT(obj);
121         cfs_down(&obj->lo_guard);
122 }
123
124 static inline void
125 lmv_object_unlock(struct lmv_object *obj)
126 {
127         LASSERT(obj);
128         cfs_up(&obj->lo_guard);
129 }
130
131 void lmv_object_add(struct lmv_object *obj);
132 void lmv_object_del(struct lmv_object *obj);
133
134 void lmv_object_put(struct lmv_object *obj);
135 void lmv_object_put_unlock(struct lmv_object *obj);
136 void lmv_object_free(struct lmv_object *obj);
137
138 struct lmv_object *lmv_object_get(struct lmv_object *obj);
139
140 struct lmv_object *lmv_object_find(struct obd_device *obd,
141                                    const struct lu_fid *fid);
142
143 struct lmv_object *lmv_object_find_lock(struct obd_device *obd,
144                                         const struct lu_fid *fid);
145
146 struct lmv_object *lmv_object_alloc(struct obd_device *obd,
147                                     const struct lu_fid *fid,
148                                     struct lmv_stripe_md *mea);
149
150 struct lmv_object *lmv_object_create(struct obd_export *exp,
151                                      const struct lu_fid *fid,
152                                      struct lmv_stripe_md *mea);
153
154 int lmv_object_delete(struct obd_export *exp,
155                       const struct lu_fid *fid);
156
157 int lmv_check_connect(struct obd_device *obd);
158
159 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
160                     void *lmm, int lmmsize, struct lookup_intent *it,
161                     int flags, struct ptlrpc_request **reqp,
162                     ldlm_blocking_callback cb_blocking,
163                     int extra_lock_flags);
164
165 int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
166                       void *lmm, int lmmsize, struct lookup_intent *it,
167                       int flags, struct ptlrpc_request **reqp,
168                       ldlm_blocking_callback cb_blocking,
169                       int extra_lock_flags);
170
171 int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
172                     void *lmm, int lmmsize, struct lookup_intent *it,
173                     int flags, struct ptlrpc_request **reqp,
174                     ldlm_blocking_callback cb_blocking,
175                     int extra_lock_flags);
176
177 int lmv_allocate_slaves(struct obd_device *obd, struct lu_fid *pid,
178                         struct md_op_data *op, struct lu_fid *fid);
179
180 int lmv_revalidate_slaves(struct obd_export *, struct ptlrpc_request **,
181                           const struct lu_fid *, struct lookup_intent *, int,
182                           ldlm_blocking_callback cb_blocking,
183                           int extra_lock_flags);
184
185 int lmv_handle_split(struct obd_export *, const struct lu_fid *);
186 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
187                      void *, int);
188 int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid,
189                    mdsno_t *mds);
190 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
191                     mdsno_t mds);
192 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
193                   struct md_op_data *op_data);
194
195 static inline struct lmv_stripe_md *lmv_get_mea(struct ptlrpc_request *req)
196 {
197         struct mdt_body         *body;
198         struct lmv_stripe_md    *mea;
199
200         LASSERT(req != NULL);
201
202         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
203
204         if (!body || !S_ISDIR(body->mode) || !body->eadatasize)
205                 return NULL;
206
207         mea = req_capsule_server_sized_get(&req->rq_pill, &RMF_MDT_MD,
208                                            body->eadatasize);
209         LASSERT(mea != NULL);
210
211         if (mea->mea_count == 0)
212                 return NULL;
213         if( mea->mea_magic != MEA_MAGIC_LAST_CHAR &&
214                 mea->mea_magic != MEA_MAGIC_ALL_CHARS &&
215                 mea->mea_magic != MEA_MAGIC_HASH_SEGMENT)
216                 return NULL;
217
218         return mea;
219 }
220
221 static inline int lmv_get_easize(struct lmv_obd *lmv)
222 {
223         return sizeof(struct lmv_stripe_md) +
224                 lmv->desc.ld_tgt_count *
225                 sizeof(struct lu_fid);
226 }
227
228 static inline struct lmv_tgt_desc *
229 lmv_get_target(struct lmv_obd *lmv, mdsno_t mds)
230 {
231         return &lmv->tgts[mds];
232 }
233
234 static inline struct lmv_tgt_desc *
235 lmv_find_target(struct lmv_obd *lmv, const struct lu_fid *fid)
236 {
237         mdsno_t mds = 0;
238         int rc;
239
240         if (lmv->desc.ld_tgt_count > 1) {
241                 rc = lmv_fld_lookup(lmv, fid, &mds);
242                 if (rc)
243                         return ERR_PTR(rc);
244         }
245
246         return lmv_get_target(lmv, mds);
247 }
248
249 /* lproc_lmv.c */
250 #ifdef LPROCFS
251 void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars);
252 #else
253 static inline void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars)
254 {
255         memset(lvars, 0, sizeof(*lvars));
256 }
257 #endif
258 extern struct file_operations lmv_proc_target_fops;
259
260 #endif