diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2018-09-23 11:04:22 +0300 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-09-26 04:17:30 +0000 |
commit | 341ba81448e869ae388b4b37556e47f6bf7413a5 (patch) | |
tree | 2867552e09e07d4320fc9cefb96a9533fc719658 /xlators/features | |
parent | 064b24900e1f5e3ba3087f7c6a0249613ebed61f (diff) |
Quota related files: 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 code to use it.
Please review carefully.
Compile-tested only!
updates: bz#1193929
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Change-Id: If4f425a9827be7c36ccfbb9761006ae824a818c6
Diffstat (limited to 'xlators/features')
-rw-r--r-- | xlators/features/marker/src/marker-quota.c | 62 | ||||
-rw-r--r-- | xlators/features/marker/src/marker.c | 8 | ||||
-rw-r--r-- | xlators/features/quota/src/quota-enforcer-client.c | 19 | ||||
-rw-r--r-- | xlators/features/quota/src/quota.c | 32 | ||||
-rw-r--r-- | xlators/features/quota/src/quota.h | 3 | ||||
-rw-r--r-- | xlators/features/quota/src/quotad-aggregator.c | 31 | ||||
-rw-r--r-- | xlators/features/quota/src/quotad.c | 9 |
7 files changed, 104 insertions, 60 deletions
diff --git a/xlators/features/marker/src/marker-quota.c b/xlators/features/marker/src/marker-quota.c index 28da33849a0..0fc7ba66ee0 100644 --- a/xlators/features/marker/src/marker-quota.c +++ b/xlators/features/marker/src/marker-quota.c @@ -286,8 +286,8 @@ out: * This function returns success even is inode-quota xattrs are missing and * hence no healing performed. */ -int32_t -_quota_dict_get_meta(xlator_t *this, dict_t *dict, char *key, +static int32_t +_quota_dict_get_meta(xlator_t *this, dict_t *dict, char *key, const int keylen, quota_meta_t *meta, ia_type_t ia_type, gf_boolean_t add_delta) { @@ -296,7 +296,7 @@ _quota_dict_get_meta(xlator_t *this, dict_t *dict, char *key, priv = this->private; - ret = quota_dict_get_inode_meta(dict, key, meta); + ret = quota_dict_get_inode_meta(dict, key, keylen, meta); if (ret == -2 && (priv->feature_enabled & GF_INODE_QUOTA) == 0) { /* quota_dict_get_inode_meta returns -2 if * inode quota xattrs are not present. @@ -430,13 +430,15 @@ mq_are_xattrs_set(xlator_t *this, loc_t *loc, gf_boolean_t *contri_set, *contri_set = _gf_true; *size_set = _gf_true; if (loc->inode->ia_type == IA_IFDIR) { - ret = quota_dict_get_inode_meta(rsp_dict, size_key, &meta); + ret = quota_dict_get_inode_meta(rsp_dict, size_key, strlen(size_key), + &meta); if (ret < 0 || meta.dir_count == 0) *size_set = _gf_false; } if (!loc_is_root(loc)) { - ret = quota_dict_get_inode_meta(rsp_dict, contri_key, &meta); + ret = quota_dict_get_inode_meta(rsp_dict, contri_key, + strlen(contri_key), &meta); if (ret < 0) *contri_set = _gf_false; } @@ -726,6 +728,7 @@ _mq_get_metadata(xlator_t *this, loc_t *loc, quota_meta_t *contri, char size_key[QUOTA_KEY_MAX] = { 0, }; + int keylen = 0; dict_t *dict = NULL; dict_t *rsp_dict = NULL; struct iatt stbuf = { @@ -745,8 +748,8 @@ _mq_get_metadata(xlator_t *this, loc_t *loc, quota_meta_t *contri, } if (size && loc->inode->ia_type == IA_IFDIR) { - GET_SIZE_KEY(this, size_key, ret); - if (ret < 0) + GET_SIZE_KEY(this, size_key, keylen); + if (keylen < 0) goto out; ret = dict_set_int64(dict, size_key, 0); if (ret < 0) { @@ -775,7 +778,7 @@ _mq_get_metadata(xlator_t *this, loc_t *loc, quota_meta_t *contri, if (size) { if (loc->inode->ia_type == IA_IFDIR) { - ret = quota_dict_get_meta(rsp_dict, size_key, &meta); + ret = quota_dict_get_meta(rsp_dict, size_key, keylen, &meta); if (ret < 0) { gf_log(this->name, GF_LOG_ERROR, "dict_get failed."); goto out; @@ -792,7 +795,8 @@ _mq_get_metadata(xlator_t *this, loc_t *loc, quota_meta_t *contri, } if (contri && !loc_is_root(loc)) { - ret = quota_dict_get_meta(rsp_dict, contri_key, &meta); + ret = quota_dict_get_meta(rsp_dict, contri_key, strlen(contri_key), + &meta); if (ret < 0) { contri->size = 0; contri->file_count = 0; @@ -1876,6 +1880,7 @@ mq_update_dirty_inode_task(void *opaque) char contri_key[QUOTA_KEY_MAX] = { 0, }; + int keylen = 0; GF_ASSERT(opaque); @@ -1889,9 +1894,11 @@ mq_update_dirty_inode_task(void *opaque) if (ret < 0) goto out; - GET_CONTRI_KEY(this, contri_key, loc->gfid, ret); - if (ret < 0) + GET_CONTRI_KEY(this, contri_key, loc->gfid, keylen); + if (keylen < 0) { + ret = keylen; goto out; + } xdata = dict_new(); if (xdata == NULL) { @@ -1958,7 +1965,7 @@ mq_update_dirty_inode_task(void *opaque) continue; memset(&contri, 0, sizeof(contri)); - quota_dict_get_meta(entry->dict, contri_key, &contri); + quota_dict_get_meta(entry->dict, contri_key, keylen, &contri); if (quota_meta_is_null(&contri)) continue; @@ -2073,6 +2080,7 @@ mq_inspect_directory_xattr(xlator_t *this, quota_inode_ctx_t *ctx, char size_key[QUOTA_KEY_MAX] = { 0, }; + int keylen = 0; gf_boolean_t status = _gf_false; ret = dict_get_int8(dict, QUOTA_DIRTY_KEY, &dirty); @@ -2084,21 +2092,24 @@ mq_inspect_directory_xattr(xlator_t *this, quota_inode_ctx_t *ctx, dirty = 0; } - GET_SIZE_KEY(this, size_key, ret); - if (ret < 0) + GET_SIZE_KEY(this, size_key, keylen); + if (keylen < 0) { + ret = -1; goto out; - ret = _quota_dict_get_meta(this, dict, size_key, &size, IA_IFDIR, + } + ret = _quota_dict_get_meta(this, dict, size_key, keylen, &size, IA_IFDIR, _gf_false); if (ret < 0) goto create_xattr; if (!loc_is_root(loc)) { - GET_CONTRI_KEY(this, contri_key, contribution->gfid, ret); - if (ret < 0) + GET_CONTRI_KEY(this, contri_key, contribution->gfid, keylen); + if (keylen < 0) { + ret = -1; goto out; - - ret = _quota_dict_get_meta(this, dict, contri_key, &contri, IA_IFDIR, - _gf_false); + } + ret = _quota_dict_get_meta(this, dict, contri_key, keylen, &contri, + IA_IFDIR, _gf_false); if (ret < 0) goto create_xattr; @@ -2166,6 +2177,7 @@ mq_inspect_file_xattr(xlator_t *this, quota_inode_ctx_t *ctx, char contri_key[QUOTA_KEY_MAX] = { 0, }; + int keylen = 0; gf_boolean_t status = _gf_false; if (!buf || !contribution || !ctx) @@ -2183,12 +2195,14 @@ mq_inspect_file_xattr(xlator_t *this, quota_inode_ctx_t *ctx, } UNLOCK(&ctx->lock); - GET_CONTRI_KEY(this, contri_key, contribution->gfid, ret); - if (ret < 0) + GET_CONTRI_KEY(this, contri_key, contribution->gfid, keylen); + if (keylen < 0) { + ret = -1; goto out; + } - ret = _quota_dict_get_meta(this, dict, contri_key, &contri, IA_IFREG, - _gf_true); + ret = _quota_dict_get_meta(this, dict, contri_key, keylen, &contri, + IA_IFREG, _gf_true); if (ret < 0) { ret = mq_create_xattrs_txn(this, loc, NULL); } else { diff --git a/xlators/features/marker/src/marker.c b/xlators/features/marker/src/marker.c index 29294e73fd4..2d3177c7ec3 100644 --- a/xlators/features/marker/src/marker.c +++ b/xlators/features/marker/src/marker.c @@ -1521,7 +1521,7 @@ marker_do_rename(call_frame_t *frame, void *cookie, xlator_t *this, char contri_key[QUOTA_KEY_MAX] = { 0, }; - int32_t ret = 0; + int keylen = 0; quota_meta_t contribution = { 0, }; @@ -1543,12 +1543,12 @@ marker_do_rename(call_frame_t *frame, void *cookie, xlator_t *this, goto err; } - GET_CONTRI_KEY(this, contri_key, oplocal->loc.parent->gfid, ret); - if (ret < 0) { + GET_CONTRI_KEY(this, contri_key, oplocal->loc.parent->gfid, keylen); + if (keylen < 0) { local->err = errno ? errno : ENOMEM; goto err; } - quota_dict_get_meta(dict, contri_key, &contribution); + quota_dict_get_meta(dict, contri_key, keylen, &contribution); oplocal->contribution = contribution; STACK_WIND(frame, marker_rename_cbk, FIRST_CHILD(this), diff --git a/xlators/features/quota/src/quota-enforcer-client.c b/xlators/features/quota/src/quota-enforcer-client.c index 57105549cf8..d69bc919e23 100644 --- a/xlators/features/quota/src/quota-enforcer-client.c +++ b/xlators/features/quota/src/quota-enforcer-client.c @@ -395,7 +395,8 @@ quota_enforcer_blocking_connect(rpc_clnt_t *rpc) if (options == NULL) goto out; - ret = dict_set_str(options, "non-blocking-io", "no"); + ret = dict_set_nstrn(options, "non-blocking-io", SLEN("non-blocking-io"), + "no", SLEN("no")); if (ret) goto out; @@ -403,7 +404,8 @@ quota_enforcer_blocking_connect(rpc_clnt_t *rpc) rpc_clnt_start(rpc); - ret = dict_set_str(options, "non-blocking-io", "yes"); + ret = dict_set_nstrn(options, "non-blocking-io", SLEN("non-blocking-io"), + "yes", SLEN("yes")); if (ret) goto out; @@ -442,16 +444,21 @@ quota_enforcer_init(xlator_t *this, dict_t *options) priv->quota_enforcer = "a_enforcer_clnt; - ret = dict_set_str(options, "transport.address-family", "unix"); + ret = dict_set_nstrn(options, "transport.address-family", + SLEN("transport.address-family"), "unix", + SLEN("unix")); if (ret) goto out; - ret = dict_set_str(options, "transport-type", "socket"); + ret = dict_set_nstrn(options, "transport-type", SLEN("transport-type"), + "socket", SLEN("socket")); if (ret) goto out; - ret = dict_set_str(options, "transport.socket.connect-path", - "/var/run/gluster/quotad.socket"); + 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")); if (ret) goto out; diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c index af3e8a48b7f..8015e8aae8b 100644 --- a/xlators/features/quota/src/quota.c +++ b/xlators/features/quota/src/quota.c @@ -615,7 +615,8 @@ quota_validate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, goto unwind; } - ret = quota_dict_get_meta(xdata, QUOTA_SIZE_KEY, &size); + ret = quota_dict_get_meta(xdata, QUOTA_SIZE_KEY, SLEN(QUOTA_SIZE_KEY), + &size); if (ret == -1) { gf_msg(this->name, GF_LOG_WARNING, EINVAL, Q_MSG_SIZE_KEY_MISSING, "quota size key not present " @@ -3151,12 +3152,13 @@ off: return 0; } -int32_t +static int32_t quota_send_dir_limit_to_cli(call_frame_t *frame, xlator_t *this, inode_t *inode, - const char *name) + const char *name, const int namelen) { int32_t ret = 0; - char dir_limit[1024] = { + int dir_limit_len = 0; + char dir_limit[64] = { 0, }; dict_t *dict = NULL; @@ -3166,7 +3168,8 @@ quota_send_dir_limit_to_cli(call_frame_t *frame, xlator_t *this, inode_t *inode, priv = this->private; if (!priv->is_quota_on) { - snprintf(dir_limit, 1024, "Quota is disabled please turn on"); + dir_limit_len = snprintf(dir_limit, sizeof(dir_limit), + "Quota is disabled please turn on"); goto dict_set; } @@ -3175,7 +3178,8 @@ quota_send_dir_limit_to_cli(call_frame_t *frame, xlator_t *this, inode_t *inode, goto out; ctx = (quota_inode_ctx_t *)(unsigned long)value; - snprintf(dir_limit, 1024, "%" PRId64 ",%" PRId64, ctx->size, ctx->hard_lim); + dir_limit_len = snprintf(dir_limit, sizeof(dir_limit), + "%" PRId64 ",%" PRId64, ctx->size, ctx->hard_lim); dict_set: dict = dict_new(); @@ -3184,7 +3188,7 @@ dict_set: goto out; } - ret = dict_set_str(dict, (char *)name, dir_limit); + ret = dict_set_nstrn(dict, (char *)name, namelen, dir_limit, dir_limit_len); if (ret < 0) goto out; @@ -3207,7 +3211,9 @@ quota_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name, int32_t ret = 0; if (name && strcasecmp(name, "trusted.limit.list") == 0) { - ret = quota_send_dir_limit_to_cli(frame, this, fd->inode, name); + ret = quota_send_dir_limit_to_cli(frame, this, fd->inode, + "trusted.limit.list", + SLEN("trusted.limit.list")); if (ret == 0) { return 0; } @@ -3225,7 +3231,9 @@ quota_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t ret = 0; if ((name != NULL) && strcasecmp(name, "trusted.limit.list") == 0) { - ret = quota_send_dir_limit_to_cli(frame, this, loc->inode, name); + ret = quota_send_dir_limit_to_cli(frame, this, loc->inode, + "trusted.limit.list", + SLEN("trusted.limit.list")); if (ret == 0) return 0; } @@ -3959,7 +3967,8 @@ 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_get(xdata, GLUSTERFS_INTERNAL_FOP_KEY)) + if (xdata && dict_getn(xdata, GLUSTERFS_INTERNAL_FOP_KEY, + SLEN(GLUSTERFS_INTERNAL_FOP_KEY))) internal_fop = _gf_true; if (frame->root->pid >= 0 && internal_fop == _gf_false) { @@ -4320,7 +4329,8 @@ quota_statfs_validate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, goto resume; } - ret = quota_dict_get_meta(xdata, QUOTA_SIZE_KEY, &size); + ret = quota_dict_get_meta(xdata, QUOTA_SIZE_KEY, SLEN(QUOTA_SIZE_KEY), + &size); if (ret == -1) { gf_msg(this->name, GF_LOG_WARNING, EINVAL, Q_MSG_SIZE_KEY_MISSING, "size key not present in " diff --git a/xlators/features/quota/src/quota.h b/xlators/features/quota/src/quota.h index 7ced27a6188..f0a5d4ed279 100644 --- a/xlators/features/quota/src/quota.h +++ b/xlators/features/quota/src/quota.h @@ -47,7 +47,8 @@ #define QUOTA_WIND_FOR_INTERNAL_FOP(xdata, label) \ do { \ - if (xdata && dict_get(xdata, GLUSTERFS_INTERNAL_FOP_KEY)) \ + if (xdata && dict_getn(xdata, GLUSTERFS_INTERNAL_FOP_KEY, \ + SLEN(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 b9c18f40f4b..288955034bd 100644 --- a/xlators/features/quota/src/quotad-aggregator.c +++ b/xlators/features/quota/src/quotad-aggregator.c @@ -138,11 +138,11 @@ quotad_aggregator_getlimit_cbk(xlator_t *this, call_frame_t *frame, if (xdata) { state = frame->root->state; - ret = dict_get_int32(state->xdata, "type", &type); + ret = dict_get_int32n(state->xdata, "type", SLEN("type"), &type); if (ret < 0) goto out; - ret = dict_set_int32(xdata, "type", type); + ret = dict_set_int32n(xdata, "type", SLEN("type"), type); if (ret < 0) goto out; } @@ -219,7 +219,7 @@ quotad_aggregator_getlimit(rpcsvc_request_t *req) } } - ret = dict_get_str(dict, "gfid", &gfid_str); + ret = dict_get_strn(dict, "gfid", SLEN("gfid"), &gfid_str); if (ret) { goto err; } @@ -234,22 +234,26 @@ quotad_aggregator_getlimit(rpcsvc_request_t *req) state = frame->root->state; state->xdata = dict; - ret = dict_set_int32(state->xdata, QUOTA_LIMIT_KEY, 42); + ret = dict_set_int32n(state->xdata, QUOTA_LIMIT_KEY, SLEN(QUOTA_LIMIT_KEY), + 42); if (ret) goto err; - ret = dict_set_int32(state->xdata, QUOTA_LIMIT_OBJECTS_KEY, 42); + ret = dict_set_int32n(state->xdata, QUOTA_LIMIT_OBJECTS_KEY, + SLEN(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_int32(state->xdata, QUOTA_SIZE_KEY, 42); + ret = dict_set_int32n(state->xdata, QUOTA_SIZE_KEY, SLEN(QUOTA_SIZE_KEY), + 42); if (ret) goto err; - ret = dict_set_int32(state->xdata, GET_ANCESTRY_PATH_KEY, 42); + ret = dict_set_int32n(state->xdata, GET_ANCESTRY_PATH_KEY, + SLEN(GET_ANCESTRY_PATH_KEY), 42); if (ret) goto err; @@ -385,16 +389,21 @@ quotad_aggregator_init(xlator_t *this) return 0; } - ret = dict_set_str(this->options, "transport.address-family", "unix"); + ret = dict_set_nstrn(this->options, "transport.address-family", + SLEN("transport.address-family"), "unix", + SLEN("unix")); if (ret) goto out; - ret = dict_set_str(this->options, "transport-type", "socket"); + ret = dict_set_nstrn(this->options, "transport-type", + SLEN("transport-type"), "socket", SLEN("socket")); if (ret) goto out; - ret = dict_set_str(this->options, "transport.socket.listen-path", - "/var/run/gluster/quotad.socket"); + ret = dict_set_nstrn(this->options, "transport.socket.listen-path", + SLEN("transport.socket.listen-path"), + "/var/run/gluster/quotad.socket", + SLEN("/var/run/gluster/quotad.socket")); if (ret) goto out; diff --git a/xlators/features/quota/src/quotad.c b/xlators/features/quota/src/quotad.c index 1b61468f183..5b0ab83673b 100644 --- a/xlators/features/quota/src/quotad.c +++ b/xlators/features/quota/src/quotad.c @@ -81,14 +81,16 @@ qd_find_subvol(xlator_t *this, char *volume_uuid) xlator_list_t *child = NULL; xlator_t *subvol = NULL; char key[1024]; + int keylen = 0; char *optstr = NULL; if (!this || !volume_uuid) goto out; for (child = this->children; child; child = child->next) { - snprintf(key, 1024, "%s.volume-id", child->xlator->name); - if (dict_get_str(this->options, key, &optstr) < 0) + keylen = snprintf(key, sizeof(key), "%s.volume-id", + child->xlator->name); + if (dict_get_strn(this->options, key, keylen, &optstr) < 0) continue; if (strcmp(optstr, volume_uuid) == 0) { @@ -128,7 +130,8 @@ qd_nameless_lookup(xlator_t *this, call_frame_t *frame, gfs3_lookup_req *req, memcpy(loc.gfid, req->gfid, 16); - ret = dict_get_str(xdata, "volume-uuid", &volume_uuid); + ret = dict_get_strn(xdata, "volume-uuid", SLEN("volume-uuid"), + &volume_uuid); if (ret < 0) { op_errno = EINVAL; goto out; |