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