libglusterfs: Implement float percentage

Change-Id: Ia7ea63471f0bbd74686873f5f6f183475880f1a0
BUG: 839595
Signed-off-by: Pranith Kumar K <pranithk@gluster.com>
Reviewed-on: http://review.gluster.org/4162
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
This commit is contained in:
Pranith Kumar K 2012-11-06 12:19:47 +05:30 committed by Vijay Bellur
parent 6dee0e3d99
commit 76a4afec6e
8 changed files with 48 additions and 45 deletions

View File

@ -676,11 +676,10 @@ gf_string2time (const char *str, uint32_t *n)
return 0;
}
int
gf_string2percent (const char *str, uint32_t *n)
gf_string2percent (const char *str, double *n)
{
unsigned long value = 0;
double value = 0;
char *tail = NULL;
int old_errno = 0;
const char *s = NULL;
@ -701,7 +700,7 @@ gf_string2percent (const char *str, uint32_t *n)
old_errno = errno;
errno = 0;
value = strtol (str, &tail, 0);
value = strtod (str, &tail);
if (errno == ERANGE || errno == EINVAL)
return -1;

View File

@ -509,7 +509,7 @@ int gf_string2percent_or_bytesize (const char *str, uint64_t *n,
gf_boolean_t *is_percent);
int gf_string2boolean (const char *str, gf_boolean_t *b);
int gf_string2percent (const char *str, uint32_t *n);
int gf_string2percent (const char *str, double *n);
int gf_string2time (const char *str, uint32_t *n);
int gf_lockfd (int fd);

View File

@ -53,7 +53,6 @@ out:
return ret;
}
static int
xlator_option_validate_int (xlator_t *xl, const char *key, const char *value,
volume_option_t *opt, char **op_errstr)
@ -298,10 +297,9 @@ static int
xlator_option_validate_percent (xlator_t *xl, const char *key, const char *value,
volume_option_t *opt, char **op_errstr)
{
int ret = -1;
char errstr[256];
uint32_t percent = 0;
double percent = 0;
int ret = -1;
char errstr[256];
/* Check if the value is valid percentage */
if (gf_string2percent (value, &percent) != 0) {
@ -312,9 +310,9 @@ xlator_option_validate_percent (xlator_t *xl, const char *key, const char *value
goto out;
}
if ((percent < 0) || (percent > 100)) {
if ((percent < 0.0) || (percent > 100.0)) {
snprintf (errstr, 256,
"'%d' in 'option %s %s' is out of range [0 - 100]",
"'%lf' in 'option %s %s' is out of range [0 - 100]",
percent, key, value);
gf_log (xl->name, GF_LOG_ERROR, "%s", errstr);
goto out;
@ -1043,19 +1041,24 @@ xl_by_name (char *in, xlator_t **out)
static int
pc_or_size (char *in, uint64_t *out)
pc_or_size (char *in, double *out)
{
uint32_t pc = 0;
double pc = 0;
int ret = 0;
uint64_t size = 0;
if (gf_string2percent (in, &pc) == 0) {
if (pc > 100) {
ret = gf_string2bytesize (in, out);
if (pc > 100.0) {
ret = gf_string2bytesize (in, &size);
if (!ret)
*out = size;
} else {
*out = pc;
}
} else {
ret = gf_string2bytesize (in, out);
ret = gf_string2bytesize (in, &size);
if (!ret)
*out = size;
}
return ret;
}
@ -1067,8 +1070,8 @@ DEFINE_INIT_OPT(int64_t, int64, gf_string2int64);
DEFINE_INIT_OPT(uint32_t, uint32, gf_string2uint32);
DEFINE_INIT_OPT(int32_t, int32, gf_string2int32);
DEFINE_INIT_OPT(uint64_t, size, gf_string2bytesize);
DEFINE_INIT_OPT(uint32_t, percent, gf_string2percent);
DEFINE_INIT_OPT(uint64_t, percent_or_size, pc_or_size);
DEFINE_INIT_OPT(double, percent, gf_string2percent);
DEFINE_INIT_OPT(double, percent_or_size, pc_or_size);
DEFINE_INIT_OPT(gf_boolean_t, bool, gf_string2boolean);
DEFINE_INIT_OPT(xlator_t *, xlator, xl_by_name);
DEFINE_INIT_OPT(char *, path, pass);
@ -1082,8 +1085,8 @@ DEFINE_RECONF_OPT(int64_t, int64, gf_string2int64);
DEFINE_RECONF_OPT(uint32_t, uint32, gf_string2uint32);
DEFINE_RECONF_OPT(int32_t, int32, gf_string2int32);
DEFINE_RECONF_OPT(uint64_t, size, gf_string2bytesize);
DEFINE_RECONF_OPT(uint32_t, percent, gf_string2percent);
DEFINE_RECONF_OPT(uint64_t, percent_or_size, pc_or_size);
DEFINE_RECONF_OPT(double, percent, gf_string2percent);
DEFINE_RECONF_OPT(double, percent_or_size, pc_or_size);
DEFINE_RECONF_OPT(gf_boolean_t, bool, gf_string2boolean);
DEFINE_RECONF_OPT(xlator_t *, xlator, xl_by_name);
DEFINE_RECONF_OPT(char *, path, pass);

View File

@ -105,8 +105,8 @@ DECLARE_INIT_OPT(int64_t, int64);
DECLARE_INIT_OPT(uint32_t, uint32);
DECLARE_INIT_OPT(int32_t, int32);
DECLARE_INIT_OPT(uint64_t, size);
DECLARE_INIT_OPT(uint32_t, percent);
DECLARE_INIT_OPT(uint64_t, percent_or_size);
DECLARE_INIT_OPT(double, percent);
DECLARE_INIT_OPT(double, percent_or_size);
DECLARE_INIT_OPT(gf_boolean_t, bool);
DECLARE_INIT_OPT(xlator_t *, xlator);
DECLARE_INIT_OPT(char *, path);
@ -185,8 +185,8 @@ DECLARE_RECONF_OPT(int64_t, int64);
DECLARE_RECONF_OPT(uint32_t, uint32);
DECLARE_RECONF_OPT(int32_t, int32);
DECLARE_RECONF_OPT(uint64_t, size);
DECLARE_RECONF_OPT(uint32_t, percent);
DECLARE_RECONF_OPT(uint64_t, percent_or_size);
DECLARE_RECONF_OPT(double, percent);
DECLARE_RECONF_OPT(double, percent_or_size);
DECLARE_RECONF_OPT(gf_boolean_t, bool);
DECLARE_RECONF_OPT(xlator_t *, xlator);
DECLARE_RECONF_OPT(char *, path);

View File

@ -243,8 +243,8 @@ struct dht_conf {
gf_boolean_t search_unhashed;
int gen;
dht_du_t *du_stats;
uint64_t min_free_disk;
uint32_t min_free_inodes;
double min_free_disk;
double min_free_inodes;
char disk_unit;
int32_t refresh_interval;
gf_boolean_t unhashed_sticky_bit;

View File

@ -125,8 +125,8 @@ dht_priv_dump (xlator_t *this)
gf_proc_dump_write("search_unhashed", "%d", conf->search_unhashed);
gf_proc_dump_write("gen", "%d", conf->gen);
gf_proc_dump_write("min_free_disk", "%lu", conf->min_free_disk);
gf_proc_dump_write("min_free_inodes", "%lu", conf->min_free_inodes);
gf_proc_dump_write("min_free_disk", "%lf", conf->min_free_disk);
gf_proc_dump_write("min_free_inodes", "%lf", conf->min_free_inodes);
gf_proc_dump_write("disk_unit", "%c", conf->disk_unit);
gf_proc_dump_write("refresh_interval", "%d", conf->refresh_interval);
gf_proc_dump_write("unhashed_sticky_bit", "%d", conf->unhashed_sticky_bit);
@ -326,7 +326,7 @@ reconfigure (xlator_t *this, dict_t *options)
percent_or_size, out);
/* option can be any one of percent or bytes */
conf->disk_unit = 0;
if (conf->min_free_disk < 100)
if (conf->min_free_disk < 100.0)
conf->disk_unit = 'p';
GF_OPTION_RECONF ("min-free-inodes", conf->min_free_inodes, options,

View File

@ -502,7 +502,8 @@ init (xlator_t *this)
int ret = -1;
int i = 0;
char my_hostname[256];
uint32_t temp_free_disk = 0;
double temp_free_disk = 0;
uint64_t size = 0;
if (!this->children) {
gf_log (this->name, GF_LOG_CRITICAL,
@ -587,16 +588,16 @@ init (xlator_t *this)
if (gf_string2percent (temp_str,
&temp_free_disk) == 0) {
if (temp_free_disk > 100) {
gf_string2bytesize (temp_str,
&conf->min_free_disk);
gf_string2bytesize (temp_str, &size);
conf->min_free_disk = size;
conf->disk_unit = 'b';
} else {
conf->min_free_disk = (uint64_t)temp_free_disk;
conf->min_free_disk = temp_free_disk;
conf->disk_unit = 'p';
}
} else {
gf_string2bytesize (temp_str,
&conf->min_free_disk);
gf_string2bytesize (temp_str, &size);
conf->min_free_disk = size;
conf->disk_unit = 'b';
}
}

View File

@ -842,7 +842,8 @@ init (xlator_t *this)
char *temp_str = NULL;
int ret = -1;
int i = 0;
uint32_t temp_free_disk = 0;
double temp_free_disk = 0;
uint64_t size = 0;
if (!this->children) {
gf_log (this->name, GF_LOG_CRITICAL,
@ -875,24 +876,23 @@ init (xlator_t *this)
gf_string2boolean (temp_str, &conf->unhashed_sticky_bit);
}
conf->min_free_disk = 10;
conf->min_free_disk = 10.0;
conf->disk_unit = 'p';
if (dict_get_str (this->options, "min-free-disk",
&temp_str) == 0) {
if (gf_string2percent (temp_str,
&temp_free_disk) == 0) {
if (gf_string2percent (temp_str, &temp_free_disk) == 0) {
if (temp_free_disk > 100) {
gf_string2bytesize (temp_str,
&conf->min_free_disk);
gf_string2bytesize (temp_str, &size);
conf->min_free_disk = size;
conf->disk_unit = 'b';
} else {
conf->min_free_disk = (uint64_t)temp_free_disk;
conf->min_free_disk = temp_free_disk;
conf->disk_unit = 'p';
}
} else {
gf_string2bytesize (temp_str,
&conf->min_free_disk);
gf_string2bytesize (temp_str, &size);
conf->min_free_disk = size;
conf->disk_unit = 'b';
}
}