From 573f4524c3e198830b5f5895b7584a166616b643 Mon Sep 17 00:00:00 2001 From: Saravanakumar Arumugam Date: Mon, 6 Jun 2016 14:44:35 +0530 Subject: [PATCH 192/192] glusterd/geo-rep: Avoid started status check if same host After carrying out add-brick, session creation is carried out again, to involve new brick in the session. This needs to be done, even if the session is in Started state. While involving slave uuid as part of a session, User is warned if session is in Started state. This check needs to be avoided if it is same slave host and session creation needs to be proceeded. Change-Id: Ic73edd5bd9e3ee55da96f5aceec0bafa14d3f3dd BUG: 1342938 Reviewed-on: http://review.gluster.org/#/c/14653 Signed-off-by: Saravanakumar Arumugam Reviewed-on: https://code.engineering.redhat.com/gerrit/76070 Reviewed-by: Aravinda Vishwanathapura Krishna Murthy --- xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 95 ++++++++++++++++++-------- 1 files changed, 67 insertions(+), 28 deletions(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c index 934d242..c5e9720 100644 --- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c +++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c @@ -588,6 +588,7 @@ struct dictidxmark { struct slave_vol_config { char old_slvhost[_POSIX_HOST_NAME_MAX+1]; + char old_slvuser[_POSIX_LOGIN_NAME_MAX]; unsigned old_slvidx; char slave_voluuid[GF_UUID_BUF_SIZE]; }; @@ -2884,8 +2885,14 @@ get_slavehost_from_voluuid (dict_t *dict, char *key, data_t *value, void *data) /* To go past username in non-root geo-rep session */ tmp = strchr (slave_host, '@'); - if (tmp) + if (tmp) { + strncpy (slave_vol->old_slvuser, slave_host, + (tmp - slave_host)); + slave_vol->old_slvuser[(tmp - slave_host) + 1] + = '\0'; slave_host = tmp + 1; + } else + strcpy (slave_vol->old_slvuser, "root"); tmp = strchr (slave_host, ':'); if (!tmp) { @@ -2898,7 +2905,7 @@ get_slavehost_from_voluuid (dict_t *dict, char *key, data_t *value, void *data) strncpy (slave_vol->old_slvhost, slave_host, (tmp - slave_host)); - slave_vol->old_slvhost[(tmp - slave_host)+1] = '\0'; + slave_vol->old_slvhost[(tmp - slave_host) + 1] = '\0'; goto out; } @@ -2970,6 +2977,11 @@ glusterd_op_stage_gsync_create (dict_t *dict, char **op_errstr) int ret_status = 0; char *statedir = NULL; char statefiledir[PATH_MAX] = {0,}; + gf_boolean_t is_different_slavehost = _gf_false; + gf_boolean_t is_different_username = _gf_false; + char *slave_user = NULL; + char *save_ptr = NULL; + char *slave_url_buf = NULL; this = THIS; GF_ASSERT (this); @@ -3231,32 +3243,57 @@ glusterd_op_stage_gsync_create (dict_t *dict, char **op_errstr) slave_vol, slave_host); goto out; } - /* Now, check whether session is already started, if so, warn!*/ - ret = snprintf (old_confpath, sizeof(old_confpath) - 1, - "%s/"GEOREP"/%s_%s_%s/gsyncd.conf", - conf->workdir, volinfo->volname, - slave1.old_slvhost, slave_vol); - /* construct old slave url with (old) slave host */ - old_slave_url = old_slave_url_info; - strncpy (old_slave_url, slave1.old_slvhost, - sizeof(old_slave_url_info)); - old_slave_url = strcat (old_slave_url, "::"); - old_slave_url = strncat (old_slave_url, slave_vol, - sizeof(old_slave_url_info)); + /* Now, check whether session is already started.If so, warn!*/ + is_different_slavehost = + (strcmp (slave_host, slave1.old_slvhost) != 0) + ? _gf_true : _gf_false; - ret = glusterd_check_gsync_running_local (volinfo->volname, - old_slave_url, - old_confpath, - &is_running); - if (_gf_true == is_running) { - snprintf (errmsg, sizeof(errmsg), "Geo" - " -replication session between %s and %s" - " is still active. Please stop the " - "session and retry.", - volinfo->volname, old_slave_url); - ret = -1; - goto out; + if (strstr (slave_url, "@")) { + slave_url_buf = gf_strdup (slave_url); + if (!slave_url_buf) { + gf_msg (this->name, GF_LOG_ERROR, ENOMEM, + GD_MSG_NO_MEMORY, + "Unable to allocate memory"); + ret = -1; + goto out; + } + slave_user = strtok_r (slave_url_buf, "@", &save_ptr); + } else + slave_user = "root"; + is_different_username = + (strcmp (slave_user, slave1.old_slvuser) != 0) + ? _gf_true : _gf_false; + + /* Do the check, only if different slave host/slave user */ + if (is_different_slavehost || is_different_username) { + ret = snprintf (old_confpath, sizeof(old_confpath) - 1, + "%s/"GEOREP"/%s_%s_%s/gsyncd.conf", + conf->workdir, volinfo->volname, + slave1.old_slvhost, slave_vol); + + /* construct old slave url with (old) slave host */ + old_slave_url = old_slave_url_info; + strncpy (old_slave_url, slave1.old_slvhost, + sizeof(old_slave_url_info)); + old_slave_url = strcat (old_slave_url, "::"); + old_slave_url = strncat (old_slave_url, slave_vol, + sizeof(old_slave_url_info)); + + ret = glusterd_check_gsync_running_local ( + volinfo->volname, + old_slave_url, + old_confpath, + &is_running); + if (_gf_true == is_running) { + snprintf (errmsg, sizeof(errmsg), "Geo" + "-replication session between %s and %s" + " is still active. Please stop the " + "session and retry.", + volinfo->volname, old_slave_url); + ret = -1; + goto out; + } } ret = dict_set_dynstr_with_alloc (dict, "old_slavehost", @@ -3297,6 +3334,8 @@ out: if (ret && errmsg[0] != '\0') *op_errstr = gf_strdup (errmsg); + if (slave_url_buf) + GF_FREE (slave_url_buf); gf_msg_debug (this->name, 0, "Returning %d", ret); return ret; -- 1.7.1