21ab4e
From 4e912d9d3306a806e77818e35454d14786c94c3e Mon Sep 17 00:00:00 2001
21ab4e
From: Samikshan Bairagya <samikshan@gmail.com>
21ab4e
Date: Mon, 31 Jul 2017 10:51:21 +0530
21ab4e
Subject: [PATCH 616/616] glusterd: Add geo-replication session details to
21ab4e
 get-state output
21ab4e
21ab4e
This commit adds support to the get-state CLI to capture details
21ab4e
on geo-replication session as obtained in
21ab4e
`gluster volume geo-replication status detail` in its output.
21ab4e
21ab4e
>Fixes: #291
21ab4e
>Change-Id: I2fbcba70bfdaf439522637234805545194777ed4
21ab4e
>Signed-off-by: Samikshan Bairagya <samikshan@gmail.com>
21ab4e
>Reviewed-on: https://review.gluster.org/17941
21ab4e
>Smoke: Gluster Build System <jenkins@build.gluster.org>
21ab4e
>Reviewed-by: Shubhendu Tripathi <shtripat@redhat.com>
21ab4e
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
21ab4e
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
21ab4e
Bug: 1475334
21ab4e
Change-Id: I2fbcba70bfdaf439522637234805545194777ed4
21ab4e
Signed-off-by: Samikshan Bairagya <samikshan@gmail.com>
21ab4e
Reviewed-on: https://code.engineering.redhat.com/gerrit/117184
21ab4e
Tested-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
Reviewed-by: Milind Changire <mchangir@redhat.com>
21ab4e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
---
21ab4e
 .gitignore                                   |   1 +
21ab4e
 cli/src/cli-rpc-ops.c                        |  33 -------
21ab4e
 libglusterfs/src/Makefile.am                 |   7 +-
21ab4e
 libglusterfs/src/common-utils.c              |  36 ++++++++
21ab4e
 libglusterfs/src/common-utils.h              |   3 +
21ab4e
 xlators/mgmt/glusterd/src/glusterd-geo-rep.c |   2 +-
21ab4e
 xlators/mgmt/glusterd/src/glusterd-geo-rep.h |   4 +
21ab4e
 xlators/mgmt/glusterd/src/glusterd-handler.c | 127 +++++++++++++++++++++++++++
21ab4e
 8 files changed, 177 insertions(+), 36 deletions(-)
21ab4e
21ab4e
diff --git a/.gitignore b/.gitignore
21ab4e
index 11ee200..0702279 100644
21ab4e
--- a/.gitignore
21ab4e
+++ b/.gitignore
21ab4e
@@ -87,6 +87,7 @@ libglusterfs/src/y.tab.h
21ab4e
 libglusterfs/src/defaults.c
21ab4e
 libglusterfs/src/glusterfs-fops.h
21ab4e
 libglusterfs/src/cli1-xdr.h
21ab4e
+libglusterfs/src/protocol-common.h
21ab4e
 libtool
21ab4e
 run-tests.sh
21ab4e
 tests/env.rc
21ab4e
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
21ab4e
index c46f9d4..7ded5f9 100644
21ab4e
--- a/cli/src/cli-rpc-ops.c
21ab4e
+++ b/cli/src/cli-rpc-ops.c
21ab4e
@@ -5608,39 +5608,6 @@ gf_cli_gsync_config_command (dict_t *dict)
21ab4e
         return runner_run (&runner);
21ab4e
 }
21ab4e
 
21ab4e
-char*
21ab4e
-get_struct_variable (int mem_num, gf_gsync_status_t *sts_val)
21ab4e
-{
21ab4e
-        switch (mem_num) {
21ab4e
-        case 0:  return (sts_val->node);
21ab4e
-        case 1:  return (sts_val->master);
21ab4e
-        case 2:  return (sts_val->brick);
21ab4e
-        case 3:  return (sts_val->slave_user);
21ab4e
-        case 4:  return (sts_val->slave);
21ab4e
-        case 5:  return (sts_val->slave_node);
21ab4e
-        case 6:  return (sts_val->worker_status);
21ab4e
-        case 7:  return (sts_val->crawl_status);
21ab4e
-        case 8:  return (sts_val->last_synced);
21ab4e
-        case 9:  return (sts_val->entry);
21ab4e
-        case 10:  return (sts_val->data);
21ab4e
-        case 11:  return (sts_val->meta);
21ab4e
-        case 12: return (sts_val->failures);
21ab4e
-        case 13:  return (sts_val->checkpoint_time);
21ab4e
-        case 14:  return (sts_val->checkpoint_completed);
21ab4e
-        case 15:  return (sts_val->checkpoint_completion_time);
21ab4e
-        case 16: return (sts_val->brick_host_uuid);
21ab4e
-        case 17: return (sts_val->last_synced_utc);
21ab4e
-        case 18: return (sts_val->checkpoint_time_utc);
21ab4e
-        case 19: return (sts_val->checkpoint_completion_time_utc);
21ab4e
-        case 20: return (sts_val->slavekey);
21ab4e
-        case 21: return (sts_val->session_slave);
21ab4e
-        default:
21ab4e
-                 goto out;
21ab4e
-        }
21ab4e
-
21ab4e
-out:
21ab4e
-        return NULL;
21ab4e
-}
21ab4e
 
