Whamcloud - gitweb
- fixes in split about using correct byte order;
[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 static inline void lov_llh_addref(void *llhp)
76 {
77         struct lov_lock_handles *llh = llhp;
78         atomic_inc(&llh->llh_refcount);
79         CDEBUG(D_INFO, "GETting llh %p : new refcount %d\n", llh,
80                atomic_read(&llh->llh_refcount));
81 }
82
83 static inline struct lov_lock_handles *lov_llh_new(struct lov_stripe_md *lsm)
84 {
85         struct lov_lock_handles *llh;
86
87         OBD_ALLOC(llh, sizeof *llh +
88                   sizeof(*llh->llh_handles) * lsm->lsm_stripe_count);
89         if (llh == NULL)
90                 return NULL;
91         atomic_set(&llh->llh_refcount, 2);
92         llh->llh_stripe_count = lsm->lsm_stripe_count;
93         CFS_INIT_LIST_HEAD(&llh->llh_handle.h_link);
94         class_handle_hash(&llh->llh_handle, lov_llh_addref);
95         return llh;
96 }
97
98 static inline struct lov_lock_handles *
99 lov_handle2llh(struct lustre_handle *handle)
100 {
101         LASSERT(handle != NULL);
102         return(class_handle2object(handle->cookie));
103 }
104
105 static inline void lov_llh_put(struct lov_lock_handles *llh)
106 {
107         CDEBUG(D_INFO, "PUTting llh %p : new refcount %d\n", llh,
108                atomic_read(&llh->llh_refcount) - 1);
109         LASSERT(atomic_read(&llh->llh_refcount) > 0 &&
110                 atomic_read(&llh->llh_refcount) < 0x5a5a);
111         if (atomic_dec_and_test(&llh->llh_refcount)) {
112                 class_handle_unhash(&llh->llh_handle);
113                 LASSERT(list_empty(&llh->llh_handle.h_link));
114                 OBD_FREE(llh, sizeof *llh +
115                          sizeof(*llh->llh_handles) * llh->llh_stripe_count);
116         }
117 }
118
119 #define lov_uuid2str(lv, index) \
120         (char *)((lv)->lov_tgts[index]->ltd_uuid.uuid)
121
122 /* lov_merge.c */
123 void lov_merge_attrs(struct obdo *tgt, struct obdo *src, obd_flag valid,
124                      struct lov_stripe_md *lsm, int stripeno, int *set);
125 int lov_merge_lvb(struct obd_export *exp, struct lov_stripe_md *lsm,
126                   struct ost_lvb *lvb, int kms_only);
127 int lov_adjust_kms(struct obd_export *exp, struct lov_stripe_md *lsm,
128                    obd_off size, int shrink);
129
130 /* lov_offset.c */
131 obd_size lov_stripe_size(struct lov_stripe_md *lsm, obd_size ost_size,
132                          int stripeno);
133 int lov_stripe_offset(struct lov_stripe_md *lsm, obd_off lov_off,
134                       int stripeno, obd_off *obd_off);
135 obd_off lov_size_to_stripe(struct lov_stripe_md *lsm, obd_off file_size,
136                            int stripeno);
137 int lov_stripe_intersects(struct lov_stripe_md *lsm, int stripeno,
138                           obd_off start, obd_off end,
139                           obd_off *obd_start, obd_off *obd_end);
140 int lov_stripe_number(struct lov_stripe_md *lsm, obd_off lov_off);
141
142 /* lov_qos.c */
143 int qos_add_tgt(struct obd_device *obd, __u32 index);
144 int qos_del_tgt(struct obd_device *obd, __u32 index);
145 void qos_shrink_lsm(struct lov_request_set *set);
146 int qos_prep_create(struct obd_export *exp, struct lov_request_set *set);
147 void qos_update(struct lov_obd *lov, int idx, struct obd_statfs *osfs);
148 int qos_remedy_create(struct lov_request_set *set, struct lov_request *req);
149
150 /* lov_request.c */
151 void lov_set_add_req(struct lov_request *req, struct lov_request_set *set);
152 void lov_update_set(struct lov_request_set *set,
153                     struct lov_request *req, int rc);
154 int lov_update_common_set(struct lov_request_set *set,
155                           struct lov_request *req, int rc);
156 int lov_prep_create_set(struct obd_export *exp, struct obd_info *oifo,
157                         struct lov_stripe_md **ea, struct obdo *src_oa,
158                         struct obd_trans_info *oti,
159                         struct lov_request_set **reqset);
160 int lov_update_create_set(struct lov_request_set *set,
161                           struct lov_request *req, int rc);
162 int lov_fini_create_set(struct lov_request_set *set, struct lov_stripe_md **ea);
163 int lov_prep_brw_set(struct obd_export *exp, struct obd_info *oinfo,
164                      obd_count oa_bufs, struct brw_page *pga,
165                      struct obd_trans_info *oti,
166                      struct lov_request_set **reqset);
167 int lov_fini_brw_set(struct lov_request_set *set);
168 int lov_prep_getattr_set(struct obd_export *exp, struct obd_info *oinfo,
169                          struct lov_request_set **reqset);
170 int lov_fini_getattr_set(struct lov_request_set *set);
171 int lov_prep_destroy_set(struct obd_export *exp, struct obd_info *oinfo,
172                          struct obdo *src_oa, struct lov_stripe_md *lsm,
173                          struct obd_trans_info *oti,
174                          struct lov_request_set **reqset);
175 int lov_update_destroy_set(struct lov_request_set *set,
176                            struct lov_request *req, int rc);
177 int lov_fini_destroy_set(struct lov_request_set *set);
178 int lov_prep_setattr_set(struct obd_export *exp, struct obd_info *oinfo,
179                          struct obd_trans_info *oti,
180                          struct lov_request_set **reqset);
181 int lov_update_setattr_set(struct lov_request_set *set,
182                            struct lov_request *req, int rc);
183 int lov_fini_setattr_set(struct lov_request_set *set);
184 int lov_prep_punch_set(struct obd_export *exp, struct obd_info *oinfo,
185                        struct obd_trans_info *oti,
186                        struct lov_request_set **reqset);
187 int lov_fini_punch_set(struct lov_request_set *set);
188 int lov_prep_sync_set(struct obd_export *exp, struct obd_info *obd_info,
189                       struct obdo *src_oa,
190                       struct lov_stripe_md *lsm, obd_off start,
191                       obd_off end, struct lov_request_set **reqset);
192 int lov_fini_sync_set(struct lov_request_set *set);
193 int lov_prep_enqueue_set(struct obd_export *exp, struct obd_info *oinfo,
194                          struct obd_enqueue_info *einfo,
195                          struct lov_request_set **reqset);
196 int lov_fini_enqueue_set(struct lov_request_set *set, __u32 mode, int rc);
197 int lov_prep_match_set(struct obd_export *exp, struct obd_info *oinfo,
198                        struct lov_stripe_md *lsm,
199                        ldlm_policy_data_t *policy, __u32 mode,
200                        struct lustre_handle *lockh,
201                        struct lov_request_set **reqset);
202 int lov_update_match_set(struct lov_request_set *set, struct lov_request *req,
203                          int rc);
204 int lov_fini_match_set(struct lov_request_set *set, __u32 mode, int flags);
205 int lov_prep_cancel_set(struct obd_export *exp, struct obd_info *oinfo,
206                         struct lov_stripe_md *lsm,
207                         __u32 mode, struct lustre_handle *lockh,
208                         struct lov_request_set **reqset);
209 int lov_fini_cancel_set(struct lov_request_set *set);
210 int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo,
211                         struct lov_request_set **reqset);
212 void lov_update_statfs(struct obd_device *obd, struct obd_statfs *osfs,
213                        struct obd_statfs *lov_sfs, int success);
214 int lov_fini_statfs(struct obd_device *obd, struct obd_statfs *osfs,
215                     int success);
216 int lov_fini_statfs_set(struct lov_request_set *set);
217
218 /* lov_obd.c */
219 void lov_fix_desc(struct lov_desc *desc);
220 int lov_get_stripecnt(struct lov_obd *lov, int stripe_count);
221 void lov_getref(struct obd_device *obd);
222 void lov_putref(struct obd_device *obd);
223
224 /* lov_log.c */
225 int lov_llog_init(struct obd_device *obd, struct obd_llogs *llogs, 
226                   struct obd_device *tgt, int count, struct llog_catid *logid, 
227                   struct obd_uuid *uuid);
228 int lov_llog_finish(struct obd_device *obd, int count);
229
230 /* lov_pack.c */
231 int lov_packmd(struct obd_export *exp, struct lov_mds_md **lmm,
232                struct lov_stripe_md *lsm);
233 int lov_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
234                  struct lov_mds_md *lmm, int lmm_bytes);
235 int lov_setstripe(struct obd_export *exp,
236                   struct lov_stripe_md **lsmp, struct lov_user_md *lump);
237 int lov_setea(struct obd_export *exp, struct lov_stripe_md **lsmp,
238               struct lov_user_md *lump);
239 int lov_getstripe(struct obd_export *exp,
240                   struct lov_stripe_md *lsm, struct lov_user_md *lump);
241 int lov_alloc_memmd(struct lov_stripe_md **lsmp, int stripe_count,
242                       int pattern, int magic);
243 void lov_free_memmd(struct lov_stripe_md **lsmp);
244
245 void lov_dump_lmm_v1(int level, struct lov_mds_md_v1 *lmm);
246 void lov_dump_lmm_join(int level, struct lov_mds_md_join *lmmj);
247 /* lov_ea.c */
248 int lov_unpackmd_join(struct lov_obd *lov, struct lov_stripe_md *lsm,
249                       struct lov_mds_md *lmm);
250
251 struct lov_extent *lovea_idx2le(struct lov_stripe_md *lsm, int stripe_no);
252 struct lov_extent *lovea_off2le(struct lov_stripe_md *lsm, obd_off lov_off);
253 int lovea_destroy_object(struct lov_obd *lov, struct lov_stripe_md *lsm,
254                          struct obdo *oa, void *data);
255 /* lproc_lov.c */
256 extern struct file_operations lov_proc_target_fops;
257
258 #endif