Blob Blame History Raw
From 0141f90b41ecd102e52a7e605858e25bd084a044 Mon Sep 17 00:00:00 2001
From: Sunny Kumar <sunkumar@redhat.com>
Date: Thu, 1 Feb 2018 12:08:06 +0530
Subject: [PATCH 137/139] bitrot : improved cli report after bitrot operatoin

Improved cli report post bitrot opertaion as previously it was
showing output "volume bitrot: success" for all the sucessfull
bitrot operations (enable, disable or scrub options).

Upstream Patch : https://review.gluster.org/c/19344/

>BUG: 1539166
>Signed-off-by: Sunny Kumar <sunkumar@redhat.com>

BUG: 1517463

Change-Id: I0857e99f3956221a51cfd1b29a90e1038b90570f
Signed-off-by: Sunny Kumar <sunkumar@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/129218
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 cli/src/cli-rpc-ops.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index b91400b..1bb01e8 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -11922,6 +11922,10 @@ gf_cli_bitrot_cbk (struct rpc_req *req, struct iovec *iov,
         int                  type                      = 0;
         gf_cli_rsp           rsp                       = {0, };
         dict_t               *dict                     = NULL;
+        char                 *scrub_cmd                = NULL;
+        char                 *volname                  = NULL;
+        char                 *cmd_str                  = NULL;
+        char                 *cmd_op                   = NULL;
 
         GF_ASSERT (myframe);
 
@@ -11977,6 +11981,22 @@ gf_cli_bitrot_cbk (struct rpc_req *req, struct iovec *iov,
                 goto out;
         }
 
+        /* Ignoring the error, as using dict val for cli output only */
+        ret = dict_get_str (dict, "scrub-value", &scrub_cmd);
+        if (ret)
+                gf_log ("cli", GF_LOG_TRACE, "Failed to get scrub command");
+
+        ret = dict_get_str (dict, "volname", &volname);
+        if (ret)
+                gf_log ("cli", GF_LOG_TRACE, "failed to get volume name");
+
+        ret = dict_get_str (dict, "cmd-str", &cmd_str);
+        if (ret)
+                gf_log ("cli", GF_LOG_TRACE, "failed to get command string");
+
+        if (cmd_str)
+                cmd_op = strrchr(cmd_str, ' ') + 1;
+
         if ((type == GF_BITROT_CMD_SCRUB_STATUS) &&
              !(global_state->mode & GLUSTER_MODE_XML)) {
                 ret = gf_cli_print_bitrot_scrub_status (dict);
@@ -11987,6 +12007,43 @@ gf_cli_bitrot_cbk (struct rpc_req *req, struct iovec *iov,
                 goto out;
         }
 
+        switch (type) {
+        case  GF_BITROT_OPTION_TYPE_ENABLE:
+                cli_out("volume bitrot: success bitrot enabled "
+                        "for volume %s", volname);
+                ret = 0;
+                goto out;
+        case GF_BITROT_OPTION_TYPE_DISABLE:
+                cli_out("volume bitrot: success bitrot disabled "
+                        "for volume %s", volname);
+                ret = 0;
+                goto out;
+        case GF_BITROT_CMD_SCRUB_ONDEMAND:
+                cli_out("volume bitrot: scrubber started ondemand "
+                        "for volume %s", volname);
+                ret = 0;
+                goto out;
+        case GF_BITROT_OPTION_TYPE_SCRUB:
+                if (!strncmp ("pause", scrub_cmd, strlen("pause")))
+                        cli_out("volume bitrot: scrubber paused "
+                                "for volume %s", volname);
+                if (!strncmp ("resume", scrub_cmd, strlen("resume")))
+                        cli_out("volume bitrot: scrubber resumed "
+                                "for volume %s", volname);
+                ret = 0;
+                goto out;
+        case GF_BITROT_OPTION_TYPE_SCRUB_FREQ:
+                cli_out("volume bitrot: scrub-frequency is set to %s "
+                        "successfully for volume %s", cmd_op, volname);
+                ret = 0;
+                goto out;
+        case GF_BITROT_OPTION_TYPE_SCRUB_THROTTLE:
+                cli_out("volume bitrot: scrub-throttle is set to %s "
+                        "successfully for volume %s", cmd_op, volname);
+                ret = 0;
+                goto out;
+        }
+
 xml_output:
         if (global_state->mode & GLUSTER_MODE_XML) {
                 ret = cli_xml_output_vol_profile (dict, rsp.op_ret,
-- 
1.8.3.1