diff options
| author | Krishnan Parthasarathi <kparthas@redhat.com> | 2014-04-02 11:36:20 +0530 | 
|---|---|---|
| committer | Anand Avati <avati@redhat.com> | 2014-04-14 09:15:14 -0700 | 
| commit | a9d4d369efc978511e3cb69e5643945710cc9416 (patch) | |
| tree | 19a8b0da0502de2d486470a921fc6dec45afc100 | |
| parent | 09d2dcac3a238cfe6bde1a7aed06facfa16caf20 (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;
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>
| -rw-r--r-- | libglusterfs/src/dict.c | 17 | ||||
| -rw-r--r-- | libglusterfs/src/dict.h | 1 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 36 | 
3 files changed, 30 insertions, 24 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 7bc5d57b032..1bed8bf9b69 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -2067,6 +2067,23 @@ err:  }  int +dict_set_dynstr_with_alloc (dict_t *this, char *key, const char *str) +{ +        char *alloc_str = NULL; +        int   ret       = -1; + +        alloc_str = gf_strdup (str); +        if (!alloc_str) +                return -1; + +        ret = dict_set_dynstr (this, key, alloc_str); +        if (ret) +                GF_FREE (alloc_str); + +        return ret; +} + +int  dict_set_dynstr (dict_t *this, char *key, char *str)  {          data_t * data = NULL; diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index 6e5d8aa0650..a92fd2cb61a 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -228,6 +228,7 @@ GF_MUST_CHECK int dict_set_static_bin (dict_t *this, char *key, void *ptr, size_  GF_MUST_CHECK int dict_set_str (dict_t *this, char *key, char *str);  GF_MUST_CHECK int dict_set_dynmstr (dict_t *this, char *key, char *str);  GF_MUST_CHECK int dict_set_dynstr (dict_t *this, char *key, char *str); +GF_MUST_CHECK int dict_set_dynstr_with_alloc (dict_t *this, char *key, const char *str);  GF_MUST_CHECK int dict_get_str (dict_t *this, char *key, char **str);  GF_MUST_CHECK int dict_get_str_boolean (dict_t *this, char *key, int default_val); diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index eb6fb675770..1822be1ec36 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -5671,11 +5671,8 @@ 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; -        struct mntent  *entry                = NULL;          FILE           *mtab                 = NULL; +        struct mntent  *entry                = NULL;          snprintf (base_key, sizeof (base_key), "brick%d", count); @@ -5693,8 +5690,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; @@ -5702,8 +5698,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; @@ -5711,8 +5706,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); @@ -5857,7 +5851,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}; @@ -5888,16 +5881,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;          } @@ -6559,8 +6547,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; @@ -7979,7 +7966,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"); @@ -8083,8 +8070,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."); @@ -8093,7 +8080,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;          }  | 
