e7a346
From 37897f0b72617e442e4799b35ebda94294218e05 Mon Sep 17 00:00:00 2001
e7a346
From: Pranith Kumar K <pkarampu@redhat.com>
e7a346
Date: Wed, 28 Feb 2018 17:58:31 +0530
e7a346
Subject: [PATCH 183/201] cluster/afr: Fix dict-leak in pre-op
e7a346
e7a346
At the time of pre-op, pre_op_xdata is populted with the xattrs we get from the
e7a346
disk and at the time of post-op it gets over-written without unreffing the
e7a346
previous value stored leading to a leak.
e7a346
This is a regression we missed in
e7a346
https://review.gluster.org/#/q/ba149bac92d169ae2256dbc75202dc9e5d06538e
e7a346
e7a346
 >BUG: 1550078
e7a346
 >Change-Id: I0456f9ad6f77ce6248b747964a037193af3a3da7
e7a346
 >Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
e7a346
 >Upstream: https://review.gluster.org/19647
e7a346
e7a346
BUG: 1552360
e7a346
Change-Id: I0456f9ad6f77ce6248b747964a037193af3a3da7
e7a346
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/131936
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
e7a346
---
e7a346
 xlators/cluster/afr/src/afr-common.c      | 16 ++++++++--------
e7a346
 xlators/cluster/afr/src/afr-transaction.c | 20 ++++++++++----------
e7a346
 xlators/cluster/afr/src/afr.h             |  4 ++--
e7a346
 3 files changed, 20 insertions(+), 20 deletions(-)
e7a346
e7a346
diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c
e7a346
index 6e6f5fa..855e568 100644
e7a346
--- a/xlators/cluster/afr/src/afr-common.c
e7a346
+++ b/xlators/cluster/afr/src/afr-common.c
e7a346
@@ -1039,7 +1039,7 @@ afr_readables_fill (call_frame_t *frame, xlator_t *this, inode_t *inode,
e7a346
                         xdata = replies[i].xdata;
e7a346
                         ia_type = replies[i].poststat.ia_type;
e7a346
                 } else {/* pre-op xattrop */
e7a346
-                        xdata = local->transaction.pre_op_xdata[i];
e7a346
+                        xdata = local->transaction.changelog_xdata[i];
e7a346
                         ia_type = inode->ia_type;
e7a346
                 }
e7a346
 
e7a346
@@ -1757,13 +1757,13 @@ afr_local_transaction_cleanup (afr_local_t *local, xlator_t *this)
e7a346
         GF_FREE (local->transaction.pre_op);
e7a346
 
e7a346
         GF_FREE (local->transaction.pre_op_sources);
