+static inline struct seq_server_site *osp_seq_site(struct osp_device *osp)
+{
+ return osp->opd_dt_dev.dd_lu_dev.ld_site->ld_seq_site;
+}
+
+#define osp_init_rpc_lock(lck) mdc_init_rpc_lock(lck)
+
+static inline void osp_get_rpc_lock(struct osp_device *osp)
+{
+ struct mdc_rpc_lock *rpc_lock = osp->opd_obd->u.cli.cl_rpc_lock;
+
+ mdc_get_rpc_lock(rpc_lock, NULL);
+}
+
+static inline void osp_put_rpc_lock(struct osp_device *osp)
+{
+ struct mdc_rpc_lock *rpc_lock = osp->opd_obd->u.cli.cl_rpc_lock;
+
+ mdc_put_rpc_lock(rpc_lock, NULL);
+}
+
+static inline int osp_fid_diff(const struct lu_fid *fid1,
+ const struct lu_fid *fid2)
+{
+ /* In 2.6+ ost_idx is packed into IDIF FID, while in 2.4 and 2.5 IDIF
+ * is always FID_SEQ_IDIF(0x100000000ULL), which does not include OST
+ * index in the seq. So we can not compare IDIF FID seq here */
+ if (fid_is_idif(fid1) && fid_is_idif(fid2)) {
+ __u32 ost_idx1 = fid_idif_ost_idx(fid1);
+ __u32 ost_idx2 = fid_idif_ost_idx(fid2);
+
+ LASSERTF(ost_idx1 == 0 || ost_idx2 == 0 || ost_idx1 == ost_idx2,
+ "fid1: "DFID", fid2: "DFID"\n", PFID(fid1),
+ PFID(fid2));
+
+ return fid_idif_id(fid1->f_seq, fid1->f_oid, 0) -
+ fid_idif_id(fid2->f_seq, fid2->f_oid, 0);
+ }
+
+ LASSERTF(fid_seq(fid1) == fid_seq(fid2), "fid1:"DFID
+ ", fid2:"DFID"\n", PFID(fid1), PFID(fid2));
+
+ return fid_oid(fid1) - fid_oid(fid2);
+}
+
+
+static inline void osp_update_last_fid(struct osp_device *d, struct lu_fid *fid)
+{
+ int diff = osp_fid_diff(fid, &d->opd_last_used_fid);
+ /*
+ * we might have lost precreated objects due to VBR and precreate
+ * orphans, the gap in objid can be calculated properly only here
+ */
+ if (diff > 0) {
+ if (diff > 1) {
+ d->opd_gap_start_fid = d->opd_last_used_fid;
+ d->opd_gap_start_fid.f_oid++;
+ d->opd_gap_count = diff - 1;
+ CDEBUG(D_HA, "Gap in objids: start="DFID", count =%d\n",
+ PFID(&d->opd_gap_start_fid), d->opd_gap_count);
+ }
+ d->opd_last_used_fid = *fid;
+ }
+}
+
+static int osp_fid_end_seq(const struct lu_env *env, struct lu_fid *fid)
+{
+ if (fid_is_idif(fid)) {
+ struct osp_thread_info *info = osp_env_info(env);
+ struct ost_id *oi = &info->osi_oi;
+
+ fid_to_ostid(fid, oi);
+ return ostid_id(oi) == IDIF_MAX_OID;
+ } else {
+ return fid_oid(fid) == LUSTRE_DATA_SEQ_MAX_WIDTH;
+ }
+}
+
+static inline int osp_precreate_end_seq_nolock(const struct lu_env *env,
+ struct osp_device *osp)
+{
+ struct lu_fid *fid = &osp->opd_pre_last_created_fid;
+
+ return osp_fid_end_seq(env, fid);
+}
+
+static inline int osp_precreate_end_seq(const struct lu_env *env,
+ struct osp_device *osp)
+{
+ int rc;
+
+ spin_lock(&osp->opd_pre_lock);
+ rc = osp_precreate_end_seq_nolock(env, osp);
+ spin_unlock(&osp->opd_pre_lock);
+ return rc;
+}
+
+static inline int osp_is_fid_client(struct osp_device *osp)
+{
+ struct obd_import *imp = osp->opd_obd->u.cli.cl_import;
+
+ return imp->imp_connect_data.ocd_connect_flags & OBD_CONNECT_FID;
+}
+
+struct object_update *
+update_buffer_get_update(struct object_update_request *request,
+ unsigned int index);
+
+int osp_extend_update_buffer(const struct lu_env *env,
+ struct osp_update_request *our);
+
+struct osp_update_request_sub *
+osp_current_object_update_request(struct osp_update_request *our);
+
+int osp_object_update_request_create(struct osp_update_request *our,
+ size_t size);
+
+#define osp_update_rpc_pack(env, name, our, op, ...) \
+({ \
+ struct object_update *object_update; \
+ size_t max_update_length; \
+ struct osp_update_request_sub *ours; \
+ int ret; \
+ \
+ while (1) { \
+ ours = osp_current_object_update_request(our); \
+ LASSERT(ours != NULL); \
+ max_update_length = ours->ours_req_size - \
+ object_update_request_size(ours->ours_req); \
+ \
+ object_update = update_buffer_get_update(ours->ours_req,\
+ ours->ours_req->ourq_count); \
+ ret = out_##name##_pack(env, object_update, \
+ &max_update_length, \
+ __VA_ARGS__); \
+ if (ret == -E2BIG) { \
+ int rc1; \
+ /* Create new object update request */ \
+ rc1 = osp_object_update_request_create(our, \
+ max_update_length + \
+ offsetof(struct object_update_request, \
+ ourq_updates[0]) + 1); \
+ if (rc1 != 0) { \
+ ret = rc1; \
+ break; \
+ } \
+ continue; \
+ } else { \
+ if (ret == 0) { \
+ ours->ours_req->ourq_count++; \
+ (our)->our_update_nr++; \
+ object_update->ou_batchid = \
+ (our)->our_batchid;\
+ object_update->ou_flags |= \
+ (our)->our_flags; \
+ } \
+ break; \
+ } \
+ } \
+ ret; \
+})
+
+static inline bool osp_send_update_thread_running(struct osp_device *osp)
+{
+ return osp->opd_update_thread.t_flags & SVC_RUNNING;
+}
+
+static inline bool osp_send_update_thread_stopped(struct osp_device *osp)
+{
+ return osp->opd_update_thread.t_flags & SVC_STOPPED;
+}
+
+typedef int (*osp_update_interpreter_t)(const struct lu_env *env,
+ struct object_update_reply *rep,
+ struct ptlrpc_request *req,
+ struct osp_object *obj,
+ void *data, int index, int rc);
+
+/* osp_dev.c */
+void osp_update_last_id(struct osp_device *d, u64 objid);
+extern struct llog_operations osp_mds_ost_orig_logops;
+
+/* osp_trans.c */
+int osp_insert_async_request(const struct lu_env *env, enum update_type op,
+ struct osp_object *obj, int count, __u16 *lens,
+ const void **bufs, void *data, __u32 repsize,
+ osp_update_interpreter_t interpreter);
+
+int osp_unplug_async_request(const struct lu_env *env,
+ struct osp_device *osp,
+ struct osp_update_request *update);
+int osp_trans_update_request_create(struct thandle *th);
+struct thandle *osp_trans_create(const struct lu_env *env,
+ struct dt_device *d);
+int osp_trans_start(const struct lu_env *env, struct dt_device *dt,
+ struct thandle *th);
+int osp_insert_update_callback(const struct lu_env *env,
+ struct osp_update_request *update,
+ struct osp_object *obj, void *data,
+ osp_update_interpreter_t interpreter);
+
+struct osp_update_request *osp_update_request_create(struct dt_device *dt);
+void osp_update_request_destroy(struct osp_update_request *update);
+
+int osp_send_update_thread(void *arg);
+int osp_check_and_set_rpc_version(struct osp_thandle *oth,
+ struct osp_object *obj);
+
+void osp_thandle_destroy(struct osp_thandle *oth);
+static inline void osp_thandle_get(struct osp_thandle *oth)
+{
+ atomic_inc(&oth->ot_refcount);
+}
+
+static inline void osp_thandle_put(struct osp_thandle *oth)
+{
+ if (atomic_dec_and_test(&oth->ot_refcount))
+ osp_thandle_destroy(oth);
+}
+
+int osp_prep_update_req(const struct lu_env *env, struct obd_import *imp,
+ struct osp_update_request *our,
+ struct ptlrpc_request **reqp);
+int osp_remote_sync(const struct lu_env *env, struct osp_device *osp,
+ struct osp_update_request *update,
+ struct ptlrpc_request **reqp);
+
+struct thandle *osp_get_storage_thandle(const struct lu_env *env,
+ struct thandle *th,
+ struct osp_device *osp);
+void osp_trans_callback(const struct lu_env *env,
+ struct osp_thandle *oth, int rc);
+void osp_invalidate_request(struct osp_device *osp);
+/* osp_object.c */
+int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
+ struct lu_attr *attr);
+int osp_xattr_get(const struct lu_env *env, struct dt_object *dt,
+ struct lu_buf *buf, const char *name);
+int osp_declare_xattr_set(const struct lu_env *env, struct dt_object *dt,
+ const struct lu_buf *buf, const char *name,
+ int flag, struct thandle *th);
+int osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
+ const struct lu_buf *buf, const char *name, int fl,
+ struct thandle *th);
+int osp_declare_xattr_del(const struct lu_env *env, struct dt_object *dt,
+ const char *name, struct thandle *th);
+int osp_xattr_del(const struct lu_env *env, struct dt_object *dt,
+ const char *name, struct thandle *th);
+
+int osp_trans_stop(const struct lu_env *env, struct dt_device *dt,
+ struct thandle *th);
+int osp_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb);
+
+struct dt_it *osp_it_init(const struct lu_env *env, struct dt_object *dt,
+ __u32 attr);
+void osp_it_fini(const struct lu_env *env, struct dt_it *di);
+int osp_it_get(const struct lu_env *env, struct dt_it *di,
+ const struct dt_key *key);
+void osp_it_put(const struct lu_env *env, struct dt_it *di);
+__u64 osp_it_store(const struct lu_env *env, const struct dt_it *di);
+int osp_it_key_rec(const struct lu_env *env, const struct dt_it *di,
+ void *key_rec);
+int osp_it_next_page(const struct lu_env *env, struct dt_it *di);
+int osp_oac_init(struct osp_object *obj);
+/* osp_md_object.c */
+int osp_md_declare_object_create(const struct lu_env *env,
+ struct dt_object *dt,
+ struct lu_attr *attr,
+ struct dt_allocation_hint *hint,
+ struct dt_object_format *dof,
+ struct thandle *th);
+int osp_md_object_create(const struct lu_env *env, struct dt_object *dt,
+ struct lu_attr *attr, struct dt_allocation_hint *hint,
+ struct dt_object_format *dof, struct thandle *th);
+int osp_md_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
+ const struct lu_attr *attr, struct thandle *th);
+int osp_md_attr_set(const struct lu_env *env, struct dt_object *dt,
+ const struct lu_attr *attr, struct thandle *th);
+extern const struct dt_index_operations osp_md_index_ops;
+
+/* osp_precreate.c */
+int osp_init_precreate(struct osp_device *d);
+int osp_precreate_reserve(const struct lu_env *env, struct osp_device *d);
+__u64 osp_precreate_get_id(struct osp_device *d);
+int osp_precreate_get_fid(const struct lu_env *env, struct osp_device *d,
+ struct lu_fid *fid);
+void osp_precreate_fini(struct osp_device *d);
+int osp_object_truncate(const struct lu_env *env, struct dt_object *dt, __u64);
+void osp_pre_update_status(struct osp_device *d, int rc);
+void osp_statfs_need_now(struct osp_device *d);
+int osp_reset_last_used(const struct lu_env *env, struct osp_device *osp);
+int osp_write_last_oid_seq_files(struct lu_env *env, struct osp_device *osp,
+ struct lu_fid *fid, int sync);
+int osp_init_pre_fid(struct osp_device *osp);
+