summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorNiels de Vos <ndevos@redhat.com>2014-08-14 17:24:12 +0200
committerNiels de Vos <ndevos@redhat.com>2014-08-15 09:45:52 -0700
commit2dfe3715b56a90d5b7df914c7b67d308b0b45b67 (patch)
tree89a495d466a568a12993fb843c15f12f1d00a354 /xlators
parent9bb7cb9ff1b4e52a0ec65c61a742955d340b1baf (diff)
dict: add dict_set_dynstr_with_alloc
There is an overwhelming no. of instances of the following pattern in glusterd module. ... char *dynstr = gf_strdup (str); if (!dynstr) goto err; ret = dict_set_dynstr (dict, key, dynstr); if (ret) goto err; ... With this changes it would look as below, ret = dict_set_dynstr_with_alloc (dict, key, str); if (ret) goto err; Cherry picked from commit a9d4d369efc978511e3cb69e5643945710cc9416: > Change-Id: I6a47b1cbab4834badadc48c56d0b5c8c06c6dd4d > Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com> > Reviewed-on: http://review.gluster.org/7379 > Tested-by: Gluster Build System <jenkins@build.gluster.com> > Reviewed-by: Jeff Darcy <jdarcy@redhat.com> Backport notes: Included this change to accommodate additional backports. BUG: 1081016 Change-Id: I6a47b1cbab4834badadc48c56d0b5c8c06c6dd4d Signed-off-by: Niels de Vos <ndevos@redhat.com> Reviewed-on: http://review.gluster.org/8489 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Diffstat (limited to 'xlators')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c34
1 files changed, 11 insertions, 23 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 36cd2ddc741..ded09f154ce 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -5119,9 +5119,6 @@ glusterd_add_brick_mount_details (glusterd_brickinfo_t *brickinfo,
char key[1024] = {0};
char base_key[1024] = {0};
char *mnt_pt = NULL;
- char *fs_name = NULL;
- char *mnt_options = NULL;
- char *device = NULL;
FILE *mtab = NULL;
struct mntent *entry = NULL;
@@ -5154,8 +5151,7 @@ glusterd_add_brick_mount_details (glusterd_brickinfo_t *brickinfo,
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "%s.device", base_key);
- device = gf_strdup (entry->mnt_fsname);
- ret = dict_set_dynstr (dict, key, device);
+ ret = dict_set_dynstr_with_alloc (dict, key, entry->mnt_fsname);
if (ret)
goto out;
@@ -5163,8 +5159,7 @@ glusterd_add_brick_mount_details (glusterd_brickinfo_t *brickinfo,
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "%s.fs_name", base_key);
- fs_name = gf_strdup (entry->mnt_type);
- ret = dict_set_dynstr (dict, key, fs_name);
+ ret = dict_set_dynstr_with_alloc (dict, key, entry->mnt_type);
if (ret)
goto out;
@@ -5172,8 +5167,7 @@ glusterd_add_brick_mount_details (glusterd_brickinfo_t *brickinfo,
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "%s.mnt_options", base_key);
- mnt_options = gf_strdup (entry->mnt_opts);
- ret = dict_set_dynstr (dict, key, mnt_options);
+ ret = dict_set_dynstr_with_alloc (dict, key, entry->mnt_opts);
out:
GF_FREE (mnt_pt);
@@ -5279,7 +5273,6 @@ glusterd_add_brick_to_dict (glusterd_volinfo_t *volinfo,
int ret = -1;
int32_t pid = -1;
int32_t brick_online = -1;
- char *peer_id_str = NULL;
char key[1024] = {0};
char base_key[1024] = {0};
char pidfile[PATH_MAX] = {0};
@@ -5310,16 +5303,11 @@ glusterd_add_brick_to_dict (glusterd_volinfo_t *volinfo,
goto out;
/* add peer uuid */
- peer_id_str = gf_strdup (uuid_utoa (brickinfo->uuid));
- if (!peer_id_str) {
- ret = -1;
- goto out;
- }
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "%s.peerid", base_key);
- ret = dict_set_dynstr (dict, key, peer_id_str);
+ ret = dict_set_dynstr_with_alloc (dict, key,
+ uuid_utoa (brickinfo->uuid));
if (ret) {
- GF_FREE (peer_id_str);
goto out;
}
@@ -5981,8 +5969,7 @@ glusterd_sm_tr_log_transition_add_to_dict (dict_t *dict,
snprintf (key, sizeof (key), "log%d-time", count);
gf_time_fmt (timestr, sizeof timestr, log->transitions[i].time,
gf_timefmt_FT);
- str = gf_strdup (timestr);
- ret = dict_set_dynstr (dict, key, str);
+ ret = dict_set_dynstr_with_alloc (dict, key, timestr);
if (ret)
goto out;
@@ -7389,7 +7376,7 @@ glusterd_append_gsync_status (dict_t *dst, dict_t *src)
goto out;
}
- ret = dict_set_dynstr (dst, "gsync-status", gf_strdup (stop_msg));
+ ret = dict_set_dynstr_with_alloc (dst, "gsync-status", stop_msg);
if (ret) {
gf_log ("glusterd", GF_LOG_WARNING, "Unable to set the stop"
"message in the ctx dictionary");
@@ -7493,8 +7480,8 @@ glusterd_gsync_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict, char *op_errstr)
ret = dict_get_str (rsp_dict, "conf_path", &conf_path);
if (!ret && conf_path) {
- ret = dict_set_dynstr (ctx, "conf_path",
- gf_strdup(conf_path));
+ ret = dict_set_dynstr_with_alloc (ctx, "conf_path",
+ conf_path);
if (ret) {
gf_log ("", GF_LOG_ERROR,
"Unable to store conf path.");
@@ -7503,7 +7490,8 @@ glusterd_gsync_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict, char *op_errstr)
}
}
if ((op_errstr) && (strcmp ("", op_errstr))) {
- ret = dict_set_dynstr (ctx, "errstr", gf_strdup(op_errstr));
+ ret = dict_set_dynstr_with_alloc (ctx, "errstr",
+ op_errstr);
if (ret)
goto out;
}