1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2003 Cluster File Systems, Inc.
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
10 #ifndef LOV_INTERNAL_H
11 #define LOV_INTERNAL_H
13 #include <lustre/lustre_user.h>
15 struct lov_lock_handles {
16 struct portals_handle llh_handle;
17 atomic_t llh_refcount;
19 struct lustre_handle llh_handles[0];
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 */
30 int rq_buflen; /* length of sub_md */
32 struct lov_stripe_md *rq_md;
37 struct lov_request_set {
38 atomic_t set_refcount;
39 struct obd_export *set_exp;
43 struct llog_cookie *set_cookies;
45 struct lov_stripe_md *set_md;
47 struct obd_trans_info *set_oti;
49 struct brw_page *set_pga;
50 struct lov_lock_handles *set_lockh;
51 struct list_head set_list;
54 #define LAP_MAGIC 8200
56 #define LOV_MAX_TGT_COUNT 1024
58 #define lov_tgts_lock(lov) spin_lock(&lov->lov_lock);
59 #define lov_tgts_unlock(lov) spin_unlock(&lov->lov_lock);
62 lov_tgt_set_flags(struct lov_obd *lov, struct lov_tgt_desc *tgt, int flags)
65 if ((flags & LTD_ACTIVE) && ((tgt->ltd_flags & LTD_ACTIVE) == 0))
66 lov->desc.ld_active_tgt_count++;
67 tgt->ltd_flags |= flags;
72 lov_tgt_clear_flags(struct lov_obd *lov, struct lov_tgt_desc *tgt, int flags)
77 if ((flags & LTD_ACTIVE) && (tgt->ltd_flags & LTD_ACTIVE))
78 lov->desc.ld_active_tgt_count--;
79 tgt->ltd_flags &= ~flags;
85 lov_tgt_changed(struct lov_obd *lov, struct lov_oinfo *loi)
90 changed = lov->tgts[loi->loi_ost_idx].ltd_gen != loi->loi_ost_gen;
97 lov_tgt_active(struct lov_obd *lov, struct lov_tgt_desc *tgt, int gen)
102 if (((gen == 0) || (gen == tgt->ltd_gen)) &&
103 ((tgt->ltd_flags &(LTD_ACTIVE|LTD_DEL_PENDING)) == LTD_ACTIVE)) {
108 lov_tgts_unlock(lov);
113 lov_tgt_ready(struct lov_obd *lov, struct lov_tgt_desc *tgt, int gen)
119 if (((gen == 0) || (gen == tgt->ltd_gen)) &&
120 (tgt->ltd_flags & LTD_ACTIVE)) {
125 lov_tgts_unlock(lov);
130 lov_tgt_decref(struct lov_obd *lov, struct lov_tgt_desc *tgt)
136 if ((--tgt->ltd_refcount == 0) && (tgt->ltd_flags & LTD_DEL_PENDING)) {
140 lov_tgts_unlock(lov);
142 wake_up(&lov->lov_tgt_waitq);
146 lov_tgt_pending(struct lov_obd *lov, struct lov_tgt_desc *tgt, int gen)
151 if (((gen == 0) || (gen == tgt->ltd_gen)) &&
152 (tgt->ltd_flags &(LTD_ACTIVE|LTD_DEL_PENDING)) == LTD_DEL_PENDING) {
157 lov_tgts_unlock(lov);
161 struct lov_async_page {
164 obd_off lap_sub_offset;
165 void *lap_sub_cookie;
166 struct obd_async_page_ops *lap_caller_ops;
167 void *lap_caller_data;
171 #define LAP_FROM_COOKIE(c) \
172 (LASSERT(((struct lov_async_page *)(c))->lap_magic == LAP_MAGIC), \
173 (struct lov_async_page *)(c))
175 static inline void lov_llh_addref(void *llhp)
177 struct lov_lock_handles *llh = llhp;
178 atomic_inc(&llh->llh_refcount);
179 CDEBUG(D_INFO, "GETting llh %p : new refcount %d\n", llh,
180 atomic_read(&llh->llh_refcount));
183 static inline struct lov_lock_handles *lov_llh_new(struct lov_stripe_md *lsm)
185 struct lov_lock_handles *llh;
187 OBD_ALLOC(llh, sizeof *llh +
188 sizeof(*llh->llh_handles) * lsm->lsm_stripe_count);
191 atomic_set(&llh->llh_refcount, 2);
192 llh->llh_stripe_count = lsm->lsm_stripe_count;
193 INIT_LIST_HEAD(&llh->llh_handle.h_link);
194 class_handle_hash(&llh->llh_handle, lov_llh_addref);
198 static inline struct lov_lock_handles *
199 lov_handle2llh(struct lustre_handle *handle)
201 LASSERT(handle != NULL);
202 return(class_handle2object(handle->cookie));
205 static inline void lov_llh_put(struct lov_lock_handles *llh)
207 CDEBUG(D_INFO, "PUTting llh %p : new refcount %d\n", llh,
208 atomic_read(&llh->llh_refcount) - 1);
209 LASSERT(atomic_read(&llh->llh_refcount) > 0 &&
210 atomic_read(&llh->llh_refcount) < 0x5a5a);
211 if (atomic_dec_and_test(&llh->llh_refcount)) {
212 class_handle_unhash(&llh->llh_handle);
213 LASSERT(list_empty(&llh->llh_handle.h_link));
214 OBD_FREE(llh, sizeof *llh +
215 sizeof(*llh->llh_handles) * llh->llh_stripe_count);
220 void lov_merge_attrs(struct obdo *tgt, struct obdo *src, obd_flags valid,
221 struct lov_stripe_md *lsm, int stripeno, int *set);
223 int lov_adjust_kms(struct obd_export *exp, struct lov_stripe_md *lsm,
224 obd_off size, int shrink);
226 obd_size lov_stripe_size(struct lov_stripe_md *lsm, obd_size ost_size,
228 int lov_stripe_offset(struct lov_stripe_md *lsm, obd_off lov_off,
229 int stripeno, obd_off *obd_off);
230 obd_off lov_size_to_stripe(struct lov_stripe_md *lsm, obd_off file_size,
232 int lov_stripe_intersects(struct lov_stripe_md *lsm, int stripeno,
233 obd_off start, obd_off end,
234 obd_off *obd_start, obd_off *obd_end);
235 int lov_stripe_number(struct lov_stripe_md *lsm, obd_off lov_off);
238 void qos_shrink_lsm(struct lov_request_set *set);
239 int qos_prep_create(struct lov_obd *lov, struct lov_request_set *set,
243 void lov_set_add_req(struct lov_request *req, struct lov_request_set *set);
244 int lov_update_common_set(struct lov_request_set *set,
245 struct lov_request *req, int rc);
246 int lov_prep_create_set(struct obd_export *exp, struct lov_stripe_md **ea,
247 struct obdo *src_oa, struct obd_trans_info *oti,
248 struct lov_request_set **reqset);
249 int lov_update_create_set(struct lov_request_set *set,
250 struct lov_request *req, int rc);
251 int lov_fini_create_set(struct lov_request_set *set, struct lov_stripe_md **ea);
252 int lov_prep_brw_set(struct obd_export *exp, struct obdo *src_oa,
253 struct lov_stripe_md *lsm, obd_count oa_bufs,
254 struct brw_page *pga, struct obd_trans_info *oti,
255 struct lov_request_set **reqset);
256 int lov_fini_brw_set(struct lov_request_set *set);
257 int lov_prep_getattr_set(struct obd_export *exp, struct obdo *src_oa,
258 struct lov_stripe_md *lsm,
259 struct lov_request_set **reqset);
260 int lov_fini_getattr_set(struct lov_request_set *set);
261 int lov_prep_destroy_set(struct obd_export *exp, struct obdo *src_oa,
262 struct lov_stripe_md *lsm,
263 struct obd_trans_info *oti,
264 struct lov_request_set **reqset);
265 int lov_update_destroy_set(struct lov_request_set *set,
266 struct lov_request *req, int rc);
267 int lov_fini_destroy_set(struct lov_request_set *set);
268 int lov_prep_setattr_set(struct obd_export *exp, struct obdo *src_oa,
269 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
270 struct lov_request_set **reqset);
271 int lov_fini_setattr_set(struct lov_request_set *set);
272 int lov_prep_punch_set(struct obd_export *exp, struct obdo *src_oa,
273 struct lov_stripe_md *lsm, obd_off start,
274 obd_off end, struct obd_trans_info *oti,
275 struct lov_request_set **reqset);
276 int lov_update_punch_set(struct lov_request_set *set, struct lov_request *req,
278 int lov_fini_punch_set(struct lov_request_set *set);
279 int lov_prep_sync_set(struct obd_export *exp, struct obdo *src_oa,
280 struct lov_stripe_md *lsm, obd_off start,
281 obd_off end, struct lov_request_set **reqset);
282 int lov_fini_sync_set(struct lov_request_set *set);
283 int lov_prep_enqueue_set(struct obd_export *exp, struct lov_stripe_md *lsm,
284 ldlm_policy_data_t *policy, __u32 mode,
285 struct lustre_handle *lockh,
286 struct lov_request_set **reqset);
287 int lov_update_enqueue_set(struct lov_request_set *set,
288 struct lov_request *req, int rc, int flags);
289 int lov_fini_enqueue_set(struct lov_request_set *set, __u32 mode);
290 int lov_prep_match_set(struct obd_export *exp, struct lov_stripe_md *lsm,
291 ldlm_policy_data_t *policy, __u32 mode,
292 struct lustre_handle *lockh,
293 struct lov_request_set **reqset);
294 int lov_update_match_set(struct lov_request_set *set, struct lov_request *req,
296 int lov_fini_match_set(struct lov_request_set *set, __u32 mode, int flags);
297 int lov_prep_cancel_set(struct obd_export *exp, struct lov_stripe_md *lsm,
298 __u32 mode, struct lustre_handle *lockh,
299 struct lov_request_set **reqset);
300 int lov_fini_cancel_set(struct lov_request_set *set);
303 int lov_get_stripecnt(struct lov_obd *lov, int stripe_count);
304 int lov_alloc_memmd(struct lov_stripe_md **lsmp, int stripe_count, int pattern);
305 void lov_free_memmd(struct lov_stripe_md **lsmp);
308 int lov_llog_init(struct obd_device *, struct obd_llogs *,
309 struct obd_device *, int, struct llog_catid *);
310 int lov_llog_finish(struct obd_device *, struct obd_llogs *, int);
313 int lov_packmd(struct obd_export *exp, struct lov_mds_md **lmm,
314 struct lov_stripe_md *lsm);
315 int lov_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
316 struct lov_mds_md *lmm, int lmm_bytes);
317 int lov_setstripe(struct obd_export *exp,
318 struct lov_stripe_md **lsmp, struct lov_user_md *lump);
319 int lov_setea(struct obd_export *exp, struct lov_stripe_md **lsmp,
320 struct lov_user_md *lump);
321 int lov_getstripe(struct obd_export *exp,
322 struct lov_stripe_md *lsm, struct lov_user_md *lump);
325 extern struct file_operations lov_proc_target_fops;