e7a346
From fd9e0103cd5c3f2962e063dbc3083c451b7e592b Mon Sep 17 00:00:00 2001
e7a346
From: Raghavendra Bhat <raghavendra@redhat.com>
e7a346
Date: Thu, 4 Oct 2018 14:27:45 -0400
e7a346
Subject: [PATCH 433/444] mgmt/glusterd: use proper path to the volfile
e7a346
e7a346
    > Upstream: https://review.gluster.org/#/c/glusterfs/+/21314/
e7a346
    > BUG: 1635050
e7a346
    > Change-Id: I28b2dfa5d9b379fe943db92c2fdfea879a6a594e
e7a346
e7a346
NOTE: This patch is actually directly applied from the patch that
e7a346
      was sent to the release-4.1 branch. The master branch patch
e7a346
      will have merge conflicts due to the clang format changes done
e7a346
      there. This is the patch which this commit is a backport of.
e7a346
e7a346
      upstream(4.1): https://review.gluster.org/#/c/glusterfs/+/21348/
e7a346
      Chane-ID: I28b2dfa5d9b379fe943db92c2fdfea879a6a594e
e7a346
e7a346
Till now, glusterd was generating the volfile path for the snapshot
e7a346
volume's bricks like this.
e7a346
e7a346
/snaps/<snap name>/<brick volfile>
e7a346
e7a346
But in reality, the path to the brick volfile for a snapshot volume is
e7a346
e7a346
/snaps/<snap name>/<snap volume name>/<brick volfile>
e7a346
e7a346
The above workaround was used to distinguish between a mount command used
e7a346
to mount the snapshot volume, and a brick of the snapshot volume, so that
e7a346
based on what is actually happening, glusterd can return the proper volfile
e7a346
(client volfile for the former and the brick volfile for the latter). But,
e7a346
this was causing problems for snapshot restore when brick multiplexing is
e7a346
enabled. Because, with brick multiplexing, it tries to find the volfile
e7a346
and sends GETSPEC rpc call to glusterd using the 2nd style of path i.e.
e7a346
e7a346
/snaps/<snap name>/<snap volume name>/<brick volfile>
e7a346
e7a346
So, when the snapshot brick (which is multiplexed) sends a GETSPEC rpc
e7a346
request to glusterd for obtaining the brick volume file, glusterd was
e7a346
returning the client volume file of the snapshot volume instead of the
e7a346
brick volume file.
e7a346
e7a346
Change-Id: I28b2dfa5d9b379fe943db92c2fdfea879a6a594e
e7a346
BUG: 1636291
e7a346
Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/155129
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
e7a346
---
e7a346
 .../snapview-server/src/snapview-server-helpers.c    |  5 +++--
e7a346
 xlators/mgmt/glusterd/src/glusterd-handshake.c       | 20 ++++++++++++++++++--
e7a346
 xlators/mgmt/glusterd/src/glusterd-utils.c           |  9 +++++----
e7a346
 3 files changed, 26 insertions(+), 8 deletions(-)
e7a346
e7a346
diff --git a/xlators/features/snapview-server/src/snapview-server-helpers.c b/xlators/features/snapview-server/src/snapview-server-helpers.c
e7a346
index 2ad74ef..4c2edc6 100644
e7a346
--- a/xlators/features/snapview-server/src/snapview-server-helpers.c
e7a346
+++ b/xlators/features/snapview-server/src/snapview-server-helpers.c
e7a346
@@ -481,8 +481,9 @@ __svs_initialise_snapshot_volume (xlator_t *this, const char *name,
e7a346
                 goto out;
e7a346
         }
e7a346
 
e7a346
-        snprintf (volname, sizeof (volname), "/snaps/%s/%s",
e7a346
-                  dirent->name, dirent->snap_volname);
e7a346
+        snprintf (volname, sizeof (volname), "/snaps/%s/%s/%s",
e7a346
+                  dirent->name, dirent->snap_volname,
e7a346
+                  dirent->snap_volname);
e7a346
 
e7a346
 
e7a346
         fs = glfs_new (volname);
