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