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