summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-locks.c
diff options
context:
space:
mode:
authorAvra Sengupta <asengupt@redhat.com>2013-10-09 22:13:34 +0530
committershishir gowda <sgowda@redhat.com>2013-11-15 12:37:58 +0530
commit8c89a5ffc9d1a9aa6a52a915cdd988c40aececb7 (patch)
treea5629248a8c8f78637370920c26445310c283fe3 /xlators/mgmt/glusterd/src/glusterd-locks.c
parent99a7b58a2983788a3bb36662d2b83c2da3b6472c (diff)
glusterd/locks: Adding multiple volume locks supports
Also linking snap create command to mgmt_v3 Change-Id: If2ed29be072e10d0b0bd271d53e48eeaa6501ed7 Signed-off-by: Avra Sengupta <asengupt@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-locks.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-locks.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-locks.c b/xlators/mgmt/glusterd/src/glusterd-locks.c
index c09ba33a7..f0658da3a 100644
--- a/xlators/mgmt/glusterd/src/glusterd-locks.c
+++ b/xlators/mgmt/glusterd/src/glusterd-locks.c
@@ -81,6 +81,132 @@ out:
}
int32_t
+glusterd_multiple_volumes_unlock (dict_t *dict, uuid_t uuid)
+{
+ int32_t ret = -1;
+ int32_t op_ret = 0;
+ int32_t i = -1;
+ int32_t volcount = -1;
+ char volname_buf[PATH_MAX] = "";
+ char *volname = NULL;
+
+ if (!dict) {
+ gf_log ("", GF_LOG_ERROR, "dict is null.");
+ ret = -1;
+ goto out;
+ }
+
+ ret = dict_get_int32 (dict, "volcount", &volcount);
+ if (ret) {
+ gf_log ("", GF_LOG_DEBUG, "Failed to get volcount"
+ "name");
+ goto out;
+ }
+
+ /* Unlocking one volume after other */
+ for (i = 1; i <= volcount; i++) {
+ ret = snprintf (volname_buf, sizeof(volname_buf) - 1,
+ "volname%d", i);
+ volname_buf[ret] = '\0';
+
+ ret = dict_get_str (dict, volname_buf, &volname);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to get %s Volcount = %d",
+ volname_buf, volcount);
+ goto out;
+ }
+
+ ret = glusterd_volume_unlock (volname, uuid);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR,
+ "Failed to release lock for %s. ", volname);
+ op_ret = ret;
+ }
+ }
+
+ ret = op_ret;
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
+
+int32_t
+glusterd_multiple_volumes_lock (dict_t *dict, uuid_t uuid)
+{
+ int32_t ret = -1;
+ int32_t i = -1;
+ int32_t volcount = -1;
+ char volname_buf[PATH_MAX] = "";
+ char *volname = NULL;
+ int32_t locked_volcount = 0;
+
+ if (!dict) {
+ gf_log ("", GF_LOG_ERROR, "dict is null.");
+ ret = -1;
+ goto out;
+ }
+
+ ret = dict_get_int32 (dict, "volcount", &volcount);
+ if (ret) {
+ gf_log ("", GF_LOG_DEBUG, "Failed to get volcount"
+ "name");
+ goto out;
+ }
+
+ /* Locking one volume after other */
+ for (i = 1; i <= volcount; i++) {
+ ret = snprintf (volname_buf, sizeof(volname_buf) - 1,
+ "volname%d", i);
+ volname_buf[ret] = '\0';
+
+ ret = dict_get_str (dict, volname_buf, &volname);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to get %s Volcount = %d",
+ volname_buf, volcount);
+ goto out;
+ }
+
+ ret = glusterd_volume_lock (volname, uuid);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR,
+ "Failed to acquire lock for %s. "
+ "Unlocking other volumes locked "
+ "by this transaction", volname);
+ break;
+ }
+ locked_volcount ++;
+ }
+
+ /* If we failed to lock one volume, unlock others and return failure */
+ if (volcount != locked_volcount) {
+ for (i = 1; i <= locked_volcount; i++) {
+ ret = snprintf (volname_buf, sizeof(volname_buf) - 1,
+ "volname%d", i);
+ volname_buf[ret] = '\0';
+
+ ret = dict_get_str (dict, volname_buf, &volname);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR,
+ "Unable to get %s lockd_volcount = %d",
+ volname_buf, volcount);
+ goto out;
+ }
+
+ ret = glusterd_volume_unlock (volname, uuid);
+ if (ret)
+ gf_log ("", GF_LOG_ERROR,
+ "Failed to release lock for %s.",
+ volname);
+ }
+ ret = -1;
+ }
+
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
+
+int32_t
glusterd_volume_lock (char *volname, uuid_t uuid)
{
int32_t ret = -1;