diff options
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-locks.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-locks.c | 126 |
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; |