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, 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 */
71 /* device used to store persistent state (llogs, last ids) */
72 struct obd_export *opd_storage_exp;
73 struct dt_device *opd_storage;
74 struct dt_object *opd_last_used_oid_file;
75 struct dt_object *opd_last_used_seq_file;
77 /* stored persistently in LE format, updated directly to/from disk
78 * and required le64_to_cpu() conversion before use.
79 * Protected by opd_pre_lock */
80 struct lu_fid opd_last_used_fid;
81 struct lu_fid opd_gap_start_fid;
83 /* connection to OST */
84 struct obd_device *opd_obd;
85 struct obd_export *opd_exp;
86 struct obd_uuid opd_cluuid;
87 struct obd_connect_data *opd_connect_data;
89 cfs_proc_dir_entry_t *opd_proc_entry;
90 struct lprocfs_stats *opd_stats;
91 /* connection status. */
92 int opd_new_connection;
93 int opd_got_disconnected;
94 int opd_imp_connected;
96 int opd_imp_seen_connected:1,
99 /* whether local recovery is completed:
100 * reported via ->ldo_recovery_complete() */
101 int opd_recovery_completed;
106 spinlock_t opd_pre_lock;
108 /* last fid to assign in creation */
109 struct lu_fid opd_pre_used_fid;
110 /* last created id OST reported, next-created - available id's */
111 struct lu_fid opd_pre_last_created_fid;
112 /* how many ids are reserved in declare, we shouldn't block in create */
113 __u64 opd_pre_reserved;
114 /* dedicate precreate thread */
115 struct ptlrpc_thread opd_pre_thread;
116 /* thread waits for signals about pool going empty */
117 cfs_waitq_t opd_pre_waitq;
118 /* consumers (who needs new ids) wait here */
119 cfs_waitq_t opd_pre_user_waitq;
120 /* current precreation status: working, failed, stopping? */
122 /* how many to precreate next time */
123 int opd_pre_grow_count;
124 int opd_pre_min_grow_count;
125 int opd_pre_max_grow_count;
126 /* whether to grow precreation window next time or not */
127 int opd_pre_grow_slow;
128 /* cleaning up orphans or recreating missing objects */
129 int opd_pre_recovering;
132 * OST synchronization
134 spinlock_t opd_syn_lock;
135 /* unique generation, to recognize start of new records in the llog */
136 struct llog_gen opd_syn_generation;
137 /* number of changes to sync, used to wake up sync thread */
138 unsigned long opd_syn_changes;
139 /* processing of changes from previous mount is done? */
140 int opd_syn_prev_done;
142 struct ptlrpc_thread opd_syn_thread;
143 cfs_waitq_t opd_syn_waitq;
144 /* list of remotely committed rpc */
145 cfs_list_t opd_syn_committed_there;
146 /* number of changes being under sync */
147 int opd_syn_sync_in_progress;
148 /* number of RPCs in flight - flow control */
149 int opd_syn_rpc_in_flight;
150 int opd_syn_max_rpc_in_flight;
151 /* number of RPC in processing (including non-committed by OST) */
152 int opd_syn_rpc_in_progress;
153 int opd_syn_max_rpc_in_progress;
154 /* osd api's commit cb control structure */
155 struct dt_txn_callback opd_syn_txn_cb;
156 /* last used change number -- semantically similar to transno */
157 unsigned long opd_syn_last_used_id;
158 /* last committed change number -- semantically similar to
160 unsigned long opd_syn_last_committed_id;
161 /* last processed (taken from llog) id */
162 unsigned long opd_syn_last_processed_id;
163 struct osp_id_tracker *opd_syn_tracker;
164 cfs_list_t opd_syn_ontrack;
167 * statfs related fields: OSP maintains it on its own
169 struct obd_statfs opd_statfs;
170 cfs_time_t opd_statfs_fresh_till;
171 cfs_timer_t opd_statfs_timer;
172 int opd_statfs_update_in_progress;
173 /* how often to update statfs data */
174 int opd_statfs_maxage;
176 cfs_proc_dir_entry_t *opd_symlink;
179 extern cfs_mem_cache_t *osp_object_kmem;
181 /* this is a top object */
183 struct lu_object_header opo_header;
184 struct dt_object opo_obj;
189 /* read/write lock for md osp object */
190 struct rw_semaphore opo_sem;
191 const struct lu_env *opo_owner;
194 extern struct lu_object_operations osp_lu_obj_ops;
195 extern const struct dt_device_operations osp_dt_ops;
196 extern struct dt_object_operations osp_md_obj_ops;
197 extern struct dt_lock_operations osp_md_lock_ops;
199 struct osp_thread_info {
200 struct lu_buf osi_lb;
201 struct lu_buf osi_lb2;
202 struct lu_fid osi_fid;
203 struct lu_attr osi_attr;
204 struct ost_id osi_oi;
205 struct ost_id osi_oi2;
209 struct llog_rec_hdr osi_hdr;
210 struct llog_unlink64_rec osi_unlink;
211 struct llog_setattr64_rec osi_setattr;
212 struct llog_gen_rec osi_gen;
214 struct llog_cookie osi_cookie;
215 struct llog_catid osi_cid;
216 struct lu_seq_range osi_seq;
217 struct ldlm_res_id osi_resid;
218 struct obdo osi_obdo;
221 static inline void osp_objid_buf_prep(struct lu_buf *buf, loff_t *off,
222 __u32 *id, int index)
224 buf->lb_buf = (void *)id;
225 buf->lb_len = sizeof(obd_id);
226 *off = sizeof(obd_id) * index;
229 static inline void osp_objseq_buf_prep(struct lu_buf *buf, loff_t *off,
230 __u64 *seq, int index)
232 buf->lb_buf = (void *)seq;
233 buf->lb_len = sizeof(obd_id);
234 *off = sizeof(obd_id) * index;
237 static inline void osp_buf_prep(struct lu_buf *lb, void *buf, int buf_len)
240 lb->lb_len = buf_len;
243 extern struct lu_context_key osp_thread_key;
245 static inline struct osp_thread_info *osp_env_info(const struct lu_env *env)
247 struct osp_thread_info *info;
249 info = lu_context_key_get(&env->le_ctx, &osp_thread_key);
251 lu_env_refill((struct lu_env *)env);
252 info = lu_context_key_get(&env->le_ctx, &osp_thread_key);
258 struct osp_txn_info {
259 __u32 oti_current_id;
262 extern struct lu_context_key osp_txn_key;
264 static inline struct osp_txn_info *osp_txn_info(struct lu_context *ctx)
266 struct osp_txn_info *info;
268 info = lu_context_key_get(ctx, &osp_txn_key);
272 extern const struct lu_device_operations osp_lu_ops;
274 static inline int lu_device_is_osp(struct lu_device *d)
276 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osp_lu_ops);
279 static inline struct osp_device *lu2osp_dev(struct lu_device *d)
281 LASSERT(lu_device_is_osp(d));
282 return container_of0(d, struct osp_device, opd_dt_dev.dd_lu_dev);
285 static inline struct lu_device *osp2lu_dev(struct osp_device *d)
287 return &d->opd_dt_dev.dd_lu_dev;
290 static inline struct osp_device *dt2osp_dev(struct dt_device *d)
292 LASSERT(lu_device_is_osp(&d->dd_lu_dev));
293 return container_of0(d, struct osp_device, opd_dt_dev);
296 static inline struct osp_object *lu2osp_obj(struct lu_object *o)
298 LASSERT(ergo(o != NULL, lu_device_is_osp(o->lo_dev)));
299 return container_of0(o, struct osp_object, opo_obj.do_lu);
302 static inline struct lu_object *osp2lu_obj(struct osp_object *obj)
304 return &obj->opo_obj.do_lu;
307 static inline struct osp_object *osp_obj(const struct lu_object *o)
309 LASSERT(lu_device_is_osp(o->lo_dev));
310 return container_of0(o, struct osp_object, opo_obj.do_lu);
313 static inline struct osp_object *dt2osp_obj(const struct dt_object *d)
315 return osp_obj(&d->do_lu);
318 static inline struct dt_object *osp_object_child(struct osp_object *o)
320 return container_of0(lu_object_next(osp2lu_obj(o)),
321 struct dt_object, do_lu);
324 #define osp_init_rpc_lock(lck) mdc_init_rpc_lock(lck)
325 #define osp_get_rpc_lock(lck, it) mdc_get_rpc_lock(lck, it)
326 #define osp_put_rpc_lock(lck, it) mdc_put_rpc_lock(lck, it)
328 static inline void osp_update_last_fid(struct osp_device *d, struct lu_fid *fid)
330 int diff = lu_fid_diff(fid, &d->opd_last_used_fid);
332 * we might have lost precreated objects due to VBR and precreate
333 * orphans, the gap in objid can be calculated properly only here
337 d->opd_gap_start_fid = d->opd_last_used_fid;
338 d->opd_gap_start_fid.f_oid++;
339 d->opd_gap_count = diff - 1;
340 CDEBUG(D_HA, "Gap in objids: start="DFID", count =%d\n",
341 PFID(&d->opd_gap_start_fid), d->opd_gap_count);
343 d->opd_last_used_fid = *fid;
347 static int osp_fid_end_seq(const struct lu_env *env, struct lu_fid *fid)
349 if (fid_is_idif(fid)) {
350 struct osp_thread_info *info = osp_env_info(env);
351 struct ost_id *oi = &info->osi_oi;
353 fid_ostid_pack(fid, oi);
354 return oi->oi_id == IDIF_MAX_OID;
356 return fid_oid(fid) == LUSTRE_DATA_SEQ_MAX_WIDTH;
360 static inline int osp_precreate_end_seq_nolock(const struct lu_env *env,
361 struct osp_device *osp)
363 struct lu_fid *fid = &osp->opd_pre_last_created_fid;
365 return osp_fid_end_seq(env, fid);
368 static inline int osp_precreate_end_seq(const struct lu_env *env,
369 struct osp_device *osp)
373 spin_lock(&osp->opd_pre_lock);
374 rc = osp_precreate_end_seq_nolock(env, osp);
375 spin_unlock(&osp->opd_pre_lock);
379 static inline int osp_is_fid_client(struct osp_device *osp)
381 struct obd_import *imp = osp->opd_obd->u.cli.cl_import;
383 return imp->imp_connect_data.ocd_connect_flags & OBD_CONNECT_FID;
387 void osp_update_last_id(struct osp_device *d, obd_id objid);
388 extern struct llog_operations osp_mds_ost_orig_logops;
390 /* osp_md_object.c */
391 int osp_trans_start(const struct lu_env *env, struct dt_device *dt,
393 int osp_trans_stop(const struct lu_env *env, struct thandle *th);
394 /* osp_precreate.c */
395 int osp_init_precreate(struct osp_device *d);
396 int osp_precreate_reserve(const struct lu_env *env, struct osp_device *d);
397 __u64 osp_precreate_get_id(struct osp_device *d);
398 int osp_precreate_get_fid(const struct lu_env *env, struct osp_device *d,
400 void osp_precreate_fini(struct osp_device *d);
401 int osp_object_truncate(const struct lu_env *env, struct dt_object *dt, __u64);
402 void osp_pre_update_status(struct osp_device *d, int rc);
403 void osp_statfs_need_now(struct osp_device *d);
404 int osp_reset_last_used(const struct lu_env *env, struct osp_device *osp);
405 int osp_write_last_oid_seq_files(struct lu_env *env, struct osp_device *osp,
406 struct lu_fid *fid, int sync);
409 void lprocfs_osp_init_vars(struct lprocfs_static_vars *lvars);
410 void osp_lprocfs_init(struct osp_device *osp);
413 int osp_sync_declare_add(const struct lu_env *env, struct osp_object *o,
414 llog_op_type type, struct thandle *th);
415 int osp_sync_add(const struct lu_env *env, struct osp_object *o,
416 llog_op_type type, struct thandle *th,
417 const struct lu_attr *attr);
418 int osp_sync_init(const struct lu_env *env, struct osp_device *d);
419 int osp_sync_fini(struct osp_device *d);
420 void __osp_sync_check_for_work(struct osp_device *d);
423 void lprocfs_lwp_init_vars(struct lprocfs_static_vars *lvars);
424 extern struct obd_ops lwp_obd_device_ops;
425 extern struct lu_device_type lwp_device_type;