233933
From b963fa8bb71963127147d33bf609f439dd5bd107 Mon Sep 17 00:00:00 2001
233933
From: Mohammed Rafi KC <rkavunga@redhat.com>
233933
Date: Thu, 27 Jun 2019 19:17:29 +0530
233933
Subject: [PATCH 220/221] graph/shd: Use top down approach while cleaning
233933
 xlator
233933
233933
We were cleaning xlator from botton to top, which might
233933
lead to problems when upper xlators trying to access
233933
the xlator object loaded below.
233933
233933
One such scenario is when fd_unref happens as part of the
233933
fini call which might lead to calling the releasedir to
233933
lower xlator. This will lead to invalid mem access
233933
233933
Backport of:https://review.gluster.org/#/c/glusterfs/+/22968/
233933
233933
>Change-Id: I8a6cb619256fab0b0c01a2d564fc88287c4415a0
233933
>Updates: bz#1716695
233933
>Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
233933
233933
Change-Id: I22bbf99e9451183b3e0fe61b57b2440ab4163fe5
233933
BUG: 1711939
233933
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
233933
Reviewed-on: https://code.engineering.redhat.com/gerrit/174882
233933
Tested-by: RHGS Build Bot <nigelb@redhat.com>
233933
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
233933
---
233933
 libglusterfs/src/graph.c                         | 10 +++++++++-
233933
 xlators/features/bit-rot/src/stub/bit-rot-stub.c |  1 +
233933
 xlators/features/changelog/src/changelog.c       |  1 +
233933
 xlators/features/cloudsync/src/cloudsync.c       |  4 +++-
233933
 xlators/features/index/src/index.c               |  1 +
233933
 xlators/features/quiesce/src/quiesce.c           |  1 +
233933
 xlators/features/read-only/src/worm.c            |  1 +
233933
 xlators/features/sdfs/src/sdfs.c                 |  1 +
233933
 xlators/features/selinux/src/selinux.c           |  2 ++
233933
 xlators/features/trash/src/trash.c               |  1 +
233933
 10 files changed, 21 insertions(+), 2 deletions(-)
233933
233933
diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c
233933
index 5b95fd6..172dc61 100644
233933
--- a/libglusterfs/src/graph.c
233933
+++ b/libglusterfs/src/graph.c
233933
@@ -1193,6 +1193,14 @@ glusterfs_graph_fini(glusterfs_graph_t *graph)
233933
         if (trav->init_succeeded) {
233933
             trav->cleanup_starting = 1;
233933
             trav->fini(trav);
233933
+            if (trav->local_pool) {
233933
+                mem_pool_destroy(trav->local_pool);
233933
+                trav->local_pool = NULL;
233933
+            }
233933
+            if (trav->itable) {
233933
+                inode_table_destroy(trav->itable);
233933
+                trav->itable = NULL;
233933
+            }
233933
             trav->init_succeeded = 0;
233933
         }
233933
         trav = trav->next;
233933
@@ -1394,7 +1402,7 @@ glusterfs_graph_cleanup(void *arg)
233933
 
233933
     pthread_mutex_lock(&ctx->cleanup_lock);
233933
     {
233933
-        glusterfs_graph_deactivate(graph);
233933
+        glusterfs_graph_fini(graph);
233933
         glusterfs_graph_destroy(graph);
233933
     }
233933
     pthread_mutex_unlock(&ctx->cleanup_lock);
233933
diff --git a/xlators/features/bit-rot/src/stub/bit-rot-stub.c b/xlators/features/bit-rot/src/stub/bit-rot-stub.c
233933
index 3f48a4b..03446be 100644
233933
--- a/xlators/features/bit-rot/src/stub/bit-rot-stub.c
233933
+++ b/xlators/features/bit-rot/src/stub/bit-rot-stub.c
233933
@@ -185,6 +185,7 @@ cleanup_lock:
233933
     pthread_mutex_destroy(&priv->lock);
233933
 free_mempool:
233933
     mem_pool_destroy(priv->local_pool);
233933
+    priv->local_pool = NULL;
233933
 free_priv:
233933
     GF_FREE(priv);
233933
     this->private = NULL;
233933
diff --git a/xlators/features/changelog/src/changelog.c b/xlators/features/changelog/src/changelog.c
233933
index d9025f3..2862d1e 100644
233933
--- a/xlators/features/changelog/src/changelog.c
233933
+++ b/xlators/features/changelog/src/changelog.c
233933
@@ -2790,6 +2790,7 @@ cleanup_options:
233933
     changelog_freeup_options(this, priv);
233933
 cleanup_mempool:
233933
     mem_pool_destroy(this->local_pool);
