summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-handshake.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-handshake.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handshake.c102
1 files changed, 77 insertions, 25 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c
index dbf342c..a1368e2 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handshake.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c
@@ -42,19 +42,21 @@ static size_t
build_volfile_path (const char *volname, char *path,
size_t path_len, char *trusted_str)
{
- struct stat stbuf = {0,};
- int32_t ret = -1;
- glusterd_conf_t *priv = NULL;
- char *vol = NULL;
- char *dup_volname = NULL;
- char *free_ptr = NULL;
- char *tmp = NULL;
- glusterd_volinfo_t *volinfo = NULL;
- char *server = NULL;
- gf_boolean_t snap_volume = _gf_false;
- char *str = NULL;
- char *tmp_volname = NULL;
- char *input_vol = NULL;
+ struct stat stbuf = {0,};
+ int32_t ret = -1;
+ glusterd_conf_t *priv = NULL;
+ char *vol = NULL;
+ char *dup_volname = NULL;
+ char *free_ptr = NULL;
+ char *tmp = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ glusterd_volinfo_t *parent_volinfo = NULL;
+ glusterd_snap_t *snap = NULL;
+ char *server = NULL;
+ gf_boolean_t snap_volume = _gf_false;
+ char *str = NULL;
+ char *parent_volname = NULL;
+ char *input_vol = NULL;
priv = THIS->private;
@@ -64,17 +66,53 @@ build_volfile_path (const char *volname, char *path,
path, path_len);
ret = 1;
goto out;
- } else if (strstr (volname, "/snaps/")) {
- input_vol = gf_strdup (volname);
+ } else if ((tmp = strstr (volname, "/snaps/"))) {
+ /* Input volname will have below formats:
+ <parent_volname>/snaps/<uuid>/<brick_path>
+ or
+ <parent_volname>/snaps/snapname
+
+ We need to extract snap uuid from the input volname */
+
snap_volume = _gf_true;
+ input_vol = gf_strdup (volname);
+ if (!input_vol)
+ goto out;
+ parent_volname = strtok_r (input_vol, "/", &str);
+ if (!parent_volname)
+ goto out;
+
str = strrchr (volname, '/');
if (str)
str++;
- dup_volname = gf_strdup (str);
+
+ tmp = strstr (tmp+1, "/");
+ while(*tmp && *tmp == '/')
+ tmp++;
+
+ /* User has provided snapname from the mountpoint.
+ Map the snapname to uuid to find the volfile */
+ if (tmp == str) {
+ ret = glusterd_volinfo_find (parent_volname,
+ &parent_volinfo);
+ if (ret) {
+ gf_log(THIS->name, GF_LOG_ERROR, "Failed to "
+ "find parent volinfo for snap %s", str);
+ goto out;
+ }
+ snap = glusterd_find_snap_by_name (parent_volinfo, str);
+ if (!snap) {
+ gf_log(THIS->name, GF_LOG_ERROR, "Failed to "
+ "fetch snap %s", str);
+ ret = -1;
+ goto out;
+ }
+ dup_volname = gf_strdup (snap->snap_volume->volname);
+ } else {
+ dup_volname = gf_strdup (str);
+ }
str = NULL;
- tmp_volname = strtok_r (input_vol, "/", &str);
- if (!tmp_volname)
- goto out;
+
} else if (volname[0] != '/') {
/* Normal behavior */
dup_volname = gf_strdup (volname);
@@ -85,9 +123,23 @@ build_volfile_path (const char *volname, char *path,
dup_volname = gf_strdup (&volname[1]);
}
+ if (!dup_volname) {
+ gf_log(THIS->name, GF_LOG_ERROR, "strdup failed");
+ ret = -1;
+ goto out;
+ }
free_ptr = dup_volname;
- ret = glusterd_volinfo_find (dup_volname, &volinfo);
+ if (!snap_volume) {
+ ret = glusterd_volinfo_find (dup_volname, &volinfo);
+ } else {
+ ret = 0;
+ if (snap)
+ volinfo = snap->snap_volume;
+ else
+ ret = glusterd_snap_volinfo_find (dup_volname,&volinfo);
+ }
+
if (ret) {
/* Split the volume name */
vol = strtok_r (dup_volname, ".", &tmp);
@@ -125,9 +177,9 @@ build_volfile_path (const char *volname, char *path,
dup_volname);
else
snprintf (path, path_len,
- "%s/vols/%s/snaps/%s/%s%s-fuse.vol",
- priv->workdir, tmp_volname, volinfo->volname,
- (trusted_str ? trusted_str:""), dup_volname);
+ "%s/vols/%s/snaps/%s/%s%s-fuse.vol",
+ priv->workdir, parent_volname, volinfo->volname,
+ (trusted_str ? trusted_str:""), dup_volname);
ret = stat (path, &stbuf);
}
@@ -139,8 +191,8 @@ build_volfile_path (const char *volname, char *path,
else
snprintf (path, path_len,
"%s/vols/%s/snaps/%s/%s-tcp.vol",
- priv->workdir, tmp_volname, volinfo->volname,
- volname);
+ priv->workdir, parent_volname,
+ volinfo->volname, volname);
}
ret = 1;