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