summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvra Sengupta <asengupt@redhat.com>2014-03-03 23:07:23 +0000
committerRajesh Joseph <rjoseph@redhat.com>2014-03-07 04:30:44 -0800
commitb121434902d5839938045294cfdfe2a86e01a951 (patch)
treefed315406ccacf20bf13454a4d3601760c88fcad
parent44428343529bec83fab0e3519396471fc8f651b4 (diff)
glusterd/mgmt_v3 locks: Handling different entities with mgmt_v3_locks.
Within the same namespace allowing mgmt_v3 lock engine to handle entities of valid types. Postfixing the element's name with the entity type allows us to perform locking operations on different elements of different entitites at the same time. For example: A volume named test, will acquire a lock on the name test_vol, while a snap named test will acquire lock on the name test_snap, and thus be allowed to co-exist in the same namespace. Change-Id: I611d1a59b707e497d35a37bdca5a66e29a1b6f06 Signed-off-by: Avra Sengupta <asengupt@redhat.com> Reviewed-on: http://review.gluster.org/7188 Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Tested-by: Rajesh Joseph <rjoseph@redhat.com>
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c8
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-locks.c118
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-locks.h4
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c4
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-mgmt.c6
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c9
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-syncop.c5
7 files changed, 111 insertions, 43 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index c0325f0..f0316e7 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -671,7 +671,7 @@ glusterd_op_txn_begin (rpcsvc_request_t *req, glusterd_op_t op, void *ctx,
goto out;
}
- ret = glusterd_mgmt_v3_lock (volname, MY_UUID);
+ ret = glusterd_mgmt_v3_lock (volname, MY_UUID, "vol");
if (ret) {
gf_log (this->name, GF_LOG_ERROR,
"Unable to acquire lock for %s", volname);
@@ -722,7 +722,8 @@ out:
if (priv->op_version < 3)
glusterd_unlock (MY_UUID);
else {
- ret = glusterd_mgmt_v3_unlock (volname, MY_UUID);
+ ret = glusterd_mgmt_v3_unlock (volname, MY_UUID,
+ "vol");
if (ret)
gf_log (this->name, GF_LOG_ERROR,
"Unable to release lock for %s",
@@ -4070,7 +4071,8 @@ __glusterd_peer_rpc_notify (struct rpc_clnt *rpc, void *mydata,
if (peerinfo->connected) {
list_for_each_entry (volinfo, &conf->volumes, vol_list) {
ret = glusterd_mgmt_v3_unlock (volinfo->volname,
- peerinfo->uuid);
+ peerinfo->uuid,
+ "vol");
if (ret)
gf_log (this->name, GF_LOG_TRACE,
"Lock not released for %s",
diff --git a/xlators/mgmt/glusterd/src/glusterd-locks.c b/xlators/mgmt/glusterd/src/glusterd-locks.c
index d2601eb..f5636a0 100644
--- a/xlators/mgmt/glusterd/src/glusterd-locks.c
+++ b/xlators/mgmt/glusterd/src/glusterd-locks.c
@@ -26,8 +26,30 @@
#include <signal.h>
+/* Valid entities that the mgt_v3 lock can hold locks upon */
+char *valid_types[] = { "vol", "snap", NULL };
+
static dict_t *mgmt_v3_lock;
+/* Checks if the lock request is for a valid entity */
+gf_boolean_t
+glusterd_mgmt_v3_is_type_valid (char *type)
+{
+ int32_t i = 0;
+ gf_boolean_t ret = _gf_false;
+
+ GF_ASSERT (type);
+
+ for (i = 0; valid_types[i]; i++) {
+ if (!strcmp (type, valid_types[i])) {
+ ret = _gf_true;
+ break;
+ }
+ }
+
+ return ret;
+}
+
/* Initialize the global mgmt_v3 lock list(dict) when
* glusterd is spawned */
int32_t
@@ -116,7 +138,7 @@ glusterd_multiple_mgmt_v3_unlock (dict_t *dict, uuid_t uuid)
goto out;
}
- ret = glusterd_mgmt_v3_unlock (volname, uuid);
+ ret = glusterd_mgmt_v3_unlock (volname, uuid, "vol");
if (ret) {
gf_log ("", GF_LOG_ERROR,
"Failed to release lock for %s. ", volname);
@@ -148,7 +170,7 @@ glusterd_multiple_mgmt_v3_lock (dict_t *dict, uuid_t uuid)
ret = dict_get_int32 (dict, "volcount", &volcount);
if (ret) {
- gf_log ("", GF_LOG_DEBUG, "Failed to get volcount"
+ gf_log ("", GF_LOG_ERROR, "Failed to get volcount"
"name");
goto out;
}
@@ -166,7 +188,7 @@ glusterd_multiple_mgmt_v3_lock (dict_t *dict, uuid_t uuid)
goto out;
}
- ret = glusterd_mgmt_v3_lock (volname, uuid);
+ ret = glusterd_mgmt_v3_lock (volname, uuid, "vol");
if (ret) {
gf_log ("", GF_LOG_ERROR,
"Failed to acquire lock for %s "
@@ -193,7 +215,7 @@ glusterd_multiple_mgmt_v3_lock (dict_t *dict, uuid_t uuid)
goto out;
}
- ret = glusterd_mgmt_v3_unlock (volname, uuid);
+ ret = glusterd_mgmt_v3_unlock (volname, uuid, "vol");
if (ret)
gf_log ("", GF_LOG_ERROR,
"Failed to release lock for %s.",
@@ -208,21 +230,39 @@ out:
}
int32_t
-glusterd_mgmt_v3_lock (char *key, uuid_t uuid)
+glusterd_mgmt_v3_lock (const char *name, uuid_t uuid, char *type)
{
- int32_t ret = -1;
- mgmt_v3_lock_obj *lock_obj = NULL;
- uuid_t owner = {0};
+ char key[PATH_MAX] = "";
+ int32_t ret = -1;
+ mgmt_v3_lock_obj *lock_obj = NULL;
+ gf_boolean_t is_valid = _gf_true;
+ uuid_t owner = {0};
+
+ if (!name || !type) {
+ gf_log (THIS->name, GF_LOG_ERROR, "name or type is null.");
+ ret = -1;
+ goto out;
+ }
- if (!key) {
- gf_log (THIS->name, GF_LOG_ERROR, "key is null.");
+ is_valid = glusterd_mgmt_v3_is_type_valid (type);
+ if (is_valid != _gf_true) {
+ gf_log ("", GF_LOG_ERROR,
+ "Invalid entity. Cannot perform locking "
+ "operation on %s types", type);
ret = -1;
goto out;
}
- gf_log (THIS->name, GF_LOG_TRACE,
- "Trying to acquire lock of %s for %s",
- key, uuid_utoa (uuid));
+ ret = snprintf (key, sizeof(key), "%s_%s", name, type);
+ if (ret != strlen(name) + 1 + strlen(type)) {
+ ret = -1;
+ gf_log (THIS->name, GF_LOG_ERROR, "Unable to create key");
+ goto out;
+ }
+
+ gf_log (THIS->name, GF_LOG_DEBUG,
+ "Trying to acquire lock of %s %s for %s as %s",
+ type, name, uuid_utoa (uuid), key);
ret = glusterd_get_mgmt_v3_lock_owner (key, &owner);
if (ret) {
@@ -235,7 +275,7 @@ glusterd_mgmt_v3_lock (char *key, uuid_t uuid)
* we fail */
if (!uuid_is_null (owner)) {
gf_log (THIS->name, GF_LOG_ERROR, "Lock for %s held by %s",
- key, uuid_utoa (owner));
+ name, uuid_utoa (owner));
ret = -1;
goto out;
}
@@ -259,8 +299,9 @@ glusterd_mgmt_v3_lock (char *key, uuid_t uuid)
goto out;
}
- gf_log (THIS->name, GF_LOG_DEBUG, "Lock for %s successfully held by %s",
- key, uuid_utoa (uuid));
+ gf_log (THIS->name, GF_LOG_DEBUG,
+ "Lock for %s %s successfully held by %s",
+ type, name, uuid_utoa (uuid));
ret = 0;
out:
@@ -269,19 +310,39 @@ out:
}
int32_t
-glusterd_mgmt_v3_unlock (char *key, uuid_t uuid)
+glusterd_mgmt_v3_unlock (const char *name, uuid_t uuid, char *type)
{
- int32_t ret = -1;
- uuid_t owner = {0};
+ char key[PATH_MAX] = "";
+ int32_t ret = -1;
+ gf_boolean_t is_valid = _gf_true;
+ uuid_t owner = {0};
+
+ if (!name || !type) {
+ gf_log (THIS->name, GF_LOG_ERROR, "name is null.");
+ ret = -1;
+ goto out;
+ }
+
+ is_valid = glusterd_mgmt_v3_is_type_valid (type);
+ if (is_valid != _gf_true) {
+ gf_log ("", GF_LOG_ERROR,
+ "Invalid entity. Cannot perform unlocking "
+ "operation on %s types", type);
+ ret = -1;
+ goto out;
+ }
- if (!key) {
- gf_log (THIS->name, GF_LOG_ERROR, "key is null.");
+ ret = snprintf (key, sizeof(key), "%s_%s",
+ name, type);
+ if (ret != strlen(name) + 1 + strlen(type)) {
+ gf_log (THIS->name, GF_LOG_ERROR, "Unable to create key");
ret = -1;
goto out;
}
- gf_log (THIS->name, GF_LOG_TRACE, "Trying to release lock of %s for %s",
- key, uuid_utoa (uuid));
+ gf_log (THIS->name, GF_LOG_DEBUG,
+ "Trying to release lock of %s %s for %s as %s",
+ type, name, uuid_utoa (uuid), key);
ret = glusterd_get_mgmt_v3_lock_owner (key, &owner);
if (ret) {
@@ -292,7 +353,7 @@ glusterd_mgmt_v3_unlock (char *key, uuid_t uuid)
if (uuid_is_null (owner)) {
gf_log (THIS->name, GF_LOG_ERROR,
- "Lock for %s not held", key);
+ "Lock for %s %s not held", type, name);
ret = -1;
goto out;
}
@@ -301,16 +362,17 @@ glusterd_mgmt_v3_unlock (char *key, uuid_t uuid)
if (ret) {
gf_log (THIS->name, GF_LOG_ERROR, "Lock owner mismatch. "
- "Lock for %s held by %s",
- key, uuid_utoa (owner));
+ "Lock for %s %s held by %s",
+ type, name, uuid_utoa (owner));
goto out;
}
/* Removing the mgmt_v3 lock from the global list */
dict_del (mgmt_v3_lock, key);
- gf_log (THIS->name, GF_LOG_DEBUG, "Lock for %s successfully released",
- key);
+ gf_log (THIS->name, GF_LOG_DEBUG,
+ "Lock for %s %s successfully released",
+ type, name);
ret = 0;
out:
diff --git a/xlators/mgmt/glusterd/src/glusterd-locks.h b/xlators/mgmt/glusterd/src/glusterd-locks.h
index 71339ed..9ca332f 100644
--- a/xlators/mgmt/glusterd/src/glusterd-locks.h
+++ b/xlators/mgmt/glusterd/src/glusterd-locks.h
@@ -29,10 +29,10 @@ int32_t
glusterd_get_mgmt_v3_lock_owner (char *volname, uuid_t *uuid);
int32_t
-glusterd_mgmt_v3_lock (char *key, uuid_t uuid);
+glusterd_mgmt_v3_lock (const char *key, uuid_t uuid, char *type);
int32_t
-glusterd_mgmt_v3_unlock (char *key, uuid_t uuid);
+glusterd_mgmt_v3_unlock (const char *key, uuid_t uuid, char *type);
int32_t
glusterd_multiple_mgmt_v3_lock (dict_t *dict, uuid_t uuid);
diff --git a/xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c b/xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c
index 72181e9..5077a00 100644
--- a/xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c
@@ -74,7 +74,7 @@ glusterd_synctasked_mgmt_v3_lock (rpcsvc_request_t *req,
"Failed to get volname");
goto out;
}
- ret = glusterd_mgmt_v3_lock (volname, ctx->uuid);
+ ret = glusterd_mgmt_v3_lock (volname, ctx->uuid, "vol");
if (ret)
gf_log (this->name, GF_LOG_ERROR,
@@ -755,7 +755,7 @@ glusterd_synctasked_mgmt_v3_unlock (rpcsvc_request_t *req,
"Failed to get volname");
goto out;
}
- ret = glusterd_mgmt_v3_unlock (volname, ctx->uuid);
+ ret = glusterd_mgmt_v3_unlock (volname, ctx->uuid, "vol");
if (ret)
gf_log (this->name, GF_LOG_ERROR,
"Unable to release lock for %s", volname);
diff --git a/xlators/mgmt/glusterd/src/glusterd-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-mgmt.c
index 7359169..e895f6e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-mgmt.c
+++ b/xlators/mgmt/glusterd/src/glusterd-mgmt.c
@@ -313,7 +313,7 @@ glusterd_mgmt_v3_initiate_lockdown (glusterd_conf_t *conf, glusterd_op_t op,
goto out;
}
} else {
- ret = glusterd_mgmt_v3_lock (volname, MY_UUID);
+ ret = glusterd_mgmt_v3_lock (volname, MY_UUID, "vol");
if (ret) {
gf_log (this->name, GF_LOG_ERROR,
"Unable to acquire local lock for %s", volname);
@@ -1452,7 +1452,7 @@ out:
gf_log ("", GF_LOG_ERROR,
"Failed to release mgmt_v3 locks on localhost");
} else {
- ret = glusterd_mgmt_v3_unlock (volname, MY_UUID);
+ ret = glusterd_mgmt_v3_unlock (volname, MY_UUID, "vol");
if (ret)
gf_log (this->name, GF_LOG_ERROR,
"Unable to release local lock for %s", volname);
@@ -1646,7 +1646,7 @@ out:
gf_log ("", GF_LOG_ERROR,
"Failed to release mgmt_v3 locks on localhost");
} else {
- ret = glusterd_mgmt_v3_unlock (volname, MY_UUID);
+ ret = glusterd_mgmt_v3_unlock (volname, MY_UUID, "vol");
if (ret)
gf_log (this->name, GF_LOG_ERROR,
"Unable to release local lock for %s", volname);
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 05e4b71..1666f5e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -2749,7 +2749,8 @@ glusterd_op_ac_lock (glusterd_op_sm_event_t *event, void *ctx)
gf_log (this->name, GF_LOG_ERROR,
"Unable to acquire volname");
else {
- ret = glusterd_mgmt_v3_lock (volname, lock_ctx->uuid);
+ ret = glusterd_mgmt_v3_lock (volname, lock_ctx->uuid,
+ "vol");
if (ret)
gf_log (this->name, GF_LOG_ERROR,
"Unable to acquire lock for %s",
@@ -2796,7 +2797,8 @@ glusterd_op_ac_unlock (glusterd_op_sm_event_t *event, void *ctx)
gf_log (this->name, GF_LOG_ERROR,
"Unable to acquire volname");
else {
- ret = glusterd_mgmt_v3_unlock (volname, lock_ctx->uuid);
+ ret = glusterd_mgmt_v3_unlock (volname, lock_ctx->uuid,
+ "vol");
if (ret)
gf_log (this->name, GF_LOG_ERROR,
"Unable to release lock for %s", volname);
@@ -4082,7 +4084,8 @@ glusterd_op_txn_complete (uuid_t *txn_id)
"Unable to acquire volname");
if (volname) {
- ret = glusterd_mgmt_v3_unlock (volname, MY_UUID);
+ ret = glusterd_mgmt_v3_unlock (volname, MY_UUID,
+ "vol");
if (ret)
gf_log (this->name, GF_LOG_ERROR,
"Unable to release lock for %s",
diff --git a/xlators/mgmt/glusterd/src/glusterd-syncop.c b/xlators/mgmt/glusterd/src/glusterd-syncop.c
index beab4ac..438df82 100644
--- a/xlators/mgmt/glusterd/src/glusterd-syncop.c
+++ b/xlators/mgmt/glusterd/src/glusterd-syncop.c
@@ -1336,7 +1336,8 @@ out:
if (conf->op_version < 3)
glusterd_unlock (MY_UUID);
else {
- ret = glusterd_mgmt_v3_unlock (volname, MY_UUID);
+ ret = glusterd_mgmt_v3_unlock (volname, MY_UUID,
+ "vol");
if (ret)
gf_log (this->name, GF_LOG_ERROR,
"Unable to release lock for %s",
@@ -1527,7 +1528,7 @@ gd_sync_task_begin (dict_t *op_ctx, rpcsvc_request_t * req)
goto out;
}
- ret = glusterd_mgmt_v3_lock (volname, MY_UUID);
+ ret = glusterd_mgmt_v3_lock (volname, MY_UUID, "vol");
if (ret) {
gf_log (this->name, GF_LOG_ERROR,
"Unable to acquire lock for %s", volname);