diff options
author | Samikshan Bairagya <samikshan@gmail.com> | 2017-07-31 10:51:21 +0530 |
---|---|---|
committer | Shyamsundar Ranganathan <srangana@redhat.com> | 2017-08-04 13:32:52 +0000 |
commit | 9bc0cf820ace2df58fc666f4ff4c7c50973b60a3 (patch) | |
tree | 69454561a59bad7eeb03b57f12c903099d1e37a3 | |
parent | 985d86bbc08bb44d105bcacd32750f1b1c505d43 (diff) | |
download | glusterfs-9bc0cf820ace2df58fc666f4ff4c7c50973b60a3.tar.gz glusterfs-9bc0cf820ace2df58fc666f4ff4c7c50973b60a3.tar.xz glusterfs-9bc0cf820ace2df58fc666f4ff4c7c50973b60a3.zip |
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.
> Reviewed-on: https://review.gluster.org/17941
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Shubhendu Tripathi <shtripat@redhat.com>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
(cherry picked from commit 2e7daeffef05c6100cbcc39f1be62935711db3eb)
Fixes: #291
Change-Id: I2fbcba70bfdaf439522637234805545194777ed4
Signed-off-by: Samikshan Bairagya <samikshan@gmail.com>
Reviewed-on: https://review.gluster.org/17971
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Smoke: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | cli/src/cli-rpc-ops.c | 33 | ||||
-rw-r--r-- | libglusterfs/src/Makefile.am | 7 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.c | 36 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.h | 3 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 2 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-geo-rep.h | 4 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handler.c | 127 |
8 files changed, 177 insertions, 36 deletions
diff --git a/.gitignore b/.gitignore index ccda5aa878..c991724811 100644 --- a/.gitignore +++ b/.gitignore @@ -91,6 +91,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 # copied XDR for cyclic libglusterfs <-> rpc-header dependency rpc/xdr/gen/*.x diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index ff44a22be7..cbc9740686 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -5537,39 +5537,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 768fe042a1..6c81142b82 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -38,9 +38,12 @@ libglusterfs_la_SOURCES = dict.c xlator.c logging.c \ compound-fop-utils.c throttle-tbf.c nodist_libglusterfs_la_SOURCES = y.tab.c graph.lex.c defaults.c -nodist_libglusterfs_la_HEADERS = y.tab.h +nodist_libglusterfs_la_HEADERS = y.tab.h protocol-common.h -BUILT_SOURCES = graph.lex.c defaults.c eventtypes.h +BUILT_SOURCES = graph.lex.c defaults.c 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 ec1d5c4823..772f4e05ad 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -53,6 +53,7 @@ #include "xxhash.h" #include <ifaddrs.h> #include "libglusterfs-messages.h" +#include "protocol-common.h" #ifndef AI_ADDRCONFIG #define AI_ADDRCONFIG 0 @@ -4930,3 +4931,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 022a2a70ff..e1c5f6680f 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) @@ -939,5 +940,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 19f7a3b4d7..b3ce6d102f 100644 --- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c +++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c @@ -4882,7 +4882,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 045bc2e4ba..8d08bcda50 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 523e9d51be..a57a4e1c8d 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" @@ -4985,6 +4986,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; @@ -5635,6 +5758,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); |