e3c68b
From faaaa3452ceec6afcc18cffc9beca3fe19841cce Mon Sep 17 00:00:00 2001
e3c68b
From: Mohammed Rafi KC <rkavunga@redhat.com>
e3c68b
Date: Thu, 3 Jan 2019 17:44:18 +0530
e3c68b
Subject: [PATCH 104/124] afr/shd: Cleanup self heal daemon resources during
e3c68b
 afr fini
e3c68b
e3c68b
We were not properly cleaning self-heal daemon resources
e3c68b
during afr fini. This patch will clean the same.
e3c68b
e3c68b
Backport of: https://review.gluster.org/#/c/glusterfs/+/22151/
e3c68b
e3c68b
>Change-Id: I597860be6f781b195449e695d871b8667a418d5a
e3c68b
>updates: bz#1659708
e3c68b
>Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
e3c68b
e3c68b
Change-Id: I7be981b9c2476c8cacadea6b14d74234f67b714f
e3c68b
BUG: 1471742
e3c68b
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
e3c68b
Reviewed-on: https://code.engineering.redhat.com/gerrit/167845
e3c68b
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e3c68b
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
e3c68b
---
e3c68b
 libglusterfs/src/syncop-utils.c          |  8 +++++
e3c68b
 xlators/cluster/afr/src/afr-self-heald.c |  2 ++
e3c68b
 xlators/cluster/afr/src/afr.c            | 57 ++++++++++++++++++++++++++++++++
e3c68b
 3 files changed, 67 insertions(+)
e3c68b
e3c68b
diff --git a/libglusterfs/src/syncop-utils.c b/libglusterfs/src/syncop-utils.c
e3c68b
index be03527..b842142 100644
e3c68b
--- a/libglusterfs/src/syncop-utils.c
e3c68b
+++ b/libglusterfs/src/syncop-utils.c
e3c68b
@@ -350,6 +350,11 @@ syncop_mt_dir_scan(call_frame_t *frame, xlator_t *subvol, loc_t *loc, int pid,
e3c68b
     gf_boolean_t cond_init = _gf_false;
e3c68b
     gf_boolean_t mut_init = _gf_false;
e3c68b
     gf_dirent_t entries;
e3c68b
+    xlator_t *this = NULL;
e3c68b
+
e3c68b
+    if (frame) {
e3c68b
+        this = frame->this;
e3c68b
+    }
e3c68b
 
e3c68b
     /*For this functionality to be implemented in general, we need
e3c68b
      * synccond_t infra which doesn't block the executing thread. Until then
e3c68b
@@ -397,6 +402,9 @@ syncop_mt_dir_scan(call_frame_t *frame, xlator_t *subvol, loc_t *loc, int pid,
e3c68b
 
e3c68b
         list_for_each_entry_safe(entry, tmp, &entries.list, list)
e3c68b
         {
e3c68b
+            if (this && this->cleanup_starting)
e3c68b
+                goto out;
e3c68b
+
e3c68b
             list_del_init(&entry->list);
e3c68b
             if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) {
e3c68b
                 gf_dirent_entry_free(entry);
e3c68b
diff --git a/xlators/cluster/afr/src/afr-self-heald.c b/xlators/cluster/afr/src/afr-self-heald.c
e3c68b
index 7eb1207..8bc4720 100644
e3c68b
--- a/xlators/cluster/afr/src/afr-self-heald.c
e3c68b
+++ b/xlators/cluster/afr/src/afr-self-heald.c
e3c68b
@@ -373,6 +373,7 @@ afr_shd_sweep_prepare(struct subvol_healer *healer)
e3c68b
 
e3c68b
     time(&event->start_time);
e3c68b
     event->end_time = 0;
e3c68b
+    _mask_cancellation();
e3c68b
 }
e3c68b
 
e3c68b
 void
e3c68b
@@ -394,6 +395,7 @@ afr_shd_sweep_done(struct subvol_healer *healer)
e3c68b
 
e3c68b
     if (eh_save_history(shd->statistics[healer->subvol], history) < 0)
e3c68b
         GF_FREE(history);
e3c68b
+    _unmask_cancellation();
e3c68b
 }
e3c68b
 
e3c68b
 int
e3c68b
diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c
e3c68b
index 33258a0..a0a7551 100644
e3c68b
--- a/xlators/cluster/afr/src/afr.c
e3c68b
+++ b/xlators/cluster/afr/src/afr.c
e3c68b
@@ -611,13 +611,70 @@ init(xlator_t *this)
e3c68b
 out:
e3c68b
     return ret;
e3c68b
 }
e3c68b
+void
e3c68b
+afr_destroy_healer_object(xlator_t *this, struct subvol_healer *healer)
e3c68b
+{
e3c68b
+    int ret = -1;
e3c68b
+
e3c68b
+    if (!healer)
e3c68b
+        return;
e3c68b
+
e3c68b
+    if (healer->running) {
e3c68b
+        /*
e3c68b
+         * If there are any resources to cleanup, We need
e3c68b
+         * to do that gracefully using pthread_cleanup_push
e3c68b
+         */
e3c68b
+        ret = gf_thread_cleanup_xint(healer->thread);
e3c68b
+        if (ret)
e3c68b
+            gf_msg(this->name, GF_LOG_WARNING, 0, AFR_MSG_SELF_HEAL_FAILED,
e3c68b
+                   "Failed to clean up healer threads.");
e3c68b
+        healer->thread = 0;
e3c68b
+    }
e3c68b
+    pthread_cond_destroy(&healer->cond);
e3c68b
+    pthread_mutex_destroy(&healer->mutex);
e3c68b
+}
e3c68b
+
e3c68b
+void
e3c68b
+afr_selfheal_daemon_fini(xlator_t *this)
e3c68b
+{
e3c68b
+    struct subvol_healer *healer = NULL;
e3c68b
+    afr_self_heald_t *shd = NULL;
e3c68b
+    afr_private_t *priv = NULL;
e3c68b
+    int i = 0;
e3c68b
+
e3c68b
+    priv = this->private;
e3c68b
+    if (!priv)
e3c68b
+        return;
e3c68b
+
e3c68b
+    shd = &priv->shd;
e3c68b
+    if (!shd->iamshd)
e3c68b
+        return;
e3c68b
+
e3c68b
+    for (i = 0; i < priv->child_count; i++) {
e3c68b
+        healer = &shd->index_healers[i];
e3c68b
+        afr_destroy_healer_object(this, healer);
e3c68b
 
e3c68b
+        healer = &shd->full_healers[i];
e3c68b
+        afr_destroy_healer_object(this, healer);
e3c68b
+
e3c68b
+        if (shd->statistics[i])
e3c68b
+            eh_destroy(shd->statistics[i]);
e3c68b
+    }
e3c68b
+    GF_FREE(shd->index_healers);
e3c68b
+    GF_FREE(shd->full_healers);
e3c68b
+    GF_FREE(shd->statistics);
e3c68b
+    if (shd->split_brain)
e3c68b
+        eh_destroy(shd->split_brain);
e3c68b
+}
e3c68b
 void
e3c68b
 fini(xlator_t *this)
e3c68b
 {
e3c68b
     afr_private_t *priv = NULL;
e3c68b
 
e3c68b
     priv = this->private;
e3c68b
+
e3c68b
+    afr_selfheal_daemon_fini(this);
e3c68b
+
e3c68b
     LOCK(&priv->lock);
e3c68b
     if (priv->timer != NULL) {
e3c68b
         gf_timer_call_cancel(this->ctx, priv->timer);
e3c68b
-- 
e3c68b
1.8.3.1
e3c68b