256ebe
From 998d9b8b5e271f407e1c654c34f45f0db36abc71 Mon Sep 17 00:00:00 2001
256ebe
From: Mohammed Rafi KC <rkavunga@redhat.com>
256ebe
Date: Tue, 21 May 2019 17:15:07 +0530
256ebe
Subject: [PATCH 172/178] ec/fini: Fix race with ec_fini and ec_notify
256ebe
256ebe
During a graph cleanup, we first sent a PARENT_DOWN and wait for
256ebe
a child down to ultimately free the xlator and the graph.
256ebe
256ebe
In the ec xlator, we cleanup the threads when we get a PARENT_DOWN event.
256ebe
But a racing event like CHILD_UP or event xl_op may trigger healing threads
256ebe
after threads cleanup.
256ebe
256ebe
So there is a chance that the threads might access a freed private variabe
256ebe
256ebe
Upstream patch: https://review.gluster.org/#/c/glusterfs/+/22758/
256ebe
256ebe
>Change-Id: I252d10181bb67b95900c903d479de707a8489532
256ebe
>fixes: bz#1703948
256ebe
>Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
256ebe
256ebe
Change-Id: I84a10352d9fb3e68d4147b3791e3af45ab79050e
256ebe
BUG: 1703434
256ebe
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
256ebe
Reviewed-on: https://code.engineering.redhat.com/gerrit/172285
256ebe
Tested-by: RHGS Build Bot <nigelb@redhat.com>
256ebe
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
256ebe
---
256ebe
 libglusterfs/src/glusterfs/xlator.h |  3 +++
256ebe
 libglusterfs/src/libglusterfs.sym   |  1 +
256ebe
 libglusterfs/src/xlator.c           | 21 +++++++++++++++++++++
256ebe
 xlators/cluster/ec/src/ec-heal.c    |  4 ++++
256ebe
 xlators/cluster/ec/src/ec-heald.c   |  6 ++++++
256ebe
 xlators/cluster/ec/src/ec.c         |  3 +++
256ebe
 6 files changed, 38 insertions(+)
256ebe
256ebe
diff --git a/libglusterfs/src/glusterfs/xlator.h b/libglusterfs/src/glusterfs/xlator.h
256ebe
index 8998976..09e463e 100644
256ebe
--- a/libglusterfs/src/glusterfs/xlator.h
256ebe
+++ b/libglusterfs/src/glusterfs/xlator.h
256ebe
@@ -1092,4 +1092,7 @@ gluster_graph_take_reference(xlator_t *tree);
256ebe
 
256ebe
 gf_boolean_t
256ebe
 mgmt_is_multiplexed_daemon(char *name);
256ebe
+
256ebe
+gf_boolean_t
256ebe
+xlator_is_cleanup_starting(xlator_t *this);
256ebe
 #endif /* _XLATOR_H */
256ebe
diff --git a/libglusterfs/src/libglusterfs.sym b/libglusterfs/src/libglusterfs.sym
256ebe
index ec474e7..7a2edef 100644
256ebe
--- a/libglusterfs/src/libglusterfs.sym
256ebe
+++ b/libglusterfs/src/libglusterfs.sym
256ebe
@@ -1161,3 +1161,4 @@ glusterfs_process_svc_attach_volfp
256ebe
 glusterfs_mux_volfile_reconfigure
256ebe
 glusterfs_process_svc_detach
256ebe
 mgmt_is_multiplexed_daemon
256ebe
+xlator_is_cleanup_starting
256ebe
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
256ebe
index 022c3ed..fbfbbe2 100644
256ebe
--- a/libglusterfs/src/xlator.c
256ebe
+++ b/libglusterfs/src/xlator.c
256ebe
@@ -1486,3 +1486,24 @@ mgmt_is_multiplexed_daemon(char *name)
256ebe
     }
256ebe
     return _gf_false;
256ebe
 }
