summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorvmallika <vmallika@redhat.com>2015-04-01 16:56:00 +0530
committerVijay Bellur <vbellur@redhat.com>2015-04-10 11:21:48 +0000
commitd06e6bac4b5aa6d0fbf1660b92c4100de8f79e68 (patch)
tree106e47847a88aab96c284b8e3b6aa1c2feffe3e8 /libglusterfs
parentfcb55d54a62c8d4a2e8ce4596cd462c471f74dd3 (diff)
quota/cli: validate quota hard-limit option
Quota hard-limit is supported only upto: 9223372036854775807 (int 64) In CLI, it is allowed to set the value upto 16384PB (unsigned int 64), this is not a valid value as the xattrop for quota accounting and the quota enforcer operates on a signed int64 limit value. This patches fixes the problem in CLI and allows user to set the hard-limit value only from range 0 - 9223372036854775807 Change-Id: Ifce6e509e1832ef21d3278bacfa5bd71040c8cba BUG: 1206432 Signed-off-by: vmallika <vmallika@redhat.com> Reviewed-on: http://review.gluster.org/10022 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Kaushal M <kaushal@redhat.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/common-utils.c68
-rw-r--r--libglusterfs/src/common-utils.h1
2 files changed, 53 insertions, 16 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 6c5f65f6987..b57066d41da 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -1450,13 +1450,17 @@ err:
int
gf_string2bytesize_range (const char *str, uint64_t *n, uint64_t max)
{
- double value = 0.0;
- char *tail = NULL;
- int old_errno = 0;
- const char *s = NULL;
+ double value = 0.0;
+ uint64_t int_value = 0;
+ uint64_t unit = 0;
+ char *tail = NULL;
+ int old_errno = 0;
+ const char *s = NULL;
+ gf_boolean_t fraction = _gf_false;
if (str == NULL || n == NULL) {
- gf_log_callingfn (THIS->name, GF_LOG_WARNING, "argument invalid");
+ gf_log_callingfn (THIS->name, GF_LOG_WARNING,
+ "argument invalid");
errno = EINVAL;
return -1;
}
@@ -1469,9 +1473,16 @@ gf_string2bytesize_range (const char *str, uint64_t *n, uint64_t max)
break;
}
+ if (strrchr (str, '.'))
+ fraction = _gf_true;
+
old_errno = errno;
errno = 0;
- value = strtod (str, &tail);
+ if (fraction)
+ value = strtod (str, &tail);
+ else
+ int_value = strtoll (str, &tail, 10);
+
if (str == tail)
errno = EINVAL;
@@ -1484,25 +1495,39 @@ gf_string2bytesize_range (const char *str, uint64_t *n, uint64_t max)
if (tail[0] != '\0')
{
if (strcasecmp (tail, GF_UNIT_KB_STRING) == 0)
- value *= GF_UNIT_KB;
+ unit = GF_UNIT_KB;
else if (strcasecmp (tail, GF_UNIT_MB_STRING) == 0)
- value *= GF_UNIT_MB;
+ unit = GF_UNIT_MB;
else if (strcasecmp (tail, GF_UNIT_GB_STRING) == 0)
- value *= GF_UNIT_GB;
+ unit = GF_UNIT_GB;
else if (strcasecmp (tail, GF_UNIT_TB_STRING) == 0)
- value *= GF_UNIT_TB;
+ unit = GF_UNIT_TB;
else if (strcasecmp (tail, GF_UNIT_PB_STRING) == 0)
- value *= GF_UNIT_PB;
+ unit = GF_UNIT_PB;
else if (strcasecmp (tail, GF_UNIT_B_STRING) != 0)
return -1;
- }
- if ((max - value) < 0) {
- errno = ERANGE;
- return -1;
+ if (unit > 0) {
+ if (fraction)
+ value *= unit;
+ else
+ int_value *= unit;
+ }
}
- *n = (uint64_t) value;
+ if (fraction) {
+ if ((max - value) < 0) {
+ errno = ERANGE;
+ return -1;
+ }
+ *n = (uint64_t) value;
+ } else {
+ if ((max - int_value) < 0) {
+ errno = ERANGE;
+ return -1;
+ }
+ *n = int_value;
+ }
return 0;
}
@@ -1530,6 +1555,17 @@ gf_string2bytesize_uint64 (const char *str, uint64_t *n)
}
int
+gf_string2bytesize_int64 (const char *str, int64_t *n)
+{
+ uint64_t u64 = 0;
+ int ret = 0;
+
+ ret = gf_string2bytesize_range(str, &u64, INT64_MAX);
+ *n = (int64_t) u64;
+ return ret;
+}
+
+int
gf_string2percent_or_bytesize (const char *str, double *n,
gf_boolean_t *is_percent)
{
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index ec7e772e6cb..a93c6233a4e 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -604,6 +604,7 @@ int gf_string2uint64_base10 (const char *str, uint64_t *n);
int gf_string2bytesize (const char *str, uint64_t *n);
int gf_string2bytesize_size (const char *str, size_t *n);
int gf_string2bytesize_uint64 (const char *str, uint64_t *n);
+int gf_string2bytesize_int64 (const char *str, int64_t *n);
int gf_string2percent_or_bytesize (const char *str, double *n,
gf_boolean_t *is_percent);