3604df
From 5f467f9f83c0fe81b0f54bcd23ad1f6aa86cd548 Mon Sep 17 00:00:00 2001
3604df
From: N Balachandran <nbalacha@redhat.com>
3604df
Date: Fri, 16 Sep 2016 22:23:51 +0530
3604df
Subject: [PATCH 70/86] dht/events:  Added rebalance events
3604df
3604df
The rebalance process will now send an event when it is
3604df
complete.
3604df
Also fixed a problem where the run-time was not always
3604df
set causing spurious rebalance failure events to be sent.
3604df
3604df
> Change-Id: Ib445171c78c9560940022bca20c887d31a9bb1ca
3604df
> BUG: 1371874
3604df
> Signed-off-by: N Balachandran <nbalacha@redhat.com>
3604df
> Reviewed-on: http://review.gluster.org/15501
3604df
> Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
3604df
> Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com>
3604df
3604df
>Reviewed-on: http://review.gluster.org/15520
3604df
>Smoke: Gluster Build System <jenkins@build.gluster.org>
3604df
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
3604df
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
3604df
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
3604df
Change-Id: Ia24038c04548a98aac899df10414585b988caa76
3604df
BUG: 1361066
3604df
Signed-off-by: N Balachandran <nbalacha@redhat.com>
3604df
Reviewed-on: https://code.engineering.redhat.com/gerrit/84875
3604df
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
Tested-by: Atin Mukherjee <amukherj@redhat.com>
3604df
---
3604df
 xlators/cluster/dht/src/dht-rebalance.c |   56 +++++++++++++++++++++++++++---
3604df
 1 files changed, 50 insertions(+), 6 deletions(-)
3604df
3604df
diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c
3604df
index 58b0d74..194fbb0 100644
3604df
--- a/xlators/cluster/dht/src/dht-rebalance.c
3604df
+++ b/xlators/cluster/dht/src/dht-rebalance.c
3604df
@@ -74,6 +74,49 @@ dht_set_global_defrag_error (gf_defrag_info_t *defrag, int ret)
3604df
 }
3604df
 
3604df
 static int
3604df
+dht_send_rebalance_event (xlator_t *this, gf_defrag_status_t status)
3604df
+{
3604df
+        int ret = -1;
3604df
+        char *volname = NULL;
3604df
+        char *tmpstr  = NULL;
3604df
+
3604df
+        eventtypes_t event = EVENT_LAST;
3604df
+
3604df
+        switch (status) {
3604df
+        case GF_DEFRAG_STATUS_COMPLETE:
3604df
+                event = EVENT_VOLUME_REBALANCE_COMPLETE;
3604df
+                break;
3604df
+        case GF_DEFRAG_STATUS_FAILED:
3604df
+                event = EVENT_VOLUME_REBALANCE_FAILED;
3604df
+                break;
3604df
+        case GF_DEFRAG_STATUS_STOPPED:
3604df
+                event = EVENT_VOLUME_REBALANCE_STOP;
3604df
+                break;
3604df
+        default:
3604df
+                break;
3604df
+
3604df
+        }
3604df
+
3604df
+        tmpstr = gf_strdup (this->name);
3604df
+        if (tmpstr) {
3604df
+                volname = strtok(tmpstr, "-dht");
3604df
+        }
3604df
+
3604df
+        if (!volname)
3604df
+                volname = this->name;
3604df
+
3604df
+        if (event != EVENT_LAST) {
3604df
+                ret = gf_event (event, "volume=%s", volname);
3604df
+        }
3604df
+        GF_FREE (tmpstr);
3604df
+        return ret;
3604df
+}
3604df
+
3604df
+
3604df
+
3604df
+
3604df
+
3604df
+static int
3604df
 dht_write_with_holes (xlator_t *to, fd_t *fd, struct iovec *vec, int count,
3604df
                       int32_t size, off_t offset, struct iobref *iobref)
3604df
 {
3604df
@@ -3823,6 +3866,8 @@ out:
3604df
                 defrag->defrag_status = GF_DEFRAG_STATUS_COMPLETE;
3604df
         }
3604df
 
3604df
+        dht_send_rebalance_event (this, defrag->defrag_status);
3604df
+
3604df
         LOCK (&defrag->lock);
3604df
         {
3604df
                 status = dict_new ();
3604df
@@ -3973,12 +4018,11 @@ gf_defrag_status_get (gf_defrag_info_t *defrag, dict_t *dict)
3604df
         if (ret)
3604df
                 gf_log (THIS->name, GF_LOG_WARNING,
3604df
                         "failed to set status");
3604df
-        if (elapsed) {
3604df
-                ret = dict_set_double (dict, "run-time", elapsed);
3604df
-                if (ret)
3604df
-                        gf_log (THIS->name, GF_LOG_WARNING,
3604df
-                                "failed to set run-time");
3604df
-        }
3604df
+
3604df
+        ret = dict_set_double (dict, "run-time", elapsed);
3604df
+        if (ret)
3604df
+                gf_log (THIS->name, GF_LOG_WARNING,
3604df
+                        "failed to set run-time");
3604df
 
3604df
         ret = dict_set_uint64 (dict, "failures", failures);
3604df
         if (ret)
3604df
-- 
3604df
1.7.1
3604df