diff options
author | Atin Mukherjee <amukherj@redhat.com> | 2016-01-19 10:45:22 +0530 |
---|---|---|
committer | Atin Mukherjee <amukherj@redhat.com> | 2016-03-02 20:15:59 -0800 |
commit | cdc96d5d4c6247d9b0ca942eeb37338dacfe93ee (patch) | |
tree | 855a1f45bae156c9979262496c2721aa9958ad71 | |
parent | f7063e738c16ae89d49968cdf4161792fae5431e (diff) |
glusterd: use string comparison for realpath checks in glusterd_is_brickpath_available
Backport of http://review.gluster.org/13258
glusterd_is_brickpath_available () used to call realpath() for checking the
whether the new brick path matches with the existing ones. The problem with this
is if the underlying file system is bad for any one of the existing bricks then
realpath() would fail and we wouldn't allow to create the new brick even if it
should be allowed.
Fix is to use string comparison with having a new field real_path in brickinfo
to store the absolute path
Change-Id: I1250ea5345f00fca0f6128056ebd08750d604f0a
BUG: 1312878
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
Reviewed-on: http://review.gluster.org/13258
Smoke: Gluster Build System <jenkins@build.gluster.com>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-on: http://review.gluster.org/13550
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-snapshot.c | 16 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-store.c | 18 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 29 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd.h | 1 |
4 files changed, 51 insertions, 13 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index 7718fb5d16d..8b814acd455 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -4821,6 +4821,7 @@ glusterd_add_brick_to_snap_volume (dict_t *dict, dict_t *rsp_dict, gf_boolean_t add_missed_snap = _gf_false; int32_t ret = -1; xlator_t *this = NULL; + char abspath[PATH_MAX] = {0}; this = THIS; GF_ASSERT (this); @@ -4957,6 +4958,21 @@ glusterd_add_brick_to_snap_volume (dict_t *dict, dict_t *rsp_dict, strcpy (snap_brickinfo->hostname, original_brickinfo->hostname); strcpy (snap_brickinfo->path, snap_brick_path); + + if (!realpath (snap_brick_path, abspath)) { + /* ENOENT indicates that brick path has not been created which + * is a valid scenario */ + if (errno != ENOENT) { + gf_msg (this->name, GF_LOG_CRITICAL, errno, + GD_MSG_BRICKINFO_CREATE_FAIL, "realpath () " + "failed for brick %s. The underlying filesystem" + " may be in bad state", snap_brick_path); + ret = -1; + goto out; + } + } + strncpy (snap_brickinfo->real_path, abspath, strlen(abspath)); + strcpy (snap_brickinfo->mount_dir, original_brickinfo->mount_dir); gf_uuid_copy (snap_brickinfo->uuid, original_brickinfo->uuid); /* AFR changelog names are based on brick_id and hence the snap diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index ca02b10b572..19115ef8943 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -2252,6 +2252,7 @@ glusterd_store_retrieve_bricks (glusterd_volinfo_t *volinfo) char tmpkey[4096] = {0,}; gf_store_iter_t *tmpiter = NULL; char *tmpvalue = NULL; + char abspath[PATH_MAX] = {0}; struct pmap_registry *pmap = NULL; xlator_t *this = NULL; int brickid = 0; @@ -2405,7 +2406,22 @@ glusterd_store_retrieve_bricks (glusterd_volinfo_t *volinfo) GLUSTERD_ASSIGN_BRICKID_TO_BRICKINFO (brickinfo, volinfo, brickid++); } - + ret = glusterd_resolve_brick (brickinfo); + if (ret) + goto out; + if (!gf_uuid_compare(brickinfo->uuid, MY_UUID)) { + if (!realpath (brickinfo->path, abspath)) { + gf_msg (this->name, GF_LOG_CRITICAL, errno, + GD_MSG_BRICKINFO_CREATE_FAIL, "realpath" + " () failed for brick %s. The " + "underlying file system may be in bad" + " state", brickinfo->path); + ret = -1; + goto out; + } + strncpy (brickinfo->real_path, abspath, + strlen(abspath)); + } cds_list_add_tail (&brickinfo->brick_list, &volinfo->bricks); brick_count++; } diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index a4d6ec592d9..7e9781f190d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -679,6 +679,7 @@ glusterd_brickinfo_dup (glusterd_brickinfo_t *brickinfo, strcpy (dup_brickinfo->hostname, brickinfo->hostname); strcpy (dup_brickinfo->path, brickinfo->path); + strcpy (dup_brickinfo->real_path, brickinfo->real_path); strcpy (dup_brickinfo->device_path, brickinfo->device_path); strcpy (dup_brickinfo->fstype, brickinfo->fstype); strcpy (dup_brickinfo->mnt_opts, brickinfo->mnt_opts); @@ -1072,6 +1073,7 @@ glusterd_brickinfo_new_from_brick (char *brick, int32_t ret = -1; glusterd_brickinfo_t *new_brickinfo = NULL; xlator_t *this = NULL; + char abspath[PATH_MAX] = {0}; this = THIS; GF_ASSERT (this); @@ -1106,10 +1108,23 @@ glusterd_brickinfo_new_from_brick (char *brick, ret = gf_canonicalize_path (path); if (ret) goto out; - strncpy (new_brickinfo->hostname, hostname, 1024); strncpy (new_brickinfo->path, path, 1024); + if (!realpath (new_brickinfo->path, abspath)) { + /* ENOENT indicates that brick path has not been created which + * is a valid scenario */ + if (errno != ENOENT) { + gf_msg (this->name, GF_LOG_CRITICAL, errno, + GD_MSG_BRICKINFO_CREATE_FAIL, "realpath () failed for " + "brick %s. The underlying filesystem may be in bad " + "state", new_brickinfo->path); + ret = -1; + goto out; + } + } + strncpy (new_brickinfo->real_path, abspath, strlen(abspath)); + *brickinfo = new_brickinfo; ret = 0; @@ -1171,7 +1186,6 @@ glusterd_is_brickpath_available (uuid_t uuid, char *path) glusterd_conf_t *priv = NULL; gf_boolean_t available = _gf_false; char tmp_path[PATH_MAX+1] = {0}; - char tmp_brickpath[PATH_MAX+1] = {0}; priv = THIS->private; @@ -1190,16 +1204,7 @@ glusterd_is_brickpath_available (uuid_t uuid, char *path) brick_list) { if (gf_uuid_compare (uuid, brickinfo->uuid)) continue; - - if (!realpath (brickinfo->path, tmp_brickpath)) { - if (errno == ENOENT) - strncpy (tmp_brickpath, brickinfo->path, - PATH_MAX); - else - goto out; - } - - if (_is_prefix (tmp_brickpath, tmp_path)) + if (_is_prefix (brickinfo->real_path, tmp_path)) goto out; } } diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index c872cd2339c..01dbd5878fb 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -194,6 +194,7 @@ typedef enum gf_brick_status { struct glusterd_brickinfo { char hostname[1024]; char path[PATH_MAX]; + char real_path[PATH_MAX]; char device_path[PATH_MAX]; char mount_dir[PATH_MAX]; char brick_id[1024];/*Client xlator name, AFR changelog name*/ |