+int tgt_server_data_update(const struct lu_env *env, struct lu_target *tg,
+ int sync);
+int tgt_truncate_last_rcvd(const struct lu_env *env, struct lu_target *tg,
+ loff_t off);
+int tgt_reply_data_init(const struct lu_env *env, struct lu_target *tgt);
+bool tgt_lookup_reply(struct ptlrpc_request *req, struct tg_reply_data *trd);
+int tgt_add_reply_data(const struct lu_env *env, struct lu_target *tgt,
+ struct tg_export_data *ted, struct tg_reply_data *trd,
+ struct thandle *th, bool update_lrd_file);
+struct tg_reply_data *tgt_lookup_reply_by_xid(struct tg_export_data *ted,
+ __u64 xid);
+
+/* target/update_trans.c */
+int distribute_txn_init(const struct lu_env *env,
+ struct lu_target *lut,
+ struct target_distribute_txn_data *tdtd,
+ __u32 index);
+void distribute_txn_fini(const struct lu_env *env,
+ struct target_distribute_txn_data *tdtd);
+
+/* target/update_recovery.c */
+int insert_update_records_to_replay_list(struct target_distribute_txn_data *,
+ struct llog_update_record *,
+ struct llog_cookie *, __u32);
+void dtrq_list_dump(struct target_distribute_txn_data *tdtd,
+ unsigned int mask);
+void dtrq_list_destroy(struct target_distribute_txn_data *tdtd);
+int distribute_txn_replay_handle(struct lu_env *env,
+ struct target_distribute_txn_data *tdtd,
+ struct distribute_txn_replay_req *dtrq);
+__u64 distribute_txn_get_next_transno(struct target_distribute_txn_data *tdtd);
+struct distribute_txn_replay_req *
+distribute_txn_get_next_req(struct target_distribute_txn_data *tdtd);
+void dtrq_destroy(struct distribute_txn_replay_req *dtrq);
+struct distribute_txn_replay_req_sub *
+dtrq_sub_lookup(struct distribute_txn_replay_req *dtrq, __u32 mdt_index);
+struct distribute_txn_replay_req *
+distribute_txn_lookup_finish_list(struct target_distribute_txn_data *tdtd,
+ __u64 transno);
+bool is_req_replayed_by_update(struct ptlrpc_request *req);
+enum {
+ ESERIOUS = 0x0001000
+};
+
+static inline int err_serious(int rc)
+{
+ LASSERT(rc < 0);
+ return -(-rc | ESERIOUS);
+}
+
+static inline int clear_serious(int rc)
+{
+ if (rc < 0)
+ rc = -(-rc & ~ESERIOUS);
+ return rc;
+}
+
+static inline int is_serious(int rc)
+{
+ return (rc < 0 && -rc & ESERIOUS);
+}
+
+/**
+ * Do not return server-side uid/gid to remote client
+ */
+static inline void tgt_drop_id(struct obd_export *exp, struct obdo *oa)
+{
+ if (unlikely(exp_connect_rmtclient(exp))) {
+ oa->o_uid = -1;
+ oa->o_gid = -1;
+ oa->o_valid &= ~(OBD_MD_FLUID | OBD_MD_FLGID);
+ }
+}
+
+/*
+ * Unified target generic handers macros and generic functions.
+ */
+#define TGT_RPC_HANDLER_HP(base, flags, opc, fn, hp, fmt, version) \
+[opc - base] = { \
+ .th_name = #opc, \
+ .th_fail_id = OBD_FAIL_ ## opc ## _NET, \
+ .th_opc = opc, \
+ .th_flags = flags, \
+ .th_act = fn, \
+ .th_fmt = fmt, \
+ .th_version = version, \
+ .th_hp = hp, \
+}
+#define TGT_RPC_HANDLER(base, flags, opc, fn, fmt, version) \
+ TGT_RPC_HANDLER_HP(base, flags, opc, fn, NULL, fmt, version)
+
+/* MDT Request with a format known in advance */
+#define TGT_MDT_HDL(flags, name, fn) \
+ TGT_RPC_HANDLER(MDS_FIRST_OPC, flags, name, fn, &RQF_ ## name, \
+ LUSTRE_MDS_VERSION)
+/* Request with a format we do not yet know */
+#define TGT_MDT_HDL_VAR(flags, name, fn) \
+ TGT_RPC_HANDLER(MDS_FIRST_OPC, flags, name, fn, NULL, \
+ LUSTRE_MDS_VERSION)
+
+/* OST Request with a format known in advance */
+#define TGT_OST_HDL(flags, name, fn) \
+ TGT_RPC_HANDLER(OST_FIRST_OPC, flags, name, fn, &RQF_ ## name, \
+ LUSTRE_OST_VERSION)
+#define TGT_OST_HDL_HP(flags, name, fn, hp) \
+ TGT_RPC_HANDLER_HP(OST_FIRST_OPC, flags, name, fn, hp, \
+ &RQF_ ## name, LUSTRE_OST_VERSION)
+
+/* MGS request with a format known in advance */
+#define TGT_MGS_HDL(flags, name, fn) \
+ TGT_RPC_HANDLER(MGS_FIRST_OPC, flags, name, fn, &RQF_ ## name, \
+ LUSTRE_MGS_VERSION)
+#define TGT_MGS_HDL_VAR(flags, name, fn) \
+ TGT_RPC_HANDLER(MGS_FIRST_OPC, flags, name, fn, NULL, \
+ LUSTRE_MGS_VERSION)
+
+/*
+ * OBD handler macros and generic functions.
+ */
+#define TGT_OBD_HDL(flags, name, fn) \
+ TGT_RPC_HANDLER(OBD_FIRST_OPC, flags, name, fn, &RQF_ ## name, \
+ LUSTRE_OBD_VERSION)
+#define TGT_OBD_HDL_VAR(flags, name, fn) \
+ TGT_RPC_HANDLER(OBD_FIRST_OPC, flags, name, fn, NULL, \
+ LUSTRE_OBD_VERSION)
+
+/*
+ * DLM handler macros and generic functions.
+ */
+#define TGT_DLM_HDL_VAR(flags, name, fn) \
+ TGT_RPC_HANDLER(LDLM_FIRST_OPC, flags, name, fn, NULL, \
+ LUSTRE_DLM_VERSION)
+#define TGT_DLM_HDL(flags, name, fn) \
+ TGT_RPC_HANDLER(LDLM_FIRST_OPC, flags, name, fn, &RQF_ ## name, \
+ LUSTRE_DLM_VERSION)
+
+/*
+ * LLOG handler macros and generic functions.
+ */
+#define TGT_LLOG_HDL_VAR(flags, name, fn) \
+ TGT_RPC_HANDLER(LLOG_FIRST_OPC, flags, name, fn, NULL, \
+ LUSTRE_LOG_VERSION)
+#define TGT_LLOG_HDL(flags, name, fn) \
+ TGT_RPC_HANDLER(LLOG_FIRST_OPC, flags, name, fn, &RQF_ ## name, \
+ LUSTRE_LOG_VERSION)
+
+/*
+ * Sec context handler macros and generic functions.
+ */
+#define TGT_SEC_HDL_VAR(flags, name, fn) \
+ TGT_RPC_HANDLER(SEC_FIRST_OPC, flags, name, fn, NULL, \
+ LUSTRE_OBD_VERSION)
+
+#define TGT_QUOTA_HDL(flags, name, fn) \
+ TGT_RPC_HANDLER(QUOTA_DQACQ, flags, name, fn, &RQF_ ## name, \
+ LUSTRE_MDS_VERSION)
+
+/* Sequence service handlers */
+#define TGT_SEQ_HDL(flags, name, fn) \
+ TGT_RPC_HANDLER(SEQ_QUERY, flags, name, fn, &RQF_ ## name, \
+ LUSTRE_MDS_VERSION)
+
+/* FID Location Database handlers */
+#define TGT_FLD_HDL_VAR(flags, name, fn) \
+ TGT_RPC_HANDLER(FLD_QUERY, flags, name, fn, NULL, \
+ LUSTRE_MDS_VERSION)
+
+/* LFSCK handlers */
+#define TGT_LFSCK_HDL(flags, name, fn) \
+ TGT_RPC_HANDLER(LFSCK_FIRST_OPC, flags, name, fn, \
+ &RQF_ ## name, LUSTRE_OBD_VERSION)
+
+/* Request with a format known in advance */
+#define TGT_UPDATE_HDL(flags, name, fn) \
+ TGT_RPC_HANDLER(OUT_UPDATE, flags, name, fn, &RQF_ ## name, \
+ LUSTRE_MDS_VERSION)