summaryrefslogtreecommitdiffstats
path: root/xlators/features/quota
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
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')
-rw-r--r--xlators/features/quota/src/quota-enforcer-client.c19
-rw-r--r--xlators/features/quota/src/quota.c32
-rw-r--r--xlators/features/quota/src/quota.h3
-rw-r--r--xlators/features/quota/src/quotad-aggregator.c31
-rw-r--r--xlators/features/quota/src/quotad.c9
5 files changed, 62 insertions, 32 deletions
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 = &quota_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;