summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulesWang <w.jq0722@gmail.com>2013-01-25 11:49:18 +0800
committerAnand Avati <avati@redhat.com>2013-01-26 11:39:34 -0800
commit710c52d23a2e7839a156c123167c6e13c8207f76 (patch)
tree87d9576bcfedc84091b5d9e686cb7d0a2a629e76
parent0cd9ef501d4e938a49da7835d96cec9f72521ecd (diff)
glusterd: make 'glusterd_is_local_addr' return bool
Change-Id: Id3bd0bfc4802c166f7a32b0cc6a726aeb5617b5d BUG: 890618 Signed-off-by: JulesWang <w.jq0722@gmail.com> Reviewed-on: http://review.gluster.org/4427 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c5
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handshake.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c39
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-replace-brick.c24
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c19
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h2
6 files changed, 45 insertions, 46 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index bfec8d4698f..ec717ac2ebf 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -736,9 +736,10 @@ glusterd_handle_cli_probe (rpcsvc_request_t *req)
gf_log ("glusterd", GF_LOG_INFO, "Received CLI probe req %s %d",
cli_req.hostname, cli_req.port);
- if (!(ret = glusterd_is_local_addr(cli_req.hostname))) {
+ if (glusterd_is_local_addr(cli_req.hostname)) {
glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_LOCALHOST, NULL,
cli_req.hostname, cli_req.port);
+ ret = 0;
goto out;
}
@@ -1440,7 +1441,7 @@ glusterd_handle_sync_volume (rpcsvc_request_t *req)
gf_log (this->name, GF_LOG_INFO, "Received volume sync req "
"for volume %s", (flags & GF_CLI_SYNC_ALL) ? "all" : volname);
- if (!glusterd_is_local_addr (hostname)) {
+ if (glusterd_is_local_addr (hostname)) {
ret = -1;
snprintf (msg, sizeof (msg), "sync from localhost"
" not allowed");
diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c
index adbb40c4fed..6a273df54b6 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handshake.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c
@@ -146,7 +146,7 @@ server_getspec (rpcsvc_request_t *req)
*tmp = '\0';
/* we trust the local admin */
- if (!glusterd_is_local_addr (addrstr)) {
+ if (glusterd_is_local_addr (addrstr)) {
ret = build_volfile_path (volume, filename,
sizeof (filename),
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index ef262b85733..b5026193ec4 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -763,25 +763,7 @@ glusterd_op_stage_sync_volume (dict_t *dict, char **op_errstr)
goto out;
}
- ret = glusterd_is_local_addr (hostname);
- if (ret) {
- ret = glusterd_friend_find (NULL, hostname, &peerinfo);
- if (ret) {
- snprintf (msg, sizeof (msg), "%s, is not a friend",
- hostname);
- *op_errstr = gf_strdup (msg);
- goto out;
- }
-
- if (!peerinfo->connected) {
- snprintf (msg, sizeof (msg), "%s, is not connected at "
- "the moment", hostname);
- *op_errstr = gf_strdup (msg);
- ret = -1;
- goto out;
- }
- } else {
-
+ if (glusterd_is_local_addr (hostname)) {
//volname is not present in case of sync all
ret = dict_get_str (dict, "volname", &volname);
if (!ret) {
@@ -800,6 +782,23 @@ glusterd_op_stage_sync_volume (dict_t *dict, char **op_errstr)
} else {
ret = 0;
}
+ } else {
+ ret = glusterd_friend_find (NULL, hostname, &peerinfo);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "%s, is not a friend",
+ hostname);
+ *op_errstr = gf_strdup (msg);
+ goto out;
+ }
+
+ if (!peerinfo->connected) {
+ snprintf (msg, sizeof (msg), "%s, is not connected at "
+ "the moment", hostname);
+ *op_errstr = gf_strdup (msg);
+ ret = -1;
+ goto out;
+ }
+
}
out:
@@ -1654,7 +1653,7 @@ glusterd_op_sync_volume (dict_t *dict, char **op_errstr,
goto out;
}
- if (glusterd_is_local_addr (hostname)) {
+ if (!glusterd_is_local_addr (hostname)) {
ret = 0;
goto out;
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
index a91c2ee1c64..8bd9a1529f1 100644
--- a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
+++ b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
@@ -431,7 +431,7 @@ glusterd_op_stage_replace_brick (dict_t *dict, char **op_errstr,
}
}
- if (!glusterd_is_local_addr (src_brickinfo->hostname)) {
+ if (glusterd_is_local_addr (src_brickinfo->hostname)) {
gf_log (this->name, GF_LOG_DEBUG,
"I AM THE SOURCE HOST");
if (src_brickinfo->port && rsp_dict) {
@@ -510,7 +510,7 @@ glusterd_op_stage_replace_brick (dict_t *dict, char **op_errstr,
}
if (!glusterd_is_rb_ongoing (volinfo) &&
- !glusterd_is_local_addr (host)) {
+ glusterd_is_local_addr (host)) {
ret = glusterd_brick_create_path (host, path,
volinfo->volume_id,
op_errstr);
@@ -518,7 +518,7 @@ glusterd_op_stage_replace_brick (dict_t *dict, char **op_errstr,
goto out;
}
- if (glusterd_is_local_addr (host)) {
+ if (!glusterd_is_local_addr (host)) {
ret = glusterd_friend_find (NULL, host, &peerinfo);
if (ret) {
snprintf (msg, sizeof (msg), "%s, is not a friend",
@@ -545,7 +545,7 @@ glusterd_op_stage_replace_brick (dict_t *dict, char **op_errstr,
}
if (replace_op == GF_REPLACE_OP_START &&
- !glusterd_is_local_addr (volinfo->rep_brick.dst_brick->hostname)) {
+ glusterd_is_local_addr (volinfo->rep_brick.dst_brick->hostname)) {
port = pmap_registry_alloc (THIS);
if (!port) {
gf_log (THIS->name, GF_LOG_CRITICAL,
@@ -1406,7 +1406,7 @@ rb_update_srcbrick_port (glusterd_brickinfo_t *src_brickinfo, dict_t *rsp_dict,
if (src_port)
src_brickinfo->port = src_port;
- if (!glusterd_is_local_addr (src_brickinfo->hostname)) {
+ if (glusterd_is_local_addr (src_brickinfo->hostname)) {
gf_log ("", GF_LOG_INFO,
"adding src-brick port no");
@@ -1460,7 +1460,7 @@ rb_update_dstbrick_port (glusterd_brickinfo_t *dst_brickinfo, dict_t *rsp_dict,
dst_brickinfo->port = dst_port;
- if (!glusterd_is_local_addr (dst_brickinfo->hostname)) {
+ if (glusterd_is_local_addr (dst_brickinfo->hostname)) {
gf_log ("", GF_LOG_INFO,
"adding dst-brick port no");
@@ -1668,7 +1668,7 @@ glusterd_op_replace_brick (dict_t *dict, dict_t *rsp_dict)
uuid_parse (task_id_str, volinfo->rep_brick.rb_id);
}
- if (!glusterd_is_local_addr (dst_brickinfo->hostname)) {
+ if (glusterd_is_local_addr (dst_brickinfo->hostname)) {
gf_log (this->name, GF_LOG_INFO,
"I AM THE DESTINATION HOST");
if (!glusterd_is_rb_paused (volinfo)) {
@@ -1688,7 +1688,7 @@ glusterd_op_replace_brick (dict_t *dict, dict_t *rsp_dict)
}
- if (!glusterd_is_local_addr (src_brickinfo->hostname)) {
+ if (glusterd_is_local_addr (src_brickinfo->hostname)) {
ret = rb_src_brick_restart (volinfo, src_brickinfo,
1);
if (ret) {
@@ -1698,7 +1698,7 @@ glusterd_op_replace_brick (dict_t *dict, dict_t *rsp_dict)
}
}
- if (!glusterd_is_local_addr (dst_brickinfo->hostname)) {
+ if (glusterd_is_local_addr (dst_brickinfo->hostname)) {
gf_log (this->name, GF_LOG_INFO,
"adding dst-brick port no");
@@ -1729,7 +1729,7 @@ glusterd_op_replace_brick (dict_t *dict, dict_t *rsp_dict)
/* fall through */
case GF_REPLACE_OP_COMMIT_FORCE:
{
- if (!glusterd_is_local_addr (dst_brickinfo->hostname)) {
+ if (glusterd_is_local_addr (dst_brickinfo->hostname)) {
gf_log (this->name, GF_LOG_DEBUG,
"I AM THE DESTINATION HOST");
ret = rb_kill_destination_brick (volinfo,
@@ -1810,7 +1810,7 @@ glusterd_op_replace_brick (dict_t *dict, dict_t *rsp_dict)
}
}
- if (!glusterd_is_local_addr (src_brickinfo->hostname)) {
+ if (glusterd_is_local_addr (src_brickinfo->hostname)) {
ret = rb_src_brick_restart (volinfo, src_brickinfo,
0);
if (ret) {
@@ -1821,7 +1821,7 @@ glusterd_op_replace_brick (dict_t *dict, dict_t *rsp_dict)
}
}
- if (!glusterd_is_local_addr (dst_brickinfo->hostname)) {
+ if (glusterd_is_local_addr (dst_brickinfo->hostname)) {
gf_log (this->name, GF_LOG_INFO,
"I AM THE DESTINATION HOST");
ret = rb_kill_destination_brick (volinfo, dst_brickinfo);
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index d093301cea9..b68ba252ebc 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -191,15 +191,13 @@ get_ip_from_addrinfo (struct addrinfo *addr, char **ip)
return *ip;
}
-/*TODO:FIXME: The function is expected to return a "yes/no" result.
- change return type to bool.*/
-int32_t
+gf_boolean_t
glusterd_is_local_addr (char *hostname)
{
int32_t ret = -1;
struct addrinfo *result = NULL;
struct addrinfo *res = NULL;
- int32_t found = 0;
+ gf_boolean_t found = _gf_false;
int sd = -1;
char *ip = NULL;
xlator_t *this = NULL;
@@ -244,7 +242,7 @@ out:
if (!found)
gf_log (this->name, GF_LOG_DEBUG, "%s is not local", hostname);
- return !found;
+ return found;
}
int32_t
@@ -4060,7 +4058,7 @@ glusterd_get_brickinfo (xlator_t *this, const char *brickname, int port,
list_for_each_entry (volinfo, &priv->volumes, vol_list) {
list_for_each_entry (tmpbrkinfo, &volinfo->bricks,
brick_list) {
- if (localhost && glusterd_is_local_addr (tmpbrkinfo->hostname))
+ if (localhost && !glusterd_is_local_addr (tmpbrkinfo->hostname))
continue;
if (!strcmp(tmpbrkinfo->path, brickname) &&
(tmpbrkinfo->port == port)) {
@@ -4725,11 +4723,12 @@ glusterd_hostname_to_uuid (char *hostname, uuid_t uuid)
ret = glusterd_friend_find_by_hostname (hostname, &peerinfo);
if (ret) {
- ret = glusterd_is_local_addr (hostname);
- if (ret)
- goto out;
- else
+ if (glusterd_is_local_addr (hostname)) {
uuid_copy (uuid, MY_UUID);
+ ret = 0;
+ } else {
+ goto out;
+ }
} else {
uuid_copy (uuid, peerinfo->uuid);
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index e5e6123cb71..ded299af70f 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -148,7 +148,7 @@ glusterd_volume_brickinfo_get_by_brick (char *brick,
glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t **brickinfo);
-int32_t
+gf_boolean_t
glusterd_is_local_addr (char *hostname);
int32_t