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