Patchwork [BUG:1505,2/3] Add brick hostname should not be localhost

login
register
Submitter shishir gowda
Date 2010-09-04 06:42:09
Message ID <20100904064209.GA4186@dev.gluster.com>
Download mbox | patch
Permalink /patch/4543/
State Accepted
Headers show

Comments

shishir gowda - 2010-09-04 06:42:09
Add brick hostname should not be localhost or 127.0.0.1, but valid
 nodeid or ip. This will prevent volfiles being generated at
 respective glusterd's as hostname would be localhost

Signed-off-by: shishir gowda <shishirng@gluster.com>
---
 cli/src/cli-cmd-parser.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

Patch

diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index cf9357c..cc14dfd 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -332,6 +332,9 @@  cli_cmd_volume_add_brick_parse (const char **words, int wordcount,
         int     j = 0;
         char    *tmp_list = NULL;
         char    *tmpptr = NULL;
+        char    *host_name = NULL;
+        char    *tmp = NULL;
+        char    *freeptr = NULL;
 
         GF_ASSERT (words);
         GF_ASSERT (options);
@@ -408,6 +411,26 @@  cli_cmd_volume_add_brick_parse (const char **words, int wordcount,
                         ret = -1;
                         goto out;
                 }
+
+                host_name = gf_strdup(words[brick_index]);
+                if (!host_name) {
+                        ret = -1;
+                        gf_log ("cli", GF_LOG_ERROR, "unable to allocate "
+                                "memory");
+                        goto out;
+                }
+                freeptr = host_name;
+                strtok_r(host_name, ":", &tmp);
+                if (!(strcmp(host_name, "localhost") &&
+                      strcmp (host_name, "127.0.0.1"))) {
+                        cli_out ("Please provide a valid hostname/ip other "
+                                 "localhost or 127.0.0.1");
+                        ret = -1;
+                        GF_FREE (freeptr);
+                        goto out;
+                }
+                GF_FREE (freeptr);
+
                 tmp_list = strdup(brick_list+1);
                 j = 0;
                 while(( brick_count != 0) && (j < brick_count)) {