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
This commit is contained in:
Yaniv Kaul 2018-09-23 11:04:22 +03:00 committed by Amar Tumballi
parent 064b24900e
commit 341ba81448
13 changed files with 134 additions and 78 deletions

View File

@ -109,16 +109,21 @@ cli_quotad_clnt_init(xlator_t *this, dict_t *options)
struct rpc_clnt *rpc = NULL;
int ret = -1;
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;

View File

@ -3812,9 +3812,11 @@ print_quota_list_from_quotad(call_frame_t *frame, dict_t *rsp_dict)
limits.sl = ntoh64(size_limits->sl);
if (type == GF_QUOTA_OPTION_TYPE_LIST)
ret = quota_dict_get_meta(rsp_dict, QUOTA_SIZE_KEY, &used_space);
ret = quota_dict_get_meta(rsp_dict, QUOTA_SIZE_KEY,
SLEN(QUOTA_SIZE_KEY), &used_space);
else
ret = quota_dict_get_inode_meta(rsp_dict, QUOTA_SIZE_KEY, &used_space);
ret = quota_dict_get_inode_meta(rsp_dict, QUOTA_SIZE_KEY,
SLEN(QUOTA_SIZE_KEY), &used_space);
if (ret < 0) {
gf_log("cli", GF_LOG_WARNING, "size key not present in dict");

View File

@ -25,13 +25,13 @@ quota_meta_is_null(const quota_meta_t *meta)
}
int32_t
quota_data_to_meta(data_t *data, char *key, quota_meta_t *meta)
quota_data_to_meta(data_t *data, quota_meta_t *meta)
{
int32_t ret = -1;
quota_meta_t *value = NULL;
int64_t *size = NULL;
if (!data || !key || !meta)
if (!data || !meta)
goto out;
if (data->len > sizeof(int64_t)) {
@ -66,7 +66,8 @@ out:
}
int32_t
quota_dict_get_inode_meta(dict_t *dict, char *key, quota_meta_t *meta)
quota_dict_get_inode_meta(dict_t *dict, char *key, const int keylen,
quota_meta_t *meta)
{
int32_t ret = -1;
data_t *data = NULL;
@ -74,11 +75,11 @@ quota_dict_get_inode_meta(dict_t *dict, char *key, quota_meta_t *meta)
if (!dict || !key || !meta)
goto out;
data = dict_get(dict, key);
data = dict_getn(dict, key, keylen);
if (!data || !data->data)
goto out;
ret = quota_data_to_meta(data, key, meta);
ret = quota_data_to_meta(data, meta);
out:
@ -86,11 +87,12 @@ out:
}
int32_t
quota_dict_get_meta(dict_t *dict, char *key, quota_meta_t *meta)
quota_dict_get_meta(dict_t *dict, char *key, const int keylen,
quota_meta_t *meta)
{
int32_t ret = -1;
ret = quota_dict_get_inode_meta(dict, key, meta);
ret = quota_dict_get_inode_meta(dict, key, keylen, meta);
if (ret == -2)
ret = 0;

View File

@ -39,13 +39,15 @@ gf_boolean_t
quota_meta_is_null(const quota_meta_t *meta);
int32_t
quota_data_to_meta(data_t *data, char *key, quota_meta_t *meta);
quota_data_to_meta(data_t *data, quota_meta_t *meta);
int32_t
quota_dict_get_inode_meta(dict_t *dict, char *key, quota_meta_t *meta);
quota_dict_get_inode_meta(dict_t *dict, char *key, const int keylen,
quota_meta_t *meta);
int32_t
quota_dict_get_meta(dict_t *dict, char *key, quota_meta_t *meta);
quota_dict_get_meta(dict_t *dict, char *key, const int keylen,
quota_meta_t *meta);
int32_t
quota_dict_set_meta(dict_t *dict, char *key, const quota_meta_t *meta,

View File

@ -77,7 +77,8 @@ afr_handle_quota_size(call_frame_t *frame, xlator_t *this)
continue;
if (!replies[i].xdata)
continue;
ret = quota_dict_get_meta(replies[i].xdata, QUOTA_SIZE_KEY, &size);
ret = quota_dict_get_meta(replies[i].xdata, QUOTA_SIZE_KEY,
SLEN(QUOTA_SIZE_KEY), &size);
if (ret == -1)
continue;
if (read_subvol == -1)

View File

@ -684,7 +684,7 @@ ec_dict_data_quota(ec_cbk_data_t *cbk, int32_t which, char *key)
*/
for (i = 0; i < ec->nodes; i++) {
if ((data[i] == NULL) || (data[i] == EC_MISSING_DATA) ||
(quota_data_to_meta(data[i], QUOTA_SIZE_KEY, &size) < 0)) {
(quota_data_to_meta(data[i], &size) < 0)) {
continue;
}

View File

@ -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 {

View File

@ -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),

View File

@ -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;

View File

@ -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 "

View File

@ -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)

View File

@ -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;

View File

@ -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;