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