]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common: remove ::validate definitions
authorJohn Spray <john.spray@redhat.com>
Wed, 5 Jul 2017 20:25:17 +0000 (16:25 -0400)
committerJohn Spray <john.spray@redhat.com>
Fri, 21 Jul 2017 10:27:24 +0000 (06:27 -0400)
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>
src/CMakeLists.txt
src/common/config_validators.cc [deleted file]
src/common/config_validators.h [deleted file]
src/common/legacy_config_opts.h
src/common/options.h

index 02687949c98865aa583fc6ce0284935ec20e7c1f..66f0c14e0b8cb09144d55a3592742f920bb79dfd 100644 (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
diff --git a/src/common/config_validators.cc b/src/common/config_validators.cc
deleted file mode 100644 (file)
index ebd3eb3..0000000
+++ /dev/null
@@ -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;
-}
-
diff --git a/src/common/config_validators.h b/src/common/config_validators.h
deleted file mode 100644 (file)
index f647369..0000000
+++ /dev/null
@@ -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
index 4f51a943588c0877cd64377ae7328523df242180..0bf4c203d6cd87e96def91feeedcdc74722e1679 100644 (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
 
index 92af1684ecf87af40fb46905c51895b90c94149e..ad1b29c113778880aaa94802e6a0300a62231a1b 100644 (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;