From 605db00dbad94d5bba6510e7695383715ef5035a Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Wed, 12 Nov 2014 18:02:15 +0530 Subject: rdma: Wrong volfile fetch on fuse mounting tcp,rdma volume via rdma Backport of http://review.gluster.org/8498 As of now for both tcp only volumes and rdma only volumes, volfile names are in the format -fuse.vol. This patch will change the client volfile namings as shown below. * TCP mounts always use -fuse.vol * RDMA mounts always use .rdma-fuse.vol Following the above naming convention, for tcp,rdma volumes both volfiles will be present under /var/lib/glusterd/vols// such that rdma only volume can be mounted as mount -t glusterfs -o transport=rdma :/ OR mount -t glusterfs :/.rdma The above command format can also be used to fuse mount a tcp,rdma volume via rdma transport. When we try to fuse mount a tcp,rdma volume with transport-type as rdma it silently mounts via tcp. This change will also make sure that it fetches the correct volfile based on the transport-type specified from client side. Change-Id: Id8b74c1c3e1e7fd323463061f8b13dd623fa6876 BUG: 1166515 Signed-off-by: Anoop C S Reviewed-on: http://review.gluster.org/8498 Tested-by: Gluster Build System Reviewed-by: Krishnan Parthasarathi Reviewed-by: Raghavendra G Tested-by: Raghavendra G Reviewed-on: http://review.gluster.org/9182 Reviewed-by: Raghavendra Bhat --- xlators/mgmt/glusterd/src/glusterd-handshake.c | 122 ++++++++++++++----------- xlators/mgmt/glusterd/src/glusterd-utils.c | 54 +++++++---- xlators/mgmt/glusterd/src/glusterd-utils.h | 4 +- xlators/mgmt/glusterd/src/glusterd-volgen.c | 30 +++--- 4 files changed, 128 insertions(+), 82 deletions(-) (limited to 'xlators/mgmt/glusterd') diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c index 7971f12bdac..f2f5178a456 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handshake.c +++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c @@ -147,54 +147,73 @@ out: } static size_t -build_volfile_path (const char *volname, char *path, +build_volfile_path (char *volume_id, 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 *save_ptr = NULL; - char *str_token = NULL; - glusterd_volinfo_t *volinfo = NULL; - char *server = NULL; - const char *volname_ptr = NULL; + char *free_ptr = NULL; + char *volname = NULL; + char *volid_ptr = NULL; char path_prefix [PATH_MAX] = {0,}; xlator_t *this = NULL; - char *volname_tmp = NULL; + glusterd_volinfo_t *volinfo = NULL; + glusterd_conf_t *priv = NULL; this = THIS; GF_ASSERT (this); priv = this->private; GF_ASSERT (priv); - GF_ASSERT (volname); + GF_ASSERT (volume_id); GF_ASSERT (path); - if (strstr (volname, "snapd/")) { - volname_tmp = strchr (volname, '/') + 1; - ret = glusterd_volinfo_find (volname_tmp, &volinfo); + volid_ptr = strstr (volume_id, "snapd/"); + if (volid_ptr) { + volid_ptr = strchr (volid_ptr, '/'); + if (!volid_ptr) { + ret = -1; + goto out; + } + volid_ptr++; + + ret = glusterd_volinfo_find (volid_ptr, &volinfo); if (ret == -1) { gf_log (this->name, GF_LOG_ERROR, "Couldn't find volinfo"); goto out; } glusterd_get_snapd_volfile (volinfo, path, path_len); - ret = 1; + ret = 0; goto out; - } else if (strstr (volname, "gluster/")) { - server = strchr (volname, '/') + 1; - glusterd_get_nodesvc_volfile (server, priv->workdir, + + } + + volid_ptr = strstr (volume_id, "gluster/"); + if (volid_ptr) { + volid_ptr = strchr (volid_ptr, '/'); + if (!volid_ptr) { + ret = -1; + goto out; + } + volid_ptr++; + + glusterd_get_nodesvc_volfile (volid_ptr, priv->workdir, path, path_len); - ret = 1; + ret = 0; goto out; - } else if ((str_token = strstr (volname, "/snaps/"))) { - ret = get_snap_volname_and_volinfo (str_token, &dup_volname, + + } + + volid_ptr = strstr (volume_id, "/snaps/"); + if (volid_ptr) { + ret = get_snap_volname_and_volinfo (volid_ptr, &volname, &volinfo); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Failed to get snap" - " volinfo from path (%s)", volname); + " volinfo from path (%s)", volume_id); ret = -1; goto out; } @@ -202,38 +221,43 @@ build_volfile_path (const char *volname, char *path, snprintf (path_prefix, sizeof (path_prefix), "%s/snaps/%s", priv->workdir, volinfo->snapshot->snapname); - free_ptr = dup_volname; - volname_ptr = dup_volname; + volid_ptr = volname; + /* this is to ensure that volname recvd from + get_snap_volname_and_volinfo is free'd */ + free_ptr = volname; goto gotvolinfo; - } else if (volname[0] != '/') { - /* Normal behavior */ - dup_volname = gf_strdup (volname); - } else { - /* Bringing in NFS like behavior for mount command, */ - /* With this, one can mount a volume with below cmd */ - /* bash# mount -t glusterfs server:/volume /mnt/pnt */ - dup_volname = gf_strdup (&volname[1]); + } - if (!dup_volname) { - gf_log(THIS->name, GF_LOG_ERROR, "strdup failed"); - ret = -1; - goto out; + if (volume_id[0] == '/') { + /* Normal behavior */ + volid_ptr = volume_id; + volid_ptr++; + + } else { + /* Bringing in NFS like behavior for mount command, */ + /* With this, one can mount a volume with below cmd */ + /* bash# mount -t glusterfs server:/volume /mnt/pnt */ + volid_ptr = volume_id; } - free_ptr = dup_volname; - volname_ptr = volname; snprintf (path_prefix, sizeof (path_prefix), "%s/vols", priv->workdir); - ret = glusterd_volinfo_find (dup_volname, &volinfo); + ret = glusterd_volinfo_find (volid_ptr, &volinfo); if (ret) { + dup_volname = gf_strdup (volid_ptr); + if (!dup_volname) { + ret = -1; + goto out; + } /* Split the volume name */ vol = strtok_r (dup_volname, ".", &save_ptr); - if (!vol) + if (!vol) { + ret = -1; goto out; - + } ret = glusterd_volinfo_find (vol, &volinfo); if (ret) goto out; @@ -244,7 +268,7 @@ gotvolinfo: trusted_str = NULL; ret = snprintf (path, path_len, "%s/%s/%s.vol", path_prefix, - volinfo->volname, volname_ptr); + volinfo->volname, volid_ptr); if (ret == -1) goto out; @@ -254,19 +278,14 @@ gotvolinfo: snprintf (path, path_len, "%s/%s/%s%s-fuse.vol", path_prefix, volinfo->volname, (trusted_str ? trusted_str : ""), - dup_volname); - + volid_ptr); ret = stat (path, &stbuf); } - - if ((ret == -1) && (errno == ENOENT)) { - snprintf (path, path_len, "%s/%s/%s-tcp.vol", - path_prefix, volinfo->volname, volname_ptr); - } - - ret = 1; out: - GF_FREE (free_ptr); + if (dup_volname) + GF_FREE (dup_volname); + if (free_ptr) + GF_FREE (free_ptr); return ret; } @@ -705,7 +724,7 @@ __server_getspec (rpcsvc_request_t *req) sizeof (filename), NULL); } - if (ret > 0) { + if (ret == 0) { /* to allocate the proper buffer to hold the file data */ ret = stat (filename, &stbuf); if (ret < 0){ @@ -725,6 +744,7 @@ __server_getspec (rpcsvc_request_t *req) ret = file_len = stbuf.st_size; } else { op_errno = ENOENT; + goto fail; } if (file_len) { diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index fcaa215b578..c2869d0faba 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -9032,47 +9032,65 @@ out: return ret; } -void +int glusterd_get_client_filepath (char *filepath, glusterd_volinfo_t *volinfo, gf_transport_type type) { - char path[PATH_MAX] = {0,}; + int ret = 0; + char path[PATH_MAX] = {0,}; glusterd_conf_t *priv = NULL; priv = THIS->private; GLUSTERD_GET_VOLUME_DIR (path, volinfo, priv); - if ((volinfo->transport_type == GF_TRANSPORT_BOTH_TCP_RDMA) && - (type == GF_TRANSPORT_RDMA)) - snprintf (filepath, PATH_MAX, "%s/%s.rdma-fuse.vol", - path, volinfo->volname); - else - snprintf (filepath, PATH_MAX, "%s/%s-fuse.vol", - path, volinfo->volname); + switch (type) { + case GF_TRANSPORT_TCP: + snprintf (filepath, PATH_MAX, + "%s/%s-fuse.vol", path, volinfo->volname); + break; + + case GF_TRANSPORT_RDMA: + snprintf (filepath, PATH_MAX, + "%s/%s.rdma-fuse.vol", path, volinfo->volname); + break; + default: + ret = -1; + break; + } + + return ret; } -void +int glusterd_get_trusted_client_filepath (char *filepath, glusterd_volinfo_t *volinfo, gf_transport_type type) { - char path[PATH_MAX] = {0,}; + int ret = 0; + char path[PATH_MAX] = {0,}; glusterd_conf_t *priv = NULL; priv = THIS->private; GLUSTERD_GET_VOLUME_DIR (path, volinfo, priv); - if ((volinfo->transport_type == GF_TRANSPORT_BOTH_TCP_RDMA) && - (type == GF_TRANSPORT_RDMA)) - snprintf (filepath, PATH_MAX, - "%s/trusted-%s.rdma-fuse.vol", + switch (type) { + case GF_TRANSPORT_TCP: + snprintf (filepath, PATH_MAX, "%s/trusted-%s-fuse.vol", path, volinfo->volname); - else - snprintf (filepath, PATH_MAX, - "%s/trusted-%s-fuse.vol", + break; + + case GF_TRANSPORT_RDMA: + snprintf (filepath, PATH_MAX, "%s/trusted-%s.rdma-fuse.vol", path, volinfo->volname); + break; + default: + ret = -1; + break; + } + + return ret; } int diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h index 2fe926c5fc9..77e51f6b61d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-utils.h @@ -458,11 +458,11 @@ glusterd_friend_contains_vol_bricks (glusterd_volinfo_t *volinfo, int glusterd_friend_remove_cleanup_vols (uuid_t uuid); -void +int glusterd_get_client_filepath (char *filepath, glusterd_volinfo_t *volinfo, gf_transport_type type); -void +int glusterd_get_trusted_client_filepath (char *filepath, glusterd_volinfo_t *volinfo, gf_transport_type type); diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index ba653a191ac..f38616ffbc7 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -3975,12 +3975,15 @@ int generate_client_volfiles (glusterd_volinfo_t *volinfo, glusterd_client_type_t client_type) { + int i = 0; + int ret = -1; char filepath[PATH_MAX] = {0,}; - int ret = -1; - char *types[] = {NULL, NULL, NULL}; - int i = 0; - dict_t *dict = NULL; - gf_transport_type type = GF_TRANSPORT_TCP; + char *types[] = {NULL, NULL, NULL}; + dict_t *dict = NULL; + xlator_t *this = NULL; + gf_transport_type type = GF_TRANSPORT_TCP; + + this = THIS; enumerate_transport_reqs (volinfo->transport_type, types); dict = dict_new (); @@ -3998,13 +4001,18 @@ generate_client_volfiles (glusterd_volinfo_t *volinfo, goto out; if (client_type == GF_CLIENT_TRUSTED) { - glusterd_get_trusted_client_filepath (filepath, - volinfo, - type); + ret = glusterd_get_trusted_client_filepath (filepath, + volinfo, + type); } else { - glusterd_get_client_filepath (filepath, - volinfo, - type); + ret = glusterd_get_client_filepath (filepath, + volinfo, + type); + } + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "Received invalid transport-type"); + goto out; } ret = generate_single_transport_client_volfile (volinfo, -- cgit