summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPranith Kumar K <pkarampu@redhat.com>2014-07-05 12:19:28 +0530
committerVijay Bellur <vbellur@redhat.com>2014-07-09 05:09:26 -0700
commit82e0fb290db880323613a3791acd33f96d421363 (patch)
treeb011dad9477373295a181d659fa20fef6abbbca0
parent56c7b07c746ba7ae86117f19bbf304e1150184fb (diff)
client_t: Fix memory leaks
- Assign frame->root->client so that gf_client_unref happens in server_connection_cleanup_flush_cbk - Avoid taking extra ref in gf_client_get TODO: The whole reason why there are two types of refs bind, ref-count is to avoid lock inside lock which is not the case now. I will be sending one more patch which will accomplish that as well as changing the tablearray to list Change-Id: Ic9971cf248c5ee2cdbfdef8e9ff6d54e3ec60ced BUG: 1116672 Signed-off-by: Pranith Kumar K <pkarampu@redhat.com> Reviewed-on: http://review.gluster.org/8247 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
-rw-r--r--libglusterfs/src/client_t.c27
-rw-r--r--xlators/protocol/server/src/server-handshake.c5
-rw-r--r--xlators/protocol/server/src/server-helpers.c4
-rw-r--r--xlators/protocol/server/src/server.c12
4 files changed, 30 insertions, 18 deletions
diff --git a/libglusterfs/src/client_t.c b/libglusterfs/src/client_t.c
index 957eca6..6e09a37 100644
--- a/libglusterfs/src/client_t.c
+++ b/libglusterfs/src/client_t.c
@@ -171,6 +171,11 @@ gf_client_clienttable_destroy (clienttable_t *clienttable)
# define DECREMENT_ATOMIC(lk,op) ({ LOCK (&lk); --op; UNLOCK (&lk); op; })
#endif
+/*
+ * Increments ref.bind if the client is already present or creates a new
+ * client with ref.bind = 1,ref.count = 1 it signifies that
+ * as long as ref.bind is > 0 client should be alive.
+ */
client_t *
gf_client_get (xlator_t *this, struct rpcsvc_auth_data *cred, char *client_uid)
{
@@ -206,13 +211,10 @@ gf_client_get (xlator_t *this, struct rpcsvc_auth_data *cred, char *client_uid)
client->auth.len) == 0))) {
INCREMENT_ATOMIC (client->ref.lock,
client->ref.bind);
- break;
+ goto unlock;
}
}
- if (client) {
- gf_client_ref (client);
- goto unlock;
- }
+
client = GF_CALLOC (1, sizeof(client_t), gf_common_mt_client_t);
if (client == NULL) {
errno = ENOMEM;
@@ -285,11 +287,13 @@ gf_client_get (xlator_t *this, struct rpcsvc_auth_data *cred, char *client_uid)
cliententry->client = client;
clienttable->first_free = cliententry->next_free;
cliententry->next_free = GF_CLIENTENTRY_ALLOCATED;
- gf_client_ref (client);
}
unlock:
UNLOCK (&clienttable->lock);
+ gf_log_callingfn ("client_t", GF_LOG_DEBUG, "%s: bind_ref: %d, ref: %d",
+ client->client_uid, client->ref.bind,
+ client->ref.count);
return client;
}
@@ -306,9 +310,10 @@ gf_client_put (client_t *client, gf_boolean_t *detached)
if (bind_ref == 0)
unref = _gf_true;
+ gf_log_callingfn ("client_t", GF_LOG_DEBUG, "%s: bind_ref: %d, ref: %d,"
+ " unref: %d", client->client_uid, client->ref.bind,
+ client->ref.count, unref);
if (unref) {
- gf_log (THIS->name, GF_LOG_INFO, "Shutting down connection %s",
- client->client_uid);
if (detached)
*detached = _gf_true;
gf_client_unref (client);
@@ -324,6 +329,8 @@ gf_client_ref (client_t *client)
}
INCREMENT_ATOMIC (client->ref.lock, client->ref.count);
+ gf_log_callingfn ("client_t", GF_LOG_DEBUG, "%s: ref-count %d",
+ client->client_uid, client->ref.count);
return client;
}
@@ -403,7 +410,11 @@ gf_client_unref (client_t *client)
}
refcount = DECREMENT_ATOMIC (client->ref.lock, client->ref.count);
+ gf_log_callingfn ("client_t", GF_LOG_DEBUG, "%s: ref-count %d",
+ client->client_uid, (int)client->ref.count);
if (refcount == 0) {
+ gf_log (THIS->name, GF_LOG_INFO, "Shutting down connection %s",
+ client->client_uid);
client_destroy (client);
}
}
diff --git a/xlators/protocol/server/src/server-handshake.c b/xlators/protocol/server/src/server-handshake.c
index 98418e7..9396499 100644
--- a/xlators/protocol/server/src/server-handshake.c
+++ b/xlators/protocol/server/src/server-handshake.c
@@ -757,12 +757,13 @@ server_set_lk_version (rpcsvc_request_t *req)
}
serv_ctx->lk_version = args.lk_ver;
- gf_client_put (client, NULL);
-
rsp.lk_ver = args.lk_ver;
op_ret = 0;
fail:
+ if (client)
+ gf_client_put (client, NULL);
+
rsp.op_ret = op_ret;
rsp.op_errno = op_errno;
server_submit_reply (NULL, req, &rsp, NULL, 0, NULL,
diff --git a/xlators/protocol/server/src/server-helpers.c b/xlators/protocol/server/src/server-helpers.c
index ebeaf90..dbd2653 100644
--- a/xlators/protocol/server/src/server-helpers.c
+++ b/xlators/protocol/server/src/server-helpers.c
@@ -242,7 +242,6 @@ server_connection_cleanup_flush_cbk (call_frame_t *frame, void *cookie,
client_t *client = NULL;
GF_VALIDATE_OR_GOTO ("server", this, out);
- GF_VALIDATE_OR_GOTO ("server", cookie, out);
GF_VALIDATE_OR_GOTO ("server", frame, out);
fd = frame->local;
@@ -298,9 +297,9 @@ do_fd_cleanup (xlator_t *this, client_t* client, fdentry_t *fdentries, int fd_co
}
tmp_frame->local = fd;
-
tmp_frame->root->pid = 0;
gf_client_ref (client);
+ tmp_frame->root->client = client;
memset (&tmp_frame->root->lk_owner, 0,
sizeof (gf_lkowner_t));
@@ -1098,6 +1097,7 @@ server_ctx_get (client_t *client, xlator_t *xlator)
if (client_ctx_set (client, xlator, ctx) != 0) {
LOCK_DESTROY (&ctx->fdtable_lock);
+ GF_FREE (ctx->fdtable);
GF_FREE (ctx);
ctx = NULL;
}
diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c
index 60092a5..3de856e 100644
--- a/xlators/protocol/server/src/server.c
+++ b/xlators/protocol/server/src/server.c
@@ -201,18 +201,18 @@ server_submit_reply (call_frame_t *frame, rpcsvc_request_t *req, void *arg,
ret = 0;
ret:
- if (state) {
+ if (state)
free_state (state);
- }
- if (frame) {
+ if (client)
gf_client_unref (client);
+
+ if (frame)
STACK_DESTROY (frame->root);
- }
- if (new_iobref) {
+ if (new_iobref)
iobref_unref (iobref);
- }
+
return ret;
}