From 76cc1ea613e038ced4bc6ae26233cb0681b63be5 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Fri, 28 Sep 2018 13:03:38 +0530 Subject: libglusterfs/dict: Add sizeof()-1 variants of dict functions One needs to be very careful about giving same key for the key and SLEN(key) arguments in dict_xxxn() functions. Writing macros that would take care of passing the SLEN(key) would help reduce this burden on the developer and reviewer. updates: bz#1193929 Change-Id: I312c479b919826570b47ae2c219c53e2f9b2ddef Signed-off-by: Pranith Kumar K --- xlators/cluster/afr/src/afr-inode-write.c | 8 ++++---- xlators/features/quota/src/quota-enforcer-client.c | 19 ++++++------------- xlators/features/quota/src/quota.c | 3 +-- xlators/features/quota/src/quota.h | 3 +-- xlators/features/quota/src/quotad-aggregator.c | 14 +++++--------- xlators/mgmt/glusterd/src/glusterd-handler.c | 6 ++---- xlators/mgmt/glusterd/src/glusterd-op-sm.c | 8 +++----- xlators/mgmt/glusterd/src/glusterd-quota.c | 3 +-- 8 files changed, 23 insertions(+), 41 deletions(-) (limited to 'xlators') diff --git a/xlators/cluster/afr/src/afr-inode-write.c b/xlators/cluster/afr/src/afr-inode-write.c index df807342b99..c6fe0939841 100644 --- a/xlators/cluster/afr/src/afr-inode-write.c +++ b/xlators/cluster/afr/src/afr-inode-write.c @@ -307,8 +307,8 @@ afr_inode_write_fill(call_frame_t *frame, xlator_t *this, int child_index, local->update_open_fd_count = _gf_true; } - ret = dict_get_int32n(xdata, GLUSTERFS_INODELK_COUNT, - SLEN(GLUSTERFS_INODELK_COUNT), &num_inodelks); + ret = dict_get_int32_sizen(xdata, GLUSTERFS_INODELK_COUNT, + &num_inodelks); if (ret < 0) goto unlock; if (num_inodelks > local->num_inodelks) { @@ -528,8 +528,8 @@ afr_writev(call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector, goto out; } - if (dict_set_strn(local->xdata_req, GLUSTERFS_INODELK_DOM_COUNT, - SLEN(GLUSTERFS_INODELK_DOM_COUNT), this->name)) { + if (dict_set_str_sizen(local->xdata_req, GLUSTERFS_INODELK_DOM_COUNT, + this->name)) { op_errno = ENOMEM; goto out; } diff --git a/xlators/features/quota/src/quota-enforcer-client.c b/xlators/features/quota/src/quota-enforcer-client.c index d69bc919e23..1a4c2e30dd6 100644 --- a/xlators/features/quota/src/quota-enforcer-client.c +++ b/xlators/features/quota/src/quota-enforcer-client.c @@ -395,8 +395,7 @@ quota_enforcer_blocking_connect(rpc_clnt_t *rpc) if (options == NULL) goto out; - ret = dict_set_nstrn(options, "non-blocking-io", SLEN("non-blocking-io"), - "no", SLEN("no")); + ret = dict_set_sizen_str_sizen(options, "non-blocking-io", "no"); if (ret) goto out; @@ -404,8 +403,7 @@ quota_enforcer_blocking_connect(rpc_clnt_t *rpc) rpc_clnt_start(rpc); - ret = dict_set_nstrn(options, "non-blocking-io", SLEN("non-blocking-io"), - "yes", SLEN("yes")); + ret = dict_set_sizen_str_sizen(options, "non-blocking-io", "yes"); if (ret) goto out; @@ -444,21 +442,16 @@ quota_enforcer_init(xlator_t *this, dict_t *options) priv->quota_enforcer = "a_enforcer_clnt; - ret = dict_set_nstrn(options, "transport.address-family", - SLEN("transport.address-family"), "unix", - SLEN("unix")); + ret = dict_set_sizen_str_sizen(options, "transport.address-family", "unix"); if (ret) goto out; - ret = dict_set_nstrn(options, "transport-type", SLEN("transport-type"), - "socket", SLEN("socket")); + ret = dict_set_sizen_str_sizen(options, "transport-type", "socket"); if (ret) goto out; - ret = dict_set_nstrn(options, "transport.socket.connect-path", - SLEN("transport.socket.connect-path"), - "/var/run/gluster/quotad.socket", - SLEN("/var/run/gluster/quotad.socket")); + ret = dict_set_sizen_str_sizen(options, "transport.socket.connect-path", + "/var/run/gluster/quotad.socket"); if (ret) goto out; diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c index 8015e8aae8b..6310967fc0d 100644 --- a/xlators/features/quota/src/quota.c +++ b/xlators/features/quota/src/quota.c @@ -3967,8 +3967,7 @@ quota_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, VALIDATE_OR_GOTO(this, err); VALIDATE_OR_GOTO(loc, err); - if (xdata && dict_getn(xdata, GLUSTERFS_INTERNAL_FOP_KEY, - SLEN(GLUSTERFS_INTERNAL_FOP_KEY))) + if (xdata && dict_get_sizen(xdata, GLUSTERFS_INTERNAL_FOP_KEY)) internal_fop = _gf_true; if (frame->root->pid >= 0 && internal_fop == _gf_false) { diff --git a/xlators/features/quota/src/quota.h b/xlators/features/quota/src/quota.h index f0a5d4ed279..8bcc3ec6176 100644 --- a/xlators/features/quota/src/quota.h +++ b/xlators/features/quota/src/quota.h @@ -47,8 +47,7 @@ #define QUOTA_WIND_FOR_INTERNAL_FOP(xdata, label) \ do { \ - if (xdata && dict_getn(xdata, GLUSTERFS_INTERNAL_FOP_KEY, \ - SLEN(GLUSTERFS_INTERNAL_FOP_KEY))) \ + if (xdata && dict_get_sizen(xdata, GLUSTERFS_INTERNAL_FOP_KEY)) \ goto label; \ } while (0) diff --git a/xlators/features/quota/src/quotad-aggregator.c b/xlators/features/quota/src/quotad-aggregator.c index 288955034bd..e0129e4f63a 100644 --- a/xlators/features/quota/src/quotad-aggregator.c +++ b/xlators/features/quota/src/quotad-aggregator.c @@ -142,7 +142,7 @@ quotad_aggregator_getlimit_cbk(xlator_t *this, call_frame_t *frame, if (ret < 0) goto out; - ret = dict_set_int32n(xdata, "type", SLEN("type"), type); + ret = dict_set_int32_sizen(xdata, "type", type); if (ret < 0) goto out; } @@ -234,26 +234,22 @@ quotad_aggregator_getlimit(rpcsvc_request_t *req) state = frame->root->state; state->xdata = dict; - ret = dict_set_int32n(state->xdata, QUOTA_LIMIT_KEY, SLEN(QUOTA_LIMIT_KEY), - 42); + ret = dict_set_int32_sizen(state->xdata, QUOTA_LIMIT_KEY, 42); if (ret) goto err; - ret = dict_set_int32n(state->xdata, QUOTA_LIMIT_OBJECTS_KEY, - SLEN(QUOTA_LIMIT_OBJECTS_KEY), 42); + ret = dict_set_int32_sizen(state->xdata, QUOTA_LIMIT_OBJECTS_KEY, 42); if (ret) { gf_msg(this->name, GF_LOG_ERROR, ENOMEM, Q_MSG_ENOMEM, "Failed to set QUOTA_LIMIT_OBJECTS_KEY"); goto err; } - ret = dict_set_int32n(state->xdata, QUOTA_SIZE_KEY, SLEN(QUOTA_SIZE_KEY), - 42); + ret = dict_set_int32_sizen(state->xdata, QUOTA_SIZE_KEY, 42); if (ret) goto err; - ret = dict_set_int32n(state->xdata, GET_ANCESTRY_PATH_KEY, - SLEN(GET_ANCESTRY_PATH_KEY), 42); + ret = dict_set_int32_sizen(state->xdata, GET_ANCESTRY_PATH_KEY, 42); if (ret) goto err; diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index 5714e44e1f4..aa8892784df 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -3499,13 +3499,11 @@ glusterd_friend_rpc_create(xlator_t *this, glusterd_peerinfo_t *peerinfo, data = dict_getn(this->options, "transport.socket.bind-address", SLEN("transport.socket.bind-address")); if (data) { - ret = dict_setn(options, "transport.socket.source-addr", - SLEN("transport.socket.source-addr"), data); + ret = dict_set_sizen(options, "transport.socket.source-addr", data); } data = dict_getn(this->options, "ping-timeout", SLEN("ping-timeout")); if (data) { - ret = dict_setn(options, "ping-timeout", SLEN("ping-timeout"), - data); + ret = dict_set_sizen(options, "ping-timeout", data); } } diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index c8343fb0a2d..3ccc9a3c776 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -2122,7 +2122,7 @@ _delete_reconfig_opt(dict_t *this, char *key, data_t *value, void *data) * option is going to be reset * */ if (!strncmp(key, VKEY_FEATURES_BITROT, strlen(VKEY_FEATURES_BITROT))) { - dict_deln(this, VKEY_FEATURES_SCRUB, SLEN(VKEY_FEATURES_SCRUB)); + dict_del_sizen(this, VKEY_FEATURES_SCRUB); } out: return 0; @@ -3244,10 +3244,8 @@ glusterd_remove_profile_volume_options(glusterd_volinfo_t *volinfo) { GF_ASSERT(volinfo); - 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)); + dict_del_sizen(volinfo->dict, VKEY_DIAG_LAT_MEASUREMENT); + dict_del_sizen(volinfo->dict, VKEY_DIAG_CNT_FOP_HITS); } static int diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c index d2fefeff9f0..014d3d55b98 100644 --- a/xlators/mgmt/glusterd/src/glusterd-quota.c +++ b/xlators/mgmt/glusterd/src/glusterd-quota.c @@ -540,8 +540,7 @@ glusterd_quota_get_default_soft_limit(glusterd_volinfo_t *volinfo, else val = gf_strdup("80%"); - ret = dict_set_dynstrn(rsp_dict, "default-soft-limit", - SLEN("default-soft-limit"), val); + ret = dict_set_dynstr_sizen(rsp_dict, "default-soft-limit", val); if (ret) { gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to set default " -- cgit