Patchwork [BUG:1569] glusterd: preserve brick's port, retrive it while starting glusterd

login
register
Submitter Amar Tumballi
Date 2010-09-08 08:59:41
Message ID <20100908085941.GA7692@gluster.com>
Download mbox | patch
Permalink /patch/4649/
State Accepted
Headers show

Comments

Amar Tumballi - 2010-09-08 08:59:41
* this solves the problem of having brickinfo->port as 0 when
  when glusterd is restarted while glusterfsd processes are
  running

Signed-off-by: Amar Tumballi <amar@gluster.com>
---
 xlators/mgmt/glusterd/src/glusterd-store.c |   20 +++++++++++++++++---
 xlators/mgmt/glusterd/src/glusterd-store.h |    1 +
 2 files changed, 18 insertions(+), 3 deletions(-)

Patch

diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index 89208a9..a709fb2 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -138,10 +138,21 @@  glusterd_store_create_brick (glusterd_volinfo_t *volinfo,
         }
 
 
-        snprintf (buf, sizeof(buf), "hostname=%s\n", brickinfo->hostname);
+        snprintf (buf, sizeof(buf), "%s=%s\n",
+                  GLUSTERD_STORE_KEY_BRICK_HOSTNAME, brickinfo->hostname);
         ret = write (shandle->fd, buf, strlen(buf));
-        snprintf (buf, sizeof(buf), "path=%s\n", brickinfo->path);
+        if (ret)
+                gf_log ("", GF_LOG_TRACE, "failed to write brick->hostname");
+        snprintf (buf, sizeof(buf), "%s=%s\n",
+                  GLUSTERD_STORE_KEY_BRICK_PATH, brickinfo->path);
+        ret = write (shandle->fd, buf, strlen(buf));
+        if (ret)
+                gf_log ("", GF_LOG_TRACE, "failed to write brick->path");
+        snprintf (buf, sizeof(buf), "%s=%d\n",
+                  GLUSTERD_STORE_KEY_BRICK_PORT, brickinfo->port);
         ret = write (shandle->fd, buf, strlen(buf));
+        if (ret)
+                gf_log ("", GF_LOG_TRACE, "failed to write brick->port");
 
         ret = 0;
 
@@ -869,7 +880,10 @@  glusterd_store_retrieve_bricks (glusterd_volinfo_t *volinfo)
                                     strlen (GLUSTERD_STORE_KEY_BRICK_PATH))) {
                                 strncpy (brickinfo->path, value,
                                          sizeof (brickinfo->path));
-                        }else {
+                        } else if (!strncmp (key, GLUSTERD_STORE_KEY_BRICK_PORT,
+                                    strlen (GLUSTERD_STORE_KEY_BRICK_PORT))) {
+                                gf_string2int (value, &brickinfo->port);
+                        } else {
                                 gf_log ("", GF_LOG_ERROR, "Unknown key: %s",
                                         key);
                         }
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.h b/xlators/mgmt/glusterd/src/glusterd-store.h
index ff426f6..af05815 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.h
+++ b/xlators/mgmt/glusterd/src/glusterd-store.h
@@ -52,6 +52,7 @@ 
 
 #define GLUSTERD_STORE_KEY_BRICK_HOSTNAME "hostname"
 #define GLUSTERD_STORE_KEY_BRICK_PATH     "path"
+#define GLUSTERD_STORE_KEY_BRICK_PORT     "listen-port"
 
 #define GLUSTERD_STORE_KEY_PEER_UUID      "uuid"
 #define GLUSTERD_STORE_KEY_PEER_HOSTNAME  "hostname"