Whamcloud - gitweb
- make HEAD from b_post_cmd3
[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 obd_info          rq_oi;
24         struct lov_request_set  *rq_rqset;
25
26         struct list_head         rq_link;
27
28         int                      rq_idx;        /* index in lov->tgts array */
29         int                      rq_stripe;     /* stripe number */
30         int                      rq_complete;
31         int                      rq_rc;
32         int                      rq_buflen;     /* length of sub_md */
33
34         obd_count                rq_oabufs;
35         obd_count                rq_pgaidx;
36 };
37
38 struct lov_request_set {
39         struct obd_enqueue_info *set_ei;
40         struct obd_info         *set_oi;
41         atomic_t                 set_refcount;
42         struct obd_export       *set_exp;
43         /* XXX: There is @set_exp already, however obd_statfs gets obd_device
44            only. */
45         struct obd_device       *set_obd;
46         int                      set_count;
47         int                      set_completes;
48         int                      set_success;
49         struct llog_cookie      *set_cookies;
50         int                      set_cookie_sent;
51         struct obd_trans_info   *set_oti;
52         obd_count                set_oabufs;
53         struct brw_page         *set_pga;
54         struct lov_lock_handles *set_lockh;
55         struct list_head         set_list;
56 };
57
58 #define LOV_AP_MAGIC 8200
59
60 struct lov_async_page {
61         int                             lap_magic;
62         int                             lap_stripe;
63         obd_off                         lap_sub_offset;
64         obd_id                          lap_loi_id;
65         obd_gr                          lap_loi_gr;
66         void                            *lap_sub_cookie;
67         struct obd_async_page_ops       *lap_caller_ops;
68         void                            *lap_caller_data;
69 };
70
71 #define LAP_FROM_COOKIE(c)                                                     \
72         (LASSERT(((struct lov_async_page *)(c))->lap_magic == LOV_AP_MAGIC),   \
73          (struct lov_async_page *)(c))
74
75 extern cfs_mem_cache_t *lov_oinfo_slab;
76
77 static inline void lov_llh_addref(void *llhp)
78 {
79         struct lov_lock_handles *llh = llhp;
80         atomic_inc(&llh->llh_refcount);
81         CDEBUG(D_INFO, "GETting llh %p : new refcount %d\n", llh,
82                atomic_read(&llh->llh_refcount));
83 }
84
85 static inline struct lov_lock_handles *lov_llh_new(struct lov_stripe_md *lsm)
86 {
87         struct lov_lock_handles *llh;
88
89         OBD_ALLOC(llh, sizeof *llh +
90                   sizeof(*llh->llh_handles) * lsm->lsm_stripe_count);
91         if (llh == NULL)
92                 return NULL;
93         atomic_set(&llh->llh_refcount, 2);
94         llh->llh_stripe_count = lsm->lsm_stripe_count;
95         CFS_INIT_LIST_HEAD(&llh->llh_handle.h_link);
96         class_handle_hash(&llh->llh_handle, lov_llh_addref);
97         return llh;
98 }
99
100 static inline struct lov_lock_handles *
101 lov_handle2llh(struct lustre_handle *handle)
102 {
103         LASSERT(handle != NULL);
104         return(class_handle2object(handle->cookie));
105 }
106
107 static inline void lov_llh_put(struct lov_lock_handles *llh)
108 {
109         CDEBUG(D_INFO, "PUTting llh %p : new refcount %d\n", llh,
110                atomic_read(&llh->llh_refcount) - 1);
111         LASSERT(atomic_read(&llh->llh_refcount) > 0 &&
112                 atomic_read(&llh->llh_refcount) < 0x5a5a);
113         if (atomic_dec_and_test(&llh->llh_refcount)) {
114                 class_handle_unhash(&llh->llh_handle);
115                 /* The structure may be held by other threads because RCU. 
116                  *   -jxiong */
117                 if (atomic_read(&llh->llh_refcount))
118                         return;
119
120                 OBD_FREE_RCU(llh, sizeof *llh +
121                              sizeof(*llh->llh_handles) * llh->llh_stripe_count,
122                              &llh->llh_handle);
123         }
124 }
125
126 #define lov_uuid2str(lv, index) \
127         (char *)((lv)->lov_tgts[index]->ltd_uuid.uuid)
128
129 /* lov_merge.c */
130 void lov_merge_attrs(struct obdo *tgt, struct obdo *src, obd_flag valid,
131                      struct lov_stripe_md *lsm, int stripeno, int *set);
132 int lov_merge_lvb(struct obd_export *exp, struct lov_stripe_md *lsm,
133                   struct ost_lvb *lvb, int kms_only);
134 int lov_adjust_kms(struct obd_export *exp, struct lov_stripe_md *lsm,
135                    obd_off size, int shrink);
136
137 /* lov_offset.c */
138 obd_size lov_stripe_size(struct lov_stripe_md *lsm, obd_size ost_size,
139                          int stripeno);
140 int lov_stripe_offset(struct lov_stripe_md *lsm, obd_off lov_off,
141                       int stripeno, obd_off *obd_off);
142 obd_off lov_size_to_stripe(struct lov_stripe_md *lsm, obd_off file_size,
143                            int stripeno);
144 int lov_stripe_intersects(struct lov_stripe_md *lsm, int stripeno,
145                           obd_off start, obd_off end,
146                           obd_off *obd_start, obd_off *obd_end);
147 int lov_stripe_number(struct lov_stripe_md *lsm, obd_off lov_off);
148
149 /* lov_qos.c */
150 int qos_add_tgt(struct obd_device *obd, __u32 index);
151 int qos_del_tgt(struct obd_device *obd, __u32 index);
152 void qos_shrink_lsm(struct lov_request_set *set);
153 int qos_prep_create(struct obd_export *exp, struct lov_request_set *set);
154 void qos_update(struct lov_obd *lov);
155 int qos_remedy_create(struct lov_request_set *set, struct lov_request *req);
156
157 /* lov_request.c */
158 void lov_set_add_req(struct lov_request *req, struct lov_request_set *set);
159 void lov_update_set(struct lov_request_set *set,
160                     struct lov_request *req, int rc);
161 int lov_update_common_set(struct lov_request_set *set,
162                           struct lov_request *req, int rc);
163 int lov_prep_create_set(struct obd_export *exp, struct obd_info *oifo,
164                         struct lov_stripe_md **ea, struct obdo *src_oa,
165                         struct obd_trans_info *oti,
166                         struct lov_request_set **reqset);
167 int lov_update_create_set(struct lov_request_set *set,
168                           struct lov_request *req, int rc);
169 int lov_fini_create_set(struct lov_request_set *set, struct lov_stripe_md **ea);
170 int lov_prep_brw_set(struct obd_export *exp, struct obd_info *oinfo,
171                      obd_count oa_bufs, struct brw_page *pga,
172                      struct obd_trans_info *oti,
173                      struct lov_request_set **reqset);
174 int lov_fini_brw_set(struct lov_request_set *set);
175 int lov_prep_getattr_set(struct obd_export *exp, struct obd_info *oinfo,
176                          struct lov_request_set **reqset);
177 int lov_fini_getattr_set(struct lov_request_set *set);
178 int lov_prep_destroy_set(struct obd_export *exp, struct obd_info *oinfo,
179                          struct obdo *src_oa, struct lov_stripe_md *lsm,
180                          struct obd_trans_info *oti,
181                          struct lov_request_set **reqset);
182 int lov_update_destroy_set(struct lov_request_set *set,
183                            struct lov_request *req, int rc);
184 int lov_fini_destroy_set(struct lov_request_set *set);
185 int lov_prep_setattr_set(struct obd_export *exp, struct obd_info *oinfo,
186                          struct obd_trans_info *oti,
187                          struct lov_request_set **reqset);
188 int lov_update_setattr_set(struct lov_request_set *set,
189                            struct lov_request *req, int rc);
190 int lov_fini_setattr_set(struct lov_request_set *set);
191 int lov_prep_punch_set(struct obd_export *exp, struct obd_info *oinfo,
192                        struct obd_trans_info *oti,
193                        struct lov_request_set **reqset);
194 int lov_fini_punch_set(struct lov_request_set *set);
195 int lov_prep_sync_set(struct obd_export *exp, struct obd_info *obd_info,
196                       struct obdo *src_oa,
197                       struct lov_stripe_md *lsm, obd_off start,
198                       obd_off end, struct lov_request_set **reqset);
199 int lov_fini_sync_set(struct lov_request_set *set);
200 int lov_prep_enqueue_set(struct obd_export *exp, struct obd_info *oinfo,
201                          struct obd_enqueue_info *einfo,
202                          struct lov_request_set **reqset);
203 int lov_fini_enqueue_set(struct lov_request_set *set, __u32 mode, int rc);
204 int lov_prep_match_set(struct obd_export *exp, struct obd_info *oinfo,
205                        struct lov_stripe_md *lsm,
206                        ldlm_policy_data_t *policy, __u32 mode,
207                        struct lustre_handle *lockh,
208                        struct lov_request_set **reqset);
209 int lov_update_match_set(struct lov_request_set *set, struct lov_request *req,
210                          int rc);
211 int lov_fini_match_set(struct lov_request_set *set, __u32 mode, int flags);
212 int lov_prep_cancel_set(struct obd_export *exp, struct obd_info *oinfo,
213                         struct lov_stripe_md *lsm,
214                         __u32 mode, struct lustre_handle *lockh,
215                         struct lov_request_set **reqset);
216 int lov_fini_cancel_set(struct lov_request_set *set);
217 int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo,
218                         struct lov_request_set **reqset);
219 void lov_update_statfs(struct obd_device *obd, struct obd_statfs *osfs,
220                        struct obd_statfs *lov_sfs, int success);
221 int lov_fini_statfs(struct obd_device *obd, struct obd_statfs *osfs,
222                     int success);
223 int lov_fini_statfs_set(struct lov_request_set *set);
224
225 /* lov_obd.c */
226 void lov_fix_desc(struct lov_desc *desc);
227 int lov_get_stripecnt(struct lov_obd *lov, int stripe_count);
228 void lov_getref(struct obd_device *obd);
229 void lov_putref(struct obd_device *obd);
230
231 /* lov_log.c */
232 int lov_llog_init(struct obd_device *obd, struct obd_llogs *llogs, 
233                   struct obd_device *tgt, int count, struct llog_catid *logid, 
234                   struct obd_uuid *uuid);
235 int lov_llog_finish(struct obd_device *obd, int count);
236
237 /* lov_pack.c */
238 int lov_packmd(struct obd_export *exp, struct lov_mds_md **lmm,
239                struct lov_stripe_md *lsm);
240 int lov_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
241                  struct lov_mds_md *lmm, int lmm_bytes);
242 int lov_setstripe(struct obd_export *exp,
243                   struct lov_stripe_md **lsmp, struct lov_user_md *lump);
244 int lov_setea(struct obd_export *exp, struct lov_stripe_md **lsmp,
245               struct lov_user_md *lump);
246 int lov_getstripe(struct obd_export *exp,
247                   struct lov_stripe_md *lsm, struct lov_user_md *lump);
248 int lov_alloc_memmd(struct lov_stripe_md **lsmp, int stripe_count,
249                       int pattern, int magic);
250 void lov_free_memmd(struct lov_stripe_md **lsmp);
251
252 void lov_dump_lmm_v1(int level, struct lov_mds_md_v1 *lmm);
253 void lov_dump_lmm_join(int level, struct lov_mds_md_join *lmmj);
254 /* lov_ea.c */
255 int lov_unpackmd_join(struct lov_obd *lov, struct lov_stripe_md *lsm,
256                       struct lov_mds_md *lmm);
257 struct lov_stripe_md *lsm_alloc_plain(int stripe_count, int *size);
258 void lsm_free_plain(struct lov_stripe_md *lsm);
259
260 struct lov_extent *lovea_idx2le(struct lov_stripe_md *lsm, int stripe_no);
261 struct lov_extent *lovea_off2le(struct lov_stripe_md *lsm, obd_off lov_off);
262 int lovea_destroy_object(struct lov_obd *lov, struct lov_stripe_md *lsm,
263                          struct obdo *oa, void *data);
264 /* lproc_lov.c */
265 extern struct file_operations lov_proc_target_fops;
266
267 #endif