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