3604df
From 3a683040b602e9c981e9fb2beb28dc20d802ef10 Mon Sep 17 00:00:00 2001
3604df
From: Kotresh HR <khiremat@redhat.com>
3604df
Date: Wed, 17 Aug 2016 19:52:29 +0530
3604df
Subject: [PATCH 47/86] eventsapi: Bitrot events
3604df
3604df
Following Bitrot Events are added
3604df
3604df
BITROT_ENABLE/BITROT_DISABLE
3604df
{
3604df
    "nodeid": NODEID,
3604df
    "ts": TIMESTAMP,
3604df
    "event": EVENT_TYPE,
3604df
    "message": {
3604df
       "name": VOLUME_NAME,
3604df
    }
3604df
}
3604df
3604df
BITROT_SCRUB_THROTTLE/BITROT_SCRUB_FREQ/BITROT_SCRUB
3604df
{
3604df
    "nodeid": NODEID,
3604df
    "ts": TIMESTAMP,
3604df
    "event": EVENT_TYPE,
3604df
    "message": {
3604df
       "name": VOLUME_NAME,
3604df
       "value": OPTION_VALUE
3604df
    }
3604df
}
3604df
3604df
EVENT_BITROT_BAD_FILE
3604df
{
3604df
    "nodeid": NODEID,
3604df
    "ts": TIMESTAMP,
3604df
    "event": EVENT_TYPE,
3604df
    "message": {
3604df
       "gfid": GFID_OF_FILE,
3604df
       "brick": BRICK_ROOT,
3604df
       "path":  FILE_PATH_FROM_BRICK_ROOT (if available)
3604df
    }
3604df
}
3604df
3604df
>Reviewed-on: http://review.gluster.org/15190
3604df
>Smoke: 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
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
3604df
>Reviewed-by: Aravinda VK <avishwan@redhat.com>
3604df
3604df
Change-Id: I8c37b0e9db9f4f0f3d05d8f78b5521c7db0e2237
3604df
BUG: 1361170
3604df
Signed-off-by: Kotresh HR <khiremat@redhat.com>
3604df
Reviewed-on: https://code.engineering.redhat.com/gerrit/84792
3604df
Reviewed-by: Milind Changire <mchangir@redhat.com>
3604df
Reviewed-by: Aravinda Vishwanathapura Krishna Murthy <avishwan@redhat.com>
3604df
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
Tested-by: Atin Mukherjee <amukherj@redhat.com>
3604df
---
3604df
 cli/src/cli-cmd-volume.c                          |   64 +++++++++++++++++++++
3604df
 events/eventskeygen.py                            |    7 ++
3604df
 xlators/features/bit-rot/src/bitd/bit-rot-scrub.c |    2 +
3604df
 3 files changed, 73 insertions(+), 0 deletions(-)
