]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
log: prohibit negative values for debug_* configurables. 20290/head
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 13 Feb 2018 15:09:55 +0000 (16:09 +0100)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 27 Feb 2018 10:38:48 +0000 (11:38 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/common/config.cc
src/log/SubsystemMap.h

index e16db0fe32269a5dd55aa551b0438ccdc74e21d5..6ab7fc47f5fc074b556f5ae033bdb7f3fb759df0 100644 (file)
@@ -325,8 +325,13 @@ int md_config_t::parse_config_files_impl(const std::list<std::string> &conf_file
       int log, gather;
       int r = sscanf(val.c_str(), "%d/%d", &log, &gather);
       if (r >= 1) {
-       if (r < 2)
+       if (r < 2) {
          gather = log;
+       }
+        if (log < 0 || gather < 0) {
+          cerr << "ERROR for " << as_option << "."
+              << "log nor gather levels cannot be negative!";
+        }
        //      cout << "config subsys " << subsys.get_name(o) << " log " << log << " gather " << gather << std::endl;
        subsys.set_log_level(o, log);
        subsys.set_gather_level(o, gather);
index 508263d1ba6e4ec723faefb4a8d768cd4429c360..94d5d382b55db9bc3c5df98c154a9fb319dc0c54 100644 (file)
@@ -71,14 +71,21 @@ public:
   bool should_gather() {
     static_assert(SubV < get_num(), "wrong subsystem ID");
     static_assert(LvlV >= -1 && LvlV <= 200);
-    return LvlV <= m_gather_levels[SubV];
+
+    if constexpr (LvlV <= 0) {
+      // handle the -1 and 0 levels entirely at compile-time.
+      // Such debugs are intended be gathered regardless even
+      // of the user configuration.
+      return true;
+    } else {
+      return LvlV <= static_cast<int>(m_gather_levels[SubV]);
+    }
   }
   bool should_gather(const unsigned sub, int level) {
     assert(sub < m_subsys.size());
-    return level <= m_gather_levels[sub];
+    return level <= static_cast<int>(m_gather_levels[sub]);
   }
 
-  // TODO(rzarzynski): verify the -1 case
   void set_log_level(unsigned subsys, uint8_t log)
   {
     assert(subsys < m_subsys.size());