From 0801dda0347556d6a933c44016ef789a370b8586 Mon Sep 17 00:00:00 2001
From: N Balachandran <nbalacha@redhat.com>
Date: Wed, 26 Oct 2016 09:25:47 +0530
Subject: [PATCH 143/157] cluster/dht: Incorrect volname in rebalance events
The rebalance event code was using strtok to parse the
volume name which is incorrect.
Reworked the code to get the correct volume name using
strstr.
Upstream patches:
master: http://review.gluster.org/15712
release-3.9: http://review.gluster.org/#/c/15725/
Change-Id: I7c00445bafe08034f77c422d2f60ac3252c7afd6
BUG: 1386472
Signed-off-by: N Balachandran <nbalacha@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/88228
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Atin Mukherjee <amukherj@redhat.com>
---
xlators/cluster/dht/src/dht-rebalance.c | 56 +++++++++++++++++++++++++++---
1 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c
index 194fbb0..5d28e0a 100644
--- a/xlators/cluster/dht/src/dht-rebalance.c
+++ b/xlators/cluster/dht/src/dht-rebalance.c
@@ -73,12 +73,40 @@ dht_set_global_defrag_error (gf_defrag_info_t *defrag, int ret)
return;
}
+
+static gf_boolean_t
+dht_is_tier_command (int cmd) {
+
+ gf_boolean_t is_tier = _gf_false;
+
+ switch (cmd) {
+ case GF_DEFRAG_CMD_START_TIER:
+ case GF_DEFRAG_CMD_STATUS_TIER:
+ case GF_DEFRAG_CMD_START_DETACH_TIER:
+ case GF_DEFRAG_CMD_STOP_DETACH_TIER:
+ case GF_DEFRAG_CMD_PAUSE_TIER:
+ case GF_DEFRAG_CMD_RESUME_TIER:
+ is_tier = _gf_true;
+ break;
+ default:
+ break;
+ }
+ return is_tier;
+
+}
+
+
static int
-dht_send_rebalance_event (xlator_t *this, gf_defrag_status_t status)
+dht_send_rebalance_event (xlator_t *this, int cmd, gf_defrag_status_t status)
{
int ret = -1;
char *volname = NULL;
char *tmpstr = NULL;
+ char *ptr = NULL;
+ char *suffix = "-dht";
+ dht_conf_t *conf = NULL;
+ gf_defrag_info_t *defrag = NULL;
+ int len = 0;
eventtypes_t event = EVENT_LAST;
@@ -97,17 +125,33 @@ dht_send_rebalance_event (xlator_t *this, gf_defrag_status_t status)
}
- tmpstr = gf_strdup (this->name);
- if (tmpstr) {
- volname = strtok(tmpstr, "-dht");
+ if (dht_is_tier_command (cmd)) {
+ /* We should have the tier volume name*/
+ conf = this->private;
+ defrag = conf->defrag;
+ volname = defrag->tier_conf.volname;
+ } else {
+ /* DHT volume */
+ len = strlen (this->name);
+ tmpstr = gf_strdup (this->name);
+ if (tmpstr) {
+ ptr = tmpstr + (len - strlen (suffix));
+ if (!strcmp (ptr, suffix)) {
+ tmpstr[len - strlen (suffix)] = '\0';
+ volname = tmpstr;
+ }
+ }
}
- if (!volname)
+ if (!volname) {
+ /* Better than nothing */
volname = this->name;
+ }
if (event != EVENT_LAST) {
ret = gf_event (event, "volume=%s", volname);
}
+
GF_FREE (tmpstr);
return ret;
}
@@ -3866,7 +3910,7 @@ out:
defrag->defrag_status = GF_DEFRAG_STATUS_COMPLETE;
}
- dht_send_rebalance_event (this, defrag->defrag_status);
+ dht_send_rebalance_event (this, defrag->cmd, defrag->defrag_status);
LOCK (&defrag->lock);
{
--
1.7.1