summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Darcy <jdarcy@fb.com>2017-07-25 17:40:49 -0700
committerJeff Darcy <jeff@pl.atyp.us>2017-09-13 17:38:36 +0000
commit3b0757b51a34bc726a40935e644f0e0498e7beff (patch)
treea239e393e2e0e77c257de6e05feeb4c8a8189fbd
parente6245ebc0bb373623e624d8a75569137d580df46 (diff)
glusterd: make peerfile parsing more robust
Summary: This will now skip files in the peer directory that don't have names or contents that match what we expect for a valid peerfile, instead of blowing up the entire glusterd initialization as soon as the first unexpected thing happens. Test Plan: Test (peer-parsing.t) included. Reviewers: #posix_storage, kvigor Reviewed By: kvigor Subscribers: kvigor Differential Revision: https://phabricator.intern.facebook.com/D5498639 Tags: gluster, posix_storage Change-Id: Ifad9b047a828c2f76f97d0c39f305b7ec5a8ca4c Signed-off-by: Jeff Darcy <jdarcy@fb.com> Reviewed-on: https://review.gluster.org/18276 Reviewed-by: Jeff Darcy <jeff@pl.atyp.us> Tested-by: Jeff Darcy <jeff@pl.atyp.us> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Smoke: Gluster Build System <jenkins@build.gluster.org>
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c47
1 files changed, 32 insertions, 15 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index 14a00f9605d..cd035060316 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -4137,6 +4137,8 @@ glusterd_store_retrieve_peers (xlator_t *this)
glusterd_peerctx_args_t args = {0};
gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
glusterd_peer_hostname_t *address = NULL;
+ uuid_t tmp_uuid;
+ gf_boolean_t is_ok;
GF_ASSERT (this);
priv = this->private;
@@ -4156,21 +4158,29 @@ glusterd_store_retrieve_peers (xlator_t *this)
goto out;
}
- GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
-
- while (entry) {
+ for (;;) {
+ GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
+ if (!entry) {
+ break;
+ }
+ if (gf_uuid_parse (entry->d_name, tmp_uuid) != 0) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "skipping non-peer file %s", entry->d_name);
+ continue;
+ }
+ is_ok = _gf_false;
snprintf (filepath, PATH_MAX, "%s/%s", path, entry->d_name);
ret = gf_store_handle_retrieve (filepath, &shandle);
if (ret)
- goto out;
+ goto next;
ret = gf_store_iter_new (shandle, &iter);
if (ret)
- goto out;
+ goto next;
ret = gf_store_iter_get_next (iter, &key, &value, &op_errno);
if (ret)
- goto out;
+ goto next;
/* Create an empty peerinfo object before reading in the
* details
@@ -4179,7 +4189,7 @@ glusterd_store_retrieve_peers (xlator_t *this)
NULL, 0);
if (peerinfo == NULL) {
ret = -1;
- goto out;
+ goto next;
}
while (!ret) {
@@ -4211,7 +4221,7 @@ glusterd_store_retrieve_peers (xlator_t *this)
&op_errno);
}
if (op_errno != GD_STORE_EOF) {
- goto out;
+ goto next;
}
(void) gf_store_iter_destroy (iter);
@@ -4220,7 +4230,7 @@ glusterd_store_retrieve_peers (xlator_t *this)
gf_log ("glusterd", GF_LOG_ERROR,
"Null UUID while attempting to read peer from '%s'",
filepath);
- goto out;
+ goto next;
}
/* Set first hostname from peerinfo->hostnames to
@@ -4231,17 +4241,27 @@ glusterd_store_retrieve_peers (xlator_t *this)
hostname_list);
if (!address) {
ret = -1;
- goto out;
+ goto next;
}
peerinfo->hostname = gf_strdup (address->hostname);
ret = glusterd_friend_add_from_peerinfo (peerinfo, 1, NULL);
if (ret)
- goto out;
+ goto next;
peerinfo->shandle = shandle;
+ is_ok = _gf_true;
+
+next:
+ if (!is_ok) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "skipping malformed peer file %s",
+ entry->d_name);
+ if (peerinfo) {
+ glusterd_peerinfo_cleanup (peerinfo);
+ }
+ }
peerinfo = NULL;
- GF_FOR_EACH_ENTRY_IN_DIR (entry, dir);
}
args.mode = GD_MODE_ON;
@@ -4256,9 +4276,6 @@ glusterd_store_retrieve_peers (xlator_t *this)
peerinfo = NULL;
out:
- if (peerinfo)
- glusterd_peerinfo_cleanup (peerinfo);
-
if (dir)
sys_closedir (dir);
gf_msg_debug (this->name, 0, "Returning with %d", ret);