Whamcloud - gitweb
The variable, not the literal. Thanks mjmac.
[fs/lustre-release.git] / lustre / lov / lov_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2003 Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  */
9
10 #ifndef LOV_INTERNAL_H
11 #define LOV_INTERNAL_H
12
13 #include <lustre/lustre_user.h>
14
15 struct lov_lock_handles {
16         struct portals_handle   llh_handle;
17         atomic_t                llh_refcount;
18         int                     llh_stripe_count;
19         struct lustre_handle    llh_handles[0];
20 };
21
22 struct lov_request {
23         struct list_head         rq_link;
24         struct ldlm_extent       rq_extent;
25         int                      rq_idx;        /* index in lov->tgts array */
26         int                      rq_gen;        /* lov target generation # */
27         int                      rq_stripe;     /* stripe number */
28         int                      rq_complete;
29         int                      rq_rc;
30         int                      rq_buflen;     /* length of sub_md */
31         struct obdo             *rq_oa;
32         struct lov_stripe_md    *rq_md;
33         obd_count                rq_oabufs;
34         obd_count                rq_pgaidx;
35 };
36
37 struct lov_request_set {
38         atomic_t                 set_refcount;
39         struct obd_export       *set_exp;
40         int                      set_count;
41         int                      set_completes;
42         int                      set_success;
43         struct llog_cookie      *set_cookies;
44         int                      set_cookie_sent;
45         struct lov_stripe_md    *set_md;
46         struct obdo             *set_oa;
47         struct obd_trans_info   *set_oti;
48         obd_count                set_oabufs;
49         struct brw_page         *set_pga;
50         struct lov_lock_handles *set_lockh;
51         struct list_head         set_list;
52 };
53
54 #define LAP_MAGIC 8200
55
56 #define LOV_MAX_TGT_COUNT 1024
57
58 #define lov_tgts_lock(lov)      spin_lock(&lov->lov_lock);
59 #define lov_tgts_unlock(lov)    spin_unlock(&lov->lov_lock);
60
61 static inline void
62 lov_tgt_set_flags(struct lov_obd *lov, struct lov_tgt_desc *tgt, int flags)
63 {
64         lov_tgts_lock(lov);
65         if ((flags & LTD_ACTIVE) && ((tgt->ltd_flags & LTD_ACTIVE) == 0))
66                 lov->desc.ld_active_tgt_count++;
67         tgt->ltd_flags |= flags;
68         lov_tgts_unlock(lov);
69 }
70
71 static inline void
72 lov_tgt_clear_flags(struct lov_obd *lov, struct lov_tgt_desc *tgt, int flags)
73 {
74         ENTRY;
75
76         lov_tgts_lock(lov);
77         if ((flags & LTD_ACTIVE) && (tgt->ltd_flags & LTD_ACTIVE))
78                 lov->desc.ld_active_tgt_count--;
79         tgt->ltd_flags &= ~flags;
80         lov_tgts_unlock(lov);
81         EXIT;
82 }
83
84 static inline int
85 lov_tgt_changed(struct lov_obd *lov, struct lov_oinfo *loi)
86 {
87         int changed;
88
89         lov_tgts_lock(lov);
90         changed = lov->tgts[loi->loi_ost_idx].ltd_gen != loi->loi_ost_gen;
91         lov_tgts_unlock(lov);
92
93         return changed;
94 }
95
96 static inline int
97 lov_tgt_active(struct lov_obd *lov, struct lov_tgt_desc *tgt, int gen)
98 {
99         int rc = 0;
100         lov_tgts_lock(lov);
101
102         if (((gen == 0) || (gen == tgt->ltd_gen)) &&
103             ((tgt->ltd_flags &(LTD_ACTIVE|LTD_DEL_PENDING)) == LTD_ACTIVE)) {
104                 tgt->ltd_refcount++;
105                 rc = 1;
106         }
107
108         lov_tgts_unlock(lov);
109         return rc;
110 }
111
112 static inline int
113 lov_tgt_ready(struct lov_obd *lov, struct lov_tgt_desc *tgt, int gen)
114 {
115         int rc = 0;
116
117         lov_tgts_lock(lov);
118
119         if (((gen == 0) || (gen == tgt->ltd_gen)) &&
120             (tgt->ltd_flags & LTD_ACTIVE)) {
121                 tgt->ltd_refcount++;
122                 rc = 1;
123         }
124
125         lov_tgts_unlock(lov);
126         return rc;
127 }
128
129 static inline int
130 lov_tgt_valid(struct lov_obd *lov, struct lov_tgt_desc *tgt, int gen)
131 {
132         int rc = 0;
133         lov_tgts_lock(lov);
134
135         if (((gen == 0) || (gen == tgt->ltd_gen)) && (tgt->ltd_exp != NULL)) {
136                 tgt->ltd_refcount++;
137                 rc = 1;
138         }
139
140         lov_tgts_unlock(lov);
141         return rc;
142 }
143
144 static inline void
145 lov_tgt_decref(struct lov_obd *lov, struct lov_tgt_desc *tgt)
146 {
147         int do_wakeup = 0;
148
149         lov_tgts_lock(lov);
150
151         if ((--tgt->ltd_refcount == 0) && (tgt->ltd_flags & LTD_DEL_PENDING)) {
152                 do_wakeup = 1;
153         } 
154
155         lov_tgts_unlock(lov);
156         if (do_wakeup)
157                 wake_up(&lov->lov_tgt_waitq);
158 }
159
160 struct lov_async_page {
161         int                             lap_magic;
162         int                             lap_stripe;
163         obd_off                         lap_sub_offset;
164         void                            *lap_sub_cookie;
165         struct obd_async_page_ops       *lap_caller_ops;
166         void                            *lap_caller_data;
167         obd_id                          lap_loi_id;
168 };
169
170 #define LAP_FROM_COOKIE(c)                                                      \
171         (LASSERT(((struct lov_async_page *)(c))->lap_magic == LAP_MAGIC),       \
172          (struct lov_async_page *)(c))
173
174 static inline void lov_llh_addref(void *llhp)
175 {
176         struct lov_lock_handles *llh = llhp;
177         atomic_inc(&llh->llh_refcount);
178         CDEBUG(D_INFO, "GETting llh %p : new refcount %d\n", llh,
179                atomic_read(&llh->llh_refcount));
180 }
181
182 static inline struct lov_lock_handles *lov_llh_new(struct lov_stripe_md *lsm)
183 {
184         struct lov_lock_handles *llh;
185
186         OBD_ALLOC(llh, sizeof *llh +
187                   sizeof(*llh->llh_handles) * lsm->lsm_stripe_count);
188         if (llh == NULL) 
189                 return NULL;
190         atomic_set(&llh->llh_refcount, 2);
191         llh->llh_stripe_count = lsm->lsm_stripe_count;
192         INIT_LIST_HEAD(&llh->llh_handle.h_link);
193         class_handle_hash(&llh->llh_handle, lov_llh_addref);
194         return llh;
195 }
196
197 static inline struct lov_lock_handles *
198 lov_handle2llh(struct lustre_handle *handle)
199 {
200         LASSERT(handle != NULL);
201         return(class_handle2object(handle->cookie));
202 }
203
204 static inline void lov_llh_put(struct lov_lock_handles *llh)
205 {
206         CDEBUG(D_INFO, "PUTting llh %p : new refcount %d\n", llh,
207                atomic_read(&llh->llh_refcount) - 1);
208         LASSERT(atomic_read(&llh->llh_refcount) > 0 &&
209                 atomic_read(&llh->llh_refcount) < 0x5a5a);
210         if (atomic_dec_and_test(&llh->llh_refcount)) {
211                 class_handle_unhash(&llh->llh_handle);
212                 LASSERT(list_empty(&llh->llh_handle.h_link));
213                 OBD_FREE(llh, sizeof *llh +
214                          sizeof(*llh->llh_handles) * llh->llh_stripe_count);
215         }
216 }
217
218 /* lov_merge.c */
219 void lov_merge_attrs(struct obdo *tgt, struct obdo *src, obd_flags valid,
220                      struct lov_stripe_md *lsm, int stripeno, int *set);
221
222 int lov_adjust_kms(struct obd_export *exp, struct lov_stripe_md *lsm,
223                    obd_off size, int shrink);
224 /* lov_offset.c */
225 obd_size lov_stripe_size(struct lov_stripe_md *lsm, obd_size ost_size, 
226                          int stripeno);
227 int lov_stripe_offset(struct lov_stripe_md *lsm, obd_off lov_off,
228                       int stripeno, obd_off *obd_off);
229 obd_off lov_size_to_stripe(struct lov_stripe_md *lsm, obd_off file_size,
230                            int stripeno);
231 int lov_stripe_intersects(struct lov_stripe_md *lsm, int stripeno,
232                           obd_off start, obd_off end,
233                           obd_off *obd_start, obd_off *obd_end);
234 int lov_stripe_number(struct lov_stripe_md *lsm, obd_off lov_off);
235
236 /* lov_qos.c */
237 void qos_shrink_lsm(struct lov_request_set *set);
238 int qos_prep_create(struct lov_obd *lov, struct lov_request_set *set, 
239                     int newea);
240
241 /* lov_request.c */
242 void lov_set_add_req(struct lov_request *req, struct lov_request_set *set);
243 int lov_update_common_set(struct lov_request_set *set, 
244                           struct lov_request *req, int rc);
245 int lov_prep_create_set(struct obd_export *exp, struct lov_stripe_md **ea, 
246                         struct obdo *src_oa, struct obd_trans_info *oti,
247                         struct lov_request_set **reqset);
248 int lov_update_create_set(struct lov_request_set *set,
249                           struct lov_request *req, int rc);
250 int lov_fini_create_set(struct lov_request_set *set, struct lov_stripe_md **ea);
251 int lov_prep_brw_set(struct obd_export *exp, struct obdo *src_oa, 
252                      struct lov_stripe_md *lsm, obd_count oa_bufs,
253                      struct brw_page *pga, struct obd_trans_info *oti,
254                      struct lov_request_set **reqset);
255 int lov_fini_brw_set(struct lov_request_set *set);
256 int lov_prep_getattr_set(struct obd_export *exp, struct obdo *src_oa, 
257                          struct lov_stripe_md *lsm, 
258                          struct lov_request_set **reqset);
259 int lov_fini_getattr_set(struct lov_request_set *set);
260 int lov_prep_destroy_set(struct obd_export *exp, struct obdo *src_oa,
261                          struct lov_stripe_md *lsm, 
262                          struct obd_trans_info *oti, 
263                          struct lov_request_set **reqset);
264 int lov_update_destroy_set(struct lov_request_set *set,
265                            struct lov_request *req, int rc);
266 int lov_fini_destroy_set(struct lov_request_set *set);
267 int lov_prep_setattr_set(struct obd_export *exp, struct obdo *src_oa,
268                          struct lov_stripe_md *lsm, struct obd_trans_info *oti,
269                          struct lov_request_set **reqset);
270 int lov_fini_setattr_set(struct lov_request_set *set);
271 int lov_prep_punch_set(struct obd_export *exp, struct obdo *src_oa,
272                        struct lov_stripe_md *lsm, obd_off start,
273                        obd_off end, struct obd_trans_info *oti,
274                        struct lov_request_set **reqset);
275 int lov_update_punch_set(struct lov_request_set *set, struct lov_request *req,
276                          int rc);
277 int lov_fini_punch_set(struct lov_request_set *set);
278 int lov_prep_sync_set(struct obd_export *exp, struct obdo *src_oa,
279                       struct lov_stripe_md *lsm, obd_off start,
280                       obd_off end, struct lov_request_set **reqset);
281 int lov_fini_sync_set(struct lov_request_set *set);
282 int lov_prep_enqueue_set(struct obd_export *exp, struct lov_stripe_md *lsm, 
283                          ldlm_policy_data_t *policy, __u32 mode,
284                          struct lustre_handle *lockh,
285                          struct lov_request_set **reqset);
286 int lov_update_enqueue_set(struct lov_request_set *set, 
287                            struct lov_request *req, int rc, int flags);
288 int lov_fini_enqueue_set(struct lov_request_set *set, __u32 mode);
289 int lov_prep_match_set(struct obd_export *exp, struct lov_stripe_md *lsm,
290                        ldlm_policy_data_t *policy, __u32 mode,
291                        struct lustre_handle *lockh,
292                        struct lov_request_set **reqset);
293 int lov_update_match_set(struct lov_request_set *set, struct lov_request *req,
294                          int rc);
295 int lov_fini_match_set(struct lov_request_set *set, __u32 mode, int flags); 
296 int lov_prep_cancel_set(struct obd_export *exp, struct lov_stripe_md *lsm,
297                         __u32 mode, struct lustre_handle *lockh,
298                         struct lov_request_set **reqset);
299 int lov_fini_cancel_set(struct lov_request_set *set);
300
301 /* lov_obd.c */
302 int lov_get_stripecnt(struct lov_obd *lov, int stripe_count);
303 int lov_alloc_memmd(struct lov_stripe_md **lsmp, int stripe_count, int pattern);
304 void lov_free_memmd(struct lov_stripe_md **lsmp);
305
306 /* lov_log.c */
307 int lov_llog_init(struct obd_device *, struct obd_llogs *,
308                   struct obd_device *, int, struct llog_catid *);
309 int lov_llog_finish(struct obd_device *, struct obd_llogs *, int);
310
311 /* lov_pack.c */
312 int lov_packmd(struct obd_export *exp, struct lov_mds_md **lmm,
313                struct lov_stripe_md *lsm);
314 int lov_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
315                  struct lov_mds_md *lmm, int lmm_bytes);
316 int lov_setstripe(struct obd_export *exp,
317                   struct lov_stripe_md **lsmp, struct lov_user_md *lump);
318 int lov_setea(struct obd_export *exp, struct lov_stripe_md **lsmp,
319               struct lov_user_md *lump);
320 int lov_getstripe(struct obd_export *exp,
321                   struct lov_stripe_md *lsm, struct lov_user_md *lump);
322
323 /* lproc_lov.c */
324 extern struct file_operations lov_proc_target_fops;
325
326 #endif