256ebe
+
256ebe
+gf_boolean_t
256ebe
+xlator_is_cleanup_starting(xlator_t *this)
256ebe
+{
256ebe
+    gf_boolean_t cleanup = _gf_false;
256ebe
+    glusterfs_graph_t *graph = NULL;
256ebe
+    xlator_t *xl = NULL;
256ebe
+
256ebe
+    if (!this)
256ebe
+        goto out;
256ebe
+    graph = this->graph;
256ebe
+
256ebe
+    if (!graph)
256ebe
+        goto out;
256ebe
+
256ebe
+    xl = graph->first;
256ebe
+    if (xl && xl->cleanup_starting)
256ebe
+        cleanup = _gf_true;
256ebe
+out:
256ebe
+    return cleanup;
256ebe
+}
256ebe
diff --git a/xlators/cluster/ec/src/ec-heal.c b/xlators/cluster/ec/src/ec-heal.c
256ebe
index 2fa1f11..8844c29 100644
256ebe
--- a/xlators/cluster/ec/src/ec-heal.c
256ebe
+++ b/xlators/cluster/ec/src/ec-heal.c
256ebe
@@ -2855,6 +2855,10 @@ ec_replace_brick_heal_wrap(void *opaque)
256ebe
         itable = ec->xl->itable;
256ebe
     else
256ebe
         goto out;
256ebe
+
256ebe
+    if (xlator_is_cleanup_starting(ec->xl))
256ebe
+        goto out;
256ebe
+
256ebe
     ret = ec_replace_heal(ec, itable->root);
256ebe
 out:
256ebe
     return ret;
256ebe
diff --git a/xlators/cluster/ec/src/ec-heald.c b/xlators/cluster/ec/src/ec-heald.c
256ebe
index edf5e11..91512d7 100644
256ebe
--- a/xlators/cluster/ec/src/ec-heald.c
256ebe
+++ b/xlators/cluster/ec/src/ec-heald.c
256ebe
@@ -444,6 +444,9 @@ unlock:
256ebe
 int
256ebe
 ec_shd_full_healer_spawn(xlator_t *this, int subvol)
256ebe
 {
256ebe
+    if (xlator_is_cleanup_starting(this))
256ebe
+        return -1;
256ebe
+
256ebe
     return ec_shd_healer_spawn(this, NTH_FULL_HEALER(this, subvol),
256ebe
                                ec_shd_full_healer);
256ebe
 }
256ebe
@@ -451,6 +454,9 @@ ec_shd_full_healer_spawn(xlator_t *this, int subvol)
256ebe
 int
256ebe
 ec_shd_index_healer_spawn(xlator_t *this, int subvol)
256ebe
 {
256ebe
+    if (xlator_is_cleanup_starting(this))
256ebe
+        return -1;
256ebe
+
256ebe
     return ec_shd_healer_spawn(this, NTH_INDEX_HEALER(this, subvol),
256ebe
                                ec_shd_index_healer);
256ebe
 }
256ebe
diff --git a/xlators/cluster/ec/src/ec.c b/xlators/cluster/ec/src/ec.c
256ebe
index 264582a..df5912c 100644
256ebe
--- a/xlators/cluster/ec/src/ec.c
256ebe
+++ b/xlators/cluster/ec/src/ec.c
256ebe
@@ -486,6 +486,9 @@ ec_set_up_state(ec_t *ec, uintptr_t index_mask, uintptr_t new_state)
256ebe
 {
256ebe
     uintptr_t current_state = 0;
256ebe
 
256ebe
+    if (xlator_is_cleanup_starting(ec->xl))
256ebe
+        return _gf_false;
256ebe
+
256ebe
     if ((ec->xl_notify & index_mask) == 0) {
256ebe
         ec->xl_notify |= index_mask;
256ebe
         ec->xl_notify_count++;
256ebe
-- 
256ebe
1.8.3.1
256ebe