summaryrefslogtreecommitdiffstats
path: root/xlators/features/quota/src/quota.c
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-09-23 11:04:22 +0300
committerAmar Tumballi <amarts@redhat.com>2018-09-26 04:17:30 +0000
commit341ba81448e869ae388b4b37556e47f6bf7413a5 (patch)
tree2867552e09e07d4320fc9cefb96a9533fc719658 /xlators/features/quota/src/quota.c
parent064b24900e1f5e3ba3087f7c6a0249613ebed61f (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/quota/src/quota.c')
-rw-r--r--xlators/features/quota/src/quota.c32
1 files changed, 21 insertions, 11 deletions
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 "