* the field names of md_config_t and get a key in normal form.
*/
std::string ConfFile::
-normalize_key_name(const std::string &key)
+normalize_key_name(std::string_view key)
{
- if (key.find_first_of(" \t\r\n\f\v\xa0") == string::npos) {
- return key;
+ std::string k{key};
+ if (k.find_first_of(" \t\r\n\f\v\xa0") == k.npos) {
+ return k;
}
-
- string k(key);
ConfFile::trim_whitespace(k, true);
std::replace(k.begin(), k.end(), ' ', '_');
return k;
const_section_iter_t sections_end() const;
static void trim_whitespace(std::string &str, bool strip_internal);
- static std::string normalize_key_name(const std::string &key);
+ static std::string normalize_key_name(std::string_view key);
friend std::ostream &operator<<(std::ostream &oss, const ConfFile &cf);
private:
}
}
-const Option *md_config_t::find_option(const string& name) const
+const Option *md_config_t::find_option(const std::string_view name) const
{
auto p = schema.find(name);
if (p != schema.end()) {
void md_config_t::set_val_default(ConfigValues& values,
const ConfigTracker& tracker,
- const string& name, const std::string& val)
+ const string_view name, const std::string& val)
{
const Option *o = find_option(name);
ceph_assert(o);
void md_config_t::set_val_or_die(ConfigValues& values,
const ConfigTracker& tracker,
- const std::string &key,
+ const std::string_view key,
const std::string &val)
{
std::stringstream err;
int md_config_t::set_val(ConfigValues& values,
const ConfigTracker& tracker,
- const std::string &key, const char *val,
+ const std::string_view key, const char *val,
std::stringstream *err_ss)
{
if (key.empty()) {
return -ENOENT;
}
-int md_config_t::rm_val(ConfigValues& values, const std::string& key)
+int md_config_t::rm_val(ConfigValues& values, const std::string_view key)
{
return _rm_val(values, key, CONF_OVERRIDE);
}
}
int md_config_t::get_val(const ConfigValues& values,
- const std::string &key, char **buf, int len) const
+ const std::string_view key, char **buf, int len) const
{
string k(ConfFile::normalize_key_name(key));
return _get_val_cstr(values, k, buf, len);
int md_config_t::get_val(
const ConfigValues& values,
- const std::string &key,
+ const std::string_view key,
std::string *val) const
{
return conf_stringify(get_val_generic(values, key), val);
Option::value_t md_config_t::get_val_generic(
const ConfigValues& values,
- const std::string &key) const
+ const std::string_view key) const
{
string k(ConfFile::normalize_key_name(key));
return _get_val(values, k);
Option::value_t md_config_t::_get_val(
const ConfigValues& values,
- const std::string &key,
+ const std::string_view key,
expand_stack_t *stack,
std::ostream *err) const
{
int md_config_t::_get_val_cstr(
const ConfigValues& values,
- const std::string &key, char **buf, int len) const
+ const std::string& key, char **buf, int len) const
{
if (key.empty())
return -EINVAL;
int md_config_t::get_val_from_conf_file(
const ConfigValues& values,
const std::vector <std::string> §ions,
- const std::string &key,
+ const std::string_view key,
std::string &out,
bool emeta) const
{
int md_config_t::_get_val_from_conf_file(
const std::vector <std::string> §ions,
- const std::string &key,
+ const std::string_view key,
std::string &out) const
{
- std::vector <std::string>::const_iterator s = sections.begin();
- std::vector <std::string>::const_iterator s_end = sections.end();
- for (; s != s_end; ++s) {
- int ret = cf.read(s->c_str(), key, out);
+ for (auto &s : sections) {
+ int ret = cf.read(s.c_str(), std::string{key}, out);
if (ret == 0) {
return 0;
} else if (ret != -ENOENT) {
}
int md_config_t::_rm_val(ConfigValues& values,
- const std::string& key,
+ const std::string_view key,
int level)
{
if (schema.count(key) == 0) {
return -EINVAL;
}
- auto ret = values.rm_val(key, level);
+ auto ret = values.rm_val(std::string{key}, level);
if (ret < 0) {
return ret;
}
// we only have a default value; exclude from diff
return;
}
- f->open_object_section(name.c_str());
+ f->open_object_section(std::string{name}.c_str());
const Option *o = find_option(name);
dump(f, CONF_DEFAULT, _get_val_default(*o));
for (auto& j : configs) {
void _clear_safe_to_start_threads(); // this is only used by the unit test
/// Look up an option in the schema
- const Option *find_option(const string& name) const;
+ const Option *find_option(const std::string_view name) const;
/// Set a default value
void set_val_default(ConfigValues& values,
const ConfigTracker& tracker,
- const std::string& key, const std::string &val);
+ const std::string_view key, const std::string &val);
/// Set a values from mon
int set_mon_vals(CephContext *cct,
// Set a configuration value, or crash
// Metavariables will be expanded.
void set_val_or_die(ConfigValues& values, const ConfigTracker& tracker,
- const std::string &key, const std::string &val);
+ const std::string_view key, const std::string &val);
// Set a configuration value.
// Metavariables will be expanded.
int set_val(ConfigValues& values, const ConfigTracker& tracker,
- const std::string &key, const char *val,
+ const std::string_view key, const char *val,
std::stringstream *err_ss=nullptr);
int set_val(ConfigValues& values, const ConfigTracker& tracker,
- const std::string &key, const string& s,
+ const std::string_view key, const std::string& s,
std::stringstream *err_ss=nullptr) {
return set_val(values, tracker, key, s.c_str(), err_ss);
}
/// clear override value
- int rm_val(ConfigValues& values, const std::string& key);
+ int rm_val(ConfigValues& values, const std::string_view key);
/// get encoded map<string,map<int32_t,string>> of entire config
void get_config_bl(const ConfigValues& values,
// Get a configuration value.
// No metavariables will be returned (they will have already been expanded)
- int get_val(const ConfigValues& values, const std::string &key, char **buf, int len) const;
- int get_val(const ConfigValues& values, const std::string &key, std::string *val) const;
- Option::value_t get_val_generic(const ConfigValues& values, const std::string &key) const;
- template<typename T> const T get_val(const ConfigValues& values, const std::string &key) const;
+ int get_val(const ConfigValues& values, const std::string_view key, char **buf, int len) const;
+ int get_val(const ConfigValues& values, const std::string_view key, std::string *val) const;
+ template<typename T> const T get_val(const ConfigValues& values, const std::string_view key) const;
template<typename T, typename Callback, typename...Args>
- auto with_val(const ConfigValues& values, const string& key,
+ auto with_val(const ConfigValues& values, const std::string_view key,
Callback&& cb, Args&&... args) const ->
std::result_of_t<Callback(const T&, Args...)> {
return std::forward<Callback>(cb)(
// Metavariables will be expanded if emeta is true.
int get_val_from_conf_file(const ConfigValues& values,
const std::vector <std::string> §ions,
- std::string const &key, std::string &out, bool emeta) const;
+ const std::string_view key, std::string &out, bool emeta) const;
/// dump all config values to a stream
void show_config(const ConfigValues& values, std::ostream& out) const;
void validate_schema();
void validate_default_settings();
+ Option::value_t get_val_generic(const ConfigValues& values,
+ const std::string_view key) const;
int _get_val_cstr(const ConfigValues& values,
- const std::string &key, char **buf, int len) const;
+ const std::string& key, char **buf, int len) const;
Option::value_t _get_val(const ConfigValues& values,
- const std::string &key,
+ const std::string_view key,
expand_stack_t *stack=0,
std::ostream *err=0) const;
Option::value_t _get_val(const ConfigValues& values,
Option::value_t _get_val_nometa(const ConfigValues& values,
const Option& o) const;
- int _rm_val(ConfigValues& values, const std::string& key, int level);
+ int _rm_val(ConfigValues& values, const std::string_view key, int level);
void _refresh(ConfigValues& values, const Option& opt);
std::vector <std::string> §ions) const;
int _get_val_from_conf_file(const std::vector <std::string> §ions,
- const std::string &key, std::string &out) const;
+ const std::string_view key, std::string &out) const;
int parse_option(ConfigValues& values,
const ConfigTracker& tracker,
template<typename T>
const T md_config_t::get_val(const ConfigValues& values,
- const std::string &key) const {
+ const std::string_view key) const {
return boost::get<T>(this->get_val_generic(values, key));
}
ConfigValues* operator->() noexcept {
return &values;
}
- int get_val(const std::string& key, char** buf, int len) const {
+ int get_val(const std::string_view key, char** buf, int len) const {
std::lock_guard l{lock};
return config.get_val(values, key, buf, len);
}
- int get_val(const std::string &key, std::string *val) const {
+ int get_val(const std::string_view key, std::string *val) const {
std::lock_guard l{lock};
return config.get_val(values, key, val);
}
template<typename T>
- const T get_val(const std::string& key) const {
+ const T get_val(const std::string_view key) const {
std::lock_guard l{lock};
return config.template get_val<T>(values, key);
}
template<typename T, typename Callback, typename...Args>
- auto with_val(const string& key, Callback&& cb, Args&&... args) const {
+ auto with_val(const std::string_view key, Callback&& cb, Args&&... args) const {
std::lock_guard l{lock};
return config.template with_val<T>(values, key,
std::forward<Callback>(cb),
const decltype(md_config_t::schema)& get_schema() const {
return config.schema;
}
- const Option* get_schema(const std::string& key) const {
+ const Option* get_schema(const std::string_view key) const {
auto found = config.schema.find(key);
if (found == config.schema.end()) {
return nullptr;
return config.get_all_sections(sections);
}
int get_val_from_conf_file(const std::vector<std::string>& sections,
- const std::string& key, std::string& out,
+ const std::string_view key, std::string& out,
bool emeta) const {
std::lock_guard l{lock};
return config.get_val_from_conf_file(values,
std::lock_guard l{lock};
config.config_options(f);
}
- int rm_val(const std::string& key) {
+ int rm_val(const std::string_view key) {
std::lock_guard l{lock};
return config.rm_val(values, key);
}
map_observer_changes(obs, key, rev_obs);
}, oss);
}
- int set_val(const std::string& key, const std::string& s,
+ int set_val(const std::string_view key, const std::string& s,
std::stringstream* err_ss=nullptr) {
std::lock_guard l{lock};
return config.set_val(values, obs_mgr, key, s, err_ss);
}
- void set_val_default(const std::string& key, const std::string& val) {
+ void set_val_default(const std::string_view key, const std::string& val) {
std::lock_guard l{lock};
config.set_val_default(values, obs_mgr, key, val);
}
- void set_val_or_die(const std::string& key, const std::string& val) {
+ void set_val_or_die(const std::string_view key, const std::string& val) {
std::lock_guard l{lock};
config.set_val_or_die(values, obs_mgr, key, val);
}
int init() {
CephContext *cct = (CephContext *)io_ctx.cct();
- for (auto &it : *this) {
- int r = cct->_conf.get_val(std::string(it.first), &it.second.first);
+ for (auto& [k,v] : *this) {
+ int r = cct->_conf.get_val(k, &v.first);
ceph_assert(r == 0);
- it.second.second = RBD_CONFIG_SOURCE_CONFIG;
+ v.second = RBD_CONFIG_SOURCE_CONFIG;
}
std::string last_key = ImageCtx::METADATA_CONF_PREFIX;
for (auto& [k,v] : opts) {
if (v.second == RBD_CONFIG_SOURCE_POOL) {
- r = config->set_val(std::string(k), v.first);
+ r = config->set_val(k, v.first);
if (r < 0) {
lderr(cct) << "failed to override pool config " << k << "="
<< v.first << ": " << cpp_strerror(r) << dendl;