e7a346
From 47678bde5c2f8e674289d2b0893865ab3fa43940 Mon Sep 17 00:00:00 2001
e7a346
From: Atin Mukherjee <amukherj@redhat.com>
e7a346
Date: Sun, 1 Apr 2018 10:10:41 +0530
e7a346
Subject: [PATCH 207/212] glusterd: fix txn_opinfo memory leak
e7a346
e7a346
For transactions where there's no volname involved (eg : gluster v
e7a346
status), the originator node initiates with staging phase and what that
e7a346
means in op-sm there's no unlock event triggered which resulted into a
e7a346
txn_opinfo dictionary leak.
e7a346
e7a346
Credits : cynthia.zhou@nokia-sbell.com
e7a346
e7a346
> upstream patch : https://review.gluster.org/#/c/19801/
e7a346
e7a346
>Change-Id: I92fffbc2e8e1b010f489060f461be78aa2b86615
e7a346
>Fixes: bz#1550339
e7a346
>Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
e7a346
e7a346
Change-Id: I92fffbc2e8e1b010f489060f461be78aa2b86615
e7a346
BUG: 1529451
e7a346
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/134448
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
---
e7a346
 xlators/mgmt/glusterd/src/glusterd-handler.c |  1 +
e7a346
 xlators/mgmt/glusterd/src/glusterd-op-sm.c   | 32 ++++++++++++++++++++--------
e7a346
 xlators/mgmt/glusterd/src/glusterd-op-sm.h   |  1 +
e7a346
 3 files changed, 25 insertions(+), 9 deletions(-)
e7a346
e7a346
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
e7a346
index ddab159..dbf80a1 100644
e7a346
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
e7a346
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
e7a346
@@ -1073,6 +1073,7 @@ __glusterd_handle_stage_op (rpcsvc_request_t *req)
e7a346
                 glusterd_txn_opinfo_init (&txn_op_info, &state, &op_req.op,
e7a346
                                           req_ctx->dict, req);
e7a346
 
e7a346
+                txn_op_info.skip_locking = _gf_true;
e7a346
                 ret = glusterd_set_txn_opinfo (txn_id, &txn_op_info);
e7a346
                 if (ret) {
e7a346
                         gf_msg (this->name, GF_LOG_ERROR, 0,
e7a346
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
e7a346
index a02a0b3..72d349b 100644
e7a346
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
e7a346
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
e7a346
@@ -5919,14 +5919,15 @@ glusterd_op_init_commit_rsp_dict (glusterd_op_t op)
e7a346
 static int
e7a346
 glusterd_op_ac_commit_op (glusterd_op_sm_event_t *event, void *ctx)
e7a346
 {
e7a346
-        int                       ret        = 0;
e7a346
-        glusterd_req_ctx_t       *req_ctx    = NULL;
e7a346
-        int32_t                   status     = 0;
e7a346
-        char                     *op_errstr  = NULL;
e7a346
-        dict_t                   *dict       = NULL;
e7a346
-        dict_t                   *rsp_dict   = NULL;
e7a346
-        xlator_t                 *this       = NULL;
e7a346
-        uuid_t                   *txn_id     = NULL;
e7a346
+        int                       ret         = 0;
e7a346
+        glusterd_req_ctx_t       *req_ctx     = NULL;
e7a346
+        int32_t                   status      = 0;
e7a346
+        char                     *op_errstr   = NULL;
e7a346
+        dict_t                   *dict        = NULL;
e7a346
+        dict_t                   *rsp_dict    = NULL;
e7a346
+        xlator_t                 *this        = NULL;
e7a346
+        uuid_t                   *txn_id      = NULL;
e7a346
+        glusterd_op_info_t        txn_op_info = {{0},};
e7a346
 
e7a346
         this = THIS;
e7a346
         GF_ASSERT (this);
e7a346
@@ -5965,6 +5966,15 @@ glusterd_op_ac_commit_op (glusterd_op_sm_event_t *event, void *ctx)
e7a346
                 ret = -1;
e7a346
                 goto out;
e7a346
         }
e7a346
+        ret = glusterd_get_txn_opinfo (&event->txn_id, &txn_op_info);
e7a346
+        if (ret) {
e7a346
+                gf_msg_callingfn (this->name, GF_LOG_ERROR, 0,
e7a346
+                        GD_MSG_TRANS_OPINFO_GET_FAIL,
e7a346
+                        "Unable to get transaction opinfo "
e7a346
+                        "for transaction ID : %s",
e7a346
+                        uuid_utoa (event->txn_id));
e7a346
+                goto out;
e7a346
+        }
e7a346
 
e7a346
         ret = dict_set_bin (rsp_dict, "transaction_id",
e7a346
                             txn_id, sizeof(*txn_id));
e7a346
@@ -5985,7 +5995,11 @@ out:
e7a346
 
e7a346
         if (rsp_dict)
e7a346
                 dict_unref (rsp_dict);
e7a346
-
e7a346
+        /* for no volname transactions, the txn_opinfo needs to be cleaned up
e7a346
+         * as there's no unlock event triggered
e7a346
+         */
e7a346
+        if (txn_op_info.skip_locking)
e7a346
+                ret = glusterd_clear_txn_opinfo (txn_id);
e7a346
         gf_msg_debug (this->name, 0, "Returning with %d", ret);
e7a346
 
e7a346
         return ret;
e7a346
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h
e7a346
index 24b1944..f2aee9c 100644
e7a346
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h
e7a346
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h
e7a346
@@ -101,6 +101,7 @@ struct glusterd_op_info_ {
e7a346
         char                            *op_errstr;
e7a346
         struct  cds_list_head           pending_bricks;
e7a346
         uint32_t                        txn_generation;
e7a346
+        gf_boolean_t                    skip_locking;
e7a346
 };
e7a346
 
e7a346
 typedef struct glusterd_op_info_ glusterd_op_info_t;
e7a346
-- 
e7a346
1.8.3.1
e7a346