Patchwork [BUG:1473] mgmt/glusterd: handle port allocation so ports are reused for same brick

login
register
Submitter Amar Tumballi
Date 2010-08-29 12:38:37
Message ID <20100829123837.GA28773@gluster.com>
Download mbox | patch
Permalink /patch/4359/
State Accepted
Delegated to: Anand Avati
Headers show

Comments

Amar Tumballi - 2010-08-29 12:38:37
* if 'brickinfo->port' exists use it instead of pmap_registry_alloc(),
  hence a brick after stop/start starts on same port

Signed-off-by: Amar Tumballi <amar@gluster.com>
---
 xlators/mgmt/glusterd/src/glusterd-pmap.c  |   16 ++++++++--------
 xlators/mgmt/glusterd/src/glusterd-utils.c |    4 +++-
 2 files changed, 11 insertions(+), 9 deletions(-)

Patch

diff --git a/xlators/mgmt/glusterd/src/glusterd-pmap.c b/xlators/mgmt/glusterd/src/glusterd-pmap.c
index dfb39b3..b919372 100644
--- a/xlators/mgmt/glusterd/src/glusterd-pmap.c
+++ b/xlators/mgmt/glusterd/src/glusterd-pmap.c
@@ -74,13 +74,11 @@  pmap_registry_new (void)
         for (i = 0; i < 65536; i++) {
                 if (!pmap_port_isfree (i)) {
                         pmap->ports[i].used = 1;
-                        pmap->last_alloc = i;
                 }
         }
 
-        pmap->base_port = 6969;
-        if (pmap->last_alloc < 6969)
-                pmap->last_alloc = 6969;
+        pmap->base_port = 6971; /* 6969 default for tcp, 6970 for IB */
+        pmap->last_alloc = 6971;
 
         return pmap;
 }
@@ -115,7 +113,7 @@  pmap_registry_search (xlator_t *this, const char *brickname)
 
         pmap = pmap_registry_get (this);
 
-        for (p = pmap->base_port; p < pmap->last_alloc; p++) {
+        for (p = pmap->base_port; p <= pmap->last_alloc; p++) {
                 if (!pmap->ports[p].brickname)
                         continue;
                 if (strcmp (pmap->ports[p].brickname, brickname) == 0) {
@@ -136,7 +134,7 @@  pmap_registry_search_by_xprt (xlator_t *this, void *xprt)
 
         pmap = pmap_registry_get (this);
 
-        for (p = pmap->base_port; p < pmap->last_alloc; p++) {
+        for (p = pmap->base_port; p <= pmap->last_alloc; p++) {
                 if (!pmap->ports[p].xprt)
                         continue;
                 if (pmap->ports[p].xprt == xprt) {
@@ -177,7 +175,7 @@  pmap_registry_alloc (xlator_t *this)
 
         pmap = pmap_registry_get (this);
 
-        for (p = pmap->base_port; p < 65535; p++) {
+        for (p = pmap->last_alloc; p < 65535; p++) {
                 if (pmap->ports[p].used)
                         continue;
 
@@ -188,6 +186,9 @@  pmap_registry_alloc (xlator_t *this)
                 }
         }
 
+        if (port)
+                pmap->last_alloc = port;
+
         return port;
 }
 
@@ -253,7 +254,6 @@  remove:
         gf_log ("pmap", GF_LOG_INFO, "removing brick %s on port %d",
                 pmap->ports[p].brickname, p);
 
-        pmap->ports[p].used = 0;
         if (pmap->ports[p].brickname)
                 free (pmap->ports[p].brickname);
 
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 156e262..0d1d7bf 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -786,7 +786,9 @@  glusterd_volume_start_glusterfs (glusterd_volinfo_t  *volinfo,
                 goto out;
         }
 
-        port = pmap_registry_alloc (THIS);
+        port = brickinfo->port;
+        if (!port)
+                port = pmap_registry_alloc (THIS);
 
         GLUSTERD_GET_BRICK_PIDFILE (pidfile, path, brickinfo->hostname,
                                     brickinfo->path);