Blob Blame History Raw
From 7e7ab869176fc7df8bc8c09a16d271ea235d7c80 Mon Sep 17 00:00:00 2001
From: Atin Mukherjee <amukherj@redhat.com>
Date: Mon, 18 Jul 2016 12:54:38 +0530
Subject: [PATCH 22/86] glusterd: search for free port from base_port

Backport of http://review.gluster.org/#/c/14939/

When a volume is deleted, the freed up ports are never considered for further
allocation since pmap_registry_alloc () always starts scanning from last_alloc.
So in use cases where gluster volumes are frequently created and deleted
managing ports become nightmare as for every new volume creation ports need to
be opened up by the admin based on the volume topology.

Solution: Instead of scanning from last_alloc, pmap_registry_alloc () always
starts from base_port now. What that means is glusterd will always try to find
out the ports which have been freed from earlier volumes and reallocate them for
the newer ones. There could be possibilities that when a volume is stopped and
started back their brick ports are changed which is completely acceptible IMHO.

>Reviewed-on: http://review.gluster.org/14939
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
>Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
>Smoke: Gluster Build System <jenkins@build.gluster.org>

This BZ fixes #1263090 as well

Change-Id: I99ccc11732b6a75527fcb6abafaf249ed02b3b78
BUG: 1356058
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/84627
---
 xlators/mgmt/glusterd/src/glusterd-pmap.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/xlators/mgmt/glusterd/src/glusterd-pmap.c b/xlators/mgmt/glusterd/src/glusterd-pmap.c
index 6a89a4f..3b9b227 100644
--- a/xlators/mgmt/glusterd/src/glusterd-pmap.c
+++ b/xlators/mgmt/glusterd/src/glusterd-pmap.c
@@ -184,7 +184,7 @@ pmap_registry_alloc (xlator_t *this)
 
         pmap = pmap_registry_get (this);
 
-        for (p = pmap->last_alloc; p <= GF_PORT_MAX; p++) {
+        for (p = pmap->base_port; p <= GF_PORT_MAX; p++) {
                 /* GF_PMAP_PORT_FOREIGN may be freed up ? */
                 if ((pmap->ports[p].type == GF_PMAP_PORT_FREE) ||
                     (pmap->ports[p].type == GF_PMAP_PORT_FOREIGN)) {
@@ -197,7 +197,7 @@ pmap_registry_alloc (xlator_t *this)
                 }
         }
 
-        if (port)
+        if (port > pmap->last_alloc)
                 pmap->last_alloc = port;
 
         return port;
-- 
1.7.1