forked from vitalif/vitastor
Fix true/false parsing in json configs like no_recovery/no_rebalance
parent
3e1b03bb5c
commit
0cdc9292c8
|
@ -758,3 +758,21 @@ static std::string trim(const std::string & in)
|
||||||
int end = in.find_last_not_of(" \n\r\t");
|
int end = in.find_last_not_of(" \n\r\t");
|
||||||
return in.substr(begin, end+1-begin);
|
return in.substr(begin, end+1-begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool json_is_true(const json11::Json & val)
|
||||||
|
{
|
||||||
|
if (val.is_string())
|
||||||
|
return val == "true" || val == "yes" || val == "1";
|
||||||
|
return val.bool_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool json_is_false(const json11::Json & val)
|
||||||
|
{
|
||||||
|
if (val.is_string())
|
||||||
|
return val.string_value() == "false" || val.string_value() == "no" || val.string_value() == "0";
|
||||||
|
if (val.is_number())
|
||||||
|
return val.number_value() == 0;
|
||||||
|
if (val.is_bool())
|
||||||
|
return !val.bool_value();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -52,3 +52,6 @@ void http_close(http_co_t *co);
|
||||||
// Utils
|
// Utils
|
||||||
uint64_t stoull_full(const std::string & str, int base = 10);
|
uint64_t stoull_full(const std::string & str, int base = 10);
|
||||||
std::string strtolower(const std::string & in);
|
std::string strtolower(const std::string & in);
|
||||||
|
// FIXME: move to json11
|
||||||
|
bool json_is_true(const json11::Json & val);
|
||||||
|
bool json_is_false(const json11::Json & val);
|
||||||
|
|
|
@ -92,10 +92,7 @@ void nfs_proxy_t::run(json11::Json cfg)
|
||||||
if (bind_address == "")
|
if (bind_address == "")
|
||||||
bind_address = "0.0.0.0";
|
bind_address = "0.0.0.0";
|
||||||
default_pool = cfg["pool"].as_string();
|
default_pool = cfg["pool"].as_string();
|
||||||
portmap_enabled = cfg.object_items().find("portmap") == cfg.object_items().end() ||
|
portmap_enabled = !json_is_false(cfg["portmap"]);
|
||||||
cfg["portmap"].uint64_value() ||
|
|
||||||
cfg["portmap"].string_value() == "yes" ||
|
|
||||||
cfg["portmap"].string_value() == "true";
|
|
||||||
nfs_port = cfg["port"].uint64_value() & 0xffff;
|
nfs_port = cfg["port"].uint64_value() & 0xffff;
|
||||||
if (!nfs_port)
|
if (!nfs_port)
|
||||||
nfs_port = 2049;
|
nfs_port = 2049;
|
||||||
|
|
12
src/osd.cpp
12
src/osd.cpp
|
@ -54,7 +54,7 @@ osd_t::osd_t(const json11::Json & config, ring_loop_t *ringloop)
|
||||||
autosync_writes = max_autosync;
|
autosync_writes = max_autosync;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->config["osd_memlock"] == "true" || this->config["osd_memlock"] == "1" || this->config["osd_memlock"] == "yes")
|
if (json_is_true(this->config["osd_memlock"]))
|
||||||
{
|
{
|
||||||
// Lock all OSD memory if requested
|
// Lock all OSD memory if requested
|
||||||
if (mlockall(MCL_CURRENT|MCL_FUTURE
|
if (mlockall(MCL_CURRENT|MCL_FUTURE
|
||||||
|
@ -127,11 +127,11 @@ void osd_t::parse_config(const json11::Json & config)
|
||||||
etcd_report_interval = config["etcd_report_interval"].uint64_value();
|
etcd_report_interval = config["etcd_report_interval"].uint64_value();
|
||||||
if (etcd_report_interval <= 0)
|
if (etcd_report_interval <= 0)
|
||||||
etcd_report_interval = 5;
|
etcd_report_interval = 5;
|
||||||
readonly = config["readonly"] == "true" || config["readonly"] == "1" || config["readonly"] == "yes";
|
readonly = json_is_true(config["readonly"]);
|
||||||
run_primary = config["run_primary"] != "false" && config["run_primary"] != "0" && config["run_primary"] != "no";
|
run_primary = !json_is_false(config["run_primary"]);
|
||||||
no_rebalance = config["no_rebalance"] == "true" || config["no_rebalance"] == "1" || config["no_rebalance"] == "yes";
|
no_rebalance = json_is_true(config["no_rebalance"]);
|
||||||
no_recovery = config["no_recovery"] == "true" || config["no_recovery"] == "1" || config["no_recovery"] == "yes";
|
no_recovery = json_is_true(config["no_recovery"]);
|
||||||
allow_test_ops = config["allow_test_ops"] == "true" || config["allow_test_ops"] == "1" || config["allow_test_ops"] == "yes";
|
allow_test_ops = json_is_true(config["allow_test_ops"]);
|
||||||
if (config["immediate_commit"] == "all")
|
if (config["immediate_commit"] == "all")
|
||||||
immediate_commit = IMMEDIATE_ALL;
|
immediate_commit = IMMEDIATE_ALL;
|
||||||
else if (config["immediate_commit"] == "small")
|
else if (config["immediate_commit"] == "small")
|
||||||
|
|
Loading…
Reference in New Issue