summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libglusterfs/src/client_t.c76
-rw-r--r--libglusterfs/src/client_t.h2
-rw-r--r--xlators/features/locks/src/posix.c6
-rw-r--r--xlators/performance/io-threads/src/io-threads.c6
-rw-r--r--xlators/protocol/server/src/server-helpers.c12
5 files changed, 59 insertions, 43 deletions
diff --git a/libglusterfs/src/client_t.c b/libglusterfs/src/client_t.c
index 1adfef5c7e3..62cfbc422f8 100644
--- a/libglusterfs/src/client_t.c
+++ b/libglusterfs/src/client_t.c
@@ -439,7 +439,31 @@ gf_client_unref (client_t *client)
static int
-client_ctx_set_int (client_t *client, void *key, void *value)
+__client_ctx_get_int (client_t *client, void *key, void **value)
+{
+ int index = 0;
+ int ret = 0;
+
+ for (index = 0; index < client->scratch_ctx.count; index++) {
+ if (client->scratch_ctx.ctx[index].ctx_key == key)
+ break;
+ }
+
+ if (index == client->scratch_ctx.count) {
+ ret = -1;
+ goto out;
+ }
+
+ if (value)
+ *value = client->scratch_ctx.ctx[index].ctx_value;
+
+out:
+ return ret;
+}
+
+
+static int
+__client_ctx_set_int (client_t *client, void *key, void *value)
{
int index = 0;
int ret = 0;
@@ -471,45 +495,31 @@ out:
}
-int
+/*will return success with old value if exist*/
+void *
client_ctx_set (client_t *client, void *key, void *value)
{
int ret = 0;
+ void *ret_value = NULL;
- if (!client || !key)
- return -1;
+ if (!client || !key || !value)
+ return NULL;
LOCK (&client->scratch_ctx.lock);
{
- ret = client_ctx_set_int (client, key, value);
- }
- UNLOCK (&client->scratch_ctx.lock);
-
- return ret;
-}
-
-
-static int
-client_ctx_get_int (client_t *client, void *key, void **value)
-{
- int index = 0;
- int ret = 0;
-
- for (index = 0; index < client->scratch_ctx.count; index++) {
- if (client->scratch_ctx.ctx[index].ctx_key == key)
- break;
- }
+ ret = __client_ctx_get_int (client, key, &ret_value);
+ if (!ret && ret_value) {
+ UNLOCK (&client->scratch_ctx.lock);
+ return ret_value;
+ }
- if (index == client->scratch_ctx.count) {
- ret = -1;
- goto out;
+ ret = __client_ctx_set_int (client, key, value);
}
+ UNLOCK (&client->scratch_ctx.lock);
- if (value)
- *value = client->scratch_ctx.ctx[index].ctx_value;
-
-out:
- return ret;
+ if (ret)
+ return NULL;
+ return value;
}
@@ -523,7 +533,7 @@ client_ctx_get (client_t *client, void *key, void **value)
LOCK (&client->scratch_ctx.lock);
{
- ret = client_ctx_get_int (client, key, value);
+ ret = __client_ctx_get_int (client, key, value);
}
UNLOCK (&client->scratch_ctx.lock);
@@ -532,7 +542,7 @@ client_ctx_get (client_t *client, void *key, void **value)
static int
-client_ctx_del_int (client_t *client, void *key, void **value)
+__client_ctx_del_int (client_t *client, void *key, void **value)
{
int index = 0;
int ret = 0;
@@ -568,7 +578,7 @@ client_ctx_del (client_t *client, void *key, void **value)
LOCK (&client->scratch_ctx.lock);
{
- ret = client_ctx_del_int (client, key, value);
+ ret = __client_ctx_del_int (client, key, value);
}
UNLOCK (&client->scratch_ctx.lock);
diff --git a/libglusterfs/src/client_t.h b/libglusterfs/src/client_t.h
index 31f1bd048ed..b4546f36bea 100644
--- a/libglusterfs/src/client_t.h
+++ b/libglusterfs/src/client_t.h
@@ -101,7 +101,7 @@ gf_client_dump_inodes_to_dict (xlator_t *this, dict_t *dict);
int
gf_client_dump_inodes (xlator_t *this);
-int
+void *
client_ctx_set (client_t *client, void *key, void *value);
int
diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c
index 44ca5004171..1b691c0a878 100644
--- a/xlators/features/locks/src/posix.c
+++ b/xlators/features/locks/src/posix.c
@@ -3480,6 +3480,7 @@ pl_ctx_get (client_t *client, xlator_t *xlator)
{
void *tmp = NULL;
pl_ctx_t *ctx = NULL;
+ pl_ctx_t *setted_ctx = NULL;
client_ctx_get (client, xlator, &tmp);
@@ -3498,10 +3499,11 @@ pl_ctx_get (client_t *client, xlator_t *xlator)
INIT_LIST_HEAD (&ctx->entrylk_lockers);
INIT_LIST_HEAD (&ctx->metalk_list);
- if (client_ctx_set (client, xlator, ctx) != 0) {
+ setted_ctx = client_ctx_set (client, xlator, ctx);
+ if (ctx != setted_ctx) {
pthread_mutex_destroy (&ctx->lock);
GF_FREE (ctx);
- ctx = NULL;
+ ctx = setted_ctx;
}
out:
return ctx;
diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c
index fd860d6a133..1247e41c99e 100644
--- a/xlators/performance/io-threads/src/io-threads.c
+++ b/xlators/performance/io-threads/src/io-threads.c
@@ -52,6 +52,7 @@ iot_client_ctx_t *
iot_get_ctx (xlator_t *this, client_t *client)
{
iot_client_ctx_t *ctx = NULL;
+ iot_client_ctx_t *setted_ctx = NULL;
int i;
if (client_ctx_get (client, this, (void **)&ctx) != 0) {
@@ -62,9 +63,10 @@ iot_get_ctx (xlator_t *this, client_t *client)
INIT_LIST_HEAD (&ctx[i].clients);
INIT_LIST_HEAD (&ctx[i].reqs);
}
- if (client_ctx_set (client, this, ctx) != 0) {
+ setted_ctx = client_ctx_set (client, this, ctx);
+ if (ctx != setted_ctx) {
GF_FREE (ctx);
- ctx = NULL;
+ ctx = setted_ctx;
}
}
}
diff --git a/xlators/protocol/server/src/server-helpers.c b/xlators/protocol/server/src/server-helpers.c
index 290038a9e6e..37f7bca47f0 100644
--- a/xlators/protocol/server/src/server-helpers.c
+++ b/xlators/protocol/server/src/server-helpers.c
@@ -1170,6 +1170,7 @@ server_ctx_get (client_t *client, xlator_t *xlator)
{
void *tmp = NULL;
server_ctx_t *ctx = NULL;
+ server_ctx_t *setted_ctx = NULL;
client_ctx_get (client, xlator, &tmp);
@@ -1194,11 +1195,12 @@ server_ctx_get (client_t *client, xlator_t *xlator)
LOCK_INIT (&ctx->fdtable_lock);
- if (client_ctx_set (client, xlator, ctx) != 0) {
- LOCK_DESTROY (&ctx->fdtable_lock);
- GF_FREE (ctx->fdtable);
- GF_FREE (ctx);
- ctx = NULL;
+ setted_ctx = client_ctx_set (client, xlator, ctx);
+ if (ctx != setted_ctx) {
+ LOCK_DESTROY (&ctx->fdtable_lock);
+ GF_FREE (ctx->fdtable);
+ GF_FREE (ctx);
+ ctx = setted_ctx;
}
out: