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 --- glusterfsd/src/glusterfsd-mgmt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'glusterfsd') diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c index 2b97dc91165..65446ab05c1 100644 --- a/glusterfsd/src/glusterfsd-mgmt.c +++ b/glusterfsd/src/glusterfsd-mgmt.c @@ -722,7 +722,8 @@ glusterfs_handle_translator_op(rpcsvc_request_t *req) xlator_t *xlator = NULL; xlator_t *any = NULL; dict_t *output = NULL; - char key[2048] = {0}; + char key[32] = {0}; + int len; char *xname = NULL; glusterfs_ctx_t *ctx = NULL; glusterfs_graph_t *active = NULL; @@ -774,8 +775,8 @@ glusterfs_handle_translator_op(rpcsvc_request_t *req) } for (i = 0; i < count; i++) { - snprintf(key, sizeof(key), "xl-%d", i); - ret = dict_get_str(input, key, &xname); + len = snprintf(key, sizeof(key), "xl-%d", i); + ret = dict_get_strn(input, key, len, &xname); if (ret) { gf_log(this->name, GF_LOG_ERROR, "Couldn't get " @@ -793,8 +794,8 @@ glusterfs_handle_translator_op(rpcsvc_request_t *req) } } for (i = 0; i < count; i++) { - snprintf(key, sizeof(key), "xl-%d", i); - ret = dict_get_str(input, key, &xname); + len = snprintf(key, sizeof(key), "xl-%d", i); + ret = dict_get_strn(input, key, len, &xname); xlator = xlator_search_by_name(any, xname); XLATOR_NOTIFY(ret, xlator, GF_EVENT_TRANSLATOR_OP, input, output); /* If notify fails for an xlator we need to capture it but -- cgit