From 09198e203ece6925791a8a3a6121c5f808e4e873 Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Mon, 3 Sep 2018 13:55:01 +0300 Subject: 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 --- xlators/mgmt/glusterd/src/glusterd-brick-ops.c | 218 ++-- xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c | 4 +- xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c | 10 +- xlators/mgmt/glusterd/src/glusterd-handler.c | 510 ++++---- xlators/mgmt/glusterd/src/glusterd-mgmt.c | 37 +- xlators/mgmt/glusterd/src/glusterd-mountbroker.c | 5 +- xlators/mgmt/glusterd/src/glusterd-op-sm.c | 436 ++++--- xlators/mgmt/glusterd/src/glusterd-peer-utils.c | 54 +- xlators/mgmt/glusterd/src/glusterd-quota.c | 59 +- xlators/mgmt/glusterd/src/glusterd-quotad-svc.c | 4 +- xlators/mgmt/glusterd/src/glusterd-rebalance.c | 58 +- xlators/mgmt/glusterd/src/glusterd-replace-brick.c | 32 +- xlators/mgmt/glusterd/src/glusterd-reset-brick.c | 16 +- xlators/mgmt/glusterd/src/glusterd-rpc-ops.c | 47 +- xlators/mgmt/glusterd/src/glusterd-sm.c | 41 +- xlators/mgmt/glusterd/src/glusterd-snapshot.c | 859 +++++++------ xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c | 15 +- xlators/mgmt/glusterd/src/glusterd-tier.c | 125 +- xlators/mgmt/glusterd/src/glusterd-tierd-svc.c | 13 +- xlators/mgmt/glusterd/src/glusterd-utils.c | 1263 +++++++++++--------- xlators/mgmt/glusterd/src/glusterd-utils.h | 5 +- xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 259 ++-- 22 files changed, 2357 insertions(+), 1713 deletions(-) (limited to 'xlators/mgmt/glusterd/src') diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c index 5591070f32f..73dcfaaa2b6 100644 --- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c @@ -465,7 +465,7 @@ __glusterd_handle_add_brick (rpcsvc_request_t *req) } } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get volume " @@ -484,7 +484,7 @@ __glusterd_handle_add_brick (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "count", &brick_count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &brick_count); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get volume " "brick count"); @@ -493,28 +493,31 @@ __glusterd_handle_add_brick (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "replica-count", &replica_count); + ret = dict_get_int32n (dict, "replica-count", SLEN ("replica-count"), + &replica_count); if (!ret) { gf_msg (this->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_SUCCESS, "replica-count is %d", replica_count); } - ret = dict_get_int32 (dict, "arbiter-count", &arbiter_count); + ret = dict_get_int32n (dict, "arbiter-count", SLEN ("arbiter-count"), + &arbiter_count); if (!ret) { gf_msg (this->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_SUCCESS, "arbiter-count is %d", arbiter_count); } - ret = dict_get_int32 (dict, "stripe-count", &stripe_count); + ret = dict_get_int32n (dict, "stripe-count", SLEN ("stripe-count"), + &stripe_count); if (!ret) { gf_msg (this->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_SUCCESS, "stripe-count is %d", stripe_count); } - if (!dict_get (dict, "force")) { + if (!dict_getn (dict, "force", SLEN ("force"))) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Failed to get flag"); goto out; @@ -532,7 +535,7 @@ __glusterd_handle_add_brick (rpcsvc_request_t *req) total_bricks = volinfo->brick_count + brick_count; - if (dict_get (dict, "attach-tier")) { + if (dict_getn (dict, "attach-tier", SLEN ("attach-tier"))) { if (volinfo->type == GF_CLUSTER_TYPE_TIER) { snprintf (err_str, sizeof (err_str), "Volume %s is already a tier.", volname); @@ -550,7 +553,7 @@ __glusterd_handle_add_brick (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "hot-type", &type); + ret = dict_get_int32n (dict, "hot-type", SLEN ("hot-type"), &type); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, @@ -608,7 +611,8 @@ __glusterd_handle_add_brick (rpcsvc_request_t *req) if (ret == 1) stripe_count = 0; - ret = dict_set_int32 (dict, "stripe-count", stripe_count); + ret = dict_set_int32n (dict, "stripe-count", + SLEN ("stripe-count"), stripe_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, @@ -632,7 +636,8 @@ __glusterd_handle_add_brick (rpcsvc_request_t *req) if (ret == 1) replica_count = 0; - ret = dict_set_int32 (dict, "replica-count", replica_count); + ret = dict_set_int32n (dict, "replica-count", + SLEN ("replica-count"), replica_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, @@ -641,7 +646,7 @@ __glusterd_handle_add_brick (rpcsvc_request_t *req) } brick_val: - ret = dict_get_str (dict, "bricks", &bricks); + ret = dict_get_strn (dict, "bricks", SLEN ("bricks"), &bricks); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get volume " "bricks"); @@ -651,7 +656,7 @@ brick_val: } if (type != volinfo->type) { - ret = dict_set_int32 (dict, "type", type); + ret = dict_set_int32n (dict, "type", SLEN ("type"), type); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, @@ -805,7 +810,7 @@ glusterd_set_detach_bricks(dict_t *dict, glusterd_volinfo_t *volinfo) } } - ret = dict_set_int32(dict, "count", hot_brick_num); + ret = dict_set_int32n (dict, "count", SLEN ("count"), hot_brick_num); if (ret) return -1; @@ -886,6 +891,7 @@ __glusterd_handle_remove_brick (rpcsvc_request_t *req) int32_t count = 0; char *brick = NULL; char key[64] = ""; + int keylen; int i = 1; glusterd_volinfo_t *volinfo = NULL; glusterd_brickinfo_t *brickinfo = NULL; @@ -935,7 +941,7 @@ __glusterd_handle_remove_brick (rpcsvc_request_t *req) } } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get volume " "name"); @@ -944,7 +950,7 @@ __glusterd_handle_remove_brick (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "count", &count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &count); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get brick " "count"); @@ -971,7 +977,7 @@ __glusterd_handle_remove_brick (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "command", &cmd); + ret = dict_get_int32n (dict, "command", SLEN ("command"), &cmd); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get cmd " "ccommand"); @@ -989,7 +995,8 @@ __glusterd_handle_remove_brick (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "replica-count", &replica_count); + ret = dict_get_int32n (dict, "replica-count", SLEN ("replica-count"), + &replica_count); if (!ret) { gf_msg (this->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_FAILED, @@ -1002,12 +1009,13 @@ __glusterd_handle_remove_brick (rpcsvc_request_t *req) itself */ goto out; } - dict_del (dict, "replica-count"); + dict_deln (dict, "replica-count", SLEN ("replica-count")); if (ret) { replica_count = 0; } else { - ret = dict_set_int32 (dict, "replica-count", - replica_count); + ret = dict_set_int32n (dict, "replica-count", + SLEN ("replica-count"), + replica_count); if (ret) { gf_msg (this->name, GF_LOG_WARNING, errno, GD_MSG_DICT_SET_FAILED, @@ -1104,8 +1112,8 @@ __glusterd_handle_remove_brick (rpcsvc_request_t *req) } while ( i <= count) { - snprintf (key, sizeof (key), "brick%d", i); - ret = dict_get_str (dict, key, &brick); + keylen = snprintf (key, sizeof (key), "brick%d", i); + ret = dict_get_strn (dict, key, keylen, &brick); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get %s", key); @@ -1233,7 +1241,8 @@ _glusterd_restart_gsync_session (dict_t *this, char *key, else return 0; - ret = dict_set_dynstr (param->rsp_dict, "slave", slave_buf); + ret = dict_set_dynstrn (param->rsp_dict, "slave", SLEN ("slave"), + slave_buf); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, @@ -1344,23 +1353,26 @@ glusterd_op_perform_add_bricks (glusterd_volinfo_t *volinfo, int32_t count, brick = strtok_r (brick_list+1, " \n", &saveptr); if (dict) { - ret = dict_get_int32 (dict, "stripe-count", &stripe_count); + ret = dict_get_int32n (dict, "stripe-count", + SLEN ("stripe-count"), &stripe_count); if (!ret) gf_msg (THIS->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_SUCCESS, "stripe-count is set %d", stripe_count); - ret = dict_get_int32 (dict, "replica-count", &replica_count); + ret = dict_get_int32n (dict, "replica-count", + SLEN ("replica-count"), &replica_count); if (!ret) gf_msg (THIS->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_SUCCESS, "replica-count is set %d", replica_count); - ret = dict_get_int32 (dict, "arbiter-count", &arbiter_count); + ret = dict_get_int32n (dict, "arbiter-count", + SLEN ("arbiter-count"), &arbiter_count); if (!ret) gf_msg (THIS->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_SUCCESS, "arbiter-count is set %d", arbiter_count); - ret = dict_get_int32 (dict, "type", &type); + ret = dict_get_int32n (dict, "type", SLEN ("type"), &type); if (!ret) gf_msg (THIS->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_SUCCESS, @@ -1417,7 +1429,7 @@ glusterd_op_perform_add_bricks (glusterd_volinfo_t *volinfo, int32_t count, brickinfo->statfs_fsid = brickstat.f_fsid; } /* hot tier bricks are added to head of brick list */ - if (dict_get (dict, "attach-tier")) { + if (dict_getn (dict, "attach-tier", SLEN ("attach-tier"))) { cds_list_add (&brickinfo->brick_list, &volinfo->bricks); } else if (stripe_count || replica_count) { add_brick_at_right_order (brickinfo, volinfo, (i - 1), @@ -1443,9 +1455,10 @@ glusterd_op_perform_add_bricks (glusterd_volinfo_t *volinfo, int32_t count, */ if (type && glusterd_is_volume_replicate (volinfo) && conf->op_version >= GD_OP_VERSION_3_12_2) { - ret = dict_set_str (volinfo->dict, - "performance.client-io-threads", - "off"); + ret = dict_set_nstrn (volinfo->dict, + "performance.client-io-threads", + SLEN ("performance.client-io-threads"), + "off", SLEN ("off")); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set " @@ -1500,7 +1513,7 @@ glusterd_op_perform_add_bricks (glusterd_volinfo_t *volinfo, int32_t count, */ if (glusterd_is_volume_replicate (volinfo)) { if (replica_count && - !dict_get (dict, "attach-tier") && + !dict_getn (dict, "attach-tier", SLEN ("attach-tier")) && conf->op_version >= GD_OP_VERSION_3_7_10) { is_valid_add_brick = _gf_true; ret = generate_dummy_client_volfiles (volinfo); @@ -1688,7 +1701,7 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) conf = this->private; GF_ASSERT (conf); - 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, errno, GD_MSG_DICT_GET_FAILED, @@ -1708,13 +1721,15 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) if (ret) goto out; - ret = dict_get_int32 (dict, "replica-count", &replica_count); + ret = dict_get_int32n (dict, "replica-count", SLEN ("replica-count"), + &replica_count); if (ret) { gf_msg_debug (THIS->name, 0, "Unable to get replica count"); } - ret = dict_get_int32 (dict, "arbiter-count", &arbiter_count); + ret = dict_get_int32n (dict, "arbiter-count", + SLEN ("arbiter-count"), &arbiter_count); if (ret) { gf_msg_debug (THIS->name, 0, "No arbiter count present in the dict"); @@ -1736,7 +1751,7 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) * is being increased. */ if (conf->op_version >= GD_OP_VERSION_3_7_10 && - !dict_get (dict, "attach-tier") && + !dict_getn (dict, "attach-tier", SLEN ("attach-tier")) && replica_count && GLUSTERD_STATUS_STOPPED == volinfo->status) { ret = -1; @@ -1831,7 +1846,7 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) goto out; } - if (dict_get(dict, "attach-tier")) { + if (dict_getn (dict, "attach-tier", SLEN ("attach-tier"))) { /* * This check is needed because of add/remove brick @@ -1854,14 +1869,14 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) } } - ret = dict_get_int32 (dict, "count", &count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &count); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Unable to get count"); goto out; } - ret = dict_get_str (dict, "bricks", &bricks); + ret = dict_get_strn (dict, "bricks", SLEN ("bricks"), &bricks); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Unable to get bricks"); @@ -1968,8 +1983,8 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) i++; } - ret = dict_set_int32 (rsp_dict, "brick_count", - local_brick_count); + ret = dict_set_int32n (rsp_dict, "brick_count", SLEN ("brick_count"), + local_brick_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, @@ -1999,6 +2014,7 @@ glusterd_remove_brick_validate_bricks (gf1_op_commands cmd, int32_t brick_count, char *brick = NULL; char msg[2048] = ""; char key[64] = ""; + int keylen; glusterd_brickinfo_t *brickinfo = NULL; glusterd_peerinfo_t *peerinfo = NULL; int i = 0; @@ -2010,8 +2026,8 @@ glusterd_remove_brick_validate_bricks (gf1_op_commands cmd, int32_t brick_count, /* Check whether all the nodes of the bricks to be removed are * up, if not fail the operation */ for (i = 1; i <= brick_count; i++) { - snprintf (key, sizeof (key), "brick%d", i); - ret = dict_get_str (dict, key, &brick); + keylen = snprintf (key, sizeof (key), "brick%d", i); + ret = dict_get_strn (dict, key, keylen, &brick); if (ret) { snprintf (msg, sizeof (msg), "Unable to get %s", key); @@ -2159,7 +2175,7 @@ glusterd_op_stage_remove_brick (dict_t *dict, char **op_errstr) goto out; } - 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, errno, GD_MSG_DICT_SET_FAILED, "Unable to get volume name"); @@ -2178,7 +2194,7 @@ glusterd_op_stage_remove_brick (dict_t *dict, char **op_errstr) if (ret) goto out; - ret = dict_get_int32 (dict, "command", &flag); + ret = dict_get_int32n (dict, "command", SLEN ("command"), &flag); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, @@ -2187,7 +2203,7 @@ glusterd_op_stage_remove_brick (dict_t *dict, char **op_errstr) } cmd = flag; - ret = dict_get_int32 (dict, "count", &brick_count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &brick_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Unable to get brick count"); @@ -2225,7 +2241,8 @@ glusterd_op_stage_remove_brick (dict_t *dict, char **op_errstr) case GF_OP_CMD_START: { if ((volinfo->type == GF_CLUSTER_TYPE_REPLICATE) && - dict_get (dict, "replica-count")) { + dict_getn (dict, "replica-count", + SLEN ("replica-count"))) { snprintf (msg, sizeof(msg), "Migration of data is not " "needed when reducing replica count. Use the" " 'force' option"); @@ -2302,7 +2319,8 @@ glusterd_op_stage_remove_brick (dict_t *dict, char **op_errstr) if (is_origin_glusterd (dict)) { ret = glusterd_generate_and_set_task_id - (dict, GF_REMOVE_BRICK_TID_KEY); + (dict, GF_REMOVE_BRICK_TID_KEY, + SLEN (GF_REMOVE_BRICK_TID_KEY)); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_TASKID_GEN_FAIL, @@ -2310,8 +2328,9 @@ glusterd_op_stage_remove_brick (dict_t *dict, char **op_errstr) goto out; } } else { - ret = dict_get_str (dict, GF_REMOVE_BRICK_TID_KEY, - &task_id_str); + ret = dict_get_strn (dict, GF_REMOVE_BRICK_TID_KEY, + SLEN (GF_REMOVE_BRICK_TID_KEY), + &task_id_str); if (ret) { gf_msg (this->name, GF_LOG_WARNING, errno, GD_MSG_DICT_GET_FAILED, @@ -2521,21 +2540,27 @@ glusterd_op_perform_attach_tier (dict_t *dict, volinfo->tier_info.cold_disperse_count = volinfo->disperse_count; volinfo->tier_info.cold_redundancy_count = volinfo->redundancy_count; - ret = dict_get_int32 (dict, "replica-count", &replica_count); + ret = dict_get_int32n (dict, "replica-count", + SLEN ("replica-count"), &replica_count); if (!ret) volinfo->tier_info.hot_replica_count = replica_count; else volinfo->tier_info.hot_replica_count = 1; volinfo->tier_info.hot_brick_count = count; - ret = dict_get_int32 (dict, "hot-type", &type); + ret = dict_get_int32n (dict, "hot-type", SLEN ("hot-type"), &type); volinfo->tier_info.hot_type = type; - ret = dict_set_int32 (dict, "type", GF_CLUSTER_TYPE_TIER); + ret = dict_set_int32n (dict, "type", SLEN ("type"), + GF_CLUSTER_TYPE_TIER); if (!ret) - ret = dict_set_str (volinfo->dict, "features.ctr-enabled", "on"); + ret = dict_set_nstrn (volinfo->dict, "features.ctr-enabled", + SLEN ("features.ctr-enabled"), + "on", SLEN ("on")); if (!ret) - ret = dict_set_str (volinfo->dict, "cluster.tier-mode", "cache"); + ret = dict_set_nstrn (volinfo->dict, "cluster.tier-mode", + SLEN ("cluster.tier-mode"), + "cache", SLEN ("cache")); return ret; } @@ -2557,7 +2582,7 @@ glusterd_op_add_brick (dict_t *dict, char **op_errstr) priv = this->private; GF_ASSERT (priv); - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, errno, @@ -2573,7 +2598,7 @@ glusterd_op_add_brick (dict_t *dict, char **op_errstr) goto out; } - ret = dict_get_int32 (dict, "count", &count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &count); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Unable to get count"); @@ -2581,14 +2606,14 @@ glusterd_op_add_brick (dict_t *dict, char **op_errstr) } - ret = dict_get_str (dict, "bricks", &bricks); + ret = dict_get_strn (dict, "bricks", SLEN ("bricks"), &bricks); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Unable to get bricks"); goto out; } - if (dict_get(dict, "attach-tier")) { + if (dict_getn (dict, "attach-tier", SLEN ("attach-tier"))) { gf_msg_debug (THIS->name, 0, "Adding tier"); glusterd_op_perform_attach_tier (dict, volinfo, count, bricks); } @@ -2637,7 +2662,7 @@ glusterd_op_add_tier_brick (dict_t *dict, char **op_errstr) priv = this->private; GF_VALIDATE_OR_GOTO (this->name, priv, out); - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, errno, @@ -2653,7 +2678,7 @@ glusterd_op_add_tier_brick (dict_t *dict, char **op_errstr) goto out; } - ret = dict_get_int32 (dict, "count", &count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &count); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Unable to get count"); @@ -2661,14 +2686,14 @@ glusterd_op_add_tier_brick (dict_t *dict, char **op_errstr) } - ret = dict_get_str (dict, "bricks", &bricks); + ret = dict_get_strn (dict, "bricks", SLEN ("bricks"), &bricks); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Unable to get bricks"); goto out; } - if (dict_get(dict, "attach-tier")) { + if (dict_getn (dict, "attach-tier", SLEN ("attach-tier"))) { gf_msg_debug (THIS->name, 0, "Adding tier"); glusterd_op_perform_attach_tier (dict, volinfo, count, bricks); } @@ -2720,6 +2745,7 @@ glusterd_op_remove_brick (dict_t *dict, char **op_errstr) int32_t count = 0; int32_t i = 1; char key[64] = ""; + int keylen; int32_t flag = 0; int need_rebalance = 0; int force = 0; @@ -2746,7 +2772,7 @@ glusterd_op_remove_brick (dict_t *dict, char **op_errstr) conf = this->private; GF_VALIDATE_OR_GOTO (this->name, conf, out); - 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, @@ -2761,7 +2787,7 @@ glusterd_op_remove_brick (dict_t *dict, char **op_errstr) goto out; } - ret = dict_get_int32 (dict, "command", &flag); + ret = dict_get_int32n (dict, "command", SLEN ("command"), &flag); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Unable to get command"); @@ -2781,7 +2807,8 @@ glusterd_op_remove_brick (dict_t *dict, char **op_errstr) if (!gf_uuid_is_null (volinfo->rebal.rebalance_id)) { ret = glusterd_copy_uuid_to_dict (volinfo->rebal.rebalance_id, dict, - GF_REMOVE_BRICK_TID_KEY); + GF_REMOVE_BRICK_TID_KEY, + SLEN (GF_REMOVE_BRICK_TID_KEY)); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_REMOVE_BRICK_ID_SET_FAIL, @@ -2850,7 +2877,9 @@ glusterd_op_remove_brick (dict_t *dict, char **op_errstr) */ volinfo->rebal.defrag_cmd = cmd; volinfo->rebal.defrag_status = GF_DEFRAG_STATUS_NOT_STARTED; - ret = dict_get_str (dict, GF_REMOVE_BRICK_TID_KEY, &task_id_str); + ret = dict_get_strn (dict, GF_REMOVE_BRICK_TID_KEY, + SLEN (GF_REMOVE_BRICK_TID_KEY), + &task_id_str); if (ret) { gf_msg_debug (this->name, errno, "Missing remove-brick-id"); @@ -2876,8 +2905,10 @@ glusterd_op_remove_brick (dict_t *dict, char **op_errstr) * Revisit this code when this constraint no * longer exist. */ - dict_del (volinfo->dict, "features.ctr-enabled"); - dict_del (volinfo->dict, "cluster.tier-mode"); + dict_deln (volinfo->dict, "features.ctr-enabled", + SLEN ("features.ctr-enabled")); + dict_deln (volinfo->dict, "cluster.tier-mode", + SLEN ("cluster.tier-mode")); hot_shd_key = gd_get_shd_key (volinfo->tier_info.hot_type); cold_shd_key = gd_get_shd_key (volinfo->tier_info.cold_type); @@ -2923,7 +2954,7 @@ glusterd_op_remove_brick (dict_t *dict, char **op_errstr) break; } - ret = dict_get_int32 (dict, "count", &count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &count); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Unable to get count"); @@ -2944,7 +2975,8 @@ glusterd_op_remove_brick (dict_t *dict, char **op_errstr) ret = -1; goto out; } - ret = dict_set_int32 (bricks_dict, "count", count); + ret = dict_set_int32n (bricks_dict, "count", + SLEN ("count"), count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, @@ -2954,8 +2986,8 @@ glusterd_op_remove_brick (dict_t *dict, char **op_errstr) } while ( i <= count) { - snprintf (key, sizeof(key), "brick%d", i); - ret = dict_get_str (dict, key, &brick); + keylen = snprintf (key, sizeof(key), "brick%d", i); + ret = dict_get_strn (dict, key, keylen, &brick); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Unable to get %s", @@ -2972,7 +3004,8 @@ glusterd_op_remove_brick (dict_t *dict, char **op_errstr) "Failed to duplicate brick name"); goto out; } - ret = dict_set_dynstr (bricks_dict, key, brick_tmpstr); + ret = dict_set_dynstrn (bricks_dict, key, keylen, + brick_tmpstr); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, @@ -2998,7 +3031,8 @@ glusterd_op_remove_brick (dict_t *dict, char **op_errstr) if (start_remove) volinfo->rebal.dict = dict_ref (bricks_dict); - ret = dict_get_int32 (dict, "replica-count", &replica_count); + ret = dict_get_int32n (dict, "replica-count", + SLEN ("replica-count"), &replica_count); if (!ret) { gf_msg (this->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_FAILED, @@ -3036,9 +3070,10 @@ glusterd_op_remove_brick (dict_t *dict, char **op_errstr) if (!glusterd_is_volume_replicate (volinfo) && conf->op_version >= GD_OP_VERSION_3_12_2) { - ret = dict_set_str (volinfo->dict, - "performance.client-io-threads", - "on"); + ret = dict_set_nstrn (volinfo->dict, + "performance.client-io-threads", + SLEN ("performance.client-io-threads"), + "on", SLEN ("on")); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set " @@ -3135,7 +3170,7 @@ glusterd_op_stage_barrier (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 (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Volname not present in " @@ -3184,7 +3219,7 @@ glusterd_op_barrier (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 (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Volname not present in " @@ -3200,7 +3235,7 @@ glusterd_op_barrier (dict_t *dict, char **op_errstr) goto out; } - ret = dict_get_str (dict, "barrier", &barrier_op); + ret = dict_get_strn (dict, "barrier", SLEN ("barrier"), &barrier_op); if (ret) { gf_asprintf (op_errstr, "Barrier op for volume %s not present " "in dict", volname); @@ -3287,7 +3322,7 @@ __glusterd_handle_add_tier_brick (rpcsvc_request_t *req) } } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get volume " @@ -3306,7 +3341,7 @@ __glusterd_handle_add_tier_brick (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "count", &brick_count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &brick_count); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get volume " "brick count"); @@ -3315,21 +3350,23 @@ __glusterd_handle_add_tier_brick (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "replica-count", &replica_count); + ret = dict_get_int32n (dict, "replica-count", + SLEN ("replica-count"), &replica_count); if (!ret) { gf_msg (this->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_SUCCESS, "replica-count is %d", replica_count); } - ret = dict_get_int32 (dict, "arbiter-count", &arbiter_count); + ret = dict_get_int32n (dict, "arbiter-count", + SLEN ("arbiter-count"), &arbiter_count); if (!ret) { gf_msg (this->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_SUCCESS, "arbiter-count is %d", arbiter_count); } - if (!dict_get (dict, "force")) { + if (!dict_getn (dict, "force", SLEN ("force"))) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Failed to get flag"); ret = -1; @@ -3354,7 +3391,7 @@ __glusterd_handle_add_tier_brick (rpcsvc_request_t *req) goto out; } - if (dict_get (dict, "attach-tier")) { + if (dict_getn (dict, "attach-tier", SLEN ("attach-tier"))) { if (volinfo->type == GF_CLUSTER_TYPE_TIER) { snprintf (err_str, sizeof (err_str), "Volume %s is already a tier.", volname); @@ -3364,7 +3401,8 @@ __glusterd_handle_add_tier_brick (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "hot-type", &type); + ret = dict_get_int32n (dict, "hot-type", SLEN ("hot-type"), + &type); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, @@ -3374,7 +3412,7 @@ __glusterd_handle_add_tier_brick (rpcsvc_request_t *req) } - ret = dict_get_str (dict, "bricks", &bricks); + ret = dict_get_strn (dict, "bricks", SLEN ("bricks"), &bricks); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get volume " "bricks"); @@ -3384,7 +3422,7 @@ __glusterd_handle_add_tier_brick (rpcsvc_request_t *req) } if (type != volinfo->type) { - ret = dict_set_int32 (dict, "type", type); + ret = dict_set_int32n (dict, "type", SLEN ("type"), type); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, diff --git a/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c index 607a0655432..a2c12ed5e32 100644 --- a/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c +++ b/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c @@ -41,7 +41,9 @@ glusterd_conn_init (glusterd_conn_t *conn, char *sockpath, if (ret) goto out; - ret = dict_set_str (options, "transport.socket.ignore-enoent", "on"); + ret = dict_set_nstrn (options, "transport.socket.ignore-enoent", + SLEN ("transport.socket.ignore-enoent"), + "on", SLEN ("on")); if (ret) goto out; diff --git a/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c b/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c index 7f2e92614eb..b92109cc027 100644 --- a/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c +++ b/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c @@ -109,8 +109,9 @@ int glusterd_gfproxydsvc_init (glusterd_volinfo_t *volinfo) goto out; } - 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) { volfileserver = "localhost"; } ret = glusterd_proc_init (&(svc->proc), gfproxyd_svc_name, pidfile, @@ -325,8 +326,9 @@ glusterd_gfproxydsvc_start (glusterd_svc_t *svc, int flags) if (volinfo->memory_accounting) runner_add_arg (&runner, "--mem-accounting"); - if (dict_get_str (priv->opts, GLUSTERD_LOCALTIME_LOGGING_KEY, - &localtime_logging) == 0) { + 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"); } diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index 8dd60dec517..44460bde005 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -292,6 +292,7 @@ static int _build_option_key (dict_t *d, char *k, data_t *v, void *tmp) { char reconfig_key[256] = {0, }; + int keylen; struct args_pack *pack = NULL; int ret = -1; xlator_t *this = NULL; @@ -320,9 +321,9 @@ _build_option_key (dict_t *d, char *k, data_t *v, void *tmp) (strcmp (k, "snap-max-soft-limit") == 0)) return 0; - snprintf (reconfig_key, sizeof (reconfig_key), "volume%d.option.%s", - pack->vol_count, k); - ret = dict_set_str (pack->dict, reconfig_key, v->data); + keylen = snprintf (reconfig_key, sizeof (reconfig_key), + "volume%d.option.%s", pack->vol_count, k); + ret = dict_set_strn (pack->dict, reconfig_key, keylen, v->data); if (0 == ret) pack->opt_count++; @@ -334,62 +335,76 @@ glusterd_add_tier_volume_detail_to_dict (glusterd_volinfo_t *volinfo, dict_t *dict, int count) { int ret = -1; - char key[256] = {0,}; + char key[64] = {0,}; + int keylen; GF_ASSERT (volinfo); GF_ASSERT (dict); - snprintf (key, sizeof (key), "volume%d.cold_type", count); - ret = dict_set_int32 (dict, key, volinfo->tier_info.cold_type); + keylen = snprintf (key, sizeof (key), "volume%d.cold_type", count); + ret = dict_set_int32n (dict, key, keylen, + volinfo->tier_info.cold_type); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.cold_brick_count", count); - ret = dict_set_int32 (dict, key, volinfo->tier_info.cold_brick_count); + keylen = snprintf (key, sizeof (key), "volume%d.cold_brick_count", + count); + ret = dict_set_int32n (dict, key, keylen, + volinfo->tier_info.cold_brick_count); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.cold_dist_count", count); - ret = dict_set_int32 (dict, key, - volinfo->tier_info.cold_dist_leaf_count); + keylen = snprintf (key, sizeof (key), "volume%d.cold_dist_count", + count); + ret = dict_set_int32n (dict, key, keylen, + volinfo->tier_info.cold_dist_leaf_count); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.cold_replica_count", count); - ret = dict_set_int32 (dict, key, - volinfo->tier_info.cold_replica_count); + keylen = snprintf (key, sizeof (key), "volume%d.cold_replica_count", + count); + ret = dict_set_int32n (dict, key, keylen, + volinfo->tier_info.cold_replica_count); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.cold_arbiter_count", count); - ret = dict_set_int32 (dict, key, volinfo->arbiter_count); + keylen = snprintf (key, sizeof (key), "volume%d.cold_arbiter_count", + count); + ret = dict_set_int32n (dict, key, keylen, volinfo->arbiter_count); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.cold_disperse_count", count); - ret = dict_set_int32 (dict, key, - volinfo->tier_info.cold_disperse_count); + keylen = snprintf (key, sizeof (key), "volume%d.cold_disperse_count", + count); + ret = dict_set_int32n (dict, key, keylen, + volinfo->tier_info.cold_disperse_count); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.cold_redundancy_count", count); - ret = dict_set_int32 (dict, key, - volinfo->tier_info.cold_redundancy_count); + keylen = snprintf (key, sizeof (key), + "volume%d.cold_redundancy_count", count); + ret = dict_set_int32n (dict, key, keylen, + volinfo->tier_info.cold_redundancy_count); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.hot_type", count); - ret = dict_set_int32 (dict, key, volinfo->tier_info.hot_type); + keylen = snprintf (key, sizeof (key), "volume%d.hot_type", count); + ret = dict_set_int32n (dict, key, keylen, + volinfo->tier_info.hot_type); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.hot_brick_count", count); - ret = dict_set_int32 (dict, key, volinfo->tier_info.hot_brick_count); + keylen = snprintf (key, sizeof (key), "volume%d.hot_brick_count", + count); + ret = dict_set_int32n (dict, key, keylen, + volinfo->tier_info.hot_brick_count); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.hot_replica_count", count); - ret = dict_set_int32 (dict, key, volinfo->tier_info.hot_replica_count); + keylen = snprintf (key, sizeof (key), "volume%d.hot_replica_count", + count); + ret = dict_set_int32n (dict, key, keylen, + volinfo->tier_info.hot_replica_count); if (ret) goto out; @@ -402,7 +417,8 @@ int glusterd_add_arbiter_info_to_bricks (glusterd_volinfo_t *volinfo, dict_t *volumes, int count) { - char key[256] = {0, }; + char key[64] = {0, }; + int keylen; int i = 0; int start_index = 0; int ret = 0; @@ -421,9 +437,10 @@ glusterd_add_arbiter_info_to_bricks (glusterd_volinfo_t *volinfo, if ((i - start_index + 1) % volinfo->tier_info.cold_replica_count != 0) continue; - snprintf (key, sizeof (key), "volume%d.brick%d.isArbiter", - count, i); - ret = dict_set_int32 (volumes, key, 1); + keylen = snprintf (key, sizeof (key), + "volume%d.brick%d.isArbiter", + count, i); + ret = dict_set_int32n (volumes, key, keylen, 1); if (ret) return ret; } @@ -433,9 +450,10 @@ glusterd_add_arbiter_info_to_bricks (glusterd_volinfo_t *volinfo, for (i = 1; i <= volinfo->brick_count; i++) { if (i % volinfo->replica_count != 0) continue; - snprintf (key, sizeof (key), "volume%d.brick%d.isArbiter", - count, i); - ret = dict_set_int32 (volumes, key, 1); + keylen = snprintf (key, sizeof (key), + "volume%d.brick%d.isArbiter", + count, i); + ret = dict_set_int32n (volumes, key, keylen, 1); if (ret) return ret; } @@ -449,7 +467,8 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo, { int ret = -1; - char key[256] = {0, }; + char key[64] = {0, }; + int keylen; glusterd_brickinfo_t *brickinfo = NULL; char *buf = NULL; int i = 1; @@ -469,28 +488,30 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo, GF_ASSERT (priv); - snprintf (key, sizeof (key), "volume%d.name", count); - ret = dict_set_str (volumes, key, volinfo->volname); + keylen = snprintf (key, sizeof (key), "volume%d.name", count); + ret = dict_set_strn (volumes, key, keylen, volinfo->volname); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.type", count); - ret = dict_set_int32 (volumes, key, volinfo->type); + keylen = snprintf (key, sizeof (key), "volume%d.type", count); + ret = dict_set_int32n (volumes, key, keylen, volinfo->type); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.status", count); - ret = dict_set_int32 (volumes, key, volinfo->status); + keylen = snprintf (key, sizeof (key), "volume%d.status", count); + ret = dict_set_int32n (volumes, key, keylen, volinfo->status); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.brick_count", count); - ret = dict_set_int32 (volumes, key, volinfo->brick_count); + keylen = snprintf (key, sizeof (key), "volume%d.brick_count", count); + ret = dict_set_int32n (volumes, key, keylen, volinfo->brick_count); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.hot_brick_count", count); - ret = dict_set_int32 (volumes, key, volinfo->tier_info.hot_brick_count); + keylen = snprintf (key, sizeof (key), "volume%d.hot_brick_count", + count); + ret = dict_set_int32n (volumes, key, keylen, + volinfo->tier_info.hot_brick_count); if (ret) goto out; @@ -501,38 +522,43 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo, goto out; } - snprintf (key, sizeof (key), "volume%d.dist_count", count); - ret = dict_set_int32 (volumes, key, volinfo->dist_leaf_count); + keylen = snprintf (key, sizeof (key), "volume%d.dist_count", count); + ret = dict_set_int32n (volumes, key, keylen, volinfo->dist_leaf_count); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.stripe_count", count); - ret = dict_set_int32 (volumes, key, volinfo->stripe_count); + keylen = snprintf (key, sizeof (key), "volume%d.stripe_count", count); + ret = dict_set_int32n (volumes, key, keylen, volinfo->stripe_count); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.replica_count", count); - ret = dict_set_int32 (volumes, key, volinfo->replica_count); + keylen = snprintf (key, sizeof (key), "volume%d.replica_count", + count); + ret = dict_set_int32n (volumes, key, keylen, volinfo->replica_count); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.disperse_count", count); - ret = dict_set_int32 (volumes, key, volinfo->disperse_count); + keylen = snprintf (key, sizeof (key), "volume%d.disperse_count", + count); + ret = dict_set_int32n (volumes, key, keylen, volinfo->disperse_count); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.redundancy_count", count); - ret = dict_set_int32 (volumes, key, volinfo->redundancy_count); + keylen = snprintf (key, sizeof (key), "volume%d.redundancy_count", + count); + ret = dict_set_int32n (volumes, key, keylen, + volinfo->redundancy_count); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.arbiter_count", count); - ret = dict_set_int32 (volumes, key, volinfo->arbiter_count); + keylen = snprintf (key, sizeof (key), "volume%d.arbiter_count", + count); + ret = dict_set_int32n (volumes, key, keylen, volinfo->arbiter_count); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.transport", count); - ret = dict_set_int32 (volumes, key, volinfo->transport_type); + keylen = snprintf (key, sizeof (key), "volume%d.transport", count); + ret = dict_set_int32n (volumes, key, keylen, volinfo->transport_type); if (ret) goto out; @@ -540,25 +566,27 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo, if (!volume_id_str) goto out; - snprintf (key, sizeof (key), "volume%d.volume_id", count); - ret = dict_set_dynstr (volumes, key, volume_id_str); + keylen = snprintf (key, sizeof (key), "volume%d.volume_id", count); + ret = dict_set_dynstrn (volumes, key, keylen, volume_id_str); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.rebalance", count); - ret = dict_set_int32 (volumes, key, volinfo->rebal.defrag_cmd); + keylen = snprintf (key, sizeof (key), "volume%d.rebalance", count); + ret = dict_set_int32n (volumes, key, keylen, + volinfo->rebal.defrag_cmd); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.snap_count", count); - ret = dict_set_int32 (volumes, key, volinfo->snap_count); + keylen = snprintf (key, sizeof (key), "volume%d.snap_count", count); + ret = dict_set_int32n (volumes, key, keylen, volinfo->snap_count); if (ret) goto out; #ifdef HAVE_BD_XLATOR if (volinfo->caps) { caps = 0; - snprintf (key, sizeof (key), "volume%d.xlator0", count); + keylen = snprintf (key, sizeof (key), "volume%d.xlator0", + count); buf = GF_MALLOC (256, gf_common_mt_char); if (!buf) { ret = ENOMEM; @@ -573,8 +601,8 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo, } if (volinfo->caps & CAPS_THIN) { - snprintf (key, sizeof (key), "volume%d.xlator0.caps%d", count, - caps++); + snprintf (key, sizeof (key), "volume%d.xlator0.caps%d", + count, caps++); buf = GF_MALLOC (256, gf_common_mt_char); if (!buf) { ret = ENOMEM; @@ -589,8 +617,8 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo, } if (volinfo->caps & CAPS_OFFLOAD_COPY) { - snprintf (key, sizeof (key), "volume%d.xlator0.caps%d", count, - caps++); + snprintf (key, sizeof (key), "volume%d.xlator0.caps%d", + count, caps++); buf = GF_MALLOC (256, gf_common_mt_char); if (!buf) { ret = ENOMEM; @@ -605,8 +633,8 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo, } if (volinfo->caps & CAPS_OFFLOAD_SNAPSHOT) { - snprintf (key, sizeof (key), "volume%d.xlator0.caps%d", count, - caps++); + snprintf (key, sizeof (key), "volume%d.xlator0.caps%d", + count, caps++); buf = GF_MALLOC (256, gf_common_mt_char); if (!buf) { ret = ENOMEM; @@ -621,8 +649,8 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo, } if (volinfo->caps & CAPS_OFFLOAD_ZERO) { - snprintf (key, sizeof (key), "volume%d.xlator0.caps%d", count, - caps++); + snprintf (key, sizeof (key), "volume%d.xlator0.caps%d", + count, caps++); buf = GF_MALLOC (256, gf_common_mt_char); if (!buf) { ret = ENOMEM; @@ -642,30 +670,34 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo, cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { char brick[1024] = {0,}; char brick_uuid[64] = {0,}; - snprintf (key, sizeof (key), "volume%d.brick%d", count, i); - len = snprintf (brick, sizeof (brick), "%s:%s", brickinfo->hostname, - brickinfo->path); - if ((len < 0) || (len >= 1024)) { + len = snprintf (brick, sizeof (brick), "%s:%s", + brickinfo->hostname, brickinfo->path); + if ((len < 0) || (len >= sizeof (brick))) { ret = -1; goto out; } buf = gf_strdup (brick); - ret = dict_set_dynstr (volumes, key, buf); + keylen = snprintf (key, sizeof (key), "volume%d.brick%d", + count, i); + ret = dict_set_dynstrn (volumes, key, keylen, buf); if (ret) goto out; - snprintf (key, sizeof (key), "volume%d.brick%d.uuid", count, i); - snprintf (brick_uuid, sizeof (brick_uuid), "%s", uuid_utoa (brickinfo->uuid)); + keylen = snprintf (key, sizeof (key), "volume%d.brick%d.uuid", + count, i); + snprintf (brick_uuid, sizeof (brick_uuid), "%s", + uuid_utoa (brickinfo->uuid)); buf = gf_strdup (brick_uuid); if (!buf) goto out; - ret = dict_set_dynstr (volumes, key, buf); + ret = dict_set_dynstrn (volumes, key, keylen, buf); if (ret) goto out; #ifdef HAVE_BD_XLATOR if (volinfo->caps & CAPS_BD) { - snprintf (key, sizeof (key), "volume%d.vg%d", count, i); - snprintf (brick, 1024, "%s", brickinfo->vg); + snprintf (key, sizeof (key), "volume%d.vg%d", + count, i); + snprintf (brick, sizeof (brick), "%s", brickinfo->vg); buf = gf_strdup (brick); ret = dict_set_dynstr (volumes, key, buf); if (ret) @@ -690,8 +722,9 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo, dict_foreach (dict, _build_option_key, (void *) &pack); dict_foreach (priv->opts, _build_option_key, &pack); - snprintf (key, sizeof (key), "volume%d.opt_count", pack.vol_count); - ret = dict_set_int32 (volumes, key, pack.opt_count); + keylen = snprintf (key, sizeof (key), "volume%d.opt_count", + pack.vol_count); + ret = dict_set_int32n (volumes, key, keylen, pack.opt_count); out: return ret; } @@ -763,7 +796,7 @@ glusterd_op_txn_begin (rpcsvc_request_t *req, glusterd_op_t op, void *ctx, } else { /* If no volname is given as a part of the command, locks will * not be held */ - ret = dict_get_str (dict, "volname", &tmp); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &tmp); if (ret) { gf_msg (this->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_FAILED, @@ -1215,7 +1248,7 @@ __glusterd_handle_cli_probe (rpcsvc_request_t *req) } } - ret = dict_get_str (dict, "hostname", &hostname); + ret = dict_get_strn (dict, "hostname", SLEN ("hostname"), &hostname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_HOSTNAME_NOTFOUND_IN_DICT, @@ -1223,7 +1256,7 @@ __glusterd_handle_cli_probe (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "port", &port); + ret = dict_get_int32n (dict, "port", SLEN ("port"), &port); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_PORT_NOTFOUND_IN_DICT, "Failed to get port"); @@ -1246,8 +1279,9 @@ __glusterd_handle_cli_probe (rpcsvc_request_t *req) "Received CLI probe req %s %d", hostname, port); - if (dict_get_str(this->options,"transport.socket.bind-address", - &bind_name) == 0) { + if (dict_get_strn (this->options, "transport.socket.bind-address", + SLEN ("transport.socket.bind-address"), + &bind_name) == 0) { gf_msg_debug ("glusterd", 0, "only checking probe address vs. bind address"); ret = gf_is_same_address (bind_name, hostname); @@ -1360,7 +1394,7 @@ __glusterd_handle_cli_deprobe (rpcsvc_request_t *req) GD_MSG_CLI_REQ_RECVD, "Received CLI deprobe req"); - ret = dict_get_str (dict, "hostname", &hostname); + ret = dict_get_strn (dict, "hostname", SLEN ("hostname"), &hostname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_HOSTNAME_NOTFOUND_IN_DICT, @@ -1368,13 +1402,13 @@ __glusterd_handle_cli_deprobe (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "port", &port); + ret = dict_get_int32n (dict, "port", SLEN ("port"), &port); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_PORT_NOTFOUND_IN_DICT, "Failed to get port"); goto out; } - ret = dict_get_int32 (dict, "flags", &flags); + ret = dict_get_int32n (dict, "flags", SLEN ("flags"), &flags); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_FLAGS_NOTFOUND_IN_DICT, "Failed to get flags"); @@ -1569,7 +1603,7 @@ __glusterd_handle_cli_get_volume (rpcsvc_request_t *req) } } - ret = dict_get_int32 (dict, "flags", &flags); + ret = dict_get_int32n (dict, "flags", SLEN ("flags"), &flags); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_FLAGS_NOTFOUND_IN_DICT, "failed to get flags"); @@ -1767,7 +1801,7 @@ __glusterd_handle_cli_uuid_get (rpcsvc_request_t *req) } uuid_utoa_r (MY_UUID, uuid_str); - ret = dict_set_str (rsp_dict, "uuid", uuid_str); + ret = dict_set_strn (rsp_dict, "uuid", SLEN ("uuid"), uuid_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set uuid in " @@ -1818,7 +1852,8 @@ __glusterd_handle_cli_list_volume (rpcsvc_request_t *req) glusterd_conf_t *priv = NULL; glusterd_volinfo_t *volinfo = NULL; int count = 0; - char key[1024] = {0,}; + char key[64] = {0,}; + int keylen; gf_cli_rsp rsp = {0,}; GF_ASSERT (req); @@ -1831,14 +1866,14 @@ __glusterd_handle_cli_list_volume (rpcsvc_request_t *req) goto out; cds_list_for_each_entry (volinfo, &priv->volumes, vol_list) { - snprintf (key, sizeof (key), "volume%d", count); - ret = dict_set_str (dict, key, volinfo->volname); + keylen = snprintf (key, sizeof (key), "volume%d", count); + ret = dict_set_strn (dict, key, keylen, volinfo->volname); if (ret) goto out; count++; } - ret = dict_set_int32 (dict, "count", count); + ret = dict_set_int32n (dict, "count", SLEN ("count"), count); if (ret) goto out; @@ -1934,7 +1969,7 @@ __glusterd_handle_reset_volume (rpcsvc_request_t *req) } } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { snprintf (err_str, sizeof (err_str), "Failed to get volume " "name"); @@ -2016,7 +2051,7 @@ __glusterd_handle_set_volume (rpcsvc_request_t *req) } } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { snprintf (err_str, sizeof (err_str), "Failed to get volume " "name while handling volume set command"); @@ -2032,7 +2067,7 @@ __glusterd_handle_set_volume (rpcsvc_request_t *req) goto out; } - ret = dict_get_str (dict, "key1", &key); + ret = dict_get_strn (dict, "key1", SLEN ("key1"), &key); if (ret) { snprintf (err_str, sizeof (err_str), "Failed to get key while" " handling volume set for %s", volname); @@ -2041,7 +2076,7 @@ __glusterd_handle_set_volume (rpcsvc_request_t *req) goto out; } - ret = dict_get_str (dict, "value1", &value); + ret = dict_get_strn (dict, "value1", SLEN ("value1"), &value); if (ret) { snprintf (err_str, sizeof (err_str), "Failed to get value while" " handling volume set for %s", volname); @@ -2124,7 +2159,7 @@ __glusterd_handle_sync_volume (rpcsvc_request_t *req) } } - ret = dict_get_str (dict, "hostname", &hostname); + ret = dict_get_strn (dict, "hostname", SLEN ("hostname"), &hostname); if (ret) { snprintf (msg, sizeof (msg), "Failed to get hostname"); gf_msg (this->name, GF_LOG_ERROR, 0, @@ -2132,12 +2167,13 @@ __glusterd_handle_sync_volume (rpcsvc_request_t *req) goto out; } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { - ret = dict_get_int32 (dict, "flags", (int32_t*)&flags); + ret = dict_get_int32n (dict, "flags", SLEN ("flags"), + (int32_t*)&flags); if (ret) { - snprintf (msg, sizeof (msg), "Failed to get volume name" - " or flags"); + snprintf (msg, sizeof (msg), + "Failed to get volume name or flags"); gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_FLAGS_NOTFOUND_IN_DICT, "%s", msg); goto out; @@ -2581,7 +2617,7 @@ __glusterd_handle_incoming_unfriend_req (rpcsvc_request_t *req) { int32_t ret = -1; gd1_mgmt_friend_req friend_req = {{0},}; - char remote_hostname[UNIX_PATH_MAX + 1] = {0,}; + char remote_hostname[UNIX_PATH_MAX + 1] = {0,}; GF_ASSERT (req); ret = xdr_to_generic (req->msg[0], &friend_req, @@ -2636,7 +2672,7 @@ glusterd_handle_friend_update_delete (dict_t *dict) GF_ASSERT (dict); - ret = dict_get_str (dict, "hostname", &hostname); + ret = dict_get_strn (dict, "hostname", SLEN ("hostname"), &hostname); if (ret) goto out; @@ -2682,6 +2718,7 @@ __glusterd_handle_friend_update (rpcsvc_request_t *req) gd1_mgmt_friend_update_rsp rsp = {{0},}; dict_t *dict = NULL; char key[100] = {0,}; + int keylen; char *uuid_buf = NULL; int i = 1; int count = 0; @@ -2745,11 +2782,11 @@ __glusterd_handle_friend_update (rpcsvc_request_t *req) } } - ret = dict_get_int32 (dict, "count", &count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &count); if (ret) goto out; - ret = dict_get_int32 (dict, "op", &op); + ret = dict_get_int32n (dict, "op", SLEN ("op"), &op); if (ret) goto out; @@ -2760,8 +2797,8 @@ __glusterd_handle_friend_update (rpcsvc_request_t *req) args.mode = GD_MODE_ON; while ( i <= count) { - snprintf (key, sizeof (key), "friend%d.uuid", i); - ret = dict_get_str (dict, key, &uuid_buf); + keylen = snprintf (key, sizeof (key), "friend%d.uuid", i); + ret = dict_get_strn (dict, key, keylen, &uuid_buf); if (ret) goto out; gf_uuid_parse (uuid_buf, uuid); @@ -3009,7 +3046,7 @@ __glusterd_handle_cli_profile_volume (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get volume " "name"); @@ -3022,7 +3059,7 @@ __glusterd_handle_cli_profile_volume (rpcsvc_request_t *req) GD_MSG_VOL_PROFILE_REQ_RCVD, "Received volume profile req " "for volume %s", volname); - ret = dict_get_int32 (dict, "op", &op); + ret = dict_get_int32n (dict, "op", SLEN ("op"), &op); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get operation"); gf_msg (this->name, GF_LOG_ERROR, 0, @@ -3205,8 +3242,9 @@ __glusterd_handle_umount (rpcsvc_request_t *req) GD_MSG_UMOUNT_REQ_RCVD, "Received umount req"); - if (dict_get_str (this->options, "mountbroker-root", - &mountbroker_root) != 0) { + if (dict_get_strn (this->options, "mountbroker-root", + SLEN ("mountbroker-root"), + &mountbroker_root) != 0) { rsp.op_errno = ENOENT; goto out; } @@ -3374,7 +3412,8 @@ glusterd_transport_inet_options_build (dict_t **options, const char *hostname, * wait too long after cli timesout before being able to resume normal * operations */ - ret = dict_set_int32 (dict, "frame-timeout", 600); + ret = dict_set_int32n (dict, "frame-timeout", SLEN ("frame-timeout"), + 600); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -3383,25 +3422,28 @@ glusterd_transport_inet_options_build (dict_t **options, const char *hostname, } /* Set keepalive options */ - ret = dict_get_int32 (this->options, - "transport.socket.keepalive-interval", - &interval); + ret = dict_get_int32n (this->options, + "transport.socket.keepalive-interval", + SLEN ("transport.socket.keepalive-interval"), + &interval); if (ret) { gf_msg ("glusterd", GF_LOG_WARNING, 0, GD_MSG_DICT_GET_FAILED, "Failed to get socket keepalive-interval"); } - ret = dict_get_int32 (this->options, - "transport.socket.keepalive-time", - &time); + ret = dict_get_int32n (this->options, + "transport.socket.keepalive-time", + SLEN ("transport.socket.keepalive-time"), + &time); if (ret) { gf_msg ("glusterd", GF_LOG_WARNING, 0, GD_MSG_DICT_GET_FAILED, "Failed to get socket keepalive-time"); } - ret = dict_get_int32 (this->options, - "transport.tcp-user-timeout", - &timeout); + ret = dict_get_int32n (this->options, + "transport.tcp-user-timeout", + SLEN ("transport.tcp-user-timeout"), + &timeout); if (ret) { gf_msg ("glusterd", GF_LOG_WARNING, 0, GD_MSG_DICT_GET_FAILED, @@ -3452,15 +3494,21 @@ glusterd_friend_rpc_create (xlator_t *this, glusterd_peerinfo_t *peerinfo, * use to reach us. */ if (this->options) { - data = dict_get(this->options,"transport.socket.bind-address"); + data = dict_getn (this->options, + "transport.socket.bind-address", + SLEN ("transport.socket.bind-address")); if (data) { - ret = dict_set(options, - "transport.socket.source-addr",data); + ret = dict_setn (options, + "transport.socket.source-addr", + SLEN ("transport.socket.source-addr"), + data); } - data = dict_get(this->options,"ping-timeout"); + data = dict_getn (this->options, "ping-timeout", + SLEN ("ping-timeout")); if (data) { - ret = dict_set(options, - "ping-timeout",data); + ret = dict_setn (options, + "ping-timeout", + SLEN ("ping-timeout"), data); } } @@ -3468,8 +3516,9 @@ glusterd_friend_rpc_create (xlator_t *this, glusterd_peerinfo_t *peerinfo, * is enabled */ if (this->ctx->secure_mgmt) { - ret = dict_set_str (options, "transport.socket.ssl-enabled", - "on"); + ret = dict_set_nstrn (options, "transport.socket.ssl-enabled", + SLEN ("transport.socket.ssl-enabled"), + "on", SLEN ("on")); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -3923,7 +3972,8 @@ glusterd_xfer_cli_probe_resp (rpcsvc_request_t *req, int32_t op_ret, sizeof (errstr), hostname, port); if (dict) { - 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_CMDSTR_NOTFOUND_IN_DICT, "Failed to get " @@ -4025,7 +4075,8 @@ glusterd_xfer_cli_deprobe_resp (rpcsvc_request_t *req, int32_t op_ret, sizeof (errstr), hostname); if (dict) { - 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_CMDSTR_NOTFOUND_IN_DICT, "Failed to get " @@ -4059,7 +4110,8 @@ glusterd_list_friends (rpcsvc_request_t *req, dict_t *dict, int32_t flags) dict_t *friends = NULL; gf1_cli_peer_list_rsp rsp = {0,}; char my_uuid_str[64] = {0,}; - char key[256] = {0,}; + char key[64] = {0,}; + int keylen; priv = THIS->private; GF_ASSERT (priv); @@ -4078,7 +4130,7 @@ glusterd_list_friends (rpcsvc_request_t *req, dict_t *dict, int32_t flags) cds_list_for_each_entry_rcu (entry, &priv->peers, uuid_list) { count++; ret = gd_add_peer_detail_to_dict (entry, - friends, count); + friends, count); if (ret) goto unlock; } @@ -4090,24 +4142,27 @@ unlock: if (flags == GF_CLI_LIST_POOL_NODES) { count++; - snprintf (key, sizeof (key), "friend%d.uuid", count); + keylen = snprintf (key, sizeof (key), "friend%d.uuid", count); uuid_utoa_r (MY_UUID, my_uuid_str); - ret = dict_set_str (friends, key, my_uuid_str); + ret = dict_set_strn (friends, key, keylen, my_uuid_str); if (ret) goto out; - snprintf (key, sizeof (key), "friend%d.hostname", count); - ret = dict_set_str (friends, key, "localhost"); + keylen = snprintf (key, sizeof (key), "friend%d.hostname", + count); + ret = dict_set_nstrn (friends, key, keylen, + "localhost", SLEN ("localhost")); if (ret) goto out; - snprintf (key, sizeof (key), "friend%d.connected", count); - ret = dict_set_int32 (friends, key, 1); + keylen = snprintf (key, sizeof (key), "friend%d.connected", + count); + ret = dict_set_int32n (friends, key, keylen, 1); if (ret) goto out; } - ret = dict_set_int32 (friends, "count", count); + ret = dict_set_int32n (friends, "count", SLEN ("count"), count); if (ret) goto out; @@ -4172,7 +4227,8 @@ glusterd_get_volumes (rpcsvc_request_t *req, dict_t *dict, int32_t flags) } } else if (flags == GF_CLI_GET_NEXT_VOLUME) { - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), + &volname); if (ret) { if (priv->volumes.next) { @@ -4200,7 +4256,8 @@ glusterd_get_volumes (rpcsvc_request_t *req, dict_t *dict, int32_t flags) count++; } } else if (flags == GF_CLI_GET_VOLUME) { - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), + &volname); if (ret) goto respond; @@ -4220,7 +4277,7 @@ glusterd_get_volumes (rpcsvc_request_t *req, dict_t *dict, int32_t flags) } respond: - ret = dict_set_int32 (volumes, "count", count); + ret = dict_set_int32n (volumes, "count", SLEN ("count"), count); if (ret) goto out; ret = dict_allocate_and_serialize (volumes, &rsp.dict.dict_val, @@ -4301,7 +4358,8 @@ __glusterd_handle_status_volume (rpcsvc_request_t *req) goto out; if (!(cmd & GF_CLI_STATUS_ALL)) { - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), + &volname); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get " "volume name"); @@ -4444,7 +4502,7 @@ __glusterd_handle_cli_clearlocks_volume (rpcsvc_request_t *req) goto out; } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get volume " "name"); @@ -4568,7 +4626,7 @@ __glusterd_handle_barrier (rpcsvc_request_t *req) goto out; } - 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_VOLNAME_NOTFOUND_IN_DICT, @@ -4628,6 +4686,7 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict) char *value = NULL; char err_str[2048] = {0,}; char dict_key[50] = {0,}; + int keylen; xlator_t *this = NULL; glusterd_conf_t *priv = NULL; glusterd_volinfo_t *volinfo = NULL; @@ -4643,7 +4702,7 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict) GF_ASSERT (req); GF_ASSERT (dict); - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { snprintf (err_str, sizeof (err_str), "Failed to get volume " "name while handling get volume option command"); @@ -4659,7 +4718,7 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict) } - ret = dict_get_str (dict, "key", &key); + ret = dict_get_strn (dict, "key", SLEN ("key"), &key); if (ret) { snprintf (err_str, sizeof (err_str), "Failed to get key " "while handling get volume option for %s", volname); @@ -4681,15 +4740,14 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict) } if (strcmp(key, "all")) { if (fnmatch (GD_HOOKS_SPECIFIC_KEY, key, FNM_NOESCAPE) == 0) { - sprintf (dict_key, "key%d", count); - ret = dict_set_str(dict, dict_key, key); + keylen = sprintf (dict_key, "key%d", count); + ret = dict_set_strn (dict, dict_key, keylen, key); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to " "set %s in dictionary", key); goto out; } - sprintf (dict_key, "value%d", count); ret = dict_get_str (volinfo->dict, key, &value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, @@ -4697,7 +4755,8 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict) "get %s in dictionary", key); goto out; } - ret = dict_set_str(dict, dict_key, value); + keylen = sprintf (dict_key, "value%d", count); + ret = dict_set_strn (dict, dict_key, keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to " @@ -4705,7 +4764,8 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict) goto out; } } else { - exists = glusterd_check_option_exists (key, &key_fixed); + exists = glusterd_check_option_exists (key, + &key_fixed); if (!exists) { snprintf (err_str, sizeof (err_str), "Option " "with name: %s does not exist", key); @@ -4732,7 +4792,9 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict) next release. Consider using `volume \ get all` instead for global options"; - ret = dict_set_str (dict, "warning", warn_str); + ret = dict_set_strn (dict, "warning", + SLEN ("warning"), + warn_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -4748,18 +4810,19 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict) goto out; } else if (strcmp (key, GLUSTERD_GLOBAL_OP_VERSION_KEY) == 0) { - sprintf (dict_key, "key%d", count); - ret = dict_set_str(dict, dict_key, key); + keylen = sprintf (dict_key, "key%d", count); + ret = dict_set_strn (dict, dict_key, keylen, + key); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed" "to set %s in dictionary", key); goto out; } - sprintf (dict_key, "value%d", count); + keylen = sprintf (dict_key, "value%d", count); sprintf (op_version_buff, "%d", priv->op_version); - ret = dict_set_str (dict, dict_key, + ret = dict_set_strn (dict, dict_key, keylen, op_version_buff); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, @@ -4770,8 +4833,9 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict) } } else if (strcmp (key, "config.memory-accounting") == 0) { - sprintf (dict_key, "key%d", count); - ret = dict_set_str(dict, dict_key, key); + keylen = sprintf (dict_key, "key%d", count); + ret = dict_set_strn (dict, dict_key, keylen, + key); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed" @@ -4779,14 +4843,18 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict) key); goto out; } - sprintf (dict_key, "value%d", count); + keylen = sprintf (dict_key, "value%d", count); if (volinfo->memory_accounting) - ret = dict_set_str(dict, dict_key, - "Enabled"); + ret = dict_set_nstrn (dict, dict_key, + keylen, + "Enabled", + SLEN ("Enabled")); else - ret = dict_set_str(dict, dict_key, - "Disabled"); + ret = dict_set_nstrn (dict, dict_key, + keylen, + "Disabled", + SLEN ("Disabled")); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed" @@ -4795,54 +4863,62 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict) goto out; } } else if (strcmp (key, "config.transport") == 0) { - sprintf (dict_key, "key%d", count); - ret = dict_set_str(dict, dict_key, key); + keylen = sprintf (dict_key, "key%d", count); + ret = dict_set_strn (dict, dict_key, keylen, + key); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, - GD_MSG_DICT_SET_FAILED, "Failed" - "to set %s in dictionary", key); + GD_MSG_DICT_SET_FAILED, + "Failed to set %s in " + "dictionary", key); goto out; } - sprintf (dict_key, "value%d", count); + keylen = sprintf (dict_key, "value%d", count); if (volinfo->transport_type == GF_TRANSPORT_RDMA) - ret = dict_set_str(dict, dict_key, - "rdma"); + ret = dict_set_nstrn (dict, dict_key, + keylen, "rdma", + SLEN ("rdma")); else if (volinfo->transport_type == GF_TRANSPORT_TCP) - ret = dict_set_str(dict, dict_key, - "tcp"); + ret = dict_set_nstrn (dict, dict_key, + keylen, "tcp", + SLEN ("tcp")); else if (volinfo->transport_type == GF_TRANSPORT_BOTH_TCP_RDMA) - ret = dict_set_str(dict, dict_key, - "tcp,rdma"); + ret = dict_set_nstrn (dict, dict_key, + keylen, + "tcp,rdma", + SLEN ("tcp,rdma")); else - ret = dict_set_str(dict, dict_key, - "none"); + ret = dict_set_nstrn (dict, dict_key, + keylen, "none", + SLEN ("none")); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, - GD_MSG_DICT_SET_FAILED, "Failed" - " to set value for key %s in " - "dictionary", key); + GD_MSG_DICT_SET_FAILED, + "Failed to set value for key " + "%s in dictionary", key); goto out; } } else { - sprintf (dict_key, "key%d", count); - ret = dict_set_str(dict, dict_key, key); + keylen = sprintf (dict_key, "key%d", count); + ret = dict_set_strn (dict, dict_key, keylen, + key); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, - GD_MSG_DICT_SET_FAILED, "Failed" - " to set %s in dictionary", - key); + GD_MSG_DICT_SET_FAILED, + "Failed to set %s in " + "dictionary", key); goto out; } - sprintf (dict_key, "value%d", count); + keylen = sprintf (dict_key, "value%d", count); ret = dict_get_str (priv->opts, key, &value); if (!ret) { - ret = dict_set_str(dict, dict_key, - value); + ret = dict_set_strn (dict, dict_key, + keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, @@ -4872,7 +4948,7 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict) /* Request is for a single option, explicitly set count to 1 * in the dictionary. */ - ret = dict_set_int32 (dict, "count", 1); + ret = dict_set_int32n (dict, "count", SLEN ("count"), 1); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, "Failed to set count " @@ -5016,7 +5092,8 @@ glusterd_print_gsync_status (FILE *fp, dict_t *gsync_dict) GF_VALIDATE_OR_GOTO (THIS->name, fp, out); GF_VALIDATE_OR_GOTO (THIS->name, gsync_dict, out); - ret = dict_get_int32 (gsync_dict, "gsync-count", &gsync_count); + ret = dict_get_int32n (gsync_dict, "gsync-count", + SLEN ("gsync-count"), &gsync_count); fprintf (fp, "Volume%d.gsync_count: %d\n", volcount, gsync_count); @@ -5026,9 +5103,11 @@ glusterd_print_gsync_status (FILE *fp, dict_t *gsync_dict) } for (i = 0; i < gsync_count; i++) { - snprintf (status_val_name, sizeof(status_val_name), "status_value%d", i); + snprintf (status_val_name, sizeof(status_val_name), + "status_value%d", i); - ret = dict_get_bin (gsync_dict, status_val_name, (void **)&(status_vals)); + ret = dict_get_bin (gsync_dict, status_val_name, + (void **)&(status_vals)); if (ret) goto out; @@ -5161,7 +5240,8 @@ glusterd_print_client_details (FILE *fp, dict_t *dict, xlator_t *this = NULL; int brick_index = -1; int client_count = 0; - char key[1024] = {0,}; + char key[64] = {0,}; + int keylen; char *clientname = NULL; uint64_t bytesread = 0; uint64_t byteswrite = 0; @@ -5217,15 +5297,18 @@ glusterd_print_client_details (FILE *fp, dict_t *dict, brick_req->op = GLUSTERD_BRICK_STATUS; brick_req->name = ""; - ret = dict_set_str (dict, "brick-name", brickinfo->path); + ret = dict_set_strn (dict, "brick-name", SLEN ("brick-name"), + brickinfo->path); if (ret) goto out; - ret = dict_set_int32 (dict, "cmd", GF_CLI_STATUS_CLIENTS); + ret = dict_set_int32n (dict, "cmd", SLEN ("cmd"), + GF_CLI_STATUS_CLIENTS); if (ret) goto out; - ret = dict_set_str (dict, "volname", volinfo->volname); + ret = dict_set_strn (dict, "volname", SLEN ("volname"), + volinfo->volname); if (ret) goto out; @@ -5240,7 +5323,8 @@ glusterd_print_client_details (FILE *fp, dict_t *dict, if (args.op_ret) goto out; - ret = dict_get_int32 (args.dict, "clientcount", &client_count); + ret = dict_get_int32n (args.dict, "clientcount", SLEN("clientcount"), + &client_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Couldn't get client count"); @@ -5257,8 +5341,9 @@ glusterd_print_client_details (FILE *fp, dict_t *dict, int i; for (i = 1; i <= client_count; i++) { - snprintf (key, sizeof (key), "client%d.hostname", i-1); - ret = dict_get_str (args.dict, key, &clientname); + keylen = snprintf (key, sizeof (key), + "client%d.hostname", i-1); + ret = dict_get_strn (args.dict, key, keylen, &clientname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -5375,7 +5460,7 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict) GF_VALIDATE_OR_GOTO (this->name, dict, out); - ret = dict_get_str (dict, "odir", &tmp_str); + ret = dict_get_strn (dict, "odir", SLEN ("odir"), &tmp_str); if (ret) { odirlen = gf_asprintf (&odir, "%s", "/var/run/gluster/"); gf_msg (this->name, GF_LOG_INFO, 0, @@ -5406,7 +5491,7 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict) goto out; } - ret = dict_get_str (dict, "filename", &tmp_str); + ret = dict_get_strn (dict, "filename", SLEN ("filename"), &tmp_str); if (ret) { now = time (NULL); strftime (timestamp, sizeof (timestamp), @@ -5435,7 +5520,8 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict) GF_FREE (odir); GF_FREE (filename); - ret = dict_set_dynstr (dict, "ofilepath", ofilepath); + ret = dict_set_dynstrn (dict, "ofilepath", SLEN ("ofilepath"), + ofilepath); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Unable to set output path"); diff --git a/xlators/mgmt/glusterd/src/glusterd-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-mgmt.c index a924dd3425b..2714478cda6 100644 --- a/xlators/mgmt/glusterd/src/glusterd-mgmt.c +++ b/xlators/mgmt/glusterd/src/glusterd-mgmt.c @@ -396,7 +396,9 @@ gd_mgmt_v3_commit_fn (glusterd_op_t op, dict_t *dict, "tier detach commit failed."); 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; @@ -477,7 +479,8 @@ gd_mgmt_v3_post_validate_fn (glusterd_op_t op, int32_t op_ret, dict_t *dict, } case GD_OP_ADD_BRICK: { - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", + SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get" @@ -505,7 +508,8 @@ gd_mgmt_v3_post_validate_fn (glusterd_op_t op, int32_t op_ret, dict_t *dict, } case GD_OP_START_VOLUME: { - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", + SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get" @@ -532,7 +536,8 @@ gd_mgmt_v3_post_validate_fn (glusterd_op_t op, int32_t op_ret, dict_t *dict, } case GD_OP_STOP_VOLUME: { - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", + SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get" @@ -551,7 +556,8 @@ gd_mgmt_v3_post_validate_fn (glusterd_op_t op, int32_t op_ret, dict_t *dict, } case GD_OP_ADD_TIER_BRICK: { - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", + SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get" @@ -574,7 +580,8 @@ gd_mgmt_v3_post_validate_fn (glusterd_op_t op, int32_t op_ret, dict_t *dict, GLUSTERD_VOLINFO_VER_AC_INCREMENT); if (ret) goto out; - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", + SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get" @@ -1196,7 +1203,8 @@ glusterd_mgmt_v3_build_payload (dict_t **req, char **op_errstr, dict_t *dict, case GD_OP_RESET_BRICK: case GD_OP_ADD_TIER_BRICK: { - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", + SLEN ("volname"), &volname); if (ret) { gf_msg (this->name, GF_LOG_CRITICAL, errno, GD_MSG_DICT_GET_FAILED, @@ -1684,15 +1692,15 @@ glusterd_mgmt_v3_commit (glusterd_op_t op, dict_t *op_ctx, dict_t *req_dict, if (!peerinfo->connected) { if (op == GD_OP_TIER_STATUS || op == GD_OP_DETACH_TIER_STATUS) { - ret = dict_get_int32 (args.dict, "count", - &count); + ret = dict_get_int32n (args.dict, "count", + SLEN ("count"), &count); if (ret) gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "failed to get index"); count++; - ret = dict_set_int32 (args.dict, "count", - count); + ret = dict_set_int32n (args.dict, "count", + SLEN ("count"), count); if (ret) gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -2330,7 +2338,7 @@ glusterd_set_barrier_value (dict_t *dict, char *option) * As of now only snapshot of single volume is supported, * Hence volname1 is directly fetched */ - ret = dict_get_str (dict, "volname1", &volname); + ret = dict_get_strn (dict, "volname1", SLEN ("volname1"), &volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Volname not present in " @@ -2435,7 +2443,8 @@ glusterd_mgmt_v3_initiate_snap_phases (rpcsvc_request_t *req, glusterd_op_t op, } /* Marking the operation as complete synctasked */ - ret = dict_set_int32 (dict, "is_synctasked", _gf_true); + ret = dict_set_int32n (dict, "is_synctasked", + SLEN ("is_synctasked"), _gf_true); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -2530,7 +2539,7 @@ glusterd_mgmt_v3_initiate_snap_phases (rpcsvc_request_t *req, glusterd_op_t op, above and along with it the originator glusterd also goes down? Who will initiate the cleanup? */ - ret = dict_set_int32 (req_dict, "cleanup", 1); + ret = dict_set_int32n (req_dict, "cleanup", SLEN ("cleanup"), 1); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "failed to set dict"); diff --git a/xlators/mgmt/glusterd/src/glusterd-mountbroker.c b/xlators/mgmt/glusterd/src/glusterd-mountbroker.c index c205b911d8e..4678d39d9ce 100644 --- a/xlators/mgmt/glusterd/src/glusterd-mountbroker.c +++ b/xlators/mgmt/glusterd/src/glusterd-mountbroker.c @@ -540,8 +540,9 @@ glusterd_do_mount (char *label, dict_t *argdict, char **path, int *op_errno) GF_ASSERT (op_errno); *op_errno = 0; - if (dict_get_str (this->options, "mountbroker-root", - &mountbroker_root) != 0) { + if (dict_get_strn (this->options, "mountbroker-root", + SLEN ("mountbroker-root"), + &mountbroker_root) != 0) { *op_errno = ENOENT; gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "'option mountbroker-root' " diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 551672c1d74..592bc16468a 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -600,10 +600,12 @@ glusterd_brick_op_build_payload (glusterd_op_t op, glusterd_brickinfo_t *brickin brick_req->op = GLUSTERD_BRICK_XLATOR_OP; brick_req->name = ""; - ret = dict_get_int32 (dict, "heal-op", (int32_t*)&heal_op); + ret = dict_get_int32n (dict, "heal-op", SLEN ("heal-op"), + (int32_t*)&heal_op); if (ret) goto out; - ret = dict_set_int32 (dict, "xl-op", heal_op); + ret = dict_set_int32n (dict, "xl-op", SLEN ("xl-op"), + heal_op); if (ret) goto out; } @@ -616,7 +618,8 @@ glusterd_brick_op_build_payload (glusterd_op_t op, glusterd_brickinfo_t *brickin goto out; brick_req->op = GLUSTERD_BRICK_STATUS; brick_req->name = ""; - ret = dict_set_str (dict, "brick-name", brickinfo->path); + ret = dict_set_strn (dict, "brick-name", SLEN ("brick-name"), + brickinfo->path); if (ret) goto out; } @@ -631,16 +634,17 @@ glusterd_brick_op_build_payload (glusterd_op_t op, glusterd_brickinfo_t *brickin goto out; brick_req->op = GLUSTERD_BRICK_XLATOR_DEFRAG; - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), + &volname); if (ret) goto out; ret = glusterd_volinfo_find (volname, &volinfo); if (ret) goto out; if (volinfo->type == GF_CLUSTER_TYPE_TIER) - snprintf (name, 1024, "%s-tier-dht", volname); + snprintf (name, sizeof (name), "%s-tier-dht", volname); else - snprintf (name, 1024, "%s-dht", volname); + snprintf (name, sizeof (name), "%s-dht", volname); brick_req->name = gf_strdup (name); break; @@ -717,7 +721,8 @@ glusterd_node_op_build_payload (glusterd_op_t op, gd1_mgmt_brick_op_req **req, brick_req->op = GLUSTERD_NODE_BITROT; - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), + &volname); if (ret) goto out; @@ -842,8 +847,8 @@ glusterd_validate_shared_storage (char *key, char *value, char *errstr) } if (!strncmp (value, "disable", SLEN ("disable"))) { - ret = dict_get_str (conf->opts, GLUSTERD_SHARED_STORAGE_KEY, - &op); + ret = dict_get_strn (conf->opts, GLUSTERD_SHARED_STORAGE_KEY, + SLEN (GLUSTERD_SHARED_STORAGE_KEY), &op); if (ret || !strncmp (op, "disable", SLEN ("disable"))) { snprintf (errstr, PATH_MAX, "Shared storage volume " "does not exist. Please enable shared storage" @@ -996,7 +1001,8 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) char *key_fixed = NULL; char *value = NULL; char *val_dup = NULL; - char str[100] = {0, }; + char keystr[100] = {0, }; + int keylen; char *trash_path = NULL; int trash_path_len = 0; int count = 0; @@ -1067,7 +1073,7 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) } } - ret = dict_get_int32 (dict, "count", &dict_count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &dict_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -1077,12 +1083,12 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) if (dict_count == 0) { /*No options would be specified of volume set help */ - if (dict_get (dict, "help" )) { + if (dict_getn (dict, "help", SLEN ("help"))) { ret = 0; goto out; } - if (dict_get (dict, "help-xml" )) { + if (dict_getn (dict, "help-xml", SLEN ("help-xml"))) { #if (HAVE_LIB_XML) ret = 0; goto out; @@ -1103,7 +1109,7 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) goto out; } - 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, @@ -1143,13 +1149,13 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) for ( count = 1; ret != 1 ; count++ ) { global_opt = _gf_false; - sprintf (str, "key%d", count); - ret = dict_get_str (dict, str, &key); + keylen = sprintf (keystr, "key%d", count); + ret = dict_get_strn (dict, keystr, keylen, &key); if (ret) break; - sprintf (str, "value%d", count); - ret = dict_get_str (dict, str, &value); + keylen = sprintf (keystr, "value%d", count); + ret = dict_get_strn (dict, keystr, keylen, &value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -1231,7 +1237,8 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) * command only if the volume is still in 'Created' * state */ - if ((dict_get (dict, "is-special-key") == NULL) && + if ((dict_getn (dict, "is-special-key", + SLEN ("is-special-key")) == NULL) && (volinfo->status != GLUSTERD_STATUS_NONE)) { snprintf (errstr, sizeof (errstr), " 'gluster " "volume set %s {enable, " @@ -1329,9 +1336,9 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) (local_key_op_version > local_new_client_op_version)) local_new_client_op_version = local_key_op_version; - sprintf (str, "op-version%d", count); + sprintf (keystr, "op-version%d", count); if (origin_glusterd) { - ret = dict_set_uint32 (dict, str, local_key_op_version); + ret = dict_set_uint32 (dict, keystr, local_key_op_version); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -1339,7 +1346,7 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) goto out; } } else if (check_op_version) { - ret = dict_get_uint32 (dict, str, &key_op_version); + ret = dict_get_uint32 (dict, keystr, &key_op_version); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -1680,7 +1687,7 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr) priv = this->private; GF_ASSERT (priv); - 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, @@ -1709,7 +1716,7 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr) } - ret = dict_get_str (dict, "key", &key); + ret = dict_get_strn (dict, "key", SLEN ("key"), &key); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get option key"); @@ -1799,7 +1806,7 @@ glusterd_op_stage_sync_volume (dict_t *dict, char **op_errstr) char msg[2048] = {0,}; glusterd_volinfo_t *volinfo = NULL; - ret = dict_get_str (dict, "hostname", &hostname); + ret = dict_get_strn (dict, "hostname", SLEN ("hostname"), &hostname); if (ret) { snprintf (msg, sizeof (msg), "hostname couldn't be " "retrieved from msg"); @@ -1809,7 +1816,8 @@ glusterd_op_stage_sync_volume (dict_t *dict, char **op_errstr) if (gf_is_local_addr (hostname)) { //volname is not present in case of sync all - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), + &volname); if (!ret) { exists = glusterd_check_volume_exists (volname); if (!exists) { @@ -1910,7 +1918,7 @@ glusterd_op_stage_status_volume (dict_t *dict, char **op_errstr) goto out; } - 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, "Unable to get volume name"); @@ -2005,7 +2013,7 @@ glusterd_op_stage_status_volume (dict_t *dict, char **op_errstr) goto out; } } else if ((cmd & GF_CLI_STATUS_BRICK) != 0) { - ret = dict_get_str (dict, "brick", &brick); + ret = dict_get_strn (dict, "brick", SLEN ("brick"), &brick); if (ret) goto out; @@ -2044,7 +2052,7 @@ glusterd_op_stage_stats_volume (dict_t *dict, char **op_errstr) int32_t stats_op = GF_CLI_STATS_NONE; glusterd_volinfo_t *volinfo = NULL; - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { snprintf (msg, sizeof (msg), "Volume name get failed"); goto out; @@ -2063,7 +2071,7 @@ glusterd_op_stage_stats_volume (dict_t *dict, char **op_errstr) if (ret) goto out; - ret = dict_get_int32 (dict, "op", &stats_op); + ret = dict_get_int32n (dict, "op", SLEN ("op"), &stats_op); if (ret) { snprintf (msg, sizeof (msg), "Volume profile op get failed"); goto out; @@ -2151,7 +2159,7 @@ _delete_reconfig_opt (dict_t *this, char *key, data_t *value, void *data) * */ if (!strncmp (key, VKEY_FEATURES_BITROT, strlen (VKEY_FEATURES_BITROT))) { - dict_del (this, VKEY_FEATURES_SCRUB); + dict_deln (this, VKEY_FEATURES_SCRUB, SLEN (VKEY_FEATURES_SCRUB)); } out: return 0; @@ -2273,14 +2281,14 @@ glusterd_op_reset_all_volume_options (xlator_t *this, dict_t *dict) gf_boolean_t quorum_action = _gf_false; conf = this->private; - ret = dict_get_str (dict, "key", &key); + ret = dict_get_strn (dict, "key", SLEN ("key"), &key); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get key"); goto out; } - ret = dict_get_int32 (dict, "force", &is_force); + ret = dict_get_int32n (dict, "force", SLEN ("force"), &is_force); if (ret) is_force = 0; @@ -2313,7 +2321,8 @@ glusterd_op_reset_all_volume_options (xlator_t *this, dict_t *dict) if (ret) goto out; - ret = dict_set_str (dup_opt, GLUSTERD_GLOBAL_OPT_VERSION, next_version); + ret = dict_set_strn (dup_opt, GLUSTERD_GLOBAL_OPT_VERSION, + SLEN (GLUSTERD_GLOBAL_OPT_VERSION), next_version); if (ret) goto out; @@ -2324,8 +2333,9 @@ glusterd_op_reset_all_volume_options (xlator_t *this, dict_t *dict) if (glusterd_is_quorum_changed (conf->opts, key, NULL)) quorum_action = _gf_true; - ret = dict_set_dynstr (conf->opts, GLUSTERD_GLOBAL_OPT_VERSION, - next_version); + ret = dict_set_dynstrn (conf->opts, GLUSTERD_GLOBAL_OPT_VERSION, + SLEN (GLUSTERD_GLOBAL_OPT_VERSION), + next_version); if (ret) goto out; else @@ -2362,7 +2372,7 @@ glusterd_op_reset_volume (dict_t *dict, char **op_rspstr) xlator_t *this = NULL; this = THIS; - 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, "Unable to get volume name"); @@ -2374,11 +2384,11 @@ glusterd_op_reset_volume (dict_t *dict, char **op_rspstr) goto out; } - ret = dict_get_int32 (dict, "force", &is_force); + ret = dict_get_int32n (dict, "force", SLEN ("force"), &is_force); if (ret) is_force = 0; - ret = dict_get_str (dict, "key", &key); + ret = dict_get_strn (dict, "key", SLEN ("key"), &key); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get option key"); @@ -2525,8 +2535,10 @@ glusterd_update_volumes_dict (glusterd_volinfo_t *volinfo) goto out; } } - ret = dict_get_str (volinfo->dict, "transport.address-family", - &address_family_str); + ret = dict_get_strn (volinfo->dict, + "transport.address-family", + SLEN ("transport.address-family"), + &address_family_str); if (ret) { if (volinfo->transport_type == GF_TRANSPORT_TCP) { ret = dict_set_dynstr_with_alloc @@ -2571,7 +2583,10 @@ glusterd_set_brick_mx_opts (dict_t *dict, char *key, char *value, priv = this->private; if (!strcmp (key, GLUSTERD_BRICK_MULTIPLEX_KEY)) { - ret = dict_set_dynstr (priv->opts, key, gf_strdup (value)); + ret = dict_set_dynstrn (priv->opts, + GLUSTERD_BRICK_MULTIPLEX_KEY, + SLEN (GLUSTERD_BRICK_MULTIPLEX_KEY), + gf_strdup (value)); } out: @@ -2584,7 +2599,8 @@ out: static int glusterd_dict_set_skip_cliot_key (glusterd_volinfo_t *volinfo) { - return dict_set_int32 (volinfo->dict, "skip-CLIOT", 1); + return dict_set_int32n (volinfo->dict, "skip-CLIOT", + SLEN ("skip-CLIOT"), 1); } static int @@ -2605,11 +2621,11 @@ glusterd_op_set_all_volume_options (xlator_t *this, dict_t *dict, glusterd_svc_t *svc = NULL; conf = this->private; - ret = dict_get_str (dict, "key1", &key); + ret = dict_get_strn (dict, "key1", SLEN ("key1"), &key); if (ret) goto out; - ret = dict_get_str (dict, "value1", &value); + ret = dict_get_strn (dict, "value1", SLEN ("value1"), &value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -2746,7 +2762,9 @@ glusterd_op_set_all_volume_options (xlator_t *this, dict_t *dict, if (ret) goto out; - ret = dict_set_str (dup_opt, GLUSTERD_GLOBAL_OPT_VERSION, next_version); + ret = dict_set_strn (dup_opt, GLUSTERD_GLOBAL_OPT_VERSION, + SLEN (GLUSTERD_GLOBAL_OPT_VERSION), + next_version); if (ret) goto out; @@ -2757,8 +2775,9 @@ glusterd_op_set_all_volume_options (xlator_t *this, dict_t *dict, if (glusterd_is_quorum_changed (conf->opts, key, value)) quorum_action = _gf_true; - ret = dict_set_dynstr (conf->opts, GLUSTERD_GLOBAL_OPT_VERSION, - next_version); + ret = dict_set_dynstrn (conf->opts, GLUSTERD_GLOBAL_OPT_VERSION, + SLEN (GLUSTERD_GLOBAL_OPT_VERSION), + next_version); if (ret) goto out; else @@ -2795,7 +2814,8 @@ glusterd_op_get_max_opversion (char **op_errstr, dict_t *rsp_dict) GF_VALIDATE_OR_GOTO (THIS->name, rsp_dict, out); - ret = dict_set_int32 (rsp_dict, "max-opversion", GD_OP_VERSION_MAX); + ret = dict_set_int32n (rsp_dict, "max-opversion", + SLEN ("max-opversion"), GD_OP_VERSION_MAX); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Setting value for max-opversion to dict failed"); @@ -2902,7 +2922,8 @@ glusterd_op_set_volume (dict_t *dict, char **errstr) char *key = NULL; char *key_fixed = NULL; char *value = NULL; - char str[50] = {0, }; + char keystr[50] = {0, }; + int keylen; gf_boolean_t global_opt = _gf_false; gf_boolean_t global_opts_set = _gf_false; glusterd_volinfo_t *voliter = NULL; @@ -2918,7 +2939,7 @@ glusterd_op_set_volume (dict_t *dict, char **errstr) priv = this->private; GF_ASSERT (priv); - ret = dict_get_int32 (dict, "count", &dict_count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &dict_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -2931,7 +2952,7 @@ glusterd_op_set_volume (dict_t *dict, char **errstr) goto out; } - 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, "Unable to get volume name"); @@ -2968,13 +2989,13 @@ glusterd_op_set_volume (dict_t *dict, char **errstr) for (count = 1; ret != -1 ; count++) { - snprintf (str, sizeof str, "key%d", count); - ret = dict_get_str (dict, str, &key); + keylen = snprintf (keystr, sizeof (keystr), "key%d", count); + ret = dict_get_strn (dict, keystr, keylen, &key); if (ret) break; - snprintf (str, sizeof str, "value%d", count); - ret = dict_get_str (dict, str, &value); + keylen = snprintf (keystr, sizeof (keystr), "value%d", count); + ret = dict_get_strn (dict, keystr, keylen, &value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -3205,7 +3226,7 @@ glusterd_op_sync_volume (dict_t *dict, char **op_errstr, priv = this->private; GF_ASSERT (priv); - ret = dict_get_str (dict, "hostname", &hostname); + ret = dict_get_strn (dict, "hostname", SLEN ("hostname"), &hostname); if (ret) { snprintf (msg, sizeof (msg), "hostname couldn't be " "retrieved from msg"); @@ -3219,7 +3240,7 @@ glusterd_op_sync_volume (dict_t *dict, char **op_errstr, } //volname is not present in case of sync all - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (!ret) { ret = glusterd_volinfo_find (volname, &volinfo); if (ret) { @@ -3252,7 +3273,7 @@ glusterd_op_sync_volume (dict_t *dict, char **op_errstr, vol_count = count++; } } - ret = dict_set_int32 (rsp_dict, "count", vol_count); + ret = dict_set_int32n (rsp_dict, "count", SLEN ("count"), vol_count); out: gf_msg_debug ("glusterd", 0, "Returning %d", ret); @@ -3264,29 +3285,28 @@ static int glusterd_add_profile_volume_options (glusterd_volinfo_t *volinfo) { int ret = -1; - char *latency_key = NULL; - char *fd_stats_key = NULL; GF_ASSERT (volinfo); - latency_key = VKEY_DIAG_LAT_MEASUREMENT; - fd_stats_key = VKEY_DIAG_CNT_FOP_HITS; - - ret = dict_set_str (volinfo->dict, latency_key, "on"); + ret = dict_set_nstrn (volinfo->dict, VKEY_DIAG_LAT_MEASUREMENT, + SLEN (VKEY_DIAG_LAT_MEASUREMENT), + "on", SLEN ("on")); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "failed to set the volume %s " "option %s value %s", - volinfo->volname, latency_key, "on"); + volinfo->volname, VKEY_DIAG_LAT_MEASUREMENT, "on"); goto out; } - ret = dict_set_str (volinfo->dict, fd_stats_key, "on"); + ret = dict_set_nstrn (volinfo->dict, VKEY_DIAG_CNT_FOP_HITS, + SLEN (VKEY_DIAG_CNT_FOP_HITS), + "on", SLEN ("on")); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "failed to set the volume %s " "option %s value %s", - volinfo->volname, fd_stats_key, "on"); + volinfo->volname, VKEY_DIAG_CNT_FOP_HITS, "on"); goto out; } out: @@ -3297,15 +3317,12 @@ out: static void glusterd_remove_profile_volume_options (glusterd_volinfo_t *volinfo) { - char *latency_key = NULL; - char *fd_stats_key = NULL; - GF_ASSERT (volinfo); - latency_key = VKEY_DIAG_LAT_MEASUREMENT; - fd_stats_key = VKEY_DIAG_CNT_FOP_HITS; - dict_del (volinfo->dict, latency_key); - dict_del (volinfo->dict, fd_stats_key); + dict_deln (volinfo->dict, VKEY_DIAG_LAT_MEASUREMENT, + SLEN (VKEY_DIAG_LAT_MEASUREMENT)); + dict_deln (volinfo->dict, VKEY_DIAG_CNT_FOP_HITS, + SLEN (VKEY_DIAG_CNT_FOP_HITS)); } static int @@ -3318,7 +3335,7 @@ glusterd_op_stats_volume (dict_t *dict, char **op_errstr, glusterd_volinfo_t *volinfo = NULL; int32_t stats_op = GF_CLI_STATS_NONE; - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "volume name get failed"); @@ -3335,7 +3352,7 @@ glusterd_op_stats_volume (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_int32 (dict, "op", &stats_op); + ret = dict_get_int32n (dict, "op", SLEN ("op"), &stats_op); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "volume profile op get failed"); @@ -3406,9 +3423,9 @@ _add_remove_bricks_to_dict (dict_t *dict, glusterd_volinfo_t *volinfo, int i = 0; char brick_key[1024] = {0,}; char dict_key[1024] ={0,}; + int keylen; char *brick = NULL; xlator_t *this = NULL; - int32_t len = 0; GF_ASSERT (dict); GF_ASSERT (volinfo); @@ -3417,7 +3434,8 @@ _add_remove_bricks_to_dict (dict_t *dict, glusterd_volinfo_t *volinfo, this = THIS; GF_ASSERT (this); - ret = dict_get_int32 (volinfo->rebal.dict, "count", &count); + ret = dict_get_int32n (volinfo->rebal.dict, "count", + SLEN ("count"), &count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -3425,8 +3443,8 @@ _add_remove_bricks_to_dict (dict_t *dict, glusterd_volinfo_t *volinfo, goto out; } - snprintf (dict_key, sizeof (dict_key), "%s.count", prefix); - ret = dict_set_int32 (dict, dict_key, count); + keylen = snprintf (dict_key, sizeof (dict_key), "%s.count", prefix); + ret = dict_set_int32n (dict, dict_key, keylen, count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -3435,9 +3453,11 @@ _add_remove_bricks_to_dict (dict_t *dict, glusterd_volinfo_t *volinfo, } for (i = 1; i <= count; i++) { - snprintf (brick_key, sizeof (brick_key), "brick%d", i); + keylen = snprintf (brick_key, sizeof (brick_key), + "brick%d", i); - ret = dict_get_str (volinfo->rebal.dict, brick_key, &brick); + ret = dict_get_strn (volinfo->rebal.dict, brick_key, + keylen, &brick); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -3445,13 +3465,13 @@ _add_remove_bricks_to_dict (dict_t *dict, glusterd_volinfo_t *volinfo, goto out; } - len = snprintf (dict_key, sizeof (dict_key), "%s.%s", prefix, - brick_key); - if ((len < 0) || (len >= sizeof(dict_key))) { + keylen = snprintf (dict_key, sizeof (dict_key), + "%s.%s", prefix, brick_key); + if ((keylen < 0) || (keylen >= sizeof(dict_key))) { ret = -1; goto out; } - ret = dict_set_str (dict, dict_key, brick); + ret = dict_set_strn (dict, dict_key, keylen, brick); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -3473,7 +3493,8 @@ _add_task_to_dict (dict_t *dict, glusterd_volinfo_t *volinfo, int op, int index) { int ret = -1; - char key[128] = {0,}; + char key[64] = {0,}; + int keylen; char *uuid_str = NULL; int status = 0; xlator_t *this = NULL; @@ -3509,8 +3530,8 @@ _add_task_to_dict (dict_t *dict, glusterd_volinfo_t *volinfo, int op, int index) goto out; } - snprintf (key, sizeof (key), "task%d.type", index); - ret = dict_set_str (dict, key, (char *)gd_op_list[op]); + keylen = snprintf (key, sizeof (key), "task%d.type", index); + ret = dict_set_strn (dict, key, keylen, (char *)gd_op_list[op]); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -3518,11 +3539,11 @@ _add_task_to_dict (dict_t *dict, glusterd_volinfo_t *volinfo, int op, int index) goto out; } - snprintf (key, sizeof (key), "task%d.id", index); + keylen = snprintf (key, sizeof (key), "task%d.id", index); if (!uuid_str) goto out; - ret = dict_set_dynstr (dict, key, uuid_str); + ret = dict_set_dynstrn (dict, key, keylen, uuid_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -3531,8 +3552,8 @@ _add_task_to_dict (dict_t *dict, glusterd_volinfo_t *volinfo, int op, int index) } uuid_str = NULL; - snprintf (key, sizeof (key), "task%d.status", index); - ret = dict_set_int32 (dict, key, status); + keylen = snprintf (key, sizeof (key), "task%d.status", index); + ret = dict_set_int32n (dict, key, keylen, status); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -3585,7 +3606,7 @@ glusterd_aggregate_task_status (dict_t *rsp_dict, glusterd_volinfo_t *volinfo) tasks++; } done: - ret = dict_set_int32 (rsp_dict, "tasks", tasks); + ret = dict_set_int32n (rsp_dict, "tasks", SLEN ("tasks"), tasks); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -3653,7 +3674,7 @@ glusterd_op_status_volume (dict_t *dict, char **op_errstr, if (cmd & GF_CLI_STATUS_ALL) goto out; - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) goto out; @@ -3718,7 +3739,7 @@ glusterd_op_status_volume (dict_t *dict, char **op_errstr, other_count++; node_count++; } else if ((cmd & GF_CLI_STATUS_BRICK) != 0) { - ret = dict_get_str (dict, "brick", &brick); + ret = dict_get_strn (dict, "brick", SLEN ("brick"), &brick); if (ret) goto out; @@ -3861,29 +3882,33 @@ glusterd_op_status_volume (dict_t *dict, char **op_errstr, if (volinfo->type == GF_CLUSTER_TYPE_TIER) hot_brick_count = volinfo->tier_info.hot_brick_count; - ret = dict_set_int32 (rsp_dict, "hot_brick_count", hot_brick_count); + ret = dict_set_int32n (rsp_dict, "hot_brick_count", + SLEN ("hot_brick_count"), hot_brick_count); if (ret) goto out; - ret = dict_set_int32 (rsp_dict, "type", volinfo->type); + ret = dict_set_int32n (rsp_dict, "type", SLEN ("type"), + volinfo->type); if (ret) goto out; - ret = dict_set_int32 (rsp_dict, "brick-index-max", brick_index); + ret = dict_set_int32n (rsp_dict, "brick-index-max", + SLEN ("brick-index-max"), brick_index); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Error setting brick-index-max to dict"); goto out; } - ret = dict_set_int32 (rsp_dict, "other-count", other_count); + ret = dict_set_int32n (rsp_dict, "other-count", + SLEN ("other-count"), other_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Error setting other-count to dict"); goto out; } - ret = dict_set_int32 (rsp_dict, "count", node_count); + ret = dict_set_int32n (rsp_dict, "count", SLEN ("count"), node_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -4230,7 +4255,8 @@ glusterd_op_ac_lock (glusterd_op_sm_event_t *event, void *ctx) if (!ret) conf->mgmt_v3_lock_timeout = timeout + 120; - ret = dict_get_str (lock_ctx->dict, "volname", &volname); + ret = dict_get_strn (lock_ctx->dict, "volname", + SLEN ("volname"), &volname); if (ret) gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -4245,7 +4271,8 @@ glusterd_op_ac_lock (glusterd_op_sm_event_t *event, void *ctx) volname); goto out; } - ret = dict_get_str (lock_ctx->dict, "globalname", &globalname); + ret = dict_get_strn (lock_ctx->dict, "globalname", + SLEN ("globalname"), &globalname); if (!ret) { ret = glusterd_mgmt_v3_lock (globalname, lock_ctx->uuid, &op_errno, "global"); @@ -4293,7 +4320,8 @@ glusterd_op_ac_unlock (glusterd_op_sm_event_t *event, void *ctx) ret = glusterd_unlock (lock_ctx->uuid); glusterd_op_unlock_send_resp (lock_ctx->req, ret); } else { - ret = dict_get_str (lock_ctx->dict, "volname", &volname); + ret = dict_get_strn (lock_ctx->dict, "volname", + SLEN ("volname"), &volname); if (ret) gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -4309,7 +4337,8 @@ glusterd_op_ac_unlock (glusterd_op_sm_event_t *event, void *ctx) goto out; } - ret = dict_get_str (lock_ctx->dict, "globalname", &globalname); + ret = dict_get_strn (lock_ctx->dict, "globalname", + SLEN ("globalname"), &globalname); if (!ret) { ret = glusterd_mgmt_v3_unlock (globalname, lock_ctx->uuid, "global"); @@ -4407,7 +4436,7 @@ glusterd_dict_set_volid (dict_t *dict, char *volname, char **op_errstr) ret = -1; goto out; } - ret = dict_set_dynstr (dict, "vol-id", volid); + ret = dict_set_dynstrn (dict, "vol-id", SLEN ("vol-id"), volid); if (ret) { snprintf (msg, sizeof (msg), "Failed to set volume id of volume" " %s", volname); @@ -4504,8 +4533,9 @@ glusterd_op_build_payload (dict_t **req, char **op_errstr, dict_t *op_ctx) case GD_OP_CREATE_VOLUME: { ++glusterfs_port; - ret = dict_set_int32 (dict, "port", - glusterfs_port); + ret = dict_set_int32n (dict, "port", + SLEN ("port"), + glusterfs_port); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -4536,7 +4566,8 @@ glusterd_op_build_payload (dict_t **req, char **op_errstr, dict_t *op_ctx) case GD_OP_SET_VOLUME: { - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", + SLEN ("volname"), &volname); if (ret) { gf_msg (this->name, GF_LOG_CRITICAL, 0, GD_MSG_DICT_GET_FAILED, @@ -4562,7 +4593,8 @@ glusterd_op_build_payload (dict_t **req, char **op_errstr, dict_t *op_ctx) case GD_OP_REMOVE_TIER_BRICK: { dict_t *dict = ctx; - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", + SLEN ("volname"), &volname); if (ret) { gf_msg (this->name, GF_LOG_CRITICAL, 0, GD_MSG_DICT_GET_FAILED, @@ -4655,7 +4687,8 @@ glusterd_op_build_payload (dict_t **req, char **op_errstr, dict_t *op_ctx) * other special needs can all "fall through" to it. */ if (do_common) { - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), + &volname); if (ret) { gf_msg (this->name, GF_LOG_CRITICAL, -ret, GD_MSG_DICT_GET_FAILED, @@ -4833,6 +4866,7 @@ glusterd_op_volume_dict_uuid_to_hostname (dict_t *dict, const char *key_fmt, int ret = -1; int i = 0; char key[1024]; + int keylen; char *uuid_str = NULL; uuid_t uuid = {0,}; char *hostname = NULL; @@ -4845,8 +4879,8 @@ glusterd_op_volume_dict_uuid_to_hostname (dict_t *dict, const char *key_fmt, GF_ASSERT (key_fmt); for (i = idx_min; i < idx_max; i++) { - snprintf (key, sizeof (key), key_fmt, i); - ret = dict_get_str (dict, key, &uuid_str); + keylen = snprintf (key, sizeof (key), key_fmt, i); + ret = dict_get_strn (dict, key, keylen, &uuid_str); if (ret) { ret = 0; continue; @@ -4868,7 +4902,7 @@ glusterd_op_volume_dict_uuid_to_hostname (dict_t *dict, const char *key_fmt, if (hostname) { gf_msg_debug (this->name, 0, "%s -> %s", uuid_str, hostname); - ret = dict_set_dynstr (dict, key, hostname); + ret = dict_set_dynstrn (dict, key, keylen, hostname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -4886,7 +4920,7 @@ out: } static int -reassign_defrag_status (dict_t *dict, char *key, gf_defrag_status_t *status) +reassign_defrag_status (dict_t *dict, char *key, int keylen, gf_defrag_status_t *status) { int ret = 0; @@ -4913,7 +4947,7 @@ reassign_defrag_status (dict_t *dict, char *key, gf_defrag_status_t *status) break; } - ret = dict_set_int32(dict, key, *status); + ret = dict_set_int32n (dict, key, keylen, *status); if (ret) gf_msg (THIS->name, GF_LOG_WARNING, 0, GD_MSG_DICT_SET_FAILED, @@ -4931,12 +4965,13 @@ glusterd_op_check_peer_defrag_status (dict_t *dict, int count) { glusterd_volinfo_t *volinfo = NULL; gf_defrag_status_t status = GF_DEFRAG_STATUS_NOT_STARTED; - char key[256] = {0,}; + char key[64] = {0,}; + int keylen; char *volname = NULL; int ret = -1; int i = 1; - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg (THIS->name, GF_LOG_WARNING, 0, GD_MSG_DICT_GET_FAILED, "Unable to get volume name"); @@ -4959,15 +4994,15 @@ glusterd_op_check_peer_defrag_status (dict_t *dict, int count) } do { - snprintf (key, sizeof (key), "status-%d", i); - ret = dict_get_int32 (dict, key, (int32_t *)&status); + keylen = snprintf (key, sizeof (key), "status-%d", i); + ret = dict_get_int32n (dict, key, keylen, (int32_t *)&status); if (ret) { gf_msg (THIS->name, GF_LOG_WARNING, 0, GD_MSG_DICT_GET_FAILED, "failed to get defrag %s", key); goto out; } - ret = reassign_defrag_status (dict, key, &status); + ret = reassign_defrag_status (dict, key, keylen, &status); if (ret) goto out; i++; @@ -5018,26 +5053,30 @@ glusterd_op_modify_port_key (dict_t *op_ctx, int brick_index_max) char *port = NULL; int i = 0; int ret = -1; - char key[1024] = {0}; - char old_key[1024] = {0}; + char key[64] = {0}; + int keylen; + char old_key[64] = {0}; + int old_keylen; for (i = 0; i <= brick_index_max; i++) { - snprintf (key, sizeof (key), "brick%d.rdma_port", i); - ret = dict_get_str (op_ctx, key, &port); + keylen = snprintf (key, sizeof (key), "brick%d.rdma_port", i); + ret = dict_get_strn (op_ctx, key, keylen, &port); if (ret) { - snprintf (old_key, sizeof (old_key), - "brick%d.port", i); - ret = dict_get_str (op_ctx, old_key, &port); + old_keylen = snprintf (old_key, sizeof (old_key), + "brick%d.port", i); + ret = dict_get_strn (op_ctx, old_key, old_keylen, + &port); if (ret) goto out; - ret = dict_set_str (op_ctx, key, port); + ret = dict_set_strn (op_ctx, key, keylen, port); if (ret) goto out; - ret = dict_set_str (op_ctx, old_key, "\0"); + ret = dict_set_nstrn (op_ctx, old_key, old_keylen, + "\0", SLEN ("\0")); if (ret) goto out; } @@ -5065,7 +5104,8 @@ glusterd_op_modify_op_ctx (glusterd_op_t op, void *ctx) glusterd_volinfo_t *volinfo = NULL; char *port = 0; int i = 0; - char key[1024] = {0,}; + char key[64] = {0,}; + int keylen; this = THIS; GF_ASSERT (this); @@ -5099,15 +5139,17 @@ glusterd_op_modify_op_ctx (glusterd_op_t op, void *ctx) goto out; } - ret = dict_get_int32 (op_ctx, "brick-index-max", - &brick_index_max); + ret = dict_get_int32n (op_ctx, "brick-index-max", + SLEN ("brick-index-max"), + &brick_index_max); if (ret) { gf_msg_debug (this->name, 0, "Failed to get brick-index-max"); goto out; } - ret = dict_get_int32 (op_ctx, "other-count", &other_count); + ret = dict_get_int32n (op_ctx, "other-count", + SLEN ("other-count"), &other_count); if (ret) { gf_msg_debug (this->name, 0, "Failed to get other-count"); @@ -5121,15 +5163,18 @@ glusterd_op_modify_op_ctx (glusterd_op_t op, void *ctx) * rdma port in older key. Changing that value from here * to support backward compatibility */ - ret = dict_get_str (op_ctx, "volname", &volname); + ret = dict_get_strn (op_ctx, "volname", SLEN ("volname"), + &volname); if (ret) goto out; for (i = 0; i <= brick_index_max; i++) { - snprintf (key, sizeof (key), "brick%d.rdma_port", i); - ret = dict_get_str (op_ctx, key, &port); + keylen = snprintf (key, sizeof (key), + "brick%d.rdma_port", i); + ret = dict_get_strn (op_ctx, key, keylen, &port); if (ret) { - ret = dict_set_str (op_ctx, key, "\0"); + ret = dict_set_nstrn (op_ctx, key, keylen, + "\0", SLEN ("\0")); if (ret) goto out; } @@ -5147,17 +5192,19 @@ glusterd_op_modify_op_ctx (glusterd_op_t op, void *ctx) /* add 'brick%d.peerid' into op_ctx with value of 'brick%d.path'. nfs/sshd like services have this additional uuid */ { - char key[1024]; char *uuid_str = NULL; char *uuid = NULL; int i; for (i = brick_index_max + 1; i < count; i++) { - snprintf (key, sizeof (key), "brick%d.path", i); - ret = dict_get_str (op_ctx, key, &uuid_str); + keylen = snprintf (key, sizeof (key), + "brick%d.path", i); + ret = dict_get_strn (op_ctx, key, keylen, + &uuid_str); if (!ret) { - snprintf (key, sizeof (key), - "brick%d.peerid", i); + keylen = snprintf (key, sizeof (key), + "brick%d.peerid", + i); uuid = gf_strdup (uuid_str); if (!uuid) { gf_msg_debug (this->name, 0, @@ -5165,8 +5212,8 @@ glusterd_op_modify_op_ctx (glusterd_op_t op, void *ctx) " uuid_str"); continue; } - ret = dict_set_dynstr (op_ctx, key, - uuid); + ret = dict_set_dynstrn (op_ctx, key, + keylen, uuid); if (ret != 0) { GF_FREE (uuid); } @@ -5189,7 +5236,8 @@ glusterd_op_modify_op_ctx (glusterd_op_t op, void *ctx) if (!ret) goto out; - ret = dict_get_int32 (op_ctx, "count", &count); + ret = dict_get_int32n (op_ctx, "count", SLEN ("count"), + &count); if (ret) { gf_msg_debug (this->name, 0, "Failed to get brick count"); @@ -5215,7 +5263,8 @@ glusterd_op_modify_op_ctx (glusterd_op_t op, void *ctx) case GD_OP_DETACH_TIER_STATUS: case GD_OP_SCRUB_STATUS: case GD_OP_SCRUB_ONDEMAND: - ret = dict_get_int32 (op_ctx, "count", &count); + ret = dict_get_int32n (op_ctx, "count", SLEN ("count"), + &count); if (ret) { gf_msg_debug (this->name, 0, "Failed to get count"); @@ -5225,17 +5274,18 @@ glusterd_op_modify_op_ctx (glusterd_op_t op, void *ctx) /* add 'node-name-%d' into op_ctx with value uuid_str. this will be used to convert to hostname later */ { - char key[1024]; char *uuid_str = NULL; char *uuid = NULL; int i; for (i = 1; i <= count; i++) { - snprintf (key, sizeof (key), "node-uuid-%d", i); - ret = dict_get_str (op_ctx, key, &uuid_str); + keylen = snprintf (key, sizeof (key), + "node-uuid-%d", i); + ret = dict_get_strn (op_ctx, key, keylen, + &uuid_str); if (!ret) { - snprintf (key, sizeof (key), - "node-name-%d", i); + keylen = snprintf (key, sizeof (key), + "node-name-%d", i); uuid = gf_strdup (uuid_str); if (!uuid) { gf_msg_debug (this->name, 0, @@ -5243,8 +5293,8 @@ glusterd_op_modify_op_ctx (glusterd_op_t op, void *ctx) " uuid_str"); continue; } - ret = dict_set_dynstr (op_ctx, key, - uuid); + ret = dict_set_dynstrn (op_ctx, key, + keylen, uuid); if (ret != 0) { GF_FREE (uuid); } @@ -5788,7 +5838,8 @@ glusterd_op_txn_complete (uuid_t *txn_id) else gf_msg_debug (this->name, 0, "Cleared local lock"); } else { - ret = dict_get_str (ctx, "volname", &volname); + ret = dict_get_strn (ctx, "volname", SLEN ("volname"), + &volname); if (ret) gf_msg (this->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -6442,12 +6493,13 @@ glusterd_bricks_select_remove_brick (dict_t *dict, char **op_errstr, char *brick = NULL; int32_t count = 0; int32_t i = 1; - char key[256] = {0,}; + char key[64] = {0,}; + int keylen; glusterd_pending_node_t *pending_node = NULL; int32_t command = 0; int32_t force = 0; - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, @@ -6463,14 +6515,15 @@ glusterd_bricks_select_remove_brick (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_int32 (dict, "count", &count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &count); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, -ret, GD_MSG_DICT_GET_FAILED, "Unable to get count"); goto out; } - ret = dict_get_int32 (dict, "command", &command); + ret = dict_get_int32n (dict, "command", SLEN ("command"), + &command); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, -ret, GD_MSG_DICT_GET_FAILED, "Unable to get command"); @@ -6481,7 +6534,7 @@ glusterd_bricks_select_remove_brick (dict_t *dict, char **op_errstr, return glusterd_bricks_select_tier_volume(dict, op_errstr, selected); - ret = dict_get_int32 (dict, "force", &force); + ret = dict_get_int32n (dict, "force", SLEN ("force"), &force); if (ret) { gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, "force flag is not set"); @@ -6490,9 +6543,9 @@ glusterd_bricks_select_remove_brick (dict_t *dict, char **op_errstr, } while ( i <= count) { - snprintf (key, 256, "brick%d", i); + keylen = snprintf (key, sizeof (key), "brick%d", i); - ret = dict_get_str (dict, key, &brick); + ret = dict_get_strn (dict, key, keylen, &brick); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get brick"); @@ -6555,7 +6608,7 @@ glusterd_bricks_select_profile_volume (dict_t *dict, char **op_errstr, priv = this->private; GF_ASSERT (priv); - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "volume name get failed"); @@ -6573,7 +6626,7 @@ glusterd_bricks_select_profile_volume (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_int32 (dict, "op", &stats_op); + ret = dict_get_int32n (dict, "op", SLEN ("op"), &stats_op); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "volume profile op get failed"); @@ -6668,7 +6721,7 @@ glusterd_bricks_select_profile_volume (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_str (dict, "brick", &brick); + ret = dict_get_strn (dict, "brick", SLEN ("brick"), &brick); if (!ret) { ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo, &brickinfo, @@ -6745,7 +6798,8 @@ _add_hxlator_to_dict (dict_t *dict, glusterd_volinfo_t *volinfo, int index, int count) { int ret = -1; - char key[128] = {0,}; + char key[64] = {0,}; + int keylen; char *xname = NULL; char *xl_type = 0; @@ -6754,13 +6808,13 @@ _add_hxlator_to_dict (dict_t *dict, glusterd_volinfo_t *volinfo, int index, } else { xl_type = "replicate"; } - snprintf (key, sizeof (key), "xl-%d", count); + keylen = snprintf (key, sizeof (key), "xl-%d", count); ret = gf_asprintf (&xname, "%s-%s-%d", volinfo->volname, xl_type, index); if (ret == -1) goto out; - ret = dict_set_dynstr (dict, key, xname); + ret = dict_set_dynstrn (dict, key, keylen, xname); if (ret) goto out; @@ -6787,10 +6841,12 @@ get_replica_index_for_per_replica_cmd (glusterd_volinfo_t *volinfo, goto out; } - ret = dict_get_str (dict, "per-replica-cmd-hostname", &hostname); + ret = dict_get_strn (dict, "per-replica-cmd-hostname", + SLEN ("per-replica-cmd-hostname"), &hostname); if (ret) goto out; - ret = dict_get_str (dict, "per-replica-cmd-path", &path); + ret = dict_get_strn (dict, "per-replica-cmd-path", + SLEN ("per-replica-cmd-path"), &path); if (ret) goto out; @@ -6825,7 +6881,8 @@ _select_hxlator_with_matching_brick (xlator_t *this, int hxl_children = 0; if (!dict || - dict_get_str (dict, "per-replica-cmd-path", &path)) + dict_get_strn (dict, "per-replica-cmd-path", + SLEN ("per-replica-cmd-path"), &path)) return -1; hxl_children = _get_hxl_children_count (volinfo); @@ -6942,7 +6999,7 @@ glusterd_bricks_select_snap (dict_t *dict, char **op_errstr, priv = this->private; GF_ASSERT (priv); - 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, "Unable to get" @@ -6987,6 +7044,7 @@ fill_shd_status_for_local_bricks (dict_t *dict, glusterd_volinfo_t *volinfo, glusterd_brickinfo_t *brickinfo = NULL; char *msg = "self-heal-daemon is not running on"; char key[1024] = {0,}; + int keylen; char value[1024] = {0,}; int ret = 0; xlator_t *this = NULL; @@ -7023,18 +7081,19 @@ fill_shd_status_for_local_bricks (dict_t *dict, glusterd_volinfo_t *volinfo, } } - snprintf (key, sizeof (key), "%d-status", (*index)); + keylen = snprintf (key, sizeof (key), "%d-status", (*index)); snprintf (value, sizeof (value), "%s %s",msg, uuid_utoa(MY_UUID)); - ret = dict_set_dynstr (dict, key, gf_strdup(value)); + ret = dict_set_dynstrn (dict, key, keylen, gf_strdup(value)); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Unable to" "set the dictionary for shd status msg"); goto out; } - snprintf (key, sizeof (key), "%d-shd-status", (*index)); - ret = dict_set_str (dict, key, "off"); + keylen = snprintf (key, sizeof (key), "%d-shd-status", + (*index)); + ret = dict_set_nstrn (dict, key, keylen, "off", SLEN ("off")); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Unable to" @@ -7161,7 +7220,7 @@ glusterd_bricks_select_heal_volume (dict_t *dict, char **op_errstr, priv = this->private; GF_ASSERT (priv); - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "volume name get failed"); @@ -7179,7 +7238,8 @@ glusterd_bricks_select_heal_volume (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_int32 (dict, "heal-op", (int32_t *)&heal_op); + ret = dict_get_int32n (dict, "heal-op", SLEN ("heal-op"), + (int32_t *)&heal_op); if (ret || (heal_op == GF_SHD_OP_INVALID)) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "heal op invalid"); @@ -7228,7 +7288,8 @@ glusterd_bricks_select_heal_volume (dict_t *dict, char **op_errstr, goto out; } - ret = dict_set_int32 (dict, "count", hxlator_count); + ret = dict_set_int32n (dict, "count", SLEN ("count"), + hxlator_count); if (ret) goto out; pending_node = GF_CALLOC (1, sizeof (*pending_node), @@ -7265,7 +7326,7 @@ glusterd_bricks_select_tier_volume (dict_t *dict, char **op_errstr, this = THIS; GF_VALIDATE_OR_GOTO (THIS->name, this, out); - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "volume name get failed"); @@ -7324,7 +7385,7 @@ glusterd_bricks_select_rebalance_volume (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 ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "volume name get failed"); @@ -7379,7 +7440,7 @@ glusterd_bricks_select_status_volume (dict_t *dict, char **op_errstr, priv = this->private; GF_ASSERT (priv); - ret = dict_get_int32 (dict, "cmd", &cmd); + ret = dict_get_int32n (dict, "cmd", SLEN ("cmd"), &cmd); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get status type"); @@ -7407,7 +7468,7 @@ glusterd_bricks_select_status_volume (dict_t *dict, char **op_errstr, default: goto out; } - 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, "Unable to get volname"); @@ -7419,7 +7480,8 @@ glusterd_bricks_select_status_volume (dict_t *dict, char **op_errstr, } if ( (cmd & GF_CLI_STATUS_BRICK) != 0) { - ret = dict_get_str (dict, "brick", &brickname); + ret = dict_get_strn (dict, "brick", SLEN ("brick"), + &brickname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -7644,7 +7706,7 @@ glusterd_bricks_select_scrub (dict_t *dict, char **op_errstr, 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, "Unable to get" @@ -7701,7 +7763,7 @@ glusterd_bricks_select_barrier (dict_t *dict, struct cds_list_head *selected) 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"); diff --git a/xlators/mgmt/glusterd/src/glusterd-peer-utils.c b/xlators/mgmt/glusterd/src/glusterd-peer-utils.c index 6d0cb2131d6..bd15633cdc2 100644 --- a/xlators/mgmt/glusterd/src/glusterd-peer-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-peer-utils.c @@ -621,8 +621,8 @@ gd_add_friend_to_dict (glusterd_peerinfo_t *friend, dict_t *dict, } count++; } - snprintf (key, sizeof (key), "%s.address-count", prefix); - ret = dict_set_int32 (dict, key, count); + ret = snprintf (key, sizeof (key), "%s.address-count", prefix); + ret = dict_set_int32n (dict, key, ret, count); if (ret) gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -768,8 +768,8 @@ gd_update_peerinfo_from_dict (glusterd_peerinfo_t *peerinfo, dict_t *dict, GF_VALIDATE_OR_GOTO (this->name, (dict != NULL), out); GF_VALIDATE_OR_GOTO (this->name, (prefix != NULL), out); - snprintf (key, sizeof (key), "%s.hostname", prefix); - ret = dict_get_str (dict, key, &hostname); + ret = snprintf (key, sizeof (key), "%s.hostname", prefix); + ret = dict_get_strn (dict, key, ret, &hostname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Key %s not present in " @@ -793,8 +793,8 @@ gd_update_peerinfo_from_dict (glusterd_peerinfo_t *peerinfo, dict_t *dict, goto out; } - snprintf (key, sizeof (key), "%s.address-count", prefix); - ret = dict_get_int32 (dict, key, &count); + ret = snprintf (key, sizeof (key), "%s.address-count", prefix); + ret = dict_get_int32n (dict, key, ret, &count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Key %s not present in " @@ -803,8 +803,8 @@ gd_update_peerinfo_from_dict (glusterd_peerinfo_t *peerinfo, dict_t *dict, } hostname = NULL; for (i = 0; i < count; i++) { - snprintf (key, sizeof (key), "%s.hostname%d",prefix, i); - ret = dict_get_str (dict, key, &hostname); + ret = snprintf (key, sizeof (key), "%s.hostname%d", prefix, i); + ret = dict_get_strn (dict, key, ret, &hostname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Key %s not present " @@ -862,8 +862,8 @@ gd_peerinfo_from_dict (dict_t *dict, const char *prefix) goto out; } - snprintf (key, sizeof (key), "%s.uuid", prefix); - ret = dict_get_str (dict, key, &uuid_str); + ret = snprintf (key, sizeof (key), "%s.uuid", prefix); + ret = dict_get_strn (dict, key, ret, &uuid_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Key %s not present in " @@ -917,8 +917,8 @@ gd_add_peer_hostnames_to_dict (glusterd_peerinfo_t *peerinfo, dict_t *dict, count++; } - snprintf (key, sizeof (key), "%s.hostname_count", prefix); - ret = dict_set_int32 (dict, key, count); + ret = snprintf (key, sizeof (key), "%s.hostname_count", prefix); + ret = dict_set_int32n (dict, key, ret, count); out: return ret; @@ -930,41 +930,43 @@ gd_add_peer_detail_to_dict (glusterd_peerinfo_t *peerinfo, dict_t *friends, { int ret = -1; - char key[256] = {0, }; + char key[64] = {0, }; + int keylen; char *peer_uuid_str = NULL; GF_ASSERT (peerinfo); GF_ASSERT (friends); - snprintf (key, sizeof (key), "friend%d.uuid", count); peer_uuid_str = gd_peer_uuid_str (peerinfo); - ret = dict_set_str (friends, key, peer_uuid_str); + keylen = snprintf (key, sizeof (key), "friend%d.uuid", count); + ret = dict_set_strn (friends, key, keylen, peer_uuid_str); if (ret) goto out; - snprintf (key, sizeof (key), "friend%d.hostname", count); - ret = dict_set_str (friends, key, peerinfo->hostname); + keylen = snprintf (key, sizeof (key), "friend%d.hostname", count); + ret = dict_set_strn (friends, key, keylen, peerinfo->hostname); if (ret) goto out; - snprintf (key, sizeof (key), "friend%d.port", count); - ret = dict_set_int32 (friends, key, peerinfo->port); + keylen = snprintf (key, sizeof (key), "friend%d.port", count); + ret = dict_set_int32n (friends, key, keylen, peerinfo->port); if (ret) goto out; - snprintf (key, sizeof (key), "friend%d.stateId", count); - ret = dict_set_int32 (friends, key, peerinfo->state.state); + keylen = snprintf (key, sizeof (key), "friend%d.stateId", count); + ret = dict_set_int32n (friends, key, keylen, peerinfo->state.state); if (ret) goto out; - snprintf (key, sizeof (key), "friend%d.state", count); - ret = dict_set_str (friends, key, - glusterd_friend_sm_state_name_get(peerinfo->state.state)); + keylen = snprintf (key, sizeof (key), "friend%d.state", count); + ret = dict_set_strn (friends, key, keylen, + glusterd_friend_sm_state_name_get(peerinfo->state.state)); if (ret) goto out; - snprintf (key, sizeof (key), "friend%d.connected", count); - ret = dict_set_int32 (friends, key, (int32_t)peerinfo->connected); + keylen = snprintf (key, sizeof (key), "friend%d.connected", count); + ret = dict_set_int32n (friends, key, keylen, + (int32_t)peerinfo->connected); if (ret) goto out; diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c index e1385e6cd9d..e79d5037962 100644 --- a/xlators/mgmt/glusterd/src/glusterd-quota.c +++ b/xlators/mgmt/glusterd/src/glusterd-quota.c @@ -162,7 +162,7 @@ __glusterd_handle_quota (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), "Unable to get volume name"); gf_msg (this->name, GF_LOG_ERROR, 0, @@ -171,7 +171,7 @@ __glusterd_handle_quota (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "type", &type); + ret = dict_get_int32n (dict, "type", SLEN ("type"), &type); if (ret) { snprintf (msg, sizeof (msg), "Unable to get type of command"); gf_msg (this->name, GF_LOG_ERROR, 0, @@ -281,8 +281,9 @@ _glusterd_quota_initiate_fs_crawl (glusterd_conf_t *priv, goto out; } - 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) volfileserver = "localhost"; len = snprintf (vol_id, sizeof (vol_id), @@ -529,7 +530,8 @@ glusterd_quota_get_default_soft_limit (glusterd_volinfo_t *volinfo, else val = gf_strdup ("80%"); - ret = dict_set_dynstr (rsp_dict, "default-soft-limit", val); + ret = dict_set_dynstrn (rsp_dict, "default-soft-limit", + SLEN ("default-soft-limit"), val); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set default " @@ -1326,7 +1328,7 @@ glusterd_quota_limit_usage (glusterd_volinfo_t *volinfo, dict_t *dict, goto out; } - ret = dict_get_str (dict, "path", &path); + ret = dict_get_strn (dict, "path", SLEN ("path"), &path); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to fetch path"); @@ -1336,15 +1338,17 @@ glusterd_quota_limit_usage (glusterd_volinfo_t *volinfo, dict_t *dict, if (ret) goto out; - ret = dict_get_str (dict, "hard-limit", &hard_limit); + ret = dict_get_strn (dict, "hard-limit", SLEN ("hard-limit"), + &hard_limit); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to fetch hard limit"); goto out; } - if (dict_get (dict, "soft-limit")) { - ret = dict_get_str (dict, "soft-limit", &soft_limit); + if (dict_getn (dict, "soft-limit", SLEN ("soft-limit"))) { + ret = dict_get_strn (dict, "soft-limit", SLEN ("soft-limit"), + &soft_limit); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to fetch " @@ -1369,7 +1373,7 @@ glusterd_quota_limit_usage (glusterd_volinfo_t *volinfo, dict_t *dict, goto out; } - ret = dict_get_str (dict, "gfid", &gfid_str); + ret = dict_get_strn (dict, "gfid", SLEN ("gfid"), &gfid_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get gfid of path " @@ -1459,7 +1463,7 @@ glusterd_quota_remove_limits (glusterd_volinfo_t *volinfo, dict_t *dict, goto out; } - ret = dict_get_str (dict, "path", &path); + ret = dict_get_strn (dict, "path", SLEN ("path"), &path); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to fetch path"); @@ -1477,7 +1481,7 @@ glusterd_quota_remove_limits (glusterd_volinfo_t *volinfo, dict_t *dict, goto out; } - ret = dict_get_str (dict, "gfid", &gfid_str); + ret = dict_get_strn (dict, "gfid", SLEN ("gfid"), &gfid_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get gfid of path " @@ -1516,7 +1520,7 @@ glusterd_set_quota_option (glusterd_volinfo_t *volinfo, dict_t *dict, return -1; } - ret = dict_get_str (dict, "value", &value); + ret = dict_get_strn (dict, "value", SLEN ("value"), &value); if(ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Option value absent."); @@ -1587,7 +1591,7 @@ glusterd_op_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) priv = this->private; GF_ASSERT (priv); - 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, "Unable to get volume name"); @@ -1600,7 +1604,7 @@ glusterd_op_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) goto out; } - ret = dict_get_int32 (dict, "type", &type); + ret = dict_get_int32n (dict, "type", SLEN ("type"), &type); if (!glusterd_is_quota_supported (type, op_errstr)) { ret = -1; @@ -1767,7 +1771,8 @@ glusterd_get_gfid_from_brick (dict_t *dict, glusterd_volinfo_t *volinfo, xlator_t *this = NULL; glusterd_conf_t *priv = NULL; glusterd_brickinfo_t *brickinfo = NULL; - char key[256] = {0,}; + char key[64] = {0,}; + int keylen; char *gfid_str = NULL; uuid_t gfid; @@ -1776,7 +1781,7 @@ glusterd_get_gfid_from_brick (dict_t *dict, glusterd_volinfo_t *volinfo, priv = this->private; GF_ASSERT (priv); - ret = dict_get_str (dict, "path", &path); + ret = dict_get_strn (dict, "path", SLEN ("path"), &path); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get path"); @@ -1818,7 +1823,7 @@ glusterd_get_gfid_from_brick (dict_t *dict, glusterd_volinfo_t *volinfo, ret = 0; continue; } - snprintf (key, sizeof (key), "gfid%d", count); + keylen = snprintf (key, sizeof (key), "gfid%d", count); gfid_str = gf_strdup (uuid_utoa (gfid)); if (!gfid_str) { @@ -1826,7 +1831,7 @@ glusterd_get_gfid_from_brick (dict_t *dict, glusterd_volinfo_t *volinfo, goto out; } - ret = dict_set_dynstr (rsp_dict, key, gfid_str); + ret = dict_set_dynstrn (rsp_dict, key, keylen, gfid_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to place " @@ -1837,7 +1842,7 @@ glusterd_get_gfid_from_brick (dict_t *dict, glusterd_volinfo_t *volinfo, count++; } - ret = dict_set_int32 (rsp_dict, "count", count); + ret = dict_set_int32n (rsp_dict, "count", SLEN ("count"), count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set count"); @@ -1886,7 +1891,7 @@ _glusterd_validate_quota_opts (dict_t *dict, int type, char **errstr) GD_MSG_UNKNOWN_KEY, "Unknown option: %s", key); goto out; } - ret = dict_get_str (dict, "value", &value); + ret = dict_get_strn (dict, "value", SLEN ("value"), &value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Value not found for key %s", @@ -1950,8 +1955,9 @@ glusterd_create_quota_auxiliary_mount (xlator_t *this, char *volname, int type) DEFAULT_LOG_FILE_DIRECTORY, volname); snprintf(qpid, 15, "%d", GF_CLIENT_PID_QUOTA_MOUNT); - 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) volfileserver = "localhost"; synclock_unlock (&priv->big_lock); @@ -2015,7 +2021,7 @@ glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) GF_ASSERT (dict); GF_ASSERT (op_errstr); - 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, "Unable to get volume name"); @@ -2041,7 +2047,7 @@ glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) goto out; } - ret = dict_get_int32 (dict, "type", &type); + ret = dict_get_int32n (dict, "type", SLEN ("type"), &type); if (ret) { *op_errstr = gf_strdup ("Volume quota failed, internal error, " "unable to get type of operation"); @@ -2104,7 +2110,8 @@ glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) switch (type) { case GF_QUOTA_OPTION_TYPE_LIMIT_USAGE: - ret = dict_get_str (dict, "hard-limit", &hard_limit_str); + ret = dict_get_strn (dict, "hard-limit", SLEN ("hard-limit"), + &hard_limit_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, diff --git a/xlators/mgmt/glusterd/src/glusterd-quotad-svc.c b/xlators/mgmt/glusterd/src/glusterd-quotad-svc.c index 827b2c62ccb..b05516c60ba 100644 --- a/xlators/mgmt/glusterd/src/glusterd-quotad-svc.c +++ b/xlators/mgmt/glusterd/src/glusterd-quotad-svc.c @@ -132,8 +132,8 @@ glusterd_quotadsvc_start (glusterd_svc_t *svc, int flags) goto out; for (i = 0; options[i]; i++) { - snprintf (key, sizeof (key), "arg%d", i); - ret = dict_set_str (cmdline, key, options[i]); + ret = snprintf (key, sizeof (key), "arg%d", i); + ret = dict_set_strn (cmdline, key, ret, options[i]); if (ret) goto out; } 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"); diff --git a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c index c3c7d7230d7..f2d59b593f1 100644 --- a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c +++ b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c @@ -84,7 +84,7 @@ __glusterd_handle_replace_brick (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), "Could not get volume name"); gf_msg (this->name, GF_LOG_ERROR, 0, @@ -92,7 +92,8 @@ __glusterd_handle_replace_brick (rpcsvc_request_t *req) goto out; } - ret = dict_get_str (dict, "operation", &cli_op); + ret = dict_get_strn (dict, "operation", SLEN ("operation"), + &cli_op); if (ret) { gf_msg_debug (this->name, 0, "dict_get on operation failed"); @@ -113,7 +114,8 @@ __glusterd_handle_replace_brick (rpcsvc_request_t *req) goto out; } - ret = dict_get_str (dict, "src-brick", &src_brick); + ret = dict_get_strn (dict, "src-brick", SLEN ("src-brick"), + &src_brick); if (ret) { snprintf (msg, sizeof (msg), "Failed to get src brick"); @@ -127,7 +129,8 @@ __glusterd_handle_replace_brick (rpcsvc_request_t *req) if (!strcmp (cli_op, "GF_RESET_OP_COMMIT") || !strcmp (cli_op, "GF_RESET_OP_COMMIT_FORCE") || !strcmp (cli_op, "GF_REPLACE_OP_COMMIT_FORCE")) { - ret = dict_get_str (dict, "dst-brick", &dst_brick); + ret = dict_get_strn (dict, "dst-brick", SLEN ("dst-brick"), + &dst_brick); if (ret) { snprintf (msg, sizeof (msg), "Failed to get" @@ -332,7 +335,8 @@ glusterd_op_stage_replace_brick (dict_t *dict, char **op_errstr, } } - ret = dict_set_int32 (rsp_dict, "brick_count", 1); + ret = dict_set_int32n (rsp_dict, "brick_count", + SLEN ("brick_count"), 1); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -394,7 +398,9 @@ glusterd_op_perform_replace_brick (glusterd_volinfo_t *volinfo, * introduced in gluster-3.6.0 */ if (conf->op_version >= GD_OP_VERSION_3_6_0) { - ret = dict_get_str (dict, "brick1.mount_dir", &brick_mount_dir); + ret = dict_get_strn (dict, "brick1.mount_dir", + SLEN ("brick1.mount_dir"), + &brick_mount_dir); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_BRICK_MOUNTDIR_GET_FAIL, @@ -461,7 +467,8 @@ glusterd_op_replace_brick (dict_t *dict, dict_t *rsp_dict) priv = this->private; GF_ASSERT (priv); - ret = dict_get_str (dict, "src-brick", &src_brick); + ret = dict_get_strn (dict, "src-brick", SLEN ("src-brick"), + &src_brick); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get src brick"); @@ -470,7 +477,8 @@ glusterd_op_replace_brick (dict_t *dict, dict_t *rsp_dict) gf_msg_debug (this->name, 0, "src brick=%s", src_brick); - ret = dict_get_str (dict, "dst-brick", &dst_brick); + ret = dict_get_strn (dict, "dst-brick", SLEN ("dst-brick"), + &dst_brick); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get dst brick"); @@ -479,14 +487,15 @@ glusterd_op_replace_brick (dict_t *dict, dict_t *rsp_dict) gf_msg_debug (this->name, 0, "dst brick=%s", dst_brick); - 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, "Unable to get volume name"); goto out; } - ret = dict_get_str (dict, "operation", &replace_op); + ret = dict_get_strn (dict, "operation", SLEN ("operation"), + &replace_op); if (ret) { gf_msg_debug (this->name, 0, "dict_get on operation failed"); @@ -622,7 +631,8 @@ glusterd_mgmt_v3_initiate_replace_brick_cmd_phases (rpcsvc_request_t *req, goto out; } - ret = dict_set_int32 (dict, "is_synctasked", _gf_true); + ret = dict_set_int32n (dict, "is_synctasked", + SLEN ("is_synctasked"), _gf_true); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, diff --git a/xlators/mgmt/glusterd/src/glusterd-reset-brick.c b/xlators/mgmt/glusterd/src/glusterd-reset-brick.c index c1de0432a73..52ddf1ba791 100644 --- a/xlators/mgmt/glusterd/src/glusterd-reset-brick.c +++ b/xlators/mgmt/glusterd/src/glusterd-reset-brick.c @@ -154,7 +154,8 @@ glusterd_reset_brick_prevalidate (dict_t *dict, char **op_errstr, volinfo->rep_brick.src_brick = src_brickinfo; volinfo->rep_brick.dst_brick = dst_brickinfo; - ret = dict_get_int32 (dict, "ignore-partition", &ignore_partition); + ret = dict_get_int32n (dict, "ignore-partition", + SLEN ("ignore-partition"), &ignore_partition); ret = 0; if (gf_is_local_addr (host)) { ret = glusterd_validate_and_create_brickpath @@ -217,7 +218,8 @@ glusterd_reset_brick_prevalidate (dict_t *dict, char **op_errstr, } } - ret = dict_set_int32 (rsp_dict, "brick_count", 1); + ret = dict_set_int32n (rsp_dict, "brick_count", + SLEN ( "brick_count"), 1); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -254,14 +256,14 @@ glusterd_op_reset_brick (dict_t *dict, dict_t *rsp_dict) priv = this->private; GF_ASSERT (priv); - ret = dict_get_str (dict, "operation", &op); + ret = dict_get_strn (dict, "operation", SLEN ("operation"), &op); if (ret) { gf_msg_debug (this->name, 0, "dict_get on operation failed"); goto out; } - 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, "Unable to get volume name"); @@ -272,7 +274,8 @@ glusterd_op_reset_brick (dict_t *dict, dict_t *rsp_dict) if (ret) goto out; - ret = dict_get_str (dict, "src-brick", &src_brick); + ret = dict_get_strn (dict, "src-brick", SLEN ("src-brick"), + &src_brick); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get src brick"); @@ -305,7 +308,8 @@ glusterd_op_reset_brick (dict_t *dict, dict_t *rsp_dict) } else if (!strcmp (op, "GF_RESET_OP_COMMIT") || !strcmp (op, "GF_RESET_OP_COMMIT_FORCE")) { - ret = dict_get_str (dict, "dst-brick", &dst_brick); + ret = dict_get_strn (dict, "dst-brick", SLEN ("dst-brick"), + &dst_brick); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, diff --git a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c index be5979cf858..f3bb402471e 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c @@ -63,7 +63,8 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret, case GD_OP_REMOVE_BRICK: { if (ctx) - ret = dict_get_str (ctx, "errstr", &errstr); + ret = dict_get_strn (ctx, "errstr", SLEN ("errstr"), + &errstr); break; } case GD_OP_RESET_VOLUME: @@ -79,7 +80,8 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret, case GD_OP_DEFRAG_BRICK_VOLUME: { if (ctx) { - ret = dict_get_int32 (ctx, "status", &status); + ret = dict_get_int32n (ctx, "status", + SLEN ("status"), &status); if (ret) { gf_msg_trace (this->name, 0, "failed to get status"); @@ -91,8 +93,11 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret, case GD_OP_GSYNC_SET: { if (ctx) { - ret = dict_get_str (ctx, "errstr", &errstr); - ret = dict_set_str (ctx, "glusterd_workdir", conf->workdir); + ret = dict_get_strn (ctx, "errstr", SLEN ("errstr"), + &errstr); + ret = dict_set_strn (ctx, "glusterd_workdir", + SLEN ("glusterd_workdir"), + conf->workdir); /* swallow error here, that will be re-triggered in cli */ } @@ -101,8 +106,10 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret, } case GD_OP_PROFILE_VOLUME: { - if (ctx && dict_get_int32 (ctx, "count", &count)) { - ret = dict_set_int32 (ctx, "count", 0); + if (ctx && dict_get_int32n (ctx, "count", SLEN ("count"), + &count)) { + ret = dict_set_int32n (ctx, "count", SLEN ("count"), + 0); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -160,15 +167,18 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret, case GD_OP_COPY_FILE: { if (ctx) - ret = dict_get_str (ctx, "errstr", &errstr); + ret = dict_get_strn (ctx, "errstr", SLEN ("errstr"), + &errstr); break; } case GD_OP_SYS_EXEC: { if (ctx) { - ret = dict_get_str (ctx, "errstr", &errstr); - ret = dict_set_str (ctx, "glusterd_workdir", - conf->workdir); + ret = dict_get_strn (ctx, "errstr", SLEN ("errstr"), + &errstr); + ret = dict_set_strn (ctx, "glusterd_workdir", + SLEN ("glusterd_workdir"), + conf->workdir); } break; } @@ -1503,10 +1513,11 @@ glusterd_rpc_probe (call_frame_t *frame, xlator_t *this, priv = this->private; GF_ASSERT (priv); - ret = dict_get_str (dict, "hostname", &hostname); + ret = dict_get_strn (dict, "hostname", SLEN ("hostname"), + &hostname); if (ret) goto out; - ret = dict_get_int32 (dict, "port", &port); + ret = dict_get_int32n (dict, "port", SLEN ("port"), &port); if (ret) port = GF_DEFAULT_BASE_PORT; @@ -1706,7 +1717,7 @@ glusterd_rpc_friend_update (call_frame_t *frame, xlator_t *this, if (ret) goto out; /* Don't want to send the pointer over */ - dict_del (friends, "peerinfo"); + dict_deln (friends, "peerinfo", SLEN ("peerinfo")); ret = dict_allocate_and_serialize (friends, &req.friends.friends_val, &req.friends.friends_len); @@ -1795,7 +1806,7 @@ glusterd_mgmt_v3_lock_peers (call_frame_t *frame, xlator_t *this, goto out; //peerinfo should not be in payload - dict_del (dict, "peerinfo"); + dict_deln (dict, "peerinfo", SLEN ("peerinfo")); glusterd_get_uuid (&req.uuid); @@ -1875,7 +1886,7 @@ glusterd_mgmt_v3_unlock_peers (call_frame_t *frame, xlator_t *this, goto out; //peerinfo should not be in payload - dict_del (dict, "peerinfo"); + dict_deln (dict, "peerinfo", SLEN ("peerinfo")); glusterd_get_uuid (&req.uuid); @@ -1999,7 +2010,7 @@ glusterd_stage_op (call_frame_t *frame, xlator_t *this, goto out; //peerinfo should not be in payload - dict_del (dict, "peerinfo"); + dict_deln (dict, "peerinfo", SLEN ("peerinfo")); glusterd_get_uuid (&req.uuid); req.op = glusterd_op_get_op (); @@ -2080,7 +2091,7 @@ glusterd_commit_op (call_frame_t *frame, xlator_t *this, goto out; //peerinfo should not be in payload - dict_del (dict, "peerinfo"); + dict_deln (dict, "peerinfo", SLEN ("peerinfo")); glusterd_get_uuid (&req.uuid); req.op = glusterd_op_get_op (); @@ -2212,7 +2223,7 @@ __glusterd_brick_op_cbk (struct rpc_req *req, struct iovec *iov, if (GD_OP_STATUS_VOLUME == req_ctx->op) { node = frame->cookie; index = node->index; - ret = dict_set_int32 (dict, "index", index); + ret = dict_set_int32n (dict, "index", SLEN ("index"), index); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c index 59a2f635106..ac02edd345d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-sm.c @@ -129,7 +129,8 @@ glusterd_broadcast_friend_delete (char *hostname, uuid_t uuid) glusterd_peerinfo_t *peerinfo = NULL; glusterd_conf_t *priv = NULL; dict_t *friends = NULL; - char key[100] = {0,}; + char key[64] = {0,}; + int keylen; int32_t count = 0; this = THIS; @@ -144,17 +145,17 @@ glusterd_broadcast_friend_delete (char *hostname, uuid_t uuid) if (!friends) goto out; - snprintf (key, sizeof (key), "op"); - ret = dict_set_int32 (friends, key, ctx.op); + keylen = snprintf (key, sizeof (key), "op"); + ret = dict_set_int32n (friends, key, keylen, ctx.op); if (ret) goto out; - snprintf (key, sizeof (key), "hostname"); - ret = dict_set_str (friends, key, hostname); + keylen = snprintf (key, sizeof (key), "hostname"); + ret = dict_set_strn (friends, key, keylen, hostname); if (ret) goto out; - ret = dict_set_int32 (friends, "count", count); + ret = dict_set_int32n (friends, "count", SLEN ("count"), count); if (ret) goto out; @@ -380,11 +381,13 @@ glusterd_ac_friend_probe (glusterd_friend_sm_event_t *event, void *ctx) dict = dict_new (); if (!dict) goto out; - ret = dict_set_str (dict, "hostname", probe_ctx->hostname); + ret = dict_set_strn (dict, "hostname", SLEN ("hostname"), + probe_ctx->hostname); if (ret) goto out; - ret = dict_set_int32 (dict, "port", probe_ctx->port); + ret = dict_set_int32n (dict, "port", SLEN ("port"), + probe_ctx->port); if (ret) goto out; @@ -524,7 +527,8 @@ glusterd_ac_send_friend_update (glusterd_friend_sm_event_t *event, void *ctx) glusterd_friend_update_ctx_t ev_ctx = {{0}}; glusterd_conf_t *priv = NULL; dict_t *friends = NULL; - char key[100] = {0,}; + char key[64] = {0,}; + int keylen; int32_t count = 0; GF_ASSERT (event); @@ -551,8 +555,8 @@ glusterd_ac_send_friend_update (glusterd_friend_sm_event_t *event, void *ctx) if (!friends) goto out; - snprintf (key, sizeof (key), "op"); - ret = dict_set_int32 (friends, key, ev_ctx.op); + keylen = snprintf (key, sizeof (key), "op"); + ret = dict_set_int32n (friends, key, keylen, ev_ctx.op); if (ret) goto out; @@ -568,7 +572,7 @@ glusterd_ac_send_friend_update (glusterd_friend_sm_event_t *event, void *ctx) goto out; } - ret = dict_set_int32 (friends, "count", count); + ret = dict_set_int32n (friends, "count", SLEN ("count"), count); if (ret) goto out; @@ -618,7 +622,8 @@ glusterd_ac_update_friend (glusterd_friend_sm_event_t *event, void *ctx) glusterd_friend_update_ctx_t ev_ctx = {{0}}; glusterd_conf_t *priv = NULL; dict_t *friends = NULL; - char key[100] = {0,}; + char key[64] = {0,}; + int keylen; int32_t count = 0; GF_ASSERT (event); @@ -654,8 +659,8 @@ glusterd_ac_update_friend (glusterd_friend_sm_event_t *event, void *ctx) if (!friends) goto out; - snprintf (key, sizeof (key), "op"); - ret = dict_set_int32 (friends, key, ev_ctx.op); + keylen = snprintf (key, sizeof (key), "op"); + ret = dict_set_int32n (friends, key, keylen, ev_ctx.op); if (ret) goto out; @@ -671,7 +676,7 @@ glusterd_ac_update_friend (glusterd_friend_sm_event_t *event, void *ctx) goto out; } - ret = dict_set_int32 (friends, "count", count); + ret = dict_set_int32n (friends, "count", SLEN ("count"), count); if (ret) goto out; @@ -1012,8 +1017,8 @@ glusterd_ac_handle_friend_add_req (glusterd_friend_sm_event_t *event, void *ctx) new_event->ctx = new_ev_ctx; - ret = dict_get_str (ev_ctx->vols, "hostname_in_cluster", - &hostname); + ret = dict_get_strn (ev_ctx->vols, "hostname_in_cluster", + SLEN ("hostname_in_cluster"), &hostname); if (ret || !hostname) { gf_msg_debug (this->name, 0, "Unable to fetch local hostname from peer"); diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index 5d0e15ade02..51d0d288a16 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -229,7 +229,8 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname, char *op_errstr, int len) { char err_str[PATH_MAX] = ""; - char buf[PATH_MAX] = ""; + char key[64] = ""; + int keylen; glusterd_conf_t *conf = NULL; glusterd_volinfo_t *volinfo = NULL; int ret = -1; @@ -276,49 +277,51 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname, soft_limit_value = (opt_soft_max * active_hard_limit) / 100; - snprintf (buf, sizeof(buf), "volume%"PRId64"-volname", - count); - ret = dict_set_str (rsp_dict, buf, volinfo->volname); + keylen = snprintf (key, sizeof (key), + "volume%"PRId64"-volname", count); + ret = dict_set_strn (rsp_dict, key, keylen, + volinfo->volname); if (ret) { len = snprintf (err_str, PATH_MAX, - "Failed to set %s", buf); + "Failed to set %s", key); if (len < 0) { strcpy(err_str, ""); } goto out; } - snprintf (buf, sizeof(buf), - "volume%"PRId64"-snap-max-hard-limit", count); - ret = dict_set_uint64 (rsp_dict, buf, snap_max_limit); + snprintf (key, sizeof (key), + "volume%"PRId64"-snap-max-hard-limit", + count); + ret = dict_set_uint64 (rsp_dict, key, snap_max_limit); if (ret) { len = snprintf (err_str, PATH_MAX, - "Failed to set %s", buf); + "Failed to set %s", key); if (len < 0) { strcpy(err_str, ""); } goto out; } - snprintf (buf, sizeof(buf), + snprintf (key, sizeof (key), "volume%"PRId64"-active-hard-limit", count); - ret = dict_set_uint64 (rsp_dict, buf, + ret = dict_set_uint64 (rsp_dict, key, active_hard_limit); if (ret) { len = snprintf (err_str, PATH_MAX, - "Failed to set %s", buf); + "Failed to set %s", key); if (len < 0) { strcpy(err_str, ""); } goto out; } - snprintf (buf, sizeof(buf), + snprintf (key, sizeof (key), "volume%"PRId64"-snap-max-soft-limit", count); - ret = dict_set_uint64 (rsp_dict, buf, soft_limit_value); + ret = dict_set_uint64 (rsp_dict, key, soft_limit_value); if (ret) { len = snprintf (err_str, PATH_MAX, - "Failed to set %s", buf); + "Failed to set %s", key); if (len < 0) { strcpy(err_str, ""); } @@ -351,47 +354,48 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname, soft_limit_value = (opt_soft_max * active_hard_limit) / 100; - snprintf (buf, sizeof(buf), "volume%"PRId64"-volname", count); - ret = dict_set_str (rsp_dict, buf, volinfo->volname); + keylen = snprintf (key, sizeof (key), + "volume%"PRId64"-volname", count); + ret = dict_set_strn (rsp_dict, key, keylen, volinfo->volname); if (ret) { len = snprintf (err_str, PATH_MAX, - "Failed to set %s", buf); + "Failed to set %s", key); if (len < 0) { strcpy(err_str, ""); } goto out; } - snprintf (buf, sizeof(buf), + snprintf (key, sizeof (key), "volume%"PRId64"-snap-max-hard-limit", count); - ret = dict_set_uint64 (rsp_dict, buf, snap_max_limit); + ret = dict_set_uint64 (rsp_dict, key, snap_max_limit); if (ret) { len = snprintf (err_str, PATH_MAX, - "Failed to set %s", buf); + "Failed to set %s", key); if (len < 0) { strcpy(err_str, ""); } goto out; } - snprintf (buf, sizeof(buf), + snprintf (key, sizeof (key), "volume%"PRId64"-active-hard-limit", count); - ret = dict_set_uint64 (rsp_dict, buf, active_hard_limit); + ret = dict_set_uint64 (rsp_dict, key, active_hard_limit); if (ret) { len = snprintf (err_str, PATH_MAX, - "Failed to set %s", buf); + "Failed to set %s", key); if (len < 0) { strcpy(err_str, ""); } goto out; } - snprintf (buf, sizeof(buf), + snprintf (key, sizeof (key), "volume%"PRId64"-snap-max-soft-limit", count); - ret = dict_set_uint64 (rsp_dict, buf, soft_limit_value); + ret = dict_set_uint64 (rsp_dict, key, soft_limit_value); if (ret) { len = snprintf (err_str, PATH_MAX, - "Failed to set %s", buf); + "Failed to set %s", key); if (len < 0) { strcpy(err_str, ""); } @@ -433,8 +437,9 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname, * in that case it's better to consider the default value. * Hence not erroring out if Key is not found. */ - ret = dict_get_str (conf->opts, GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE, - &auto_delete); + ret = dict_get_strn (conf->opts, GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE, + SLEN (GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE), + &auto_delete); ret = dict_set_dynstr_with_alloc (rsp_dict, GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE, @@ -450,8 +455,9 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname, * in that case it's better to consider the default value. * Hence not erroring out if Key is not found. */ - ret = dict_get_str (conf->opts, GLUSTERD_STORE_KEY_SNAP_ACTIVATE, - &snap_activate); + ret = dict_get_strn (conf->opts, GLUSTERD_STORE_KEY_SNAP_ACTIVATE, + SLEN (GLUSTERD_STORE_KEY_SNAP_ACTIVATE), + &snap_activate); ret = dict_set_dynstr_with_alloc (rsp_dict, GLUSTERD_STORE_KEY_SNAP_ACTIVATE, @@ -818,7 +824,7 @@ glusterd_snapshot_restore (dict_t *dict, char **op_errstr, dict_t *rsp_dict) priv = this->private; GF_ASSERT (priv); - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -963,7 +969,8 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr, int32_t volcount = 0; int32_t brick_count = 0; gf_boolean_t snap_restored = _gf_false; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; char *volname = NULL; char *snapname = NULL; glusterd_volinfo_t *volinfo = NULL; @@ -979,7 +986,7 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr, GF_VALIDATE_OR_GOTO (this->name, op_errno, out); GF_ASSERT (rsp_dict); - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get " @@ -1015,7 +1022,8 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr, goto out; } - ret = dict_set_str (rsp_dict, "snapname", snapname); + ret = dict_set_strn (rsp_dict, "snapname", SLEN ("snapname"), + snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set " @@ -1023,7 +1031,8 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_int32 (dict, "volcount", &volcount); + ret = dict_get_int32n (dict, "volcount", SLEN ("volcount"), + &volcount); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, @@ -1034,8 +1043,8 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr, /* Snapshot restore will only work if all the volumes, that are part of the snapshot, are stopped. */ for (i = 1; i <= volcount; ++i) { - snprintf (key, sizeof (key), "volname%d", i); - ret = dict_get_str (dict, key, &volname); + keylen = snprintf (key, sizeof (key), "volname%d", i); + ret = dict_get_strn (dict, key, keylen, &volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to " @@ -1095,9 +1104,11 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr, if (gf_uuid_compare (brickinfo->uuid, MY_UUID)) continue; - snprintf (key, sizeof (key), "snap%d.brick%d.path", + keylen = snprintf (key, sizeof (key), + "snap%d.brick%d.path", volcount, brick_count); - ret = dict_set_str (rsp_dict, key, brickinfo->path); + ret = dict_set_strn (rsp_dict, key, keylen, + brickinfo->path); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -1105,10 +1116,10 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr, goto out; } - snprintf (key, sizeof (key), - "snap%d.brick%d.snap_status", - volcount, brick_count); - ret = dict_set_int32 (rsp_dict, key, + keylen = snprintf (key, sizeof (key), + "snap%d.brick%d.snap_status", + volcount, brick_count); + ret = dict_set_int32n (rsp_dict, key, keylen, brickinfo->snap_status); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, @@ -1117,11 +1128,11 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr, goto out; } - snprintf (key, sizeof (key), - "snap%d.brick%d.device_path", - volcount, brick_count); - ret = dict_set_str (rsp_dict, key, - brickinfo->device_path); + keylen = snprintf (key, sizeof (key), + "snap%d.brick%d.device_path", + volcount, brick_count); + ret = dict_set_strn (rsp_dict, key, keylen, + brickinfo->device_path); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -1129,11 +1140,11 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr, goto out; } - snprintf (key, sizeof (key), - "snap%d.brick%d.fs_type", - volcount, brick_count); - ret = dict_set_str (rsp_dict, key, - brickinfo->fstype); + keylen = snprintf (key, sizeof (key), + "snap%d.brick%d.fs_type", + volcount, brick_count); + ret = dict_set_strn (rsp_dict, key, keylen, + brickinfo->fstype); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -1141,11 +1152,11 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr, goto out; } - snprintf (key, sizeof (key), - "snap%d.brick%d.mnt_opts", - volcount, brick_count); - ret = dict_set_str (rsp_dict, key, - brickinfo->mnt_opts); + keylen = snprintf (key, sizeof (key), + "snap%d.brick%d.mnt_opts", + volcount, brick_count); + ret = dict_set_strn (rsp_dict, key, keylen, + brickinfo->mnt_opts); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -1154,8 +1165,9 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr, } } - snprintf (key, sizeof (key), "snap%d.brick_count", volcount); - ret = dict_set_int32 (rsp_dict, key, brick_count); + keylen = snprintf (key, sizeof (key), "snap%d.brick_count", + volcount); + ret = dict_set_int32n (rsp_dict, key, keylen, brick_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -1164,7 +1176,8 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr, } } - ret = dict_set_int32 (rsp_dict, "volcount", volcount); + ret = dict_set_int32n (rsp_dict, "volcount", SLEN ("volcount"), + volcount); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -1284,7 +1297,8 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr, GF_ASSERT (conf); - ret = dict_get_int32 (dict, "config-command", &config_command); + ret = dict_get_int32n (dict, "config-command", + SLEN ("config-command"), &config_command); if (ret) { snprintf (err_str, sizeof (err_str), "failed to get config-command type"); @@ -1296,7 +1310,7 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (volname) { ret = glusterd_volinfo_find (volname, &volinfo); if (ret) { @@ -1344,7 +1358,8 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr, goto out; } - if (dict_get(dict, GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE)) { + if (dict_getn (dict, GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE, + SLEN (GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE))) { req_auto_delete = dict_get_str_boolean (dict, GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE, _gf_false); @@ -1373,7 +1388,8 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr, *op_errno = EINVAL; goto out; } - } else if (dict_get(dict, GLUSTERD_STORE_KEY_SNAP_ACTIVATE)) { + } else if (dict_getn (dict, GLUSTERD_STORE_KEY_SNAP_ACTIVATE, + SLEN (GLUSTERD_STORE_KEY_SNAP_ACTIVATE))) { req_snap_activate = dict_get_str_boolean (dict, GLUSTERD_STORE_KEY_SNAP_ACTIVATE, _gf_false); @@ -1449,20 +1465,22 @@ glusterd_handle_snapshot_config (rpcsvc_request_t *req, glusterd_op_t op, /* TODO : Type of lock to be taken when we are setting * limits system wide */ - ret = dict_get_int32 (dict, "config-command", &config_command); + ret = dict_get_int32n (dict, "config-command", + SLEN ("config-command"), &config_command); if (ret) { snprintf (err_str, len, "Failed to get config-command type"); goto out; } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); switch (config_command) { case GF_SNAP_CONFIG_TYPE_SET: if (!volname) { - ret = dict_set_int32 (dict, "hold_vol_locks", - _gf_false); + ret = dict_set_int32n (dict, "hold_vol_locks", + SLEN ("hold_vol_locks"), + _gf_false); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -1513,7 +1531,8 @@ glusterd_snap_create_clone_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) { char *snap_brick_dir = NULL; char *snap_device = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; char *value = ""; char snapbrckcnt[PATH_MAX] = ""; char snapbrckord[PATH_MAX] = ""; @@ -1551,7 +1570,7 @@ glusterd_snap_create_clone_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) for (j = 0; j < brick_count; j++) { /* Fetching data from source dict */ - snprintf (key, sizeof(key) - 1, + snprintf (key, sizeof (key), "vol%"PRId64".brickdir%"PRId64, i+1, j); ret = dict_get_ptr (src, key, (void **)&snap_brick_dir); @@ -1573,7 +1592,7 @@ glusterd_snap_create_clone_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) goto out; } - snprintf (key, sizeof(key) - 1, + snprintf (key, sizeof (key), "vol%"PRId64".brickdir%"PRId64, i+1, brick_order); ret = dict_set_dynstr_with_alloc (dst, key, @@ -1585,9 +1604,10 @@ glusterd_snap_create_clone_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) goto out; } - snprintf (key, sizeof(key) - 1, - "vol%"PRId64".fstype%"PRId64, i+1, j); - ret = dict_get_str (src, key, &value); + keylen = snprintf (key, sizeof (key), + "vol%"PRId64".fstype%"PRId64, + i+1, j); + ret = dict_get_strn (src, key, keylen, &value); if (ret) { gf_msg (this->name, GF_LOG_WARNING, 0, GD_MSG_DICT_GET_FAILED, @@ -1595,7 +1615,7 @@ glusterd_snap_create_clone_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) continue; } - snprintf (key, sizeof(key) - 1, + snprintf (key, sizeof (key), "vol%"PRId64".fstype%"PRId64, i+1, brick_order); ret = dict_set_dynstr_with_alloc (dst, key, value); @@ -1606,9 +1626,10 @@ glusterd_snap_create_clone_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) goto out; } - snprintf (key, sizeof(key) - 1, - "vol%"PRId64".mnt_opts%"PRId64, i+1, j); - ret = dict_get_str (src, key, &value); + keylen = snprintf (key, sizeof (key), + "vol%"PRId64".mnt_opts%"PRId64, + i+1, j); + ret = dict_get_strn (src, key, keylen, &value); if (ret) { gf_msg (this->name, GF_LOG_WARNING, 0, GD_MSG_DICT_GET_FAILED, @@ -1616,7 +1637,7 @@ glusterd_snap_create_clone_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) continue; } - snprintf (key, sizeof(key) - 1, + snprintf (key, sizeof (key), "vol%"PRId64".mnt_opts%"PRId64, i+1, brick_order); ret = dict_set_dynstr_with_alloc (dst, key, value); @@ -1627,7 +1648,7 @@ glusterd_snap_create_clone_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) goto out; } - snprintf (key, sizeof(key) - 1, + snprintf (key, sizeof(key), "vol%"PRId64".brick_snapdevice%"PRId64, i+1, j); ret = dict_get_ptr (src, key, @@ -1639,7 +1660,7 @@ glusterd_snap_create_clone_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) goto out; } - snprintf (key, sizeof(key) - 1, + snprintf (key, sizeof (key), "vol%"PRId64".brick_snapdevice%"PRId64, i+1, brick_order); ret = dict_set_dynstr_with_alloc (dst, key, @@ -1651,9 +1672,11 @@ glusterd_snap_create_clone_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) goto out; } - snprintf (key, sizeof (key), - "vol%"PRId64".brick%"PRId64".status", i+1, brick_order); - ret = dict_get_int32 (src, key, &brick_online); + keylen = snprintf (key, sizeof (key), + "vol%"PRId64".brick%"PRId64".status", + i+1, brick_order); + ret = dict_get_int32n (src, key, keylen, + &brick_online); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "failed to " @@ -1661,7 +1684,7 @@ glusterd_snap_create_clone_pre_val_use_rsp_dict (dict_t *dst, dict_t *src) goto out; } - ret = dict_set_int32 (dst, key, brick_online); + ret = dict_set_int32n (dst, key, keylen, brick_online); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "failed to " @@ -1682,7 +1705,8 @@ out: int32_t glusterd_snap_restore_use_rsp_dict (dict_t *dst, dict_t *src) { - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; char *strvalue = NULL; int32_t value = -1; int32_t i = -1; @@ -1710,8 +1734,9 @@ glusterd_snap_restore_use_rsp_dict (dict_t *dst, dict_t *src) } for (i = 1; i <= vol_count; i++) { - snprintf (key, sizeof (key), "snap%d.brick_count", i); - ret = dict_get_int32 (src, key, &brickcount); + keylen = snprintf (key, sizeof (key), + "snap%d.brick_count", i); + ret = dict_get_int32n (src, key, keylen, &brickcount); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -1720,9 +1745,9 @@ glusterd_snap_restore_use_rsp_dict (dict_t *dst, dict_t *src) } for (j = 1; j <= brickcount; j++) { - snprintf (key, sizeof (key), "snap%d.brick%d.path", - i, j); - ret = dict_get_str (src, key, &strvalue); + keylen = snprintf (key, sizeof (key), + "snap%d.brick%d.path", i, j); + ret = dict_get_strn (src, key, keylen, &strvalue); if (ret) { /* The brickinfo will be present in * another rsp_dict */ @@ -1738,16 +1763,17 @@ glusterd_snap_restore_use_rsp_dict (dict_t *dst, dict_t *src) goto out; } - snprintf (key, sizeof (key), - "snap%d.brick%d.snap_status", i, j); - ret = dict_get_int32 (src, key, &value); + keylen = snprintf (key, sizeof (key), + "snap%d.brick%d.snap_status", + i, j); + ret = dict_get_int32n (src, key, keylen, &value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get %s", key); goto out; } - ret = dict_set_int32 (dst, key, value); + ret = dict_set_int32n (dst, key, keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -1755,9 +1781,10 @@ glusterd_snap_restore_use_rsp_dict (dict_t *dst, dict_t *src) goto out; } - snprintf (key, sizeof (key), - "snap%d.brick%d.device_path", i, j); - ret = dict_get_str (src, key, &strvalue); + keylen = snprintf (key, sizeof (key), + "snap%d.brick%d.device_path", + i, j); + ret = dict_get_strn (src, key, keylen, &strvalue); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -1771,9 +1798,9 @@ glusterd_snap_restore_use_rsp_dict (dict_t *dst, dict_t *src) goto out; } - snprintf (key, sizeof (key), - "snap%d.brick%d.fs_type", i, j); - ret = dict_get_str (src, key, &strvalue); + keylen = snprintf (key, sizeof (key), + "snap%d.brick%d.fs_type", i, j); + ret = dict_get_strn (src, key, keylen, &strvalue); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -1787,9 +1814,9 @@ glusterd_snap_restore_use_rsp_dict (dict_t *dst, dict_t *src) goto out; } - snprintf (key, sizeof (key), - "snap%d.brick%d.mnt_opts", i, j); - ret = dict_get_str (src, key, &strvalue); + keylen = snprintf (key, sizeof (key), + "snap%d.brick%d.mnt_opts", i, j); + ret = dict_get_strn (src, key, keylen, &strvalue); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -1827,7 +1854,7 @@ glusterd_snap_pre_validate_use_rsp_dict (dict_t *dst, dict_t *src) goto out; } - ret = dict_get_int32 (dst, "type", &snap_command); + ret = dict_get_int32n (dst, "type", SLEN ("type"), &snap_command); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "unable to get the type of " @@ -2005,8 +2032,9 @@ glusterd_snapshot_pause_tier (xlator_t *this, glusterd_volinfo_t *volinfo) goto out; } - ret = dict_set_int32 (dict, "rebalance-command", - GF_DEFRAG_CMD_PAUSE_TIER); + ret = dict_set_int32n (dict, "rebalance-command", + SLEN ("rebalance-command"), + GF_DEFRAG_CMD_PAUSE_TIER); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -2014,7 +2042,8 @@ glusterd_snapshot_pause_tier (xlator_t *this, glusterd_volinfo_t *volinfo) goto out; } - ret = dict_set_str (dict, "volname", volinfo->volname); + ret = dict_set_strn (dict, "volname", SLEN ("volname"), + volinfo->volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -2046,7 +2075,8 @@ glusterd_snapshot_resume_tier (xlator_t *this, dict_t *snap_dict) int ret = -1; dict_t *dict = NULL; int64_t volcount = 0; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; char *volname = NULL; int i = 0; char *op_errstr = NULL; @@ -2069,8 +2099,8 @@ glusterd_snapshot_resume_tier (xlator_t *this, dict_t *snap_dict) goto out; for (i = 1; i <= volcount; i++) { - snprintf (key, sizeof (key), "volname%d", i); - ret = dict_get_str (snap_dict, key, &volname); + keylen = snprintf (key, sizeof (key), "volname%d", i); + ret = dict_get_strn (snap_dict, key, keylen, &volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -2085,8 +2115,9 @@ glusterd_snapshot_resume_tier (xlator_t *this, dict_t *snap_dict) if (volinfo->type != GF_CLUSTER_TYPE_TIER) continue; - ret = dict_set_int32 (dict, "rebalance-command", - GF_DEFRAG_CMD_RESUME_TIER); + ret = dict_set_int32n (dict, "rebalance-command", + SLEN ("rebalance-command"), + GF_DEFRAG_CMD_RESUME_TIER); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -2095,7 +2126,8 @@ glusterd_snapshot_resume_tier (xlator_t *this, dict_t *snap_dict) goto out; } - ret = dict_set_str (dict, "volname", volname); + ret = dict_set_strn (dict, "volname", SLEN ("volname"), + volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -2366,14 +2398,15 @@ glusterd_snapshot_clone_prevalidate (dict_t *dict, char **op_errstr, GF_ASSERT (dict); GF_VALIDATE_OR_GOTO (this->name, op_errno, out); - ret = dict_get_str (dict, "clonename", &clonename); + ret = dict_get_strn (dict, "clonename", SLEN ("clonename"), + &clonename); if (ret) { snprintf (err_str, sizeof (err_str), "Failed to " "get the clone name"); goto out; } - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { snprintf (err_str, sizeof (err_str), "Failed to get snapname"); goto out; @@ -2458,7 +2491,8 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, { char *volname = NULL; char *snapname = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; char snap_volname[64] = ""; char err_str[PATH_MAX] = ""; int ret = -1; @@ -2493,13 +2527,14 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { snprintf (err_str, sizeof (err_str), "Failed to get snapname"); goto out; } - ret = dict_get_str (dict, "description", &description); + ret = dict_get_strn (dict, "description", SLEN ("description"), + &description); if (description && !(*description)) { /* description should have a non-null value */ ret = -1; @@ -2508,7 +2543,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_int32 (dict, "flags", &flags); + ret = dict_get_int32n (dict, "flags", SLEN ("flags"), &flags); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get flags"); @@ -2524,8 +2559,8 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, } for (i = 1; i <= volcount; i++) { - snprintf (key, sizeof (key), "volname%"PRId64, i); - ret = dict_get_str (dict, key, &volname); + keylen = snprintf (key, sizeof (key), "volname%"PRId64, i); + ret = dict_get_strn (dict, key, keylen, &volname); if (ret) { snprintf (err_str, sizeof (err_str), "failed to get volume name"); @@ -2608,7 +2643,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr, goto out; } - snprintf (key, sizeof(key) - 1, "vol%"PRId64"_volid", i); + snprintf (key, sizeof (key), "vol%"PRId64"_volid", i); ret = dict_get_bin (dict, key, (void **)&snap_volid); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, @@ -3286,6 +3321,7 @@ glusterd_snapshot_get_snapvol_detail (dict_t *dict, int ret = -1; int snap_limit = 0; char key[PATH_MAX] = ""; + int keylen; char *value = NULL; glusterd_volinfo_t *origin_vol = NULL; glusterd_conf_t *conf = NULL; @@ -3305,8 +3341,8 @@ glusterd_snapshot_get_snapvol_detail (dict_t *dict, if (!value) goto out; - snprintf (key, sizeof (key), "%s.volname", keyprefix); - ret = dict_set_dynstr (dict, key, value); + keylen = snprintf (key, sizeof (key), "%s.volname", keyprefix); + ret = dict_set_dynstrn (dict, key, keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set " @@ -3321,8 +3357,8 @@ glusterd_snapshot_get_snapvol_detail (dict_t *dict, goto out; } - snprintf (key, sizeof (key), "%s.vol-id", keyprefix); - ret = dict_set_dynstr (dict, key, value); + keylen = snprintf (key, sizeof (key), "%s.vol-id", keyprefix); + ret = dict_set_dynstrn (dict, key, keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_NO_MEMORY, "Failed to set " @@ -3332,16 +3368,19 @@ glusterd_snapshot_get_snapvol_detail (dict_t *dict, value = NULL; /* volume status */ - snprintf (key, sizeof (key), "%s.vol-status", keyprefix); + keylen = snprintf (key, sizeof (key), "%s.vol-status", keyprefix); switch (snap_vol->status) { case GLUSTERD_STATUS_STARTED: - ret = dict_set_str (dict, key, "Started"); + ret = dict_set_nstrn (dict, key, keylen, + "Started", SLEN ("Started")); break; case GLUSTERD_STATUS_STOPPED: - ret = dict_set_str (dict, key, "Stopped"); + ret = dict_set_nstrn (dict, key, keylen, + "Stopped", SLEN ("Stopped")); break; case GD_SNAP_STATUS_NONE: - ret = dict_set_str (dict, key, "None"); + ret = dict_set_nstrn (dict, key, keylen, + "None", SLEN ("None")); break; default: gf_msg (this->name, GF_LOG_ERROR, EINVAL, @@ -3391,9 +3430,10 @@ glusterd_snapshot_get_snapvol_detail (dict_t *dict, "snap-max-hard-limit value is set to %d", snap_limit); } - snprintf (key, sizeof (key), "%s.snaps-available", keyprefix); + keylen = snprintf (key, sizeof (key), "%s.snaps-available", + keyprefix); if (snap_limit > origin_vol->snap_count) - ret = dict_set_int32 (dict, key, + ret = dict_set_int32n (dict, key, keylen, snap_limit - origin_vol->snap_count); else ret = dict_set_int32 (dict, key, 0); @@ -3404,8 +3444,8 @@ glusterd_snapshot_get_snapvol_detail (dict_t *dict, goto out; } - snprintf (key, sizeof (key), "%s.snapcount", keyprefix); - ret = dict_set_int32 (dict, key, origin_vol->snap_count); + keylen = snprintf (key, sizeof (key), "%s.snapcount", keyprefix); + ret = dict_set_int32n (dict, key, keylen, origin_vol->snap_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Could not save snapcount"); @@ -3420,8 +3460,8 @@ glusterd_snapshot_get_snapvol_detail (dict_t *dict, if (!value) goto out; - snprintf (key, sizeof (key), "%s.origin-volname", keyprefix); - ret = dict_set_dynstr (dict, key, value); + keylen = snprintf (key, sizeof (key), "%s.origin-volname", keyprefix); + ret = dict_set_dynstrn (dict, key, keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set parent " @@ -3445,6 +3485,7 @@ glusterd_snapshot_get_snap_detail (dict_t *dict, glusterd_snap_t *snap, int ret = -1; int volcount = 0; char key[PATH_MAX] = ""; + int keylen; char timestr[64] = ""; char *value = NULL; glusterd_volinfo_t *snap_vol = NULL; @@ -3462,8 +3503,8 @@ glusterd_snapshot_get_snap_detail (dict_t *dict, glusterd_snap_t *snap, if (!value) goto out; - snprintf (key, sizeof (key), "%s.snapname", keyprefix); - ret = dict_set_dynstr (dict, key, value); + keylen = snprintf (key, sizeof (key), "%s.snapname", keyprefix); + ret = dict_set_dynstrn (dict, key, keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set " @@ -3478,8 +3519,8 @@ glusterd_snapshot_get_snap_detail (dict_t *dict, glusterd_snap_t *snap, goto out; } - snprintf (key, sizeof (key), "%s.snap-id", keyprefix); - ret = dict_set_dynstr (dict, key, value); + keylen = snprintf (key, sizeof (key), "%s.snap-id", keyprefix); + ret = dict_set_dynstrn (dict, key, keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set " @@ -3497,8 +3538,8 @@ glusterd_snapshot_get_snap_detail (dict_t *dict, glusterd_snap_t *snap, goto out; } - snprintf (key, sizeof (key), "%s.snap-time", keyprefix); - ret = dict_set_dynstr (dict, key, value); + keylen = snprintf (key, sizeof (key), "%s.snap-time", keyprefix); + ret = dict_set_dynstrn (dict, key, keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set " @@ -3515,8 +3556,8 @@ glusterd_snapshot_get_snap_detail (dict_t *dict, glusterd_snap_t *snap, goto out; } - snprintf (key, sizeof (key), "%s.snap-desc", keyprefix); - ret = dict_set_dynstr (dict, key, value); + keylen = snprintf (key, sizeof (key), "%s.snap-desc", keyprefix); + ret = dict_set_dynstrn (dict, key, keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set " @@ -3526,22 +3567,28 @@ glusterd_snapshot_get_snap_detail (dict_t *dict, glusterd_snap_t *snap, value = NULL; } - snprintf (key, sizeof (key), "%s.snap-status", keyprefix); + keylen = snprintf (key, sizeof (key), "%s.snap-status", keyprefix); switch (snap->snap_status) { case GD_SNAP_STATUS_INIT: - ret = dict_set_str (dict, key, "Init"); + ret = dict_set_nstrn (dict, key, keylen, + "Init", SLEN ("Init")); break; case GD_SNAP_STATUS_IN_USE: - ret = dict_set_str (dict, key, "In-use"); + ret = dict_set_nstrn (dict, key, keylen, + "In-use", SLEN ("In-use")); break; case GD_SNAP_STATUS_DECOMMISSION: - ret = dict_set_str (dict, key, "Decommisioned"); + ret = dict_set_nstrn (dict, key, keylen, + "Decommisioned", + SLEN ("Decommisioned")); break; case GD_SNAP_STATUS_RESTORED: - ret = dict_set_str (dict, key, "Restored"); + ret = dict_set_nstrn (dict, key, keylen, + "Restored", SLEN ("Restored")); break; case GD_SNAP_STATUS_NONE: - ret = dict_set_str (dict, key, "None"); + ret = dict_set_nstrn (dict, key, keylen, + "None", SLEN ("None")); break; default: gf_msg (this->name, GF_LOG_ERROR, EINVAL, @@ -3587,8 +3634,8 @@ glusterd_snapshot_get_snap_detail (dict_t *dict, glusterd_snap_t *snap, } done: - snprintf (key, sizeof (key), "%s.vol-count", keyprefix); - ret = dict_set_int32 (dict, key, volcount); + keylen = snprintf (key, sizeof (key), "%s.vol-count", keyprefix); + ret = dict_set_int32n (dict, key, keylen, volcount); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set %s", @@ -3609,7 +3656,7 @@ glusterd_snapshot_get_all_snap_info (dict_t *dict) { int ret = -1; int snapcount = 0; - char key[PATH_MAX] = ""; + char key[64] = ""; glusterd_snap_t *snap = NULL; glusterd_snap_t *tmp_snap = NULL; glusterd_conf_t *priv = NULL; @@ -3635,7 +3682,8 @@ glusterd_snapshot_get_all_snap_info (dict_t *dict) } } - ret = dict_set_int32 (dict, "snapcount", snapcount); + ret = dict_set_int32n (dict, "snapcount", SLEN ("snapcount"), + snapcount); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set snapcount"); @@ -3655,7 +3703,7 @@ glusterd_snapshot_get_info_by_volume (dict_t *dict, char *volname, int snapcount = 0; int snap_limit = 0; char *value = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; glusterd_volinfo_t *volinfo = NULL; glusterd_volinfo_t *snap_vol = NULL; glusterd_volinfo_t *tmp_vol = NULL; @@ -3705,10 +3753,12 @@ glusterd_snapshot_get_info_by_volume (dict_t *dict, char *volname, } if (snap_limit > volinfo->snap_count) - ret = dict_set_int32 (dict, "snaps-available", - snap_limit - volinfo->snap_count); + ret = dict_set_int32n (dict, "snaps-available", + SLEN ("snaps-available"), + snap_limit - volinfo->snap_count); else - ret = dict_set_int32 (dict, "snaps-available", 0); + ret = dict_set_int32n (dict, "snaps-available", + SLEN ("snaps-available"), 0); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -3721,11 +3771,12 @@ glusterd_snapshot_get_info_by_volume (dict_t *dict, char *volname, if (!value) goto out; - ret = dict_set_dynstr (dict, "origin-volname", value); + ret = dict_set_dynstrn (dict, "origin-volname", + SLEN ("origin-volname"), value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set parent " - "volume name in dictionary: %s", key); + "volume name in dictionary: %s", value); goto out; } value = NULL; @@ -3745,7 +3796,8 @@ glusterd_snapshot_get_info_by_volume (dict_t *dict, char *volname, goto out; } } - ret = dict_set_int32 (dict, "snapcount", snapcount); + ret = dict_set_int32n (dict, "snapcount", SLEN ("snapcount"), + snapcount); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set snapcount"); @@ -3789,7 +3841,7 @@ glusterd_handle_snapshot_info (rpcsvc_request_t *req, glusterd_op_t op, GF_VALIDATE_OR_GOTO (this->name, dict, out); - ret = dict_get_int32 (dict, "sub-cmd", &cmd); + ret = dict_get_int32n (dict, "sub-cmd", SLEN ("sub-cmd"), &cmd); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get type " @@ -3812,7 +3864,8 @@ glusterd_handle_snapshot_info (rpcsvc_request_t *req, glusterd_op_t op, case GF_SNAP_INFO_TYPE_SNAP: { - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", + SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -3820,7 +3873,8 @@ glusterd_handle_snapshot_info (rpcsvc_request_t *req, glusterd_op_t op, goto out; } - ret = dict_set_int32 (dict, "snapcount", 1); + ret = dict_set_int32n (dict, "snapcount", + SLEN ("snapcount"), 1); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -3853,7 +3907,8 @@ glusterd_handle_snapshot_info (rpcsvc_request_t *req, glusterd_op_t op, case GF_SNAP_INFO_TYPE_VOL: { - 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_VOL_NOT_FOUND, @@ -3905,7 +3960,8 @@ glusterd_snapshot_get_all_snapnames (dict_t *dict) int ret = -1; int snapcount = 0; char *snapname = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; glusterd_snap_t *snap = NULL; glusterd_snap_t *tmp_snap = NULL; glusterd_conf_t *priv = NULL; @@ -3926,8 +3982,9 @@ glusterd_snapshot_get_all_snapnames (dict_t *dict) ret = -1; goto out; } - snprintf (key, sizeof (key), "snapname%d", snapcount); - ret = dict_set_dynstr (dict, key, snapname); + keylen = snprintf (key, sizeof (key), "snapname%d", + snapcount); + ret = dict_set_dynstrn (dict, key, keylen, snapname); if (ret) { GF_FREE (snapname); gf_msg (this->name, GF_LOG_ERROR, 0, @@ -3937,7 +3994,8 @@ glusterd_snapshot_get_all_snapnames (dict_t *dict) } } - ret = dict_set_int32 (dict, "snapcount", snapcount); + ret = dict_set_int32n (dict, "snapcount", + SLEN ("snapcount"), snapcount); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set snapcount"); @@ -3983,7 +4041,8 @@ glusterd_snapshot_get_vol_snapnames (dict_t *dict, glusterd_volinfo_t *volinfo) } } - ret = dict_set_int32 (dict, "snapcount", snapcount); + ret = dict_set_int32n (dict, "snapcount", SLEN ("snapcount"), + snapcount); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set snapcount"); @@ -4013,7 +4072,7 @@ glusterd_handle_snapshot_list (rpcsvc_request_t *req, glusterd_op_t op, GF_VALIDATE_OR_GOTO (this->name, op_errno, out); /* Ignore error for getting volname as it is optional */ - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (NULL == volname) { ret = glusterd_snapshot_get_all_snapnames (dict); @@ -4082,7 +4141,8 @@ glusterd_handle_snapshot_create (rpcsvc_request_t *req, glusterd_op_t op, char *snapname = NULL; int64_t volcount = 0; xlator_t *this = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; char *username = NULL; char *password = NULL; uuid_t *uuid_ptr = NULL; @@ -4114,7 +4174,7 @@ glusterd_handle_snapshot_create (rpcsvc_request_t *req, glusterd_op_t op, goto out; } - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "failed to get the snapname"); @@ -4179,8 +4239,8 @@ glusterd_handle_snapshot_create (rpcsvc_request_t *req, glusterd_op_t op, uuid_ptr = NULL; for (i = 1; i <= volcount; i++) { - snprintf (key, sizeof (key), "volname%d", i); - ret = dict_get_str (dict, key, &volname); + keylen = snprintf (key, sizeof (key), "volname%d", i); + ret = dict_get_strn (dict, key, keylen, &volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -4191,8 +4251,8 @@ glusterd_handle_snapshot_create (rpcsvc_request_t *req, glusterd_op_t op, /* generate internal username and password for the snap*/ gf_uuid_generate (tmp_uuid); username = gf_strdup (uuid_utoa (tmp_uuid)); - snprintf (key, sizeof(key), "volume%d_username", i); - ret = dict_set_dynstr (dict, key, username); + keylen = snprintf (key, sizeof(key), "volume%d_username", i); + ret = dict_set_dynstrn (dict, key, keylen, username); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set snap " @@ -4203,8 +4263,8 @@ glusterd_handle_snapshot_create (rpcsvc_request_t *req, glusterd_op_t op, gf_uuid_generate (tmp_uuid); password = gf_strdup (uuid_utoa (tmp_uuid)); - snprintf (key, sizeof(key), "volume%d_password", i); - ret = dict_set_dynstr (dict, key, password); + keylen = snprintf (key, sizeof(key), "volume%d_password", i); + ret = dict_set_dynstrn (dict, key, keylen, password); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set snap " @@ -4221,7 +4281,7 @@ glusterd_handle_snapshot_create (rpcsvc_request_t *req, glusterd_op_t op, goto out; } - snprintf (key, sizeof(key) - 1, "vol%d_volid", i); + snprintf (key, sizeof (key), "vol%d_volid", i); gf_uuid_generate (*uuid_ptr); ret = dict_set_bin (dict, key, uuid_ptr, sizeof(uuid_t)); if (ret) { @@ -4318,7 +4378,8 @@ glusterd_handle_snapshot_clone (rpcsvc_request_t *req, glusterd_op_t op, char *clonename = NULL; char *snapname = NULL; xlator_t *this = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; char *username = NULL; char *password = NULL; char *volname = NULL; @@ -4333,7 +4394,8 @@ glusterd_handle_snapshot_clone (rpcsvc_request_t *req, glusterd_op_t op, GF_ASSERT (dict); GF_ASSERT (err_str); - ret = dict_get_str (dict, "clonename", &clonename); + ret = dict_get_strn (dict, "clonename", SLEN ("clonename"), + &clonename); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "failed to " @@ -4342,8 +4404,8 @@ glusterd_handle_snapshot_clone (rpcsvc_request_t *req, glusterd_op_t op, } /*We need to take a volume lock on clone name*/ volname = gf_strdup (clonename); - snprintf (key, sizeof(key), "volname1"); - ret = dict_set_dynstr (dict, key, volname); + keylen = snprintf (key, sizeof (key), "volname1"); + ret = dict_set_dynstrn (dict, key, keylen, volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set clone " @@ -4352,7 +4414,7 @@ glusterd_handle_snapshot_clone (rpcsvc_request_t *req, glusterd_op_t op, goto out; } - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "failed to get the snapname"); @@ -4377,7 +4439,7 @@ glusterd_handle_snapshot_clone (rpcsvc_request_t *req, glusterd_op_t op, } uuid_ptr = NULL; - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -4387,8 +4449,8 @@ glusterd_handle_snapshot_clone (rpcsvc_request_t *req, glusterd_op_t op, gf_uuid_generate (tmp_uuid); username = gf_strdup (uuid_utoa (tmp_uuid)); - snprintf (key, sizeof(key), "volume1_username"); - ret = dict_set_dynstr (dict, key, username); + keylen = snprintf (key, sizeof (key), "volume1_username"); + ret = dict_set_dynstrn (dict, key, keylen, username); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -4400,8 +4462,8 @@ glusterd_handle_snapshot_clone (rpcsvc_request_t *req, glusterd_op_t op, gf_uuid_generate (tmp_uuid); password = gf_strdup (uuid_utoa (tmp_uuid)); - snprintf (key, sizeof(key), "volume1_password"); - ret = dict_set_dynstr (dict, key, password); + keylen = snprintf (key, sizeof (key), "volume1_password"); + ret = dict_set_dynstrn (dict, key, keylen, password); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -4419,7 +4481,7 @@ glusterd_handle_snapshot_clone (rpcsvc_request_t *req, glusterd_op_t op, goto out; } - snprintf (key, sizeof(key) - 1, "vol1_volid"); + snprintf (key, sizeof (key), "vol1_volid"); gf_uuid_generate (*uuid_ptr); ret = dict_set_bin (dict, key, uuid_ptr, sizeof(uuid_t)); if (ret) { @@ -4476,7 +4538,8 @@ glusterd_handle_snapshot_restore (rpcsvc_request_t *req, glusterd_op_t op, glusterd_snap_t *snap = NULL; glusterd_volinfo_t *snap_volinfo = NULL; int32_t i = 0; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; this = THIS; GF_ASSERT (this); @@ -4487,7 +4550,7 @@ glusterd_handle_snapshot_restore (rpcsvc_request_t *req, glusterd_op_t op, GF_ASSERT (dict); GF_ASSERT (err_str); - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to " @@ -4508,13 +4571,13 @@ glusterd_handle_snapshot_restore (rpcsvc_request_t *req, glusterd_op_t op, list_for_each_entry (snap_volinfo, &snap->volumes, vol_list) { i++; - snprintf (key, sizeof (key), "volname%d", i); + keylen = snprintf (key, sizeof (key), "volname%d", i); buf = gf_strdup (snap_volinfo->parent_volname); if (!buf) { ret = -1; goto out; } - ret = dict_set_dynstr (dict, key, buf); + ret = dict_set_dynstrn (dict, key, keylen, buf); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Could not set " @@ -4526,7 +4589,7 @@ glusterd_handle_snapshot_restore (rpcsvc_request_t *req, glusterd_op_t op, buf = NULL; } - ret = dict_set_int32 (dict, "volcount", i); + ret = dict_set_int32n (dict, "volcount", SLEN ("volcount"), i); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -4567,7 +4630,7 @@ glusterd_create_snap_object (dict_t *dict, dict_t *rsp_dict) GF_ASSERT (rsp_dict); /* Fetch snapname, description, id and time from dict */ - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to fetch snapname"); @@ -4575,7 +4638,8 @@ glusterd_create_snap_object (dict_t *dict, dict_t *rsp_dict) } /* Ignore ret value for description*/ - ret = dict_get_str (dict, "description", &description); + ret = dict_get_strn (dict, "description", + SLEN ("description"), &description); ret = dict_get_bin (dict, "snap-id", (void **)&snap_id); if (ret) { @@ -4706,8 +4770,9 @@ glusterd_add_missed_snaps_to_dict (dict_t *rsp_dict, } /* Fetch the missed_snap_count from the dict */ - ret = dict_get_int32 (rsp_dict, "missed_snap_count", - &missed_snap_count); + ret = dict_get_int32n (rsp_dict, "missed_snap_count", + SLEN ("missed_snap_count"), + &missed_snap_count); if (ret) { /* Initialize the missed_snap_count for the first time */ missed_snap_count = 0; @@ -4728,8 +4793,9 @@ glusterd_add_missed_snaps_to_dict (dict_t *rsp_dict, missed_snap_count++; /* Setting the new missed_snap_count in the dict */ - ret = dict_set_int32 (rsp_dict, "missed_snap_count", - missed_snap_count); + ret = dict_set_int32n (rsp_dict, "missed_snap_count", + SLEN ("missed_snap_count"), + missed_snap_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -4934,7 +5000,8 @@ glusterd_add_brick_to_snap_volume (dict_t *dict, dict_t *rsp_dict, int64_t volcount, int32_t brick_count, int clone) { - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; char *value = NULL; char *snap_brick_dir = NULL; char snap_brick_path[PATH_MAX] = ""; @@ -4954,7 +5021,7 @@ glusterd_add_brick_to_snap_volume (dict_t *dict, dict_t *rsp_dict, GF_ASSERT (snap_vol); GF_ASSERT (original_brickinfo); - snprintf (key, sizeof(key), "vol%"PRId64".origin_brickpath%d", + snprintf (key, sizeof (key), "vol%"PRId64".origin_brickpath%d", volcount, brick_count); ret = dict_set_dynstr_with_alloc (dict, key, original_brickinfo->path); if (ret) { @@ -4973,9 +5040,9 @@ glusterd_add_brick_to_snap_volume (dict_t *dict, dict_t *rsp_dict, goto out; } - snprintf (key, sizeof(key) - 1, "vol%"PRId64".fstype%d", volcount, - brick_count); - ret = dict_get_str (dict, key, &value); + keylen = snprintf (key, sizeof (key), "vol%"PRId64".fstype%d", + volcount, brick_count); + ret = dict_get_strn (dict, key, keylen, &value); if (!ret) { /* Update the fstype in original brickinfo as well */ gf_strncpy (original_brickinfo->fstype, value, @@ -4987,9 +5054,9 @@ glusterd_add_brick_to_snap_volume (dict_t *dict, dict_t *rsp_dict, add_missed_snap = _gf_true; } - snprintf (key, sizeof(key) - 1, "vol%"PRId64".mnt_opts%d", volcount, - brick_count); - ret = dict_get_str (dict, key, &value); + keylen = snprintf (key, sizeof (key), "vol%"PRId64".mnt_opts%d", + volcount, brick_count); + ret = dict_get_strn (dict, key, keylen, &value); if (!ret) { /* Update the mnt_opts in original brickinfo as well */ gf_strncpy (original_brickinfo->mnt_opts, value, @@ -5001,9 +5068,9 @@ glusterd_add_brick_to_snap_volume (dict_t *dict, dict_t *rsp_dict, add_missed_snap = _gf_true; } - snprintf (key, sizeof(key) - 1, "vol%"PRId64".brickdir%d", volcount, - brick_count); - ret = dict_get_str (dict, key, &snap_brick_dir); + keylen = snprintf (key, sizeof (key), "vol%"PRId64".brickdir%d", + volcount, brick_count); + ret = dict_get_strn (dict, key, keylen, &snap_brick_dir); if (ret) { /* Using original brickinfo here because it will be a * pending snapshot and storing the original brickinfo @@ -5075,9 +5142,9 @@ glusterd_add_brick_to_snap_volume (dict_t *dict, dict_t *rsp_dict, goto out; } - snprintf (key, sizeof(key), "vol%"PRId64".brick_snapdevice%d", + keylen = snprintf (key, sizeof (key), "vol%"PRId64".brick_snapdevice%d", volcount, brick_count); - ret = dict_get_str (dict, key, &snap_device); + ret = dict_get_strn (dict, key, keylen, &snap_device); if (ret) { /* If the device name is empty, so will be the brick path * Hence the missed snap has already been added above @@ -5233,7 +5300,8 @@ glusterd_take_brick_snapshot (dict_t *dict, glusterd_volinfo_t *snap_vol, int32_t clone) { char *origin_brick_path = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; int32_t ret = -1; gf_boolean_t snap_activate = _gf_false; xlator_t *this = NULL; @@ -5255,9 +5323,9 @@ glusterd_take_brick_snapshot (dict_t *dict, glusterd_volinfo_t *snap_vol, goto out; } - snprintf (key, sizeof(key) - 1, "vol%d.origin_brickpath%d", volcount, - brick_count); - ret = dict_get_str (dict, key, &origin_brick_path); + keylen = snprintf (key, sizeof(key), "vol%d.origin_brickpath%d", + volcount, brick_count); + ret = dict_get_strn (dict, key, keylen, &origin_brick_path); if (ret) { gf_msg (this->name, GF_LOG_WARNING, 0, GD_MSG_DICT_GET_FAILED, "Unable to fetch " @@ -5375,7 +5443,8 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap, dict_t *dict, dict_t *rsp_dict, int64_t volcount, int clone) { - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; char *username = NULL; char *password = NULL; glusterd_brickinfo_t *brickinfo = NULL; @@ -5412,16 +5481,18 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap, GF_ASSERT (rsp_dict); /* fetch username, password and vol_id from dict*/ - snprintf (key, sizeof(key), "volume%"PRId64"_username", volcount); - ret = dict_get_str (dict, key, &username); + keylen = snprintf (key, sizeof (key), "volume%"PRId64"_username", + volcount); + ret = dict_get_strn (dict, key, keylen, &username); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get %s for " "snap %s", key, snap->snapname); goto out; } - snprintf (key, sizeof(key), "volume%"PRId64"_password", volcount); - ret = dict_get_str (dict, key, &password); + keylen = snprintf (key, sizeof (key), "volume%"PRId64"_password", + volcount); + ret = dict_get_strn (dict, key, keylen, &password); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get %s for " @@ -5429,7 +5500,7 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap, goto out; } - snprintf (key, sizeof(key) - 1, "vol%"PRId64"_volid", volcount); + snprintf (key, sizeof (key), "vol%"PRId64"_volid", volcount); ret = dict_get_bin (dict, key, (void **)&snap_volid); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, @@ -5458,7 +5529,8 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap, if (clone) { snap_vol->is_snap_volume = _gf_false; - ret = dict_get_str (dict, "clonename", &clonename); + ret = dict_get_strn (dict, "clonename", SLEN ("clonename"), + &clonename); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get %s " @@ -5531,7 +5603,8 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap, * before storing and generating the brick volfiles. Also update * the snap vol's version after removing the barrier key. */ - dict_del (snap_vol->dict, "features.barrier"); + dict_deln (snap_vol->dict, "features.barrier", + SLEN ("features.barrier")); gd_update_volume_op_versions (snap_vol); ret = glusterd_store_volinfo (snap_vol, @@ -5647,7 +5720,7 @@ glusterd_snapshot_activate_deactivate_prevalidate (dict_t *dict, goto out; } - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Getting the snap name " @@ -5666,7 +5739,7 @@ glusterd_snapshot_activate_deactivate_prevalidate (dict_t *dict, /*If its activation of snap then fetch the flags*/ if (is_op_activate) { - ret = dict_get_int32 (dict, "flags", &flags); + ret = dict_get_int32n (dict, "flags", SLEN ("flags"), &flags); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -5743,7 +5816,7 @@ glusterd_handle_snapshot_delete_vol (dict_t *dict, char *err_str, GF_ASSERT (dict); GF_VALIDATE_OR_GOTO (this->name, op_errno, out); - 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 " @@ -5812,7 +5885,7 @@ glusterd_handle_snapshot_delete_all (dict_t *dict) } } - ret = dict_set_int32 (dict, "snapcount", i); + ret = dict_set_int32n (dict, "snapcount", SLEN ("snapcount"), i); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -5836,7 +5909,8 @@ glusterd_handle_snapshot_delete_type_snap (rpcsvc_request_t *req, int64_t volcount = 0; char *snapname = NULL; char *volname = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; glusterd_snap_t *snap = NULL; glusterd_volinfo_t *snap_vol = NULL; glusterd_volinfo_t *tmp = NULL; @@ -5849,7 +5923,7 @@ glusterd_handle_snapshot_delete_type_snap (rpcsvc_request_t *req, GF_ASSERT (dict); GF_ASSERT (err_str); - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get snapname"); @@ -5878,8 +5952,9 @@ glusterd_handle_snapshot_delete_type_snap (rpcsvc_request_t *req, goto out; } - snprintf (key, sizeof (key), "volname%"PRId64, volcount); - ret = dict_set_dynstr (dict, key, volname); + keylen = snprintf (key, sizeof (key), "volname%"PRId64, + volcount); + ret = dict_set_dynstrn (dict, key, keylen, volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set " @@ -5941,7 +6016,7 @@ glusterd_handle_snapshot_delete (rpcsvc_request_t *req, glusterd_op_t op, GF_ASSERT (err_str); GF_VALIDATE_OR_GOTO (this->name, op_errno, out); - ret = dict_get_int32 (dict, "sub-cmd", &delete_cmd); + ret = dict_get_int32n (dict, "sub-cmd", SLEN ("sub-cmd"), &delete_cmd); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_COMMAND_NOT_FOUND, "Failed to get sub-cmd"); @@ -6025,7 +6100,7 @@ glusterd_snapshot_remove_prevalidate (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Getting the snap name " @@ -6083,7 +6158,7 @@ glusterd_snapshot_status_prevalidate (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_int32 (dict, "sub-cmd", &cmd); + ret = dict_get_int32n (dict, "sub-cmd", SLEN ("sub-cmd"), &cmd); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -6099,7 +6174,8 @@ glusterd_snapshot_status_prevalidate (dict_t *dict, char **op_errstr, case GF_SNAP_STATUS_TYPE_ITER: case GF_SNAP_STATUS_TYPE_SNAP: { - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", + SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -6125,7 +6201,8 @@ glusterd_snapshot_status_prevalidate (dict_t *dict, char **op_errstr, } case GF_SNAP_STATUS_TYPE_VOL: { - 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, @@ -6189,7 +6266,7 @@ glusterd_snapshot_activate_commit (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Getting the snap name " @@ -6197,7 +6274,7 @@ glusterd_snapshot_activate_commit (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_int32 (dict, "flags", &flags); + ret = dict_get_int32n (dict, "flags", SLEN ("flags"), &flags); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get flags"); @@ -6292,7 +6369,7 @@ glusterd_snapshot_deactivate_commit (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Getting the snap name " @@ -6393,7 +6470,7 @@ glusterd_snapshot_remove_commit (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Getting the snap name " @@ -6515,7 +6592,7 @@ glusterd_do_snap_cleanup (dict_t *dict, char **op_errstr, dict_t *rsp_dict) } /* As of now snapshot of multiple volumes are not supported */ - ret = dict_get_str (dict, "volname1", &volname); + ret = dict_get_strn (dict, "volname1", SLEN ("volname1"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get" @@ -6523,7 +6600,7 @@ glusterd_do_snap_cleanup (dict_t *dict, char **op_errstr, dict_t *rsp_dict) goto out; } - ret = dict_get_str (dict, "snapname", &name); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &name); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "getting the snap " @@ -6580,8 +6657,9 @@ glusterd_snapshot_update_snaps_post_validate (dict_t *dict, char **op_errstr, GF_ASSERT (rsp_dict); GF_ASSERT (op_errstr); - ret = dict_get_int32 (dict, "missed_snap_count", - &missed_snap_count); + ret = dict_get_int32n (dict, "missed_snap_count", + SLEN ("missed_snap_count"), + &missed_snap_count); if (ret) { gf_msg_debug (this->name, 0, "No missed snaps"); ret = 0; @@ -6616,7 +6694,8 @@ glusterd_take_brick_snapshot_task (void *opaque) int32_t clone = 0; snap_create_args_t *snap_args = NULL; char *clonename = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; GF_ASSERT (opaque); @@ -6625,13 +6704,16 @@ glusterd_take_brick_snapshot_task (void *opaque) /* Try and fetch clonename. If present set status with clonename * * else do so as snap-vol */ - ret = dict_get_str (snap_args->dict, "clonename", &clonename); + ret = dict_get_strn (snap_args->dict, "clonename", + SLEN ("clonename"), &clonename); if (ret) { - snprintf (key, sizeof (key), "snap-vol%d.brick%d.status", - snap_args->volcount, snap_args->brickorder); + keylen = snprintf (key, sizeof (key), + "snap-vol%d.brick%d.status", + snap_args->volcount, snap_args->brickorder); } else { - snprintf (key, sizeof (key), "clone%d.brick%d.status", - snap_args->volcount, snap_args->brickorder); + keylen = snprintf (key, sizeof (key), + "clone%d.brick%d.status", + snap_args->volcount, snap_args->brickorder); clone = 1; } @@ -6651,7 +6733,7 @@ glusterd_take_brick_snapshot_task (void *opaque) snap_args->snap_vol->volname); } - if (dict_set_int32 (snap_args->rsp_dict, key, (ret)?0:1)) { + if (dict_set_int32n (snap_args->rsp_dict, key, keylen, (ret)?0:1)) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "failed to " "add %s to dict", key); @@ -6691,7 +6773,8 @@ glusterd_schedule_brick_snapshot (dict_t *dict, dict_t *rsp_dict, int32_t brickcount = 0; int32_t brickorder = 0; int32_t taskcount = 0; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; xlator_t *this = NULL; glusterd_volinfo_t *snap_vol = NULL; glusterd_brickinfo_t *brickinfo = NULL; @@ -6712,10 +6795,11 @@ glusterd_schedule_brick_snapshot (dict_t *dict, dict_t *rsp_dict, brickorder = 0; cds_list_for_each_entry (brickinfo, &snap_vol->bricks, brick_list) { - snprintf (key, sizeof(key) - 1, - "snap-vol%d.brick%d.order", volcount, - brickcount); - ret = dict_set_int32 (rsp_dict, key, brickorder); + keylen = snprintf (key, sizeof(key), + "snap-vol%d.brick%d.order", + volcount, brickcount); + ret = dict_set_int32n (rsp_dict, key, keylen, + brickorder); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -6727,10 +6811,12 @@ glusterd_schedule_brick_snapshot (dict_t *dict, dict_t *rsp_dict, (brickinfo->snap_status == -1)) { if (!gf_uuid_compare (brickinfo->uuid, MY_UUID)) { brickcount++; - snprintf (key, sizeof (key), - "snap-vol%d.brick%d.status", - volcount, brickorder); - ret = dict_set_int32 (rsp_dict, key, 0); + keylen = snprintf (key, sizeof (key), + "snap-vol%d.brick%d.status", + volcount, + brickorder); + ret = dict_set_int32n (rsp_dict, key, + keylen, 0); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, @@ -6817,7 +6903,8 @@ glusterd_create_snap_object_for_clone (dict_t *dict, dict_t *rsp_dict) GF_ASSERT (rsp_dict); /* Fetch snapname, description, id and time from dict */ - ret = dict_get_str (dict, "clonename", &snapname); + ret = dict_get_strn (dict, "clonename", SLEN ("clonename"), + &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to fetch clonename"); @@ -6878,7 +6965,8 @@ glusterd_snapshot_clone_commit (dict_t *dict, char **op_errstr, GF_ASSERT(priv); - ret = dict_get_str (dict, "clonename", &snapname); + ret = dict_get_strn (dict, "clonename", SLEN ("clonename"), + &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to fetch clonename"); @@ -6903,7 +6991,7 @@ glusterd_snapshot_clone_commit (dict_t *dict, char **op_errstr, tmp_name = NULL; - ret = dict_get_str (dict, "snapname", &volname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -7009,7 +7097,8 @@ glusterd_snapshot_create_commit (dict_t *dict, char **op_errstr, char *snapname = NULL; char *volname = NULL; char *tmp_name = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; xlator_t *this = NULL; glusterd_snap_t *snap = NULL; glusterd_volinfo_t *origin_vol = NULL; @@ -7033,7 +7122,7 @@ glusterd_snapshot_create_commit (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to fetch snapname"); @@ -7067,8 +7156,8 @@ glusterd_snapshot_create_commit (dict_t *dict, char **op_errstr, } for (i = 1; i <= volcount; i++) { - snprintf (key, sizeof (key), "volname%"PRId64, i); - ret = dict_get_str (dict, key, &volname); + keylen = snprintf (key, sizeof (key), "volname%"PRId64, i); + ret = dict_get_strn (dict, key, keylen, &volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -7153,7 +7242,7 @@ glusterd_snapshot_create_commit (dict_t *dict, char **op_errstr, } /* Activate created bricks in case of activate-on-create config. */ - ret = dict_get_int32 (dict, "flags", &flags); + ret = dict_get_int32n (dict, "flags", SLEN ("flags"), &flags); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get flags"); @@ -7227,8 +7316,9 @@ snap_max_hard_limit_set_commit (dict_t *dict, uint64_t value, if (ret) goto out; - ret = dict_set_str (conf->opts, GLUSTERD_GLOBAL_OPT_VERSION, - next_version); + ret = dict_set_strn (conf->opts, GLUSTERD_GLOBAL_OPT_VERSION, + SLEN (GLUSTERD_GLOBAL_OPT_VERSION), + next_version); if (ret) goto out; @@ -7295,7 +7385,8 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr, GF_ASSERT (conf); - ret = dict_get_int32 (dict, "config-command", &config_command); + ret = dict_get_int32n (dict, "config-command", + SLEN ("config-command"), &config_command); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_COMMAND_NOT_FOUND, @@ -7307,7 +7398,7 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); /* config values snap-max-hard-limit and snap-max-soft-limit are * optional and hence we are not erroring out if values are not @@ -7348,9 +7439,10 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr, goto done; } - if (!dict_get_str(dict, - GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE, - &auto_delete)) { + if (!dict_get_strn (dict, + GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE, + SLEN (GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE), + &auto_delete)) { system_conf = _gf_true; ret = dict_set_dynstr_with_alloc (conf->opts, GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE, @@ -7361,9 +7453,10 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr, "save auto-delete value in conf->opts"); goto out; } - } else if (!dict_get_str(dict, - GLUSTERD_STORE_KEY_SNAP_ACTIVATE, - &snap_activate)) { + } else if (!dict_get_strn (dict, + GLUSTERD_STORE_KEY_SNAP_ACTIVATE, + SLEN (GLUSTERD_STORE_KEY_SNAP_ACTIVATE), + &snap_activate)) { system_conf = _gf_true; ret = dict_set_dynstr_with_alloc (conf->opts, GLUSTERD_STORE_KEY_SNAP_ACTIVATE, @@ -7392,8 +7485,9 @@ done: goto out; } - ret = dict_set_str (conf->opts, GLUSTERD_GLOBAL_OPT_VERSION, - next_version); + ret = dict_set_strn (conf->opts, GLUSTERD_GLOBAL_OPT_VERSION, + SLEN (GLUSTERD_GLOBAL_OPT_VERSION), + next_version); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_GLOBAL_OP_VERSION_SET_FAIL, @@ -7575,6 +7669,7 @@ glusterd_get_single_brick_status (char **op_errstr, dict_t *rsp_dict, xlator_t *this = NULL; glusterd_conf_t *priv = NULL; char key[PATH_MAX] = ""; + int keylen; char *device = NULL; char *value = NULL; char brick_path[PATH_MAX] = ""; @@ -7592,9 +7687,10 @@ glusterd_get_single_brick_status (char **op_errstr, dict_t *rsp_dict, GF_ASSERT (snap_volinfo); GF_ASSERT (brickinfo); - ret = snprintf (key, sizeof (key), "%s.brick%d.path", keyprefix, + keylen = snprintf (key, sizeof (key), "%s.brick%d.path", keyprefix, index); - if (ret < 0) { + if (keylen < 0) { + ret = -1; goto out; } @@ -7610,7 +7706,7 @@ glusterd_get_single_brick_status (char **op_errstr, dict_t *rsp_dict, goto out; } - ret = dict_set_dynstr (rsp_dict, key, value); + ret = dict_set_dynstrn (rsp_dict, key, keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Unable to store " @@ -7626,9 +7722,9 @@ glusterd_get_single_brick_status (char **op_errstr, dict_t *rsp_dict, goto out; } - snprintf (key, sizeof (key), "%s.brick%d.vgname", - keyprefix, index); - ret = dict_set_dynstr (rsp_dict, key, value); + keylen = snprintf (key, sizeof (key), "%s.brick%d.vgname", + keyprefix, index); + ret = dict_set_dynstrn (rsp_dict, key, keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -7641,9 +7737,10 @@ glusterd_get_single_brick_status (char **op_errstr, dict_t *rsp_dict, } value = NULL; - ret = snprintf (key, sizeof (key), "%s.brick%d.status", - keyprefix, index); - if (ret < 0) { + keylen = snprintf (key, sizeof (key), "%s.brick%d.status", + keyprefix, index); + if (keylen < 0) { + ret = -1; goto out; } @@ -7653,7 +7750,7 @@ glusterd_get_single_brick_status (char **op_errstr, dict_t *rsp_dict, ret = -1; goto out; } - ret = dict_set_str (rsp_dict, key, value); + ret = dict_set_strn (rsp_dict, key, keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -7667,7 +7764,7 @@ glusterd_get_single_brick_status (char **op_errstr, dict_t *rsp_dict, ret = -1; goto out; } - ret = dict_set_str (rsp_dict, key, value); + ret = dict_set_strn (rsp_dict, key, keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -7680,13 +7777,15 @@ glusterd_get_single_brick_status (char **op_errstr, dict_t *rsp_dict, brickinfo, priv); if (gf_is_service_running (pidfile, &pid)) { - ret = snprintf (key, sizeof (key), "%s.brick%d.pid", - keyprefix, index); - if (ret < 0) { + keylen = snprintf (key, sizeof (key), + "%s.brick%d.pid", + keyprefix, index); + if (keylen < 0) { + ret = -1; goto out; } - ret = dict_set_int32 (rsp_dict, key, pid); + ret = dict_set_int32n (rsp_dict, key, keylen, pid); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -7696,9 +7795,10 @@ glusterd_get_single_brick_status (char **op_errstr, dict_t *rsp_dict, } } - ret = snprintf (key, sizeof (key), "%s.brick%d", - keyprefix, index); - if (ret < 0) { + keylen = snprintf (key, sizeof (key), "%s.brick%d", + keyprefix, index); + if (keylen < 0) { + ret = -1; goto out; } /* While getting snap status we should show relevant information @@ -7712,9 +7812,9 @@ glusterd_get_single_brick_status (char **op_errstr, dict_t *rsp_dict, goto out; } - snprintf (key, sizeof (key), "%s.brick%d.vgname", - keyprefix, index); - ret = dict_set_dynstr (rsp_dict, key, value); + keylen = snprintf (key, sizeof (key), "%s.brick%d.vgname", + keyprefix, index); + ret = dict_set_dynstrn (rsp_dict, key, keylen, value); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -7750,6 +7850,7 @@ glusterd_get_single_snap_status (char **op_errstr, dict_t *rsp_dict, int ret = -1; xlator_t *this = NULL; char key[PATH_MAX] = ""; + int keylen; char brickkey[PATH_MAX] = ""; glusterd_volinfo_t *snap_volinfo = NULL; glusterd_volinfo_t *tmp_volinfo = NULL; @@ -7767,9 +7868,10 @@ glusterd_get_single_snap_status (char **op_errstr, dict_t *rsp_dict, cds_list_for_each_entry_safe (snap_volinfo, tmp_volinfo, &snap->volumes, vol_list) { - ret = snprintf (key, sizeof (key), "%s.vol%d", keyprefix, + keylen = snprintf (key, sizeof (key), "%s.vol%d", keyprefix, volcount); - if (ret < 0) { + if (keylen < 0) { + ret = -1; goto out; } cds_list_for_each_entry (brickinfo, &snap_volinfo->bricks, @@ -7792,13 +7894,14 @@ glusterd_get_single_snap_status (char **op_errstr, dict_t *rsp_dict, } brickcount++; } - ret = snprintf (brickkey, sizeof (brickkey), "%s.brickcount", - key); - if (ret < 0) { + keylen = snprintf (brickkey, sizeof (brickkey), + "%s.brickcount", key); + if (keylen < 0) { goto out; } - ret = dict_set_int32 (rsp_dict, brickkey, brickcount); + ret = dict_set_int32n (rsp_dict, brickkey, keylen, + brickcount); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -7808,12 +7911,13 @@ glusterd_get_single_snap_status (char **op_errstr, dict_t *rsp_dict, volcount++; } - ret = snprintf (key, sizeof (key), "%s.volcount", keyprefix); - if (ret < 0) { + keylen = snprintf (key, sizeof (key), "%s.volcount", keyprefix); + if (keylen < 0) { + ret = -1; goto out; } - ret = dict_set_int32 (rsp_dict, key, volcount); + ret = dict_set_int32n (rsp_dict, key, keylen, volcount); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -7832,6 +7936,7 @@ glusterd_get_each_snap_object_status (char **op_errstr, dict_t *rsp_dict, { int ret = -1; char key[PATH_MAX] = ""; + int keylen; char *temp = NULL; xlator_t *this = NULL; @@ -7845,8 +7950,9 @@ glusterd_get_each_snap_object_status (char **op_errstr, dict_t *rsp_dict, /* TODO : Get all the snap volume info present in snap object, * as of now, There will be only one snapvolinfo per snap object */ - ret = snprintf (key, sizeof (key), "%s.snapname", keyprefix); - if (ret < 0) { + keylen = snprintf (key, sizeof (key), "%s.snapname", keyprefix); + if (keylen < 0) { + ret = -1; goto out; } @@ -7855,7 +7961,7 @@ glusterd_get_each_snap_object_status (char **op_errstr, dict_t *rsp_dict, ret = -1; goto out; } - ret = dict_set_dynstr (rsp_dict, key, temp); + ret = dict_set_dynstrn (rsp_dict, key, keylen, temp); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Could not save " @@ -7865,8 +7971,9 @@ glusterd_get_each_snap_object_status (char **op_errstr, dict_t *rsp_dict, temp = NULL; - ret = snprintf (key, sizeof (key), "%s.uuid", keyprefix); - if (ret < 0) { + keylen = snprintf (key, sizeof (key), "%s.uuid", keyprefix); + if (keylen < 0) { + ret = -1; goto out; } @@ -7876,7 +7983,7 @@ glusterd_get_each_snap_object_status (char **op_errstr, dict_t *rsp_dict, goto out; } - ret = dict_set_dynstr (rsp_dict, key, temp); + ret = dict_set_dynstrn (rsp_dict, key, keylen, temp); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Could not save " @@ -7895,12 +8002,13 @@ glusterd_get_each_snap_object_status (char **op_errstr, dict_t *rsp_dict, goto out; } - ret = snprintf (key, sizeof (key), "%s.volcount", keyprefix); - if (ret < 0) { + keylen = snprintf (key, sizeof (key), "%s.volcount", keyprefix); + if (keylen < 0) { + ret = keylen; goto out; } - ret = dict_set_int32 (rsp_dict, key, 1); + ret = dict_set_int32n (rsp_dict, key, keylen, 1); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Could not save volcount"); @@ -7920,7 +8028,7 @@ glusterd_get_snap_status_of_volume (char **op_errstr, dict_t *rsp_dict, glusterd_volinfo_t *snap_volinfo = NULL; glusterd_volinfo_t *temp_volinfo = NULL; glusterd_volinfo_t *volinfo = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; xlator_t *this = NULL; glusterd_conf_t *priv = NULL; int i = 0; @@ -7963,7 +8071,8 @@ glusterd_get_snap_status_of_volume (char **op_errstr, dict_t *rsp_dict, i++; } - ret = dict_set_int32 (rsp_dict, "status.snapcount", i); + ret = dict_set_int32n (rsp_dict, "status.snapcount", + SLEN ("status.snapcount"), i); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to save snapcount"); @@ -7980,7 +8089,7 @@ glusterd_get_all_snapshot_status (dict_t *dict, char **op_errstr, { int32_t i = 0; int ret = -1; - char key[PATH_MAX] = ""; + char key[64] = ""; glusterd_conf_t *priv = NULL; glusterd_snap_t *snap = NULL; glusterd_snap_t *tmp_snap = NULL; @@ -8014,7 +8123,8 @@ glusterd_get_all_snapshot_status (dict_t *dict, char **op_errstr, i++; } - ret = dict_set_int32 (rsp_dict, "status.snapcount", i); + ret = dict_set_int32n (rsp_dict, "status.snapcount", + SLEN ("status.snapcount"), i); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Could not save snapcount"); @@ -8049,7 +8159,7 @@ glusterd_snapshot_status_commit (dict_t *dict, char **op_errstr, conf = this->private; GF_ASSERT (conf); - ret = dict_get_int32 (dict, "sub-cmd", &cmd); + ret = dict_get_int32n (dict, "sub-cmd", SLEN ("sub-cmd"), &cmd); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -8057,7 +8167,7 @@ glusterd_snapshot_status_commit (dict_t *dict, char **op_errstr, goto out; } - ret = dict_set_int32 (rsp_dict, "sub-cmd", cmd); + ret = dict_set_int32n (rsp_dict, "sub-cmd", SLEN ("sub-cmd"), cmd); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -8081,7 +8191,8 @@ glusterd_snapshot_status_commit (dict_t *dict, char **op_errstr, case GF_SNAP_STATUS_TYPE_SNAP: { - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", + SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to " @@ -8111,7 +8222,8 @@ glusterd_snapshot_status_commit (dict_t *dict, char **op_errstr, goto out; } - ret = dict_set_int32 (rsp_dict, "status.snapcount", 1); + ret = dict_set_int32n (rsp_dict, "status.snapcount", + SLEN ("status.snapcount"), 1); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Unable to " @@ -8122,7 +8234,8 @@ glusterd_snapshot_status_commit (dict_t *dict, char **op_errstr, } case GF_SNAP_STATUS_TYPE_VOL: { - 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, "Unable to" @@ -8156,7 +8269,8 @@ glusterd_handle_snap_limit (dict_t *dict, dict_t *rsp_dict) int64_t volcount = 0; int i = 0; char *volname = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; char msg[PATH_MAX] = ""; glusterd_volinfo_t *volinfo = NULL; uint64_t limit = 0; @@ -8182,8 +8296,8 @@ glusterd_handle_snap_limit (dict_t *dict, dict_t *rsp_dict) } for (i = 1; i <= volcount; i++) { - snprintf (key, sizeof (key), "volname%d", i); - ret = dict_get_str (dict, key, &volname); + keylen = snprintf (key, sizeof (key), "volname%d", i); + ret = dict_get_strn (dict, key, keylen, &volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "failed to get the " @@ -8291,7 +8405,8 @@ glusterd_snapshot_clone_postvalidate (dict_t *dict, int32_t op_ret, priv = this->private; GF_ASSERT (priv); - ret = dict_get_str (dict, "clonename", &clonename); + ret = dict_get_strn (dict, "clonename", SLEN ("clonename"), + &clonename); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to fetch " @@ -8315,7 +8430,8 @@ glusterd_snapshot_clone_postvalidate (dict_t *dict, int32_t op_ret, * needed in case of a clone * */ if (op_ret) { - ret = dict_get_int32 (dict, "cleanup", &cleanup); + ret = dict_get_int32n (dict, "cleanup", SLEN ("cleanup"), + &cleanup); if (!ret && cleanup && snap) { glusterd_snap_remove (rsp_dict, snap, _gf_true, _gf_true, @@ -8372,7 +8488,8 @@ glusterd_snapshot_create_postvalidate (dict_t *dict, int32_t op_ret, GF_ASSERT (priv); if (op_ret) { - ret = dict_get_int32 (dict, "cleanup", &cleanup); + ret = dict_get_int32n (dict, "cleanup", SLEN ("cleanup"), + &cleanup); if (!ret && cleanup) { ret = glusterd_do_snap_cleanup (dict, op_errstr, rsp_dict); @@ -8392,7 +8509,7 @@ glusterd_snapshot_create_postvalidate (dict_t *dict, int32_t op_ret, goto out; } - ret = dict_get_str (dict, "snapname", &snapname); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &snapname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to fetch " @@ -8448,7 +8565,8 @@ glusterd_snapshot_create_postvalidate (dict_t *dict, int32_t op_ret, uuid_utoa(snap->snap_id)); } - ret = dict_get_str (dict, "volname1", &volname); + ret = dict_get_strn (dict, "volname1", SLEN ("volname1"), + &volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -8549,7 +8667,7 @@ glusterd_snapshot (dict_t *dict, char **op_errstr, priv = this->private; GF_ASSERT (priv); - ret = dict_get_int32 (dict, "type", &snap_command); + ret = dict_get_int32n (dict, "type", SLEN ("type"), &snap_command); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_COMMAND_NOT_FOUND, "unable to get the type of " @@ -8605,7 +8723,8 @@ glusterd_snapshot (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_str (dict, "snapname", &snap_name); + ret = dict_get_strn (dict, "snapname", + SLEN ("snapname"), &snap_name); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -8688,7 +8807,8 @@ glusterd_snapshot_brickop (dict_t *dict, char **op_errstr, dict_t *rsp_dict) int ret = -1; int64_t vol_count = 0; int64_t count = 1; - char key[1024] = ""; + char key[64] = ""; + int keylen; char *volname = NULL; int32_t snap_command = 0; xlator_t *this = NULL; @@ -8700,7 +8820,7 @@ glusterd_snapshot_brickop (dict_t *dict, char **op_errstr, dict_t *rsp_dict) GF_ASSERT (dict); GF_ASSERT (rsp_dict); - ret = dict_get_int32 (dict, "type", &snap_command); + ret = dict_get_int32n (dict, "type", SLEN ("type"), &snap_command); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_COMMAND_NOT_FOUND, "unable to get the type of " @@ -8714,7 +8834,8 @@ glusterd_snapshot_brickop (dict_t *dict, char **op_errstr, dict_t *rsp_dict) /* op_type with tell us whether its pre-commit operation * or post-commit */ - ret = dict_get_str (dict, "operation-type", &op_type); + ret = dict_get_strn (dict, "operation-type", + SLEN ("operation-type"), &op_type); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to fetch " @@ -8756,15 +8877,17 @@ glusterd_snapshot_brickop (dict_t *dict, char **op_errstr, dict_t *rsp_dict) if (ret) goto out; while (count <= vol_count) { - snprintf (key, 1024, "volname%"PRId64, count); - ret = dict_get_str (dict, key, &volname); + keylen = snprintf (key, sizeof (key), + "volname%"PRId64, count); + ret = dict_get_strn (dict, key, keylen, &volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get volname"); goto out; } - ret = dict_set_str (dict, "volname", volname); + ret = dict_set_strn (dict, "volname", + SLEN ("volname"), volname); if (ret) goto out; @@ -8776,7 +8899,7 @@ glusterd_snapshot_brickop (dict_t *dict, char **op_errstr, dict_t *rsp_dict) count++; } - dict_del (dict, "volname"); + dict_deln (dict, "volname", SLEN ("volname")); ret = 0; break; case GF_SNAP_OPTION_TYPE_DELETE: @@ -8804,7 +8927,7 @@ glusterd_snapshot_prevalidate (dict_t *dict, char **op_errstr, GF_ASSERT (rsp_dict); GF_VALIDATE_OR_GOTO (this->name, op_errno, out); - ret = dict_get_int32 (dict, "type", &snap_command); + ret = dict_get_int32n (dict, "type", SLEN ("type"), &snap_command); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_COMMAND_NOT_FOUND, "unable to get the type of " @@ -9224,7 +9347,7 @@ glusterd_snapshot_restore_postop (dict_t *dict, int32_t op_ret, GF_ASSERT (dict); GF_ASSERT (rsp_dict); - ret = dict_get_str (dict, "snapname", &name); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &name); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "getting the snap " @@ -9242,7 +9365,7 @@ glusterd_snapshot_restore_postop (dict_t *dict, int32_t op_ret, } /* TODO: fix this when multiple volume support will come */ - ret = dict_get_str (dict, "volname1", &volname); + ret = dict_get_strn (dict, "volname1", SLEN ("volname1"), &volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -9258,7 +9381,7 @@ glusterd_snapshot_restore_postop (dict_t *dict, int32_t op_ret, goto out; } - ret = dict_get_str (dict, "snapname", &name); + ret = dict_get_strn (dict, "snapname", SLEN ("snapname"), &name); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "getting the snap " @@ -9287,7 +9410,8 @@ glusterd_snapshot_restore_postop (dict_t *dict, int32_t op_ret, goto out; } } else { /* On failure revert snapshot restore */ - ret = dict_get_int32 (dict, "cleanup", &cleanup); + ret = dict_get_int32n (dict, "cleanup", SLEN ("cleanup"), + &cleanup); /* Perform cleanup only when required */ if (ret || (0 == cleanup)) { /* Delete the backup copy of volume folder */ @@ -9355,7 +9479,7 @@ glusterd_snapshot_postvalidate (dict_t *dict, int32_t op_ret, char **op_errstr, GF_ASSERT (dict); GF_ASSERT (rsp_dict); - ret = dict_get_int32 (dict, "type", &snap_command); + ret = dict_get_int32n (dict, "type", SLEN ("type"), &snap_command); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_COMMAND_NOT_FOUND, "unable to get the type of " @@ -9547,7 +9671,8 @@ glusterd_handle_snapshot_fn (rpcsvc_request_t *req) ret = -1; goto out; } - ret = dict_set_dynstr (dict, "host-uuid", host_uuid); + ret = dict_set_dynstrn (dict, "host-uuid", SLEN ("host-uuid"), + host_uuid); if (ret) { GF_FREE (host_uuid); goto out; @@ -9574,7 +9699,7 @@ glusterd_handle_snapshot_fn (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "type", &type); + ret = dict_get_int32n (dict, "type", SLEN ("type"), &type); if (ret < 0) { snprintf (err_str, sizeof (err_str), "Command type not found"); gf_msg (this->name, GF_LOG_ERROR, 0, @@ -9985,7 +10110,8 @@ glusterd_add_missed_snaps_to_list (dict_t *dict, int32_t missed_snap_count) char *snap_vol_id = NULL; char *brick_path = NULL; char missed_info[PATH_MAX] = ""; - char name_buf[PATH_MAX] = ""; + char key[64] = ""; + int keylen; int32_t i = -1; int32_t ret = -1; int32_t brick_num = -1; @@ -10004,13 +10130,13 @@ glusterd_add_missed_snaps_to_list (dict_t *dict, int32_t missed_snap_count) /* We can update the missed_snaps_list without acquiring * * any additional locks as big lock will be held. */ for (i = 0; i < missed_snap_count; i++) { - snprintf (name_buf, sizeof(name_buf), "missed_snaps_%d", - i); - ret = dict_get_str (dict, name_buf, &buf); + keylen = snprintf (key, sizeof (key), "missed_snaps_%d", + i); + ret = dict_get_strn (dict, key, keylen, &buf); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, - "Unable to fetch %s", name_buf); + "Unable to fetch %s", key); goto out; } @@ -10313,7 +10439,8 @@ glusterd_snapshot_get_volnames_uuids (dict_t *dict, } } - ret = dict_set_int32 (dict, "snap-count", snapcount); + ret = dict_set_int32n (dict, "snap-count", SLEN ("snap-count"), + snapcount); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set snapcount"); diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c index fcf8e666d3e..9a1fa1dff11 100644 --- a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c +++ b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c @@ -97,8 +97,9 @@ glusterd_svc_init_common (glusterd_svc_t *svc, glusterd_svc_build_volfileid_path (svc_name, volfileid, sizeof(volfileid)); - 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) { volfileserver = "localhost"; } @@ -199,13 +200,15 @@ glusterd_svc_start (glusterd_svc_t *svc, int flags, dict_t *cmdline) "-S", svc->conn.sockpath, NULL); - if (dict_get_str (priv->opts, GLUSTERD_LOCALTIME_LOGGING_KEY, - &localtime_logging) == 0) { + 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"); } - if (dict_get_str (priv->opts, GLUSTERD_DAEMON_LOG_LEVEL_KEY, - &log_level) == 0) { + if (dict_get_strn (priv->opts, GLUSTERD_DAEMON_LOG_LEVEL_KEY, + SLEN (GLUSTERD_DAEMON_LOG_LEVEL_KEY), + &log_level) == 0) { snprintf (daemon_log_level, 30, "--log-level=%s", log_level); runner_add_arg (&runner, daemon_log_level); } diff --git a/xlators/mgmt/glusterd/src/glusterd-tier.c b/xlators/mgmt/glusterd/src/glusterd-tier.c index d20f6900b21..9ec30b12908 100644 --- a/xlators/mgmt/glusterd/src/glusterd-tier.c +++ b/xlators/mgmt/glusterd/src/glusterd-tier.c @@ -86,7 +86,7 @@ __glusterd_handle_tier (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), "Unable to get volume name"); gf_msg (this->name, GF_LOG_ERROR, errno, @@ -95,7 +95,8 @@ __glusterd_handle_tier (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "rebalance-command", &cmd); + ret = dict_get_int32n (dict, "rebalance-command", + SLEN ("rebalance-command"), &cmd); if (ret) { snprintf (msg, sizeof (msg), "Unable to get the command"); gf_msg (this->name, GF_LOG_ERROR, errno, @@ -119,8 +120,9 @@ __glusterd_handle_tier (rpcsvc_request_t *req) GD_OP_VERSION_3_7_5); switch (cmd) { case GF_DEFRAG_CMD_DETACH_STOP: - ret = dict_set_int32 (dict, "rebalance-command", - GF_DEFRAG_CMD_STOP_DETACH_TIER); + ret = dict_set_int32n (dict, "rebalance-command", + SLEN ("rebalance-command"), + GF_DEFRAG_CMD_STOP_DETACH_TIER); break; case GF_DEFRAG_CMD_DETACH_COMMIT: @@ -133,8 +135,9 @@ __glusterd_handle_tier (rpcsvc_request_t *req) goto out; } ret = glusterd_set_detach_bricks (dict, volinfo); - ret = dict_set_int32 (dict, "command", - GF_OP_CMD_DETACH_COMMIT); + ret = dict_set_int32n (dict, "command", + SLEN ("command"), + GF_OP_CMD_DETACH_COMMIT); break; case GF_DEFRAG_CMD_DETACH_COMMIT_FORCE: ret = glusterd_volinfo_find (volname, &volinfo); @@ -146,8 +149,9 @@ __glusterd_handle_tier (rpcsvc_request_t *req) goto out; } ret = glusterd_set_detach_bricks (dict, volinfo); - ret = dict_set_int32 (dict, "command", - GF_OP_CMD_DETACH_COMMIT_FORCE); + ret = dict_set_int32n (dict, "command", + SLEN ("command"), + GF_OP_CMD_DETACH_COMMIT_FORCE); break; case GF_DEFRAG_CMD_DETACH_START: ret = glusterd_volinfo_find (volname, &volinfo); @@ -159,8 +163,9 @@ __glusterd_handle_tier (rpcsvc_request_t *req) goto out; } ret = glusterd_set_detach_bricks (dict, volinfo); - ret = dict_set_int32 (dict, "command", - GF_OP_CMD_DETACH_START); + ret = dict_set_int32n (dict, "command", + SLEN ("command"), + GF_OP_CMD_DETACH_START); break; default: @@ -256,6 +261,7 @@ glusterd_op_remove_tier_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) int32_t count = 0; int32_t i = 1; char key[256] = {0,}; + int keylen; int32_t flag = 0; char err_str[4096] = {0,}; int need_rebalance = 0; @@ -283,7 +289,7 @@ glusterd_op_remove_tier_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) priv = this->private; GF_VALIDATE_OR_GOTO (this->name, priv, out); - 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, errno, GD_MSG_DICT_GET_FAILED, "Unable to get volume name"); @@ -297,7 +303,8 @@ glusterd_op_remove_tier_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) 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 (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "cmd not found"); @@ -309,7 +316,8 @@ glusterd_op_remove_tier_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) if (!gf_uuid_is_null (volinfo->rebal.rebalance_id)) { ret = glusterd_copy_uuid_to_dict (volinfo->rebal.rebalance_id, dict, - GF_REMOVE_BRICK_TID_KEY); + GF_REMOVE_BRICK_TID_KEY, + SLEN (GF_REMOVE_BRICK_TID_KEY)); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_REMOVE_BRICK_ID_SET_FAIL, @@ -394,16 +402,18 @@ glusterd_op_remove_tier_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) "detach start", volname); goto out; } - ret = dict_get_str (dict, GF_REMOVE_BRICK_TID_KEY, - &task_id_str); + ret = dict_get_strn (dict, GF_REMOVE_BRICK_TID_KEY, + SLEN (GF_REMOVE_BRICK_TID_KEY), + &task_id_str); if (ret) { gf_msg_debug (this->name, errno, "Missing remove-brick-id"); ret = 0; } else { - ret = dict_set_str (rsp_dict, - GF_REMOVE_BRICK_TID_KEY, - task_id_str); + ret = dict_set_strn (rsp_dict, + GF_REMOVE_BRICK_TID_KEY, + SLEN (GF_REMOVE_BRICK_TID_KEY), + task_id_str); if (ret) { gf_msg (this->name, GF_LOG_WARNING, 0, GD_MSG_DICT_SET_FAILED, @@ -453,8 +463,10 @@ glusterd_op_remove_tier_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) * Revisit this code when this constraint no * longer exist. */ - dict_del (volinfo->dict, "features.ctr-enabled"); - dict_del (volinfo->dict, "cluster.tier-mode"); + dict_deln (volinfo->dict, "features.ctr-enabled", + SLEN ("features.ctr-enabled")); + dict_deln (volinfo->dict, "cluster.tier-mode", + SLEN ("cluster.tier-mode")); hot_shd_key = gd_get_shd_key (volinfo->tier_info.hot_type); @@ -517,7 +529,8 @@ glusterd_op_remove_tier_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) ret = -1; goto out; } - ret = dict_set_int32 (bricks_dict, "count", count); + ret = dict_set_int32n (bricks_dict, "count", SLEN ("count"), + count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, @@ -527,8 +540,8 @@ glusterd_op_remove_tier_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) } while (i <= count) { - snprintf (key, 256, "brick%d", i); - ret = dict_get_str (dict, key, &brick); + keylen = snprintf (key, sizeof (key), "brick%d", i); + ret = dict_get_strn (dict, key, keylen, &brick); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Unable to get %s", @@ -545,7 +558,8 @@ glusterd_op_remove_tier_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) "Failed to duplicate brick name"); goto out; } - ret = dict_set_dynstr (bricks_dict, key, brick_tmpstr); + ret = dict_set_dynstrn (bricks_dict, key, + keylen, brick_tmpstr); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, @@ -571,7 +585,8 @@ glusterd_op_remove_tier_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict) if (cmd == GF_DEFRAG_CMD_DETACH_START) volinfo->tier.dict = dict_ref (bricks_dict); - ret = dict_get_int32 (dict, "replica-count", &replica_count); + ret = dict_get_int32n (dict, "replica-count", SLEN ("replica-count"), + &replica_count); if (!ret) { gf_msg (this->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_FAILED, @@ -701,7 +716,7 @@ glusterd_op_tier_start_stop (dict_t *dict, char **op_errstr, dict_t *rsp_dict) priv = this->private; GF_VALIDATE_OR_GOTO (this->name, priv, out); - 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, errno, GD_MSG_DICT_GET_FAILED, "Unable to get volume name"); @@ -714,7 +729,8 @@ glusterd_op_tier_start_stop (dict_t *dict, char **op_errstr, dict_t *rsp_dict) 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 (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Unable to get cmd from " @@ -747,12 +763,14 @@ glusterd_op_tier_start_stop (dict_t *dict, char **op_errstr, dict_t *rsp_dict) /* we check if its running and skip so that we don't get a * failure during force start */ - ret = dict_get_int32 (dict, "force", &is_force); + ret = dict_get_int32n (dict, "force", SLEN ("force"), + &is_force); if (ret) { gf_msg_debug (this->name, 0, "Unable to get is_force" " from dict"); } - ret = dict_set_int32 (volinfo->dict, "force", is_force); + ret = dict_set_int32n (volinfo->dict, "force", SLEN ("force"), + is_force); if (ret) { gf_msg_debug (this->name, errno, "Unable to set" " is_force to dict"); @@ -828,14 +846,15 @@ glusterd_op_stage_tier (dict_t *dict, char **op_errstr, dict_t *rsp_dict) priv = this->private; GF_VALIDATE_OR_GOTO (this->name, priv, out); - 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, "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 (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "cmd not found"); @@ -893,7 +912,8 @@ glusterd_op_stage_tier (dict_t *dict, char **op_errstr, dict_t *rsp_dict) 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; @@ -950,7 +970,8 @@ glusterd_op_stage_tier (dict_t *dict, char **op_errstr, dict_t *rsp_dict) case GF_DEFRAG_CMD_DETACH_START: - ret = dict_get_int32 (dict, "count", &brick_count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), + &brick_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, @@ -996,7 +1017,8 @@ glusterd_op_stage_tier (dict_t *dict, char **op_errstr, dict_t *rsp_dict) if (is_origin_glusterd (dict)) { ret = glusterd_generate_and_set_task_id - (dict, GF_REMOVE_BRICK_TID_KEY); + (dict, GF_REMOVE_BRICK_TID_KEY, + SLEN (GF_REMOVE_BRICK_TID_KEY)); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_TASKID_GEN_FAIL, @@ -1004,8 +1026,9 @@ glusterd_op_stage_tier (dict_t *dict, char **op_errstr, dict_t *rsp_dict) goto out; } } else { - ret = dict_get_str (dict, GF_REMOVE_BRICK_TID_KEY, - &task_id_str); + ret = dict_get_strn (dict, GF_REMOVE_BRICK_TID_KEY, + SLEN (GF_REMOVE_BRICK_TID_KEY), + &task_id_str); if (ret) { gf_msg (this->name, GF_LOG_WARNING, errno, GD_MSG_DICT_GET_FAILED, @@ -1055,7 +1078,8 @@ glusterd_op_stage_tier (dict_t *dict, char **op_errstr, dict_t *rsp_dict) goto out; } - ret = dict_get_int32 (dict, "count", &brick_count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), + &brick_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, @@ -1112,8 +1136,8 @@ glusterd_add_tierd_to_dict (glusterd_volinfo_t *volinfo, int ret = -1; int32_t pid = -1; int32_t brick_online = -1; - char key[1024] = {0}; - char base_key[32] = {0}; + char key[64] = {0}; + int keylen; char pidfile[PATH_MAX] = {0}; xlator_t *this = NULL; @@ -1123,14 +1147,15 @@ glusterd_add_tierd_to_dict (glusterd_volinfo_t *volinfo, GF_VALIDATE_OR_GOTO (this->name, volinfo, out); GF_VALIDATE_OR_GOTO (this->name, dict, out); - snprintf (base_key, sizeof (base_key), "brick%d", count); - snprintf (key, sizeof (key), "%s.hostname", base_key); - ret = dict_set_str (dict, key, "Tier Daemon"); + keylen = snprintf (key, sizeof (key), "brick%d.hostname", count); + ret = dict_set_nstrn (dict, key, keylen, + "Tier Daemon", SLEN ("Tier Daemon")); if (ret) goto out; - snprintf (key, sizeof (key), "%s.path", base_key); - ret = dict_set_dynstr (dict, key, gf_strdup (uuid_utoa (MY_UUID))); + keylen = snprintf (key, sizeof (key), "brick%d.path", count); + ret = dict_set_dynstrn (dict, key, keylen, + gf_strdup (uuid_utoa (MY_UUID))); if (ret) goto out; @@ -1138,8 +1163,8 @@ glusterd_add_tierd_to_dict (glusterd_volinfo_t *volinfo, * an zero value to parse. * */ - snprintf (key, sizeof (key), "%s.port", base_key); - ret = dict_set_int32 (dict, key, 0); + keylen = snprintf (key, sizeof (key), "brick%d.port", count); + ret = dict_set_int32n (dict, key, keylen, 0); if (ret) goto out; @@ -1147,13 +1172,13 @@ glusterd_add_tierd_to_dict (glusterd_volinfo_t *volinfo, brick_online = gf_is_service_running (pidfile, &pid); - snprintf (key, sizeof (key), "%s.pid", base_key); - ret = dict_set_int32 (dict, key, pid); + keylen = snprintf (key, sizeof (key), "brick%d.pid", count); + ret = dict_set_int32n (dict, key, keylen, pid); if (ret) goto out; - snprintf (key, sizeof (key), "%s.status", base_key); - ret = dict_set_int32 (dict, key, brick_online); + keylen = snprintf (key, sizeof (key), "brick%d.status", count); + ret = dict_set_int32n (dict, key, keylen, brick_online); out: if (ret) diff --git a/xlators/mgmt/glusterd/src/glusterd-tierd-svc.c b/xlators/mgmt/glusterd/src/glusterd-tierd-svc.c index 9ea6f16a74c..311497e3e13 100644 --- a/xlators/mgmt/glusterd/src/glusterd-tierd-svc.c +++ b/xlators/mgmt/glusterd/src/glusterd-tierd-svc.c @@ -106,8 +106,9 @@ glusterd_tierdsvc_init (void *data) goto out; } - 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) { volfileserver = "localhost"; } ret = glusterd_proc_init (&(svc->proc), tierd_svc_name, pidfile, logdir, @@ -178,7 +179,8 @@ glusterd_tierdsvc_manager (glusterd_svc_t *svc, void *data, int flags) } } - ret = dict_get_int32 (volinfo->dict, "force", &is_force); + ret = dict_get_int32n (volinfo->dict, "force", SLEN ("force"), + &is_force); if (ret) { gf_msg_debug (this->name, errno, "Unable to get" " is_force from dict"); @@ -362,8 +364,9 @@ glusterd_tierdsvc_start (glusterd_svc_t *svc, int flags) volinfo->rebal.commit_hash); if (volinfo->memory_accounting) runner_add_arg (&runner, "--mem-accounting"); - if (dict_get_str (priv->opts, GLUSTERD_LOCALTIME_LOGGING_KEY, - &localtime_logging) == 0) { + 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"); } diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 1bf682d4fd3..fc078b37a55 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -106,7 +106,8 @@ is_brick_mx_enabled (void) priv = this->private; - ret = dict_get_str (priv->opts, GLUSTERD_BRICK_MULTIPLEX_KEY, &value); + ret = dict_get_strn (priv->opts, GLUSTERD_BRICK_MULTIPLEX_KEY, + SLEN (GLUSTERD_BRICK_MULTIPLEX_KEY), &value); if (!ret) ret = gf_string2boolean (value, &enabled); @@ -135,7 +136,8 @@ get_mux_limit_per_process (int *mux_limit) goto out; } - ret = dict_get_str (priv->opts, GLUSTERD_BRICKMUX_LIMIT_KEY, &value); + ret = dict_get_strn (priv->opts, GLUSTERD_BRICKMUX_LIMIT_KEY, + SLEN (GLUSTERD_BRICKMUX_LIMIT_KEY), &value); if (ret) { gf_msg_debug (this->name, 0, "Limit for number of bricks per " "brick process not yet set in dict. Returning " @@ -237,7 +239,9 @@ glusterd_volume_brick_for_each (glusterd_volinfo_t *volinfo, void *data, goto out; } - ret = dict_set_str (mod_dict, "hot-brick", "on"); + ret = dict_set_nstrn (mod_dict, + "hot-brick", SLEN ("hot-brick"), + "on", SLEN ("on")); if (ret) goto out; @@ -2175,8 +2179,9 @@ retry: "--process-name", "brick", NULL); - if (dict_get_str (priv->opts, GLUSTERD_LOCALTIME_LOGGING_KEY, - &localtime_logging) == 0) { + 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"); } @@ -2212,8 +2217,9 @@ retry: runner_argprintf (&runner, "%s-server.listen-port=%d", volinfo->volname, port); - if (dict_get_str (this->options, "transport.socket.bind-address", - &bind_address) == 0) { + if (dict_get_strn (this->options, "transport.socket.bind-address", + SLEN ("transport.socket.bind-address"), + &bind_address) == 0) { runner_add_arg (&runner, "--xlator-option"); runner_argprintf (&runner, "transport.socket.bind-address=%s", bind_address); @@ -2915,16 +2921,16 @@ _add_dict_to_prdict (dict_t *this, char *key, data_t *value, void *data) int ret = -1; ctx = data; - snprintf (optkey, sizeof (optkey), "%s.%s%d", ctx->prefix, + ret = snprintf (optkey, sizeof (optkey), "%s.%s%d", ctx->prefix, ctx->key_name, ctx->opt_count); - ret = dict_set_str (ctx->dict, optkey, key); + ret = dict_set_strn (ctx->dict, optkey, ret, key); if (ret) gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "option add for %s%d %s", ctx->key_name, ctx->opt_count, key); - snprintf (optkey, sizeof (optkey), "%s.%s%d", ctx->prefix, + ret = snprintf (optkey, sizeof (optkey), "%s.%s%d", ctx->prefix, ctx->val_name, ctx->opt_count); - ret = dict_set_str (ctx->dict, optkey, value->data); + ret = dict_set_strn (ctx->dict, optkey, ret, value->data); if (ret) gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -2941,18 +2947,18 @@ glusterd_add_bricks_hname_path_to_dict (dict_t *dict, { glusterd_brickinfo_t *brickinfo = NULL; int ret = 0; - char key[256] = ""; + char key[64] = ""; int index = 0; cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { - snprintf (key, sizeof (key), "%d-hostname", index); - ret = dict_set_str (dict, key, brickinfo->hostname); + ret = snprintf (key, sizeof (key), "%d-hostname", index); + ret = dict_set_strn (dict, key, ret, brickinfo->hostname); if (ret) goto out; - snprintf (key, sizeof (key), "%d-path", index); - ret = dict_set_str (dict, key, brickinfo->path); + ret = snprintf (key, sizeof (key), "%d-path", index); + ret = dict_set_strn (dict, key, ret, brickinfo->path); if (ret) goto out; @@ -2974,6 +2980,7 @@ glusterd_add_volume_to_dict (glusterd_volinfo_t *volinfo, int32_t ret = -1; char pfx[512] = ""; char key[512] = ""; + int keylen; glusterd_brickinfo_t *brickinfo = NULL; int32_t i = 1; char *volume_id_str = NULL; @@ -2989,63 +2996,70 @@ glusterd_add_volume_to_dict (glusterd_volinfo_t *volinfo, GF_ASSERT (volinfo); GF_ASSERT (prefix); - snprintf (key, sizeof (key), "%s%d.name", prefix, count); - ret = dict_set_str (dict, key, volinfo->volname); + keylen = snprintf (key, sizeof (key), "%s%d.name", prefix, count); + ret = dict_set_strn (dict, key, keylen, volinfo->volname); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.type", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->type); + keylen = snprintf (key, sizeof (key), "%s%d.type", prefix, count); + ret = dict_set_int32n (dict, key, keylen, volinfo->type); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.brick_count", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->brick_count); + keylen = snprintf (key, sizeof (key), "%s%d.brick_count", prefix, + count); + ret = dict_set_int32n (dict, key, keylen, volinfo->brick_count); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.version", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->version); + keylen = snprintf (key, sizeof (key), "%s%d.version", prefix, count); + ret = dict_set_int32n (dict, key, keylen, volinfo->version); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.status", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->status); + keylen = snprintf (key, sizeof (key), "%s%d.status", prefix, count); + ret = dict_set_int32n (dict, key, keylen, volinfo->status); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.sub_count", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->sub_count); + keylen = snprintf (key, sizeof (key), "%s%d.sub_count", prefix, + count); + ret = dict_set_int32n (dict, key, keylen, volinfo->sub_count); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.stripe_count", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->stripe_count); + keylen = snprintf (key, sizeof (key), "%s%d.stripe_count", prefix, + count); + ret = dict_set_int32n (dict, key, keylen, volinfo->stripe_count); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.replica_count", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->replica_count); + keylen = snprintf (key, sizeof (key), "%s%d.replica_count", prefix, + count); + ret = dict_set_int32n (dict, key, keylen, volinfo->replica_count); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.arbiter_count", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->arbiter_count); + keylen = snprintf (key, sizeof (key), "%s%d.arbiter_count", prefix, + count); + ret = dict_set_int32n (dict, key, keylen, volinfo->arbiter_count); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.disperse_count", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->disperse_count); + keylen = snprintf (key, sizeof (key), "%s%d.disperse_count", prefix, + count); + ret = dict_set_int32n (dict, key, keylen, volinfo->disperse_count); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.redundancy_count", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->redundancy_count); + keylen = snprintf (key, sizeof (key), "%s%d.redundancy_count", prefix, + count); + ret = dict_set_int32n (dict, key, keylen, volinfo->redundancy_count); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.dist_count", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->dist_leaf_count); + keylen = snprintf (key, sizeof (key), "%s%d.dist_count", prefix, count); + ret = dict_set_int32n (dict, key, keylen, volinfo->dist_leaf_count); if (ret) goto out; @@ -3127,30 +3141,31 @@ glusterd_add_volume_to_dict (glusterd_volinfo_t *volinfo, ret = -1; goto out; } - snprintf (key, sizeof (key), "%s%d.volume_id", prefix, count); - ret = dict_set_dynstr (dict, key, volume_id_str); + keylen = snprintf (key, sizeof (key), "%s%d.volume_id", prefix, + count); + ret = dict_set_dynstrn (dict, key, keylen, volume_id_str); if (ret) goto out; volume_id_str = NULL; - snprintf (key, sizeof (key), "%s%d.username", prefix, count); + keylen = snprintf (key, sizeof (key), "%s%d.username", prefix, count); str = glusterd_auth_get_username (volinfo); if (str) { - ret = dict_set_dynstr (dict, key, gf_strdup (str)); + ret = dict_set_dynstrn (dict, key, keylen, gf_strdup (str)); if (ret) goto out; } - snprintf (key, sizeof (key), "%s%d.password", prefix, count); + keylen = snprintf (key, sizeof (key), "%s%d.password", prefix, count); str = glusterd_auth_get_password (volinfo); if (str) { - ret = dict_set_dynstr (dict, key, gf_strdup (str)); + ret = dict_set_dynstrn (dict, key, keylen, gf_strdup (str)); if (ret) goto out; } - snprintf (key, sizeof (key), "%s%d.rebalance", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->rebal.defrag_cmd); + keylen = snprintf (key, sizeof (key), "%s%d.rebalance", prefix, count); + ret = dict_set_int32n (dict, key, keylen, volinfo->rebal.defrag_cmd); if (ret) goto out; @@ -3160,8 +3175,9 @@ glusterd_add_volume_to_dict (glusterd_volinfo_t *volinfo, ret = -1; goto out; } - snprintf (key, sizeof (key), "%s%d.rebalance-id", prefix, count); - ret = dict_set_dynstr (dict, key, rebalance_id_str); + keylen = snprintf (key, sizeof (key), "%s%d.rebalance-id", prefix, + count); + ret = dict_set_dynstrn (dict, key, keylen, rebalance_id_str); if (ret) goto out; rebalance_id_str = NULL; @@ -3181,8 +3197,9 @@ glusterd_add_volume_to_dict (glusterd_volinfo_t *volinfo, dict_foreach (volinfo->rebal.dict, _add_dict_to_prdict, &ctx); ctx.opt_count--; - snprintf (key, sizeof (key), "volume%d.rebal-dict-count", count); - ret = dict_set_int32 (dict, key, ctx.opt_count); + keylen = snprintf (key, sizeof (key), + "volume%d.rebal-dict-count", count); + ret = dict_set_int32n (dict, key, keylen, ctx.opt_count); if (ret) goto out; } @@ -3197,8 +3214,9 @@ glusterd_add_volume_to_dict (glusterd_volinfo_t *volinfo, dict_foreach (volinfo->dict, _add_dict_to_prdict, &ctx); ctx.opt_count--; - snprintf (key, sizeof (key), "%s%d.opt-count", prefix, count); - ret = dict_set_int32 (dict, key, ctx.opt_count); + keylen = snprintf (key, sizeof (key), "%s%d.opt-count", prefix, + count); + ret = dict_set_int32n (dict, key, keylen, ctx.opt_count); if (ret) goto out; @@ -3212,33 +3230,36 @@ glusterd_add_volume_to_dict (glusterd_volinfo_t *volinfo, dict_foreach (volinfo->gsync_slaves, _add_dict_to_prdict, &ctx); ctx.opt_count--; - snprintf (key, sizeof (key), "%s%d.gsync-count", prefix, count); - ret = dict_set_int32 (dict, key, ctx.opt_count); + keylen = snprintf (key, sizeof (key), "%s%d.gsync-count", prefix, + count); + ret = dict_set_int32n (dict, key, keylen, ctx.opt_count); if (ret) goto out; cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { - snprintf (key, sizeof (key), "%s%d.brick%d.hostname", - prefix, count, i); - ret = dict_set_str (dict, key, brickinfo->hostname); + keylen = snprintf (key, sizeof (key), "%s%d.brick%d.hostname", + prefix, count, i); + ret = dict_set_strn (dict, key, keylen, brickinfo->hostname); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.brick%d.path", + keylen = snprintf (key, sizeof (key), "%s%d.brick%d.path", prefix, count, i); - ret = dict_set_str (dict, key, brickinfo->path); + ret = dict_set_strn (dict, key, keylen, brickinfo->path); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.brick%d.decommissioned", - prefix, count, i); - ret = dict_set_int32 (dict, key, brickinfo->decommissioned); + keylen = snprintf (key, sizeof (key), + "%s%d.brick%d.decommissioned", + prefix, count, i); + ret = dict_set_int32n (dict, key, keylen, + brickinfo->decommissioned); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.brick%d.brick_id", + keylen = snprintf (key, sizeof (key), "%s%d.brick%d.brick_id", prefix, count, i); - ret = dict_set_str (dict, key, brickinfo->brick_id); + ret = dict_set_strn (dict, key, keylen, brickinfo->brick_id); if (ret) goto out; @@ -3260,21 +3281,25 @@ glusterd_add_volume_to_dict (glusterd_volinfo_t *volinfo, /* Add volume op-versions to dict. This prevents volume inconsistencies * in the cluster */ - snprintf (key, sizeof (key), "%s%d.op-version", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->op_version); + keylen = snprintf (key, sizeof (key), "%s%d.op-version", prefix, + count); + ret = dict_set_int32n (dict, key, keylen, volinfo->op_version); if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.client-op-version", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->client_op_version); + keylen = snprintf (key, sizeof (key), "%s%d.client-op-version", prefix, + count); + ret = dict_set_int32n (dict, key, keylen, volinfo->client_op_version); if (ret) goto out; /*Add volume Capability (BD Xlator) to dict*/ - snprintf (key, sizeof (key), "%s%d.caps", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->caps); + keylen = snprintf (key, sizeof (key), "%s%d.caps", prefix, count); + ret = dict_set_int32n (dict, key, keylen, volinfo->caps); - snprintf (key, sizeof (key), "%s%d.quota-xattr-version", prefix, count); - ret = dict_set_int32 (dict, key, volinfo->quota_xattr_version); + keylen = snprintf (key, sizeof (key), "%s%d.quota-xattr-version", + prefix, count); + ret = dict_set_int32n (dict, key, keylen, + volinfo->quota_xattr_version); out: GF_FREE (volume_id_str); GF_FREE (rebalance_id_str); @@ -3343,20 +3368,19 @@ glusterd_vol_add_quota_conf_to_dict (glusterd_volinfo_t *volinfo, dict_t* load, goto out; } - snprintf (key, sizeof(key)-1, "%s%d.gfid-count", prefix, vol_idx); - key[sizeof(key)-1] = '\0'; - ret = dict_set_int32 (load, key, gfid_idx); + ret = snprintf (key, sizeof (key), "%s%d.gfid-count", prefix, + vol_idx); + ret = dict_set_int32n (load, key, ret, gfid_idx); if (ret) goto out; - snprintf (key, sizeof(key)-1, "%s%d.quota-cksum", prefix, vol_idx); - key[sizeof(key)-1] = '\0'; + snprintf (key, sizeof (key), "%s%d.quota-cksum", prefix, + vol_idx); ret = dict_set_uint32 (load, key, volinfo->quota_conf_cksum); if (ret) goto out; - snprintf (key, sizeof(key)-1, "%s%d.quota-version", prefix, vol_idx); - key[sizeof(key)-1] = '\0'; + snprintf (key, sizeof (key), "%s%d.quota-version", prefix, vol_idx); ret = dict_set_uint32 (load, key, volinfo->quota_conf_version); if (ret) goto out; @@ -3402,7 +3426,7 @@ glusterd_add_volumes_to_export_dict (dict_t **peer_data) goto out; } - ret = dict_set_int32 (dict, "count", count); + ret = dict_set_int32n (dict, "count", SLEN ("count"), count); if (ret) goto out; @@ -3413,7 +3437,8 @@ glusterd_add_volumes_to_export_dict (dict_t **peer_data) ctx.val_name = "val"; dict_foreach (priv->opts, _add_dict_to_prdict, &ctx); ctx.opt_count--; - ret = dict_set_int32 (dict, "global-opt-count", ctx.opt_count); + ret = dict_set_int32n (dict, "global-opt-count", + SLEN ("global-opt-count"), ctx.opt_count); if (ret) goto out; @@ -3432,7 +3457,8 @@ glusterd_compare_friend_volume (dict_t *peer_data, int32_t count, { int32_t ret = -1; - char key[512] = ""; + char key[64] = ""; + int keylen; glusterd_volinfo_t *volinfo = NULL; char *volname = NULL; uint32_t cksum = 0; @@ -3448,8 +3474,8 @@ glusterd_compare_friend_volume (dict_t *peer_data, int32_t count, this = THIS; GF_ASSERT (this); - snprintf (key, sizeof (key), "volume%d.name", count); - ret = dict_get_str (peer_data, key, &volname); + keylen = snprintf (key, sizeof (key), "volume%d.name", count); + ret = dict_get_strn (peer_data, key, keylen, &volname); if (ret) goto out; @@ -3467,8 +3493,8 @@ glusterd_compare_friend_volume (dict_t *peer_data, int32_t count, goto out; } - snprintf (key, sizeof (key), "volume%d.version", count); - ret = dict_get_int32 (peer_data, key, &version); + keylen = snprintf (key, sizeof (key), "volume%d.version", count); + ret = dict_get_int32n (peer_data, key, keylen, &version); if (ret) goto out; @@ -3554,12 +3580,12 @@ glusterd_compare_friend_volume (dict_t *peer_data, int32_t count, *status = GLUSTERD_VOL_COMP_SCS; out: - snprintf (key, sizeof (key), "volume%d.update", count); + keylen = snprintf (key, sizeof (key), "volume%d.update", count); if (*status == GLUSTERD_VOL_COMP_UPDATE_REQ) { - ret = dict_set_int32 (peer_data, key, 1); + ret = dict_set_int32n (peer_data, key, keylen, 1); } else { - ret = dict_set_int32 (peer_data, key, 0); + ret = dict_set_int32n (peer_data, key, keylen, 0); } if (*status == GLUSTERD_VOL_COMP_RJT) { gf_event (EVENT_COMPARE_FRIEND_VOLUME_FAILED, "volume=%s", @@ -3575,6 +3601,7 @@ import_prdict_dict (dict_t *peer_data, dict_t *dst_dict, char *key_prefix, char *value_prefix, int opt_count, char *prefix) { char key[512] = ""; + int keylen; int32_t ret = 0; int i = 1; char *opt_key = NULL; @@ -3583,18 +3610,18 @@ import_prdict_dict (dict_t *peer_data, dict_t *dst_dict, char *key_prefix, char msg[2048] = ""; while (i <= opt_count) { - snprintf (key, sizeof (key), "%s.%s%d", - prefix, key_prefix, i); - ret = dict_get_str (peer_data, key, &opt_key); + keylen = snprintf (key, sizeof (key), "%s.%s%d", + prefix, key_prefix, i); + ret = dict_get_strn (peer_data, key, keylen, &opt_key); if (ret) { snprintf (msg, sizeof (msg), "Volume dict key not " "specified"); goto out; } - snprintf (key, sizeof (key), "%s.%s%d", - prefix, value_prefix, i); - ret = dict_get_str (peer_data, key, &opt_val); + keylen = snprintf (key, sizeof (key), "%s.%s%d", + prefix, value_prefix, i); + ret = dict_get_strn (peer_data, key, keylen, &opt_val); if (ret) { snprintf (msg, sizeof (msg), "Volume dict value not " "specified"); @@ -3647,6 +3674,7 @@ glusterd_import_friend_volume_opts (dict_t *peer_data, int count, char *prefix) { char key[512] = ""; + int keylen; int32_t ret = -1; int opt_count = 0; char msg[2048] = ""; @@ -3655,8 +3683,9 @@ glusterd_import_friend_volume_opts (dict_t *peer_data, int count, GF_ASSERT (peer_data); GF_ASSERT (volinfo); - snprintf (key, sizeof (key), "%s%d.opt-count", prefix, count); - ret = dict_get_int32 (peer_data, key, &opt_count); + keylen = snprintf (key, sizeof (key), "%s%d.opt-count", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, &opt_count); if (ret) { snprintf (msg, sizeof (msg), "Volume option count not " "specified for %s", volinfo->volname); @@ -3672,8 +3701,9 @@ glusterd_import_friend_volume_opts (dict_t *peer_data, int count, goto out; } - snprintf (key, sizeof (key), "%s%d.gsync-count", prefix, count); - ret = dict_get_int32 (peer_data, key, &opt_count); + keylen = snprintf (key, sizeof (key), "%s%d.gsync-count", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, &opt_count); if (ret) { snprintf (msg, sizeof (msg), "Gsync count not " "specified for %s", volinfo->volname); @@ -3707,6 +3737,7 @@ glusterd_import_new_brick (dict_t *peer_data, int32_t vol_count, char *prefix) { char key[512] = {0,}; + int keylen; int ret = -1; char *hostname = NULL; char *path = NULL; @@ -3721,29 +3752,29 @@ glusterd_import_new_brick (dict_t *peer_data, int32_t vol_count, GF_ASSERT (brickinfo); GF_ASSERT (prefix); - snprintf (key, sizeof (key), "%s%d.brick%d.hostname", - prefix, vol_count, brick_count); - ret = dict_get_str (peer_data, key, &hostname); + keylen = snprintf (key, sizeof (key), "%s%d.brick%d.hostname", + prefix, vol_count, brick_count); + ret = dict_get_strn (peer_data, key, keylen, &hostname); if (ret) { snprintf (msg, sizeof (msg), "%s missing in payload", key); goto out; } - snprintf (key, sizeof (key), "%s%d.brick%d.path", - prefix, vol_count, brick_count); - ret = dict_get_str (peer_data, key, &path); + keylen = snprintf (key, sizeof (key), "%s%d.brick%d.path", + prefix, vol_count, brick_count); + ret = dict_get_strn (peer_data, key, keylen, &path); if (ret) { snprintf (msg, sizeof (msg), "%s missing in payload", key); goto out; } - snprintf (key, sizeof (key), "%s%d.brick%d.brick_id", - prefix, vol_count, brick_count); - ret = dict_get_str (peer_data, key, &brick_id); + keylen = snprintf (key, sizeof (key), "%s%d.brick%d.brick_id", + prefix, vol_count, brick_count); + ret = dict_get_strn (peer_data, key, keylen, &brick_id); - snprintf (key, sizeof (key), "%s%d.brick%d.decommissioned", - prefix, vol_count, brick_count); - ret = dict_get_int32 (peer_data, key, &decommissioned); + keylen = snprintf (key, sizeof (key), "%s%d.brick%d.decommissioned", + prefix, vol_count, brick_count); + ret = dict_get_int32n (peer_data, key, keylen, &decommissioned); if (ret) { /* For backward compatibility */ ret = 0; @@ -3775,9 +3806,9 @@ glusterd_import_new_brick (dict_t *peer_data, int32_t vol_count, if (ret) goto out; - snprintf (key, sizeof (key), "%s%d.brick%d.uuid", - prefix, vol_count, brick_count); - ret = dict_get_str (peer_data, key, &brick_uuid_str); + keylen = snprintf (key, sizeof (key), "%s%d.brick%d.uuid", + prefix, vol_count, brick_count); + ret = dict_get_strn (peer_data, key, keylen, &brick_uuid_str); if (ret) goto out; gf_uuid_parse (brick_uuid_str, new_brickinfo->uuid); @@ -3848,6 +3879,7 @@ glusterd_import_quota_conf (dict_t *peer_data, int vol_idx, int ret = -1; int fd = -1; char key[PATH_MAX] = ""; + int keylen; char *gfid_str = NULL; uuid_t gfid = {0,}; xlator_t *this = NULL; @@ -3873,23 +3905,21 @@ glusterd_import_quota_conf (dict_t *peer_data, int vol_idx, goto out; } - snprintf (key, sizeof (key)-1, "%s%d.quota-cksum", prefix, vol_idx); - key[sizeof(key)-1] = '\0'; + snprintf (key, sizeof (key), "%s%d.quota-cksum", prefix, vol_idx); ret = dict_get_uint32 (peer_data, key, &new_volinfo->quota_conf_cksum); if (ret) gf_msg_debug (this->name, 0, "Failed to get quota cksum"); - snprintf (key, sizeof (key)-1, "%s%d.quota-version", prefix, vol_idx); - key[sizeof(key)-1] = '\0'; + snprintf (key, sizeof (key), "%s%d.quota-version", prefix, vol_idx); ret = dict_get_uint32 (peer_data, key, &new_volinfo->quota_conf_version); if (ret) gf_msg_debug (this->name, 0, "Failed to get quota " "version"); - snprintf (key, sizeof (key)-1, "%s%d.gfid-count", prefix, vol_idx); - key[sizeof(key)-1] = '\0'; - ret = dict_get_int32 (peer_data, key, &gfid_count); + keylen = snprintf (key, sizeof (key), "%s%d.gfid-count", prefix, + vol_idx); + ret = dict_get_int32n (peer_data, key, keylen, &gfid_count); if (ret) goto out; @@ -3900,9 +3930,9 @@ glusterd_import_quota_conf (dict_t *peer_data, int vol_idx, gfid_idx = 0; for (gfid_idx = 0; gfid_idx < gfid_count; gfid_idx++) { - snprintf (key, sizeof (key)-1, "%s%d.gfid%d", - prefix, vol_idx, gfid_idx); - ret = dict_get_str (peer_data, key, &gfid_str); + keylen = snprintf (key, sizeof (key)-1, "%s%d.gfid%d", + prefix, vol_idx, gfid_idx); + ret = dict_get_strn (peer_data, key, keylen, &gfid_str); if (ret) goto out; @@ -3962,15 +3992,15 @@ gd_import_friend_volume_rebal_dict (dict_t *dict, int count, glusterd_volinfo_t *volinfo) { int ret = -1; - char key[256] = ""; + char key[64] = ""; int dict_count = 0; char prefix[64] = ""; GF_ASSERT (dict); GF_ASSERT (volinfo); - snprintf (key, sizeof (key), "volume%d.rebal-dict-count", count); - ret = dict_get_int32 (dict, key, &dict_count); + ret = snprintf (key, sizeof (key), "volume%d.rebal-dict-count", count); + ret = dict_get_int32n (dict, key, ret, &dict_count); if (ret) { /* Older peers will not have this dict */ ret = 0; @@ -4004,6 +4034,7 @@ glusterd_import_volinfo (dict_t *peer_data, int count, { int ret = -1; char key[256] = ""; + int keylen; char *parent_volname = NULL; char *volname = NULL; glusterd_volinfo_t *new_volinfo = NULL; @@ -4019,8 +4050,8 @@ glusterd_import_volinfo (dict_t *peer_data, int count, GF_ASSERT (volinfo); GF_ASSERT (prefix); - snprintf (key, sizeof (key), "%s%d.name", prefix, count); - ret = dict_get_str (peer_data, key, &volname); + keylen = snprintf (key, sizeof (key), "%s%d.name", prefix, count); + ret = dict_get_strn (peer_data, key, keylen, &volname); if (ret) { snprintf (msg, sizeof (msg), "%s missing in payload", key); goto out; @@ -4046,16 +4077,17 @@ glusterd_import_volinfo (dict_t *peer_data, int count, ret = -1; goto out; } - snprintf (key, sizeof (key), "%s%d.type", prefix, count); - ret = dict_get_int32 (peer_data, key, &new_volinfo->type); + keylen = snprintf (key, sizeof (key), "%s%d.type", prefix, count); + ret = dict_get_int32n (peer_data, key, keylen, &new_volinfo->type); if (ret) { snprintf (msg, sizeof (msg), "%s missing in payload for %s", key, volname); goto out; } - snprintf (key, sizeof (key), "%s%d.parent_volname", prefix, count); - ret = dict_get_str (peer_data, key, &parent_volname); + keylen = snprintf (key, sizeof (key), "%s%d.parent_volname", prefix, + count); + ret = dict_get_strn (peer_data, key, keylen, &parent_volname); if (!ret) { ret = snprintf (new_volinfo->parent_volname, sizeof(new_volinfo->parent_volname), "%s", @@ -4065,32 +4097,36 @@ glusterd_import_volinfo (dict_t *peer_data, int count, goto out; } } - snprintf (key, sizeof (key), "%s%d.brick_count", prefix, count); - ret = dict_get_int32 (peer_data, key, &new_volinfo->brick_count); + keylen = snprintf (key, sizeof (key), "%s%d.brick_count", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->brick_count); if (ret) { snprintf (msg, sizeof (msg), "%s missing in payload for %s", key, volname); goto out; } - snprintf (key, sizeof (key), "%s%d.version", prefix, count); - ret = dict_get_int32 (peer_data, key, &new_volinfo->version); + keylen = snprintf (key, sizeof (key), "%s%d.version", prefix, count); + ret = dict_get_int32n (peer_data, key, keylen, &new_volinfo->version); if (ret) { snprintf (msg, sizeof (msg), "%s missing in payload for %s", key, volname); goto out; } - snprintf (key, sizeof (key), "%s%d.status", prefix, count); - ret = dict_get_int32 (peer_data, key, (int32_t *)&new_volinfo->status); + keylen = snprintf (key, sizeof (key), "%s%d.status", prefix, count); + ret = dict_get_int32n (peer_data, key, keylen, + (int32_t *)&new_volinfo->status); if (ret) { snprintf (msg, sizeof (msg), "%s missing in payload for %s", key, volname); goto out; } - snprintf (key, sizeof (key), "%s%d.sub_count", prefix, count); - ret = dict_get_int32 (peer_data, key, &new_volinfo->sub_count); + keylen = snprintf (key, sizeof (key), "%s%d.sub_count", prefix, count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->sub_count); if (ret) { snprintf (msg, sizeof (msg), "%s missing in payload for %s", key, volname); @@ -4099,8 +4135,10 @@ glusterd_import_volinfo (dict_t *peer_data, int count, /* not having a 'stripe_count' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.stripe_count", prefix, count); - ret = dict_get_int32 (peer_data, key, &new_volinfo->stripe_count); + keylen = snprintf (key, sizeof (key), "%s%d.stripe_count", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->stripe_count); if (ret) gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -4108,8 +4146,10 @@ glusterd_import_volinfo (dict_t *peer_data, int count, /* not having a 'replica_count' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.replica_count", prefix, count); - ret = dict_get_int32 (peer_data, key, &new_volinfo->replica_count); + keylen = snprintf (key, sizeof (key), "%s%d.replica_count", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->replica_count); if (ret) gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -4117,8 +4157,10 @@ glusterd_import_volinfo (dict_t *peer_data, int count, /* not having a 'arbiter_count' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.arbiter_count", prefix, count); - ret = dict_get_int32 (peer_data, key, &new_volinfo->arbiter_count); + keylen = snprintf (key, sizeof (key), "%s%d.arbiter_count", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->arbiter_count); if (ret) gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -4126,8 +4168,10 @@ glusterd_import_volinfo (dict_t *peer_data, int count, /* not having a 'disperse_count' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.disperse_count", prefix, count); - ret = dict_get_int32 (peer_data, key, &new_volinfo->disperse_count); + keylen = snprintf (key, sizeof (key), "%s%d.disperse_count", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->disperse_count); if (ret) gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -4135,8 +4179,10 @@ glusterd_import_volinfo (dict_t *peer_data, int count, /* not having a 'redundancy_count' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.redundancy_count", prefix, count); - ret = dict_get_int32 (peer_data, key, &new_volinfo->redundancy_count); + keylen = snprintf (key, sizeof (key), "%s%d.redundancy_count", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->redundancy_count); if (ret) gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -4144,8 +4190,10 @@ glusterd_import_volinfo (dict_t *peer_data, int count, /* not having a 'dist_count' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.dist_count", prefix, count); - ret = dict_get_int32 (peer_data, key, &new_volinfo->dist_leaf_count); + keylen = snprintf (key, sizeof (key), "%s%d.dist_count", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->dist_leaf_count); if (ret) gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -4153,53 +4201,56 @@ glusterd_import_volinfo (dict_t *peer_data, int count, /* not having a 'hot_brick_count' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.hot_brick_count", prefix, count); - ret = dict_get_int32 (peer_data, key, - &new_volinfo->tier_info.hot_brick_count); + keylen = snprintf (key, sizeof (key), "%s%d.hot_brick_count", prefix, count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->tier_info.hot_brick_count); if (ret) gf_msg_debug (THIS->name, 0, "peer is possibly old version"); /* not having a 'hot_type' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.hot_type", prefix, count); - ret = dict_get_int32 (peer_data, key, - &new_volinfo->tier_info.hot_type); + keylen = snprintf (key, sizeof (key), "%s%d.hot_type", prefix, count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->tier_info.hot_type); if (ret) gf_msg_debug (THIS->name, 0, "peer is possibly old version"); /* not having a 'hot_replica_count' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.hot_replica_count", prefix, count); - ret = dict_get_int32 (peer_data, key, - &new_volinfo->tier_info.hot_replica_count); + keylen = snprintf (key, sizeof (key), "%s%d.hot_replica_count", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->tier_info.hot_replica_count); if (ret) gf_msg_debug (THIS->name, 0, "peer is possibly old version"); /* not having a 'cold_brick_count' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.cold_brick_count", prefix, count); - ret = dict_get_int32 (peer_data, key, - &new_volinfo->tier_info.cold_brick_count); + keylen = snprintf (key, sizeof (key), "%s%d.cold_brick_count", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->tier_info.cold_brick_count); if (ret) gf_msg_debug (THIS->name, 0, "peer is possibly old version"); /* not having a 'cold_type' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.cold_type", prefix, count); - ret = dict_get_int32 (peer_data, key, - &new_volinfo->tier_info.cold_type); + keylen = snprintf (key, sizeof (key), "%s%d.cold_type", prefix, count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->tier_info.cold_type); if (ret) gf_msg_debug (THIS->name, 0, "peer is possibly old version"); /* not having a 'cold_replica_count' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.cold_replica_count", prefix, count); - ret = dict_get_int32 (peer_data, key, + keylen = snprintf (key, sizeof (key), "%s%d.cold_replica_count", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, &new_volinfo->tier_info.cold_replica_count); if (ret) gf_msg_debug (THIS->name, 0, @@ -4207,28 +4258,30 @@ glusterd_import_volinfo (dict_t *peer_data, int count, /* not having a 'cold_disperse_count' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.cold_disperse_count", prefix, count); - ret = dict_get_int32 (peer_data, key, - &new_volinfo->tier_info.cold_disperse_count); + keylen = snprintf (key, sizeof (key), "%s%d.cold_disperse_count", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->tier_info.cold_disperse_count); if (ret) gf_msg_debug (THIS->name, 0, "peer is possibly old version"); /* not having a 'cold_redundancy_count' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.cold_redundancy_count", + keylen = snprintf (key, sizeof (key), "%s%d.cold_redundancy_count", prefix, count); - ret = dict_get_int32 (peer_data, key, - &new_volinfo->tier_info.cold_redundancy_count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->tier_info.cold_redundancy_count); if (ret) gf_msg_debug (THIS->name, 0, "peer is possibly old version"); /* not having a 'cold_dist_count' key is not a error (as peer may be of old version) */ - snprintf (key, sizeof (key), "%s%d.cold_dist_count", prefix, count); - ret = dict_get_int32 (peer_data, key, - &new_volinfo->tier_info.cold_dist_leaf_count); + keylen = snprintf (key, sizeof (key), "%s%d.cold_dist_count", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->tier_info.cold_dist_leaf_count); if (ret) gf_msg_debug (THIS->name, 0, "peer is possibly old version"); @@ -4243,8 +4296,8 @@ glusterd_import_volinfo (dict_t *peer_data, int count, goto out; } - snprintf (key, sizeof (key), "%s%d.volume_id", prefix, count); - ret = dict_get_str (peer_data, key, &volume_id_str); + keylen = snprintf (key, sizeof (key), "%s%d.volume_id", prefix, count); + ret = dict_get_strn (peer_data, key, keylen, &volume_id_str); if (ret) { snprintf (msg, sizeof (msg), "%s missing in payload for %s", key, volname); @@ -4253,16 +4306,16 @@ glusterd_import_volinfo (dict_t *peer_data, int count, gf_uuid_parse (volume_id_str, new_volinfo->volume_id); - snprintf (key, sizeof (key), "%s%d.username", prefix, count); - ret = dict_get_str (peer_data, key, &str); + keylen = snprintf (key, sizeof (key), "%s%d.username", prefix, count); + ret = dict_get_strn (peer_data, key, keylen, &str); if (!ret) { ret = glusterd_auth_set_username (new_volinfo, str); if (ret) goto out; } - snprintf (key, sizeof (key), "%s%d.password", prefix, count); - ret = dict_get_str (peer_data, key, &str); + keylen = snprintf (key, sizeof (key), "%s%d.password", prefix, count); + ret = dict_get_strn (peer_data, key, keylen, &str); if (!ret) { ret = glusterd_auth_set_password (new_volinfo, str); if (ret) @@ -4285,15 +4338,17 @@ glusterd_import_volinfo (dict_t *peer_data, int count, goto out; } - snprintf (key, sizeof (key), "%s%d.rebalance-id", prefix, count); - ret = dict_get_str (peer_data, key, &rebalance_id_str); + keylen = snprintf (key, sizeof (key), "%s%d.rebalance-id", prefix, + count); + ret = dict_get_strn (peer_data, key, keylen, &rebalance_id_str); if (ret) { /* This is not present in older glusterfs versions, * so don't error out */ ret = 0; } else { - gf_uuid_parse (rebalance_id_str, new_volinfo->rebal.rebalance_id); + gf_uuid_parse (rebalance_id_str, + new_volinfo->rebal.rebalance_id); } snprintf (key, sizeof (key), "%s%d.rebalance-op", prefix, count); @@ -4337,12 +4392,14 @@ glusterd_import_volinfo (dict_t *peer_data, int count, * Either both the volume op-versions should be absent or both should be * present. Only one being present is a failure */ - snprintf (key, sizeof (key), "%s%d.op-version", prefix, count); - ret = dict_get_int32 (peer_data, key, &op_version); + keylen = snprintf (key, sizeof (key), "%s%d.op-version", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, &op_version); if (ret) ret = 0; - snprintf (key, sizeof (key), "%s%d.client-op-version", prefix, count); - ret = dict_get_int32 (peer_data, key, &client_op_version); + keylen = snprintf (key, sizeof (key), "%s%d.client-op-version", prefix, + count); + ret = dict_get_int32n (peer_data, key, keylen, &client_op_version); if (ret) ret = 0; @@ -4361,14 +4418,15 @@ glusterd_import_volinfo (dict_t *peer_data, int count, new_volinfo->client_op_version = 1; } - snprintf (key, sizeof (key), "%s%d.caps", prefix, count); + keylen = snprintf (key, sizeof (key), "%s%d.caps", prefix, count); /*This is not present in older glusterfs versions, so ignore ret value*/ - ret = dict_get_int32 (peer_data, key, &new_volinfo->caps); + ret = dict_get_int32n (peer_data, key, keylen, &new_volinfo->caps); - snprintf (key, sizeof (key), "%s%d.quota-xattr-version", prefix, count); + keylen = snprintf (key, sizeof (key), "%s%d.quota-xattr-version", + prefix, count); /*This is not present in older glusterfs versions, so ignore ret value*/ - ret = dict_get_int32 (peer_data, key, - &new_volinfo->quota_xattr_version); + ret = dict_get_int32n (peer_data, key, keylen, + &new_volinfo->quota_xattr_version); ret = glusterd_import_bricks (peer_data, count, new_volinfo, prefix); if (ret) @@ -4666,7 +4724,7 @@ glusterd_import_friend_volume (dict_t *peer_data, int count) glusterd_volinfo_t *new_volinfo = NULL; glusterd_svc_t *svc = NULL; int32_t update = 0; - char key[512] = ""; + char key[64] = ""; GF_ASSERT (peer_data); @@ -4675,8 +4733,8 @@ glusterd_import_friend_volume (dict_t *peer_data, int count) priv = this->private; GF_ASSERT (priv); - snprintf (key, sizeof (key), "volume%d.update", count); - ret = dict_get_int32 (peer_data, key, &update); + ret = snprintf (key, sizeof (key), "volume%d.update", count); + ret = dict_get_int32n (peer_data, key, ret, &update); if (ret || !update) { /* if update is 0 that means the volume is not imported */ goto out; @@ -4780,7 +4838,7 @@ glusterd_import_friend_volumes_synctask (void *opaque) peer_data = (dict_t *)opaque; GF_ASSERT (peer_data); - ret = dict_get_int32 (peer_data, "count", &count); + ret = dict_get_int32n (peer_data, "count", SLEN ("count"), &count); if (ret) goto out; @@ -4824,7 +4882,7 @@ glusterd_import_friend_volumes (dict_t *peer_data) GF_ASSERT (peer_data); - ret = dict_get_int32 (peer_data, "count", &count); + ret = dict_get_int32n (peer_data, "count", SLEN ("count"), &count); if (ret) goto out; @@ -4846,7 +4904,8 @@ glusterd_get_global_server_quorum_ratio (dict_t *opts, double *quorum) int ret = -1; char *quorum_str = NULL; - ret = dict_get_str (opts, GLUSTERD_QUORUM_RATIO_KEY, &quorum_str); + ret = dict_get_strn (opts, GLUSTERD_QUORUM_RATIO_KEY, + SLEN (GLUSTERD_QUORUM_RATIO_KEY), &quorum_str); if (ret) goto out; @@ -4864,7 +4923,8 @@ glusterd_get_global_opt_version (dict_t *opts, uint32_t *version) int ret = -1; char *version_str = NULL; - ret = dict_get_str (opts, GLUSTERD_GLOBAL_OPT_VERSION, &version_str); + ret = dict_get_strn (opts, GLUSTERD_GLOBAL_OPT_VERSION, + SLEN (GLUSTERD_GLOBAL_OPT_VERSION), &version_str); if (ret) goto out; @@ -4911,7 +4971,8 @@ glusterd_import_global_opts (dict_t *friend_data) this = THIS; conf = this->private; - ret = dict_get_int32 (friend_data, "global-opt-count", &count); + ret = dict_get_int32n (friend_data, "global-opt-count", + SLEN ("global-opt-count"), &count); if (ret) { //old version peer ret = 0; @@ -4994,7 +5055,7 @@ glusterd_compare_friend_data (dict_t *peer_data, int32_t *status, goto out; } - ret = dict_get_int32 (peer_data, "count", &count); + ret = dict_get_int32n (peer_data, "count", SLEN ("count"), &count); if (ret) goto out; @@ -5211,7 +5272,8 @@ glusterd_add_node_to_dict (char *server, dict_t *dict, int count, int pid = -1; int port = 0; glusterd_svc_t *svc = NULL; - char key[1024] = ""; + char key[64] = ""; + int keylen; xlator_t *this = NULL; glusterd_conf_t *priv = NULL; @@ -5253,49 +5315,57 @@ glusterd_add_node_to_dict (char *server, dict_t *dict, int count, * when output. */ - snprintf (key, sizeof (key), "brick%d.hostname", count); + keylen = snprintf (key, sizeof (key), "brick%d.hostname", count); if (!strcmp (server, priv->nfs_svc.name)) - ret = dict_set_str (dict, key, "NFS Server"); + ret = dict_set_nstrn (dict, key, keylen, + "NFS Server", SLEN ("NFS Server")); else if (!strcmp (server, priv->shd_svc.name)) - ret = dict_set_str (dict, key, "Self-heal Daemon"); + ret = dict_set_nstrn (dict, key, keylen, + "Self-heal Daemon", + SLEN ("Self-heal Daemon")); else if (!strcmp (server, priv->quotad_svc.name)) - ret = dict_set_str (dict, key, "Quota Daemon"); + ret = dict_set_nstrn (dict, key, keylen, + "Quota Daemon", SLEN ("Quota Daemon")); else if (!strcmp (server, priv->bitd_svc.name)) - ret = dict_set_str (dict, key, "Bitrot Daemon"); + ret = dict_set_nstrn (dict, key, keylen, "Bitrot Daemon", + SLEN ("Bitrot Daemon")); else if (!strcmp (server, priv->scrub_svc.name)) - ret = dict_set_str (dict, key, "Scrubber Daemon"); + ret = dict_set_nstrn (dict, key, keylen, "Scrubber Daemon", + SLEN ("Scrubber Daemon")); if (ret) goto out; - snprintf (key, sizeof (key), "brick%d.path", count); - ret = dict_set_dynstr (dict, key, gf_strdup (uuid_utoa (MY_UUID))); + keylen = snprintf (key, sizeof (key), "brick%d.path", count); + ret = dict_set_dynstrn (dict, key, keylen, + gf_strdup (uuid_utoa (MY_UUID))); if (ret) goto out; - snprintf (key, sizeof (key), "brick%d.port", count); /* Port is available only for the NFS server. * Self-heal daemon doesn't provide any port for access * by entities other than gluster. */ if (!strcmp (server, priv->nfs_svc.name)) { - if (dict_get (vol_opts, "nfs.port")) { - ret = dict_get_int32 (vol_opts, "nfs.port", &port); + if (dict_getn (vol_opts, "nfs.port", SLEN ("nfs.port"))) { + ret = dict_get_int32n (vol_opts, "nfs.port", + SLEN ("nfs.port"), &port); if (ret) goto out; } else port = GF_NFS3_PORT; } - ret = dict_set_int32 (dict, key, port); + keylen = snprintf (key, sizeof (key), "brick%d.port", count); + ret = dict_set_int32n (dict, key, keylen, port); if (ret) goto out; - snprintf (key, sizeof (key), "brick%d.pid", count); - ret = dict_set_int32 (dict, key, pid); + keylen = snprintf (key, sizeof (key), "brick%d.pid", count); + ret = dict_set_int32n (dict, key, keylen, pid); if (ret) goto out; - snprintf (key, sizeof (key), "brick%d.status", count); - ret = dict_set_int32 (dict, key, running); + keylen = snprintf (key, sizeof (key), "brick%d.status", count); + ret = dict_set_int32n (dict, key, keylen, running); if (ret) goto out; @@ -6968,8 +7038,8 @@ glusterd_add_inode_size_to_dict (dict_t *dict, int count) struct fs_info *fs = NULL; static dict_t *cached_fs = NULL; - snprintf (key, sizeof (key), "brick%d.device", count); - ret = dict_get_str (dict, key, &device); + ret = snprintf (key, sizeof (key), "brick%d.device", count); + ret = dict_get_strn (dict, key, ret, &device); if (ret) goto out; @@ -6981,8 +7051,8 @@ glusterd_add_inode_size_to_dict (dict_t *dict, int count) cached_fs = dict_new (); } - snprintf (key, sizeof (key), "brick%d.fs_name", count); - ret = dict_get_str (dict, key, &fs_name); + ret = snprintf (key, sizeof (key), "brick%d.fs_name", count); + ret = dict_get_strn (dict, key, ret, &fs_name); if (ret) goto out; @@ -7312,6 +7382,7 @@ glusterd_add_brick_to_dict (glusterd_volinfo_t *volinfo, int ret = -1; int32_t pid = -1; char key[2048] = ""; + int keylen; char base_key[1024] = ""; char pidfile[PATH_MAX] = ""; xlator_t *this = NULL; @@ -7329,14 +7400,14 @@ glusterd_add_brick_to_dict (glusterd_volinfo_t *volinfo, priv = this->private; snprintf (base_key, sizeof (base_key), "brick%d", count); - snprintf (key, sizeof (key), "%s.hostname", base_key); + keylen = snprintf (key, sizeof (key), "%s.hostname", base_key); - ret = dict_set_str (dict, key, brickinfo->hostname); + ret = dict_set_strn (dict, key, keylen, brickinfo->hostname); if (ret) goto out; - snprintf (key, sizeof (key), "%s.path", base_key); - ret = dict_set_str (dict, key, brickinfo->path); + keylen = snprintf (key, sizeof (key), "%s.path", base_key); + ret = dict_set_strn (dict, key, keylen, brickinfo->path); if (ret) goto out; @@ -7348,19 +7419,20 @@ glusterd_add_brick_to_dict (glusterd_volinfo_t *volinfo, goto out; } - snprintf (key, sizeof (key), "%s.port", base_key); - ret = dict_set_int32 (dict, key, (volinfo->transport_type == - GF_TRANSPORT_RDMA) ? 0 : brickinfo->port); + keylen = snprintf (key, sizeof (key), "%s.port", base_key); + ret = dict_set_int32n (dict, key, keylen, (volinfo->transport_type == + GF_TRANSPORT_RDMA) ? 0 : brickinfo->port); if (ret) goto out; - snprintf (key, sizeof (key), "%s.rdma_port", base_key); + keylen = snprintf (key, sizeof (key), "%s.rdma_port", base_key); if (volinfo->transport_type == GF_TRANSPORT_RDMA) { - ret = dict_set_int32 (dict, key, brickinfo->port); + ret = dict_set_int32n (dict, key, keylen, brickinfo->port); } else if (volinfo->transport_type == GF_TRANSPORT_BOTH_TCP_RDMA) { - ret = dict_set_int32 (dict, key, brickinfo->rdma_port); + ret = dict_set_int32n (dict, key, keylen, + brickinfo->rdma_port); } else - ret = dict_set_int32 (dict, key, 0); + ret = dict_set_int32n (dict, key, keylen, 0); if (ret) goto out; @@ -7389,13 +7461,13 @@ glusterd_add_brick_to_dict (glusterd_volinfo_t *volinfo, } } - snprintf (key, sizeof (key), "%s.pid", base_key); - ret = dict_set_int32 (dict, key, pid); + keylen = snprintf (key, sizeof (key), "%s.pid", base_key); + ret = dict_set_int32n (dict, key, keylen, pid); if (ret) goto out; - snprintf (key, sizeof (key), "%s.status", base_key); - ret = dict_set_int32 (dict, key, brick_online); + keylen = snprintf (key, sizeof (key), "%s.status", base_key); + ret = dict_set_int32n (dict, key, keylen, brick_online); out: if (ret) @@ -7409,7 +7481,8 @@ glusterd_get_all_volnames (dict_t *dict) { int ret = -1; int32_t vol_count = 0; - char key[256] = ""; + char key[64] = ""; + int keylen; glusterd_volinfo_t *entry = NULL; glusterd_conf_t *priv = NULL; @@ -7417,15 +7490,16 @@ glusterd_get_all_volnames (dict_t *dict) GF_ASSERT (priv); cds_list_for_each_entry (entry, &priv->volumes, vol_list) { - snprintf (key, sizeof (key), "vol%d", vol_count); - ret = dict_set_str (dict, key, entry->volname); + keylen = snprintf (key, sizeof (key), "vol%d", vol_count); + ret = dict_set_strn (dict, key, keylen, entry->volname); if (ret) goto out; vol_count++; } - ret = dict_set_int32 (dict, "vol_count", vol_count); + ret = dict_set_int32n (dict, "vol_count", SLEN ("vol_count"), + vol_count); out: if (ret) @@ -7848,28 +7922,29 @@ glusterd_sm_tr_log_transition_add_to_dict (dict_t *dict, int count) { int ret = -1; - char key[512] = ""; + char key[64] = ""; + int keylen; char timestr[64] = ""; char *str = NULL; GF_ASSERT (dict); GF_ASSERT (log); - snprintf (key, sizeof (key), "log%d-old-state", count); + keylen = snprintf (key, sizeof (key), "log%d-old-state", count); str = log->state_name_get (log->transitions[i].old_state); - ret = dict_set_str (dict, key, str); + ret = dict_set_strn (dict, key, keylen, str); if (ret) goto out; - snprintf (key, sizeof (key), "log%d-event", count); + keylen = snprintf (key, sizeof (key), "log%d-event", count); str = log->event_name_get (log->transitions[i].event); - ret = dict_set_str (dict, key, str); + ret = dict_set_strn (dict, key, keylen, str); if (ret) goto out; - snprintf (key, sizeof (key), "log%d-new-state", count); + keylen = snprintf (key, sizeof (key), "log%d-new-state", count); str = log->state_name_get (log->transitions[i].new_state); - ret = dict_set_str (dict, key, str); + ret = dict_set_strn (dict, key, keylen, str); if (ret) goto out; @@ -7895,7 +7970,7 @@ glusterd_sm_tr_log_add_to_dict (dict_t *dict, int start = 0; int end = 0; int index = 0; - char key[256] = {0}; + char key[16] = {0}; glusterd_sm_tr_log_t *log = NULL; int count = 0; @@ -7918,8 +7993,8 @@ glusterd_sm_tr_log_add_to_dict (dict_t *dict, goto out; } - snprintf (key, sizeof (key), "count"); - ret = dict_set_int32 (dict, key, log->count); + ret = snprintf (key, sizeof (key), "count"); + ret = dict_set_int32n (dict, key, ret, log->count); out: gf_msg_debug ("glusterd", 0, "returning %d", ret); @@ -9146,7 +9221,8 @@ glusterd_defrag_info_set (glusterd_volinfo_t *volinfo, dict_t *dict, int cmd, if (is_origin_glusterd (dict)) { ret = glusterd_generate_and_set_task_id(dict, - 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, @@ -9154,8 +9230,9 @@ glusterd_defrag_info_set (glusterd_volinfo_t *volinfo, dict_t *dict, int cmd, goto out; } } - 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 (this->name, GF_LOG_WARNING, 0, GD_MSG_REBALANCE_ID_MISSING, "Missing rebalance-id"); @@ -9273,7 +9350,7 @@ glusterd_validate_volume_id (dict_t *op_dict, glusterd_volinfo_t *volinfo) this = THIS; GF_ASSERT (this); - ret = dict_get_str (op_dict, "vol-id", &volid_str); + ret = dict_get_strn (op_dict, "vol-id", SLEN ("vol-id"), &volid_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -9339,7 +9416,8 @@ glusterd_defrag_volume_status_update (glusterd_volinfo_t *volinfo, gf_msg_trace (this->name, 0, "failed to get lookedup file count"); - ret = dict_get_int32 (rsp_dict, "status", (int32_t *)&status); + ret = dict_get_int32n (rsp_dict, "status", SLEN ("status"), + (int32_t *)&status); if (ret) gf_msg_trace (this->name, 0, "failed to get status"); @@ -9598,10 +9676,10 @@ glusterd_volset_help (dict_t *dict, char **op_errstr) } } - if (dict_get (dict, "help" )) { + if (dict_getn (dict, "help", SLEN ("help") )) { xml_out = _gf_false; - } else if (dict_get (dict, "help-xml" )) { + } else if (dict_getn (dict, "help-xml", SLEN("help-xml") )) { xml_out = _gf_true; #if (HAVE_LIB_XML) ret = 0; @@ -9646,7 +9724,7 @@ glusterd_to_cli (rpcsvc_request_t *req, gf_cli_rsp *arg, struct iovec *payload, op_ret = arg->op_ret; op_errstr = arg->op_errstr; - ret = dict_get_str (dict, "cmd-str", &cmd); + ret = dict_get_strn (dict, "cmd-str", SLEN ("cmd-str"), &cmd); if (ret) gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -9677,7 +9755,8 @@ glusterd_append_gsync_status (dict_t *dst, dict_t *src) int ret = 0; char *stop_msg = NULL; - ret = dict_get_str (src, "gsync-status", &stop_msg); + ret = dict_get_strn (src, "gsync-status", SLEN ("gsync-status"), + &stop_msg); if (ret) { ret = 0; goto out; @@ -9715,11 +9794,13 @@ glusterd_append_status_dicts (dict_t *dst, dict_t *src) if (src == NULL) goto out; - ret = dict_get_int32 (dst, "gsync-count", &dst_count); + ret = dict_get_int32n (dst, "gsync-count", SLEN ("gsync-count"), + &dst_count); if (ret) dst_count = 0; - ret = dict_get_int32 (src, "gsync-count", &src_count); + ret = dict_get_int32n (src, "gsync-count", SLEN ("gsync-count"), + &src_count); if (ret || !src_count) { gf_msg_debug ("glusterd", 0, "Source brick empty"); ret = 0; @@ -9752,7 +9833,8 @@ glusterd_append_status_dicts (dict_t *dst, dict_t *src) } } - ret = dict_set_int32 (dst, "gsync-count", dst_count+src_count); + ret = dict_set_int32n (dst, "gsync-count", SLEN ("gsync-count"), + dst_count+src_count); out: gf_msg_debug ("glusterd", 0, "Returning %d", ret); @@ -9763,7 +9845,8 @@ glusterd_append_status_dicts (dict_t *dst, dict_t *src) int32_t glusterd_aggr_brick_mount_dirs (dict_t *aggr, dict_t *rsp_dict) { - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; char *brick_mount_dir = NULL; int32_t brick_count = -1; int32_t ret = -1; @@ -9775,7 +9858,8 @@ glusterd_aggr_brick_mount_dirs (dict_t *aggr, dict_t *rsp_dict) GF_ASSERT (aggr); GF_ASSERT (rsp_dict); - ret = dict_get_int32 (rsp_dict, "brick_count", &brick_count); + ret = dict_get_int32n (rsp_dict, "brick_count", SLEN ("brick_count"), + &brick_count); if (ret) { gf_msg_debug (this->name, 0, "No brick_count present"); ret = 0; @@ -9784,8 +9868,8 @@ glusterd_aggr_brick_mount_dirs (dict_t *aggr, dict_t *rsp_dict) for (i = 1; i <= brick_count; i++) { brick_mount_dir = NULL; - snprintf (key, sizeof(key), "brick%d.mount_dir", i); - ret = dict_get_str (rsp_dict, key, &brick_mount_dir); + keylen = snprintf (key, sizeof(key), "brick%d.mount_dir", i); + ret = dict_get_strn (rsp_dict, key, keylen, &brick_mount_dir); if (ret) { /* Coz the info will come from a different node */ gf_msg_debug (this->name, 0, @@ -9838,7 +9922,8 @@ glusterd_gsync_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict, char *op_errstr) if (ret) goto out; - ret = dict_get_str (rsp_dict, "conf_path", &conf_path); + ret = dict_get_strn (rsp_dict, "conf_path", SLEN ("conf_path"), + &conf_path); if (!ret && conf_path) { ret = dict_set_dynstr_with_alloc (ctx, "conf_path", conf_path); @@ -9889,13 +9974,15 @@ glusterd_rb_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) } if (rsp_dict) { - ret = dict_get_int32 (rsp_dict, "src-brick-port", &src_port); + ret = dict_get_int32n (rsp_dict, "src-brick-port", + SLEN ("src-brick-port"), &src_port); if (ret == 0) { gf_msg_debug ("glusterd", 0, "src-brick-port=%d found", src_port); } - ret = dict_get_int32 (rsp_dict, "dst-brick-port", &dst_port); + ret = dict_get_int32n (rsp_dict, "dst-brick-port", + SLEN ("dst-brick-port"), &dst_port); if (ret == 0) { gf_msg_debug ("glusterd", 0, "dst-brick-port=%d found", dst_port); @@ -9912,8 +9999,9 @@ glusterd_rb_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) } if (src_port) { - ret = dict_set_int32 (ctx, "src-brick-port", - src_port); + ret = dict_set_int32n (ctx, "src-brick-port", + SLEN ("src-brick-port"), + src_port); if (ret) { gf_msg_debug ("glusterd", 0, "Could not set src-brick"); @@ -9922,8 +10010,9 @@ glusterd_rb_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) } if (dst_port) { - ret = dict_set_int32 (ctx, "dst-brick-port", - dst_port); + ret = dict_set_int32n (ctx, "dst-brick-port", + SLEN ("dst-brick-port"), + dst_port); if (ret) { gf_msg_debug ("glusterd", 0, "Could not set dst-brick"); @@ -9959,6 +10048,7 @@ _profile_volume_add_friend_rsp (dict_t *this, char *key, data_t *value, void *data) { char new_key[264] = ""; + int new_key_len; glusterd_pr_brick_rsp_conv_t *rsp_ctx = NULL; data_t *new_value = NULL; int brick_count = 0; @@ -9970,9 +10060,9 @@ _profile_volume_add_friend_rsp (dict_t *this, char *key, data_t *value, rsp_ctx = data; new_value = data_copy (value); GF_ASSERT (new_value); - snprintf (new_key, sizeof (new_key), "%d%s", - rsp_ctx->count + brick_count, brick_key); - dict_set (rsp_ctx->dict, new_key, new_value); + new_key_len = snprintf (new_key, sizeof (new_key), "%d%s", + rsp_ctx->count + brick_count, brick_key); + dict_setn (rsp_ctx->dict, new_key, new_key_len, new_value); return 0; } @@ -9990,7 +10080,8 @@ glusterd_profile_volume_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) this = THIS; GF_ASSERT (this); - ret = dict_get_int32 (rsp_dict, "count", &brick_count); + ret = dict_get_int32n (rsp_dict, "count", SLEN ("count"), + &brick_count); if (ret) { ret = 0; //no bricks in the rsp goto out; @@ -10006,11 +10097,12 @@ glusterd_profile_volume_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) goto out; } - ret = dict_get_int32 (ctx_dict, "count", &count); + ret = dict_get_int32n (ctx_dict, "count", SLEN ("count"), &count); rsp_ctx.count = count; rsp_ctx.dict = ctx_dict; dict_foreach (rsp_dict, _profile_volume_add_friend_rsp, &rsp_ctx); - ret = dict_set_int32 (ctx_dict, "count", count + brick_count); + ret = dict_set_int32n (ctx_dict, "count", SLEN ("count"), + count + brick_count); out: return ret; } @@ -10097,6 +10189,7 @@ glusterd_volume_status_aggregate_tasks_status (dict_t *ctx_dict, int i = 0; int j = 0; char key[128] = ""; + int keylen; char *task_type = NULL; int local_status = 0; int remote_status = 0; @@ -10109,7 +10202,8 @@ glusterd_volume_status_aggregate_tasks_status (dict_t *ctx_dict, this = THIS; GF_ASSERT (this); - ret = dict_get_int32 (rsp_dict, "tasks", &remote_count); + ret = dict_get_int32n (rsp_dict, "tasks", SLEN ("tasks"), + &remote_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -10119,7 +10213,8 @@ glusterd_volume_status_aggregate_tasks_status (dict_t *ctx_dict, /* Local count will not be present when this is called for the first * time with the origins rsp_dict */ - ret = dict_get_int32 (ctx_dict, "tasks", &local_count); + ret = dict_get_int32n (ctx_dict, "tasks", SLEN ("tasks"), + &local_count); if (ret) { ret = dict_foreach (rsp_dict, glusterd_volume_status_copy_tasks_to_ctx_dict, @@ -10147,8 +10242,8 @@ glusterd_volume_status_aggregate_tasks_status (dict_t *ctx_dict, */ for (i = 0; i < remote_count; i++) { - snprintf (key, sizeof (key), "task%d.type", i); - ret = dict_get_str (rsp_dict, key, &task_type); + keylen = snprintf (key, sizeof (key), "task%d.type", i); + ret = dict_get_strn (rsp_dict, key, keylen, &task_type); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -10165,16 +10260,16 @@ glusterd_volume_status_aggregate_tasks_status (dict_t *ctx_dict, if (!strcmp (task_type, "Replace brick")) continue; - snprintf (key, sizeof (key), "task%d.status", i); - ret = dict_get_int32 (rsp_dict, key, &remote_status); + keylen = snprintf (key, sizeof (key), "task%d.status", i); + ret = dict_get_int32n (rsp_dict, key, keylen, &remote_status); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get task status from rsp dict"); goto out; } - snprintf (key, sizeof (key), "task%d.id", i); - ret = dict_get_str (rsp_dict, key, &remote_task_id); + keylen = snprintf (key, sizeof (key), "task%d.id", i); + ret = dict_get_strn (rsp_dict, key, keylen, &remote_task_id); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -10182,8 +10277,9 @@ glusterd_volume_status_aggregate_tasks_status (dict_t *ctx_dict, goto out; } for (j = 0; j < local_count; j++) { - snprintf (key, sizeof (key), "task%d.id", j); - ret = dict_get_str (ctx_dict, key, &local_task_id); + keylen = snprintf (key, sizeof (key), "task%d.id", j); + ret = dict_get_strn (ctx_dict, key, keylen, + &local_task_id); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -10205,8 +10301,10 @@ glusterd_volume_status_aggregate_tasks_status (dict_t *ctx_dict, continue; } - snprintf (key, sizeof (key), "task%d.status", j); - ret = dict_get_int32 (ctx_dict, key, &local_status); + keylen = snprintf (key, sizeof (key), + "task%d.status", j); + ret = dict_get_int32n (ctx_dict, key, keylen, + &local_status); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -10235,8 +10333,9 @@ glusterd_volume_status_aggregate_tasks_status (dict_t *ctx_dict, [GF_DEFRAG_STATUS_NOT_STARTED] = 5 }; if (rank[remote_status] <= rank[local_status]) - ret = dict_set_int32 (ctx_dict, key, - remote_status); + ret = dict_set_int32n (ctx_dict, key, + keylen, + remote_status); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_TASK_STATUS_UPDATE_FAIL, @@ -10276,7 +10375,8 @@ glusterd_volume_status_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp_dict) int vol_count = -1; int i = 0; dict_t *ctx_dict = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; + int keylen; char *volname = NULL; glusterd_volinfo_t *volinfo = NULL; @@ -10291,25 +10391,29 @@ glusterd_volume_status_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp_dict) } - ret = dict_get_int32 (ctx_dict, "cmd", &cmd); + ret = dict_get_int32n (ctx_dict, "cmd", SLEN ("cmd"), &cmd); if (ret) goto out; if (cmd & GF_CLI_STATUS_ALL && is_origin_glusterd (ctx_dict)) { - ret = dict_get_int32 (rsp_dict, "vol_count", &vol_count); + ret = dict_get_int32n (rsp_dict, "vol_count", + SLEN ("vol_count"), &vol_count); if (ret == 0) { - ret = dict_set_int32 (ctx_dict, "vol_count", - vol_count); + ret = dict_set_int32n (ctx_dict, "vol_count", + SLEN ("vol_count"), vol_count); if (ret) goto out; for (i = 0; i < vol_count; i++) { - snprintf (key, sizeof (key), "vol%d", i); - ret = dict_get_str (rsp_dict, key, &volname); + keylen = snprintf (key, sizeof (key), + "vol%d", i); + ret = dict_get_strn (rsp_dict, key, keylen, + &volname); if (ret) goto out; - ret = dict_set_str (ctx_dict, key, volname); + ret = dict_set_strn (ctx_dict, key, keylen, + volname); if (ret) goto out; } @@ -10323,13 +10427,15 @@ glusterd_volume_status_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp_dict) if ((cmd & GF_CLI_STATUS_TASKS) != 0) goto aggregate_tasks; - ret = dict_get_int32 (rsp_dict, "count", &rsp_node_count); + ret = dict_get_int32n (rsp_dict, "count", SLEN ("count"), + &rsp_node_count); if (ret) { ret = 0; //no bricks in the rsp goto out; } - ret = dict_get_int32 (rsp_dict, "other-count", &rsp_other_count); + ret = dict_get_int32n (rsp_dict, "other-count", SLEN ("other-count"), + &rsp_other_count); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -10337,18 +10443,26 @@ glusterd_volume_status_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp_dict) goto out; } - ret = dict_get_int32 (ctx_dict, "count", &node_count); - ret = dict_get_int32 (ctx_dict, "other-count", &other_count); - if (!dict_get (ctx_dict, "brick-index-max")) { - ret = dict_get_int32 (rsp_dict, "brick-index-max", &brick_index_max); + ret = dict_get_int32n (ctx_dict, "count", SLEN ("count"), + &node_count); + ret = dict_get_int32n (ctx_dict, "other-count",SLEN ("other-count"), + &other_count); + if (!dict_getn (ctx_dict, "brick-index-max", SLEN ("brick-index-max"))) { + ret = dict_get_int32n (rsp_dict, "brick-index-max", + SLEN ("brick-index-max"), + &brick_index_max); if (ret) goto out; - ret = dict_set_int32 (ctx_dict, "brick-index-max", brick_index_max); + ret = dict_set_int32n (ctx_dict, "brick-index-max", + SLEN ("brick-index-max"), + brick_index_max); if (ret) goto out; } else { - ret = dict_get_int32 (ctx_dict, "brick-index-max", &brick_index_max); + ret = dict_get_int32n (ctx_dict, "brick-index-max", + SLEN ("brick-index-max"), + &brick_index_max); if (ret) goto out; } @@ -10360,7 +10474,8 @@ glusterd_volume_status_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp_dict) dict_foreach (rsp_dict, glusterd_volume_status_add_peer_rsp, &rsp_ctx); - ret = dict_set_int32 (ctx_dict, "count", node_count + rsp_node_count); + ret = dict_set_int32n (ctx_dict, "count", SLEN ("count"), + node_count + rsp_node_count); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -10368,8 +10483,8 @@ glusterd_volume_status_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp_dict) goto out; } - ret = dict_set_int32 (ctx_dict, "other-count", - (other_count + rsp_other_count)); + ret = dict_set_int32n (ctx_dict, "other-count", SLEN ("other-count"), + (other_count + rsp_other_count)); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -10377,7 +10492,7 @@ glusterd_volume_status_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp_dict) goto out; } - ret = dict_get_str (ctx_dict, "volname", &volname); + ret = dict_get_strn (ctx_dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -10396,8 +10511,9 @@ glusterd_volume_status_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp_dict) if (volinfo->type == GF_CLUSTER_TYPE_TIER) { - ret = dict_get_int32 (rsp_dict, "hot_brick_count", - &hot_brick_count); + ret = dict_get_int32n (rsp_dict, "hot_brick_count", + SLEN ("hot_brick_count"), + &hot_brick_count); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, @@ -10406,7 +10522,8 @@ glusterd_volume_status_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp_dict) } - ret = dict_get_int32 (rsp_dict, "type", &type); + ret = dict_get_int32n (rsp_dict, "type", SLEN ("type"), + &type); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, @@ -10417,8 +10534,9 @@ glusterd_volume_status_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp_dict) } - ret = dict_set_int32 (ctx_dict, "hot_brick_count", - hot_brick_count); + ret = dict_set_int32n (ctx_dict, "hot_brick_count", + SLEN ("hot_brick_count"), + hot_brick_count); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, @@ -10426,7 +10544,7 @@ glusterd_volume_status_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp_dict) goto out; } - ret = dict_set_int32 (ctx_dict, "type", type); + ret = dict_set_int32n (ctx_dict, "type", SLEN ("type"), type); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, @@ -10458,13 +10576,15 @@ glusterd_max_opversion_use_rsp_dict (dict_t *dst, dict_t *src) GF_VALIDATE_OR_GOTO (THIS->name, dst, out); GF_VALIDATE_OR_GOTO (THIS->name, src, out); - ret = dict_get_int32 (dst, "max-opversion", &max_opversion); + ret = dict_get_int32n (dst, "max-opversion", SLEN ("max-opversion"), + &max_opversion); if (ret) gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Maximum supported op-version not set in destination " "dictionary"); - ret = dict_get_int32 (src, "max-opversion", &src_max_opversion); + ret = dict_get_int32n (src, "max-opversion", SLEN ("max-opversion"), + &src_max_opversion); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get maximum supported op-version from source"); @@ -10474,7 +10594,8 @@ glusterd_max_opversion_use_rsp_dict (dict_t *dst, dict_t *src) if (max_opversion == -1 || src_max_opversion < max_opversion) max_opversion = src_max_opversion; - ret = dict_set_int32 (dst, "max-opversion", max_opversion); + ret = dict_set_int32n (dst, "max-opversion", SLEN ("max-opversion"), + max_opversion); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set max op-version"); @@ -10491,7 +10612,8 @@ glusterd_volume_bitrot_scrub_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) int ret = -1; int j = 0; uint64_t value = 0; - char key[256] = ""; + char key[64] = ""; + int keylen; char *last_scrub_time = NULL; char *scrub_time = NULL; char *volname = NULL; @@ -10516,7 +10638,7 @@ glusterd_volume_bitrot_scrub_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) priv = this->private; GF_ASSERT (priv); - ret = dict_get_str (aggr, "volname", &volname); + ret = dict_get_strn (aggr, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get volume name"); @@ -10530,9 +10652,9 @@ glusterd_volume_bitrot_scrub_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) goto out; } - ret = dict_get_int32 (aggr, "count", &dst_count); + ret = dict_get_int32n (aggr, "count", SLEN ("count"), &dst_count); - ret = dict_get_int32 (rsp_dict, "count", &src_count); + ret = dict_get_int32n (rsp_dict, "count", SLEN ("count"), &src_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "failed to get count value"); @@ -10540,17 +10662,19 @@ glusterd_volume_bitrot_scrub_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) goto out; } - ret = dict_set_int32 (aggr, "count", src_count+dst_count); + ret = dict_set_int32n (aggr, "count", SLEN ("count"), + src_count+dst_count); if (ret) gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set count in dictonary"); - snprintf (key, sizeof (key), "node-uuid-%d", src_count); - ret = dict_get_str (rsp_dict, key, &node_uuid); + keylen = snprintf (key, sizeof (key), "node-uuid-%d", src_count); + ret = dict_get_strn (rsp_dict, key, keylen, &node_uuid); if (!ret) { node_uuid_str = gf_strdup (node_uuid); - snprintf (key, sizeof (key), "node-uuid-%d", src_count+dst_count); - ret = dict_set_dynstr (aggr, key, node_uuid_str); + keylen = snprintf (key, sizeof (key), "node-uuid-%d", + src_count+dst_count); + ret = dict_set_dynstrn (aggr, key, keylen, node_uuid_str); if (ret) { gf_msg_debug (this->name, 0, "failed to set node-uuid"); } @@ -10589,12 +10713,14 @@ glusterd_volume_bitrot_scrub_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) } } - snprintf (key, sizeof (key), "last-scrub-time-%d", src_count); - ret = dict_get_str (rsp_dict, key, &last_scrub_time); + keylen = snprintf (key, sizeof (key), "last-scrub-time-%d", + src_count); + ret = dict_get_strn (rsp_dict, key, keylen, &last_scrub_time); if (!ret) { scrub_time = gf_strdup (last_scrub_time); - snprintf (key, sizeof (key), "last-scrub-time-%d", src_count+dst_count); - ret = dict_set_dynstr (aggr, key, scrub_time); + keylen = snprintf (key, sizeof (key), "last-scrub-time-%d", + src_count+dst_count); + ret = dict_set_dynstrn (aggr, key, keylen, scrub_time); if (ret) { gf_msg_debug (this->name, 0, "Failed to set " "last scrub time value"); @@ -10624,8 +10750,10 @@ glusterd_volume_bitrot_scrub_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) /* Storing all the bad files in the dictionary */ for (j = 0; j < value; j++) { - snprintf (key, sizeof (key), "quarantine-%d-%d", j, src_count); - ret = dict_get_str (rsp_dict, key, &bad_gfid_str); + keylen = snprintf (key, sizeof (key), + "quarantine-%d-%d", j, src_count); + ret = dict_get_strn (rsp_dict, key, keylen, + &bad_gfid_str); if (!ret) { snprintf (key, sizeof (key), "quarantine-%d-%d", j, src_count+dst_count); @@ -10639,7 +10767,8 @@ glusterd_volume_bitrot_scrub_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) } } - ret = dict_get_str (rsp_dict, "bitrot_log_file", &bitd_log); + ret = dict_get_strn (rsp_dict, "bitrot_log_file", + SLEN ("bitrot_log_file"), &bitd_log); if (!ret) { ret = dict_set_dynstr_with_alloc (aggr, "bitrot_log_file", bitd_log); @@ -10650,7 +10779,8 @@ glusterd_volume_bitrot_scrub_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) } } - ret = dict_get_str (rsp_dict, "scrub_log_file", &scrub_log); + ret = dict_get_strn (rsp_dict, "scrub_log_file", + SLEN ("scrub_log_file"), &scrub_log); if (!ret) { ret = dict_set_dynstr_with_alloc (aggr, "scrub_log_file", scrub_log); @@ -10661,7 +10791,8 @@ glusterd_volume_bitrot_scrub_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) } } - ret = dict_get_str (rsp_dict, "features.scrub-freq", &scrub_freq); + ret = dict_get_strn (rsp_dict, "features.scrub-freq", + SLEN ("features.scrub-freq"), &scrub_freq); if (!ret) { ret = dict_set_dynstr_with_alloc (aggr, "features.scrub-freq", scrub_freq); @@ -10672,7 +10803,8 @@ glusterd_volume_bitrot_scrub_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) } } - ret = dict_get_str (rsp_dict, "features.scrub-throttle", &scrub_impact); + ret = dict_get_strn (rsp_dict, "features.scrub-throttle", + SLEN ("features.scrub-throttle"), &scrub_impact); if (!ret) { ret = dict_set_dynstr_with_alloc (aggr, "features.scrub-throttle", @@ -10684,7 +10816,8 @@ glusterd_volume_bitrot_scrub_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) } } - ret = dict_get_str (rsp_dict, "features.scrub", &scrub_state); + ret = dict_get_strn (rsp_dict, "features.scrub", + SLEN ("features.scrub"), &scrub_state); if (!ret) { ret = dict_set_dynstr_with_alloc (aggr, "features.scrub", scrub_state); @@ -10705,7 +10838,8 @@ glusterd_bitrot_volume_node_rsp (dict_t *aggr, dict_t *rsp_dict) { int ret = -1; uint64_t value = 0; - char key[256] = ""; + char key[64] = ""; + int keylen; char buf[1024] = ""; int32_t i = 0; int32_t j = 0; @@ -10727,23 +10861,24 @@ glusterd_bitrot_volume_node_rsp (dict_t *aggr, dict_t *rsp_dict) priv = this->private; GF_ASSERT (priv); - ret = dict_set_str (aggr, "bitrot_log_file", - (priv->bitd_svc.proc.logfile)); + ret = dict_set_strn (aggr, "bitrot_log_file", + SLEN ("bitrot_log_file"), + priv->bitd_svc.proc.logfile); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set bitrot log file location"); goto out; } - ret = dict_set_str (aggr, "scrub_log_file", - (priv->scrub_svc.proc.logfile)); + ret = dict_set_strn (aggr, "scrub_log_file", SLEN ("scrub_log_file"), + priv->scrub_svc.proc.logfile); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set scrubber log file location"); goto out; } - ret = dict_get_str (aggr, "volname", &volname); + ret = dict_get_strn (aggr, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get volume name"); @@ -10757,15 +10892,15 @@ glusterd_bitrot_volume_node_rsp (dict_t *aggr, dict_t *rsp_dict) goto out; } - ret = dict_get_int32 (aggr, "count", &i); + ret = dict_get_int32n (aggr, "count", SLEN ("count"), &i); i++; - ret = dict_set_int32 (aggr, "count", i); + ret = dict_set_int32n (aggr, "count", SLEN ("count"), i); if (ret) gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set count"); - snprintf (buf, 1024, "%s", uuid_utoa (MY_UUID)); + snprintf (buf, sizeof (buf), "%s", uuid_utoa (MY_UUID)); snprintf (key, sizeof (key), "node-uuid-%d", i); ret = dict_set_dynstr_with_alloc (aggr, key, buf); @@ -10773,9 +10908,12 @@ glusterd_bitrot_volume_node_rsp (dict_t *aggr, dict_t *rsp_dict) gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "failed to set node-uuid"); - ret = dict_get_str (volinfo->dict, "features.scrub-freq", &scrub_freq); + ret = dict_get_strn (volinfo->dict, "features.scrub-freq", + SLEN ("features.scrub-freq"), &scrub_freq); if (!ret) { - ret = dict_set_str (aggr, "features.scrub-freq", scrub_freq); + ret = dict_set_strn (aggr, "features.scrub-freq", + SLEN ("features.scrub-freq"), + scrub_freq); if (ret) { gf_msg_debug (this->name, 0, "Failed to set " "scrub-frequency value to dictionary"); @@ -10795,11 +10933,13 @@ glusterd_bitrot_volume_node_rsp (dict_t *aggr, dict_t *rsp_dict) } } - ret = dict_get_str (volinfo->dict, "features.scrub-throttle", - &scrub_impact); + ret = dict_get_strn (volinfo->dict, "features.scrub-throttle", + SLEN ("features.scrub-throttle"), + &scrub_impact); if (!ret) { - ret = dict_set_str (aggr, "features.scrub-throttle", - scrub_impact); + ret = dict_set_strn (aggr, "features.scrub-throttle", + SLEN ("features.scrub-throttle"), + scrub_impact); if (ret) { gf_msg_debug (this->name, 0, "Failed to set " "scrub-throttle value to dictionary"); @@ -10820,9 +10960,11 @@ glusterd_bitrot_volume_node_rsp (dict_t *aggr, dict_t *rsp_dict) } } - ret = dict_get_str (volinfo->dict, "features.scrub", &scrub_state); + ret = dict_get_strn (volinfo->dict, "features.scrub", + SLEN ("features.scrub"), &scrub_state); if (!ret) { - ret = dict_set_str (aggr, "features.scrub", scrub_state); + ret = dict_set_strn (aggr, "features.scrub", + SLEN ("features.scrub"), scrub_state); if (ret) { gf_msg_debug (this->name, 0, "Failed to set " "scrub state value to dictionary"); @@ -10859,12 +11001,14 @@ glusterd_bitrot_volume_node_rsp (dict_t *aggr, dict_t *rsp_dict) } } - ret = dict_get_str (rsp_dict, "last-scrub-time", &last_scrub_time); + ret = dict_get_strn (rsp_dict, "last-scrub-time", + SLEN ("last-scrub-time"), &last_scrub_time); if (!ret) { - snprintf (key, sizeof (key), "last-scrub-time-%d", i); + keylen = snprintf (key, sizeof (key), + "last-scrub-time-%d", i); scrub_time = gf_strdup (last_scrub_time); - ret = dict_set_dynstr (aggr, key, scrub_time); + ret = dict_set_dynstrn (aggr, key, keylen, scrub_time); if (ret) { gf_msg_debug (this->name, 0, "Failed to set " "last scrub time value"); @@ -10892,10 +11036,13 @@ glusterd_bitrot_volume_node_rsp (dict_t *aggr, dict_t *rsp_dict) /* Storing all the bad files in the dictionary */ for (j = 0; j < value; j++) { - snprintf (key, sizeof (key), "quarantine-%d", j); - ret = dict_get_str (rsp_dict, key, &bad_gfid_str); + keylen = snprintf (key, sizeof (key), "quarantine-%d", + j); + ret = dict_get_strn (rsp_dict, key, keylen, + &bad_gfid_str); if (!ret) { - snprintf (key, sizeof (key), "quarantine-%d-%d", j, i); + snprintf (key, sizeof (key), + "quarantine-%d-%d", j, i); ret = dict_set_dynstr_with_alloc (aggr, key, bad_gfid_str); if (ret) { @@ -10914,7 +11061,8 @@ out: int glusterd_volume_rebalance_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) { - char key[256] = ""; + char key[64] = ""; + int keylen; char *node_uuid = NULL; char *node_uuid_str = NULL; char *volname = NULL; @@ -10948,7 +11096,7 @@ glusterd_volume_rebalance_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) } - ret = dict_get_str (ctx_dict, "volname", &volname); + ret = dict_get_strn (ctx_dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -10961,14 +11109,14 @@ glusterd_volume_rebalance_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) if (ret) goto out; - ret = dict_get_int32 (rsp_dict, "count", &index); + ret = dict_get_int32n (rsp_dict, "count", SLEN ("count"), &index); if (ret) gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "failed to get index"); - snprintf (key, sizeof (key), "node-uuid-%d", index); - ret = dict_get_str (rsp_dict, key, &node_uuid); + keylen = snprintf (key, sizeof (key), "node-uuid-%d", index); + ret = dict_get_strn (rsp_dict, key, keylen, &node_uuid); if (!ret) { node_uuid_str = gf_strdup (node_uuid); @@ -10985,9 +11133,11 @@ glusterd_volume_rebalance_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) rcu_read_unlock (); /* Setting the largest index value as the total count. */ - ret = dict_get_int32 (ctx_dict, "count", &count); + ret = dict_get_int32n (ctx_dict, "count", SLEN ("count"), + &count); if (count < current_index) { - ret = dict_set_int32 (ctx_dict, "count", current_index); + ret = dict_set_int32n (ctx_dict, "count", + SLEN ("count"), current_index); if (ret) gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -10995,8 +11145,9 @@ glusterd_volume_rebalance_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) } /* Setting the same index for the node, as is in the peerlist.*/ - snprintf (key, sizeof (key), "node-uuid-%d", current_index); - ret = dict_set_dynstr (ctx_dict, key, node_uuid_str); + keylen = snprintf (key, sizeof (key), "node-uuid-%d", + current_index); + ret = dict_set_dynstrn (ctx_dict, key, keylen, node_uuid_str); if (ret) { gf_msg_debug (THIS->name, 0, "failed to set node-uuid"); @@ -11036,11 +11187,12 @@ glusterd_volume_rebalance_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) } } - snprintf (key, sizeof (key), "status-%d", index); - ret = dict_get_int32 (rsp_dict, key, &value32); + keylen = snprintf (key, sizeof (key), "status-%d", index); + ret = dict_get_int32n (rsp_dict, key, keylen, &value32); if (!ret) { - snprintf (key, sizeof (key), "status-%d", current_index); - ret = dict_set_int32 (ctx_dict, key, value32); + keylen = snprintf (key, sizeof (key), "status-%d", + current_index); + ret = dict_set_int32n (ctx_dict, key, keylen, value32); if (ret) { gf_msg_debug (THIS->name, 0, "failed to set status"); @@ -11119,7 +11271,8 @@ out: int glusterd_volume_tier_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) { - char key[256] = ""; + char key[64] = ""; + int keylen; char *node_uuid = NULL; char *node_uuid_str = NULL; char *volname = NULL; @@ -11148,7 +11301,7 @@ glusterd_volume_tier_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) goto out; } - ret = dict_get_str (ctx_dict, "volname", &volname); + ret = dict_get_strn (ctx_dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -11161,28 +11314,28 @@ glusterd_volume_tier_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) if (ret) goto out; - ret = dict_get_int32 (rsp_dict, "count", &index); + ret = dict_get_int32n (rsp_dict, "count", SLEN ("count"), &index); if (ret) gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "failed to get index"); - snprintf (key, sizeof (key), "node-uuid-%d", index); - ret = dict_get_str (rsp_dict, key, &node_uuid); + keylen = snprintf (key, sizeof (key), "node-uuid-%d", index); + ret = dict_get_strn (rsp_dict, key, keylen, &node_uuid); if (!ret) { node_uuid_str = gf_strdup (node_uuid); } - ret = dict_get_int32 (ctx_dict, "count", &count); + ret = dict_get_int32n (ctx_dict, "count", SLEN ("count"), &count); count++; - ret = dict_set_int32 (ctx_dict, "count", count); + ret = dict_set_int32n (ctx_dict, "count", SLEN ("count"), count); if (ret) gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set count"); - snprintf (key, sizeof (key), "node-uuid-%d", count); - ret = dict_set_dynstr (ctx_dict, key, node_uuid_str); + keylen = snprintf (key, sizeof (key), "node-uuid-%d", count); + ret = dict_set_dynstrn (ctx_dict, key, keylen, node_uuid_str); if (ret) { gf_msg_debug (this->name, 0, "failed to set node-uuid"); @@ -11221,11 +11374,11 @@ glusterd_volume_tier_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) } } - snprintf (key, sizeof (key), "status-%d", index); - ret = dict_get_int32 (rsp_dict, key, &value32); + keylen = snprintf (key, sizeof (key), "status-%d", index); + ret = dict_get_int32n (rsp_dict, key, keylen, &value32); if (!ret) { - snprintf (key, sizeof (key), "status-%d", count); - ret = dict_set_int32 (ctx_dict, key, value32); + keylen = snprintf (key, sizeof (key), "status-%d", count); + ret = dict_set_int32n (ctx_dict, key, keylen, value32); if (ret) { gf_msg_debug (this->name, 0, "failed to set status"); @@ -11296,14 +11449,16 @@ glusterd_volume_tier_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict) } } - ret = dict_get_str (rsp_dict, GF_REMOVE_BRICK_TID_KEY, - &task_id_str); + ret = dict_get_strn (rsp_dict, GF_REMOVE_BRICK_TID_KEY, + SLEN (GF_REMOVE_BRICK_TID_KEY), + &task_id_str); if (ret) { gf_msg_debug (this->name, errno, "Missing remove-brick-id"); } else { - ret = dict_set_str (ctx_dict, GF_REMOVE_BRICK_TID_KEY, - task_id_str); + ret = dict_set_strn (ctx_dict, GF_REMOVE_BRICK_TID_KEY, + SLEN (GF_REMOVE_BRICK_TID_KEY), + task_id_str); if (ret) gf_msg_debug (this->name, errno, "Failed to set remove brick task ID"); @@ -11318,11 +11473,11 @@ out: int glusterd_sys_exec_output_rsp_dict (dict_t *dst, dict_t *src) { - char output_name[PATH_MAX] = ""; + char output_name[64] = ""; char *output = NULL; int ret = 0; int i = 0; - int len = 0; + int keylen; int src_output_count = 0; int dst_output_count = 0; @@ -11334,9 +11489,11 @@ glusterd_sys_exec_output_rsp_dict (dict_t *dst, dict_t *src) goto out; } - ret = dict_get_int32 (dst, "output_count", &dst_output_count); + ret = dict_get_int32n (dst, "output_count", SLEN ("output_count"), + &dst_output_count); - ret = dict_get_int32 (src, "output_count", &src_output_count); + ret = dict_get_int32n (src, "output_count", SLEN ("output_count"), + &src_output_count); if (ret) { gf_msg_debug ("glusterd", 0, "No output from source"); ret = 0; @@ -11344,13 +11501,13 @@ glusterd_sys_exec_output_rsp_dict (dict_t *dst, dict_t *src) } for (i = 1; i <= src_output_count; i++) { - len = snprintf (output_name, sizeof (output_name), - "output_%d", i); - if (len <= 0 || len >= sizeof (output_name)) { + keylen = snprintf (output_name, sizeof(output_name), + "output_%d", i); + if (keylen <= 0 || keylen >= sizeof (output_name)) { ret = -1; goto out; } - ret = dict_get_str (src, output_name, &output); + ret = dict_get_strn (src, output_name, keylen, &output); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -11359,13 +11516,15 @@ glusterd_sys_exec_output_rsp_dict (dict_t *dst, dict_t *src) goto out; } - len = snprintf (output_name, sizeof (output_name), - "output_%d", i+dst_output_count); - if (len <= 0 || len >= sizeof (output_name)) { + keylen = snprintf (output_name, sizeof(output_name), + "output_%d", i+dst_output_count); + if (keylen <= 0 || keylen >= sizeof (output_name)) { ret = -1; goto out; } - ret = dict_set_dynstr (dst, output_name, gf_strdup (output)); + + ret = dict_set_dynstrn (dst, output_name, keylen, + gf_strdup (output)); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -11375,7 +11534,7 @@ glusterd_sys_exec_output_rsp_dict (dict_t *dst, dict_t *src) } } - ret = dict_set_int32 (dst, "output_count", + ret = dict_set_int32n (dst, "output_count", SLEN ("output_count"), dst_output_count+src_output_count); out: gf_msg_debug ("glusterd", 0, "Returning %d", ret); @@ -11446,14 +11605,16 @@ _profile_volume_add_brick_rsp (dict_t *this, char *key, data_t *value, void *data) { char new_key[256] = ""; + int keylen; glusterd_pr_brick_rsp_conv_t *rsp_ctx = NULL; data_t *new_value = NULL; rsp_ctx = data; new_value = data_copy (value); GF_ASSERT (new_value); - snprintf (new_key, sizeof (new_key), "%d-%s", rsp_ctx->count, key); - dict_set (rsp_ctx->dict, new_key, new_value); + keylen = snprintf (new_key, sizeof (new_key), "%d-%s", + rsp_ctx->count, key); + dict_setn (rsp_ctx->dict, new_key, keylen, new_value); return 0; } @@ -11466,14 +11627,15 @@ glusterd_volume_quota_copy_to_op_ctx_dict (dict_t *dict, dict_t *rsp_dict) int rsp_dict_count = 0; char *uuid_str = NULL; char *uuid_str_dup = NULL; - char key[256] = ""; + char key[64] = ""; + int keylen; xlator_t *this = NULL; int type = GF_QUOTA_OPTION_TYPE_NONE; this = THIS; GF_ASSERT (this); - ret = dict_get_int32 (dict, "type", &type); + ret = dict_get_int32n (dict, "type", SLEN ("type"), &type); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -11490,7 +11652,8 @@ glusterd_volume_quota_copy_to_op_ctx_dict (dict_t *dict, dict_t *rsp_dict) goto out; } - ret = dict_get_int32 (rsp_dict, "count", &rsp_dict_count); + ret = dict_get_int32n (rsp_dict, "count", SLEN ("count"), + &rsp_dict_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -11499,7 +11662,7 @@ glusterd_volume_quota_copy_to_op_ctx_dict (dict_t *dict, dict_t *rsp_dict) goto out; } - ret = dict_get_int32 (dict, "count", &count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &count); if (ret) /* The key "count" is absent in op_ctx when this function is * called after self-staging on the originator. This must not @@ -11510,9 +11673,8 @@ glusterd_volume_quota_copy_to_op_ctx_dict (dict_t *dict, dict_t *rsp_dict) " copied from rsp_dict into op_ctx"); for (i = 0; i < rsp_dict_count; i++) { - snprintf (key, sizeof (key), "gfid%d", i); - - ret = dict_get_str (rsp_dict, key, &uuid_str); + keylen = snprintf (key, sizeof (key), "gfid%d", i); + ret = dict_get_strn (rsp_dict, key, keylen, &uuid_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -11521,15 +11683,14 @@ glusterd_volume_quota_copy_to_op_ctx_dict (dict_t *dict, dict_t *rsp_dict) goto out; } - snprintf (key, sizeof (key), "gfid%d", i + count); - uuid_str_dup = gf_strdup (uuid_str); if (!uuid_str_dup) { ret = -1; goto out; } - ret = dict_set_dynstr (dict, key, uuid_str_dup); + keylen = snprintf (key, sizeof (key), "gfid%d", i + count); + ret = dict_set_dynstrn (dict, key, keylen, uuid_str_dup); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -11540,7 +11701,8 @@ glusterd_volume_quota_copy_to_op_ctx_dict (dict_t *dict, dict_t *rsp_dict) } } - ret = dict_set_int32 (dict, "count", rsp_dict_count + count); + ret = dict_set_int32n (dict, "count", SLEN ("count"), + rsp_dict_count + count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -11562,7 +11724,8 @@ glusterd_profile_volume_brick_rsp (void *pending_entry, glusterd_pr_brick_rsp_conv_t rsp_ctx = {0}; int32_t count = 0; char brick[PATH_MAX+1024] = ""; - char key[256] = ""; + char key[64] = ""; + int keylen; char *full_brick = NULL; glusterd_brickinfo_t *brickinfo = NULL; xlator_t *this = NULL; @@ -11578,13 +11741,12 @@ glusterd_profile_volume_brick_rsp (void *pending_entry, priv = this->private; GF_ASSERT (priv); - ret = dict_get_int32 (op_ctx, "count", &count); + ret = dict_get_int32n (op_ctx, "count", SLEN ("count"), &count); if (ret) { count = 1; } else { count++; } - snprintf (key, sizeof (key), "%d-brick", count); if (type == GD_NODE_BRICK) { brickinfo = pending_entry; snprintf (brick, sizeof (brick), "%s:%s", brickinfo->hostname, @@ -11594,12 +11756,13 @@ glusterd_profile_volume_brick_rsp (void *pending_entry, } full_brick = gf_strdup (brick); GF_ASSERT (full_brick); - ret = dict_set_dynstr (op_ctx, key, full_brick); + keylen = snprintf (key, sizeof (key), "%d-brick", count); + ret = dict_set_dynstrn (op_ctx, key, keylen, full_brick); rsp_ctx.count = count; rsp_ctx.dict = op_ctx; dict_foreach (rsp_dict, _profile_volume_add_brick_rsp, &rsp_ctx); - ret = dict_set_int32 (op_ctx, "count", count); + ret = dict_set_int32n (op_ctx, "count", SLEN ("count"), count); return ret; } @@ -11662,8 +11825,9 @@ _heal_volume_add_shd_rsp (dict_t *this, char *key, data_t *value, void *data) goto out; } new_value = data_copy (value); - snprintf (new_key, sizeof (new_key), "%d%s", brick_id, rxl_child_end); - dict_set (rsp_ctx->dict, new_key, new_value); + int_len = snprintf (new_key, sizeof (new_key), "%d%s", brick_id, + rxl_child_end); + dict_setn (rsp_ctx->dict, new_key, int_len, new_value); out: return 0; @@ -11735,9 +11899,9 @@ _heal_volume_add_shd_rsp_of_statistics (dict_t *this, char *key, data_t goto out; new_value = data_copy (value); - snprintf (new_key, sizeof (new_key), "%s-%d%s", key_begin_string, - brick_id, rxl_child_end); - dict_set (rsp_ctx->dict, new_key, new_value); + int_len = snprintf (new_key, sizeof (new_key), "%s-%d%s", + key_begin_string, brick_id, rxl_child_end); + dict_setn (rsp_ctx->dict, new_key, int_len, new_value); out: return 0; @@ -11758,7 +11922,7 @@ glusterd_heal_volume_brick_rsp (dict_t *req_dict, dict_t *rsp_dict, GF_ASSERT (op_ctx); GF_ASSERT (op_errstr); - ret = dict_get_str (req_dict, "volname", &volname); + ret = dict_get_strn (req_dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -11766,7 +11930,8 @@ glusterd_heal_volume_brick_rsp (dict_t *req_dict, dict_t *rsp_dict, goto out; } - ret = dict_get_int32 (req_dict, "heal-op", &heal_op); + ret = dict_get_int32n (req_dict, "heal-op", SLEN ("heal-op"), + &heal_op); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -11799,13 +11964,15 @@ _status_volume_add_brick_rsp (dict_t *this, char *key, data_t *value, void *data) { char new_key[256] = ""; + int keylen; data_t *new_value = 0; glusterd_pr_brick_rsp_conv_t *rsp_ctx = NULL; rsp_ctx = data; new_value = data_copy (value); - snprintf (new_key, sizeof (new_key), "brick%d.%s", rsp_ctx->count, key); - dict_set (rsp_ctx->dict, new_key, new_value); + keylen = snprintf (new_key, sizeof (new_key), "brick%d.%s", + rsp_ctx->count, key); + dict_setn (rsp_ctx->dict, new_key, keylen, new_value); return 0; } @@ -11823,25 +11990,25 @@ glusterd_status_volume_brick_rsp (dict_t *rsp_dict, dict_t *op_ctx, GF_ASSERT (op_ctx); GF_ASSERT (op_errstr); - ret = dict_get_int32 (op_ctx, "count", &count); + ret = dict_get_int32n (op_ctx, "count", SLEN ("count"), &count); if (ret) { count = 0; } else { count++; } - ret = dict_get_int32 (rsp_dict, "index", &index); + ret = dict_get_int32n (rsp_dict, "index", SLEN ("index"), &index); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Couldn't get node index"); goto out; } - dict_del (rsp_dict, "index"); + dict_deln (rsp_dict, "index", SLEN ("index")); rsp_ctx.count = index; rsp_ctx.dict = op_ctx; dict_foreach (rsp_dict, _status_volume_add_brick_rsp, &rsp_ctx); - ret = dict_set_int32 (op_ctx, "count", count); + ret = dict_set_int32n (op_ctx, "count", SLEN ("count"), count); out: return ret; @@ -11863,19 +12030,21 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, int32_t snapd_count = 0; int32_t client_count = 0; int i = 0; - char key[256] = ""; + char key[64] = ""; GF_ASSERT (rsp_dict); GF_ASSERT (op_ctx); GF_ASSERT (op_errstr); - ret = dict_get_int32 (rsp_dict, "clientcount", &client_count); + ret = dict_get_int32n (rsp_dict, "clientcount", SLEN ("clientcount"), + &client_count); if (ret) { gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, "Couldn't get node index"); } - ret = dict_set_int32 (op_ctx, "client-count", client_count); + ret = dict_set_int32n (op_ctx, "client-count", SLEN ("client-count"), + client_count); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -11884,8 +12053,8 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, } for (i = 0; i < client_count; i++) { count = 0; - snprintf (key, sizeof (key), "client%d.name", i); - ret = dict_get_str (rsp_dict, key, &process); + ret = snprintf (key, sizeof (key), "client%d.name", i); + ret = dict_get_strn (rsp_dict, key, ret, &process); if (ret) { gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -11899,8 +12068,8 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, "Couldn't set client name"); } if (!strncmp(process, "fuse", 4)) { - ret = dict_get_int32 (op_ctx, "fuse-count", - &count); + ret = dict_get_int32n (op_ctx, "fuse-count", + SLEN ("fuse-count"), &count); if (ret) { gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -11909,8 +12078,8 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, fuse_count++; continue; } else if (!strncmp(process, "gfapi", 5)) { - ret = dict_get_int32 (op_ctx, "gfapi-count", - &count); + ret = dict_get_int32n (op_ctx, "gfapi-count", + SLEN ("gfapi-count"), &count); if (ret) { gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -11920,8 +12089,8 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, continue; } else if (!strcmp(process, "tierd")) { - ret = dict_get_int32 (op_ctx, "tierd-count", - &count); + ret = dict_get_int32n (op_ctx, "tierd-count", + SLEN ("tierd-count"), &count); if (ret) { gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -11930,8 +12099,9 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, tierd_count++; continue; } else if (!strcmp(process, "rebalance")) { - ret = dict_get_int32 (op_ctx, "rebalance-count", - &count); + ret = dict_get_int32n (op_ctx, "rebalance-count", + SLEN ("rebalance-count"), + &count); if (ret) { gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -11940,8 +12110,9 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, rebalance_count++; continue; } else if (!strcmp(process, "glustershd")) { - ret = dict_get_int32 (op_ctx, - "glustershd-count", &count); + ret = dict_get_int32n (op_ctx, "glustershd-count", + SLEN ("glustershd-count"), + &count); if (ret) { gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -11950,8 +12121,8 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, glustershd_count++; continue; } else if (!strcmp(process, "quotad")) { - ret = dict_get_int32 (op_ctx, "quotad-count", - &count); + ret = dict_get_int32n (op_ctx, "quotad-count", + SLEN ("quotad-count"), &count); if (ret) { gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -11960,8 +12131,8 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, quotad_count++; continue; } else if (!strcmp(process, "snapd")) { - ret = dict_get_int32 (op_ctx, "snapd-count", - &count); + ret = dict_get_int32n (op_ctx, "snapd-count", + SLEN ("snapd-count"), &count); if (ret) { gf_msg (THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -11973,8 +12144,8 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, } if (fuse_count) { - ret = dict_set_int32 (op_ctx, "fuse-count", - fuse_count); + ret = dict_set_int32n (op_ctx, "fuse-count", + SLEN ("fuse-count"), fuse_count); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -11983,8 +12154,8 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, } } if (gfapi_count) { - ret = dict_set_int32 (op_ctx, "gfapi-count", - gfapi_count); + ret = dict_set_int32n (op_ctx, "gfapi-count", + SLEN ("gfapi-count"), gfapi_count); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -11993,8 +12164,8 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, } } if (tierd_count) { - ret = dict_set_int32 (op_ctx, "tierd-count", - tierd_count); + ret = dict_set_int32n (op_ctx, "tierd-count", + SLEN ("tierd-count"), tierd_count); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -12003,8 +12174,9 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, } } if (rebalance_count) { - ret = dict_set_int32 (op_ctx, "rebalance-count", - rebalance_count); + ret = dict_set_int32n (op_ctx, "rebalance-count", + SLEN ("rebalance-count"), + rebalance_count); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -12013,8 +12185,9 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, } } if (glustershd_count) { - ret = dict_set_int32 (op_ctx, "glustershd-count", - glustershd_count); + ret = dict_set_int32n (op_ctx, "glustershd-count", + SLEN ("glustershd-count"), + glustershd_count); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -12023,8 +12196,8 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, } } if (quotad_count) { - ret = dict_set_int32 (op_ctx, "quotad-count", - quotad_count); + ret = dict_set_int32n (op_ctx, "quotad-count", + SLEN ("quotad-count"), quotad_count); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -12033,8 +12206,8 @@ glusterd_status_volume_client_list (dict_t *rsp_dict, dict_t *op_ctx, } } if (snapd_count) { - ret = dict_set_int32 (op_ctx, "snapd-count", - snapd_count); + ret = dict_set_int32n (op_ctx, "snapd-count", + SLEN ("snapd-count"), snapd_count); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -12051,7 +12224,8 @@ int glusterd_tier_or_rebalance_rsp (dict_t *op_ctx, glusterd_rebalance_t *index, int32_t i) { int ret = 0; - char key[256] = ""; + char key[64] = ""; + int keylen; snprintf (key, sizeof (key), "files-%d", i); ret = dict_set_uint64 (op_ctx, key, index->rebalance_files); @@ -12074,8 +12248,8 @@ glusterd_tier_or_rebalance_rsp (dict_t *op_ctx, glusterd_rebalance_t *index, int GD_MSG_DICT_SET_FAILED, "failed to set lookedup file count"); - snprintf (key, sizeof (key), "status-%d", i); - ret = dict_set_int32 (op_ctx, key, index->defrag_status); + keylen = snprintf (key, sizeof (key), "status-%d", i); + ret = dict_set_int32n (op_ctx, key, keylen, index->defrag_status); if (ret) gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -12112,7 +12286,8 @@ glusterd_defrag_volume_node_rsp (dict_t *req_dict, dict_t *rsp_dict, int ret = 0; char *volname = NULL; glusterd_volinfo_t *volinfo = NULL; - char key[256] = ""; + char key[64] = ""; + int keylen; int32_t i = 0; char buf[1024] = ""; char *node_str = NULL; @@ -12120,7 +12295,7 @@ glusterd_defrag_volume_node_rsp (dict_t *req_dict, dict_t *rsp_dict, GF_ASSERT (req_dict); - ret = dict_get_str (req_dict, "volname", &volname); + ret = dict_get_strn (req_dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -12130,7 +12305,8 @@ glusterd_defrag_volume_node_rsp (dict_t *req_dict, dict_t *rsp_dict, ret = glusterd_volinfo_find (volname, &volinfo); - ret = dict_get_int32 (req_dict, "rebalance-command", &cmd); + ret = dict_get_int32n (req_dict, "rebalance-command", + SLEN ("rebalance-command"), &cmd); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, "Unable to get the cmd"); @@ -12148,10 +12324,10 @@ glusterd_defrag_volume_node_rsp (dict_t *req_dict, dict_t *rsp_dict, goto out; } - ret = dict_get_int32 (op_ctx, "count", &i); + ret = dict_get_int32n (op_ctx, "count", SLEN ("count"), &i); i++; - ret = dict_set_int32 (op_ctx, "count", i); + ret = dict_set_int32n (op_ctx, "count", SLEN ("count"), i); if (ret) gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -12160,8 +12336,8 @@ glusterd_defrag_volume_node_rsp (dict_t *req_dict, dict_t *rsp_dict, snprintf (buf, sizeof (buf), "%s", uuid_utoa (MY_UUID)); node_str = gf_strdup (buf); - snprintf (key, sizeof (key), "node-uuid-%d", i); - ret = dict_set_dynstr (op_ctx, key, node_str); + keylen = snprintf (key, sizeof (key), "node-uuid-%d", i); + ret = dict_set_dynstrn (op_ctx, key, keylen, node_str); if (ret) gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -12213,7 +12389,7 @@ glusterd_handle_node_rsp (dict_t *req_dict, void *pending_entry, op_errstr, type); break; case GD_OP_STATUS_VOLUME: - ret = dict_get_int32 (req_dict, "cmd", &cmd); + ret = dict_get_int32n (req_dict, "cmd", SLEN ("cmd"), &cmd); if (!ret && (cmd & GF_CLI_STATUS_CLIENT_LIST)) { ret = glusterd_status_volume_client_list (rsp_dict, op_ctx, op_errstr); @@ -12308,7 +12484,7 @@ out: } int -glusterd_generate_and_set_task_id (dict_t *dict, char *key) +glusterd_generate_and_set_task_id (dict_t *dict, char *key, const int keylen) { int ret = -1; uuid_t task_id = {0,}; @@ -12327,7 +12503,7 @@ glusterd_generate_and_set_task_id (dict_t *dict, char *key) goto out; } - ret = dict_set_dynstr (dict, key, uuid_str); + ret = dict_set_dynstrn (dict, key, keylen, uuid_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set %s in dict", @@ -12345,7 +12521,8 @@ out: } int -glusterd_copy_uuid_to_dict (uuid_t uuid, dict_t *dict, char *key) +glusterd_copy_uuid_to_dict (uuid_t uuid, dict_t *dict, char *key, + const int keylen) { int ret = -1; char tmp_str[40] = ""; @@ -12359,7 +12536,7 @@ glusterd_copy_uuid_to_dict (uuid_t uuid, dict_t *dict, char *key) if (!task_id_str) return -1; - ret = dict_set_dynstr (dict, key, task_id_str); + ret = dict_set_dynstrn (dict, key, keylen, task_id_str); if (ret) { GF_FREE (task_id_str); gf_msg (THIS->name, GF_LOG_ERROR, 0, @@ -12529,7 +12706,8 @@ gd_should_i_start_rebalance (glusterd_volinfo_t *volinfo) { glusterd_brickinfo_t *brick = NULL; int count = 0; int i = 0; - char key[1023] = ""; + char key[64] = ""; + int keylen; char *brickname = NULL; @@ -12543,13 +12721,14 @@ gd_should_i_start_rebalance (glusterd_volinfo_t *volinfo) { } break; case GD_OP_REMOVE_BRICK: - ret = dict_get_int32 (volinfo->rebal.dict, "count", &count); + ret = dict_get_int32n (volinfo->rebal.dict, "count", + SLEN ("count"), &count); if (ret) { goto out; } for (i = 1; i <= count; i++) { - snprintf (key, sizeof (key), "brick%d", i); - ret = dict_get_str (volinfo->rebal.dict, key, + keylen = snprintf (key, sizeof (key), "brick%d", i); + ret = dict_get_strn (volinfo->rebal.dict, key, keylen, &brickname); if (ret) goto out; @@ -12619,7 +12798,8 @@ glusterd_validate_and_set_gfid (dict_t *op_ctx, dict_t *req_dict, uuid_t uuid1 = {0}; uuid_t uuid2 = {0,}; char *path = NULL; - char key[256] = ""; + char key[64] = ""; + int keylen; char *uuid1_str = NULL; char *uuid1_str_dup = NULL; char *uuid2_str = NULL; @@ -12628,7 +12808,7 @@ glusterd_validate_and_set_gfid (dict_t *op_ctx, dict_t *req_dict, this = THIS; GF_ASSERT (this); - ret = dict_get_int32 (op_ctx, "type", &op_code); + ret = dict_get_int32n (op_ctx, "type", SLEN ("type"), &op_code); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -12644,7 +12824,7 @@ glusterd_validate_and_set_gfid (dict_t *op_ctx, dict_t *req_dict, goto out; } - ret = dict_get_str (op_ctx, "path", &path); + ret = dict_get_strn (op_ctx, "path", SLEN ("path"), &path); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -12652,7 +12832,7 @@ glusterd_validate_and_set_gfid (dict_t *op_ctx, dict_t *req_dict, goto out; } - ret = dict_get_int32 (op_ctx, "count", &count); + ret = dict_get_int32n (op_ctx, "count", SLEN ("count"), &count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -12679,9 +12859,9 @@ glusterd_validate_and_set_gfid (dict_t *op_ctx, dict_t *req_dict, goto out; } - snprintf (key, sizeof (key) - 1, "gfid%d", 0); + keylen = snprintf (key, sizeof (key), "gfid%d", 0); - ret = dict_get_str (op_ctx, key, &uuid1_str); + ret = dict_get_strn (op_ctx, key, keylen, &uuid1_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -12693,9 +12873,9 @@ glusterd_validate_and_set_gfid (dict_t *op_ctx, dict_t *req_dict, gf_uuid_parse (uuid1_str, uuid1); for (i = 1; i < count; i++) { - snprintf (key, sizeof (key)-1, "gfid%d", i); + keylen = snprintf (key, sizeof (key), "gfid%d", i); - ret = dict_get_str (op_ctx, key, &uuid2_str); + ret = dict_get_strn (op_ctx, key, keylen, &uuid2_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -12722,7 +12902,8 @@ glusterd_validate_and_set_gfid (dict_t *op_ctx, dict_t *req_dict, goto out; } - ret = dict_set_dynstr (req_dict, "gfid", uuid1_str_dup); + ret = dict_set_dynstrn (req_dict, "gfid", SLEN ("gfid"), + uuid1_str_dup); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -13164,11 +13345,13 @@ glusterd_get_global_max_op_version (rpcsvc_request_t *req, dict_t *ctx, int ret = -1; char *def_val = NULL; char dict_key[50] = ""; + int keylen; ret = glusterd_mgmt_v3_initiate_all_phases (req, GD_OP_MAX_OPVERSION, ctx); - ret = dict_get_str (ctx, "max-opversion", &def_val); + ret = dict_get_strn (ctx, "max-opversion", + SLEN ("max-opversion"), &def_val); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -13177,8 +13360,10 @@ glusterd_get_global_max_op_version (rpcsvc_request_t *req, dict_t *ctx, goto out; } - sprintf (dict_key, "key%d", count); - ret = dict_set_str (ctx, dict_key, GLUSTERD_MAX_OP_VERSION_KEY); + keylen = sprintf (dict_key, "key%d", count); + ret = dict_set_nstrn (ctx, dict_key, keylen, + GLUSTERD_MAX_OP_VERSION_KEY, + SLEN (GLUSTERD_MAX_OP_VERSION_KEY)); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set %s in " @@ -13228,7 +13413,7 @@ glusterd_get_global_options_for_all_vols (rpcsvc_request_t *req, dict_t *ctx, GF_VALIDATE_OR_GOTO (this->name, ctx, out); - ret = dict_get_str (ctx, "key", &key); + ret = dict_get_strn (ctx, "key", SLEN ("key"), &key); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -13289,8 +13474,8 @@ glusterd_get_global_options_for_all_vols (rpcsvc_request_t *req, dict_t *ctx, } count++; - sprintf (dict_key, "key%d", count); - ret = dict_set_str (ctx, dict_key, allvolopt); + ret = sprintf (dict_key, "key%d", count); + ret = dict_set_strn (ctx, dict_key, ret, allvolopt); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -13319,7 +13504,7 @@ glusterd_get_global_options_for_all_vols (rpcsvc_request_t *req, dict_t *ctx, break; } - ret = dict_set_int32 (ctx, "count", count); + ret = dict_set_int32n (ctx, "count", SLEN ("count"), count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set count in dictionary"); @@ -13374,6 +13559,7 @@ glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts, xlator_t *this = NULL; char *def_val = NULL; char dict_key[50] = ""; + int keylen; gf_boolean_t key_found = _gf_false; glusterd_conf_t *priv = NULL; dict_t *vol_dict = NULL; @@ -13402,9 +13588,11 @@ glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts, /* First look for the key in the priv->opts for global option * and then into vol_dict, if its not present then look for * translator default value */ - ret = dict_get_str (priv->opts, vme->key, &def_val); + keylen = strlen (vme->key); + ret = dict_get_strn (priv->opts, vme->key, keylen, &def_val); if (!def_val) { - ret = dict_get_str (vol_dict, vme->key, &def_val); + ret = dict_get_strn (vol_dict, vme->key, keylen, + &def_val); if (ret == -ENOENT) def_val = glusterd_get_option_value (volinfo, vme->key); @@ -13422,8 +13610,8 @@ glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts, } } count++; - sprintf (dict_key, "key%d", count); - ret = dict_set_str(ctx, dict_key, vme->key); + keylen = sprintf (dict_key, "key%d", count); + ret = dict_set_strn (ctx, dict_key, keylen, vme->key); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -13449,7 +13637,7 @@ glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts, if (!all_opts && !key_found) goto out; - ret = dict_set_int32 (ctx, "count", count); + ret = dict_set_int32n (ctx, "count", SLEN ("count"), count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -13620,7 +13808,7 @@ cont: #endif } - ret = dict_set_dynstr (ctx, "help-str", output); + ret = dict_set_dynstrn (ctx, "help-str", SLEN ("help-str"), output); if (ret >= 0) { output = NULL; } @@ -14079,9 +14267,10 @@ glusterd_handle_replicate_brick_ops (glusterd_volinfo_t *volinfo, switch (op) { case GD_OP_REPLACE_BRICK: - 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) volfileserver = "localhost"; snprintf (logfile, sizeof (logfile), @@ -14212,7 +14401,8 @@ rb_update_dstbrick_port (glusterd_brickinfo_t *dst_brickinfo, dict_t *rsp_dict, int dict_ret = 0; int dst_port = 0; - dict_ret = dict_get_int32 (req_dict, "dst-brick-port", &dst_port); + dict_ret = dict_get_int32n (req_dict, "dst-brick-port", + SLEN ("dst-brick-port"), &dst_port); if (!dict_ret) dst_brickinfo->port = dst_port; @@ -14222,8 +14412,9 @@ rb_update_dstbrick_port (glusterd_brickinfo_t *dst_brickinfo, dict_t *rsp_dict, "adding dst-brick port no %d", dst_port); if (rsp_dict) { - ret = dict_set_int32 (rsp_dict, "dst-brick-port", - dst_brickinfo->port); + ret = dict_set_int32n (rsp_dict, "dst-brick-port", + SLEN ("dst-brick-port"), + dst_brickinfo->port); if (ret) { gf_msg_debug ("glusterd", 0, "Could not set dst-brick port no in rsp dict"); @@ -14232,8 +14423,9 @@ rb_update_dstbrick_port (glusterd_brickinfo_t *dst_brickinfo, dict_t *rsp_dict, } if (req_dict && !dict_ret) { - ret = dict_set_int32 (req_dict, "dst-brick-port", - dst_brickinfo->port); + ret = dict_set_int32n (req_dict, "dst-brick-port", + SLEN ("dst-brick-port"), + dst_brickinfo->port); if (ret) { gf_msg_debug ("glusterd", 0, "Could not set dst-brick port no"); @@ -14268,7 +14460,7 @@ glusterd_brick_op_prerequisites (dict_t *dict, priv = this->private; GF_ASSERT (priv); - ret = dict_get_str (dict, "operation", op); + ret = dict_get_strn (dict, "operation", SLEN ("operation"), op); if (ret) { gf_msg_debug (this->name, 0, "dict get on operation type failed"); @@ -14279,7 +14471,7 @@ glusterd_brick_op_prerequisites (dict_t *dict, if (*gd_op < 0) goto out; - 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, @@ -14349,7 +14541,7 @@ glusterd_brick_op_prerequisites (dict_t *dict, } } - ret = dict_get_str (dict, "src-brick", src_brick); + ret = dict_get_strn (dict, "src-brick", SLEN ("src-brick"), src_brick); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, @@ -14373,8 +14565,9 @@ glusterd_brick_op_prerequisites (dict_t *dict, gf_msg_debug (this->name, 0, "I AM THE SOURCE HOST"); if ((*src_brickinfo)->port && rsp_dict) { - ret = dict_set_int32 (rsp_dict, "src-brick-port", - (*src_brickinfo)->port); + ret = dict_set_int32n (rsp_dict, "src-brick-port", + SLEN ("src-brick-port"), + (*src_brickinfo)->port); if (ret) { gf_msg_debug (this->name, 0, "Could not set src-brick-port=%d", @@ -14412,7 +14605,7 @@ glusterd_get_dst_brick_info (char **dst_brick, char *volname, char **op_errstr, priv = this->private; GF_ASSERT (priv); - ret = dict_get_str (dict, "dst-brick", dst_brick); + ret = dict_get_strn (dict, "dst-brick", SLEN ("dst-brick"), dst_brick); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h index 97f3cc6edf0..6f77ca6fbd6 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-utils.h @@ -566,14 +566,15 @@ int glusterd_get_next_global_opt_version_str (dict_t *opts, char **version_str); int -glusterd_generate_and_set_task_id (dict_t *dict, char *key); +glusterd_generate_and_set_task_id (dict_t *dict, char *key, const int keylen); int glusterd_validate_and_set_gfid (dict_t *op_ctx, dict_t *req_dict, char **op_errstr); int -glusterd_copy_uuid_to_dict (uuid_t uuid, dict_t *dict, char *key); +glusterd_copy_uuid_to_dict (uuid_t uuid, dict_t *dict, char *key, + const int keylen); gf_boolean_t glusterd_is_same_address (char *name1, char *name2); diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c index 14638625d47..1f9426c87d3 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c @@ -114,7 +114,7 @@ glusterd_check_brick_order(dict_t *dict, char *err_str) ai_list->info = NULL; CDS_INIT_LIST_HEAD (&ai_list->list); - 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, @@ -122,7 +122,7 @@ glusterd_check_brick_order(dict_t *dict, char *err_str) goto out; } - ret = dict_get_int32 (dict, "type", &type); + ret = dict_get_int32n (dict, "type", SLEN ("type"), &type); if (ret) { snprintf (err_str, 512, "Unable to get type of volume %s", volname); @@ -132,7 +132,7 @@ glusterd_check_brick_order(dict_t *dict, char *err_str) goto out; } - ret = dict_get_str (dict, "bricks", &brick_list); + ret = dict_get_strn (dict, "bricks", SLEN ("bricks"), &brick_list); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Bricks check : Could not " @@ -140,7 +140,7 @@ glusterd_check_brick_order(dict_t *dict, char *err_str) goto out; } - ret = dict_get_int32 (dict, "count", &brick_count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &brick_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Bricks check : Could not " @@ -149,7 +149,8 @@ glusterd_check_brick_order(dict_t *dict, char *err_str) } if (type != GF_CLUSTER_TYPE_DISPERSE) { - ret = dict_get_int32 (dict, "replica-count", &sub_count); + ret = dict_get_int32n (dict, "replica-count", + SLEN ("replica-count"), &sub_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Bricks check : Could" @@ -159,7 +160,8 @@ glusterd_check_brick_order(dict_t *dict, char *err_str) gf_msg_debug (this->name, 0, "Replicate cluster type " "found. Checking brick order."); } else { - ret = dict_get_int32 (dict, "disperse-count", &sub_count); + ret = dict_get_int32n (dict, "disperse-count", + SLEN ("disperse-count"), &sub_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Bricks check : Could" @@ -337,7 +339,7 @@ __glusterd_handle_create_volume (rpcsvc_request_t *req) } } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get volume " @@ -355,7 +357,7 @@ __glusterd_handle_create_volume (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "count", &brick_count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &brick_count); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get brick count" " for volume %s", volname); @@ -364,7 +366,7 @@ __glusterd_handle_create_volume (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "type", &type); + ret = dict_get_int32n (dict, "type", SLEN ("type"), &type); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get type of " "volume %s", volname); @@ -375,7 +377,8 @@ __glusterd_handle_create_volume (rpcsvc_request_t *req) - ret = dict_get_str (dict, "transport", &trans_type); + ret = dict_get_strn (dict, "transport", SLEN ("transport"), + &trans_type); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get " "transport-type of volume %s", volname); @@ -384,8 +387,9 @@ __glusterd_handle_create_volume (rpcsvc_request_t *req) goto out; } - ret = dict_get_str (this->options, "transport.address-family", - &address_family_str); + ret = dict_get_strn (this->options, "transport.address-family", + SLEN ("transport.address-family"), + &address_family_str); if (!ret) { ret = dict_set_dynstr_with_alloc (dict, @@ -413,7 +417,7 @@ __glusterd_handle_create_volume (rpcsvc_request_t *req) } } } - ret = dict_get_str (dict, "bricks", &bricks); + ret = dict_get_strn (dict, "bricks", SLEN ("bricks"), &bricks); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get bricks for " "volume %s", volname); @@ -422,7 +426,7 @@ __glusterd_handle_create_volume (rpcsvc_request_t *req) goto out; } - if (!dict_get (dict, "force")) { + if (!dict_getn (dict, "force", SLEN ("force"))) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get 'force' flag"); goto out; @@ -430,7 +434,8 @@ __glusterd_handle_create_volume (rpcsvc_request_t *req) gf_uuid_generate (volume_id); free_ptr = gf_strdup (uuid_utoa (volume_id)); - ret = dict_set_dynstr (dict, "volume-id", free_ptr); + ret = dict_set_dynstrn (dict, "volume-id", SLEN ("volume-id"), + free_ptr); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to set volume " "id of volume %s", volname); @@ -444,7 +449,8 @@ __glusterd_handle_create_volume (rpcsvc_request_t *req) gf_uuid_generate (tmp_uuid); username = gf_strdup (uuid_utoa (tmp_uuid)); - ret = dict_set_dynstr (dict, "internal-username", username); + ret = dict_set_dynstrn (dict, "internal-username", + SLEN ("internal-username"), username); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set username for " @@ -454,7 +460,8 @@ __glusterd_handle_create_volume (rpcsvc_request_t *req) gf_uuid_generate (tmp_uuid); password = gf_strdup (uuid_utoa (tmp_uuid)); - ret = dict_set_dynstr (dict, "internal-password", password); + ret = dict_set_dynstrn (dict, "internal-password", + SLEN ("internal-password"), password); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set password for " @@ -536,7 +543,7 @@ __glusterd_handle_cli_start_volume (rpcsvc_request_t *req) } } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { snprintf (errstr, sizeof (errstr), "Unable to get volume name"); gf_msg (this->name, GF_LOG_ERROR, 0, @@ -624,7 +631,7 @@ __glusterd_handle_cli_stop_volume (rpcsvc_request_t *req) } } - ret = dict_get_str (dict, "volname", &dup_volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &dup_volname); if (ret) { snprintf (err_str, sizeof (err_str), "Failed to get volume " @@ -715,7 +722,7 @@ __glusterd_handle_cli_delete_volume (rpcsvc_request_t *req) } } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { snprintf (err_str, sizeof (err_str), "Failed to get volume " "name"); @@ -754,19 +761,22 @@ glusterd_handle_shd_option_for_tier (glusterd_volinfo_t *volinfo, char *value, dict_t *dict) { int count = 0; - char dict_key[1024] = {0, }; + char dict_key[64] = {0, }; + int keylen; char *key = NULL; int ret = 0; key = gd_get_shd_key (volinfo->tier_info.cold_type); if (key) { count++; - snprintf (dict_key, sizeof (dict_key), "key%d", count); - ret = dict_set_str (dict, dict_key, key); + keylen = snprintf (dict_key, sizeof (dict_key), "key%d", + count); + ret = dict_set_strn (dict, dict_key, keylen, key); if (ret) goto out; - snprintf (dict_key, sizeof (dict_key), "value%d", count); - ret = dict_set_str (dict, dict_key, value); + keylen = snprintf (dict_key, sizeof (dict_key), "value%d", + count); + ret = dict_set_strn (dict, dict_key, keylen, value); if (ret) goto out; } @@ -774,17 +784,19 @@ glusterd_handle_shd_option_for_tier (glusterd_volinfo_t *volinfo, key = gd_get_shd_key (volinfo->tier_info.hot_type); if (key) { count++; - snprintf (dict_key, sizeof (dict_key), "key%d", count); - ret = dict_set_str (dict, dict_key, key); + keylen = snprintf (dict_key, sizeof (dict_key), "key%d", + count); + ret = dict_set_strn (dict, dict_key, keylen, key); if (ret) goto out; - snprintf (dict_key, sizeof (dict_key), "value%d", count); - ret = dict_set_str (dict, dict_key, value); + keylen = snprintf (dict_key, sizeof (dict_key), "value%d", + count); + ret = dict_set_strn (dict, dict_key, keylen, value); if (ret) goto out; } - ret = dict_set_int32 (dict, "count", count); + ret = dict_set_int32n (dict, "count", SLEN ("count"), count); if (ret) goto out; @@ -801,7 +813,8 @@ glusterd_handle_heal_options_enable_disable (rpcsvc_request_t *req, char *key = NULL; char *value = NULL; - ret = dict_get_int32 (dict, "heal-op", (int32_t *)&heal_op); + ret = dict_get_int32n (dict, "heal-op", SLEN ("heal-op"), + (int32_t *)&heal_op); if (ret || (heal_op == GF_SHD_OP_INVALID)) { ret = -1; goto out; @@ -862,15 +875,15 @@ glusterd_handle_heal_options_enable_disable (rpcsvc_request_t *req, goto out; } - ret = dict_set_str (dict, "key1", key); + ret = dict_set_strn (dict, "key1", SLEN ("key1"), key); if (ret) goto out; - ret = dict_set_str (dict, "value1", value); + ret = dict_set_strn (dict, "value1", SLEN ("value1"), value); if (ret) goto out; - ret = dict_set_int32 (dict, "count", 1); + ret = dict_set_int32n (dict, "count", SLEN ("count"), 1); if (ret) goto out; @@ -925,7 +938,7 @@ __glusterd_handle_cli_heal_volume (rpcsvc_request_t *req) } } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { snprintf (op_errstr, sizeof (op_errstr), "Unable to find " "volume name"); @@ -964,7 +977,8 @@ __glusterd_handle_cli_heal_volume (rpcsvc_request_t *req) if (ret) goto out; - ret = dict_set_int32 (dict, "count", volinfo->brick_count); + ret = dict_set_int32n (dict, "count", SLEN ("count"), + volinfo->brick_count); if (ret) goto out; @@ -1035,16 +1049,16 @@ __glusterd_handle_cli_statedump_volume (rpcsvc_request_t *req) goto out; } } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { - snprintf (err_str, sizeof (err_str), "Unable to get the volume " - "name"); + snprintf (err_str, sizeof (err_str), + "Unable to get the volume name"); gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "%s", err_str); goto out; } - ret = dict_get_str (dict, "options", &options); + ret = dict_get_strn (dict, "options", SLEN ("options"), &options); if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get options"); gf_msg (this->name, GF_LOG_ERROR, 0, @@ -1052,7 +1066,8 @@ __glusterd_handle_cli_statedump_volume (rpcsvc_request_t *req) goto out; } - ret = dict_get_int32 (dict, "option_cnt", &option_cnt); + ret = dict_get_int32n (dict, "option_cnt", SLEN ("option_cnt"), + &option_cnt); if (ret) { snprintf (err_str , sizeof (err_str), "Unable to get option " "count"); @@ -1204,7 +1219,7 @@ glusterd_op_stage_create_volume (dict_t *dict, char **op_errstr, char *bricks = NULL; char *brick_list = NULL; char *free_ptr = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; glusterd_brickinfo_t *brick_info = NULL; int32_t brick_count = 0; int32_t local_brick_count = 0; @@ -1225,7 +1240,7 @@ glusterd_op_stage_create_volume (dict_t *dict, char **op_errstr, GF_ASSERT (priv); GF_ASSERT (rsp_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, "Unable to get volume name"); @@ -1242,7 +1257,7 @@ glusterd_op_stage_create_volume (dict_t *dict, char **op_errstr, ret = 0; } - ret = dict_get_int32 (dict, "count", &brick_count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), &brick_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get brick count " @@ -1250,7 +1265,8 @@ glusterd_op_stage_create_volume (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_str (dict, "volume-id", &volume_uuid_str); + ret = dict_get_strn (dict, "volume-id", SLEN ("volume-id"), + &volume_uuid_str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get volume id of " @@ -1267,7 +1283,7 @@ glusterd_op_stage_create_volume (dict_t *dict, char **op_errstr, goto out; } - ret = dict_get_str (dict, "bricks", &bricks); + ret = dict_get_strn (dict, "bricks", SLEN ("bricks"), &bricks); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -1378,7 +1394,7 @@ glusterd_op_stage_create_volume (dict_t *dict, char **op_errstr, * force at the end of command not given then check brick order. */ if (is_origin_glusterd (dict)) { - ret = dict_get_int32 (dict, "type", &type); + ret = dict_get_int32n (dict, "type", SLEN ("type"), &type); if (ret) { snprintf (msg, sizeof (msg), "Unable to get type of " "volume %s", volname); @@ -1395,15 +1411,16 @@ glusterd_op_stage_create_volume (dict_t *dict, char **op_errstr, if (ret) { gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER, "Not " - "creating volume because of bad " - "brick order"); + "creating volume because of " + "bad brick order"); goto out; } } } } - ret = dict_set_int32 (rsp_dict, "brick_count", local_brick_count); + ret = dict_set_int32n (rsp_dict, "brick_count", SLEN ("brick_count"), + local_brick_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -1437,14 +1454,14 @@ glusterd_op_stop_volume_args_get (dict_t *dict, char** volname, int *flags) if (!dict || !volname || !flags) goto out; - 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, "Unable to get volume name"); goto out; } - ret = dict_get_int32 (dict, "flags", flags); + ret = dict_get_int32n (dict, "flags", SLEN ("flags"), flags); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get flags"); @@ -1463,21 +1480,22 @@ glusterd_op_statedump_volume_args_get (dict_t *dict, char **volname, if (!dict || !volname || !options || !option_cnt) goto out; - ret = dict_get_str (dict, "volname", volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get volname"); goto out; } - ret = dict_get_str (dict, "options", options); + ret = dict_get_strn (dict, "options", SLEN ("options"), options); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get options"); goto out; } - ret = dict_get_int32 (dict, "option_cnt", option_cnt); + ret = dict_get_int32n (dict, "option_cnt", SLEN ("option_cnt"), + option_cnt); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get option count"); @@ -1494,7 +1512,7 @@ glusterd_op_stage_start_volume (dict_t *dict, char **op_errstr, { int ret = 0; char *volname = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; int flags = 0; int32_t brick_count = 0; int32_t local_brick_count = 0; @@ -1688,7 +1706,8 @@ glusterd_op_stage_start_volume (dict_t *dict, char **op_errstr, #endif } - ret = dict_set_int32 (rsp_dict, "brick_count", local_brick_count); + ret = dict_set_int32n (rsp_dict, "brick_count", SLEN ("brick_count"), + local_brick_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -1802,7 +1821,7 @@ glusterd_op_stage_delete_volume (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 (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get volume name"); @@ -1878,7 +1897,8 @@ glusterd_handle_heal_cmd (xlator_t *this, glusterd_volinfo_t *volinfo, "Check self-heal daemon log file."; priv = this->private; - ret = dict_get_int32 (dict, "heal-op", (int32_t*)&heal_op); + ret = dict_get_int32n (dict, "heal-op", SLEN ("heal-op"), + (int32_t*)&heal_op); if (ret) { ret = -1; *op_errstr = gf_strdup("Heal operation not specified"); @@ -1976,7 +1996,7 @@ glusterd_op_stage_heal_volume (dict_t *dict, char **op_errstr) goto out; } - ret = dict_get_str (dict, "volname", &volname); + ret = dict_get_strn (dict, "volname", SLEN ("volname"), &volname); if (ret) { gf_msg ("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get volume name"); @@ -2109,7 +2129,7 @@ glusterd_op_stage_clearlocks_volume (dict_t *dict, char **op_errstr) glusterd_volinfo_t *volinfo = NULL; char msg[2048] = {0,}; - 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, @@ -2118,7 +2138,7 @@ glusterd_op_stage_clearlocks_volume (dict_t *dict, char **op_errstr) goto out; } - ret = dict_get_str (dict, "path", &path); + ret = dict_get_strn (dict, "path", SLEN ("path"), &path); if (ret) { snprintf (msg, sizeof(msg), "Failed to get path"); gf_msg (THIS->name, GF_LOG_ERROR, 0, @@ -2127,7 +2147,7 @@ glusterd_op_stage_clearlocks_volume (dict_t *dict, char **op_errstr) goto out; } - ret = dict_get_str (dict, "kind", &kind); + ret = dict_get_strn (dict, "kind", SLEN ("kind"), &kind); if (ret) { snprintf (msg, sizeof(msg), "Failed to get kind"); gf_msg ("glusterd", GF_LOG_ERROR, 0, @@ -2136,7 +2156,7 @@ glusterd_op_stage_clearlocks_volume (dict_t *dict, char **op_errstr) goto out; } - ret = dict_get_str (dict, "type", &type); + ret = dict_get_strn (dict, "type", SLEN ("type"), &type); if (ret) { snprintf (msg, sizeof(msg), "Failed to get type"); gf_msg ("glusterd", GF_LOG_ERROR, 0, @@ -2218,7 +2238,7 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) goto out; } - 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, @@ -2234,7 +2254,7 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) GF_ASSERT (volinfo->volname); - ret = dict_get_int32 (dict, "type", &volinfo->type); + ret = dict_get_int32n (dict, "type", SLEN ("type"), &volinfo->type); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get type of volume" @@ -2242,7 +2262,8 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) goto out; } - ret = dict_get_int32 (dict, "count", &volinfo->brick_count); + ret = dict_get_int32n (dict, "count", SLEN ("count"), + &volinfo->brick_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get brick count of" @@ -2250,14 +2271,14 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) goto out; } - ret = dict_get_int32 (dict, "port", &volinfo->port); + ret = dict_get_int32n (dict, "port", SLEN ("port"), &volinfo->port); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get port"); goto out; } - ret = dict_get_str (dict, "bricks", &bricks); + ret = dict_get_strn (dict, "bricks", SLEN ("bricks"), &bricks); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get bricks for " @@ -2278,9 +2299,10 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) * replicate volumes */ if (priv->op_version >= GD_OP_VERSION_3_12_2) { - ret = dict_set_str (volinfo->dict, - "performance.client-io-threads", - "off"); + ret = dict_set_nstrn (volinfo->dict, + "performance.client-io-threads", + SLEN ("performance.client-io-threads"), + "off", SLEN ("off")); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set " @@ -2288,8 +2310,9 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) goto out; } } - ret = dict_get_int32 (dict, "replica-count", - &volinfo->replica_count); + ret = dict_get_int32n (dict, "replica-count", + SLEN ("replica-count"), + &volinfo->replica_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get " @@ -2298,11 +2321,13 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) } /* coverity[unused_value] arbiter count is optional */ - ret = dict_get_int32 (dict, "arbiter-count", - &volinfo->arbiter_count); + ret = dict_get_int32n (dict, "arbiter-count", + SLEN ("arbiter-count"), + &volinfo->arbiter_count); } else if (GF_CLUSTER_TYPE_STRIPE == volinfo->type) { - ret = dict_get_int32 (dict, "stripe-count", - &volinfo->stripe_count); + ret = dict_get_int32n (dict, "stripe-count", + SLEN ("stripe-count"), + &volinfo->stripe_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get stripe" @@ -2317,9 +2342,10 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) * replicate volumes */ if (priv->op_version >= GD_OP_VERSION_3_12_2) { - ret = dict_set_str (volinfo->dict, - "performance.client-io-threads", - "off"); + ret = dict_set_nstrn (volinfo->dict, + "performance.client-io-threads", + SLEN ("performance.client-io-threads"), + "off", SLEN ("off")); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set " @@ -2327,16 +2353,18 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) goto out; } } - ret = dict_get_int32 (dict, "stripe-count", - &volinfo->stripe_count); + ret = dict_get_int32n (dict, "stripe-count", + SLEN ("stripe-count"), + &volinfo->stripe_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get stripe" " count for volume %s", volname); goto out; } - ret = dict_get_int32 (dict, "replica-count", - &volinfo->replica_count); + ret = dict_get_int32n (dict, "replica-count", + SLEN ("replica-count"), + &volinfo->replica_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get " @@ -2345,19 +2373,22 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) } /* coverity[unused_value] arbiter count is optional */ - ret = dict_get_int32 (dict, "arbiter-count", - &volinfo->arbiter_count); + ret = dict_get_int32n (dict, "arbiter-count", + SLEN ("arbiter-count"), + &volinfo->arbiter_count); } else if (GF_CLUSTER_TYPE_DISPERSE == volinfo->type) { - ret = dict_get_int32 (dict, "disperse-count", - &volinfo->disperse_count); + ret = dict_get_int32n (dict, "disperse-count", + SLEN ("disperse-count"), + &volinfo->disperse_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get " "disperse count for volume %s", volname); goto out; } - ret = dict_get_int32 (dict, "redundancy-count", - &volinfo->redundancy_count); + ret = dict_get_int32n (dict, "redundancy-count", + SLEN ("redundancy-count"), + &volinfo->redundancy_count); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get " @@ -2387,7 +2418,8 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) if (volinfo->dist_leaf_count > 1) volinfo->sub_count = volinfo->dist_leaf_count; - ret = dict_get_str (dict, "transport", &trans_type); + ret = dict_get_strn (dict, "transport", SLEN ("transport"), + &trans_type); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -2395,7 +2427,7 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) goto out; } - ret = dict_get_str (dict, "volume-id", &str); + ret = dict_get_strn (dict, "volume-id", SLEN ("volume-id"), &str); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -2410,7 +2442,8 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) goto out; } - ret = dict_get_str (dict, "internal-username", &username); + ret = dict_get_strn (dict, "internal-username", + SLEN ("internal-username"), &username); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -2420,7 +2453,8 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) } glusterd_auth_set_username (volinfo, username); - ret = dict_get_str (dict, "internal-password", &password); + ret = dict_get_strn (dict, "internal-password", + SLEN ("internal-password"), &password); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -2474,8 +2508,10 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) */ if (priv->op_version >= GD_OP_VERSION_3_6_0) { brick_mount_dir = NULL; - snprintf (key, sizeof(key), "brick%d.mount_dir", i); - ret = dict_get_str (dict, key, &brick_mount_dir); + ret = snprintf (key, sizeof(key), + "brick%d.mount_dir", i); + ret = dict_get_strn (dict, key, ret, + &brick_mount_dir); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, @@ -2530,8 +2566,9 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) goto out; } - ret = dict_get_str (dict, "transport.address-family", - &address_family_str); + ret = dict_get_strn (dict, "transport.address-family", + SLEN ("transport.address-family"), + &address_family_str); if (!ret) { ret = dict_set_dynstr_with_alloc(volinfo->dict, @@ -2644,7 +2681,7 @@ glusterd_op_start_volume (dict_t *dict, char **op_errstr) int ret = 0; int32_t brick_count = 0; char *brick_mount_dir = NULL; - char key[PATH_MAX] = ""; + char key[64] = ""; char *volname = NULL; int flags = 0; glusterd_volinfo_t *volinfo = NULL; @@ -2692,9 +2729,10 @@ glusterd_op_start_volume (dict_t *dict, char **op_errstr) continue; if (strlen(brickinfo->mount_dir) < 1) { brick_mount_dir = NULL; - snprintf (key, sizeof(key), "brick%d.mount_dir", - brick_count); - ret = dict_get_str (dict, key, + ret = snprintf (key, sizeof (key), + "brick%d.mount_dir", + brick_count); + ret = dict_get_strn (dict, key, ret, &brick_mount_dir); if (ret) { gf_msg (this->name, GF_LOG_ERROR, 0, @@ -2867,7 +2905,7 @@ glusterd_op_delete_volume (dict_t *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 (this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Unable to get volume name"); @@ -3175,7 +3213,7 @@ glusterd_op_clearlocks_volume (dict_t *dict, char **op_errstr, dict_t *rsp_dict) char **xl_opts = NULL; glusterd_volinfo_t *volinfo = NULL; - 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 volume name"); @@ -3183,28 +3221,28 @@ glusterd_op_clearlocks_volume (dict_t *dict, char **op_errstr, dict_t *rsp_dict) } gf_msg_debug ("glusterd", 0, "Performing clearlocks on volume %s", volname); - ret = dict_get_str (dict, "path", &path); + ret = dict_get_strn (dict, "path", SLEN ("path"), &path); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get path"); goto out; } - ret = dict_get_str (dict, "kind", &kind); + ret = dict_get_strn (dict, "kind", SLEN ("kind"), &kind); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get kind"); goto out; } - ret = dict_get_str (dict, "type", &type); + ret = dict_get_strn (dict, "type", SLEN ("type"), &type); if (ret) { gf_msg (THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Failed to get type"); goto out; } - ret = dict_get_str (dict, "opts", &opts); + ret = dict_get_strn (dict, "opts", SLEN ("opts"), &opts); if (ret) ret = 0; @@ -3273,7 +3311,8 @@ glusterd_op_clearlocks_volume (dict_t *dict, char **op_errstr, dict_t *rsp_dict) } free_ptr = gf_strdup(result); - if (dict_set_dynstr (rsp_dict, "lk-summary", free_ptr)) { + if (dict_set_dynstrn (rsp_dict, "lk-summary", SLEN ("lk-summary"), + free_ptr)) { GF_FREE (free_ptr); snprintf (msg, sizeof (msg), "Failed to set clear-locks " "result"); -- cgit