4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/osp/osp_internal.h
38 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
41 #ifndef _OSP_INTERNAL_H
42 #define _OSP_INTERNAL_H
45 #include <obd_class.h>
46 #include <dt_object.h>
47 #include <md_object.h>
48 #include <lustre_fid.h>
51 * Infrastructure to support tracking of last committed llog record
53 struct osp_id_tracker {
56 __u32 otr_committed_id;
57 /* callback is register once per diskfs -- that's the whole point */
58 struct dt_txn_callback otr_tx_cb;
59 /* single node can run many clusters */
60 cfs_list_t otr_wakeup_list;
62 /* underlying shared device */
63 struct dt_device *otr_dev;
64 /* how many users of this tracker */
65 cfs_atomic_t otr_refcount;
68 struct osp_precreate {
72 spinlock_t osp_pre_lock;
74 /* last fid to assign in creation */
75 struct lu_fid osp_pre_used_fid;
76 /* last created id OST reported, next-created - available id's */
77 struct lu_fid osp_pre_last_created_fid;
78 /* how many ids are reserved in declare, we shouldn't block in create */
79 __u64 osp_pre_reserved;
80 /* consumers (who needs new ids) wait here */
81 wait_queue_head_t osp_pre_user_waitq;
82 /* current precreation status: working, failed, stopping? */
84 /* how many to precreate next time */
85 int osp_pre_grow_count;
86 int osp_pre_min_grow_count;
87 int osp_pre_max_grow_count;
88 /* whether to grow precreation window next time or not */
89 int osp_pre_grow_slow;
90 /* cleaning up orphans or recreating missing objects */
91 int osp_pre_recovering;
95 struct dt_device opd_dt_dev;
96 /* corresponded OST index */
99 /* corrsponded MDT index, which will be used when connecting to OST
100 * for validating the connection (see ofd_parse_connect_data) */
102 /* device used to store persistent state (llogs, last ids) */
103 struct obd_export *opd_storage_exp;
104 struct dt_device *opd_storage;
105 struct dt_object *opd_last_used_oid_file;
106 struct dt_object *opd_last_used_seq_file;
108 /* stored persistently in LE format, updated directly to/from disk
109 * and required le64_to_cpu() conversion before use.
110 * Protected by opd_pre_lock */
111 struct lu_fid opd_last_used_fid;
112 struct lu_fid opd_gap_start_fid;
114 /* connection to OST */
115 struct obd_device *opd_obd;
116 struct obd_export *opd_exp;
117 struct obd_uuid opd_cluuid;
118 struct obd_connect_data *opd_connect_data;
120 cfs_proc_dir_entry_t *opd_proc_entry;
121 struct lprocfs_stats *opd_stats;
122 /* connection status. */
123 int opd_new_connection;
124 int opd_got_disconnected;
125 int opd_imp_connected;
127 unsigned int opd_imp_seen_connected:1,
130 /* whether local recovery is completed:
131 * reported via ->ldo_recovery_complete() */
132 int opd_recovery_completed;
134 /* precreate structure for OSP */
135 struct osp_precreate *opd_pre;
136 /* dedicate precreate thread */
137 struct ptlrpc_thread opd_pre_thread;
138 /* thread waits for signals about pool going empty */
139 wait_queue_head_t opd_pre_waitq;
142 * OST synchronization
144 spinlock_t opd_syn_lock;
145 /* unique generation, to recognize start of new records in the llog */
146 struct llog_gen opd_syn_generation;
147 /* number of changes to sync, used to wake up sync thread */
148 unsigned long opd_syn_changes;
149 /* processing of changes from previous mount is done? */
150 int opd_syn_prev_done;
152 struct ptlrpc_thread opd_syn_thread;
153 wait_queue_head_t opd_syn_waitq;
154 /* list of remotely committed rpc */
155 cfs_list_t opd_syn_committed_there;
156 /* number of changes being under sync */
157 int opd_syn_sync_in_progress;
158 /* number of RPCs in flight - flow control */
159 int opd_syn_rpc_in_flight;
160 int opd_syn_max_rpc_in_flight;
161 /* number of RPC in processing (including non-committed by OST) */
162 int opd_syn_rpc_in_progress;
163 int opd_syn_max_rpc_in_progress;
164 /* osd api's commit cb control structure */
165 struct dt_txn_callback opd_syn_txn_cb;
166 /* last used change number -- semantically similar to transno */
167 unsigned long opd_syn_last_used_id;
168 /* last committed change number -- semantically similar to
170 unsigned long opd_syn_last_committed_id;
171 /* last processed (taken from llog) id */
172 unsigned long opd_syn_last_processed_id;
173 struct osp_id_tracker *opd_syn_tracker;
174 cfs_list_t opd_syn_ontrack;
177 * statfs related fields: OSP maintains it on its own
179 struct obd_statfs opd_statfs;
180 cfs_time_t opd_statfs_fresh_till;
181 struct timer_list opd_statfs_timer;
182 int opd_statfs_update_in_progress;
183 /* how often to update statfs data */
184 int opd_statfs_maxage;
186 cfs_proc_dir_entry_t *opd_symlink;
189 #define opd_pre_lock opd_pre->osp_pre_lock
190 #define opd_pre_used_fid opd_pre->osp_pre_used_fid
191 #define opd_pre_last_created_fid opd_pre->osp_pre_last_created_fid
192 #define opd_pre_reserved opd_pre->osp_pre_reserved
193 #define opd_pre_user_waitq opd_pre->osp_pre_user_waitq
194 #define opd_pre_status opd_pre->osp_pre_status
195 #define opd_pre_grow_count opd_pre->osp_pre_grow_count
196 #define opd_pre_min_grow_count opd_pre->osp_pre_min_grow_count
197 #define opd_pre_max_grow_count opd_pre->osp_pre_max_grow_count
198 #define opd_pre_grow_slow opd_pre->osp_pre_grow_slow
199 #define opd_pre_recovering opd_pre->osp_pre_recovering
201 extern struct kmem_cache *osp_object_kmem;
203 /* this is a top object */
205 struct lu_object_header opo_header;
206 struct dt_object opo_obj;
207 unsigned int opo_reserved:1,
211 /* read/write lock for md osp object */
212 struct rw_semaphore opo_sem;
213 const struct lu_env *opo_owner;
216 extern struct lu_object_operations osp_lu_obj_ops;
217 extern const struct dt_device_operations osp_dt_ops;
218 extern struct dt_object_operations osp_md_obj_ops;
220 struct osp_thread_info {
221 struct lu_buf osi_lb;
222 struct lu_buf osi_lb2;
223 struct lu_fid osi_fid;
224 struct lu_attr osi_attr;
225 struct ost_id osi_oi;
226 struct ost_id osi_oi2;
230 struct llog_rec_hdr osi_hdr;
231 struct llog_unlink64_rec osi_unlink;
232 struct llog_setattr64_rec osi_setattr;
233 struct llog_gen_rec osi_gen;
235 struct llog_cookie osi_cookie;
236 struct llog_catid osi_cid;
237 struct lu_seq_range osi_seq;
238 struct ldlm_res_id osi_resid;
239 struct obdo osi_obdo;
242 static inline void osp_objid_buf_prep(struct lu_buf *buf, loff_t *off,
243 __u32 *id, int index)
245 buf->lb_buf = (void *)id;
246 buf->lb_len = sizeof(obd_id);
247 *off = sizeof(obd_id) * index;
250 static inline void osp_objseq_buf_prep(struct lu_buf *buf, loff_t *off,
251 __u64 *seq, int index)
253 buf->lb_buf = (void *)seq;
254 buf->lb_len = sizeof(obd_id);
255 *off = sizeof(obd_id) * index;
258 static inline void osp_buf_prep(struct lu_buf *lb, void *buf, int buf_len)
261 lb->lb_len = buf_len;
264 extern struct lu_context_key osp_thread_key;
266 static inline struct osp_thread_info *osp_env_info(const struct lu_env *env)
268 struct osp_thread_info *info;
270 info = lu_context_key_get(&env->le_ctx, &osp_thread_key);
272 lu_env_refill((struct lu_env *)env);
273 info = lu_context_key_get(&env->le_ctx, &osp_thread_key);
279 struct osp_txn_info {
280 __u32 oti_current_id;
283 extern struct lu_context_key osp_txn_key;
285 static inline struct osp_txn_info *osp_txn_info(struct lu_context *ctx)
287 struct osp_txn_info *info;
289 info = lu_context_key_get(ctx, &osp_txn_key);
293 extern const struct lu_device_operations osp_lu_ops;
295 static inline int lu_device_is_osp(struct lu_device *d)
297 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osp_lu_ops);
300 static inline struct osp_device *lu2osp_dev(struct lu_device *d)
302 LASSERT(lu_device_is_osp(d));
303 return container_of0(d, struct osp_device, opd_dt_dev.dd_lu_dev);
306 static inline struct lu_device *osp2lu_dev(struct osp_device *d)
308 return &d->opd_dt_dev.dd_lu_dev;
311 static inline struct osp_device *dt2osp_dev(struct dt_device *d)
313 LASSERT(lu_device_is_osp(&d->dd_lu_dev));
314 return container_of0(d, struct osp_device, opd_dt_dev);
317 static inline struct osp_object *lu2osp_obj(struct lu_object *o)
319 LASSERT(ergo(o != NULL, lu_device_is_osp(o->lo_dev)));
320 return container_of0(o, struct osp_object, opo_obj.do_lu);
323 static inline struct lu_object *osp2lu_obj(struct osp_object *obj)
325 return &obj->opo_obj.do_lu;
328 static inline struct osp_object *osp_obj(const struct lu_object *o)
330 LASSERT(lu_device_is_osp(o->lo_dev));
331 return container_of0(o, struct osp_object, opo_obj.do_lu);
334 static inline struct osp_object *dt2osp_obj(const struct dt_object *d)
336 return osp_obj(&d->do_lu);
339 static inline struct dt_object *osp_object_child(struct osp_object *o)
341 return container_of0(lu_object_next(osp2lu_obj(o)),
342 struct dt_object, do_lu);
345 static inline struct seq_server_site *osp_seq_site(struct osp_device *osp)
347 return osp->opd_dt_dev.dd_lu_dev.ld_site->ld_seq_site;
350 #define osp_init_rpc_lock(lck) mdc_init_rpc_lock(lck)
351 #define osp_get_rpc_lock(lck, it) mdc_get_rpc_lock(lck, it)
352 #define osp_put_rpc_lock(lck, it) mdc_put_rpc_lock(lck, it)
354 static inline void osp_update_last_fid(struct osp_device *d, struct lu_fid *fid)
356 int diff = lu_fid_diff(fid, &d->opd_last_used_fid);
358 * we might have lost precreated objects due to VBR and precreate
359 * orphans, the gap in objid can be calculated properly only here
363 d->opd_gap_start_fid = d->opd_last_used_fid;
364 d->opd_gap_start_fid.f_oid++;
365 d->opd_gap_count = diff - 1;
366 CDEBUG(D_HA, "Gap in objids: start="DFID", count =%d\n",
367 PFID(&d->opd_gap_start_fid), d->opd_gap_count);
369 d->opd_last_used_fid = *fid;
373 static int osp_fid_end_seq(const struct lu_env *env, struct lu_fid *fid)
375 if (fid_is_idif(fid)) {
376 struct osp_thread_info *info = osp_env_info(env);
377 struct ost_id *oi = &info->osi_oi;
379 fid_to_ostid(fid, oi);
380 return ostid_id(oi) == IDIF_MAX_OID;
382 return fid_oid(fid) == LUSTRE_DATA_SEQ_MAX_WIDTH;
386 static inline int osp_precreate_end_seq_nolock(const struct lu_env *env,
387 struct osp_device *osp)
389 struct lu_fid *fid = &osp->opd_pre_last_created_fid;
391 return osp_fid_end_seq(env, fid);
394 static inline int osp_precreate_end_seq(const struct lu_env *env,
395 struct osp_device *osp)
399 spin_lock(&osp->opd_pre_lock);
400 rc = osp_precreate_end_seq_nolock(env, osp);
401 spin_unlock(&osp->opd_pre_lock);
405 static inline int osp_is_fid_client(struct osp_device *osp)
407 struct obd_import *imp = osp->opd_obd->u.cli.cl_import;
409 return imp->imp_connect_data.ocd_connect_flags & OBD_CONNECT_FID;
413 void osp_update_last_id(struct osp_device *d, obd_id objid);
414 extern struct llog_operations osp_mds_ost_orig_logops;
416 /* osp_md_object.c */
417 int osp_trans_start(const struct lu_env *env, struct dt_device *dt,
419 int osp_trans_stop(const struct lu_env *env, struct thandle *th);
420 /* osp_precreate.c */
421 int osp_init_precreate(struct osp_device *d);
422 int osp_precreate_reserve(const struct lu_env *env, struct osp_device *d);
423 __u64 osp_precreate_get_id(struct osp_device *d);
424 int osp_precreate_get_fid(const struct lu_env *env, struct osp_device *d,
426 void osp_precreate_fini(struct osp_device *d);
427 int osp_object_truncate(const struct lu_env *env, struct dt_object *dt, __u64);
428 void osp_pre_update_status(struct osp_device *d, int rc);
429 void osp_statfs_need_now(struct osp_device *d);
430 int osp_reset_last_used(const struct lu_env *env, struct osp_device *osp);
431 int osp_write_last_oid_seq_files(struct lu_env *env, struct osp_device *osp,
432 struct lu_fid *fid, int sync);
433 int osp_init_pre_fid(struct osp_device *osp);
436 void lprocfs_osp_init_vars(struct lprocfs_static_vars *lvars);
437 void osp_lprocfs_init(struct osp_device *osp);
440 int osp_sync_declare_add(const struct lu_env *env, struct osp_object *o,
441 llog_op_type type, struct thandle *th);
442 int osp_sync_add(const struct lu_env *env, struct osp_object *o,
443 llog_op_type type, struct thandle *th,
444 const struct lu_attr *attr);
445 int osp_sync_init(const struct lu_env *env, struct osp_device *d);
446 int osp_sync_fini(struct osp_device *d);
447 void __osp_sync_check_for_work(struct osp_device *d);
450 void lprocfs_lwp_init_vars(struct lprocfs_static_vars *lvars);
451 extern struct obd_ops lwp_obd_device_ops;
452 extern struct lu_device_type lwp_device_type;