summaryrefslogtreecommitdiffstats
path: root/xlators/cluster
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-09-13 16:03:23 +0300
committerPranith Kumar Karampuri <pkarampu@redhat.com>2018-12-17 11:39:14 +0000
commit403c69d35827b6cbb430e97a797c318cca81e86e (patch)
treecd994bb5b8f133a1d8b1aa56d5c17deb3e91fae0 /xlators/cluster
parentf0c46df09fe542d6a365adc0c544ba460598501c (diff)
AFR xlator: 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 xlators to use it. - In some cases, moved strlen() of the key length outside of locks, which is usually a good thing. Please verify it's safe to do so. - In some cases, created a prefix for the keys, replacing something like "%d-%d" with a "%s" in snprintf(). Not sure it adds value, but improves readability. Please review carefully. Compile-tested only! Change-Id: I04f2a1eb2ecfc3283d849d150d10d088ae7aa7f1 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'xlators/cluster')
-rw-r--r--xlators/cluster/afr/src/afr-common.c115
-rw-r--r--xlators/cluster/afr/src/afr-dir-write.c2
-rw-r--r--xlators/cluster/afr/src/afr-inode-read.c114
-rw-r--r--xlators/cluster/afr/src/afr-inode-write.c30
-rw-r--r--xlators/cluster/afr/src/afr-self-heal-common.c71
-rw-r--r--xlators/cluster/afr/src/afr-self-heal-data.c2
-rw-r--r--xlators/cluster/afr/src/afr-self-heal-entry.c4
-rw-r--r--xlators/cluster/afr/src/afr-self-heal-name.c7
-rw-r--r--xlators/cluster/afr/src/afr-self-heal.h21
-rw-r--r--xlators/cluster/afr/src/afr-self-heald.c108
-rw-r--r--xlators/cluster/afr/src/afr-transaction.c9
-rw-r--r--xlators/cluster/afr/src/afr.c2
12 files changed, 282 insertions, 203 deletions
diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c
index 9137c595d37..5656cec4226 100644
--- a/xlators/cluster/afr/src/afr-common.c
+++ b/xlators/cluster/afr/src/afr-common.c
@@ -98,21 +98,24 @@ afr_is_possibly_under_txn(afr_transaction_type type, afr_local_t *local,
int tmp = 0;
afr_private_t *priv = NULL;
GF_UNUSED char *key = NULL;
+ int keylen = 0;
priv = this->private;
- if (type == AFR_ENTRY_TRANSACTION)
+ if (type == AFR_ENTRY_TRANSACTION) {
key = GLUSTERFS_PARENT_ENTRYLK;
- else if (type == AFR_DATA_TRANSACTION)
+ keylen = SLEN(GLUSTERFS_PARENT_ENTRYLK);
+ } else if (type == AFR_DATA_TRANSACTION) {
/*FIXME: Use GLUSTERFS_INODELK_DOM_COUNT etc. once
* pl_inodelk_xattr_fill supports separate keys for different
* domains.*/
key = GLUSTERFS_INODELK_COUNT;
-
+ keylen = SLEN(GLUSTERFS_INODELK_COUNT);
+ }
for (i = 0; i < priv->child_count; i++) {
if (!local->replies[i].xdata)
continue;
- if (dict_get_int32(local->replies[i].xdata, key, &tmp) == 0)
+ if (dict_get_int32n(local->replies[i].xdata, key, keylen, &tmp) == 0)
if (tmp)
return _gf_true;
}
@@ -988,7 +991,7 @@ afr_accuse_smallfiles(xlator_t *this, struct afr_reply *replies,
for (i = 0; i < priv->child_count; i++) {
if (replies[i].valid && replies[i].xdata &&
- dict_get(replies[i].xdata, GLUSTERFS_BAD_INODE))
+ dict_get_sizen(replies[i].xdata, GLUSTERFS_BAD_INODE))
continue;
if (data_accused[i])
continue;
@@ -1037,7 +1040,7 @@ afr_readables_fill(call_frame_t *frame, xlator_t *this, inode_t *inode,
if (replies) { /* Lookup */
if (!replies[i].valid || replies[i].op_ret == -1 ||
(replies[i].xdata &&
- dict_get(replies[i].xdata, GLUSTERFS_BAD_INODE))) {
+ dict_get_sizen(replies[i].xdata, GLUSTERFS_BAD_INODE))) {
data_readable[i] = 0;
metadata_readable[i] = 0;
continue;
@@ -1452,12 +1455,12 @@ afr_inode_refresh_do(call_frame_t *frame, xlator_t *this)
return 0;
}
- ret = dict_set_str(xdata, "link-count", GF_XATTROP_INDEX_COUNT);
+ ret = dict_set_sizen_str_sizen(xdata, "link-count", GF_XATTROP_INDEX_COUNT);
if (ret) {
gf_msg_debug(this->name, -ret, "Unable to set link-count in dict ");
}
- ret = dict_set_str(xdata, GLUSTERFS_INODELK_DOM_COUNT, this->name);
+ ret = dict_set_str_sizen(xdata, GLUSTERFS_INODELK_DOM_COUNT, this->name);
if (ret) {
gf_msg_debug(this->name, -ret,
"Unable to set inodelk-dom-count in dict ");
@@ -1555,7 +1558,7 @@ afr_xattr_req_prepare(xlator_t *this, dict_t *xattr_req)
"query flag");
}
- ret = dict_set_int32(xattr_req, "list-xattr", 1);
+ ret = dict_set_int32_sizen(xattr_req, "list-xattr", 1);
if (ret) {
gf_msg_debug(this->name, -ret, "Unable to set list-xattr in dict ");
}
@@ -1600,7 +1603,8 @@ afr_lookup_xattr_req_prepare(afr_local_t *local, xlator_t *this,
GLUSTERFS_PARENT_ENTRYLK);
}
- ret = dict_set_str(local->xattr_req, "link-count", GF_XATTROP_INDEX_COUNT);
+ ret = dict_set_sizen_str_sizen(local->xattr_req, "link-count",
+ GF_XATTROP_INDEX_COUNT);
if (ret) {
gf_msg_debug(this->name, -ret, "Unable to set link-count in dict ");
}
@@ -2270,7 +2274,7 @@ afr_attempt_readsubvol_set(call_frame_t *frame, xlator_t *this,
local->loc.path);
}
if (*read_subvol >= 0)
- dict_del(local->replies[*read_subvol].xdata, GF_CONTENT_KEY);
+ dict_del_sizen(local->replies[*read_subvol].xdata, GF_CONTENT_KEY);
}
static void
@@ -2382,7 +2386,8 @@ afr_lookup_done(call_frame_t *frame, xlator_t *this)
/* If we were called from glfsheal and there is still a gfid
* mismatch, succeed the lookup and let glfsheal print the
* response via gfid-heal-msg.*/
- if (!dict_get_str(local->xattr_req, "gfid-heal-msg", &gfid_heal_msg))
+ if (!dict_get_str_sizen(local->xattr_req, "gfid-heal-msg",
+ &gfid_heal_msg))
goto cant_interpret;
/* LOG ERROR */
@@ -2412,7 +2417,7 @@ afr_lookup_done(call_frame_t *frame, xlator_t *this)
goto cant_interpret;
if (ret) {
afr_inode_event_gen_reset(local->inode, this);
- dict_del(local->replies[read_subvol].xdata, GF_CONTENT_KEY);
+ dict_del_sizen(local->replies[read_subvol].xdata, GF_CONTENT_KEY);
}
} else {
cant_interpret:
@@ -2436,10 +2441,10 @@ afr_lookup_done(call_frame_t *frame, xlator_t *this)
goto error;
}
- ret = dict_get_str(local->xattr_req, "gfid-heal-msg", &gfid_heal_msg);
+ ret = dict_get_str_sizen(local->xattr_req, "gfid-heal-msg", &gfid_heal_msg);
if (!ret) {
- ret = dict_set_str(local->replies[read_subvol].xdata, "gfid-heal-msg",
- gfid_heal_msg);
+ ret = dict_set_str_sizen(local->replies[read_subvol].xdata,
+ "gfid-heal-msg", gfid_heal_msg);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_DICT_SET_FAILED,
"Error setting gfid-heal-msg dict");
@@ -2517,7 +2522,7 @@ afr_local_discovery_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
priv = this->private;
child_index = (int32_t)(long)cookie;
- ret = dict_get_str(dict, GF_XATTR_PATHINFO_KEY, &pathinfo);
+ ret = dict_get_str_sizen(dict, GF_XATTR_PATHINFO_KEY, &pathinfo);
if (ret != 0) {
goto out;
}
@@ -2605,7 +2610,7 @@ afr_lookup_sh_metadata_wrap(void *opaque)
dict = dict_new();
if (!dict)
goto out;
- ret = dict_set_str(dict, "link-count", GF_XATTROP_INDEX_COUNT);
+ ret = dict_set_sizen_str_sizen(dict, "link-count", GF_XATTROP_INDEX_COUNT);
if (ret) {
gf_msg_debug(this->name, -ret, "Unable to set link-count in dict ");
}
@@ -2932,7 +2937,7 @@ afr_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
* with ESTALE so that a fresh lookup will be sent by the top xlator.
* So remember it.
*/
- if (xdata && dict_get(xdata, "gfid-changed"))
+ if (xdata && dict_get_sizen(xdata, "gfid-changed"))
local->cont.lookup.needs_fresh_lookup = _gf_true;
if (xdata) {
@@ -3342,7 +3347,7 @@ afr_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req)
if (loc_is_nameless(loc)) {
if (xattr_req)
- dict_del(xattr_req, "gfid-req");
+ dict_del_sizen(xattr_req, "gfid-req");
afr_discover(frame, this, loc, xattr_req);
return 0;
}
@@ -3380,7 +3385,7 @@ afr_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req)
ret = dict_get_gfuuid(local->xattr_req, "gfid-req",
&local->cont.lookup.gfid_req);
if (ret == 0) {
- dict_del(local->xattr_req, "gfid-req");
+ dict_del_sizen(local->xattr_req, "gfid-req");
}
}
@@ -6129,8 +6134,8 @@ out:
return ret;
}
-dict_t *
-afr_set_heal_info(char *status)
+static dict_t *
+afr_set_heal_info(char *status, const int status_len)
{
dict_t *dict = NULL;
int ret = -1;
@@ -6141,7 +6146,8 @@ afr_set_heal_info(char *status)
goto out;
}
- ret = dict_set_dynstr(dict, "heal-info", status);
+ ret = dict_set_nstrn(dict, "heal-info", SLEN("heal-info"), status,
+ status_len);
if (ret)
gf_msg("", GF_LOG_WARNING, -ret, AFR_MSG_DICT_SET_FAILED,
"Failed to set heal-info key to "
@@ -6173,6 +6179,7 @@ afr_get_heal_info(call_frame_t *frame, xlator_t *this, loc_t *loc)
inode_t *inode = NULL;
char *substr = NULL;
char *status = NULL;
+ int status_len = 0;
ret = afr_selfheal_locked_inspect(frame, this, loc->gfid, &inode,
&entry_selfheal, &data_selfheal,
@@ -6190,19 +6197,25 @@ afr_get_heal_info(call_frame_t *frame, xlator_t *this, loc_t *loc)
}
if (ret == -EIO) {
- ret = gf_asprintf(&status, "split-brain%s", substr ? substr : "");
- if (ret < 0)
+ status_len = gf_asprintf(&status, "split-brain%s",
+ substr ? substr : "");
+ if (status_len < 0) {
+ ret = status_len;
goto out;
- dict = afr_set_heal_info(status);
+ }
+ dict = afr_set_heal_info(status, status_len);
if (!dict) {
ret = -1;
goto out;
}
} else if (ret == -EAGAIN) {
- ret = gf_asprintf(&status, "possibly-healing%s", substr ? substr : "");
- if (ret < 0)
+ status_len = gf_asprintf(&status, "possibly-healing%s",
+ substr ? substr : "");
+ if (status_len < 0) {
+ ret = status_len;
goto out;
- dict = afr_set_heal_info(status);
+ }
+ dict = afr_set_heal_info(status, status_len);
if (!dict) {
ret = -1;
goto out;
@@ -6218,16 +6231,18 @@ afr_get_heal_info(call_frame_t *frame, xlator_t *this, loc_t *loc)
ret = -1;
goto out;
}
- dict = afr_set_heal_info(status);
+ dict = afr_set_heal_info(status, strlen(status));
if (!dict) {
ret = -1;
goto out;
}
} else {
- ret = gf_asprintf(&status, "heal%s", substr ? substr : "");
- if (ret < 0)
+ status_len = gf_asprintf(&status, "heal%s", substr ? substr : "");
+ if (status_len < 0) {
+ ret = status_len;
goto out;
- dict = afr_set_heal_info(status);
+ }
+ dict = afr_set_heal_info(status, status_len);
if (!dict) {
ret = -1;
goto out;
@@ -6242,10 +6257,12 @@ afr_get_heal_info(call_frame_t *frame, xlator_t *this, loc_t *loc)
* selfheal booleans is set.
*/
if (data_selfheal || entry_selfheal || metadata_selfheal) {
- ret = gf_asprintf(&status, "heal%s", substr ? substr : "");
- if (ret < 0)
+ status_len = gf_asprintf(&status, "heal%s", substr ? substr : "");
+ if (status_len < 0) {
+ ret = status_len;
goto out;
- dict = afr_set_heal_info(status);
+ }
+ dict = afr_set_heal_info(status, status_len);
if (!dict) {
ret = -1;
goto out;
@@ -6378,10 +6395,10 @@ afr_get_split_brain_status(void *opaque)
}
/* Calculation for string length :
- * (child_count X length of child-name) + SLEN (" Choices :")
+ * (child_count X length of child-name) + SLEN(" Choices :")
* child-name consists of :
* a) 251 = max characters for volname according to GD_VOLUME_NAME_MAX
- * b) strlen ("-client-00,") assuming 16 replicas
+ * b) strlen("-client-00,") assuming 16 replicas
*/
choices = alloca0(priv->child_count * (256 + SLEN("-client-00,")) +
SLEN(" Choices:"));
@@ -6390,8 +6407,8 @@ afr_get_split_brain_status(void *opaque)
if (ret) {
op_errno = -ret;
if (ret == -EAGAIN) {
- ret = dict_set_str(dict, GF_AFR_SBRAIN_STATUS,
- SBRAIN_HEAL_NO_GO_MSG);
+ ret = dict_set_sizen_str_sizen(dict, GF_AFR_SBRAIN_STATUS,
+ SBRAIN_HEAL_NO_GO_MSG);
if (ret) {
gf_msg(this->name, GF_LOG_WARNING, -ret,
AFR_MSG_DICT_SET_FAILED,
@@ -6420,16 +6437,15 @@ afr_get_split_brain_status(void *opaque)
op_errno = ENOMEM;
goto out;
}
- ret = dict_set_dynstr(dict, GF_AFR_SBRAIN_STATUS, status);
+ ret = dict_set_dynstr_sizen(dict, GF_AFR_SBRAIN_STATUS, status);
if (ret) {
op_errno = -ret;
ret = -1;
goto out;
}
} else {
- ret = dict_set_str(dict, GF_AFR_SBRAIN_STATUS,
- "The file is not under data or"
- " metadata split-brain");
+ ret = dict_set_sizen_str_sizen(dict, GF_AFR_SBRAIN_STATUS,
+ SFILE_NOT_UNDER_DATA);
if (ret) {
op_errno = -ret;
ret = -1;
@@ -6466,7 +6482,8 @@ afr_heal_splitbrain_file(call_frame_t *frame, xlator_t *this, loc_t *loc)
ret = afr_selfheal_do(frame, this, loc->gfid);
if (ret == 1 || ret == 2) {
- ret = dict_set_str(dict, "sh-fail-msg", "File not in split-brain");
+ ret = dict_set_sizen_str_sizen(dict, "sh-fail-msg",
+ SFILE_NOT_IN_SPLIT_BRAIN);
if (ret)
gf_msg(this->name, GF_LOG_WARNING, -ret, AFR_MSG_DICT_SET_FAILED,
"Failed to set sh-fail-msg in dict");
@@ -6670,12 +6687,14 @@ afr_serialize_xattrs_with_delimiter(call_frame_t *frame, xlator_t *this,
char *xattr = NULL;
int i = 0;
int len = 0;
+ int keylen = 0;
size_t str_len = 0;
int ret = -1;
priv = this->private;
local = frame->local;
+ keylen = strlen(local->cont.getxattr.name);
for (i = 0; i < priv->child_count; i++) {
if (!local->replies[i].valid || local->replies[i].op_ret) {
str_len = strlen(default_str);
@@ -6684,8 +6703,8 @@ afr_serialize_xattrs_with_delimiter(call_frame_t *frame, xlator_t *this,
buf[len++] = delimiter;
buf[len] = '\0';
} else {
- ret = dict_get_str(local->replies[i].xattr,
- local->cont.getxattr.name, &xattr);
+ ret = dict_get_strn(local->replies[i].xattr,
+ local->cont.getxattr.name, keylen, &xattr);
if (ret) {
gf_msg("TEST", GF_LOG_ERROR, -ret, AFR_MSG_DICT_GET_FAILED,
"Failed to get the node_uuid of brick "
diff --git a/xlators/cluster/afr/src/afr-dir-write.c b/xlators/cluster/afr/src/afr-dir-write.c
index ebfee94ae4c..486b06b162f 100644
--- a/xlators/cluster/afr/src/afr-dir-write.c
+++ b/xlators/cluster/afr/src/afr-dir-write.c
@@ -700,7 +700,7 @@ afr_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
local->cont.mkdir.mode = mode;
local->umask = umask;
- if (!xdata || !dict_get(xdata, "gfid-req")) {
+ if (!xdata || !dict_get_sizen(xdata, "gfid-req")) {
op_errno = EPERM;
gf_msg_callingfn(this->name, GF_LOG_WARNING, op_errno,
AFR_MSG_GFID_NULL,
diff --git a/xlators/cluster/afr/src/afr-inode-read.c b/xlators/cluster/afr/src/afr-inode-read.c
index a4de48eae34..1dcef5c44d2 100644
--- a/xlators/cluster/afr/src/afr-inode-read.c
+++ b/xlators/cluster/afr/src/afr-inode-read.c
@@ -531,12 +531,16 @@ afr_fgetxattr_clrlk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
int32_t callcnt = 0;
long int cky = 0;
int ret = 0;
+ int keylen = 0;
+ int children_keylen = 0;
priv = this->private;
children = priv->children;
local = frame->local;
cky = (long)cookie;
+ keylen = strlen(local->cont.getxattr.name);
+ children_keylen = strlen(children[cky]->name);
LOCK(&frame->lock);
{
@@ -547,11 +551,12 @@ afr_fgetxattr_clrlk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
if (!local->dict)
local->dict = dict_new();
if (local->dict) {
- ret = dict_get_str(dict, local->cont.getxattr.name, &tmp_report);
+ ret = dict_get_strn(dict, local->cont.getxattr.name, keylen,
+ &tmp_report);
if (ret)
goto unlock;
- ret = dict_set_dynstr(local->dict, children[cky]->name,
- gf_strdup(tmp_report));
+ ret = dict_set_dynstrn(local->dict, children[cky]->name,
+ children_keylen, gf_strdup(tmp_report));
if (ret)
goto unlock;
}
@@ -575,8 +580,8 @@ unlock:
}
if (serz_len == -1)
snprintf(lk_summary, sizeof(lk_summary), "No locks cleared.");
- ret = dict_set_dynstr(xattr, local->cont.getxattr.name,
- gf_strdup(lk_summary));
+ ret = dict_set_dynstrn(xattr, local->cont.getxattr.name, keylen,
+ gf_strdup(lk_summary));
if (ret) {
op_ret = -1;
op_errno = ENOMEM;
@@ -613,6 +618,8 @@ afr_getxattr_clrlk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
int32_t callcnt = 0;
long int cky = 0;
int ret = 0;
+ int keylen = 0;
+ int children_keylen = 0;
priv = this->private;
children = priv->children;
@@ -620,6 +627,9 @@ afr_getxattr_clrlk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
local = frame->local;
cky = (long)cookie;
+ keylen = strlen(local->cont.getxattr.name);
+ children_keylen = strlen(children[cky]->name);
+
LOCK(&frame->lock);
{
callcnt = --local->call_count;
@@ -629,11 +639,12 @@ afr_getxattr_clrlk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
if (!local->dict)
local->dict = dict_new();
if (local->dict) {
- ret = dict_get_str(dict, local->cont.getxattr.name, &tmp_report);
+ ret = dict_get_strn(dict, local->cont.getxattr.name, keylen,
+ &tmp_report);
if (ret)
goto unlock;
- ret = dict_set_dynstr(local->dict, children[cky]->name,
- gf_strdup(tmp_report));
+ ret = dict_set_dynstrn(local->dict, children[cky]->name,
+ children_keylen, gf_strdup(tmp_report));
if (ret)
goto unlock;
}
@@ -657,8 +668,8 @@ unlock:
}
if (serz_len == -1)
snprintf(lk_summary, sizeof(lk_summary), "No locks cleared.");
- ret = dict_set_dynstr(xattr, local->cont.getxattr.name,
- gf_strdup(lk_summary));
+ ret = dict_set_dynstrn(xattr, local->cont.getxattr.name, keylen,
+ gf_strdup(lk_summary));
if (ret) {
op_ret = -1;
op_errno = ENOMEM;
@@ -805,8 +816,8 @@ unlock:
GF_FREE(xattr_serz);
goto unwind;
}
- ret = dict_set_dynstr(local->dict, GF_XATTR_LIST_NODE_UUIDS_KEY,
- xattr_serz);
+ ret = dict_set_dynstr_sizen(local->dict, GF_XATTR_LIST_NODE_UUIDS_KEY,
+ xattr_serz);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
"Cannot set node_uuid key in dict");
@@ -1099,9 +1110,11 @@ afr_fgetxattr_pathinfo_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
int ret = 0;
char *xattr = NULL;
char *xattr_serz = NULL;
+ int keylen = 0;
char xattr_cky[1024] = {
0,
};
+ int xattr_cky_len = 0;
dict_t *nxattr = NULL;
long cky = 0;
int32_t padding = 0;
@@ -1114,7 +1127,9 @@ afr_fgetxattr_pathinfo_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
local = frame->local;
cky = (long)cookie;
-
+ keylen = strlen(local->cont.getxattr.name);
+ xattr_cky_len = snprintf(xattr_cky, sizeof(xattr_cky), "%s-%ld",
+ local->cont.getxattr.name, cky);
LOCK(&frame->lock);
{
callcnt = --local->call_count;
@@ -1130,27 +1145,25 @@ afr_fgetxattr_pathinfo_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
if (!dict || (op_ret < 0))
goto unlock;
- if (!local->dict)
+ if (!local->dict) {
local->dict = dict_new();
-
- if (local->dict) {
- ret = dict_get_str(dict, local->cont.getxattr.name, &xattr);
- if (ret)
+ if (!local->dict)
goto unlock;
+ }
+ ret = dict_get_strn(dict, local->cont.getxattr.name, keylen, &xattr);
+ if (ret)
+ goto unlock;
- xattr = gf_strdup(xattr);
-
- (void)snprintf(xattr_cky, sizeof(xattr_cky), "%s-%ld",
- local->cont.getxattr.name, cky);
- ret = dict_set_dynstr(local->dict, xattr_cky, xattr);
- if (ret) {
- gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
- "Cannot set xattr cookie key");
- goto unlock;
- }
+ xattr = gf_strdup(xattr);
- local->cont.getxattr.xattr_len += strlen(xattr) + 1;
+ ret = dict_set_dynstrn(local->dict, xattr_cky, xattr_cky_len, xattr);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
+ "Cannot set xattr cookie key");
+ goto unlock;
}
+
+ local->cont.getxattr.xattr_len += strlen(xattr) + 1;
}
unlock:
UNLOCK(&frame->lock);
@@ -1189,7 +1202,8 @@ unlock:
*(xattr_serz + padding + tlen) = ')';
*(xattr_serz + padding + tlen + 1) = '\0';
- ret = dict_set_dynstr(nxattr, local->cont.getxattr.name, xattr_serz);
+ ret = dict_set_dynstrn(nxattr, local->cont.getxattr.name, keylen,
+ xattr_serz);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
"Cannot set pathinfo key in dict");
@@ -1222,6 +1236,8 @@ afr_getxattr_pathinfo_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
char xattr_cky[1024] = {
0,
};
+ int keylen = 0;
+ int xattr_cky_len = 0;
dict_t *nxattr = NULL;
long cky = 0;
int32_t padding = 0;
@@ -1234,7 +1250,9 @@ afr_getxattr_pathinfo_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
local = frame->local;
cky = (long)cookie;
-
+ keylen = strlen(local->cont.getxattr.name);
+ xattr_cky_len = snprintf(xattr_cky, sizeof(xattr_cky), "%s-%ld",
+ local->cont.getxattr.name, cky);
LOCK(&frame->lock);
{
callcnt = --local->call_count;
@@ -1250,28 +1268,25 @@ afr_getxattr_pathinfo_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
if (!dict || (op_ret < 0))
goto unlock;
- if (!local->dict)
+ if (!local->dict) {
local->dict = dict_new();
-
- if (local->dict) {
- ret = dict_get_str(dict, local->cont.getxattr.name, &xattr);
- if (ret)
+ if (!local->dict)
goto unlock;
+ }
+ ret = dict_get_strn(dict, local->cont.getxattr.name, keylen, &xattr);
+ if (ret)
+ goto unlock;
- xattr = gf_strdup(xattr);
-
- (void)snprintf(xattr_cky, 1024, "%s-%ld", local->cont.getxattr.name,
- cky);
- ret = dict_set_dynstr(local->dict, xattr_cky, xattr);
- if (ret) {
- gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
- "Cannot set xattr "
- "cookie key");
- goto unlock;
- }
+ xattr = gf_strdup(xattr);
- local->cont.getxattr.xattr_len += strlen(xattr) + 1;
+ ret = dict_set_dynstrn(local->dict, xattr_cky, xattr_cky_len, xattr);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
+ "Cannot set xattr cookie key");
+ goto unlock;
}
+
+ local->cont.getxattr.xattr_len += strlen(xattr) + 1;
}
unlock:
UNLOCK(&frame->lock);
@@ -1310,7 +1325,8 @@ unlock:
*(xattr_serz + padding + tlen) = ')';
*(xattr_serz + padding + tlen + 1) = '\0';
- ret = dict_set_dynstr(nxattr, local->cont.getxattr.name, xattr_serz);
+ ret = dict_set_dynstrn(nxattr, local->cont.getxattr.name, keylen,
+ xattr_serz);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
"Cannot set pathinfo key in dict");
diff --git a/xlators/cluster/afr/src/afr-inode-write.c b/xlators/cluster/afr/src/afr-inode-write.c
index 68d68a356b3..4f6e6a906dc 100644
--- a/xlators/cluster/afr/src/afr-inode-write.c
+++ b/xlators/cluster/afr/src/afr-inode-write.c
@@ -1059,7 +1059,7 @@ afr_emptyb_set_pending_changelog_cbk(call_frame_t *frame, void *cookie,
local->replies[i].op_ret = op_ret;
local->replies[i].op_errno = op_errno;
- ret = dict_get_str(local->xdata_req, "replicate-brick-op", &op_type);
+ ret = dict_get_str_sizen(local->xdata_req, "replicate-brick-op", &op_type);
if (ret)
goto out;
@@ -1105,10 +1105,10 @@ out:
return -ret;
}
-int
+static int
_afr_handle_empty_brick_type(xlator_t *this, call_frame_t *frame, loc_t *loc,
int empty_index, afr_transaction_type type,
- char *op_type)
+ char *op_type, const int op_type_len)
{
int count = 0;
int ret = -ENOMEM;
@@ -1139,7 +1139,8 @@ _afr_handle_empty_brick_type(xlator_t *this, call_frame_t *frame, loc_t *loc,
if (!local->xdata_req)
goto out;
- ret = dict_set_str(local->xdata_req, "replicate-brick-op", op_type);
+ ret = dict_set_nstrn(local->xdata_req, "replicate-brick-op",
+ SLEN("replicate-brick-op"), op_type, op_type_len);
if (ret)
goto out;
@@ -1211,12 +1212,17 @@ _afr_handle_empty_brick(void *opaque)
call_frame_t *frame = NULL;
xlator_t *this = NULL;
char *op_type = NULL;
+ int op_type_len = 0;
afr_empty_brick_args_t *data = NULL;
data = opaque;
frame = data->frame;
empty_index = data->empty_index;
+ if (!data->op_type)
+ goto out;
+
op_type = data->op_type;
+ op_type_len = strlen(op_type);
this = frame->this;
priv = this->private;
@@ -1230,7 +1236,8 @@ _afr_handle_empty_brick(void *opaque)
priv->children[empty_index]->name);
ret = _afr_handle_empty_brick_type(this, frame, &local->loc, empty_index,
- AFR_METADATA_TRANSACTION, op_type);
+ AFR_METADATA_TRANSACTION, op_type,
+ op_type_len);
if (ret) {
op_errno = -ret;
ret = -1;
@@ -1245,7 +1252,8 @@ _afr_handle_empty_brick(void *opaque)
local->xdata_req = NULL;
ret = _afr_handle_empty_brick_type(this, frame, &local->loc, empty_index,
- AFR_ENTRY_TRANSACTION, op_type);
+ AFR_ENTRY_TRANSACTION, op_type,
+ op_type_len);
if (ret) {
op_errno = -ret;
ret = -1;
@@ -1273,14 +1281,14 @@ afr_split_brain_resolve_do(call_frame_t *frame, xlator_t *this, loc_t *loc,
goto out;
}
- ret = dict_set_int32(local->xdata_req, "heal-op",
- GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK);
+ ret = dict_set_int32_sizen(local->xdata_req, "heal-op",
+ GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK);
if (ret) {
op_errno = -ret;
ret = -1;
goto out;
}
- ret = dict_set_str(local->xdata_req, "child-name", data);
+ ret = dict_set_str_sizen(local->xdata_req, "child-name", data);
if (ret) {
op_errno = -ret;
ret = -1;
@@ -1470,11 +1478,11 @@ afr_handle_empty_brick(xlator_t *this, call_frame_t *frame, loc_t *loc,
char *op_type = NULL;
afr_empty_brick_args_t *data = NULL;
- ret = dict_get_str(dict, GF_AFR_REPLACE_BRICK, &empty_brick);
+ ret = dict_get_str_sizen(dict, GF_AFR_REPLACE_BRICK, &empty_brick);
if (!ret)
op_type = GF_AFR_REPLACE_BRICK;
- ab_ret = dict_get_str(dict, GF_AFR_ADD_BRICK, &empty_brick);
+ ab_ret = dict_get_str_sizen(dict, GF_AFR_ADD_BRICK, &empty_brick);
if (!ab_ret)
op_type = GF_AFR_ADD_BRICK;
diff --git a/xlators/cluster/afr/src/afr-self-heal-common.c b/xlators/cluster/afr/src/afr-self-heal-common.c
index 7eaae914dce..c137bf8934f 100644
--- a/xlators/cluster/afr/src/afr-self-heal-common.c
+++ b/xlators/cluster/afr/src/afr-self-heal-common.c
@@ -263,10 +263,8 @@ afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies,
"All the bricks should be up to resolve the gfid split "
"barin");
if (xdata) {
- ret = dict_set_str(xdata, "gfid-heal-msg",
- "All the "
- "bricks should be up to resolve the"
- " gfid split barin");
+ ret = dict_set_sizen_str_sizen(xdata, "gfid-heal-msg",
+ SALL_BRICKS_UP_TO_RESOLVE);
if (ret)
gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_DICT_SET_FAILED,
"Error setting"
@@ -276,7 +274,7 @@ afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies,
}
if (xdata) {
- ret = dict_get_int32(xdata, "heal-op", &heal_op);
+ ret = dict_get_int32_sizen(xdata, "heal-op", &heal_op);
if (ret)
goto fav_child;
} else {
@@ -289,10 +287,10 @@ afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies,
priv->child_count);
if (*src == -1) {
gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_SPLIT_BRAIN,
- "No bigger file");
+ SNO_BIGGER_FILE);
if (xdata) {
- ret = dict_set_str(xdata, "gfid-heal-msg",
- "No bigger file");
+ ret = dict_set_sizen_str_sizen(xdata, "gfid-heal-msg",
+ SNO_BIGGER_FILE);
if (ret)
gf_msg(this->name, GF_LOG_ERROR, 0,
AFR_MSG_DICT_SET_FAILED,
@@ -307,10 +305,10 @@ afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies,
priv->child_count);
if (*src == -1) {
gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_SPLIT_BRAIN,
- "No difference in mtime");
+ SNO_DIFF_IN_MTIME);
if (xdata) {
- ret = dict_set_str(xdata, "gfid-heal-msg",
- "No difference in mtime");
+ ret = dict_set_sizen_str_sizen(xdata, "gfid-heal-msg",
+ SNO_DIFF_IN_MTIME);
if (ret)
gf_msg(this->name, GF_LOG_ERROR, 0,
AFR_MSG_DICT_SET_FAILED,
@@ -321,7 +319,7 @@ afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies,
break;
case GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK:
- ret = dict_get_str(xdata, "child-name", &src_brick);
+ ret = dict_get_str_sizen(xdata, "child-name", &src_brick);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_SPLIT_BRAIN,
"Error getting the source "
@@ -332,12 +330,10 @@ afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies,
src_brick);
if (*src == -1) {
gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_SPLIT_BRAIN,
- "Error getting the source "
- "brick");
+ SERROR_GETTING_SRC_BRICK);
if (xdata) {
- ret = dict_set_str(xdata, "gfid-heal-msg",
- "Error getting the source "
- "brick");
+ ret = dict_set_sizen_str_sizen(xdata, "gfid-heal-msg",
+ SERROR_GETTING_SRC_BRICK);
if (ret)
gf_msg(this->name, GF_LOG_ERROR, 0,
AFR_MSG_DICT_SET_FAILED,
@@ -909,7 +905,7 @@ afr_dict_contains_heal_op(call_frame_t *frame)
local = frame->local;
xdata_req = local->xdata_req;
- ret = dict_get_int32(xdata_req, "heal-op", &heal_op);
+ ret = dict_get_int32_sizen(xdata_req, "heal-op", &heal_op);
if (ret)
return _gf_false;
if (local->xdata_rsp == NULL) {
@@ -917,8 +913,8 @@ afr_dict_contains_heal_op(call_frame_t *frame)
if (!local->xdata_rsp)
return _gf_true;
}
- ret = dict_set_str(local->xdata_rsp, "sh-fail-msg",
- "File not in split-brain");
+ ret = dict_set_sizen_str_sizen(local->xdata_rsp, "sh-fail-msg",
+ SFILE_NOT_IN_SPLIT_BRAIN);
return _gf_true;
}
@@ -972,7 +968,8 @@ afr_mark_split_brain_source_sinks_by_heal_op(
xdata_rsp = local->xdata_rsp;
if (!afr_can_decide_split_brain_source_sinks(replies, priv->child_count)) {
- ret = dict_set_str(xdata_rsp, "sh-fail-msg", SBRAIN_HEAL_NO_GO_MSG);
+ ret = dict_set_sizen_str_sizen(xdata_rsp, "sh-fail-msg",
+ SBRAIN_HEAL_NO_GO_MSG);
ret = -1;
goto out;
}
@@ -983,16 +980,16 @@ afr_mark_split_brain_source_sinks_by_heal_op(
switch (heal_op) {
case GF_SHD_OP_SBRAIN_HEAL_FROM_BIGGER_FILE:
if (type == AFR_METADATA_TRANSACTION) {
- ret = dict_set_str(xdata_rsp, "sh-fail-msg",
- "Use source-brick option to"
- " heal metadata split-brain");
+ ret = dict_set_sizen_str_sizen(xdata_rsp, "sh-fail-msg",
+ SUSE_SOURCE_BRICK_TO_HEAL);
if (!ret)
ret = -1;
goto out;
}
afr_mark_largest_file_as_source(this, sources, replies);
if (AFR_COUNT(sources, priv->child_count) != 1) {
- ret = dict_set_str(xdata_rsp, "sh-fail-msg", "No bigger file");
+ ret = dict_set_sizen_str_sizen(xdata_rsp, "sh-fail-msg",
+ SNO_BIGGER_FILE);
if (!ret)
ret = -1;
goto out;
@@ -1000,36 +997,36 @@ afr_mark_split_brain_source_sinks_by_heal_op(
break;
case GF_SHD_OP_SBRAIN_HEAL_FROM_LATEST_MTIME:
if (type == AFR_METADATA_TRANSACTION) {
- ret = dict_set_str(xdata_rsp, "sh-fail-msg",
- "Use source-brick option to"
- " heal metadata split-brain");
+ ret = dict_set_sizen_str_sizen(xdata_rsp, "sh-fail-msg",
+ SUSE_SOURCE_BRICK_TO_HEAL);
if (!ret)
ret = -1;
goto out;
}
afr_mark_latest_mtime_file_as_source(this, sources, replies);
if (AFR_COUNT(sources, priv->child_count) != 1) {
- ret = dict_set_str(xdata_rsp, "sh-fail-msg",
- "No difference in mtime");
+ ret = dict_set_sizen_str_sizen(xdata_rsp, "sh-fail-msg",
+ SNO_DIFF_IN_MTIME);
if (!ret)
ret = -1;
goto out;
}
break;
case GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK:
- ret = dict_get_str(xdata_req, "child-name", &name);
+ ret = dict_get_str_sizen(xdata_req, "child-name", &name);
if (ret)
goto out;
source = afr_get_child_index_from_name(this, name);
if (source < 0) {
- ret = dict_set_str(xdata_rsp, "sh-fail-msg",
- "Invalid brick name");
+ ret = dict_set_sizen_str_sizen(xdata_rsp, "sh-fail-msg",
+ SINVALID_BRICK_NAME);
if (!ret)
ret = -1;
goto out;
}
if (locked_on[source] != 1) {
- ret = dict_set_str(xdata_rsp, "sh-fail-msg", "Brick is not up");
+ ret = dict_set_sizen_str_sizen(xdata_rsp, "sh-fail-msg",
+ SBRICK_IS_NOT_UP);
if (!ret)
ret = -1;
goto out;
@@ -1390,7 +1387,7 @@ afr_mark_split_brain_source_sinks(
if (source >= 0)
return source;
- ret = dict_get_int32(xdata_req, "heal-op", &heal_op);
+ ret = dict_get_int32_sizen(xdata_req, "heal-op", &heal_op);
if (ret)
goto autoheal;
@@ -1406,7 +1403,7 @@ autoheal:
frame, this, inode, sources, sinks, healed_sinks, locked_on,
replies, type);
if (source != -1) {
- ret = dict_set_int32(xdata_req, "fav-child-policy", 1);
+ ret = dict_set_int32_sizen(xdata_req, "fav-child-policy", 1);
if (ret)
return -1;
}
@@ -1437,7 +1434,7 @@ _afr_fav_child_reset_sink_xattrs(call_frame_t *frame, xlator_t *this,
priv = this->private;
local = frame->local;
- if (!dict_get(local->xdata_req, "fav-child-policy"))
+ if (!dict_get_sizen(local->xdata_req, "fav-child-policy"))
return 0;
xdata = dict_new();
diff --git a/xlators/cluster/afr/src/afr-self-heal-data.c b/xlators/cluster/afr/src/afr-self-heal-data.c
index 747060b170a..1dd18b363e0 100644
--- a/xlators/cluster/afr/src/afr-self-heal-data.c
+++ b/xlators/cluster/afr/src/afr-self-heal-data.c
@@ -73,7 +73,7 @@ __afr_can_skip_data_block_heal(call_frame_t *frame, xlator_t *this, fd_t *fd,
xdata = dict_new();
if (!xdata)
goto out;
- if (dict_set_int32(xdata, "check-zero-filled", 1)) {
+ if (dict_set_int32_sizen(xdata, "check-zero-filled", 1)) {
dict_unref(xdata);
goto out;
}
diff --git a/xlators/cluster/afr/src/afr-self-heal-entry.c b/xlators/cluster/afr/src/afr-self-heal-entry.c
index ac2eab89a59..b23ed6a1afa 100644
--- a/xlators/cluster/afr/src/afr-self-heal-entry.c
+++ b/xlators/cluster/afr/src/afr-self-heal-entry.c
@@ -149,7 +149,7 @@ afr_selfheal_recreate_entry(call_frame_t *frame, int dst, int source,
}
break;
default:
- ret = dict_set_int32(xdata, GLUSTERFS_INTERNAL_FOP_KEY, 1);
+ ret = dict_set_int32_sizen(xdata, GLUSTERFS_INTERNAL_FOP_KEY, 1);
if (ret)
goto out;
ret = syncop_mknod(
@@ -551,7 +551,7 @@ afr_selfheal_entry_dirent(call_frame_t *frame, xlator_t *this, fd_t *fd,
xattr = dict_new();
if (!xattr)
return -ENOMEM;
- ret = dict_set_int32(xattr, GF_GFIDLESS_LOOKUP, 1);
+ ret = dict_set_int32_sizen(xattr, GF_GFIDLESS_LOOKUP, 1);
if (ret) {
dict_unref(xattr);
return -1;
diff --git a/xlators/cluster/afr/src/afr-self-heal-name.c b/xlators/cluster/afr/src/afr-self-heal-name.c
index f3e5017189d..c4df5d4609d 100644
--- a/xlators/cluster/afr/src/afr-self-heal-name.c
+++ b/xlators/cluster/afr/src/afr-self-heal-name.c
@@ -277,9 +277,8 @@ afr_selfheal_name_gfid_mismatch_check(xlator_t *this, struct afr_reply *replies,
bname, gfid_idx_iter, i,
locked_on, gfid_idx, xdata);
if (!ret && *gfid_idx >= 0) {
- ret = dict_set_str(xdata, "gfid-heal-msg",
- "GFID split-brain "
- "resolved");
+ ret = dict_set_sizen_str_sizen(xdata, "gfid-heal-msg",
+ "GFID split-brain resolved");
if (ret)
gf_msg(this->name, GF_LOG_ERROR, 0,
AFR_MSG_DICT_SET_FAILED,
@@ -496,7 +495,7 @@ afr_selfheal_name_do(call_frame_t *frame, xlator_t *this, inode_t *parent,
if (!xattr)
return -ENOMEM;
- ret = dict_set_int32(xattr, GF_GFIDLESS_LOOKUP, 1);
+ ret = dict_set_int32_sizen(xattr, GF_GFIDLESS_LOOKUP, 1);
if (ret) {
dict_unref(xattr);
return -1;
diff --git a/xlators/cluster/afr/src/afr-self-heal.h b/xlators/cluster/afr/src/afr-self-heal.h
index 41adbe05dc8..6555ec55771 100644
--- a/xlators/cluster/afr/src/afr-self-heal.h
+++ b/xlators/cluster/afr/src/afr-self-heal.h
@@ -97,6 +97,27 @@
#define SBRAIN_HEAL_NO_GO_MSG \
"Failed to obtain replies from all bricks of " \
"the replica (are they up?). Cannot resolve split-brain."
+#define SFILE_NOT_IN_SPLIT_BRAIN "File not in split-brain"
+#define SNO_BIGGER_FILE "No bigger file"
+#define SNO_DIFF_IN_MTIME "No difference in mtime"
+#define SUSE_SOURCE_BRICK_TO_HEAL \
+ "Use source-brick option to heal metadata" \
+ " split-brain"
+#define SINVALID_BRICK_NAME "Invalid brick name"
+#define SBRICK_IS_NOT_UP "Brick is not up"
+#define SBRICK_NOT_CONNECTED "Brick is not connected"
+#define SLESS_THAN2_BRICKS_in_REP "< 2 bricks in replica are up"
+#define SBRICK_IS_REMOTE "Brick is remote"
+#define SSTARTED_SELF_HEAL "Started self-heal"
+#define SOP_NOT_SUPPORTED "Operation Not Supported"
+#define SFILE_NOT_UNDER_DATA \
+ "The file is not under data or metadata " \
+ "split-brain"
+#define SFILE_NOT_IN_SPLIT_BRAIN "File not in split-brain"
+#define SALL_BRICKS_UP_TO_RESOLVE \
+ "All the bricks should be up to resolve the" \
+ " gfid split brain"
+#define SERROR_GETTING_SRC_BRICK "Error getting the source brick"
int
afr_selfheal(xlator_t *this, uuid_t gfid);
diff --git a/xlators/cluster/afr/src/afr-self-heald.c b/xlators/cluster/afr/src/afr-self-heald.c
index c6966147777..7eb12070a39 100644
--- a/xlators/cluster/afr/src/afr-self-heald.c
+++ b/xlators/cluster/afr/src/afr-self-heald.c
@@ -464,7 +464,7 @@ afr_shd_index_sweep(struct subvol_healer *healer, char *vgfid)
}
xdata = dict_new();
- if (!xdata || dict_set_int32(xdata, "get-gfid-type", 1)) {
+ if (!xdata || dict_set_int32_sizen(xdata, "get-gfid-type", 1)) {
ret = -ENOMEM;
goto out;
}
@@ -975,6 +975,8 @@ afr_shd_dict_add_crawl_event(xlator_t *this, dict_t *output,
int ret = 0;
uint64_t count = 0;
char key[256] = {0};
+ int keylen = 0;
+ char suffix[64] = {0};
int xl_id = 0;
uint64_t healed_count = 0;
uint64_t split_brain_count = 0;
@@ -1009,8 +1011,8 @@ afr_shd_dict_add_crawl_event(xlator_t *this, dict_t *output,
snprintf(key, sizeof(key), "statistics-%d-%d-count", xl_id, child);
ret = dict_get_uint64(output, key, &count);
- snprintf(key, sizeof(key), "statistics_healed_cnt-%d-%d-%" PRIu64, xl_id,
- child, count);
+ snprintf(suffix, sizeof(suffix), "%d-%d-%" PRIu64, xl_id, child, count);
+ snprintf(key, sizeof(key), "statistics_healed_cnt-%s", suffix);
ret = dict_set_uint64(output, key, healed_count);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
@@ -1018,8 +1020,7 @@ afr_shd_dict_add_crawl_event(xlator_t *this, dict_t *output,
goto out;
}
- snprintf(key, sizeof(key), "statistics_sb_cnt-%d-%d-%" PRIu64, xl_id, child,
- count);
+ snprintf(key, sizeof(key), "statistics_sb_cnt-%s", suffix);
ret = dict_set_uint64(output, key, split_brain_count);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
@@ -1027,17 +1028,15 @@ afr_shd_dict_add_crawl_event(xlator_t *this, dict_t *output,
goto out;
}
- snprintf(key, sizeof(key), "statistics_crawl_type-%d-%d-%" PRIu64, xl_id,
- child, count);
- ret = dict_set_str(output, key, crawl_type);
+ keylen = snprintf(key, sizeof(key), "statistics_crawl_type-%s", suffix);
+ ret = dict_set_strn(output, key, keylen, crawl_type);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
"Could not add statistics_crawl_type to output");
goto out;
}
- snprintf(key, sizeof(key), "statistics_heal_failed_cnt-%d-%d-%" PRIu64,
- xl_id, child, count);
+ snprintf(key, sizeof(key), "statistics_heal_failed_cnt-%s", suffix);
ret = dict_set_uint64(output, key, heal_failed_count);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
@@ -1045,9 +1044,8 @@ afr_shd_dict_add_crawl_event(xlator_t *this, dict_t *output,
goto out;
}
- snprintf(key, sizeof(key), "statistics_strt_time-%d-%d-%" PRIu64, xl_id,
- child, count);
- ret = dict_set_dynstr(output, key, start_time_str);
+ keylen = snprintf(key, sizeof(key), "statistics_strt_time-%s", suffix);
+ ret = dict_set_dynstrn(output, key, keylen, start_time_str);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
"Could not add statistics_crawl_start_time to output");
@@ -1061,11 +1059,10 @@ afr_shd_dict_add_crawl_event(xlator_t *this, dict_t *output,
else
progress = 0;
- snprintf(key, sizeof(key), "statistics_end_time-%d-%d-%" PRIu64, xl_id,
- child, count);
+ keylen = snprintf(key, sizeof(key), "statistics_end_time-%s", suffix);
if (!end_time_str)
end_time_str = gf_strdup("Could not determine the end time");
- ret = dict_set_dynstr(output, key, end_time_str);
+ ret = dict_set_dynstrn(output, key, keylen, end_time_str);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
"Could not add statistics_crawl_end_time to output");
@@ -1074,10 +1071,9 @@ afr_shd_dict_add_crawl_event(xlator_t *this, dict_t *output,
end_time_str = NULL;
}
- snprintf(key, sizeof(key), "statistics_inprogress-%d-%d-%" PRIu64, xl_id,
- child, count);
+ keylen = snprintf(key, sizeof(key), "statistics_inprogress-%s", suffix);
- ret = dict_set_int32(output, key, progress);
+ ret = dict_set_int32n(output, key, keylen, progress);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
"Could not add statistics_inprogress to output");
@@ -1104,6 +1100,8 @@ afr_shd_dict_add_path(xlator_t *this, dict_t *output, int child, char *path,
int ret = -1;
uint64_t count = 0;
char key[256] = {0};
+ int keylen = 0;
+ char xl_id_child_str[64] = {0};
int xl_id = 0;
ret = dict_get_int32(output, this->name, &xl_id);
@@ -1113,11 +1111,12 @@ afr_shd_dict_add_path(xlator_t *this, dict_t *output, int child, char *path,
goto out;
}
- snprintf(key, sizeof(key), "%d-%d-count", xl_id, child);
+ snprintf(xl_id_child_str, sizeof(xl_id_child_str), "%d-%d", xl_id, child);
+ snprintf(key, sizeof(key), "%s-count", xl_id_child_str);
ret = dict_get_uint64(output, key, &count);
- snprintf(key, sizeof(key), "%d-%d-%" PRIu64, xl_id, child, count);
- ret = dict_set_dynstr(output, key, path);
+ keylen = snprintf(key, sizeof(key), "%s-%" PRIu64, xl_id_child_str, count);
+ ret = dict_set_dynstrn(output, key, keylen, path);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, -ret, AFR_MSG_DICT_SET_FAILED,
@@ -1126,7 +1125,7 @@ afr_shd_dict_add_path(xlator_t *this, dict_t *output, int child, char *path,
}
if (tv) {
- snprintf(key, sizeof(key), "%d-%d-%" PRIu64 "-time", xl_id, child,
+ snprintf(key, sizeof(key), "%s-%" PRIu64 "-time", xl_id_child_str,
count);
ret = dict_set_uint32(output, key, tv->tv_sec);
if (ret) {
@@ -1136,7 +1135,7 @@ afr_shd_dict_add_path(xlator_t *this, dict_t *output, int child, char *path,
}
}
- snprintf(key, sizeof(key), "%d-%d-count", xl_id, child);
+ snprintf(key, sizeof(key), "%s-count", xl_id_child_str);
ret = dict_set_uint64(output, key, count + 1);
if (ret) {
@@ -1314,19 +1313,22 @@ afr_xl_op(xlator_t *this, dict_t *input, dict_t *output)
struct subvol_healer *healer = NULL;
int i = 0;
char key[64];
+ int keylen = 0;
+ int this_name_len = 0;
int op_ret = 0;
uint64_t cnt = 0;
priv = this->private;
shd = &priv->shd;
- ret = dict_get_int32(input, "xl-op", (int32_t *)&op);
+ ret = dict_get_int32_sizen(input, "xl-op", (int32_t *)&op);
if (ret)
goto out;
- ret = dict_get_int32(input, this->name, &xl_id);
+ this_name_len = strlen(this->name);
+ ret = dict_get_int32n(input, this->name, this_name_len, &xl_id);
if (ret)
goto out;
- ret = dict_set_int32(output, this->name, xl_id);
+ ret = dict_set_int32n(output, this->name, this_name_len, xl_id);
if (ret)
goto out;
switch (op) {
@@ -1335,19 +1337,25 @@ afr_xl_op(xlator_t *this, dict_t *input, dict_t *output)
for (i = 0; i < priv->child_count; i++) {
healer = &shd->index_healers[i];
- snprintf(key, sizeof(key), "%d-%d-status", xl_id, i);
+ keylen = snprintf(key, sizeof(key), "%d-%d-status", xl_id, i);
if (!priv->child_up[i]) {
- ret = dict_set_str(output, key, "Brick is not connected");
+ ret = dict_set_nstrn(output, key, keylen,
+ SBRICK_NOT_CONNECTED,
+ SLEN(SBRICK_NOT_CONNECTED));
op_ret = -1;
} else if (AFR_COUNT(priv->child_up, priv->child_count) < 2) {
- ret = dict_set_str(output, key,
- "< 2 bricks in replica are up");
+ ret = dict_set_nstrn(output, key, keylen,
+ SLESS_THAN2_BRICKS_in_REP,
+ SLEN(SLESS_THAN2_BRICKS_in_REP));
op_ret = -1;
} else if (!afr_shd_is_subvol_local(this, healer->subvol)) {
- ret = dict_set_str(output, key, "Brick is remote");
+ ret = dict_set_nstrn(output, key, keylen, SBRICK_IS_REMOTE,
+ SLEN(SBRICK_IS_REMOTE));
} else {
- ret = dict_set_str(output, key, "Started self-heal");
+ ret = dict_set_nstrn(output, key, keylen,
+ SSTARTED_SELF_HEAL,
+ SLEN(SSTARTED_SELF_HEAL));
afr_shd_index_healer_spawn(this, i);
}
}
@@ -1357,17 +1365,23 @@ afr_xl_op(xlator_t *this, dict_t *input, dict_t *output)
for (i = 0; i < priv->child_count; i++) {
healer = &shd->full_healers[i];
- snprintf(key, sizeof(key), "%d-%d-status", xl_id, i);
+ keylen = snprintf(key, sizeof(key), "%d-%d-status", xl_id, i);
if (!priv->child_up[i]) {
- ret = dict_set_str(output, key, "Brick is not connected");
+ ret = dict_set_nstrn(output, key, keylen,
+ SBRICK_NOT_CONNECTED,
+ SLEN(SBRICK_NOT_CONNECTED));
} else if (AFR_COUNT(priv->child_up, priv->child_count) < 2) {
- ret = dict_set_str(output, key,
- "< 2 bricks in replica are up");
+ ret = dict_set_nstrn(output, key, keylen,
+ SLESS_THAN2_BRICKS_in_REP,
+ SLEN(SLESS_THAN2_BRICKS_in_REP));
} else if (!afr_shd_is_subvol_local(this, healer->subvol)) {
- ret = dict_set_str(output, key, "Brick is remote");
+ ret = dict_set_nstrn(output, key, keylen, SBRICK_IS_REMOTE,
+ SLEN(SBRICK_IS_REMOTE));
} else {
- ret = dict_set_str(output, key, "Started self-heal");
+ ret = dict_set_nstrn(output, key, keylen,
+ SSTARTED_SELF_HEAL,
+ SLEN(SSTARTED_SELF_HEAL));
afr_shd_full_healer_spawn(this, i);
op_ret = 0;
}
@@ -1379,10 +1393,9 @@ afr_xl_op(xlator_t *this, dict_t *input, dict_t *output)
case GF_SHD_OP_HEALED_FILES:
case GF_SHD_OP_HEAL_FAILED_FILES:
for (i = 0; i < priv->child_count; i++) {
- snprintf(key, sizeof(key), "%d-%d-status", xl_id, i);
- ret = dict_set_str(output, key,
- "Operation Not "
- "Supported");
+ keylen = snprintf(key, sizeof(key), "%d-%d-status", xl_id, i);
+ ret = dict_set_nstrn(output, key, keylen, SOP_NOT_SUPPORTED,
+ SLEN(SOP_NOT_SUPPORTED));
}
break;
case GF_SHD_OP_SPLIT_BRAIN_FILES:
@@ -1403,8 +1416,11 @@ afr_xl_op(xlator_t *this, dict_t *input, dict_t *output)
for (i = 0; i < priv->child_count; i++) {
if (!priv->child_up[i]) {
- snprintf(key, sizeof(key), "%d-%d-status", xl_id, i);
- ret = dict_set_str(output, key, "Brick is not connected");
+ keylen = snprintf(key, sizeof(key), "%d-%d-status", xl_id,
+ i);
+ ret = dict_set_nstrn(output, key, keylen,
+ SBRICK_NOT_CONNECTED,
+ SLEN(SBRICK_NOT_CONNECTED));
} else {
snprintf(key, sizeof(key), "%d-%d-hardlinks", xl_id, i);
ret = afr_shd_get_index_count(this, i, &cnt);
@@ -1423,6 +1439,6 @@ afr_xl_op(xlator_t *this, dict_t *input, dict_t *output)
break;
}
out:
- dict_del(output, this->name);
+ dict_deln(output, this->name, this_name_len);
return op_ret;
}
diff --git a/xlators/cluster/afr/src/afr-transaction.c b/xlators/cluster/afr/src/afr-transaction.c
index c5f016d4a8e..ab3a121efe3 100644
--- a/xlators/cluster/afr/src/afr-transaction.c
+++ b/xlators/cluster/afr/src/afr-transaction.c
@@ -1713,6 +1713,7 @@ afr_changelog_populate_xdata(call_frame_t *frame, afr_xattrop_type_t op,
int i = 0;
int ret = 0;
char *key = NULL;
+ int keylen = 0;
const char *name = NULL;
dict_t *xdata1 = NULL;
dict_t *xdata2 = NULL;
@@ -1770,7 +1771,8 @@ afr_changelog_populate_xdata(call_frame_t *frame, afr_xattrop_type_t op,
}
if (need_entry_key_set) {
- ret = dict_set_str(xdata1, key, (char *)name);
+ keylen = strlen(key);
+ ret = dict_set_strn(xdata1, key, keylen, (char *)name);
if (ret)
gf_msg(THIS->name, GF_LOG_ERROR, 0, AFR_MSG_DICT_SET_FAILED,
"%s/%s: Could not set %s key during xattrop",
@@ -1780,7 +1782,8 @@ afr_changelog_populate_xdata(call_frame_t *frame, afr_xattrop_type_t op,
if (!xdata2)
goto out;
- ret = dict_set_str(xdata2, key, (char *)local->newloc.name);
+ ret = dict_set_strn(xdata2, key, keylen,
+ (char *)local->newloc.name);
if (ret)
gf_msg(THIS->name, GF_LOG_ERROR, 0, AFR_MSG_DICT_SET_FAILED,
"%s/%s: Could not set %s key during "
@@ -2537,7 +2540,7 @@ afr_changelog_fsync(call_frame_t *frame, xlator_t *this)
xdata = dict_new();
if (xdata)
- ret = dict_set_int32(xdata, "batch-fsync", 1);
+ ret = dict_set_int32_sizen(xdata, "batch-fsync", 1);
for (i = 0; i < priv->child_count; i++) {
if (!local->transaction.pre_op[i])
diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c
index 4e20c7542c3..c13ac8772f2 100644
--- a/xlators/cluster/afr/src/afr.c
+++ b/xlators/cluster/afr/src/afr.c
@@ -87,7 +87,7 @@ static void
fix_quorum_options(xlator_t *this, afr_private_t *priv, char *qtype,
dict_t *options)
{
- if (dict_get(options, "quorum-type") == NULL) {
+ if (dict_get_sizen(options, "quorum-type") == NULL) {
/* If user doesn't configure anything enable auto-quorum if the
* replica has more than two subvolumes */
if (priv->child_count > 2)