summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-locks.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-locks.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-locks.c118
1 files changed, 90 insertions, 28 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-locks.c b/xlators/mgmt/glusterd/src/glusterd-locks.c
index d2601ebb8..f5636a0f6 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: