From c1a7a863d784961010f07ba78531dfc24c473e16 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Sat, 30 Apr 2016 14:37:40 +0530 Subject: [PATCH 120/139] rpc: fix gf_process_reserved_ports this patch also does minor code cleanups. Backport of: > Backport of: >> Change-Id: I0d005bd0f9baaaae498aa1df4faa6fcb65fa7a6e >> BUG: 1198849 >> Signed-off-by: Prasanna Kumar Kalever >> Reviewed-on: http://review.gluster.org/13997 >> Tested-by: Prasanna Kumar Kalever >> Smoke: Gluster Build System >> Reviewed-by: Atin Mukherjee >> CentOS-regression: Gluster Build System >> Reviewed-by: Jeff Darcy >> NetBSD-regression: NetBSD Build System > Change-Id: Ia53ba724f6d31cb2fc609786e31a1b676f55fe01 > BUG: 1331941 > Signed-off-by: Prasanna Kumar Kalever > Reviewed-on: http://review.gluster.org/14128 > Reviewed-by: Raghavendra G > Tested-by: Raghavendra G > Smoke: Gluster Build System > NetBSD-regression: NetBSD Build System > CentOS-regression: Gluster Build System Change-Id: Ic1ad8a3fafdcec6f529a2d9c5702099c31eeaf13 BUG: 1322306 Signed-off-by: Prasanna Kumar Kalever Reviewed-on: https://code.engineering.redhat.com/gerrit/73588 Reviewed-by: Atin Mukherjee --- libglusterfs/src/common-utils.c | 10 ++++++++++ rpc/rpc-transport/rdma/src/name.c | 8 +------- rpc/rpc-transport/socket/src/name.c | 10 ++-------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 88fe5f3..b9ada2b 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -2797,6 +2797,12 @@ int gf_process_reserved_ports (gf_boolean_t *ports, uint32_t ceiling) { int ret = -1; + int i = 0; + + for (i = 0; i < GF_PORT_MAX; i++) { + *(ports + i) = _gf_false; + } + #if defined GF_LINUX_HOST_OS char *ports_info = NULL; char *tmp = NULL; @@ -2822,7 +2828,11 @@ gf_process_reserved_ports (gf_boolean_t *ports, uint32_t ceiling) out: GF_FREE (ports_info); + +#else /* FIXME: Non Linux Host */ + ret = 0; #endif /* GF_LINUX_HOST_OS */ + return ret; } diff --git a/rpc/rpc-transport/rdma/src/name.c b/rpc/rpc-transport/rdma/src/name.c index 0bbbbc0..2f69975 100644 --- a/rpc/rpc-transport/rdma/src/name.c +++ b/rpc/rpc-transport/rdma/src/name.c @@ -56,15 +56,9 @@ af_inet_bind_to_port_lt_ceiling (struct rdma_cm_id *cm_id, { int32_t ret = -1; uint16_t port = ceiling - 1; - /* by default assume none of the ports are blocked and all are available */ - gf_boolean_t ports[GF_PORT_MAX] = {_gf_false,}; - int i = 0; + gf_boolean_t ports[GF_PORT_MAX]; ret = gf_process_reserved_ports (ports, ceiling); - if (ret != 0) { - for (i = 0; i < GF_PORT_MAX; i++) - ports[i] = _gf_false; - } while (port) { _assign_port (sockaddr, port); diff --git a/rpc/rpc-transport/socket/src/name.c b/rpc/rpc-transport/socket/src/name.c index 650c5a7..642e99c 100644 --- a/rpc/rpc-transport/socket/src/name.c +++ b/rpc/rpc-transport/socket/src/name.c @@ -44,20 +44,14 @@ af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr, { int32_t ret = -1; uint16_t port = ceiling - 1; - // by default assume none of the ports are blocked and all are available - gf_boolean_t ports[GF_PORT_MAX] = {_gf_false,}; - int i = 0; + gf_boolean_t ports[GF_PORT_MAX]; ret = gf_process_reserved_ports (ports, ceiling); - if (ret != 0) { - for (i = 0; i < GF_PORT_MAX; i++) - ports[i] = _gf_false; - } while (port) { _assign_port (sockaddr, port); - // ignore the reserved ports + /* ignore the reserved ports */ if (ports[port] == _gf_true) { port--; continue; -- 1.7.1