From 3b4bc185024c905dc321b90d7972c3efecf45d01 Mon Sep 17 00:00:00 2001 From: Avra Sengupta Date: Wed, 30 Oct 2013 12:17:53 +0530 Subject: glusterd/Jarvis: Added aggr rsp dict in mgmt framework Also fixes snapshot config output Change-Id: Ia50d94492009cf73dbb99ba20117b9fa4c41048a Signed-off-by: Avra Sengupta --- cli/src/cli-rpc-ops.c | 9 +-- xlators/mgmt/glusterd/src/glusterd-mgmt.c | 48 +++++++++++++++- xlators/mgmt/glusterd/src/glusterd-snapshot.c | 9 ++- xlators/mgmt/glusterd/src/glusterd-syncop.c | 10 +++- xlators/mgmt/glusterd/src/glusterd-syncop.h | 6 ++ xlators/mgmt/glusterd/src/glusterd-utils.c | 82 +++++++++++++++++++++++++++ xlators/mgmt/glusterd/src/glusterd-utils.h | 2 + 7 files changed, 154 insertions(+), 12 deletions(-) diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 870588e9a..b39ce6a11 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -7988,11 +7988,12 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov, ret = -1; goto out; } - cli_out ("Max snapshot count set for %s is %"PRIu64, + cli_out ("snapshot config: snap-max-limit for " + "%s set to %"PRIu64, volname, limit); } else { - cli_out ("Snapshot config max set for %s successfull", - volname); + cli_out ("snapshot config: snap-max-limit " + "for %s set successfully", volname); } break; @@ -8029,7 +8030,7 @@ gf_cli_snapshot (call_frame_t *frame, xlator_t *this, GLUSTER_CLI_SNAP, this, cli_rpc_prog, NULL); out: - gf_log ("cli", GF_LOG_ERROR, "Returning %d", ret); + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); GF_FREE (req.dict.dict_val); return ret; diff --git a/xlators/mgmt/glusterd/src/glusterd-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-mgmt.c index 8e2c0c689..624e3a393 100644 --- a/xlators/mgmt/glusterd/src/glusterd-mgmt.c +++ b/xlators/mgmt/glusterd/src/glusterd-mgmt.c @@ -351,6 +351,7 @@ glusterd_mgmt_v3_initiate_lockdown (glusterd_conf_t *conf, glusterd_op_t op, } /* Sending Volume lock req to other nodes in the cluster */ + gd_syncargs_init (&args, NULL); synctask_barrier_init((&args)); peer_cnt = 0; list_for_each_entry (peerinfo, peers, op_peers_list) { @@ -533,6 +534,7 @@ glusterd_mgmt_v3_pre_validate (glusterd_conf_t *conf, glusterd_op_t op, } /* Sending Pre Validation req to other nodes in the cluster */ + gd_syncargs_init (&args, NULL); synctask_barrier_init((&args)); peer_cnt = 0; list_for_each_entry (peerinfo, peers, op_peers_list) { @@ -732,6 +734,7 @@ glusterd_mgmt_v3_brick_op (glusterd_conf_t *conf, glusterd_op_t op, } /* Sending brick op req to other nodes in the cluster */ + gd_syncargs_init (&args, NULL); synctask_barrier_init((&args)); peer_cnt = 0; list_for_each_entry (peerinfo, peers, op_peers_list) { @@ -768,6 +771,7 @@ gd_mgmt_v3_commit_cbk_fn (struct rpc_req *req, struct iovec *iov, call_frame_t *frame = NULL; int op_ret = -1; int op_errno = -1; + dict_t *rsp_dict = NULL; GF_ASSERT(req); GF_ASSERT(iov); @@ -789,7 +793,32 @@ gd_mgmt_v3_commit_cbk_fn (struct rpc_req *req, struct iovec *iov, if (ret < 0) goto out; + if (rsp.dict.dict_len) { + /* Unserialize the dictionary */ + rsp_dict = dict_new (); + + ret = dict_unserialize (rsp.dict.dict_val, + rsp.dict.dict_len, + &rsp_dict); + if (ret < 0) { + GF_FREE (rsp.dict.dict_val); + goto out; + } else { + rsp_dict->extra_stdfree = rsp.dict.dict_val; + } + } + uuid_copy (args->uuid, rsp.uuid); + pthread_mutex_lock (&args->lock_dict); + { + ret = glusterd_syncop_aggr_rsp_dict (rsp.op, args->dict, + rsp_dict); + if (ret) + gf_log ("", GF_LOG_ERROR, "%s", + "Failed to aggregate response from " + " node/brick"); + } + pthread_mutex_unlock (&args->lock_dict); op_ret = rsp.op_ret; op_errno = rsp.op_errno; @@ -846,7 +875,8 @@ out: int glusterd_mgmt_v3_commit (glusterd_conf_t *conf, glusterd_op_t op, - dict_t *req_dict, char **op_errstr, int npeers) + dict_t *op_ctx, dict_t *req_dict, + char **op_errstr, int npeers) { int ret = -1; int peer_cnt = 0; @@ -889,6 +919,15 @@ glusterd_mgmt_v3_commit (glusterd_conf_t *conf, glusterd_op_t op, goto out; } + ret = glusterd_syncop_aggr_rsp_dict (op, op_ctx, + rsp_dict); + if (ret) { + gf_log ("", GF_LOG_ERROR, "%s", + "Failed to aggregate response from " + " node/brick"); + goto out; + } + dict_unref (rsp_dict); rsp_dict = NULL; @@ -898,6 +937,7 @@ glusterd_mgmt_v3_commit (glusterd_conf_t *conf, glusterd_op_t op, } /* Sending commit req to other nodes in the cluster */ + gd_syncargs_init (&args, op_ctx); synctask_barrier_init((&args)); peer_cnt = 0; list_for_each_entry (peerinfo, peers, op_peers_list) { @@ -1064,6 +1104,7 @@ glusterd_mgmt_v3_post_validate (glusterd_conf_t *conf, glusterd_op_t op, } /* Sending Post Validation req to other nodes in the cluster */ + gd_syncargs_init (&args, NULL); synctask_barrier_init((&args)); peer_cnt = 0; list_for_each_entry (peerinfo, peers, op_peers_list) { @@ -1203,6 +1244,7 @@ glusterd_mgmt_v3_release_peer_locks (glusterd_conf_t *conf, glusterd_op_t op, } /* Sending Volume unlock req to other nodes in the cluster */ + gd_syncargs_init (&args, NULL); synctask_barrier_init((&args)); peer_cnt = 0; list_for_each_entry (peerinfo, peers, op_peers_list) { @@ -1317,7 +1359,7 @@ glusterd_mgmt_v3_initiate_all_phases (rpcsvc_request_t *req, glusterd_op_t op, } /* COMMIT OP PHASE */ - ret = glusterd_mgmt_v3_commit (conf, op, req_dict, + ret = glusterd_mgmt_v3_commit (conf, op, dict, req_dict, &op_errstr, npeers); if (ret) { gf_log ("", GF_LOG_ERROR, "Commit Op Failed"); @@ -1467,7 +1509,7 @@ glusterd_mgmt_v3_initiate_snap_phases (rpcsvc_request_t *req, glusterd_op_t op, } /* COMMIT OP PHASE */ - ret = glusterd_mgmt_v3_commit (conf, op, req_dict, + ret = glusterd_mgmt_v3_commit (conf, op, dict, req_dict, &op_errstr, npeers); if (ret) { gf_log ("", GF_LOG_ERROR, "Commit Op Failed"); diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index 287a44933..eeadb6d74 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -408,6 +408,7 @@ glusterd_snapshot_config_limit_prevalidate (dict_t *dict, char **op_errstr, GF_ASSERT (this); GF_ASSERT (dict); + GF_ASSERT (op_errstr); conf = this->private; @@ -3025,6 +3026,7 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr, GF_ASSERT (this); GF_ASSERT (dict); GF_ASSERT (rsp_dict); + GF_ASSERT (op_errstr); conf = this->private; @@ -3146,6 +3148,7 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr, " volume name"); goto out; } + ret = dict_set_int32 (dict, "config-command", config_command); if (ret) { gf_log (this->name, GF_LOG_ERROR, @@ -3153,8 +3156,10 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr, goto out; } out: + gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret); return ret; } + int32_t glusterd_snapshot (dict_t *dict, char **op_errstr, dict_t *rsp_dict) { @@ -3207,11 +3212,9 @@ glusterd_snapshot (dict_t *dict, char **op_errstr, dict_t *rsp_dict) break; } - - ret = 0; - out: + gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret); return ret; } diff --git a/xlators/mgmt/glusterd/src/glusterd-syncop.c b/xlators/mgmt/glusterd/src/glusterd-syncop.c index 953b9f701..74ce06b2d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-syncop.c +++ b/xlators/mgmt/glusterd/src/glusterd-syncop.c @@ -162,7 +162,7 @@ gd_collate_errors (struct syncargs *args, int op_ret, int op_errno, return; } -static void +void gd_syncargs_init (struct syncargs *args, dict_t *op_ctx) { args->dict = op_ctx; @@ -266,7 +266,7 @@ extern struct rpc_clnt_program gd_mgmt_prog; extern struct rpc_clnt_program gd_brick_prog; extern struct rpc_clnt_program gd_mgmt_v3_prog; -static int +int glusterd_syncop_aggr_rsp_dict (glusterd_op_t op, dict_t *aggr, dict_t *rsp) { int ret = 0; @@ -333,6 +333,12 @@ glusterd_syncop_aggr_rsp_dict (glusterd_op_t op, dict_t *aggr, dict_t *rsp) goto out; break; + case GD_OP_SNAP: + ret = glusterd_snap_use_rsp_dict (aggr, rsp); + if (ret) + goto out; + break; + default: break; } diff --git a/xlators/mgmt/glusterd/src/glusterd-syncop.h b/xlators/mgmt/glusterd/src/glusterd-syncop.h index 35215a78a..e83ea2f4c 100644 --- a/xlators/mgmt/glusterd/src/glusterd-syncop.h +++ b/xlators/mgmt/glusterd/src/glusterd-syncop.h @@ -62,4 +62,10 @@ gd_build_peers_list (struct list_head *peers, struct list_head *xact_peers, int gd_brick_op_phase (glusterd_op_t op, dict_t *op_ctx, dict_t *req_dict, char **op_errstr); + +int +glusterd_syncop_aggr_rsp_dict (glusterd_op_t op, dict_t *aggr, dict_t *rsp); + +void +gd_syncargs_init (struct syncargs *args, dict_t *op_ctx); #endif /* __RPC_SYNCOP_H */ diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 1f5cc741b..f79cd2353 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -7553,6 +7553,88 @@ out: return ret; } +int +glusterd_snap_config_use_rsp_dict (dict_t *dst, dict_t *src) +{ + int ret = -1; + uint64_t limit = 0; + int config_command = 0; + + if (!dst || !src) { + gf_log ("", GF_LOG_ERROR, "Source or Destination " + "dict is empty."); + goto out; + } + + ret = dict_get_int32 (dst, "config-command", &config_command); + if (ret) { + gf_log ("", GF_LOG_ERROR, + "failed to get config-command type"); + goto out; + } + + switch (config_command) { + case GF_SNAP_CONFIG_DISPLAY: + ret = dict_get_uint64 (src, "limit", &limit); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Unable to fetch limit"); + goto out; + } + + ret = dict_set_uint64 (dst, "limit", limit); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Unable to set limit"); + goto out; + } + + break; + default: + break; + } + + ret = 0; +out: + gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); + return ret; +} + +int +glusterd_snap_use_rsp_dict (dict_t *dst, dict_t *src) +{ + int ret = -1; + int32_t snap_command = 0; + + if (!dst || !src) { + gf_log ("", GF_LOG_ERROR, "Source or Destination " + "dict is empty."); + goto out; + } + + ret = dict_get_int32 (dst, "type", &snap_command); + if (ret) { + gf_log ("", GF_LOG_ERROR, "unable to get the type of " + "the snapshot command"); + goto out; + } + + switch (snap_command) { + case GF_SNAP_OPTION_TYPE_CONFIG: + ret = glusterd_snap_config_use_rsp_dict (dst, src); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Unable to use rsp dict"); + goto out; + } + break; + default: + break; + } + + ret = 0; +out: + gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); + return ret; +} + int glusterd_sys_exec_output_rsp_dict (dict_t *dst, dict_t *src) { diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h index 1fb55c499..1d5a93cc0 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-utils.h @@ -499,6 +499,8 @@ int glusterd_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict); int glusterd_sys_exec_output_rsp_dict (dict_t *aggr, dict_t *rsp_dict); +int +glusterd_snap_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict); int32_t glusterd_handle_node_rsp (dict_t *req_ctx, void *pending_entry, glusterd_op_t op, dict_t *rsp_dict, dict_t *op_ctx, -- cgit