diff options
author | Venky Shankar <vshankar@redhat.com> | 2013-08-07 17:09:17 +0530 |
---|---|---|
committer | Anand Avati <avati@redhat.com> | 2013-09-04 19:29:17 -0700 |
commit | 3bfa0dde137f35d68e7f935ddd562136b4829e21 (patch) | |
tree | 6214447af984b00de54db07d9b667ce8f46e803c | |
parent | 59d37265acf250b1b29c186020c55e9df0ef4215 (diff) |
glusterd/gverify.sh: Stops session being created with invalid slave details
create force will fail with proper message, if the ip is not
reachable, or is unable to fetch slave details.
Change-Id: I44a3ba777b37702ffd0e48e9cb46c51e293327d4
BUG: 988314
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
Signed-off-by: Venky Shankar <vshankar@redhat.com>
Reviewed-on: http://review.gluster.org/5516
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
-rwxr-xr-x | extras/hook-scripts/S56glusterd-geo-rep-create-post.sh | 5 | ||||
-rwxr-xr-x | geo-replication/src/gverify.sh | 25 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 76 |
3 files changed, 87 insertions, 19 deletions
diff --git a/extras/hook-scripts/S56glusterd-geo-rep-create-post.sh b/extras/hook-scripts/S56glusterd-geo-rep-create-post.sh index 71e44b6ed13..1369c22fc1a 100755 --- a/extras/hook-scripts/S56glusterd-geo-rep-create-post.sh +++ b/extras/hook-scripts/S56glusterd-geo-rep-create-post.sh @@ -22,6 +22,7 @@ if [ "$val" == "" ]; then exit; fi pub_file=`echo $val` +pub_file_tmp=`echo $val`_tmp key=`echo $key_val_pair3 | cut -d '=' -f 1` val=`echo $key_val_pair3 | cut -d '=' -f 2` @@ -34,8 +35,8 @@ fi slave_ip=`echo $val` if [ -f $pub_file ]; then - ssh $slave_ip "\rm -rf $pub_file" - scp $pub_file $slave_ip:$pub_file &> /dev/null + scp $pub_file $slave_ip:$pub_file_tmp + ssh $slave_ip "mv $pub_file_tmp $pub_file" ssh $slave_ip "gluster system:: copy file /geo-replication/common_secret.pem.pub > /dev/null" ssh $slave_ip "gluster system:: execute add_secret_pub > /dev/null" fi diff --git a/geo-replication/src/gverify.sh b/geo-replication/src/gverify.sh index f10e21ed6e0..49ed2e925ae 100755 --- a/geo-replication/src/gverify.sh +++ b/geo-replication/src/gverify.sh @@ -96,6 +96,15 @@ function slave_stats() function main() { + log_file=$4 + > $log_file + + ping -w 5 $2; + if [ $? -ne 0 ]; then + echo "$2 not reachable." > $log_file + exit 1; + fi; + ERRORS=0; master_data=$(master_stats $1); slave_data=$(slave_stats $2 $3); @@ -104,24 +113,22 @@ function main() master_version=$(echo $master_data | cut -f2 -d':'); slave_version=$(echo $slave_data | cut -f2 -d':'); slave_no_of_files=$(echo $slave_data | cut -f3 -d':'); - log_file=$4 - > $log_file + slave_vol_test=$5 if [[ "x$master_size" = "x" || "x$master_version" = "x" || "$master_size" -eq "0" ]]; then - echo "Unable to fetch master volume details." > $log_file; + echo "Unable to fetch master volume details. Please check the master cluster and master volume." > $log_file; exit 1; fi; if [[ "x$slave_size" = "x" || "x$slave_version" = "x" || "$slave_size" -eq "0" ]]; then - ping -w 5 $2; - if [ $? -ne 0 ]; then - echo "$2 not reachable." > $log_file - exit 1; - fi; - echo "Unable to fetch slave volume details." > $log_file; + echo "Unable to fetch slave volume details. Please check the slave cluster and slave volume." > $log_file; exit 1; fi; + if [ ! -z $slave_vol_test ]; then + exit $ERRORS; + fi + if [ ! $slave_size -ge $(($master_size - $BUFFER_SIZE )) ]; then echo "Total size of master is greater than available size of slave." >> $log_file; ERRORS=$(($ERRORS + 1)); diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c index 7ccf641c8b2..46d4d28e601 100644 --- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c +++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c @@ -1608,7 +1608,7 @@ out: static int glusterd_verify_slave (char *volname, char *slave_ip, char *slave, - char **op_errstr) + char **op_errstr, int slave_vol_test) { int32_t ret = -1; runner_t runner = {0,}; @@ -1636,6 +1636,8 @@ glusterd_verify_slave (char *volname, char *slave_ip, char *slave, runner_argprintf (&runner, "%s", slave_ip); runner_argprintf (&runner, "%s", slave); runner_argprintf (&runner, "%s", log_file_path); + if (slave_vol_test) + runner_add_args (&runner, "slave_vol_test", NULL); runner_redir (&runner, STDOUT_FILENO, RUN_PIPE); synclock_unlock (&priv->big_lock); ret = runner_run (&runner); @@ -1661,6 +1663,52 @@ out: } int +glusterd_validate_slave_ip_vol (dict_t *dict, char *volname, + char *host_uuid, char **op_errstr) +{ + int ret = -1; + char uuid_str [64] = ""; + char *slave = NULL; + char *slave_ip = NULL; + char *slave_vol = NULL; + + uuid_utoa_r (MY_UUID, uuid_str); + if (strcmp (uuid_str, host_uuid)) { + ret = 0; + goto out; + } + + ret = dict_get_str (dict, "slave", &slave); + if (ret || !slave) { + gf_log ("", GF_LOG_ERROR, "Unable to fetch slave from dict"); + ret = -1; + goto out; + } + + ret = glusterd_get_slave_info (slave, &slave_ip, &slave_vol); + if (ret) { + gf_log ("", GF_LOG_ERROR, + "Unable to fetch slave details."); + ret = -1; + goto out; + } + + /* Checking if slave ip is pingable and slave volume is + * valid. Fail even with failure in case of force */ + ret = glusterd_verify_slave (volname, slave_ip, slave_vol, + op_errstr, 1); + if (ret) { + gf_log ("", GF_LOG_ERROR, "%s", *op_errstr); + ret = -1; + goto out; + } + +out: + gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); + return ret; +} + +int glusterd_op_stage_gsync_create (dict_t *dict, char **op_errstr) { char *down_peerstr = NULL; @@ -1748,8 +1796,10 @@ glusterd_op_stage_gsync_create (dict_t *dict, char **op_errstr) volinfo->volname, slave); } + /* Checking if slave vol is empty, and if it has enough memory + * available, and bypass in case of force */ ret = glusterd_verify_slave (volname, slave_ip, slave_vol, - op_errstr); + op_errstr, 0); if ((ret) && !is_force) { gf_log ("", GF_LOG_ERROR, "%s is not a valid slave volume. Error: %s", @@ -1798,6 +1848,13 @@ glusterd_op_stage_gsync_create (dict_t *dict, char **op_errstr) ret = glusterd_get_statefile_name (volinfo, slave, conf_path, &statefile); if (ret) { + ret = glusterd_validate_slave_ip_vol (dict, volname, + host_uuid, op_errstr); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Slave validation failed."); + goto out; + } + if (!strstr(slave, "::")) snprintf (errmsg, sizeof (errmsg), "%s is not a valid slave url.", slave); @@ -1805,6 +1862,7 @@ glusterd_op_stage_gsync_create (dict_t *dict, char **op_errstr) snprintf (errmsg, sizeof (errmsg), "Please check gsync " "config file. Unable to get statefile's name"); gf_log ("", GF_LOG_ERROR, "%s", errmsg); + ret = -1; goto out; } @@ -1889,7 +1947,7 @@ glusterd_op_stage_gsync_set (dict_t *dict, char **op_errstr) } ret = glusterd_op_gsync_args_get (dict, op_errstr, - &volname, &slave, NULL); + &volname, &slave, &host_uuid); if (ret) goto out; @@ -1916,6 +1974,13 @@ glusterd_op_stage_gsync_set (dict_t *dict, char **op_errstr) ret = glusterd_get_statefile_name (volinfo, slave, conf_path, &statefile); if (ret) { + ret = glusterd_validate_slave_ip_vol (dict, volname, + host_uuid, op_errstr); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Slave validation failed."); + goto out; + } + if (!strstr(slave, "::")) snprintf (errmsg, sizeof (errmsg), "%s is not a valid slave url.", slave); @@ -1958,11 +2023,6 @@ glusterd_op_stage_gsync_set (dict_t *dict, char **op_errstr) /* Check if all peers that are a part of the volume are up or not */ if ((type == GF_GSYNC_OPTION_TYPE_DELETE) || ((type == GF_GSYNC_OPTION_TYPE_STOP) && !is_force)) { - ret = dict_get_str (dict, "host-uuid", &host_uuid); - if (ret < 0) - goto out; - - uuid_utoa_r (MY_UUID, uuid_str); if (!strcmp (uuid_str, host_uuid)) { ret = glusterd_are_vol_all_peers_up (volinfo, &conf->peers, |