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