summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorPranith Kumar K <pkarampu@redhat.com>2014-07-05 12:19:28 +0530
committerNiels de Vos <ndevos@redhat.com>2014-07-14 02:38:19 -0700
commit14aedbab7f07b581510677f7f036be5b35b39ff2 (patch)
treef174a9035af8d82eb5a20b241097d1d8fea83e4e /libglusterfs
parent9d68bd17adf45b158ba8dd89f583805ae1a9e706 (diff)
client_t: Fix memory leaks
Backport of http://review.gluster.org/8247 - 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 BUG: 1116672 Change-Id: Ica87b9cbf02cae34c10789cfb56d1ccdc393cbf0 Signed-off-by: Pranith Kumar K <pkarampu@redhat.com> Reviewed-on: http://review.gluster.org/8289 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Niels de Vos <ndevos@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/client_t.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/libglusterfs/src/client_t.c b/libglusterfs/src/client_t.c
index 957eca60978..6e09a372ea0 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);
}
}