+#define OSD_MAX_CACHE_SIZE OBD_OBJECT_EOF
+
+extern const struct dt_index_operations osd_otable_ops;
+
+static inline int osd_oi_fid2idx(struct osd_device *dev,
+ const struct lu_fid *fid)
+{
+ return fid->f_seq & (dev->od_oi_count - 1);
+}
+
+static inline struct osd_oi *osd_fid2oi(struct osd_device *osd,
+ const struct lu_fid *fid)
+{
+ LASSERTF(!fid_is_idif(fid), DFID"\n", PFID(fid));
+ LASSERTF(!fid_is_last_id(fid), DFID"\n", PFID(fid));
+ LASSERT(osd->od_oi_table != NULL && osd->od_oi_count >= 1);
+ /* It can work even od_oi_count equals to 1 although it's unexpected,
+ * the only reason we set it to 1 is for performance measurement */
+ return osd->od_oi_table[osd_oi_fid2idx(osd, fid)];
+}
+
+extern const struct lu_device_operations osd_lu_ops;
+
+static inline int lu_device_is_osd(const struct lu_device *d)
+{
+ return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osd_lu_ops);
+}
+
+static inline struct osd_device *osd_dt_dev(const struct dt_device *d)
+{
+ LASSERT(lu_device_is_osd(&d->dd_lu_dev));
+ return container_of0(d, struct osd_device, od_dt_dev);
+}
+
+static inline struct osd_device *osd_dev(const struct lu_device *d)
+{
+ LASSERT(lu_device_is_osd(d));
+ return osd_dt_dev(container_of0(d, struct dt_device, dd_lu_dev));
+}
+
+static inline struct osd_device *osd_obj2dev(const struct osd_object *o)
+{
+ return osd_dev(o->oo_dt.do_lu.lo_dev);
+}
+
+static inline struct super_block *osd_sb(const struct osd_device *dev)
+{
+ return dev->od_mnt->mnt_sb;
+}
+
+static inline int osd_object_is_root(const struct osd_object *obj)
+{
+ return osd_sb(osd_obj2dev(obj))->s_root->d_inode == obj->oo_inode;
+}
+
+static inline struct osd_object *osd_obj(const struct lu_object *o)
+{
+ LASSERT(lu_device_is_osd(o->lo_dev));
+ return container_of0(o, struct osd_object, oo_dt.do_lu);
+}
+
+static inline struct osd_object *osd_dt_obj(const struct dt_object *d)
+{
+ return osd_obj(&d->do_lu);
+}
+
+static inline struct lu_device *osd2lu_dev(struct osd_device *osd)
+{
+ return &osd->od_dt_dev.dd_lu_dev;
+}
+
+static inline journal_t *osd_journal(const struct osd_device *dev)
+{
+ return LDISKFS_SB(osd_sb(dev))->s_journal;
+}
+
+static inline struct seq_server_site *osd_seq_site(struct osd_device *osd)
+{
+ return osd->od_dt_dev.dd_lu_dev.ld_site->ld_seq_site;
+}
+
+static inline char *osd_name(struct osd_device *osd)
+{
+ return osd->od_dt_dev.dd_lu_dev.ld_obd->obd_name;
+}
+
+
+extern const struct dt_body_operations osd_body_ops;
+extern struct lu_context_key osd_key;
+
+static inline struct osd_thread_info *osd_oti_get(const struct lu_env *env)
+{
+ return lu_context_key_get(&env->le_ctx, &osd_key);
+}
+
+extern const struct dt_body_operations osd_body_ops_new;
+
+/**
+ * IAM Iterator
+ */
+static inline
+struct iam_path_descr *osd_it_ipd_get(const struct lu_env *env,
+ const struct iam_container *bag)
+{
+ return bag->ic_descr->id_ops->id_ipd_alloc(bag,
+ osd_oti_get(env)->oti_it_ipd);
+}
+
+static inline
+struct iam_path_descr *osd_idx_ipd_get(const struct lu_env *env,
+ const struct iam_container *bag)
+{
+ return bag->ic_descr->id_ops->id_ipd_alloc(bag,
+ osd_oti_get(env)->oti_idx_ipd);
+}
+
+static inline void osd_ipd_put(const struct lu_env *env,
+ const struct iam_container *bag,
+ struct iam_path_descr *ipd)
+{
+ bag->ic_descr->id_ops->id_ipd_free(ipd);
+}
+
+int osd_ldiskfs_read(struct inode *inode, void *buf, int size, loff_t *offs);
+int osd_ldiskfs_write_record(struct inode *inode, void *buf, int bufsize,
+ int write_NUL, loff_t *offs, handle_t *handle);
+
+static inline
+struct dentry *osd_child_dentry_by_inode(const struct lu_env *env,
+ struct inode *inode,
+ const char *name, const int namelen)
+{
+ struct osd_thread_info *info = osd_oti_get(env);
+ struct dentry *child_dentry = &info->oti_child_dentry;
+ struct dentry *obj_dentry = &info->oti_obj_dentry;
+
+ obj_dentry->d_inode = inode;
+ obj_dentry->d_sb = inode->i_sb;
+ obj_dentry->d_name.hash = 0;
+
+ child_dentry->d_name.hash = 0;
+ child_dentry->d_parent = obj_dentry;
+ child_dentry->d_name.name = name;
+ child_dentry->d_name.len = namelen;
+ return child_dentry;
+}
+
+#ifdef OSD_TRACK_DECLARES
+extern int osd_trans_declare_op2rb[];
+
+static inline void osd_trans_declare_op(const struct lu_env *env,
+ struct osd_thandle *oh,
+ unsigned int op, int credits)
+{
+ struct osd_thread_info *oti = osd_oti_get(env);
+
+ LASSERT(oh->ot_handle == NULL);
+ LASSERT(op < OSD_OT_MAX);
+
+ oti->oti_declare_ops[op]++;
+ oti->oti_declare_ops_cred[op] += credits;
+ oh->ot_credits += credits;
+}
+
+static inline void osd_trans_exec_op(const struct lu_env *env,
+ struct thandle *th, unsigned int op)
+{
+ struct osd_thread_info *oti = osd_oti_get(env);
+ struct osd_thandle *oh = container_of(th, struct osd_thandle,
+ ot_super);
+ unsigned int rb;
+
+ LASSERT(oh->ot_handle != NULL);
+ LASSERT(op < OSD_OT_MAX);
+
+ if (likely(!oti->oti_rollback && oti->oti_declare_ops[op] > 0)) {
+ oti->oti_declare_ops[op]--;
+ oti->oti_declare_ops_rb[op]++;
+ } else {
+ /* all future updates are considered rollback */
+ oti->oti_rollback = true;
+ rb = osd_trans_declare_op2rb[op];
+ LASSERTF(rb < OSD_OT_MAX, "op = %u\n", op);
+ LASSERTF(oti->oti_declare_ops_rb[rb] > 0, "rb = %u\n", rb);
+ oti->oti_declare_ops_rb[rb]--;
+ }
+}
+
+static inline void osd_trans_declare_rb(const struct lu_env *env,
+ struct thandle *th, unsigned int op)
+{
+ struct osd_thread_info *oti = osd_oti_get(env);
+ struct osd_thandle *oh = container_of(th, struct osd_thandle,
+ ot_super);
+
+ LASSERT(oh->ot_handle != NULL);
+ LASSERT(op < OSD_OT_MAX);
+
+ oti->oti_declare_ops_rb[op]++;
+}
+#else
+static inline void osd_trans_declare_op(const struct lu_env *env,
+ struct osd_thandle *oh,
+ unsigned int op, int credits)
+{
+ oh->ot_credits += credits;
+}
+
+static inline void osd_trans_exec_op(const struct lu_env *env,
+ struct thandle *th, unsigned int op)
+{
+}
+
+static inline void osd_trans_declare_rb(const struct lu_env *env,
+ struct thandle *th, unsigned int op)
+{
+}
+#endif
+
+/**
+ * Helper function to pack the fid, ldiskfs stores fid in packed format.