7c2869
From bb41d03cf8a907794749cd83266461b06c1b1172 Mon Sep 17 00:00:00 2001
7c2869
From: Pranith Kumar K <pkarampu@redhat.com>
7c2869
Date: Wed, 6 Jan 2016 14:30:08 +0530
7c2869
Subject: [PATCH 640/642] dict: Don't expose get_new_dict/dict_destroy
7c2869
7c2869
get_new_dict/dict_destroy is causing confusion where, dict_new/dict_destroy or
7c2869
get_new_dict/dict_unref are used instead of dict_new/dict_unref.
7c2869
7c2869
The downstream patch only covers the dictionary changes in glusterd and
7c2869
cli codebase and skip the other parts as the bug is only tracked for
7c2869
glusterd memory leak issues.
7c2869
7c2869
>Reviewed-on: http://review.gluster.org/13183
7c2869
>Smoke: Gluster Build System <jenkins@build.gluster.org>
7c2869
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
7c2869
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
7c2869
>Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
7c2869
>Reviewed-by: Krutika Dhananjay <kdhananj@redhat.com>
7c2869
7c2869
Change-Id: I4cc69f5b6711d720823395e20fd624a0c6c1168c
7c2869
BUG: 1526363
7c2869
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
7c2869
Reviewed-on: https://code.engineering.redhat.com/gerrit/125957
7c2869
Tested-by: Atin Mukherjee <amukherj@redhat.com>
7c2869
Tested-by: RHGS Build Bot <nigelb@redhat.com>
7c2869
---
7c2869
 cli/src/cli-cmd-parser.c                     | 44 ++++++++++++++--------------
7c2869
 cli/src/cli-cmd-system.c                     |  6 ++--
7c2869
 cli/src/cli-cmd-volume.c                     |  2 +-
7c2869
 cli/src/cli-rpc-ops.c                        |  4 +--
7c2869
 cli/src/cli.c                                |  2 +-
7c2869
 libglusterfs/src/dict.h                      |  4 +--
7c2869
 xlators/mgmt/glusterd/src/glusterd-geo-rep.c |  4 +--
7c2869
 xlators/mgmt/glusterd/src/glusterd-op-sm.c   |  4 +--
7c2869
 xlators/mgmt/glusterd/src/glusterd-volgen.c  | 12 ++++----
7c2869
 9 files changed, 40 insertions(+), 42 deletions(-)
7c2869
7c2869
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
7c2869
index 12717cd..0056581 100644
7c2869
--- a/cli/src/cli-cmd-parser.c
7c2869
+++ b/cli/src/cli-cmd-parser.c
7c2869
@@ -741,7 +741,7 @@ out:
7c2869
         if (ret) {
7c2869
                 gf_log ("cli", GF_LOG_ERROR, "Unable to parse create volume CLI");
7c2869
                 if (dict)
7c2869
-                        dict_destroy (dict);
7c2869
+                        dict_unref (dict);
7c2869
         }
7c2869
 
7c2869
         GF_FREE (trans_type);
7c2869
@@ -817,7 +817,7 @@ cli_cmd_volume_reset_parse (const char **words, int wordcount, dict_t **options)
7c2869
 
7c2869
 out:
7c2869
         if (ret && dict) {
7c2869
-                dict_destroy (dict);
7c2869
+                dict_unref (dict);
7c2869
         }
7c2869
 
7c2869
                 return ret;
7c2869
@@ -1138,7 +1138,7 @@ cli_cmd_inode_quota_parse (const char **words, int wordcount, dict_t **options)
7c2869
 out:
7c2869
         if (ret < 0) {
7c2869
                 if (dict)
7c2869
-                        dict_destroy (dict);
7c2869
+                        dict_unref (dict);
7c2869
         }
7c2869
 
7c2869
         return ret;
7c2869
@@ -1477,7 +1477,7 @@ set_type:
7c2869
 out:
7c2869
         if (ret < 0) {
7c2869
                 if (dict)
7c2869
-                        dict_destroy (dict);
7c2869
+                        dict_unref (dict);
7c2869
         }
