From 9969d1dc2a3e815b161ce8a3dc5d08f84cfe011f Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Mon, 9 Dec 2019 21:28:00 +0200 Subject: multiple xlators: reduce key length In many cases, we were freely allocating long keys with no need. Smaller char arrays are just fine almost anywhere, so just went ahead and looked where they we can use smaller ones. In some cases, annotated the functions as static and the prefixes passed as const as it was easier to read and understand. Where relevant, converted the dict functions to use known key length. Change-Id: I882ab33ea20d90b63278336cd1370c09ffdab7f2 updates: bz#1193929 Signed-off-by: Yaniv Kaul --- xlators/features/bit-rot/src/bitd/bit-rot-scrub.c | 14 +++++++------- .../features/snapview-server/src/snapview-server-mgmt.c | 15 ++++++++------- 2 files changed, 15 insertions(+), 14 deletions(-) (limited to 'xlators/features') diff --git a/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c b/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c index a6beb2edb92..d20ecc7cdbe 100644 --- a/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c +++ b/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c @@ -1657,7 +1657,7 @@ br_read_bad_object_dir(xlator_t *this, br_child_t *child, fd_t *fd, int32_t ret = -1; off_t offset = 0; int32_t count = 0; - char key[PATH_MAX] = { + char key[32] = { 0, }; dict_t *out_dict = NULL; @@ -1695,7 +1695,7 @@ br_read_bad_object_dir(xlator_t *this, br_child_t *child, fd_t *fd, } ret = count; - ret = dict_set_int32(dict, "count", count); + ret = dict_set_int32_sizen(dict, "count", count); out: return ret; @@ -1777,10 +1777,10 @@ br_collect_bad_objects_of_child(xlator_t *this, br_child_t *child, dict_t *dict, { int32_t ret = -1; int32_t count = 0; - char key[PATH_MAX] = { + char key[32] = { 0, }; - char main_key[PATH_MAX] = { + char main_key[32] = { 0, }; int32_t j = 0; @@ -1792,15 +1792,15 @@ br_collect_bad_objects_of_child(xlator_t *this, br_child_t *child, dict_t *dict, char *path = NULL; int32_t len = 0; - ret = dict_get_int32(child_dict, "count", &count); + ret = dict_get_int32_sizen(child_dict, "count", &count); if (ret) goto out; tmp_count = total_count; for (j = 0; j < count; j++) { - snprintf(key, PATH_MAX, "quarantine-%d", j); - ret = dict_get_str(child_dict, key, &entry); + len = snprintf(key, PATH_MAX, "quarantine-%d", j); + ret = dict_get_strn(child_dict, key, len, &entry); if (ret) continue; diff --git a/xlators/features/snapview-server/src/snapview-server-mgmt.c b/xlators/features/snapview-server/src/snapview-server-mgmt.c index d903322424e..ecf31c3b880 100644 --- a/xlators/features/snapview-server/src/snapview-server-mgmt.c +++ b/xlators/features/snapview-server/src/snapview-server-mgmt.c @@ -237,7 +237,8 @@ mgmt_get_snapinfo_cbk(struct rpc_req *req, struct iovec *iov, int count, glusterfs_ctx_t *ctx = NULL; int ret = -1; dict_t *dict = NULL; - char key[1024] = {0}; + char key[32] = {0}; + int len; int snapcount = 0; svs_private_t *priv = NULL; xlator_t *this = NULL; @@ -330,8 +331,8 @@ mgmt_get_snapinfo_cbk(struct rpc_req *req, struct iovec *iov, int count, } for (i = 0; i < snapcount; i++) { - snprintf(key, sizeof(key), "snap-volname.%d", i + 1); - ret = dict_get_str(dict, key, &value); + len = snprintf(key, sizeof(key), "snap-volname.%d", i + 1); + ret = dict_get_strn(dict, key, len, &value); if (ret) { errno = EINVAL; ret = -1; @@ -343,8 +344,8 @@ mgmt_get_snapinfo_cbk(struct rpc_req *req, struct iovec *iov, int count, strncpy(dirents[i].snap_volname, value, sizeof(dirents[i].snap_volname)); - snprintf(key, sizeof(key), "snap-id.%d", i + 1); - ret = dict_get_str(dict, key, &value); + len = snprintf(key, sizeof(key), "snap-id.%d", i + 1); + ret = dict_get_strn(dict, key, len, &value); if (ret) { errno = EINVAL; ret = -1; @@ -354,8 +355,8 @@ mgmt_get_snapinfo_cbk(struct rpc_req *req, struct iovec *iov, int count, } strncpy(dirents[i].uuid, value, sizeof(dirents[i].uuid)); - snprintf(key, sizeof(key), "snapname.%d", i + 1); - ret = dict_get_str(dict, key, &value); + len = snprintf(key, sizeof(key), "snapname.%d", i + 1); + ret = dict_get_strn(dict, key, len, &value); if (ret) { errno = EINVAL; ret = -1; -- cgit