cb8e9e
From 9ca7f82bed06ec521295de2d78abd688143d15a9 Mon Sep 17 00:00:00 2001
cb8e9e
From: Avra Sengupta <asengupt@redhat.com>
cb8e9e
Date: Wed, 3 Jun 2015 15:18:08 +0530
cb8e9e
Subject: [PATCH 23/57] snapshot: Fix finding brick mount path logic
cb8e9e
cb8e9e
    Backport of http://review.gluster.org/#/c/11060/
cb8e9e
cb8e9e
Previously while finding brick mount paths
cb8e9e
of snap volume's bricks, we were taking brick order
cb8e9e
into consideration. This logic fails when a brick is
cb8e9e
removed or a tier is added.
cb8e9e
cb8e9e
Hence modifying the logic to look for the first
cb8e9e
occurence of the word "brick" in the brick path.
cb8e9e
From there we iterate till we find a '/'. The string
cb8e9e
till the first '/' after we encounter the word brick
cb8e9e
is the brick mount path.
cb8e9e
cb8e9e
Change-Id: Ic85983c4e975e701cdfd4e13f8e276ac391a3e49
cb8e9e
BUG: 1224175
cb8e9e
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
cb8e9e
(cherry picked from commit bf3a6dcdf3c8a8a64e7c864b56c4d9be60fca8e6)
cb8e9e
Reviewed-on: https://code.engineering.redhat.com/gerrit/50360
cb8e9e
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
cb8e9e
Tested-by: Rajesh Joseph <rjoseph@redhat.com>
cb8e9e
---
cb8e9e
 tests/bugs/snapshot/bug-1227646.t             |   32 +++++++++++++++++++++++++
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-snapshot.c |    1 -
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-store.c    |   22 +++++++---------
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-utils.h    |    4 +-
cb8e9e
 4 files changed, 44 insertions(+), 15 deletions(-)
cb8e9e
 create mode 100644 tests/bugs/snapshot/bug-1227646.t
cb8e9e
cb8e9e
diff --git a/tests/bugs/snapshot/bug-1227646.t b/tests/bugs/snapshot/bug-1227646.t
cb8e9e
new file mode 100644
cb8e9e
index 0000000..643d814
cb8e9e
--- /dev/null
cb8e9e
+++ b/tests/bugs/snapshot/bug-1227646.t
cb8e9e
@@ -0,0 +1,32 @@
cb8e9e
+#!/bin/bash
cb8e9e
+
cb8e9e
+. $(dirname $0)/../../volume.rc
cb8e9e
+. $(dirname $0)/../../snapshot.rc
cb8e9e
+. $(dirname $0)/../../include.rc
cb8e9e
+
cb8e9e
+cleanup;
cb8e9e
+
cb8e9e
+TEST init_n_bricks 3;
cb8e9e
+TEST setup_lvm 3;
cb8e9e
+
cb8e9e
+TEST glusterd;
cb8e9e
+TEST pidof glusterd;
cb8e9e
+
cb8e9e
+#TEST $CLI volume create $V0 $H0:$L1 $H0:$L2 $H0:$L3;
cb8e9e
+TEST $CLI volume create $V0 $H0:$L2 $H0:$L3;
cb8e9e
+TEST $CLI volume start $V0;
cb8e9e
+
cb8e9e
+TEST $CLI snapshot create snap1 $V0 no-timestamp;
cb8e9e
+TEST $CLI volume stop $V0
cb8e9e
+TEST $CLI snapshot restore snap1;
cb8e9e
+TEST $CLI volume start $V0
cb8e9e
+TEST $CLI volume attach-tier $V0 $H0:$L1 $H0:$L2
cb8e9e
+
cb8e9e
+TEST pkill gluster
cb8e9e
+TEST glusterd
cb8e9e
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT 'Started' volinfo_field $V0 'Status'
cb8e9e
+
cb8e9e
+TEST $CLI volume stop $V0
cb8e9e
+
cb8e9e
+cleanup  ;
cb8e9e
+
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
cb8e9e
index 668c26e..0ea3935 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
cb8e9e
@@ -2721,7 +2721,6 @@ glusterd_lvm_snapshot_remove (dict_t *rsp_dict, glusterd_volinfo_t *snap_vol)
cb8e9e
 
cb8e9e
                 /* Fetch the brick mount path from the brickinfo->path */
cb8e9e
                 ret = glusterd_find_brick_mount_path (brickinfo->path,
cb8e9e
-                                                      brick_count + 1,
cb8e9e
                                                       &brick_mount_path);