7c2869
 
7c2869
         return ret;
7c2869
@@ -1748,8 +1748,8 @@ cli_cmd_volume_set_parse (struct cli_state *state, const char **words,
7c2869
         *options = dict;
7c2869
 
7c2869
 out:
7c2869
-        if (ret)
7c2869
-                dict_destroy (dict);
7c2869
+        if (ret && dict)
7c2869
+                dict_unref (dict);
7c2869
 
7c2869
         return ret;
7c2869
 }
7c2869
@@ -1889,7 +1889,7 @@ out:
7c2869
         if (ret) {
7c2869
                 gf_log ("cli", GF_LOG_ERROR, "Unable to parse add-brick CLI");
7c2869
                 if (dict)
7c2869
-                        dict_destroy (dict);
7c2869
+                        dict_unref (dict);
7c2869
         }
7c2869
 
7c2869
         return ret;
7c2869
@@ -1968,7 +1968,7 @@ out:
7c2869
         if (ret) {
7c2869
                 gf_log ("cli", GF_LOG_ERROR, "Unable to parse tier CLI");
7c2869
                 if (dict)
7c2869
-                        dict_destroy (dict);
7c2869
+                        dict_unref (dict);
7c2869
         }
7c2869
 
7c2869
         return ret;
7c2869
@@ -2197,7 +2197,7 @@ out:
7c2869
         if (ret) {
7c2869
                 gf_log ("cli", GF_LOG_ERROR, "Unable to parse remove-brick CLI");
7c2869
                 if (dict)
7c2869
-                        dict_destroy (dict);
7c2869
+                        dict_unref (dict);
7c2869
         }
7c2869
 
7c2869
         GF_FREE (tmp_brick);
7c2869
@@ -2392,7 +2392,7 @@ out:
7c2869
         if (ret) {
7c2869
                 gf_log ("cli", GF_LOG_ERROR, "Unable to parse reset-brick CLI");
7c2869
                 if (dict)
7c2869
-                        dict_destroy (dict);
7c2869
+                        dict_unref (dict);
7c2869
         }
7c2869
 
7c2869
         return ret;
7c2869
@@ -2453,7 +2453,7 @@ cli_cmd_log_filename_parse (const char **words, int wordcount, dict_t **options)
7c2869
 
7c2869
 out:
7c2869
         if (ret && dict)
7c2869
-                dict_destroy (dict);
7c2869
+                dict_unref (dict);
7c2869
 
7c2869
         return ret;
7c2869
 }
7c2869
@@ -2510,7 +2510,7 @@ cli_cmd_log_level_parse (const char **words, int worcount, dict_t **options)
7c2869
 
7c2869
  out:
7c2869
         if (ret && dict)
7c2869
-                dict_destroy (dict);
7c2869
+                dict_unref (dict);
7c2869
 
7c2869
         return ret;
7c2869
 }
7c2869
@@ -2561,7 +2561,7 @@ cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options)
7c2869
 
7c2869
 out:
7c2869
         if (ret && dict)
7c2869
-                dict_destroy (dict);
7c2869
+                dict_unref (dict);
7c2869
 
7c2869
         return ret;
7c2869
 }
7c2869
@@ -2615,7 +2615,7 @@ cli_cmd_log_rotate_parse (const char **words, int wordcount, dict_t **options)
7c2869
 
7c2869
 out:
7c2869
         if (ret && dict)
7c2869
-                dict_destroy (dict);
7c2869
+                dict_unref (dict);
7c2869
 
7c2869
         return ret;
7c2869
 }
7c2869
@@ -3057,7 +3057,7 @@ out:
7c2869
                 GF_FREE (slave_temp);
7c2869
         if (ret) {
7c2869
                 if (dict)
7c2869
-                        dict_destroy (dict);
7c2869
+                        dict_unref (dict);
7c2869
         } else
7c2869
                 *options = dict;
7c2869
 
