Whamcloud - gitweb
7a82bcad9635043f5c845f91662c2c7468dcd29e
[fs/lustre-release.git] / lustre / osp / osp_internal.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel, Inc.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/osp/osp_internal.h
37  *
38  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
39  */
40
41 #ifndef _OSP_INTERNAL_H
42 #define _OSP_INTERNAL_H
43
44 #include <obd.h>
45 #include <dt_object.h>
46 #include <lustre_fid.h>
47
48 /*
49  * Infrastructure to support tracking of last committed llog record
50  */
51 struct osp_id_tracker {
52         cfs_spinlock_t           otr_lock;
53         __u32                    otr_next_id;
54         __u32                    otr_committed_id;
55         /* callback is register once per diskfs -- that's the whole point */
56         struct dt_txn_callback   otr_tx_cb;
57         /* single node can run many clusters */
58         cfs_list_t               otr_wakeup_list;
59         cfs_list_t               otr_list;
60         /* underlying shared device */
61         struct dt_device        *otr_dev;
62         /* how many users of this tracker */
63         cfs_atomic_t             otr_refcount;
64 };
65
66 struct osp_device {
67         struct dt_device                 opd_dt_dev;
68         /* corresponded OST index */
69         int                              opd_index;
70         /* device used to store persistent state (llogs, last ids) */
71         struct obd_export               *opd_storage_exp;
72         struct dt_device                *opd_storage;
73         struct dt_object                *opd_last_used_file;
74
75         /* stored persistently in LE format, updated directly to/from disk
76          * and required le64_to_cpu() conversion before use.
77          * Protected by opd_pre_lock */
78         volatile obd_id                  opd_last_used_id;
79
80         obd_id                           opd_gap_start;
81         int                              opd_gap_count;
82         /* connection to OST */
83         struct obd_device               *opd_obd;
84         struct obd_export               *opd_exp;
85         struct obd_uuid                  opd_cluuid;
86         struct obd_connect_data         *opd_connect_data;
87         int                              opd_connects;
88         cfs_proc_dir_entry_t            *opd_proc_entry;
89         struct lprocfs_stats            *opd_stats;
90         /* connection status. */
91         int                              opd_new_connection;
92         int                              opd_got_disconnected;
93         int                              opd_imp_connected;
94         int                              opd_imp_active;
95         int                              opd_imp_seen_connected:1;
96
97         /* whether local recovery is completed:
98          * reported via ->ldo_recovery_complete() */
99         int                              opd_recovery_completed;
100
101         /*
102          * Precreation pool
103          */
104         cfs_spinlock_t                   opd_pre_lock;
105         /* next id to assign in creation */
106         __u64                            opd_pre_next;
107         /* last created id OST reported, next-created - available id's */
108         __u64                            opd_pre_last_created;
109         /* how many ids are reserved in declare, we shouldn't block in create */
110         __u64                            opd_pre_reserved;
111         /* dedicate precreate thread */
112         struct ptlrpc_thread             opd_pre_thread;
113         /* thread waits for signals about pool going empty */
114         cfs_waitq_t                      opd_pre_waitq;
115         /* consumers (who needs new ids) wait here */
116         cfs_waitq_t                      opd_pre_user_waitq;
117         /* current precreation status: working, failed, stopping? */
118         int                              opd_pre_status;
119         /* how many to precreate next time */
120         int                              opd_pre_grow_count;
121         int                              opd_pre_min_grow_count;
122         int                              opd_pre_max_grow_count;
123         /* whether to grow precreation window next time or not */
124         int                              opd_pre_grow_slow;
125
126         /*
127          * OST synchronization
128          */
129         cfs_spinlock_t                   opd_syn_lock;
130         /* unique generation, to recognize start of new records in the llog */
131         struct llog_gen                  opd_syn_generation;
132         /* number of changes to sync, used to wake up sync thread */
133         unsigned long                    opd_syn_changes;
134         /* processing of changes from previous mount is done? */
135         int                              opd_syn_prev_done;
136         /* found records */
137         struct ptlrpc_thread             opd_syn_thread;
138         cfs_waitq_t                      opd_syn_waitq;
139         /* list of remotely committed rpc */
140         cfs_list_t                       opd_syn_committed_there;
141         /* number of changes being under sync */
142         int                              opd_syn_sync_in_progress;
143         /* number of RPCs in flight - flow control */
144         int                              opd_syn_rpc_in_flight;
145         int                              opd_syn_max_rpc_in_flight;
146         /* number of RPC in processing (including non-committed by OST) */
147         int                              opd_syn_rpc_in_progress;
148         int                              opd_syn_max_rpc_in_progress;
149         /* osd api's commit cb control structure */
150         struct dt_txn_callback           opd_syn_txn_cb;
151         /* last used change number -- semantically similar to transno */
152         unsigned long                    opd_syn_last_used_id;
153         /* last committed change number -- semantically similar to
154          * last_committed */
155         unsigned long                    opd_syn_last_committed_id;
156         /* last processed (taken from llog) id */
157         unsigned long                    opd_syn_last_processed_id;
158         struct osp_id_tracker           *opd_syn_tracker;
159         cfs_list_t                       opd_syn_ontrack;
160
161         /*
162          * statfs related fields: OSP maintains it on its own
163          */
164         struct obd_statfs                opd_statfs;
165         cfs_time_t                       opd_statfs_fresh_till;
166         cfs_timer_t                      opd_statfs_timer;
167         int                              opd_statfs_update_in_progress;
168         /* how often to update statfs data */
169         int                              opd_statfs_maxage;
170
171         cfs_proc_dir_entry_t            *opd_symlink;
172 };
173
174 extern cfs_mem_cache_t *osp_object_kmem;
175
176 /* this is a top object */
177 struct osp_object {
178         struct lu_object_header  opo_header;
179         struct dt_object         opo_obj;
180         int                      opo_reserved:1,
181                                  opo_new:1;
182 };
183
184 extern struct lu_object_operations osp_lu_obj_ops;
185
186 struct osp_thread_info {
187         struct lu_buf            osi_lb;
188         struct lu_fid            osi_fid;
189         struct lu_attr           osi_attr;
190         struct ost_id            osi_oi;
191         obd_id                   osi_id;
192         loff_t                   osi_off;
193         union {
194                 struct llog_rec_hdr             osi_hdr;
195                 struct llog_unlink64_rec        osi_unlink;
196                 struct llog_setattr64_rec       osi_setattr;
197                 struct llog_gen_rec             osi_gen;
198         };
199         struct llog_cookie       osi_cookie;
200         struct llog_catid        osi_cid;
201 };
202
203 static inline void osp_objid_buf_prep(struct osp_thread_info *osi,
204                                       struct osp_device *d, int index)
205 {
206         osi->osi_lb.lb_buf = (void *)&d->opd_last_used_id;
207         osi->osi_lb.lb_len = sizeof(d->opd_last_used_id);
208         osi->osi_off = sizeof(d->opd_last_used_id) * index;
209 }
210
211 extern struct lu_context_key osp_thread_key;
212
213 static inline struct osp_thread_info *osp_env_info(const struct lu_env *env)
214 {
215         struct osp_thread_info *info;
216
217         info = lu_context_key_get(&env->le_ctx, &osp_thread_key);
218         if (info == NULL) {
219                 lu_env_refill((struct lu_env *)env);
220                 info = lu_context_key_get(&env->le_ctx, &osp_thread_key);
221         }
222         LASSERT(info);
223         return info;
224 }
225
226 struct osp_txn_info {
227         __u32   oti_current_id;
228 };
229
230 extern struct lu_context_key osp_txn_key;
231
232 static inline struct osp_txn_info *osp_txn_info(struct lu_context *ctx)
233 {
234         struct osp_txn_info *info;
235
236         info = lu_context_key_get(ctx, &osp_txn_key);
237         return info;
238 }
239
240 extern const struct lu_device_operations osp_lu_ops;
241
242 static inline int lu_device_is_osp(struct lu_device *d)
243 {
244         return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osp_lu_ops);
245 }
246
247 static inline struct osp_device *lu2osp_dev(struct lu_device *d)
248 {
249         LASSERT(lu_device_is_osp(d));
250         return container_of0(d, struct osp_device, opd_dt_dev.dd_lu_dev);
251 }
252
253 static inline struct lu_device *osp2lu_dev(struct osp_device *d)
254 {
255         return &d->opd_dt_dev.dd_lu_dev;
256 }
257
258 static inline struct osp_device *dt2osp_dev(struct dt_device *d)
259 {
260         LASSERT(lu_device_is_osp(&d->dd_lu_dev));
261         return container_of0(d, struct osp_device, opd_dt_dev);
262 }
263
264 static inline struct osp_object *lu2osp_obj(struct lu_object *o)
265 {
266         LASSERT(ergo(o != NULL, lu_device_is_osp(o->lo_dev)));
267         return container_of0(o, struct osp_object, opo_obj.do_lu);
268 }
269
270 static inline struct lu_object *osp2lu_obj(struct osp_object *obj)
271 {
272         return &obj->opo_obj.do_lu;
273 }
274
275 static inline struct osp_object *osp_obj(const struct lu_object *o)
276 {
277         LASSERT(lu_device_is_osp(o->lo_dev));
278         return container_of0(o, struct osp_object, opo_obj.do_lu);
279 }
280
281 static inline struct osp_object *dt2osp_obj(const struct dt_object *d)
282 {
283         return osp_obj(&d->do_lu);
284 }
285
286 static inline struct dt_object *osp_object_child(struct osp_object *o)
287 {
288         return container_of0(lu_object_next(osp2lu_obj(o)),
289                              struct dt_object, do_lu);
290 }
291
292 /* osp_dev.c */
293 void osp_update_last_id(struct osp_device *d, obd_id objid);
294
295 /* osp_precreate.c */
296 int osp_init_precreate(struct osp_device *d);
297 int osp_precreate_reserve(const struct lu_env *env, struct osp_device *d);
298 __u64 osp_precreate_get_id(struct osp_device *d);
299 void osp_precreate_fini(struct osp_device *d);
300 int osp_object_truncate(const struct lu_env *env, struct dt_object *dt, __u64);
301 void osp_pre_update_status(struct osp_device *d, int rc);
302 void osp_statfs_need_now(struct osp_device *d);
303
304 /* lproc_osp.c */
305 void lprocfs_osp_init_vars(struct lprocfs_static_vars *lvars);
306
307 /* osp_sync.c */
308 int osp_sync_declare_add(const struct lu_env *env, struct osp_object *o,
309                          llog_op_type type, struct thandle *th);
310 int osp_sync_add(const struct lu_env *env, struct osp_object *o,
311                  llog_op_type type, struct thandle *th,
312                  const struct lu_attr *attr);
313 int osp_sync_init(const struct lu_env *env, struct osp_device *d);
314 int osp_sync_fini(struct osp_device *d);
315 void __osp_sync_check_for_work(struct osp_device *d);
316
317 #endif