From 56b8ed7592e53226e356bced53147d365c5024e6 Mon Sep 17 00:00:00 2001 From: Avra Sengupta Date: Fri, 17 Jan 2014 05:51:17 +0000 Subject: glusterd/vol-locks: Dict_ref while adding req_ctx->dict to txn_opinfos Introducing a wrapper function glusterd_txn_opinfo_init(), to initialize the opinfo to be set in the txn_id engine. Removed glusterd_op_fini_ctx() as the txn opinfo should only be cleared by glusterd_clear_txn_opinfo(). Change-Id: I17e85a162d6a3bca79941f8603d0c2b579f0d194 Signed-off-by: Avra Sengupta --- xlators/mgmt/glusterd/src/glusterd-handler.c | 44 ++++++------ xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c | 7 +- xlators/mgmt/glusterd/src/glusterd-op-sm.c | 85 ++++++++++------------- xlators/mgmt/glusterd/src/glusterd-op-sm.h | 5 +- xlators/mgmt/glusterd/src/glusterd-syncop.c | 2 +- xlators/mgmt/glusterd/src/glusterd.c | 4 +- xlators/mgmt/glusterd/src/glusterd.h | 7 +- 7 files changed, 71 insertions(+), 83 deletions(-) (limited to 'xlators') diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index a95989cc9..d109e11bd 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -695,14 +695,14 @@ local_locking_done: } /* Save opinfo for this transaction with the transaction id */ - txn_op_info.op = op; - txn_op_info.op_ctx = ctx; - txn_op_info.req = req; + glusterd_txn_opinfo_init (&txn_op_info, NULL, &op, ctx, req); ret = glusterd_set_txn_opinfo (txn_id, &txn_op_info); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Unable to set transaction's opinfo"); + if (ctx) + dict_unref (ctx); goto out; } @@ -739,13 +739,15 @@ out: int __glusterd_handle_cluster_lock (rpcsvc_request_t *req) { - gd1_mgmt_cluster_lock_req lock_req = {{0},}; - int32_t ret = -1; - glusterd_op_lock_ctx_t *ctx = NULL; - glusterd_peerinfo_t *peerinfo = NULL; - xlator_t *this = NULL; - uuid_t *txn_id = &global_txn_id; + dict_t *op_ctx = NULL; + int32_t ret = -1; + gd1_mgmt_cluster_lock_req lock_req = {{0},}; + glusterd_op_lock_ctx_t *ctx = NULL; + glusterd_op_t op = GD_OP_EVENT_LOCK; + glusterd_peerinfo_t *peerinfo = NULL; glusterd_op_info_t txn_op_info = {{0},}; + uuid_t *txn_id = &global_txn_id; + xlator_t *this = NULL; this = THIS; GF_ASSERT (this); @@ -782,20 +784,20 @@ __glusterd_handle_cluster_lock (rpcsvc_request_t *req) ctx->req = req; ctx->dict = NULL; - txn_op_info.op = GD_OP_EVENT_LOCK; - txn_op_info.op_ctx = dict_new (); - if (!txn_op_info.op_ctx) { + op_ctx = dict_new (); + if (!op_ctx) { gf_log (this->name, GF_LOG_ERROR, "Unable to set new dict"); goto out; } - txn_op_info.req = req; + + glusterd_txn_opinfo_init (&txn_op_info, NULL, &op, op_ctx, req); ret = glusterd_set_txn_opinfo (txn_id, &txn_op_info); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Unable to set transaction's opinfo"); - dict_destroy (txn_op_info.op_ctx); + dict_unref (txn_op_info.op_ctx); goto out; } @@ -880,6 +882,7 @@ __glusterd_handle_stage_op (rpcsvc_request_t *req) xlator_t *this = NULL; uuid_t *txn_id = &global_txn_id; glusterd_op_info_t txn_op_info = {{0},}; + glusterd_op_sm_state_info_t state; this = THIS; GF_ASSERT (this); @@ -917,19 +920,18 @@ __glusterd_handle_stage_op (rpcsvc_request_t *req) * phase where the transaction opinfos are created, won't be called. */ ret = glusterd_get_txn_opinfo (txn_id, &txn_op_info); if (ret) { - gf_log (this->name, GF_LOG_ERROR, - "Unable to get transaction's opinfo"); + gf_log (this->name, GF_LOG_DEBUG, + "No transaction's opinfo set"); - txn_op_info.op = op_req.op; - txn_op_info.state.state = GD_OP_STATE_LOCKED; - txn_op_info.op_ctx = req_ctx->dict; - txn_op_info.req = req; + state.state = GD_OP_STATE_LOCKED; + glusterd_txn_opinfo_init (&txn_op_info, &state, + &op_req.op, req_ctx->dict, req); ret = glusterd_set_txn_opinfo (txn_id, &txn_op_info); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Unable to set transaction's opinfo"); - dict_destroy (req_ctx->dict); + dict_unref (req_ctx->dict); goto out; } } diff --git a/xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c b/xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c index 2ebe372cc..f4ecc486f 100644 --- a/xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c @@ -108,14 +108,15 @@ glusterd_op_state_machine_volume_lock (rpcsvc_request_t *req, GF_ASSERT (this); GF_ASSERT (req); - txn_op_info.op = lock_req->op; - txn_op_info.op_ctx = ctx->dict; - txn_op_info.req = req; + glusterd_txn_opinfo_init (&txn_op_info, NULL, &lock_req->op, + ctx->dict, req); ret = glusterd_set_txn_opinfo (&lock_req->txn_id, &txn_op_info); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Unable to set transaction's opinfo"); + if (ctx->dict) + dict_unref (ctx->dict); goto out; } diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 28c58f036..88c8858de 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -81,7 +81,7 @@ struct txn_opinfo_object_ { typedef struct txn_opinfo_object_ txn_opinfo_obj; int32_t -glusterd_txn_opinfo_init () +glusterd_txn_opinfo_dict_init () { int32_t ret = -1; @@ -97,12 +97,35 @@ out: } void -glusterd_txn_opinfo_fini () +glusterd_txn_opinfo_dict_fini () { if (txn_opinfo) dict_destroy (txn_opinfo); } +void +glusterd_txn_opinfo_init (glusterd_op_info_t *opinfo, + glusterd_op_sm_state_info_t *state, + glusterd_op_t *op, + dict_t *op_ctx, + rpcsvc_request_t *req) +{ + GF_ASSERT (opinfo); + + if (state) + opinfo->state = *state; + + if (op) + opinfo->op = *op; + + opinfo->op_ctx = dict_ref(op_ctx); + + if (req) + opinfo->req = req; + + return; +} + int32_t glusterd_get_txn_opinfo (uuid_t *txn_id, glusterd_op_info_t *opinfo) { @@ -179,7 +202,8 @@ out: int32_t glusterd_clear_txn_opinfo (uuid_t *txn_id) { - int32_t ret = -1; + int32_t ret = -1; + glusterd_op_info_t txn_op_info = {{0},}; if (!txn_id) { gf_log ("", GF_LOG_ERROR, "Empty transaction id received."); @@ -187,6 +211,14 @@ glusterd_clear_txn_opinfo (uuid_t *txn_id) goto out; } + ret = glusterd_get_txn_opinfo (txn_id, &txn_op_info); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Transaction opinfo not found"); + goto out; + } + + dict_unref (txn_op_info.op_ctx); + dict_del(txn_opinfo, uuid_utoa (*txn_id)); ret = 0; @@ -4277,7 +4309,6 @@ glusterd_op_ac_commit_op (glusterd_op_sm_event_t *event, void *ctx) ret = glusterd_op_commit_send_resp (req_ctx->req, req_ctx->op, status, op_errstr, rsp_dict); - glusterd_op_fini_ctx (); if (op_errstr && (strcmp (op_errstr, ""))) GF_FREE (op_errstr); @@ -4306,7 +4337,6 @@ glusterd_op_ac_send_commit_failed (glusterd_op_sm_event_t *event, void *ctx) opinfo.op_ret, opinfo.op_errstr, op_ctx); - glusterd_op_fini_ctx (); if (opinfo.op_errstr && (strcmp (opinfo.op_errstr, ""))) { GF_FREE (opinfo.op_errstr); opinfo.op_errstr = NULL; @@ -6173,51 +6203,6 @@ glusterd_op_clear_op (glusterd_op_t op) } -int32_t -glusterd_op_init_ctx (glusterd_op_t op, glusterd_op_info_t *op_info) -{ - int ret = 0; - dict_t *dict = NULL; - xlator_t *this = NULL; - - this = THIS; - GF_ASSERT (this); - GF_ASSERT (GD_OP_NONE < op && op < GD_OP_MAX); - - if (_gf_false == glusterd_need_brick_op (op)) { - gf_log (this->name, GF_LOG_DEBUG, "Received op: %s, returning", - gd_op_list[op]); - goto out; - } - dict = dict_new (); - if (dict == NULL) { - ret = -1; - goto out; - } - - op_info->op_ctx = dict; -out: - gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret); - return ret; -} - - - -int32_t -glusterd_op_fini_ctx () -{ - dict_t *dict = NULL; - - dict = glusterd_op_get_ctx (); - if (dict) - dict_unref (dict); - - glusterd_op_reset_ctx (); - return 0; -} - - - int32_t glusterd_op_free_ctx (glusterd_op_t op, void *ctx) { diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h index 09da6b9f7..cf57b78e0 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h @@ -261,10 +261,7 @@ glusterd_op_init_commit_rsp_dict (glusterd_op_t op); void glusterd_op_modify_op_ctx (glusterd_op_t op, void *op_ctx); -int32_t -glusterd_op_init_ctx (glusterd_op_t op, glusterd_op_info_t *op_info); -int32_t -glusterd_op_fini_ctx (); + int32_t glusterd_volume_stats_read_perf (char *brick_path, int32_t blk_size, int32_t blk_count, double *throughput, double *time); diff --git a/xlators/mgmt/glusterd/src/glusterd-syncop.c b/xlators/mgmt/glusterd/src/glusterd-syncop.c index 2b2a2ec1c..fe3cb1f33 100644 --- a/xlators/mgmt/glusterd/src/glusterd-syncop.c +++ b/xlators/mgmt/glusterd/src/glusterd-syncop.c @@ -1543,7 +1543,7 @@ gd_sync_task_begin (dict_t *op_ctx, rpcsvc_request_t * req) local_locking_done: /* Save opinfo for this transaction with the transaction id */ - txn_opinfo.op = op; + glusterd_txn_opinfo_init (&txn_opinfo, NULL, &op, NULL, NULL); ret = glusterd_set_txn_opinfo (txn_id, &txn_opinfo); if (ret) gf_log (this->name, GF_LOG_ERROR, diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c index 42fd8a725..c2806bdfa 100644 --- a/xlators/mgmt/glusterd/src/glusterd.c +++ b/xlators/mgmt/glusterd/src/glusterd.c @@ -1331,7 +1331,7 @@ init (xlator_t *this) glusterd_op_sm_init (); glusterd_opinfo_init (); glusterd_vol_lock_init (); - glusterd_txn_opinfo_init (); + glusterd_txn_opinfo_dict_init (); ret = glusterd_sm_tr_log_init (&conf->op_sm_log, glusterd_op_sm_state_name_get, glusterd_op_sm_event_name_get, @@ -1452,7 +1452,7 @@ fini (xlator_t *this) gf_store_handle_destroy (conf->handle); glusterd_sm_tr_log_delete (&conf->op_sm_log); glusterd_vol_lock_fini (); - glusterd_txn_opinfo_fini (); + glusterd_txn_opinfo_dict_fini (); GF_FREE (conf); this->private = NULL; diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index b8f048817..8997e7555 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -874,10 +874,13 @@ int32_t glusterd_defrag_event_notify_handle (dict_t *dict); int32_t -glusterd_txn_opinfo_init (); +glusterd_txn_opinfo_dict_init (); + +void +glusterd_txn_opinfo_dict_fini (); void -glusterd_txn_opinfo_fini (); +glusterd_txn_opinfo_init (); /* snapshot */ glusterd_snap_t* -- cgit