7c2869
@@ -3154,7 +3154,7 @@ cli_cmd_volume_profile_parse (const char **words, int wordcount,
7c2869
         *options = dict;
7c2869
 out:
7c2869
         if (ret && dict)
7c2869
-                dict_destroy (dict);
7c2869
+                dict_unref (dict);
7c2869
         return ret;
7c2869
 }
7c2869
 
7c2869
@@ -3343,7 +3343,7 @@ cli_cmd_volume_top_parse (const char **words, int wordcount,
7c2869
         *options = dict;
7c2869
 out:
7c2869
         if (ret && dict)
7c2869
-                dict_destroy (dict);
7c2869
+                dict_unref (dict);
7c2869
         return ret;
7c2869
 }
7c2869
 
7c2869
@@ -3556,7 +3556,7 @@ cli_cmd_volume_status_parse (const char **words, int wordcount,
7c2869
 
7c2869
  out:
7c2869
         if (ret && dict)
7c2869
-                dict_destroy (dict);
7c2869
+                dict_unref (dict);
7c2869
 
7c2869
         return ret;
7c2869
 }
7c2869
@@ -3644,7 +3644,7 @@ cli_cmd_volume_statedump_options_parse (const char **words, int wordcount,
7c2869
 out:
7c2869
         GF_FREE (tmp);
7c2869
         if (ret && dict)
7c2869
-                dict_destroy (dict);
7c2869
+                dict_unref (dict);
7c2869
         if (ret)
7c2869
                 gf_log ("cli", GF_LOG_ERROR, "Error parsing dumpoptions");
7c2869
         return ret;
7c2869
@@ -4134,7 +4134,7 @@ done:
7c2869
 
7c2869
 out:
7c2869
         if (ret && dict)
7c2869
-                dict_destroy (dict);
7c2869
+                dict_unref (dict);
7c2869
 
7c2869
         return ret;
7c2869
 }
7c2869
@@ -5458,7 +5458,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
7c2869
 out:
7c2869
         if (ret) {
7c2869
                 if (dict)
7c2869
-                        dict_destroy (dict);
7c2869
+                        dict_unref (dict);
7c2869
         } else
7c2869
                 *options = dict;
7c2869
 
7c2869
@@ -5716,7 +5716,7 @@ out:
7c2869
         if (ret) {
7c2869
                 gf_log ("cli", GF_LOG_ERROR, "Unable to parse bitrot command");
7c2869
                 if (dict)
7c2869
-                        dict_destroy (dict);
7c2869
+                        dict_unref (dict);
7c2869
         }
7c2869
 
7c2869
         return ret;