3604df
3604df
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
3604df
index 3a7c9ed..0ea461e 100644
3604df
--- a/cli/src/cli-cmd-volume.c
3604df
+++ b/cli/src/cli-cmd-volume.c
3604df
@@ -1519,6 +1519,13 @@ cli_cmd_bitrot_cbk (struct cli_state *state, struct cli_cmd_word *word,
3604df
         cli_local_t             *local     = NULL;
3604df
         rpc_clnt_procedure_t    *proc      = NULL;
3604df
         int                     sent       = 0;
3604df
+#if (USE_EVENTS)
3604df
+        int                     cmd_type        = -1;
3604df
+        int                     ret1            = -1;
3604df
+        int                     event_type      = -1;
3604df
+        char                    *tmp            = NULL;
3604df
+        char                    *events_str     = NULL;
3604df
+#endif
3604df
 
3604df
         ret = cli_cmd_bitrot_parse (words, wordcount, &options);
3604df
         if (ret < 0) {
3604df
@@ -1554,6 +1561,63 @@ out:
3604df
 
3604df
         }
3604df
 
3604df
+#if (USE_EVENTS)
3604df
+        if (ret == 0) {
3604df
+                ret1 = dict_get_int32 (options, "type", &cmd_type);
3604df
+                if (ret1)
3604df
+                        cmd_type = -1;
3604df
+                else {
3604df
+                        ret1 = dict_get_str (options, "volname", &tmp);
3604df
+                        if (ret1)
3604df
+                                tmp = "";
3604df
+                        gf_asprintf (&events_str, "name=%s", tmp);
3604df
+                }
3604df
+
3604df
+                switch (cmd_type) {
3604df
+                case GF_BITROT_OPTION_TYPE_ENABLE:
3604df
+                        event_type = EVENT_BITROT_ENABLE;
3604df
+                        break;
3604df
+                case GF_BITROT_OPTION_TYPE_DISABLE:
3604df
+                        event_type = EVENT_BITROT_DISABLE;
3604df
+                        break;
3604df
+                case GF_BITROT_OPTION_TYPE_SCRUB_THROTTLE:
3604df
+                        event_type = EVENT_BITROT_SCRUB_THROTTLE;
3604df
+                        ret1 = dict_get_str (options, "scrub-throttle-value",
3604df
+                                             &tmp);
3604df
+                        if (ret1)
3604df
+                                tmp = "";
3604df
+                        gf_asprintf (&events_str, "%s;value=%s", events_str,
3604df
+                                     tmp);
3604df
+                        break;
3604df
+                case GF_BITROT_OPTION_TYPE_SCRUB_FREQ:
3604df
+                        event_type = EVENT_BITROT_SCRUB_FREQ;
3604df
+                        ret1 = dict_get_str (options, "scrub-frequency-value",
3604df
+                                             &tmp);
3604df
+                        if (ret1)
3604df
+                                tmp = "";
3604df
+                        gf_asprintf (&events_str, "%s;value=%s", events_str,
3604df
+                                     tmp);
3604df
+                        break;
3604df
+                case GF_BITROT_OPTION_TYPE_SCRUB:
3604df
+                        event_type = EVENT_BITROT_SCRUB_OPTION;
3604df
+                        ret1 = dict_get_str (options, "scrub-value", &tmp);
3604df
+                        if (ret1)
3604df
+                                tmp = "";
3604df
+                        gf_asprintf (&events_str, "%s;value=%s", events_str,
3604df
+                                     tmp);
3604df
+                        break;
3604df
+                default:
3604df
+                        break;
3604df
+                }
3604df
+
3604df
+                if (event_type > -1)
3604df
+                        gf_event (event_type, "%s", events_str);
3604df
+
3604df
+                if (events_str)
3604df
+                        GF_FREE (events_str);
3604df
+        }
3604df
+#endif
3604df
+
3604df
         CLI_STACK_DESTROY (frame);
3604df
 
3604df
         return ret;
3604df
diff --git a/events/eventskeygen.py b/events/eventskeygen.py
3604df
index 468c795..cac8b7e 100644
3604df
--- a/events/eventskeygen.py
3604df
+++ b/events/eventskeygen.py
3604df
@@ -39,6 +39,13 @@ keys = (
3604df
     "EVENT_GEOREP_DELETE",
3604df
     "EVENT_GEOREP_CONFIG_SET",
3604df
     "EVENT_GEOREP_CONFIG_RESET",
3604df
+
3604df
+    "EVENT_BITROT_ENABLE",
3604df
+    "EVENT_BITROT_DISABLE",
3604df
+    "EVENT_BITROT_SCRUB_THROTTLE",
3604df
+    "EVENT_BITROT_SCRUB_FREQ",
3604df
+    "EVENT_BITROT_SCRUB_OPTION",
3604df
+    "EVENT_BITROT_BAD_FILE",
3604df
 )
3604df
 
3604df
 LAST_EVENT = "EVENT_LAST"
3604df
diff --git a/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c b/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
3604df
index abf8dcf..265fe60 100644
3604df
--- a/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
3604df
+++ b/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
3604df
@@ -262,6 +262,8 @@ bitd_compare_ckum (xlator_t *this,
3604df
         gf_msg (this->name, GF_LOG_ALERT, 0, BRB_MSG_MARK_CORRUPTED, "Marking"
3604df
                 " %s [GFID: %s | Brick: %s] as corrupted..", loc->path,
3604df
                 uuid_utoa (linked_inode->gfid), child->brick_path);
3604df
+        gf_event (EVENT_BITROT_BAD_FILE, "gfid=%s;path=%s;brick=%s",
3604df
+                  uuid_utoa (linked_inode->gfid), loc->path, child->brick_path);
3604df
         ret = syncop_fsetxattr (child->xl, fd, xattr, 0, NULL, NULL);
3604df
         if (ret)
3604df
                 gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_MARK_BAD_FILE,
3604df
-- 
3604df
1.7.1
3604df