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