7c2869
diff --git a/cli/src/cli-cmd-system.c b/cli/src/cli-cmd-system.c
7c2869
index ad6bb73..93aac0b 100644
7c2869
--- a/cli/src/cli-cmd-system.c
7c2869
+++ b/cli/src/cli-cmd-system.c
7c2869
@@ -66,7 +66,7 @@ cli_cmd_getspec_cbk (struct cli_state *state, struct cli_cmd_word *word,
7c2869
 out:
7c2869
         if (!proc && ret) {
7c2869
                 if (dict)
7c2869
-                        dict_destroy (dict);
7c2869
+                        dict_unref (dict);
7c2869
                 if (wordcount > 1)
7c2869
                         cli_out ("Fetching spec for volume %s failed",
7c2869
                                  (char *)words[2]);
7c2869
@@ -109,7 +109,7 @@ cli_cmd_pmap_b2p_cbk (struct cli_state *state, struct cli_cmd_word *word,
7c2869
 out:
7c2869
         if (!proc && ret) {
7c2869
                 if (dict)
7c2869
-                        dict_destroy (dict);
7c2869
+                        dict_unref (dict);
7c2869
                 if (wordcount > 1)
7c2869
                         cli_out ("Fetching spec for volume %s failed",
7c2869
                                  (char *)words[3]);
7c2869
@@ -188,7 +188,7 @@ make_seq_dict (int argc, char **argv)
7c2869
         }
7c2869
 
7c2869
         if (ret) {
7c2869
-                dict_destroy (dict);
7c2869
+                dict_unref (dict);
7c2869
                 dict = NULL;
7c2869
         }
7c2869
 
7c2869
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
7c2869
index 3ec39fd..927c802 100644
7c2869
--- a/cli/src/cli-cmd-volume.c
7c2869
+++ b/cli/src/cli-cmd-volume.c
7c2869
@@ -592,7 +592,7 @@ cli_cmd_volume_rename_cbk (struct cli_state *state, struct cli_cmd_word *word,
7c2869
 
7c2869
 out:
7c2869
         if (dict)
7c2869
-                dict_destroy (dict);
7c2869
+                dict_unref (dict);
7c2869
 
7c2869
         if (ret) {
7c2869
                 cli_cmd_sent_status_get (&sent);
7c2869
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
7c2869
index 7ded5f9..24037aa 100644
7c2869
--- a/cli/src/cli-rpc-ops.c
7c2869
+++ b/cli/src/cli-rpc-ops.c
7c2869
@@ -493,7 +493,7 @@ out:
7c2869
         cli_cmd_broadcast_response (ret);
7c2869
 
7c2869
         if (dict)
7c2869
-                dict_destroy (dict);
7c2869
+                dict_unref (dict);
7c2869
 
7c2869
         return ret;
7c2869
 }
7c2869
@@ -1127,7 +1127,7 @@ out:
7c2869
         cli_cmd_broadcast_response (ret);
7c2869
 
7c2869
         if (dict)
7c2869
-                dict_destroy (dict);
7c2869
+                dict_unref (dict);
7c2869
 
7c2869
         free (rsp.dict.dict_val);
7c2869
 
7c2869
diff --git a/cli/src/cli.c b/cli/src/cli.c
7c2869
index e0d6b3e..33250d3 100644
7c2869
--- a/cli/src/cli.c
7c2869
+++ b/cli/src/cli.c
7c2869
@@ -607,7 +607,7 @@ cli_quotad_clnt_rpc_init (void)
7c2869
 out:
7c2869
         if (ret) {
7c2869
                 if (rpc_opts)
7c2869
-                        dict_destroy(rpc_opts);
7c2869
+                        dict_unref(rpc_opts);
7c2869
         }
7c2869
         return rpc;
7c2869
 }
7c2869
diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h
7c2869
index b5d9f3e..455391a 100644
7c2869
--- a/libglusterfs/src/dict.h
7c2869
+++ b/libglusterfs/src/dict.h
7c2869
@@ -156,10 +156,7 @@ char *data_to_str (data_t *data);
7c2869
 void *data_to_bin (data_t *data);
7c2869
 void *data_to_ptr (data_t *data);
7c2869
 
7c2869
-data_t *get_new_data ();
7c2869
 data_t * data_copy (data_t *old);
7c2869
-dict_t *get_new_dict_full (int size_hint);
7c2869
-dict_t *get_new_dict ();
7c2869
 
7c2869
 int dict_foreach (dict_t *this,
7c2869
                   int (*fn)(dict_t *this,
7c2869
@@ -193,6 +190,7 @@ int dict_null_foreach_fn (dict_t *d, char *k,
7c2869
 int dict_remove_foreach_fn (dict_t *d, char *k,
7c2869
                             data_t *v, void *tmp);
7c2869
 dict_t *dict_copy (dict_t *this, dict_t *new);
7c2869
+dict_t *get_new_dict (void);
7c2869
 int dict_keys_join (void *value, int size, dict_t *dict,
7c2869
                     int (*filter_fn)(char *key));
7c2869
 
7c2869
diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
7c2869
index fa3b151..907c29f 100644
7c2869
--- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
7c2869
+++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
7c2869
@@ -1976,7 +1976,7 @@ is_geo_rep_active (glusterd_volinfo_t *volinfo, char *slave,
7c2869
         ret = 0;
7c2869
 out:
7c2869
         if (confd)
7c2869
-                dict_destroy (confd);
7c2869
+                dict_unref (confd);
7c2869
         return ret;
7c2869
 }
7c2869
 
7c2869
@@ -2617,7 +2617,7 @@ fetch_data:
7c2869
         }
7c2869
 
7c2869
         if (confd)
7c2869
-                dict_destroy (confd);
7c2869
+                dict_unref (confd);
7c2869
 
7c2869
         gf_msg_debug (this->name, 0, "Returning %d ", ret);
7c2869
         return ret;
7c2869
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
7c2869
index 51eae2d..f034ae8 100644
7c2869
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
7c2869
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
7c2869
@@ -4369,7 +4369,7 @@ glusterd_op_build_payload (dict_t **req, char **op_errstr, dict_t *op_ctx)
7c2869
                                         if (ret)
7c2869
                                                 goto out;
7c2869
                                 }
7c2869
-                                dict_destroy (req_dict);
7c2869
+                                dict_unref (req_dict);
7c2869
                                 req_dict = dict_ref (dict);
7c2869
                         }
7c2869
                         break;
7c2869
@@ -4395,7 +4395,7 @@ glusterd_op_build_payload (dict_t **req, char **op_errstr, dict_t *op_ctx)
7c2869
                                         goto out;
7c2869
                                 }
7c2869
 
7c2869
-                                dict_destroy (req_dict);
7c2869
+                                dict_unref (req_dict);
7c2869
                                 req_dict = dict_ref (dict);
7c2869
                         }
7c2869
                         break;
7c2869
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
7c2869
index 701cccf..859a932 100644
7c2869
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
7c2869
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
7c2869
@@ -93,7 +93,7 @@ xlator_instantiate_va (const char *type, const char *format, va_list arg)
7c2869
         ret = xlator_set_type_virtual (xl, type);
7c2869
         if (ret)
7c2869
                 goto error;
7c2869
-        xl->options = get_new_dict();
7c2869
+        xl->options = dict_new ();
7c2869
         if (!xl->options)
7c2869
                 goto error;
7c2869
         xl->name = volname;
7c2869
@@ -1052,7 +1052,7 @@ build_graph_generic (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
7c2869
         int ret = 0;
7c2869
 
7c2869
         if (mod_dict) {
7c2869
-                set_dict = dict_copy (volinfo->dict, NULL);
7c2869
+                set_dict = dict_copy_with_ref (volinfo->dict, NULL);
7c2869
                 if (!set_dict)
7c2869
                         return -1;
7c2869
                  dict_copy (mod_dict, set_dict);
7c2869
@@ -1066,7 +1066,7 @@ build_graph_generic (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
7c2869
                 ret = volgen_graph_set_options (graph, set_dict);
7c2869
 
7c2869
         if (mod_dict)
7c2869
-                dict_destroy (set_dict);
7c2869
+                dict_unref (set_dict);
7c2869
 
7c2869
         return ret;
7c2869
 }
7c2869
@@ -4728,7 +4728,7 @@ build_rebalance_volfile (glusterd_volinfo_t *volinfo, char *filepath,
7c2869
                 return 0;
7c2869
         }
7c2869
 
7c2869
-        set_dict = dict_copy (volinfo->dict, NULL);
7c2869
+        set_dict = dict_copy_with_ref (volinfo->dict, NULL);
7c2869
         if (!set_dict)
7c2869
                 return -1;
7c2869
 
7c2869
@@ -4770,7 +4770,7 @@ build_rebalance_volfile (glusterd_volinfo_t *volinfo, char *filepath,
7c2869
 out:
7c2869
         volgen_graph_free (&graph);
7c2869
 
7c2869
-        dict_destroy (set_dict);
7c2869
+        dict_unref (set_dict);
7c2869
 
7c2869
         return ret;
7c2869
 }
7c2869
@@ -5037,7 +5037,7 @@ build_nfs_graph (volgen_graph_t *graph, dict_t *mod_dict)
7c2869
 
7c2869
  out:
7c2869
         gf_msg_debug ("glusterd", 0, "Returning %d", ret);
7c2869
-        dict_destroy (set_dict);
7c2869
+        dict_unref (set_dict);
7c2869
 
7c2869
         return ret;
7c2869
 }
7c2869
-- 
7c2869
2.9.3
7c2869