From b0f94c628b758608669f8b47d4de5872d6197a60 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Sat, 3 Feb 2018 04:37:55 +0100 Subject: [PATCH] core: dout checks ceph_subsys_* in compile time if possible. Signed-off-by: Radoslaw Zarzynski --- src/common/dout.h | 40 +++++++++++++++++++++++++++++++++++++--- src/log/SubsystemMap.h | 10 +++++++++- src/mds/MDBalancer.cc | 2 +- src/mds/Mantle.cc | 2 +- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/common/dout.h b/src/common/dout.h index 56e768d9afe..085773d74a9 100644 --- a/src/common/dout.h +++ b/src/common/dout.h @@ -43,14 +43,45 @@ public: virtual ~DoutPrefixProvider() {} }; +// helpers +namespace ceph::dout { + +template +struct dynamic_marker_t { + T value; + operator T() const { return value; } +}; + +template +dynamic_marker_t need_dynamic(T&& t) { + return dynamic_marker_t{ std::forward(t) }; +} + +template +struct is_dynamic : public std::false_type {}; + +template +struct is_dynamic> : 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::value) { \ + return cctX->_conf->subsys.should_gather(sub, v); \ + } else { \ + return cctX->_conf->subsys.template should_gather(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::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 diff --git a/src/log/SubsystemMap.h b/src/log/SubsystemMap.h index 789cff7ade4..db03760b84a 100644 --- a/src/log/SubsystemMap.h +++ b/src/log/SubsystemMap.h @@ -7,6 +7,8 @@ #include #include +#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 + 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; diff --git a/src/mds/MDBalancer.cc b/src/mds/MDBalancer.cc index 21667874ed7..dc0b784cb93 100644 --- a/src/mds/MDBalancer.cc +++ b/src/mds/MDBalancer.cc @@ -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) diff --git a/src/mds/Mantle.cc b/src/mds/Mantle.cc index 1be12108515..24118ca3dad 100644 --- a/src/mds/Mantle.cc +++ b/src/mds/Mantle.cc @@ -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) -- 2.39.5