/*
* last_rcvd update callbacks
*/
+extern struct lu_context_key mdt_txn_key;
#define MDT_TXN_LAST_RCVD_CREDITS 1
/* add credits for last_rcvd update */
param->tp_credits += MDT_TXN_LAST_RCVD_CREDITS;
return 0;
}
+
/* Update last_rcvd records with latests transaction data */
static int mdt_txn_stop_cb(const struct lu_context *ctx,
struct dt_device *dev,
struct thandle *txn, void *cookie)
{
-/*
struct mdt_device *mdt = cookie;
+ struct mdt_txn_info *txni, *thdi;
+
+ /* transno in two contexts - for commit_cb and for thread */
+ txni = lu_context_key_get(&txn->th_ctx, &mdt_txn_key);
+ thdi = lu_context_key_get(ctx, &mdt_txn_key);
+ /*TODO: checks for recovery cases, see mds_finish_transno */
+ spin_lock(&mdt->mdt_transno_lock);
+ if (thdi->txi_transno == 0) {
+ thdi->txi_transno = ++ mdt->mdt_last_transno;
+ } else {
+ /* replay */
+ if (thdi->txi_transno > mdt->mdt_last_transno)
+ mdt->mdt_last_transno = thdi->txi_transno;
+ }
+ spin_unlock(&mdt->mdt_transno_lock);
+
+ txni->txi_transno = thdi->txi_transno;
+/*
TODO: write last_rcvd
*/
return 0;
}
-/*
- * commit callback, need to update last_commited value */
+
+/* commit callback, need to update last_commited value */
static int mdt_txn_commit_cb(const struct lu_context *ctx,
struct dt_device *dev,
struct thandle *txn, void *cookie)
{
struct mdt_device *mdt = cookie;
- /* TODO: update mdt_last_commited, need current transno here */
- ++ mdt->mdt_last_committed;
+ struct obd_device *obd = md2lu_dev(&mdt->mdt_md_dev)->ld_obd;
+ struct mdt_txn_info *txi;
+
+ txi = lu_context_key_get(&txn->th_ctx, &mdt_txn_key);
+ if (txi->txi_transno > mdt->mdt_last_committed) {
+ mdt->mdt_last_committed = txi->txi_transno;
+ ptlrpc_commit_replies (obd);
+ }
+ CDEBUG(D_HA, "%s: transno "LPD64" committed\n",
+ obd->obd_name, txi->txi_transno);
+
return 0;
}
}
/* FIXME: fake untill journal callback is OK.*/
+struct lu_context_key mdt_txn_key;
+
int mdt_update_last_transno(struct mdt_thread_info *info, int rc)
{
- __u64 last_transno;
- __u64 last_committed;
struct mdt_device *mdt = info->mti_mdt;
struct ptlrpc_request * req = mdt_info_req(info);
+ struct mdt_txn_info *txi;
+ __u64 last_transno;
+ __u64 last_committed;
LASSERT(mdt != NULL);
+ last_committed = mdt->mdt_last_committed;
+#if 0
last_transno = req->rq_reqmsg->transno;
if (rc != 0) {
if (last_transno != 0) {
/*last_committed = (mdt->mdt_last_committed);*/
last_committed = last_transno;
-
+#endif
+ txi = lu_context_key_get(info->mti_ctxt, &mdt_txn_key);
+ last_transno = txi->txi_transno;
CDEBUG(D_INFO, "last_transno = %llu, last_committed = %llu\n",
- last_transno, last_committed);
+ last_transno, last_committed);
req->rq_repmsg->transno = req->rq_transno = last_transno;
req->rq_repmsg->last_xid = req->rq_xid;
req->rq_repmsg->last_committed = last_committed;
}
/* If we're DISCONNECTing, the mdt_export_data is already freed */
+
if (h->mh_opc != MDS_DISCONNECT &&
h->mh_opc != MDS_READPAGE &&
h->mh_opc != LDLM_ENQUEUE) {
.o_disconnect = mdt_obd_disconnect,
.o_init_export = mdt_init_export, /* By Huang Hua*/
.o_destroy_export = mdt_destroy_export, /* By Huang Hua*/
- .o_notify = mdt_notify,
+ //.o_notify = mdt_notify,
};
static void mdt_device_free(const struct lu_context *ctx, struct lu_device *d)
.lct_fini = mdt_thread_fini
};
+static void *mdt_txn_init(const struct lu_context *ctx,
+ struct lu_context_key *key)
+{
+ struct mdt_txn_info *txi;
+
+ /*
+ * check that no high order allocations are incurred.
+ */
+ CLASSERT(CFS_PAGE_SIZE >= sizeof *txi);
+ OBD_ALLOC_PTR(txi);
+ if (txi == NULL)
+ txi = ERR_PTR(-ENOMEM);
+ return txi;
+}
+
+static void mdt_txn_fini(const struct lu_context *ctx,
+ struct lu_context_key *key, void *data)
+{
+ struct mdt_txn_info *txi = data;
+ OBD_FREE_PTR(txi);
+}
+
+struct lu_context_key mdt_txn_key = {
+ .lct_init = mdt_txn_init,
+ .lct_fini = mdt_txn_fini
+};
+
+
static int mdt_type_init(struct lu_device_type *t)
{
- return lu_context_key_register(&mdt_thread_key);
+ int rc;
+
+ rc = lu_context_key_register(&mdt_thread_key);
+ if (rc == 0)
+ rc = lu_context_key_register(&mdt_txn_key);
+ return rc;
}
static void mdt_type_fini(struct lu_device_type *t)
{
lu_context_key_degister(&mdt_thread_key);
+ lu_context_key_degister(&mdt_txn_key);
}
static struct lu_device_type_operations mdt_device_type_ops = {