diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2018-09-03 13:55:01 +0300 |
---|---|---|
committer | Atin Mukherjee <amukherj@redhat.com> | 2018-09-09 01:53:59 +0000 |
commit | 09198e203ece6925791a8a3a6121c5f808e4e873 (patch) | |
tree | 152f83348592c21fa697aeb0fc606e824ab7c993 /xlators/mgmt/glusterd/src/glusterd-rebalance.c | |
parent | 44e4db05a953a6f231c62225b462470cacb16bd4 (diff) |
Some (mgmt) xlators: use dict_{setn|getn|deln|get_int32n|set_int32n|set_strn}
In a previous patch (https://review.gluster.org/20769) we've
added the key length to be passed to dict_* funcs, to remove the need
to strlen() it. This patch moves some xlators to use it.
- It also adds dict_get_int32n which was missing.
- It also reduces the size of some key variables.
They were set to 1024b or PATH_MAX, where sometimes 64 bytes were
really enough.
Please review carefully:
1. That I did not reduce some the size of the key variables too much.
2. That I did not mix up some keys.
Compile-tested only!
Change-Id: Ic729baf179f40e8d02bc2350491d4bb9b6934266
updates: bz#1193929
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-rebalance.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-rebalance.c | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c index 9066e038dd7..d1794b3ef5d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rebalance.c +++ b/xlators/mgmt/glusterd/src/glusterd-rebalance.c @@ -261,8 +261,9 @@ glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr, snprintf (volname, sizeof(volname), "rebalance/%s", volinfo->volname); - if (dict_get_str (this->options, "transport.socket.bind-address", - &volfileserver) == 0) { + if (dict_get_strn (this->options, "transport.socket.bind-address", + SLEN ("transport.socket.bind-address"), + &volfileserver) == 0) { /*In the case of running multiple glusterds on a single machine, *we should ensure that log file and unix socket file should be *unique in given cluster */ @@ -309,7 +310,8 @@ glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr, runner_argprintf (&runner, logfile); if (volinfo->memory_accounting) runner_add_arg (&runner, "--mem-accounting"); - if (dict_get_str (priv->opts, GLUSTERD_LOCALTIME_LOGGING_KEY, + if (dict_get_strn (priv->opts, GLUSTERD_LOCALTIME_LOGGING_KEY, + SLEN (GLUSTERD_LOCALTIME_LOGGING_KEY), &localtime_logging) == 0) { if (strcmp (localtime_logging, "enable") == 0) runner_add_arg (&runner, "--localtime-logging"); @@ -534,7 +536,7 @@ __glusterd_handle_defrag_volume (rpcsvc_request_t *req) } } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { snprintf (msg, sizeof (msg), "Failed to get volume name"); gf_msg (this->name, GF_LOG_ERROR, 0, @@ -542,7 +544,8 @@ __glusterd_handle_defrag_volume (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "rebalance-command", (int32_t*)&cmd); + ret = dict_get_int32n (dict, "rebalance-command", + SLEN ("rebalance-command"), (int32_t*)&cmd); if (ret) { snprintf (msg, sizeof (msg), "Failed to get command"); gf_msg (this->name, GF_LOG_ERROR, 0, @@ -640,13 +643,14 @@ glusterd_op_stage_rebalance (dict_t *dict, char **op_errstr) this = THIS; GF_ASSERT (this); - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg_debug (this->name, 0, "volname not found"); goto out; } - ret = dict_get_int32 (dict, "rebalance-command", &cmd); + ret = dict_get_int32n (dict, "rebalance-command", + SLEN ("rebalance-command"), &cmd); if (ret) { gf_msg_debug (this->name, 0, "cmd not found"); goto out; @@ -660,7 +664,8 @@ glusterd_op_stage_rebalance (dict_t *dict, char **op_errstr) } switch (cmd) { case GF_DEFRAG_CMD_START_TIER: - ret = dict_get_int32 (dict, "force", &is_force); + ret = dict_get_int32n (dict, "force", SLEN ("force"), + &is_force); if (ret) is_force = 0; @@ -712,7 +717,8 @@ glusterd_op_stage_rebalance (dict_t *dict, char **op_errstr) } ret = glusterd_generate_and_set_task_id - (op_ctx, GF_REBALANCE_TID_KEY); + (op_ctx, GF_REBALANCE_TID_KEY, + SLEN (GF_REBALANCE_TID_KEY)); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_TASKID_GEN_FAIL, @@ -720,8 +726,9 @@ glusterd_op_stage_rebalance (dict_t *dict, char **op_errstr) goto out; } } else { - ret = dict_get_str (dict, GF_REBALANCE_TID_KEY, - &task_id_str); + ret = dict_get_strn (dict, GF_REBALANCE_TID_KEY, + SLEN (GF_REBALANCE_TID_KEY), + &task_id_str); if (ret) { snprintf (msg, sizeof (msg), "Missing rebalance-id"); @@ -744,7 +751,8 @@ glusterd_op_stage_rebalance (dict_t *dict, char **op_errstr) case GF_DEFRAG_CMD_STATUS: case GF_DEFRAG_CMD_STOP: - ret = dict_get_str (dict, "cmd-str", &cmd_str); + ret = dict_get_strn (dict, "cmd-str", SLEN ("cmd-str"), + &cmd_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get " @@ -840,13 +848,14 @@ glusterd_op_rebalance (dict_t *dict, char **op_errstr, dict_t *rsp_dict) this = THIS; GF_ASSERT (this); - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg_debug (this->name, 0, "volname not given"); goto out; } - ret = dict_get_int32 (dict, "rebalance-command", &cmd); + ret = dict_get_int32n (dict, "rebalance-command", + SLEN ("rebalance-command"), &cmd); if (ret) { gf_msg_debug (this->name, 0, "command not given"); goto out; @@ -879,11 +888,13 @@ glusterd_op_rebalance (dict_t *dict, char **op_errstr, dict_t *rsp_dict) if (GD_OP_REMOVE_BRICK == volinfo->rebal.op) ret = glusterd_copy_uuid_to_dict (volinfo->rebal.rebalance_id, ctx, - GF_REMOVE_BRICK_TID_KEY); + GF_REMOVE_BRICK_TID_KEY, + SLEN (GF_REMOVE_BRICK_TID_KEY)); else ret = glusterd_copy_uuid_to_dict (volinfo->rebal.rebalance_id, ctx, - GF_REBALANCE_TID_KEY); + GF_REBALANCE_TID_KEY, + SLEN (GF_REBALANCE_TID_KEY)); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_TASKID_GEN_FAIL, @@ -900,7 +911,8 @@ glusterd_op_rebalance (dict_t *dict, char **op_errstr, dict_t *rsp_dict) case GF_DEFRAG_CMD_START_TIER: - ret = dict_get_int32 (dict, "force", &is_force); + ret = dict_get_int32n (dict, "force", SLEN ("force"), + &is_force); if (ret) is_force = 0; if (!is_force) { @@ -911,8 +923,9 @@ glusterd_op_rebalance (dict_t *dict, char **op_errstr, dict_t *rsp_dict) volinfo->rebal.defrag_status = GF_DEFRAG_STATUS_NOT_STARTED; - ret = dict_get_str (dict, GF_REBALANCE_TID_KEY, - &task_id_str); + ret = dict_get_strn (dict, GF_REBALANCE_TID_KEY, + SLEN (GF_REBALANCE_TID_KEY), + &task_id_str); if (ret) { gf_msg_debug (this->name, 0, "Missing rebalance" " id"); @@ -953,8 +966,9 @@ glusterd_op_rebalance (dict_t *dict, char **op_errstr, dict_t *rsp_dict) volinfo->rebal.defrag_cmd = cmd; volinfo->rebal.op = GD_OP_REBALANCE; - ret = dict_get_str (dict, GF_REBALANCE_TID_KEY, - &task_id_str); + ret = dict_get_strn (dict, GF_REBALANCE_TID_KEY, + SLEN (GF_REBALANCE_TID_KEY), + &task_id_str); if (ret) { gf_msg_debug (this->name, 0, "Missing rebalance" " id"); @@ -1051,7 +1065,7 @@ glusterd_defrag_event_notify_handle (dict_t *dict) GF_ASSERT (this); GF_ASSERT (dict); - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get volname"); |