21ab4e
 int
21ab4e
 gf_cli_print_status (char **title_values,
21ab4e
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am
21ab4e
index efd887d..aff30f4 100644
21ab4e
--- a/libglusterfs/src/Makefile.am
21ab4e
+++ b/libglusterfs/src/Makefile.am
21ab4e
@@ -36,9 +36,12 @@ libglusterfs_la_SOURCES = dict.c xlator.c logging.c \
21ab4e
 	compound-fop-utils.c
21ab4e
 
21ab4e
 nodist_libglusterfs_la_SOURCES = y.tab.c graph.lex.c defaults.c
21ab4e
-nodist_libglusterfs_la_HEADERS = y.tab.h glusterfs-fops.h cli1-xdr.h
21ab4e
+nodist_libglusterfs_la_HEADERS = y.tab.h glusterfs-fops.h cli1-xdr.h protocol-common.h
21ab4e
 
21ab4e
-BUILT_SOURCES = graph.lex.c defaults.c glusterfs-fops.h cli1-xdr.h eventtypes.h
21ab4e
+BUILT_SOURCES = graph.lex.c defaults.c glusterfs-fops.h cli1-xdr.h eventtypes.h protocol-common.h
21ab4e
+
21ab4e
+protocol-common.h: $(top_srcdir)/rpc/rpc-lib/src/protocol-common.h
21ab4e
+	cp $(top_srcdir)/rpc/rpc-lib/src/protocol-common.h .
21ab4e
 
21ab4e
 libglusterfs_la_HEADERS = common-utils.h defaults.h default-args.h \
21ab4e
 	dict.h glusterfs.h hashfn.h timespec.h logging.h xlator.h \
21ab4e
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
21ab4e
index 6c02039..88787de 100644
21ab4e
--- a/libglusterfs/src/common-utils.c
21ab4e
+++ b/libglusterfs/src/common-utils.c
21ab4e
@@ -50,6 +50,7 @@
21ab4e
 #include "cli1-xdr.h"
21ab4e
 #include <ifaddrs.h>
21ab4e
 #include "libglusterfs-messages.h"
21ab4e
+#include "protocol-common.h"
21ab4e
 
21ab4e
 #ifndef GF_LINUX_HOST_OS
21ab4e
 #include <sys/resource.h>
21ab4e
@@ -4938,3 +4939,38 @@ glusterfs_compute_sha256 (const unsigned char *content, size_t size,
21ab4e
 
21ab4e
         return 0;
21ab4e
 }
21ab4e
+
21ab4e
+char*
21ab4e
+get_struct_variable (int mem_num, gf_gsync_status_t *sts_val)
21ab4e
+{
21ab4e
+        switch (mem_num) {
21ab4e
+        case 0:  return (sts_val->node);
21ab4e
+        case 1:  return (sts_val->master);
21ab4e
+        case 2:  return (sts_val->brick);
21ab4e
+        case 3:  return (sts_val->slave_user);
21ab4e
+        case 4:  return (sts_val->slave);
21ab4e
+        case 5:  return (sts_val->slave_node);
21ab4e
+        case 6:  return (sts_val->worker_status);
21ab4e
+        case 7:  return (sts_val->crawl_status);
21ab4e
+        case 8:  return (sts_val->last_synced);
21ab4e
+        case 9:  return (sts_val->entry);
21ab4e
+        case 10:  return (sts_val->data);
21ab4e
+        case 11:  return (sts_val->meta);
21ab4e
+        case 12: return (sts_val->failures);
21ab4e
+        case 13:  return (sts_val->checkpoint_time);
21ab4e
+        case 14:  return (sts_val->checkpoint_completed);
21ab4e
+        case 15:  return (sts_val->checkpoint_completion_time);
21ab4e
+        case 16: return (sts_val->brick_host_uuid);
21ab4e
+        case 17: return (sts_val->last_synced_utc);
21ab4e
+        case 18: return (sts_val->checkpoint_time_utc);
21ab4e
+        case 19: return (sts_val->checkpoint_completion_time_utc);
21ab4e
+        case 20: return (sts_val->slavekey);
21ab4e
+        case 21: return (sts_val->session_slave);
21ab4e
+        default:
21ab4e
+                 goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+out:
21ab4e
+        return NULL;
21ab4e
+}
21ab4e
+
21ab4e
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
21ab4e
index 89d71a6..1cff48b 100644
21ab4e
--- a/libglusterfs/src/common-utils.h
21ab4e
+++ b/libglusterfs/src/common-utils.h
21ab4e
@@ -44,6 +44,7 @@ void trap (void);
21ab4e
 #include "iatt.h"
21ab4e
 #include "uuid.h"
21ab4e
 #include "libglusterfs-messages.h"
21ab4e
+#include "protocol-common.h"
21ab4e
 
21ab4e
 #define STRINGIFY(val) #val
21ab4e
 #define TOSTRING(val) STRINGIFY(val)
21ab4e
@@ -910,5 +911,7 @@ gf_getgrouplist (const char *user, gid_t group, gid_t **groups);
21ab4e
 int
21ab4e
 glusterfs_compute_sha256 (const unsigned char *content, size_t size,
21ab4e
                           char *sha256_hash);
21ab4e
+char*
21ab4e
+get_struct_variable (int mem_num, gf_gsync_status_t *sts_val);
21ab4e
 
21ab4e
 #endif /* _COMMON_UTILS_H */
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
21ab4e
index 872f3ff..fa3b151 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
21ab4e
@@ -4902,7 +4902,7 @@ out:
21ab4e
         return ret;
21ab4e
 }
21ab4e
 
21ab4e
-static int
21ab4e
+int
21ab4e
 glusterd_get_gsync_status_mst (glusterd_volinfo_t *volinfo, dict_t *rsp_dict,
21ab4e
                                char *node)
21ab4e
 {
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.h b/xlators/mgmt/glusterd/src/glusterd-geo-rep.h
21ab4e
index 045bc2e..8d08bcd 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.h
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.h
21ab4e
@@ -45,5 +45,9 @@ int
21ab4e
 _get_slave_status (dict_t *dict, char *key, data_t *value, void *data);
21ab4e
 int
21ab4e
 glusterd_check_geo_rep_running (gsync_status_param_t *param, char **op_errstr);
21ab4e
+
21ab4e
+int
21ab4e
+glusterd_get_gsync_status_mst (glusterd_volinfo_t *volinfo, dict_t *rsp_dict,
21ab4e
+                               char *node);
21ab4e
 #endif
21ab4e
 
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
21ab4e
index e194dca..ae8ddde 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
21ab4e
@@ -32,6 +32,7 @@
21ab4e
 #include "glusterd-store.h"
21ab4e
 #include "glusterd-locks.h"
21ab4e
 #include "glusterd-snapshot-utils.h"
21ab4e
+#include "glusterd-geo-rep.h"
21ab4e
 
21ab4e
 #include "glusterd1-xdr.h"
21ab4e
 #include "cli1-xdr.h"
21ab4e
@@ -5033,6 +5034,128 @@ out:
21ab4e
 }
21ab4e
 
21ab4e
 static int
21ab4e
+glusterd_print_gsync_status (FILE *fp, dict_t *gsync_dict)
21ab4e
+{
21ab4e
+        int                     ret = -1;
21ab4e
+        int                     gsync_count = 0;
21ab4e
+        int                     i = 0;
21ab4e
+        gf_gsync_status_t       **status_vals = NULL;
21ab4e
+        char                    status_val_name[PATH_MAX] = {0,};
21ab4e
+
21ab4e
+        GF_VALIDATE_OR_GOTO (THIS->name, fp, out);
21ab4e
+        GF_VALIDATE_OR_GOTO (THIS->name, gsync_dict, out);
21ab4e
+
21ab4e
+        ret = dict_get_int32 (gsync_dict, "gsync-count", &gsync_count);
21ab4e
+
21ab4e
+        fprintf (fp, "Volume%d.gsync_count: %d\n", volcount, gsync_count);
21ab4e
+
21ab4e
+        if (gsync_count == 0) {
21ab4e
+                ret = 0;
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        status_vals = GF_CALLOC (gsync_count, sizeof (gf_gsync_status_t *),
21ab4e
+                                 gf_common_mt_char);
21ab4e
+        if (!status_vals) {
21ab4e
+                ret = -1;
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+        for (i = 0; i < gsync_count; i++) {
21ab4e
+                status_vals[i] = GF_CALLOC (1, sizeof (gf_gsync_status_t),
21ab4e
+                                            gf_common_mt_char);
21ab4e
+                if (!status_vals[i]) {
21ab4e
+                        ret = -1;
21ab4e
+                        goto out;
21ab4e
+                }
21ab4e
+        }
21ab4e
+
21ab4e
+        for (i = 0; i < gsync_count; i++) {
21ab4e
+                snprintf (status_val_name, sizeof(status_val_name), "status_value%d", i);
21ab4e
+
21ab4e
+                ret = dict_get_bin (gsync_dict, status_val_name, (void **)&(status_vals[i]));
21ab4e
+                if (ret)
21ab4e
+                        goto out;
21ab4e
+
21ab4e
+                fprintf (fp, "Volume%d.pair%d.session_slave: %s\n", volcount, i+1,
21ab4e
+                         get_struct_variable(21, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.master_node: %s\n", volcount, i+1,
21ab4e
+                         get_struct_variable(0, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.master_volume: %s\n", volcount, i+1,
21ab4e
+                         get_struct_variable(1, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.master_brick: %s\n", volcount, i+1,
21ab4e
+                         get_struct_variable(2, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.slave_user: %s\n", volcount, i+1,
21ab4e
+                         get_struct_variable(3, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.slave: %s\n", volcount, i+1,
21ab4e
+                         get_struct_variable(4, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.slave_node: %s\n", volcount, i+1,
21ab4e
+                         get_struct_variable(5, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.status: %s\n", volcount, i+1,
21ab4e
+                         get_struct_variable(6, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.crawl_status: %s\n", volcount, i+1,
21ab4e
+                         get_struct_variable(7, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.last_synced: %s\n", volcount, i+1,
21ab4e
+                         get_struct_variable(8, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.entry: %s\n", volcount, i+1,
21ab4e
+                         get_struct_variable(9, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.data: %s\n", volcount, i+1,
21ab4e
+                         get_struct_variable(10, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.meta: %s\n", volcount, i+1,
21ab4e
+                         get_struct_variable(11, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.failures: %s\n", volcount, i+1,
21ab4e
+                         get_struct_variable(12, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.checkpoint_time: %s\n", volcount,
21ab4e
+                         i+1, get_struct_variable(13, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.checkpoint_completed: %s\n",
21ab4e
+                         volcount, i+1, get_struct_variable(14, status_vals[i]));
21ab4e
+                fprintf (fp, "Volume%d.pair%d.checkpoint_completion_time: %s\n",
21ab4e
+                         volcount, i+1, get_struct_variable(15, status_vals[i]));
21ab4e
+        }
21ab4e
+out:
21ab4e
+        for (i = 0; i < gsync_count; i++) {
21ab4e
+                if (status_vals[i]) {
21ab4e
+                        GF_FREE (status_vals[i]);
21ab4e
+                }
21ab4e
+        }
21ab4e
+
21ab4e
+        if (status_vals)
21ab4e
+                GF_FREE (status_vals);
21ab4e
+
21ab4e
+        return ret;
21ab4e
+}
21ab4e
+
21ab4e
+static int
21ab4e
+glusterd_print_gsync_status_by_vol (FILE *fp, glusterd_volinfo_t *volinfo)
21ab4e
+{
21ab4e
+        int                     ret = -1;
21ab4e
+        dict_t                  *gsync_rsp_dict = NULL;
21ab4e
+        char                    my_hostname[256] = {0,};
21ab4e
+
21ab4e
+        GF_VALIDATE_OR_GOTO (THIS->name, volinfo, out);
21ab4e
+        GF_VALIDATE_OR_GOTO (THIS->name, fp, out);
21ab4e
+
21ab4e
+        gsync_rsp_dict = dict_new();
21ab4e
+        if (!gsync_rsp_dict)
21ab4e
+                goto out;
21ab4e
+
21ab4e
+        ret = gethostname(my_hostname, 256);
21ab4e
+        if (ret) {
21ab4e
+                /* stick to N/A */
21ab4e
+                (void) strcpy (my_hostname, "N/A");
21ab4e
+        }
21ab4e
+
21ab4e
+        ret = glusterd_get_gsync_status_mst (volinfo, gsync_rsp_dict,
21ab4e
+                                             my_hostname);
21ab4e
+        /* Ignoring ret as above function always returns ret = 0 */
21ab4e
+
21ab4e
+        ret = glusterd_print_gsync_status (fp, gsync_rsp_dict);
21ab4e
+        if (ret)
21ab4e
+                goto out;
21ab4e
+out:
21ab4e
+        return ret;
21ab4e
+}
21ab4e
+
21ab4e
+static int
21ab4e
 glusterd_print_snapinfo_by_vol (FILE *fp, glusterd_volinfo_t *volinfo, int volcount)
21ab4e
 {
21ab4e
         int                     ret = -1;
21ab4e
@@ -5685,6 +5808,10 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
21ab4e
                 }
21ab4e
 
21ab4e
                 volcount = count;
21ab4e
+                ret = glusterd_print_gsync_status_by_vol (fp, volinfo);
21ab4e
+                if (ret)
21ab4e
+                        goto out;
21ab4e
+
21ab4e
                 if (volinfo->dict)
21ab4e
                         dict_foreach (volinfo->dict,
21ab4e
                                       glusterd_print_volume_options, fp);
21ab4e
-- 
21ab4e
1.8.3.1
21ab4e