diff options
author | Amar Tumballi <amar@gluster.com> | 2010-08-26 09:09:59 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-08-26 08:51:22 -0700 |
commit | 67d8b620186807f38277713930da2a1d1926d6d0 (patch) | |
tree | d46c48fecffd98650f85d8f06d7a44be7d495e04 | |
parent | 0b87986fb6c35771f1ee60a161d427725c954c38 (diff) |
glusterd-pmap: trigger signout by RPC_DISCONNECT event
Signed-off-by: Amar Tumballi <amar@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 1314 (portmapper functionality)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1314
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-pmap.c | 83 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-pmap.h | 7 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd.c | 3 |
3 files changed, 77 insertions, 16 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-pmap.c b/xlators/mgmt/glusterd/src/glusterd-pmap.c index 3a45da000..dfb39b353 100644 --- a/xlators/mgmt/glusterd/src/glusterd-pmap.c +++ b/xlators/mgmt/glusterd/src/glusterd-pmap.c @@ -72,12 +72,15 @@ pmap_registry_new (void) return NULL; for (i = 0; i < 65536; i++) { - if (!pmap_port_isfree (i)) + if (!pmap_port_isfree (i)) { pmap->ports[i].used = 1; + pmap->last_alloc = i; + } } pmap->base_port = 6969; - pmap->last_alloc = 6969; + if (pmap->last_alloc < 6969) + pmap->last_alloc = 6969; return pmap; } @@ -112,7 +115,7 @@ pmap_registry_search (xlator_t *this, const char *brickname) pmap = pmap_registry_get (this); - for (p = pmap->base_port; p < 65535; 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) { @@ -124,6 +127,27 @@ pmap_registry_search (xlator_t *this, const char *brickname) return port; } +int +pmap_registry_search_by_xprt (xlator_t *this, void *xprt) +{ + struct pmap_registry *pmap = NULL; + int p = 0; + int port = 0; + + pmap = pmap_registry_get (this); + + for (p = pmap->base_port; p < pmap->last_alloc; p++) { + if (!pmap->ports[p].xprt) + continue; + if (pmap->ports[p].xprt == xprt) { + port = p; + break; + } + } + + return port; +} + char * pmap_registry_search_by_port (xlator_t *this, int port) @@ -167,10 +191,9 @@ pmap_registry_alloc (xlator_t *this) return port; } - - int -pmap_registry_bind (xlator_t *this, int port, const char *brickname) +pmap_registry_bind (xlator_t *this, int port, + const char *brickname, void *xprt) { struct pmap_registry *pmap = NULL; int p = 0; @@ -185,27 +208,58 @@ pmap_registry_bind (xlator_t *this, int port, const char *brickname) if (pmap->ports[p].brickname) free (pmap->ports[p].brickname); pmap->ports[p].brickname = strdup (brickname); + pmap->ports[p].xprt = xprt; + + gf_log ("pmap", GF_LOG_INFO, "adding brick %s on port %d", + brickname, port); + if (pmap->last_alloc < p) + pmap->last_alloc = p; out: return 0; } int -pmap_registry_remove (xlator_t *this, int port, const char *brickname) +pmap_registry_remove (xlator_t *this, int port, + const char *brickname, void *xprt) { struct pmap_registry *pmap = NULL; int p = 0; pmap = pmap_registry_get (this); - if (port > 65535) - goto out; + if (port) { + if (port > 65535) + goto out; + + p = port; + goto remove; + } + + if (brickname && strchr (brickname, '/')) { + p = pmap_registry_search (this, brickname); + if (p) + goto remove; + } + + if (xprt) { + p = pmap_registry_search_by_xprt (this, xprt); + if (p) + goto remove; + } + + goto out; +remove: + gf_log ("pmap", GF_LOG_INFO, "removing brick %s on port %d", + pmap->ports[p].brickname, p); - p = port; pmap->ports[p].used = 0; if (pmap->ports[p].brickname) free (pmap->ports[p].brickname); + pmap->ports[p].brickname = NULL; + pmap->ports[p].xprt = NULL; + out: return 0; } @@ -299,7 +353,7 @@ gluster_pmap_signup (rpcsvc_request_t *req) goto fail; } - rsp.op_ret = pmap_registry_bind (THIS, args.port, args.brick); + rsp.op_ret = pmap_registry_bind (THIS, args.port, args.brick, req->trans); fail: glusterd_submit_reply (req, &rsp, NULL, 0, NULL, @@ -320,8 +374,8 @@ gluster_pmap_signin (rpcsvc_request_t *req) goto fail; } - - rsp.op_ret = pmap_registry_bind (THIS, args.port, args.brick); + rsp.op_ret = pmap_registry_bind (THIS, args.port, args.brick, + req->trans); fail: glusterd_submit_reply (req, &rsp, NULL, 0, NULL, @@ -345,7 +399,8 @@ gluster_pmap_signout (rpcsvc_request_t *req) goto fail; } - rsp.op_ret = pmap_registry_remove (THIS, args.port, args.brick); + rsp.op_ret = pmap_registry_remove (THIS, args.port, args.brick, + req->trans); fail: glusterd_submit_reply (req, &rsp, NULL, 0, NULL, diff --git a/xlators/mgmt/glusterd/src/glusterd-pmap.h b/xlators/mgmt/glusterd/src/glusterd-pmap.h index 4bc4536f8..6db616c39 100644 --- a/xlators/mgmt/glusterd/src/glusterd-pmap.h +++ b/xlators/mgmt/glusterd/src/glusterd-pmap.h @@ -41,6 +41,7 @@ struct pmap_port_status { int used; char *brickname; + void *xprt; }; struct pmap_registry { @@ -50,7 +51,9 @@ struct pmap_registry { }; int pmap_registry_alloc (xlator_t *this); -int pmap_registry_bind (xlator_t *this, int port, const char *brickname); -int pmap_registry_remove (xlator_t *this, int port, const char *brickname); +int pmap_registry_bind (xlator_t *this, int port, const char *brickname, + void *xprt); +int pmap_registry_remove (xlator_t *this, int port, const char *brickname, + void *xprt); #endif diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c index 2665e4ad2..1d19c7ed8 100644 --- a/xlators/mgmt/glusterd/src/glusterd.c +++ b/xlators/mgmt/glusterd/src/glusterd.c @@ -151,7 +151,10 @@ glusterd_rpcsvc_notify (rpcsvc_t *rpc, void *xl, rpcsvc_event_t event, break; } case RPCSVC_EVENT_DISCONNECT: + { + pmap_registry_remove (this, 0, NULL, xprt); break; + } default: break; |