summaryrefslogtreecommitdiffstats
path: root/xlators/nfs
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@gluster.com>2011-06-29 00:35:07 +0000
committerAnand Avati <avati@gluster.com>2011-07-11 22:07:28 -0700
commit36ffb14bef1a297a9ecd5d73b4f74be444a675ea (patch)
tree3ebcbe08b4c13e5e25106bb63ca83247c66a2612 /xlators/nfs
parent2b2bddecb13465486fdcd9599bbdd95b23151c9d (diff)
nfs-rpc: Use mempool for allocating connection object
Signed-off-by: Shehjar Tikoo <shehjart@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 3039 (NFS RPC leaks memory in client connection creation on showmount -e) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=3039
Diffstat (limited to 'xlators/nfs')
-rw-r--r--xlators/nfs/lib/src/rpcsvc.c19
-rw-r--r--xlators/nfs/lib/src/rpcsvc.h3
2 files changed, 19 insertions, 3 deletions
diff --git a/xlators/nfs/lib/src/rpcsvc.c b/xlators/nfs/lib/src/rpcsvc.c
index 0831cf49ab6..6e0e020e72a 100644
--- a/xlators/nfs/lib/src/rpcsvc.c
+++ b/xlators/nfs/lib/src/rpcsvc.c
@@ -162,6 +162,7 @@ nfs_rpcsvc_init (glusterfs_ctx_t *ctx, dict_t *options)
{
rpcsvc_t *svc = NULL;
int ret = -1;
+ int poolsize = 0;
if ((!ctx) || (!options))
return NULL;
@@ -189,16 +190,28 @@ nfs_rpcsvc_init (glusterfs_ctx_t *ctx, dict_t *options)
}
ret = -1;
+ poolsize = RPCSVC_POOLCOUNT_MULT * RPCSVC_DEFAULT_MEMFACTOR;
+ svc->connpool = mem_pool_new (rpcsvc_conn_t, poolsize);
+ if (!svc->connpool) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to allocate connpool");
+ goto free_svc;
+ }
+
svc->defaultstage = nfs_rpcsvc_stage_init (svc);
if (!svc->defaultstage) {
gf_log (GF_RPCSVC, GF_LOG_ERROR,"RPC service init failed.");
- goto free_svc;
+ goto free_connpool;
}
svc->options = options;
svc->ctx = ctx;
gf_log (GF_RPCSVC, GF_LOG_DEBUG, "RPC service inited.");
ret = 0;
+
+free_connpool:
+ if (ret == -1)
+ mem_pool_destroy (svc->connpool);
+
free_svc:
if (ret == -1) {
GF_FREE (svc);
@@ -661,7 +674,7 @@ nfs_rpcsvc_conn_init (rpcsvc_t *svc, int sockfd)
int ret = -1;
unsigned int poolcount = 0;
- conn = GF_CALLOC (1, sizeof(*conn), gf_common_mt_rpcsvc_conn_t);
+ conn = mem_get (svc->connpool);
if (!conn) {
gf_log (GF_RPCSVC, GF_LOG_ERROR, "memory allocation failed");
return NULL;
@@ -717,7 +730,7 @@ nfs_rpcsvc_conn_destroy (rpcsvc_conn_t *conn)
mem_pool_destroy (conn->rxpool);
/* Need to destory record state, txlists etc. */
- GF_FREE (conn);
+ mem_put (((rpcsvc_t *)conn->stage->svc)->connpool, conn);
gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Connection destroyed");
}
diff --git a/xlators/nfs/lib/src/rpcsvc.h b/xlators/nfs/lib/src/rpcsvc.h
index 4e7c8184547..5ce3ba8e63e 100644
--- a/xlators/nfs/lib/src/rpcsvc.h
+++ b/xlators/nfs/lib/src/rpcsvc.h
@@ -526,6 +526,9 @@ typedef struct rpc_svc_state {
gf_boolean_t register_portmap;
struct list_head allprograms;
+
+ /* Mempool for incoming connection objects. */
+ struct mem_pool *connpool;
} rpcsvc_t;