cb8e9e
                 if (ret) {
cb8e9e
                         gf_msg (this->name, GF_LOG_ERROR, 0,
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
cb8e9e
index cb312ae..ee279d3 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
cb8e9e
@@ -2972,11 +2972,10 @@ out:
cb8e9e
 
cb8e9e
 /* Figure out the brick mount path, from the brick path */
cb8e9e
 int32_t
cb8e9e
-glusterd_find_brick_mount_path (char *brick_path, int32_t brick_count,
cb8e9e
-                                char **brick_mount_path)
cb8e9e
+glusterd_find_brick_mount_path (char *brick_path, char **brick_mount_path)
cb8e9e
 {
cb8e9e
-        char                     brick_num[PATH_MAX] = "";
cb8e9e
         char                    *ptr                 = NULL;
cb8e9e
+        char                    *save_ptr            = NULL;
cb8e9e
         int32_t                  ret                 = -1;
cb8e9e
         xlator_t                *this                = NULL;
cb8e9e
 
cb8e9e
@@ -2991,12 +2990,10 @@ glusterd_find_brick_mount_path (char *brick_path, int32_t brick_count,
cb8e9e
                 goto out;
cb8e9e
         }
cb8e9e
 
cb8e9e
-        snprintf (brick_num, sizeof(brick_num), "brick%d", brick_count);
cb8e9e
-
cb8e9e
         /* Finding the pointer to the end of
cb8e9e
          * /var/run/gluster/snaps/<snap-uuid>
cb8e9e
          */
cb8e9e
-        ptr = strstr (*brick_mount_path, brick_num);
cb8e9e
+        ptr = strstr (*brick_mount_path, "brick");
cb8e9e
         if (!ptr) {
cb8e9e
                 /* Snapshot bricks must have brick num as part
cb8e9e
                  * of the brickpath
cb8e9e
@@ -3011,8 +3008,13 @@ glusterd_find_brick_mount_path (char *brick_path, int32_t brick_count,
cb8e9e
          * /var/run/gluster/snaps/<snap-uuid>/<brick_num>
cb8e9e
          * and assigning '\0' to it.
cb8e9e
          */
cb8e9e
-        ptr += strlen(brick_num);
cb8e9e
-        *ptr = '\0';
cb8e9e
+        while ((*ptr != '\0') && (*ptr != '/'))
cb8e9e
+                ptr++;
cb8e9e
+
cb8e9e
+        if (*ptr == '/') {
cb8e9e
+                ptr++;
cb8e9e
+                *ptr = '\0';
cb8e9e
+        }
cb8e9e
 
cb8e9e
         ret = 0;
cb8e9e
 out:
cb8e9e
@@ -3096,15 +3098,12 @@ glusterd_recreate_vol_brick_mounts (xlator_t  *this,
cb8e9e
         char                    *brick_mount_path    = NULL;
cb8e9e
         glusterd_brickinfo_t    *brickinfo           = NULL;
cb8e9e
         int32_t                  ret                 = -1;
cb8e9e
-        int32_t                  brick_count         = -1;
cb8e9e
         struct stat              st_buf              = {0, };
cb8e9e
 
cb8e9e
         GF_ASSERT (this);
cb8e9e
         GF_ASSERT (volinfo);
cb8e9e
 
cb8e9e
-        brick_count = 0;
cb8e9e
         cds_list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
cb8e9e
-                brick_count++;
cb8e9e
                 /* If the brick is not of this node, or its
cb8e9e
                  * snapshot is pending, or the brick is not
cb8e9e
                  * a snapshotted brick, we continue
cb8e9e
@@ -3116,7 +3115,6 @@ glusterd_recreate_vol_brick_mounts (xlator_t  *this,
cb8e9e
 
cb8e9e
                 /* Fetch the brick mount path from the brickinfo->path */
cb8e9e
                 ret = glusterd_find_brick_mount_path (brickinfo->path,
cb8e9e
-                                                      brick_count,
cb8e9e
                                                       &brick_mount_path);
cb8e9e
                 if (ret) {
cb8e9e
                         gf_log (this->name, GF_LOG_ERROR,
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
cb8e9e
index d617f60..27c51fa 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
cb8e9e
@@ -582,8 +582,8 @@ int
cb8e9e
 glusterd_unlink_file (char *sock_file_path);
cb8e9e
 
cb8e9e
 int32_t
cb8e9e
-glusterd_find_brick_mount_path (char *brick_path, int32_t brick_count,
cb8e9e
-                                char **brick_mount_path);
cb8e9e
+glusterd_find_brick_mount_path (char *brick_path, char **brick_mount_path);
cb8e9e
+
cb8e9e
 /*
cb8e9e
  * Function to retrieve list of snap volnames and their uuids
cb8e9e
  */
cb8e9e
-- 
cb8e9e
1.7.1
cb8e9e