summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorKrutika Dhananjay <kdhananj@redhat.com>2013-07-31 13:19:19 +0530
committerKrutika Dhananjay <kdhananj@redhat.com>2013-08-09 15:20:11 +0530
commita09f9e94fd800fb0bbd8617de566aa57381d6048 (patch)
treee881b700c01cb154139a665443ab2c782815f81b /xlators
parent7f7e77956499f447695af2458582effd3adf08d1 (diff)
glusterd: club limit-usage and soft-limit into a single command
Change-Id: I5f680675576aeec584b497eb25dd804a9dd6d690 Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
Diffstat (limited to 'xlators')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-quota.c248
1 files changed, 83 insertions, 165 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c
index 307b16d8..474d24ad 100644
--- a/xlators/mgmt/glusterd/src/glusterd-quota.c
+++ b/xlators/mgmt/glusterd/src/glusterd-quota.c
@@ -21,6 +21,9 @@
#include "glusterd-utils.h"
#include "glusterd-volgen.h"
#include "run.h"
+#include "syscall.h"
+#include "byte-order.h"
+#include "compat-errno.h"
#include <sys/wait.h>
@@ -33,7 +36,6 @@ const char *gd_quota_op_list[GF_QUOTA_OPTION_TYPE_DEFAULT_SOFT_LIMIT+1] = {
[GF_QUOTA_OPTION_TYPE_REMOVE] = "remove",
[GF_QUOTA_OPTION_TYPE_LIST] = "list",
[GF_QUOTA_OPTION_TYPE_VERSION] = "version",
- [GF_QUOTA_OPTION_TYPE_SOFT_LIMIT] = "soft-limit",
[GF_QUOTA_OPTION_TYPE_ALERT_TIME] = "alert-time",
[GF_QUOTA_OPTION_TYPE_SOFT_TIMEOUT] = "soft-timeout",
[GF_QUOTA_OPTION_TYPE_HARD_TIMEOUT] = "hard-timeout",
@@ -600,143 +602,97 @@ out:
return ret;
}
-static void
-gd_quota_get_formatted_limit_list (char **value, char *existing_list,
- char *path, char *hard_limit,
- char *soft_limit)
+static int
+glusterd_set_quota_limit (char *volname, char *path, char *hard_limit,
+ char *soft_limit, char **op_errstr)
{
- if (!existing_list) {
- if (!soft_limit)
- gf_asprintf (value, "%s:%s", path, hard_limit);
- else
- gf_asprintf (value, "%s:%s:%s", path, hard_limit,
- soft_limit);
- } else {
- if (!soft_limit)
- gf_asprintf (value, "%s,%s:%s", existing_list, path,
- hard_limit);
- else
- gf_asprintf (value, "%s,%s:%s:%s", existing_list, path,
- hard_limit, soft_limit);
- }
-}
+ int ret = -1;
+ xlator_t *this = NULL;
+ char abspath[PATH_MAX] = {0,};
+ glusterd_conf_t *priv = NULL;
+ double soft_lim = 0;
-int32_t
-glusterd_quota_limit_usage (glusterd_volinfo_t *volinfo, dict_t *dict,
- char **op_errstr)
-{
- int32_t ret = -1;
- char *path = NULL;
- char *limit = NULL;
- char *value = NULL;
- char *sl = NULL;
- char msg[5120] = {0,};
- char *quota_limits = NULL;
- char *new_list = NULL;
- xlator_t *this = NULL;
- glusterd_conf_t *priv = NULL;
- char *removed_path = NULL;
+ struct {
+ uint64_t hl;
+ uint64_t sl;
+ } existing_limit, new_limit;
this = THIS;
GF_ASSERT (this);
priv = this->private;
GF_ASSERT (priv);
- GF_VALIDATE_OR_GOTO (this->name, dict, out);
- GF_VALIDATE_OR_GOTO (this->name, volinfo, out);
- GF_VALIDATE_OR_GOTO (this->name, op_errstr, out);
-
- ret = glusterd_check_if_quota_trans_enabled (volinfo);
- if (ret == -1) {
- *op_errstr = gf_strdup ("Quota is disabled, please enable "
- "quota");
- goto out;
- }
+ snprintf (abspath, sizeof (abspath)-1, "/tmp/%s%s", volname, path);
- ret = glusterd_volinfo_get (volinfo, VKEY_FEATURES_LIMIT_USAGE,
- &quota_limits);
+ ret = gf_lstat_dir (abspath, NULL);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "failed to get quota limits");
+ gf_asprintf (op_errstr, "Failed to find the directory %s. "
+ "Reason : %s", abspath, strerror (errno));
goto out;
}
- ret = dict_get_str (dict, "path", &path);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Unable to fetch path");
- goto out;
- }
- ret = gf_canonicalize_path (path);
- if (ret)
- goto out;
-
- ret = dict_get_str (dict, "limit", &limit);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Unable to fetch limit");
- goto out;
- }
-
- if (quota_limits == NULL) {
- ; //do nothing and go past the else block
- } else {
- ret = _glusterd_quota_remove_limits (quota_limits, path, NULL,
- &new_list, &removed_path);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR, "Unable to remove "
- "limit");
+ if (!soft_limit) {
+ ret = sys_lgetxattr (abspath,
+ "trusted.glusterfs.quota.limit-set",
+ (void *)&existing_limit,
+ sizeof (existing_limit));
+ if((ret < 0) && (errno != ENOATTR)) {
+ gf_asprintf (op_errstr, "Failed to get the xattr "
+ "'trusted.glusterfs.quota.limit-set' from "
+ "%s. Reason : %s", abspath,
+ strerror (errno));
goto out;
}
+ existing_limit.hl = ntoh64 (existing_limit.hl);
+ existing_limit.sl = ntoh64 (existing_limit.sl);
+ new_limit.sl = existing_limit.sl;
- if (removed_path && (priv->op_version > GD_OP_VERSION_MIN)) {
- ret = gf_get_soft_limit (removed_path, &sl);
- if (ret == -1)
- goto out;
- }
+ } else {
+ ret = gf_string2percent (soft_limit, &soft_lim);
+ if (ret)
+ goto out;
+ new_limit.sl = (uint64_t) soft_lim;
}
- gd_quota_get_formatted_limit_list (&value, new_list, path, limit, sl);
- ret = dict_set_str (volinfo->dict, VKEY_FEATURES_LIMIT_USAGE,
- value);
+ new_limit.sl = hton64 (new_limit.sl);
+
+ ret = gf_string2bytesize (hard_limit, &new_limit.hl);
+ if (ret)
+ goto out;
+
+ new_limit.hl = hton64 (new_limit.hl);
+
+ ret = sys_lsetxattr (abspath, "trusted.glusterfs.quota.limit-set",
+ (char *)(void *)&new_limit, sizeof (new_limit), 0);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Unable to set quota limits");
+ gf_asprintf (op_errstr, "setxattr of "
+ "'trusted.glusterfs.quota.limit-set' failed on %s."
+ " Reason : %s", abspath, strerror (errno));
goto out;
}
-
- snprintf (msg, sizeof (msg), "hard limit set on %s", path);
- *op_errstr = gf_strdup (msg);
ret = 0;
-out:
- GF_FREE (sl);
- GF_FREE (removed_path);
- GF_FREE (new_list);
- if (ret && op_errstr && !*op_errstr)
- gf_asprintf (op_errstr, "Failed to set hard limit on path %s "
- "for volume %s", path, volinfo->volname);
+out:
return ret;
}
-int
-glusterd_quota_soft_limit (glusterd_volinfo_t *volinfo, dict_t *dict,
- char **op_errstr)
+int32_t
+glusterd_quota_limit_usage (glusterd_volinfo_t *volinfo, dict_t *dict,
+ char **op_errstr)
{
- int ret = 0;
- char *path = NULL;
- char *limit = NULL;
- char *quota_limits = NULL;
- char *new_list = NULL;
- char *removed_path = NULL;
- char msg[1024] = {0,};
- char *hl = NULL;
- char *value = NULL;
- xlator_t *this = NULL;
+ int32_t ret = -1;
+ char *path = NULL;
+ char *hard_limit = NULL;
+ char *soft_limit = NULL;
+ char msg[5120] = {0,};
+ xlator_t *this = NULL;
this = THIS;
GF_ASSERT (this);
- if (!volinfo || !dict || !op_errstr) {
- ret = -1;
- goto out;
- }
+ GF_VALIDATE_OR_GOTO (this->name, dict, out);
+ GF_VALIDATE_OR_GOTO (this->name, volinfo, out);
+ GF_VALIDATE_OR_GOTO (this->name, op_errstr, out);
ret = glusterd_check_if_quota_trans_enabled (volinfo);
if (ret == -1) {
@@ -745,77 +701,46 @@ glusterd_quota_soft_limit (glusterd_volinfo_t *volinfo, dict_t *dict,
goto out;
}
- ret = glusterd_volinfo_get (volinfo, VKEY_FEATURES_LIMIT_USAGE,
- &quota_limits);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "failed to get quota limits");
- goto out;
- }
-
ret = dict_get_str (dict, "path", &path);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Unable to fetch path");
goto out;
}
-
ret = gf_canonicalize_path (path);
if (ret)
goto out;
- ret = dict_get_str (dict, "limit", &limit);
+ ret = dict_get_str (dict, "hard-limit", &hard_limit);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Unable to fetch limit");
+ gf_log (this->name, GF_LOG_ERROR, "Unable to fetch hard limit");
goto out;
}
- if (quota_limits == NULL) {
- gf_asprintf (op_errstr, "Soft-limit cannot be set on path %s, "
- "without setting hard-limit on it first.", path);
- ret = -1;
- goto out;
- } else {
- ret = _glusterd_quota_remove_limits (quota_limits, path, NULL,
- &new_list, &removed_path);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to remove "
- "limit");
- goto out;
- }
-
- if (!removed_path) {
- gf_asprintf (op_errstr, "Soft-limit cannot be set on "
- "path %s without setting hard-limit on it "
- "first.", path);
- ret = -1;
+ if (dict_get (dict, "soft-limit")) {
+ ret = dict_get_str (dict, "soft-limit", &soft_limit);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Unable to fetch "
+ "soft limit");
goto out;
- } else {
- ret = gf_get_hard_limit (removed_path, &hl);
- if (ret)
- goto out;
}
- }
-
- gd_quota_get_formatted_limit_list (&value, new_list, path, hl, limit);
-
- ret = dict_set_str (volinfo->dict, VKEY_FEATURES_LIMIT_USAGE,
- value);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Unable to set quota limits");
- goto out;
- }
+ }
- snprintf (msg, sizeof (msg), "soft limit set on %s", path);
- *op_errstr = gf_strdup (msg);
- ret = 0;
+ if (is_origin_glusterd ()) {
+ ret = glusterd_set_quota_limit (volinfo->volname, path,
+ hard_limit, soft_limit,
+ op_errstr);
+ if (ret)
+ goto out;
+ }
+ snprintf (msg, sizeof (msg)-1, "Quota limit set on %s", path);
+ *op_errstr = gf_strdup (msg);
+ ret = 0;
out:
- GF_FREE (hl);
- GF_FREE (removed_path);
- GF_FREE (new_list);
if (ret && op_errstr && !*op_errstr)
- gf_asprintf (op_errstr, "Failed to set soft limit for path %s "
- "on volume %s", path, volinfo->volname);
+ gf_asprintf (op_errstr, "Failed to set hard limit on path %s "
+ "for volume %s", path, volinfo->volname);
return ret;
}
@@ -1061,13 +986,6 @@ glusterd_op_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
goto out;
}
- if (type == GF_QUOTA_OPTION_TYPE_SOFT_LIMIT) {
- ret = glusterd_quota_soft_limit (volinfo, dict, op_errstr);
- if (ret < 0)
- goto out;
- goto create_vol;
- }
-
if (type == GF_QUOTA_OPTION_TYPE_SOFT_TIMEOUT) {
ret = glusterd_set_quota_option (volinfo, dict,
"features.soft-timeout",