]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
core: dout checks ceph_subsys_* in compile time if possible.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Sat, 3 Feb 2018 03:37:55 +0000 (04:37 +0100)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 27 Feb 2018 10:38:47 +0000 (11:38 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/common/dout.h
src/log/SubsystemMap.h
src/mds/MDBalancer.cc
src/mds/Mantle.cc

index 56e768d9afe7cc228a9d6c7d821f63fccc559abf..085773d74a96791d2a7ff7072175b4273eee9183 100644 (file)
@@ -43,14 +43,45 @@ public:
   virtual ~DoutPrefixProvider() {}
 };
 
+// helpers
+namespace ceph::dout {
+
+template<typename T>
+struct dynamic_marker_t {
+  T value;
+  operator T() const { return value; }
+};
+
+template<typename T>
+dynamic_marker_t<T> need_dynamic(T&& t) {
+  return dynamic_marker_t<T>{ std::forward<T>(t) };
+}
+
+template<typename T>
+struct is_dynamic : public std::false_type {};
+
+template<typename T>
+struct is_dynamic<dynamic_marker_t<T>> : public std::true_type {};
+
+} // ceph::dout
+
 // generic macros
 #define dout_prefix *_dout
 
 #define dout_impl(cct, sub, v)                                         \
   do {                                                                 \
-  if (cct->_conf->subsys.should_gather(sub, v)) {                      \
+  const bool should_gather = [&](const auto cctX) {                    \
+    if constexpr (ceph::dout::is_dynamic<decltype(sub)>::value) {      \
+      return cctX->_conf->subsys.should_gather(sub, v);                        \
+    } else {                                                           \
+      return cctX->_conf->subsys.template should_gather<sub>(v);       \
+    }                                                                  \
+  }(cct);                                                              \
+                                                                       \
+  if (should_gather) {                                                 \
     static size_t _log_exp_length = 80;                                \
-    ceph::logging::Entry *_dout_e = cct->_log->create_entry(v, sub, &_log_exp_length); \
+    ceph::logging::Entry *_dout_e =                                    \
+      cct->_log->create_entry(v, sub, &_log_exp_length);               \
     static_assert(std::is_convertible<decltype(&*cct),                         \
                                      CephContext* >::value,            \
                  "provided cct must be compatible with CephContext*"); \
@@ -61,7 +92,10 @@ public:
 #define ldout(cct, v)  dout_impl(cct, dout_subsys, v) dout_prefix
 #define lderr(cct) dout_impl(cct, ceph_subsys_, -1) dout_prefix
 
-#define ldpp_dout(dpp, v) if (dpp) dout_impl(dpp->get_cct(), dpp->get_subsys(), v) (*_dout << dpp->gen_prefix())
+#define ldpp_dout(dpp, v)                                              \
+  if (dpp)                                                             \
+    dout_impl(dpp->get_cct(), ceph::dout::need_dynamic(dpp->get_subsys()), v)                          \
+    (*_dout << dpp->gen_prefix())
 
 #define lgeneric_subdout(cct, sub, v) dout_impl(cct, ceph_subsys_##sub, v) *_dout
 #define lgeneric_dout(cct, v) dout_impl(cct, ceph_subsys_, v) *_dout
index 789cff7ade4f5538b5d875ea02f030f0bbe866cf..db03760b84aef082e55a63e1bc2de24a26e0dc5f 100644 (file)
@@ -7,6 +7,8 @@
 #include <string>
 #include <vector>
 
+#include "common/subsys_types.h"
+
 #include "include/assert.h"
 
 namespace ceph {
@@ -58,7 +60,13 @@ public:
     return m_subsys[subsys].name;
   }
 
-  bool should_gather(unsigned sub, int level) {
+  template <unsigned SubV>
+  bool should_gather(int level) {
+    static_assert(SubV < ceph_subsys_get_num(), "wrong subsystem ID");
+    return level <= m_subsys[SubV].gather_level ||
+      level <= m_subsys[SubV].log_level;
+  }
+  bool should_gather(const unsigned sub, int level) {
     assert(sub < m_subsys.size());
     return level <= m_subsys[sub].gather_level ||
       level <= m_subsys[sub].log_level;
index 21667874ed71b279afbd607dbd06ef8fb49dfcc2..dc0b784cb931bed91ef27121cf8fa9f8cd9182bb 100644 (file)
@@ -51,7 +51,7 @@ using std::chrono::duration_cast;
     if ((dout_context)->_conf->subsys.should_gather(ceph_subsys_mds_balancer, lvl)) {\
       subsys = ceph_subsys_mds_balancer;\
     }\
-    dout_impl(dout_context, subsys, lvl) dout_prefix
+    dout_impl(dout_context, ceph::dout::need_dynamic(subsys), lvl) dout_prefix
 #undef dendl
 #define dendl dendl_impl; } while (0)
 
index 1be12108515ffa0691ee8a33daf8f653762b0aeb..24118ca3dadbd58bac1cf0ad2c3904f97d752828 100644 (file)
@@ -31,7 +31,7 @@
     if ((dout_context)->_conf->subsys.should_gather(ceph_subsys_mds_balancer, lvl)) {\
       subsys = ceph_subsys_mds_balancer;\
     }\
-    dout_impl(dout_context, subsys, lvl) dout_prefix
+    dout_impl(dout_context, ceph::dout::need_dynamic(subsys), lvl) dout_prefix
 
 #define mantle_dendl dendl; } while (0)