+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_last_rcvd_update(const struct lu_env *env, struct lu_target *tgt,
+ struct dt_object *obj, __u64 opdata,
+ struct thandle *th, 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);
+}
+
+/*
+ * Unified target generic handers macros and generic functions.
+ */
+#define TGT_RPC_HANDLER(base, flags, opc, fn, 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 \
+}
+
+/* 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)
+
+/* 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(flags, name, fn) \
+ TGT_RPC_HANDLER(FLD_QUERY, flags, name, fn, &RQF_ ## name, \
+ LUSTRE_MDS_VERSION)
+
+/* Request with a format known in advance */
+#define TGT_UPDATE_HDL(flags, name, fn) \
+ TGT_RPC_HANDLER(UPDATE_OBJ, flags, name, fn, &RQF_ ## name, \
+ LUSTRE_MDS_VERSION)