From 7ef59472f10a69c90d94b73e97bca385c6b4b29e Mon Sep 17 00:00:00 2001 From: Pranith K Date: Mon, 7 Mar 2011 07:23:51 +0000 Subject: mgmt/glusterd: preserve delete volume payload structure for backward compatibility Signed-off-by: Pranith Kumar K Signed-off-by: Anand V. Avati BUG: 2494 ([glusterfs-3.1.3qa4]: replace brick and delete volume fails) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2494 --- xlators/mgmt/glusterd/src/glusterd-handler.c | 53 +++++++++++++++++++++------- xlators/mgmt/glusterd/src/glusterd-op-sm.c | 40 +++++++++------------ xlators/mgmt/glusterd/src/glusterd-op-sm.h | 4 +-- xlators/mgmt/glusterd/src/glusterd-rpc-ops.c | 42 +++++++++++++++------- 4 files changed, 89 insertions(+), 50 deletions(-) (limited to 'xlators') diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index 3856de86fc7..b3e92965420 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -444,6 +444,8 @@ glusterd_handle_stage_op (rpcsvc_request_t *req) int32_t ret = -1; gd1_mgmt_stage_op_req stage_req = {{0,}}; glusterd_op_stage_ctx_t *ctx = NULL; + char volname[GLUSTERD_MAX_VOLUME_NAME] = {0}; + char *dup_volname = NULL; GF_ASSERT (req); @@ -473,13 +475,25 @@ glusterd_handle_stage_op (rpcsvc_request_t *req) if (!stage_req.buf.buf_val) goto out; - ret = dict_unserialize (stage_req.buf.buf_val, - stage_req.buf.buf_len, - &ctx->dict); + if (GD_OP_DELETE_VOLUME == stage_req.op) { + strncpy (volname, stage_req.buf.buf_val, stage_req.buf.buf_len); + dup_volname = gf_strdup (volname); + if (dup_volname) { + ret = dict_set_dynstr (ctx->dict, "volname", dup_volname); + if (ret) + gf_log ("", GF_LOG_WARNING, + "failed to set volume name from payload"); + } - if (ret) - gf_log ("", GF_LOG_WARNING, - "failed to unserialize the dictionary"); + } else { + ret = dict_unserialize (stage_req.buf.buf_val, + stage_req.buf.buf_len, + &ctx->dict); + + if (ret) + gf_log ("", GF_LOG_WARNING, + "failed to unserialize the dictionary"); + } ret = glusterd_op_sm_inject_event (GD_OP_EVENT_STAGE_OP, ctx); @@ -499,6 +513,8 @@ glusterd_handle_commit_op (rpcsvc_request_t *req) int32_t ret = -1; gd1_mgmt_commit_op_req commit_req = {{0},}; glusterd_op_commit_ctx_t *ctx = NULL; + char volname[GLUSTERD_MAX_VOLUME_NAME] = {0}; + char *dup_volname = NULL; GF_ASSERT (req); @@ -531,12 +547,25 @@ glusterd_handle_commit_op (rpcsvc_request_t *req) if (!commit_req.buf.buf_val) goto out; - ret = dict_unserialize (commit_req.buf.buf_val, - commit_req.buf.buf_len, - &ctx->dict); - if (ret) - gf_log ("", GF_LOG_WARNING, - "failed to unserialize the dictionary"); + if (GD_OP_DELETE_VOLUME == commit_req.op) { + strncpy (volname, commit_req.buf.buf_val, commit_req.buf.buf_len); + dup_volname = gf_strdup (volname); + if (dup_volname) { + ret = dict_set_dynstr (ctx->dict, "volname", dup_volname); + if (ret) + gf_log ("", GF_LOG_WARNING, + "failed to set volume name from payload"); + } + + } else { + ret = dict_unserialize (commit_req.buf.buf_val, + commit_req.buf.buf_len, + &ctx->dict); + + if (ret) + gf_log ("", GF_LOG_WARNING, + "failed to unserialize the dictionary"); + } ret = glusterd_op_sm_inject_event (GD_OP_EVENT_COMMIT_OP, ctx); diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 2f6053ab85a..a25f4909b10 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -4757,10 +4757,6 @@ glusterd_op_build_payload (glusterd_op_t op, dict_t **req) if (!req_dict) goto out; - ret = dict_set_int32 (req_dict, "operation", op); - if (ret) - gf_log ("", GF_LOG_WARNING, "failed to set op"); - ctx = (void*)glusterd_op_get_ctx (op); if (!ctx) { gf_log ("", GF_LOG_ERROR, "Null Context for " @@ -4857,7 +4853,7 @@ glusterd_op_ac_send_stage_op (glusterd_op_sm_event_t *event, void *ctx) goto out; /* rsp_dict NULL from source */ - ret = glusterd_op_stage_validate (dict, &op_errstr, NULL); + ret = glusterd_op_stage_validate (i, dict, &op_errstr, NULL); if (ret) { gf_log ("", GF_LOG_ERROR, "Staging failed"); opinfo.op_errstr = op_errstr; @@ -4891,6 +4887,8 @@ glusterd_op_ac_send_stage_op (glusterd_op_sm_event_t *event, void *ctx) opinfo.pending_count = pending_count; out: + if (dict) + dict_unref (dict); if (ret) { glusterd_op_sm_inject_event (GD_OP_EVENT_RCVD_RJT, NULL); opinfo.op_ret = ret; @@ -4953,6 +4951,7 @@ glusterd_op_ac_send_commit_op (glusterd_op_sm_event_t *event, void *ctx) glusterd_conf_t *priv = NULL; xlator_t *this = NULL; dict_t *dict = NULL; + dict_t *op_dict = NULL; glusterd_peerinfo_t *peerinfo = NULL; char *op_errstr = NULL; int i = 0; @@ -4980,7 +4979,7 @@ glusterd_op_ac_send_commit_op (glusterd_op_sm_event_t *event, void *ctx) if (ret) goto out; - ret = glusterd_op_commit_perform (dict, &op_errstr, NULL); //rsp_dict invalid for source + ret = glusterd_op_commit_perform (i, dict, &op_errstr, NULL); //rsp_dict invalid for source if (ret) { gf_log ("", GF_LOG_ERROR, "Commit failed"); opinfo.op_errstr = op_errstr; @@ -5015,20 +5014,22 @@ glusterd_op_ac_send_commit_op (glusterd_op_sm_event_t *event, void *ctx) gf_log ("glusterd", GF_LOG_NORMAL, "Sent op req to %d peers", opinfo.pending_count); out: + if (dict) + dict_unref (dict); if (ret) { glusterd_op_sm_inject_event (GD_OP_EVENT_RCVD_RJT, NULL); opinfo.op_ret = ret; } if (!opinfo.pending_count) { - dict = glusterd_op_get_ctx (GD_OP_REPLACE_BRICK); - if (!dict) { + op_dict = glusterd_op_get_ctx (GD_OP_REPLACE_BRICK); + if (!op_dict) { ret = glusterd_op_sm_inject_all_acc (); goto err; } - dict = dict_ref (dict); - ret = glusterd_op_start_rb_timer (dict); + op_dict = dict_ref (op_dict); + ret = glusterd_op_start_rb_timer (op_dict); } err: @@ -5386,7 +5387,7 @@ glusterd_op_ac_stage_op (glusterd_op_sm_event_t *event, void *ctx) return -1; } - status = glusterd_op_stage_validate (dict, &op_errstr, + status = glusterd_op_stage_validate (stage_ctx->op, dict, &op_errstr, rsp_dict); if (status) { @@ -5431,7 +5432,8 @@ glusterd_op_ac_commit_op (glusterd_op_sm_event_t *event, void *ctx) goto out; } - status = glusterd_op_commit_perform (dict, &op_errstr, rsp_dict); + status = glusterd_op_commit_perform (commit_ctx->op, dict, &op_errstr, + rsp_dict); if (status) { gf_log ("", GF_LOG_ERROR, "Commit failed: %d", status); @@ -5475,15 +5477,10 @@ glusterd_op_sm_transition_state (glusterd_op_info_t *opinfo, } int32_t -glusterd_op_stage_validate (dict_t *dict, char **op_errstr, +glusterd_op_stage_validate (glusterd_op_t op, dict_t *dict, char **op_errstr, dict_t *rsp_dict) { int ret = -1; - int op = -1; - - ret = dict_get_int32 (dict, "operation", &op); - if (ret) - gf_log ("", GF_LOG_WARNING, "operation not set"); switch (op) { case GD_OP_CREATE_VOLUME: @@ -5551,15 +5548,10 @@ glusterd_op_stage_validate (dict_t *dict, char **op_errstr, int32_t -glusterd_op_commit_perform (dict_t *dict, char **op_errstr, +glusterd_op_commit_perform (glusterd_op_t op, dict_t *dict, char **op_errstr, dict_t *rsp_dict) { int ret = -1; - int op = -1; - - ret = dict_get_int32 (dict, "operation", &op); - if (ret) - gf_log ("", GF_LOG_WARNING, "operation not set"); switch (op) { case GD_OP_CREATE_VOLUME: diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h index d47f6a6f233..30d4fe9c8d2 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h @@ -175,11 +175,11 @@ int glusterd_op_build_payload (glusterd_op_t op, dict_t **req); int32_t -glusterd_op_stage_validate (dict_t *req, char **op_errstr, +glusterd_op_stage_validate (glusterd_op_t op, dict_t *req, char **op_errstr, dict_t *rsp_dict); int32_t -glusterd_op_commit_perform (dict_t *req, char **op_errstr, +glusterd_op_commit_perform (glusterd_op_t op, dict_t *req, char **op_errstr, dict_t* dict); void * diff --git a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c index fe97183c4af..e7134c990b7 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c @@ -1298,6 +1298,7 @@ glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this, glusterd_conf_t *priv = NULL; call_frame_t *dummy_frame = NULL; dict_t *dict = NULL; + gf_boolean_t is_alloc = _gf_true; if (!this) { goto out; @@ -1315,15 +1316,23 @@ glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this, //peerinfo should not be in payload dict_del (dict, "peerinfo"); - ret = dict_allocate_and_serialize (dict, &req.buf.buf_val, - (size_t *)&req.buf.buf_len); - - if (ret) - goto out; - glusterd_get_uuid (&req.uuid); req.op = glusterd_op_get_op (); + if (GD_OP_DELETE_VOLUME == req.op) { + ret = dict_get_str (dict, "volname", &req.buf.buf_val); + if (ret) + goto out; + req.buf.buf_len = strlen (req.buf.buf_val); + is_alloc = _gf_false; + } else { + ret = dict_allocate_and_serialize (dict, &req.buf.buf_val, + (size_t *)&req.buf.buf_len); + + if (ret) + goto out; + } + dummy_frame = create_frame (this, this->ctx->pool); if (!dummy_frame) goto out; @@ -1335,7 +1344,7 @@ glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this, this, glusterd3_1_stage_op_cbk); out: - if (req.buf.buf_val) + if ((_gf_true == is_alloc) && req.buf.buf_val) GF_FREE (req.buf.buf_val); gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret); @@ -1352,6 +1361,7 @@ glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this, glusterd_conf_t *priv = NULL; call_frame_t *dummy_frame = NULL; dict_t *dict = NULL; + gf_boolean_t is_alloc = _gf_true; if (!this) { goto out; @@ -1371,11 +1381,19 @@ glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this, glusterd_get_uuid (&req.uuid); req.op = glusterd_op_get_op (); - ret = dict_allocate_and_serialize (dict, &req.buf.buf_val, - (size_t *)&req.buf.buf_len); + if (GD_OP_DELETE_VOLUME == req.op) { + ret = dict_get_str (dict, "volname", &req.buf.buf_val); + if (ret) + goto out; + req.buf.buf_len = strlen (req.buf.buf_val); + is_alloc = _gf_false; + } else { + ret = dict_allocate_and_serialize (dict, &req.buf.buf_val, + (size_t *)&req.buf.buf_len); - if (ret) - goto out; + if (ret) + goto out; + } dummy_frame = create_frame (this, this->ctx->pool); if (!dummy_frame) @@ -1388,7 +1406,7 @@ glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this, this, glusterd3_1_commit_op_cbk); out: - if (req.buf.buf_val) + if ((_gf_true == is_alloc) && req.buf.buf_val) GF_FREE (req.buf.buf_val); gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret); -- cgit