From c1c329fdb6f528affd505f79f3740cc5c7c9edca Mon Sep 17 00:00:00 2001 From: tappro Date: Sun, 16 Jul 2006 12:50:41 +0000 Subject: [PATCH] add transaction callbacks to the MDT, use them to manage the transno, last_commited/etc --- lustre/mdt/mdt_fs.c | 38 ++++++++++++++++++++++++++++----- lustre/mdt/mdt_handler.c | 54 +++++++++++++++++++++++++++++++++++++++++------ lustre/mdt/mdt_internal.h | 6 ++++++ 3 files changed, 87 insertions(+), 11 deletions(-) diff --git a/lustre/mdt/mdt_fs.c b/lustre/mdt/mdt_fs.c index 97a8866..0524fba 100644 --- a/lustre/mdt/mdt_fs.c +++ b/lustre/mdt/mdt_fs.c @@ -394,6 +394,7 @@ out: /* * 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 */ @@ -404,26 +405,53 @@ static int mdt_txn_start_cb(const struct lu_context *ctx, 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; } diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 3384d08..c84e853 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -952,15 +952,20 @@ static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags) } /* 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) { @@ -982,9 +987,11 @@ int mdt_update_last_transno(struct mdt_thread_info *info, int rc) /*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; @@ -1067,6 +1074,7 @@ static int mdt_req_handle(struct mdt_thread_info *info, } /* 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) { @@ -2562,7 +2570,7 @@ static struct obd_ops mdt_obd_device_ops = { .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) @@ -2626,14 +2634,48 @@ static struct lu_context_key mdt_thread_key = { .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 = { diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 1e1d45b..b48ca65 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -247,6 +247,12 @@ struct mdt_thread_info { char ns_name[48]; } mti_u; }; +/* + * Info allocated per-transaction. + */ +struct mdt_txn_info { + __u64 txi_transno; +}; static inline struct md_device_operations *mdt_child_ops(struct mdt_device * m) { -- 1.8.3.1