e7a346
-        if (local->transaction.pre_op_xdata) {
e7a346
+        if (local->transaction.changelog_xdata) {
e7a346
                 for (i = 0; i < priv->child_count; i++) {
e7a346
-                        if (!local->transaction.pre_op_xdata[i])
e7a346
+                        if (!local->transaction.changelog_xdata[i])
e7a346
                                 continue;
e7a346
-                        dict_unref (local->transaction.pre_op_xdata[i]);
e7a346
+                        dict_unref (local->transaction.changelog_xdata[i]);
e7a346
                 }
e7a346
-                GF_FREE (local->transaction.pre_op_xdata);
e7a346
+                GF_FREE (local->transaction.changelog_xdata);
e7a346
         }
e7a346
 
e7a346
         GF_FREE (local->transaction.eager_lock);
e7a346
@@ -5531,10 +5531,10 @@ afr_transaction_local_init (afr_local_t *local, xlator_t *this)
e7a346
         if (!local->transaction.pre_op)
e7a346
                 goto out;
e7a346
 
e7a346
-        local->transaction.pre_op_xdata =
e7a346
-                GF_CALLOC (sizeof (*local->transaction.pre_op_xdata),
e7a346
+        local->transaction.changelog_xdata =
e7a346
+                GF_CALLOC (sizeof (*local->transaction.changelog_xdata),
e7a346
                            priv->child_count, gf_afr_mt_dict_t);
e7a346
-        if (!local->transaction.pre_op_xdata)
e7a346
+        if (!local->transaction.changelog_xdata)
e7a346
                 goto out;
e7a346
 
e7a346
         if (priv->arbiter_count == 1) {
e7a346
diff --git a/xlators/cluster/afr/src/afr-transaction.c b/xlators/cluster/afr/src/afr-transaction.c
e7a346
index 19740e1..97f9dd4 100644
e7a346
--- a/xlators/cluster/afr/src/afr-transaction.c
e7a346
+++ b/xlators/cluster/afr/src/afr-transaction.c
e7a346
@@ -276,9 +276,9 @@ afr_compute_pre_op_sources (call_frame_t *frame, xlator_t *this)
e7a346
         matrix = ALLOC_MATRIX (priv->child_count, int);
e7a346
 
e7a346
         for (i = 0; i < priv->child_count; i++) {
e7a346
-                if (!local->transaction.pre_op_xdata[i])
e7a346
+                if (!local->transaction.changelog_xdata[i])
e7a346
                         continue;
e7a346
-                xdata = local->transaction.pre_op_xdata[i];
e7a346
+                xdata = local->transaction.changelog_xdata[i];
e7a346
                 afr_selfheal_fill_matrix (this, matrix, i, idx, xdata);
e7a346
         }
e7a346
 
e7a346
@@ -295,13 +295,6 @@ afr_compute_pre_op_sources (call_frame_t *frame, xlator_t *this)
e7a346
                 for (j = 0; j < priv->child_count; j++)
e7a346
                         if (matrix[i][j] != 0)
e7a346
                                 local->transaction.pre_op_sources[j] = 0;
e7a346
-
e7a346
-        /*We don't need the xattrs any more. */
e7a346
-        for (i = 0; i < priv->child_count; i++)
e7a346
-                if (local->transaction.pre_op_xdata[i]) {
e7a346
-                        dict_unref (local->transaction.pre_op_xdata[i]);
e7a346
-                        local->transaction.pre_op_xdata[i] = NULL;
e7a346
-                }
e7a346
 }
e7a346
 
e7a346
 gf_boolean_t
e7a346
@@ -1173,7 +1166,7 @@ afr_changelog_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
e7a346
         }
e7a346
 
e7a346
         if (xattr)
e7a346
-                local->transaction.pre_op_xdata[child_index] = dict_ref (xattr);
e7a346
+                local->transaction.changelog_xdata[child_index] = dict_ref (xattr);
e7a346
 
e7a346
         call_count = afr_frame_return (frame);
e7a346
 
e7a346
@@ -1605,6 +1598,13 @@ afr_changelog_do (call_frame_t *frame, xlator_t *this, dict_t *xattr,
e7a346
 	local = frame->local;
e7a346
 	priv = this->private;
e7a346
 
e7a346
+        for (i = 0; i < priv->child_count; i++) {
e7a346
+                if (local->transaction.changelog_xdata[i]) {
e7a346
+                        dict_unref (local->transaction.changelog_xdata[i]);
e7a346
+                        local->transaction.changelog_xdata[i] = NULL;
e7a346
+                }
e7a346
+        }
e7a346
+
e7a346
         ret = afr_changelog_prepare (this, frame, &call_count, changelog_resume,
e7a346
                                      op, &xdata, &newloc_xdata);
e7a346
 
e7a346
diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h
e7a346
index 96fefb1..c822221 100644
e7a346
--- a/xlators/cluster/afr/src/afr.h
e7a346
+++ b/xlators/cluster/afr/src/afr.h
e7a346
@@ -748,8 +748,8 @@ typedef struct _afr_local {
e7a346
 
e7a346
                 unsigned char   *pre_op;
e7a346
 
e7a346
-                /* For arbiter configuration only. */
e7a346
-                dict_t **pre_op_xdata;
e7a346
+                /* Changelog xattr dict for [f]xattrop*/
e7a346
+                dict_t **changelog_xdata;
e7a346
                 unsigned char *pre_op_sources;
e7a346
 
e7a346
 		/* @failed_subvols: subvolumes on which a pre-op or a
e7a346
-- 
e7a346
1.8.3.1
e7a346