233933
+    this->local_pool = NULL;
233933
 cleanup_priv:
233933
     GF_FREE(priv);
233933
 error_return:
233933
diff --git a/xlators/features/cloudsync/src/cloudsync.c b/xlators/features/cloudsync/src/cloudsync.c
233933
index 26e512c..0ad987e 100644
233933
--- a/xlators/features/cloudsync/src/cloudsync.c
233933
+++ b/xlators/features/cloudsync/src/cloudsync.c
233933
@@ -200,8 +200,10 @@ cs_init(xlator_t *this)
233933
 
233933
 out:
233933
     if (ret == -1) {
233933
-        if (this->local_pool)
233933
+        if (this->local_pool) {
233933
             mem_pool_destroy(this->local_pool);
233933
+            this->local_pool = NULL;
233933
+        }
233933
 
233933
         cs_cleanup_private(priv);
233933
 
233933
diff --git a/xlators/features/index/src/index.c b/xlators/features/index/src/index.c
233933
index 2f2a6d0..4ece7ff 100644
233933
--- a/xlators/features/index/src/index.c
233933
+++ b/xlators/features/index/src/index.c
233933
@@ -2478,6 +2478,7 @@ out:
233933
             GF_FREE(priv);
233933
         this->private = NULL;
233933
         mem_pool_destroy(this->local_pool);
233933
+        this->local_pool = NULL;
233933
     }
233933
 
233933
     if (attr_inited)
233933
diff --git a/xlators/features/quiesce/src/quiesce.c b/xlators/features/quiesce/src/quiesce.c
233933
index bfd1116..06f58c9 100644
233933
--- a/xlators/features/quiesce/src/quiesce.c
233933
+++ b/xlators/features/quiesce/src/quiesce.c
233933
@@ -2536,6 +2536,7 @@ fini(xlator_t *this)
233933
     this->private = NULL;
233933
 
233933
     mem_pool_destroy(priv->local_pool);
233933
+    priv->local_pool = NULL;
233933
     LOCK_DESTROY(&priv->lock);
233933
     GF_FREE(priv);
233933
 out:
233933
diff --git a/xlators/features/read-only/src/worm.c b/xlators/features/read-only/src/worm.c
233933
index 24196f8..7d13180 100644
233933
--- a/xlators/features/read-only/src/worm.c
233933
+++ b/xlators/features/read-only/src/worm.c
233933
@@ -569,6 +569,7 @@ fini(xlator_t *this)
233933
     mem_put(priv);
233933
     this->private = NULL;
233933
     mem_pool_destroy(this->local_pool);
233933
+    this->local_pool = NULL;
233933
 out:
233933
     return;
233933
 }
233933
diff --git a/xlators/features/sdfs/src/sdfs.c b/xlators/features/sdfs/src/sdfs.c
233933
index f0247fd..164c632 100644
233933
--- a/xlators/features/sdfs/src/sdfs.c
233933
+++ b/xlators/features/sdfs/src/sdfs.c
233933
@@ -1429,6 +1429,7 @@ void
233933
 fini(xlator_t *this)
233933
 {
233933
     mem_pool_destroy(this->local_pool);
233933
+    this->local_pool = NULL;
233933
     return;
233933
 }
233933
 
233933
diff --git a/xlators/features/selinux/src/selinux.c b/xlators/features/selinux/src/selinux.c
233933
index 58b4c5d..ce5fc90 100644
233933
--- a/xlators/features/selinux/src/selinux.c
233933
+++ b/xlators/features/selinux/src/selinux.c
233933
@@ -256,6 +256,7 @@ out:
233933
             GF_FREE(priv);
233933
         }
233933
         mem_pool_destroy(this->local_pool);
233933
+        this->local_pool = NULL;
233933
     }
233933
     return ret;
233933
 }
233933
@@ -284,6 +285,7 @@ fini(xlator_t *this)
233933
     GF_FREE(priv);
233933
 
233933
     mem_pool_destroy(this->local_pool);
233933
+    this->local_pool = NULL;
233933
 
233933
     return;
233933
 }
233933
diff --git a/xlators/features/trash/src/trash.c b/xlators/features/trash/src/trash.c
233933
index d668436..eb5007b 100644
233933
--- a/xlators/features/trash/src/trash.c
233933
+++ b/xlators/features/trash/src/trash.c
233933
@@ -2523,6 +2523,7 @@ out:
233933
             GF_FREE(priv);
233933
         }
233933
         mem_pool_destroy(this->local_pool);
233933
+        this->local_pool = NULL;
233933
     }
233933
     return ret;
233933
 }
233933
-- 
233933
1.8.3.1
233933