e7a346
diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c
e7a346
index d5594d0..b2a9b20 100644
e7a346
--- a/xlators/mgmt/glusterd/src/glusterd-handshake.c
e7a346
+++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c
e7a346
@@ -52,6 +52,7 @@ get_snap_volname_and_volinfo (const char *volpath, char **volname,
e7a346
         char            *vol            = NULL;
e7a346
         glusterd_snap_t *snap           = NULL;
e7a346
         xlator_t        *this           = NULL;
e7a346
+        char            *volfile_token  = NULL;
e7a346
 
e7a346
         this = THIS;
e7a346
         GF_ASSERT (this);
e7a346
@@ -101,12 +102,27 @@ get_snap_volname_and_volinfo (const char *volpath, char **volname,
e7a346
          */
e7a346
         ret = glusterd_volinfo_find (volname_token, volinfo);
e7a346
         if (ret) {
e7a346
-                *volname = gf_strdup (volname_token);
e7a346
+                gf_msg (this->name, GF_LOG_WARNING, 0, GD_MSG_VOLINFO_GET_FAIL,
e7a346
+                        "failed to get the volinfo for the volume %s",
e7a346
+                        volname_token);
e7a346
+
e7a346
+                /* Get the actual volfile name */
e7a346
+                volfile_token = strtok_r (NULL, "/", &save_ptr);
e7a346
+                *volname = gf_strdup (volfile_token);
e7a346
                 if (NULL == *volname) {
e7a346
                         ret = -1;
e7a346
                         goto out;
e7a346
                 }
e7a346
 
e7a346
+                        /*
e7a346
+                         * Ideally, this should succeed as volname_token now
e7a346
+                         * contains the name of the snap volume (i.e. name of
e7a346
+                         * the volume that represents the snapshot).
e7a346
+                         * But, if for some reason, volinfo for the snap volume
e7a346
+                         * is not found, then try to get from the name of the
e7a346
+                         * volfile. Name of the volfile is like this.
e7a346
+                         * <snap volume name>.<hostname>.<brick path>.vol
e7a346
+                         */
e7a346
                 ret = glusterd_snap_volinfo_find (volname_token, snap,
e7a346
                                                   volinfo);
e7a346
                 if (ret) {
e7a346
@@ -115,7 +131,7 @@ get_snap_volname_and_volinfo (const char *volpath, char **volname,
e7a346
                         if (!vol) {
e7a346
                                 gf_msg (this->name, GF_LOG_ERROR, EINVAL,
e7a346
                                         GD_MSG_INVALID_ENTRY, "Invalid "
e7a346
-                                                "volname (%s)", volname_token);
e7a346
+                                                "volname (%s)", volfile_token);
e7a346
                                 goto out;
e7a346
                         }
e7a346
 
e7a346
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
e7a346
index 04fae63..7179a68 100644
e7a346
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
e7a346
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
e7a346
@@ -2068,10 +2068,10 @@ retry:
e7a346
         }
e7a346
 
e7a346
         if (volinfo->is_snap_volume) {
e7a346
-                snprintf (volfile, PATH_MAX,"/%s/%s/%s.%s.%s",
e7a346
+                snprintf (volfile, PATH_MAX, "/%s/%s/%s/%s.%s.%s",
e7a346
                           GLUSTERD_VOL_SNAP_DIR_PREFIX,
e7a346
                           volinfo->snapshot->snapname, volinfo->volname,
e7a346
-                          brickinfo->hostname, exp_path);
e7a346
+                          volinfo->volname, brickinfo->hostname, exp_path);
e7a346
         } else {
e7a346
                 snprintf (volfile, PATH_MAX, "%s.%s.%s", volinfo->volname,
e7a346
                           brickinfo->hostname, exp_path);
e7a346
@@ -5676,10 +5676,11 @@ attach_brick (xlator_t *this,
e7a346
         GLUSTERD_GET_BRICK_PIDFILE (pidfile2, volinfo, brickinfo, conf);
e7a346
 
e7a346
         if (volinfo->is_snap_volume) {
e7a346
-                snprintf (full_id, sizeof(full_id), "/%s/%s/%s.%s.%s",
e7a346
+                snprintf (full_id, sizeof(full_id), "/%s/%s/%s/%s.%s.%s",
e7a346
                           GLUSTERD_VOL_SNAP_DIR_PREFIX,
e7a346
                           volinfo->snapshot->snapname,
e7a346
-                          volinfo->volname, brickinfo->hostname, unslashed);
e7a346
+                          volinfo->volname, volinfo->volname,
e7a346
+                          brickinfo->hostname, unslashed);
e7a346
         } else {
e7a346
                 snprintf (full_id, sizeof(full_id), "%s.%s.%s",
e7a346
                           volinfo->volname, brickinfo->hostname, unslashed);
e7a346
-- 
e7a346
1.8.3.1
e7a346