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 <lustre_fid.h>
50 * Infrastructure to support tracking of last committed llog record
52 struct osp_id_tracker {
55 __u32 otr_committed_id;
56 /* callback is register once per diskfs -- that's the whole point */
57 struct dt_txn_callback otr_tx_cb;
58 /* single node can run many clusters */
59 cfs_list_t otr_wakeup_list;
61 /* underlying shared device */
62 struct dt_device *otr_dev;
63 /* how many users of this tracker */
64 cfs_atomic_t otr_refcount;
68 struct dt_device opd_dt_dev;
69 /* corresponded OST index */
72 /* corrsponded MDT index, which will be used when connecting to OST
73 * for validating the connection (see ofd_parse_connect_data) */
75 /* device used to store persistent state (llogs, last ids) */
76 struct obd_export *opd_storage_exp;
77 struct dt_device *opd_storage;
78 struct dt_object *opd_last_used_oid_file;
79 struct dt_object *opd_last_used_seq_file;
81 /* stored persistently in LE format, updated directly to/from disk
82 * and required le64_to_cpu() conversion before use.
83 * Protected by opd_pre_lock */
84 struct lu_fid opd_last_used_fid;
85 struct lu_fid opd_gap_start_fid;
87 /* connection to OST */
88 struct obd_device *opd_obd;
89 struct obd_export *opd_exp;
90 struct obd_uuid opd_cluuid;
91 struct obd_connect_data *opd_connect_data;
93 cfs_proc_dir_entry_t *opd_proc_entry;
94 struct lprocfs_stats *opd_stats;
95 /* connection status. */
96 int opd_new_connection;
97 int opd_got_disconnected;
98 int opd_imp_connected;
100 unsigned int opd_imp_seen_connected:1,
103 /* whether local recovery is completed:
104 * reported via ->ldo_recovery_complete() */
105 int opd_recovery_completed;
110 spinlock_t opd_pre_lock;
112 /* last fid to assign in creation */
113 struct lu_fid opd_pre_used_fid;
114 /* last created id OST reported, next-created - available id's */
115 struct lu_fid opd_pre_last_created_fid;
116 /* how many ids are reserved in declare, we shouldn't block in create */
117 __u64 opd_pre_reserved;
118 /* dedicate precreate thread */
119 struct ptlrpc_thread opd_pre_thread;
120 /* thread waits for signals about pool going empty */
121 cfs_waitq_t opd_pre_waitq;
122 /* consumers (who needs new ids) wait here */
123 cfs_waitq_t opd_pre_user_waitq;
124 /* current precreation status: working, failed, stopping? */
126 /* how many to precreate next time */
127 int opd_pre_grow_count;
128 int opd_pre_min_grow_count;
129 int opd_pre_max_grow_count;
130 /* whether to grow precreation window next time or not */
131 int opd_pre_grow_slow;
132 /* cleaning up orphans or recreating missing objects */
133 int opd_pre_recovering;
136 * OST synchronization
138 spinlock_t opd_syn_lock;
139 /* unique generation, to recognize start of new records in the llog */
140 struct llog_gen opd_syn_generation;
141 /* number of changes to sync, used to wake up sync thread */
142 unsigned long opd_syn_changes;
143 /* processing of changes from previous mount is done? */
144 int opd_syn_prev_done;
146 struct ptlrpc_thread opd_syn_thread;
147 cfs_waitq_t opd_syn_waitq;
148 /* list of remotely committed rpc */
149 cfs_list_t opd_syn_committed_there;
150 /* number of changes being under sync */
151 int opd_syn_sync_in_progress;
152 /* number of RPCs in flight - flow control */
153 int opd_syn_rpc_in_flight;
154 int opd_syn_max_rpc_in_flight;
155 /* number of RPC in processing (including non-committed by OST) */
156 int opd_syn_rpc_in_progress;
157 int opd_syn_max_rpc_in_progress;
158 /* osd api's commit cb control structure */
159 struct dt_txn_callback opd_syn_txn_cb;
160 /* last used change number -- semantically similar to transno */
161 unsigned long opd_syn_last_used_id;
162 /* last committed change number -- semantically similar to
164 unsigned long opd_syn_last_committed_id;
165 /* last processed (taken from llog) id */
166 unsigned long opd_syn_last_processed_id;
167 struct osp_id_tracker *opd_syn_tracker;
168 cfs_list_t opd_syn_ontrack;
171 * statfs related fields: OSP maintains it on its own
173 struct obd_statfs opd_statfs;
174 cfs_time_t opd_statfs_fresh_till;
175 cfs_timer_t opd_statfs_timer;
176 int opd_statfs_update_in_progress;
177 /* how often to update statfs data */
178 int opd_statfs_maxage;
180 cfs_proc_dir_entry_t *opd_symlink;
183 extern cfs_mem_cache_t *osp_object_kmem;
185 /* this is a top object */
187 struct lu_object_header opo_header;
188 struct dt_object opo_obj;
189 unsigned int opo_reserved:1,
193 /* read/write lock for md osp object */
194 struct rw_semaphore opo_sem;
195 const struct lu_env *opo_owner;
198 extern struct lu_object_operations osp_lu_obj_ops;
199 extern const struct dt_device_operations osp_dt_ops;
200 extern struct dt_object_operations osp_md_obj_ops;
202 struct osp_thread_info {
203 struct lu_buf osi_lb;
204 struct lu_buf osi_lb2;
205 struct lu_fid osi_fid;
206 struct lu_attr osi_attr;
207 struct ost_id osi_oi;
208 struct ost_id osi_oi2;
212 struct llog_rec_hdr osi_hdr;
213 struct llog_unlink64_rec osi_unlink;
214 struct llog_setattr64_rec osi_setattr;
215 struct llog_gen_rec osi_gen;
217 struct llog_cookie osi_cookie;
218 struct llog_catid osi_cid;
219 struct lu_seq_range osi_seq;
220 struct ldlm_res_id osi_resid;
221 struct obdo osi_obdo;
224 static inline void osp_objid_buf_prep(struct lu_buf *buf, loff_t *off,
225 __u32 *id, int index)
227 buf->lb_buf = (void *)id;
228 buf->lb_len = sizeof(obd_id);
229 *off = sizeof(obd_id) * index;
232 static inline void osp_objseq_buf_prep(struct lu_buf *buf, loff_t *off,
233 __u64 *seq, int index)
235 buf->lb_buf = (void *)seq;
236 buf->lb_len = sizeof(obd_id);
237 *off = sizeof(obd_id) * index;
240 static inline void osp_buf_prep(struct lu_buf *lb, void *buf, int buf_len)
243 lb->lb_len = buf_len;
246 extern struct lu_context_key osp_thread_key;
248 static inline struct osp_thread_info *osp_env_info(const struct lu_env *env)
250 struct osp_thread_info *info;
252 info = lu_context_key_get(&env->le_ctx, &osp_thread_key);
254 lu_env_refill((struct lu_env *)env);
255 info = lu_context_key_get(&env->le_ctx, &osp_thread_key);
261 struct osp_txn_info {
262 __u32 oti_current_id;
265 extern struct lu_context_key osp_txn_key;
267 static inline struct osp_txn_info *osp_txn_info(struct lu_context *ctx)
269 struct osp_txn_info *info;
271 info = lu_context_key_get(ctx, &osp_txn_key);
275 extern const struct lu_device_operations osp_lu_ops;
277 static inline int lu_device_is_osp(struct lu_device *d)
279 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osp_lu_ops);
282 static inline struct osp_device *lu2osp_dev(struct lu_device *d)
284 LASSERT(lu_device_is_osp(d));
285 return container_of0(d, struct osp_device, opd_dt_dev.dd_lu_dev);
288 static inline struct lu_device *osp2lu_dev(struct osp_device *d)
290 return &d->opd_dt_dev.dd_lu_dev;
293 static inline struct osp_device *dt2osp_dev(struct dt_device *d)
295 LASSERT(lu_device_is_osp(&d->dd_lu_dev));
296 return container_of0(d, struct osp_device, opd_dt_dev);
299 static inline struct osp_object *lu2osp_obj(struct lu_object *o)
301 LASSERT(ergo(o != NULL, lu_device_is_osp(o->lo_dev)));
302 return container_of0(o, struct osp_object, opo_obj.do_lu);
305 static inline struct lu_object *osp2lu_obj(struct osp_object *obj)
307 return &obj->opo_obj.do_lu;
310 static inline struct osp_object *osp_obj(const struct lu_object *o)
312 LASSERT(lu_device_is_osp(o->lo_dev));
313 return container_of0(o, struct osp_object, opo_obj.do_lu);
316 static inline struct osp_object *dt2osp_obj(const struct dt_object *d)
318 return osp_obj(&d->do_lu);
321 static inline struct dt_object *osp_object_child(struct osp_object *o)
323 return container_of0(lu_object_next(osp2lu_obj(o)),
324 struct dt_object, do_lu);
327 #define osp_init_rpc_lock(lck) mdc_init_rpc_lock(lck)
328 #define osp_get_rpc_lock(lck, it) mdc_get_rpc_lock(lck, it)
329 #define osp_put_rpc_lock(lck, it) mdc_put_rpc_lock(lck, it)
331 static inline void osp_update_last_fid(struct osp_device *d, struct lu_fid *fid)
333 int diff = lu_fid_diff(fid, &d->opd_last_used_fid);
335 * we might have lost precreated objects due to VBR and precreate
336 * orphans, the gap in objid can be calculated properly only here
340 d->opd_gap_start_fid = d->opd_last_used_fid;
341 d->opd_gap_start_fid.f_oid++;
342 d->opd_gap_count = diff - 1;
343 CDEBUG(D_HA, "Gap in objids: start="DFID", count =%d\n",
344 PFID(&d->opd_gap_start_fid), d->opd_gap_count);
346 d->opd_last_used_fid = *fid;
350 static int osp_fid_end_seq(const struct lu_env *env, struct lu_fid *fid)
352 if (fid_is_idif(fid)) {
353 struct osp_thread_info *info = osp_env_info(env);
354 struct ost_id *oi = &info->osi_oi;
356 fid_to_ostid(fid, oi);
357 return ostid_id(oi) == IDIF_MAX_OID;
359 return fid_oid(fid) == LUSTRE_DATA_SEQ_MAX_WIDTH;
363 static inline int osp_precreate_end_seq_nolock(const struct lu_env *env,
364 struct osp_device *osp)
366 struct lu_fid *fid = &osp->opd_pre_last_created_fid;
368 return osp_fid_end_seq(env, fid);
371 static inline int osp_precreate_end_seq(const struct lu_env *env,
372 struct osp_device *osp)
376 spin_lock(&osp->opd_pre_lock);
377 rc = osp_precreate_end_seq_nolock(env, osp);
378 spin_unlock(&osp->opd_pre_lock);
382 static inline int osp_is_fid_client(struct osp_device *osp)
384 struct obd_import *imp = osp->opd_obd->u.cli.cl_import;
386 return imp->imp_connect_data.ocd_connect_flags & OBD_CONNECT_FID;
390 void osp_update_last_id(struct osp_device *d, obd_id objid);
391 extern struct llog_operations osp_mds_ost_orig_logops;
393 /* osp_md_object.c */
394 int osp_trans_start(const struct lu_env *env, struct dt_device *dt,
396 int osp_trans_stop(const struct lu_env *env, struct thandle *th);
397 /* osp_precreate.c */
398 int osp_init_precreate(struct osp_device *d);
399 int osp_precreate_reserve(const struct lu_env *env, struct osp_device *d);
400 __u64 osp_precreate_get_id(struct osp_device *d);
401 int osp_precreate_get_fid(const struct lu_env *env, struct osp_device *d,
403 void osp_precreate_fini(struct osp_device *d);
404 int osp_object_truncate(const struct lu_env *env, struct dt_object *dt, __u64);
405 void osp_pre_update_status(struct osp_device *d, int rc);
406 void osp_statfs_need_now(struct osp_device *d);
407 int osp_reset_last_used(const struct lu_env *env, struct osp_device *osp);
408 int osp_write_last_oid_seq_files(struct lu_env *env, struct osp_device *osp,
409 struct lu_fid *fid, int sync);
412 void lprocfs_osp_init_vars(struct lprocfs_static_vars *lvars);
413 void osp_lprocfs_init(struct osp_device *osp);
416 int osp_sync_declare_add(const struct lu_env *env, struct osp_object *o,
417 llog_op_type type, struct thandle *th);
418 int osp_sync_add(const struct lu_env *env, struct osp_object *o,
419 llog_op_type type, struct thandle *th,
420 const struct lu_attr *attr);
421 int osp_sync_init(const struct lu_env *env, struct osp_device *d);
422 int osp_sync_fini(struct osp_device *d);
423 void __osp_sync_check_for_work(struct osp_device *d);
426 void lprocfs_lwp_init_vars(struct lprocfs_static_vars *lvars);
427 extern struct obd_ops lwp_obd_device_ops;
428 extern struct lu_device_type lwp_device_type;