common: remove ::validate definitions

These will be replaced by validate methods
on Option subclasses that need them.  The code
that was in these files moved to options.[h|cc]

Signed-off-by: John Spray <john.spray@redhat.com>
This commit is contained in:
John Spray 2017-07-05 16:25:17 -04:00
parent f1ac8dc7a4
commit 73086f1e4c
5 changed files with 102 additions and 116 deletions

View File

@ -510,7 +510,6 @@ set(libcommon_files
common/ceph_frag.cc
common/options.cc
common/config.cc
common/config_validators.cc
common/utf8.c
common/mime.c
common/strtol.cc

View File

@ -1,88 +0,0 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include "common/config_validators.h"
#include "include/stringify.h"
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/regex.hpp>
int validate(md_config_t::option_rbd_default_pool_t *,
std::string *value, std::string *error_message) {
boost::regex pattern("^[^@/]+$");
if (!boost::regex_match (*value, pattern)) {
*value = "rbd";
*error_message = "invalid RBD default pool, resetting to 'rbd'";
}
return 0;
}
int validate(md_config_t::option_rbd_default_data_pool_t *,
std::string *value, std::string *error_message) {
boost::regex pattern("^[^@/]*$");
if (!boost::regex_match (*value, pattern)) {
*value = "";
*error_message = "ignoring invalid RBD data pool";
}
return 0;
}
int validate(md_config_t::option_rbd_default_features_t *,
std::string *value, std::string *error_message) {
static const std::map<std::string, uint64_t> FEATURE_MAP = {
{RBD_FEATURE_NAME_LAYERING, RBD_FEATURE_LAYERING},
{RBD_FEATURE_NAME_STRIPINGV2, RBD_FEATURE_STRIPINGV2},
{RBD_FEATURE_NAME_EXCLUSIVE_LOCK, RBD_FEATURE_EXCLUSIVE_LOCK},
{RBD_FEATURE_NAME_OBJECT_MAP, RBD_FEATURE_OBJECT_MAP},
{RBD_FEATURE_NAME_FAST_DIFF, RBD_FEATURE_FAST_DIFF},
{RBD_FEATURE_NAME_DEEP_FLATTEN, RBD_FEATURE_DEEP_FLATTEN},
{RBD_FEATURE_NAME_JOURNALING, RBD_FEATURE_JOURNALING},
{RBD_FEATURE_NAME_DATA_POOL, RBD_FEATURE_DATA_POOL},
};
static_assert((RBD_FEATURE_DATA_POOL << 1) > RBD_FEATURES_ALL,
"new RBD feature added");
// convert user-friendly comma delimited feature name list to a bitmask
// that is used by the librbd API
uint64_t features = 0;
error_message->clear();
try {
features = boost::lexical_cast<decltype(features)>(*value);
uint64_t unsupported_features = (features & ~RBD_FEATURES_ALL);
if (unsupported_features != 0ull) {
features &= RBD_FEATURES_ALL;
std::stringstream ss;
ss << "ignoring unknown feature mask 0x"
<< std::hex << unsupported_features;
*error_message = ss.str();
}
} catch (const boost::bad_lexical_cast& ) {
int r = 0;
std::vector<std::string> feature_names;
boost::split(feature_names, *value, boost::is_any_of(","));
for (auto feature_name: feature_names) {
boost::trim(feature_name);
auto feature_it = FEATURE_MAP.find(feature_name);
if (feature_it != FEATURE_MAP.end()) {
features += feature_it->second;
} else {
if (!error_message->empty()) {
*error_message += ", ";
}
*error_message += "ignoring unknown feature " + feature_name;
r = -EINVAL;
}
}
if (features == 0 && r == -EINVAL) {
features = RBD_FEATURES_DEFAULT;
}
}
*value = stringify(features);
return 0;
}

View File

@ -1,21 +0,0 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef CEPH_CONFIG_VALIDATORS
#define CEPH_CONFIG_VALIDATORS
#include "config.h"
#include <string>
/**
* Global config value validators for the Ceph project
*/
int validate(md_config_t::option_rbd_default_pool_t *type,
std::string *value, std::string *error_message);
int validate(md_config_t::option_rbd_default_data_pool_t *type,
std::string *value, std::string *error_message);
int validate(md_config_t::option_rbd_default_features_t *type,
std::string *value, std::string *error_message);
#endif // CEPH_CONFIG_VALIDATORS

View File

@ -1421,7 +1421,6 @@ OPTION(rbd_mirroring_resync_after_disconnect, OPT_BOOL, false) // automatically
OPTION(rbd_mirroring_replay_delay, OPT_INT, 0) // time-delay in seconds for rbd-mirror asynchronous replication
OPTION(rbd_default_pool, OPT_STR, "rbd") // default pool for storing images
OPTION_VALIDATOR(rbd_default_pool)
/*
* The following options change the behavior for librbd's image creation methods that
@ -1444,7 +1443,6 @@ OPTION(rbd_default_order, OPT_INT, 22)
OPTION(rbd_default_stripe_count, OPT_U64, 0) // changing requires stripingv2 feature
OPTION(rbd_default_stripe_unit, OPT_U64, 0) // changing to non-object size requires stripingv2 feature
OPTION(rbd_default_data_pool, OPT_STR, "") // optional default pool for storing image data blocks
OPTION_VALIDATOR(rbd_default_data_pool)
/**
* RBD features are only applicable for v2 images. This setting accepts either
@ -1462,7 +1460,6 @@ OPTION_VALIDATOR(rbd_default_data_pool)
* +128 -> data-pool
*/
SAFE_OPTION(rbd_default_features, OPT_STR, "layering,exclusive-lock,object-map,fast-diff,deep-flatten")
OPTION_VALIDATOR(rbd_default_features)
OPTION(rbd_default_map_options, OPT_STR, "") // default rbd map -o / --options

View File

@ -42,9 +42,9 @@ struct Option {
std::string,
int64_t,
double,
bool//,
//entity_addr_t,
/*uuid_d*/>;
bool/*,
entity_addr_t,
uuid_d*/>;
const std::string name;
const type_t type;
const level_t level;
@ -136,5 +136,104 @@ struct Option {
}
};
// TODO: reinstate corner case logic for these RBD settings
#if 0
#include "include/stringify.h"
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/regex.hpp>
class RbdDefaultPool : public Option
{
int validate(md_config_t::option_rbd_default_pool_t *,
std::string *value, std::string *error_message) {
boost::regex pattern("^[^@/]+$");
if (!boost::regex_match (*value, pattern)) {
*value = "rbd";
*error_message = "invalid RBD default pool, resetting to 'rbd'";
}
return 0;
}
}
class RbdDefaultDataPool : public Option
{
int validate(md_config_t::option_rbd_default_data_pool_t *,
std::string *value, std::string *error_message) {
boost::regex pattern("^[^@/]*$");
if (!boost::regex_match (*value, pattern)) {
*value = "";
*error_message = "ignoring invalid RBD data pool";
}
return 0;
}
}
class RbdDefaultFeatures : public Option
{
int validate(md_config_t::option_rbd_default_features_t *,
std::string *value, std::string *error_message) {
static const std::map<std::string, uint64_t> FEATURE_MAP = {
{RBD_FEATURE_NAME_LAYERING, RBD_FEATURE_LAYERING},
{RBD_FEATURE_NAME_STRIPINGV2, RBD_FEATURE_STRIPINGV2},
{RBD_FEATURE_NAME_EXCLUSIVE_LOCK, RBD_FEATURE_EXCLUSIVE_LOCK},
{RBD_FEATURE_NAME_OBJECT_MAP, RBD_FEATURE_OBJECT_MAP},
{RBD_FEATURE_NAME_FAST_DIFF, RBD_FEATURE_FAST_DIFF},
{RBD_FEATURE_NAME_DEEP_FLATTEN, RBD_FEATURE_DEEP_FLATTEN},
{RBD_FEATURE_NAME_JOURNALING, RBD_FEATURE_JOURNALING},
{RBD_FEATURE_NAME_DATA_POOL, RBD_FEATURE_DATA_POOL},
};
static_assert((RBD_FEATURE_DATA_POOL << 1) > RBD_FEATURES_ALL,
"new RBD feature added");
// convert user-friendly comma delimited feature name list to a bitmask
// that is used by the librbd API
uint64_t features = 0;
error_message->clear();
try {
features = boost::lexical_cast<decltype(features)>(*value);
uint64_t unsupported_features = (features & ~RBD_FEATURES_ALL);
if (unsupported_features != 0ull) {
features &= RBD_FEATURES_ALL;
std::stringstream ss;
ss << "ignoring unknown feature mask 0x"
<< std::hex << unsupported_features;
*error_message = ss.str();
}
} catch (const boost::bad_lexical_cast& ) {
int r = 0;
std::vector<std::string> feature_names;
boost::split(feature_names, *value, boost::is_any_of(","));
for (auto feature_name: feature_names) {
boost::trim(feature_name);
auto feature_it = FEATURE_MAP.find(feature_name);
if (feature_it != FEATURE_MAP.end()) {
features += feature_it->second;
} else {
if (!error_message->empty()) {
*error_message += ", ";
}
*error_message += "ignoring unknown feature " + feature_name;
r = -EINVAL;
}
}
if (features == 0 && r == -EINVAL) {
features = RBD_FEATURES_DEFAULT;
}
}
*value = stringify(features);
return 0;
}
}
#endif
extern const std::vector<Option> ceph_options;