From 5368e7e0e5a0900961b0ad0652b4e21a91c83d13 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 3 Sep 2018 17:15:16 +0800 Subject: [PATCH 1/9] common: specialize for WITH_SEASTAR * define a specialized version CephContext for WITH_SEASTAR. this CephContext exposes the minimal set of interface for ceph::mon::Client * do not include unused stuff defined in common_init.cc, as it introduces more compile-time dependencies we need to prepare to appease the compiler. * implement g_conf() for WITH_SEASTAR, so it returns ceph::common::local_conf() if WITH_SEASTAR is defined. Signed-off-by: Kefu Chai --- src/common/ceph_context.cc | 35 +++++++++++++++++++++++++++++++++++ src/common/ceph_context.h | 31 ++++++++++++++++++++++++++++++- src/common/common_init.cc | 6 ++++++ src/common/common_init.h | 7 ++++++- src/global/global_context.cc | 4 ++++ 5 files changed, 81 insertions(+), 2 deletions(-) diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index e311eae3880..41d1f47bf11 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -44,6 +44,40 @@ using ceph::bufferlist; using ceph::HeartbeatMap; +#ifdef WITH_SEASTAR +CephContext::CephContext() + : _conf{ceph::common::local_conf()}, + _crypto_random{std::make_unique()} +{} + +// define the dtor in .cc as CryptoRandom is an incomplete type in the header +CephContext::~CephContext() +{} + +CryptoRandom* CephContext::random() const +{ + return _crypto_random.get(); +} + +CephContext* CephContext::get() +{ + ++nref; + return this; +} + +void CephContext::put() +{ + if (--nref == 0) { + delete this; + } +} + +PerfCountersCollection* CephContext::get_perfcounters_collection() +{ + throw std::runtime_error("not yet implemented"); +} + +#else // WITH_SEASTAR namespace { class LockdepObs : public md_config_obs_t { @@ -848,3 +882,4 @@ void CephContext::notify_post_fork() for (auto &&t : _fork_watchers) t->handle_post_fork(); } +#endif // WITH_SEASTAR diff --git a/src/common/ceph_context.h b/src/common/ceph_context.h index 88318bce3f8..e2e91bb4e18 100644 --- a/src/common/ceph_context.h +++ b/src/common/ceph_context.h @@ -29,9 +29,13 @@ #include "common/cmdparse.h" #include "common/code_environment.h" +#ifdef WITH_SEASTAR +#include "crimson/common/config_proxy.h" +#else #include "common/config_proxy.h" - #include "include/spinlock.h" +#endif + #include "crush/CrushLocation.h" @@ -52,6 +56,28 @@ namespace ceph { } } +#ifdef WITH_SEASTAR +class CephContext { +public: + CephContext(); + CephContext(uint32_t, + code_environment_t=CODE_ENVIRONMENT_UTILITY, + int = 0) + : CephContext{} + {} + ~CephContext(); + + CryptoRandom* random() const; + PerfCountersCollection* get_perfcounters_collection(); + ceph::common::ConfigProxy& _conf; + + CephContext* get(); + void put(); +private: + std::unique_ptr _crypto_random; + unsigned nref; +}; +#else /* A CephContext represents the context held by a single library user. * There can be multiple CephContexts in the same process. * @@ -244,6 +270,8 @@ private: friend class CephContextServiceThread; CephContextServiceThread *_service_thread; + using md_config_obs_t = ceph::md_config_obs_impl; + md_config_obs_t *_log_obs; /* The admin socket associated with this context */ @@ -310,5 +338,6 @@ private: friend class CephContextObs; }; +#endif // WITH_SEASTAR #endif diff --git a/src/common/common_init.cc b/src/common/common_init.cc index 30dd2b28d83..5625fd58489 100644 --- a/src/common/common_init.cc +++ b/src/common/common_init.cc @@ -27,6 +27,7 @@ #define _STR(x) #x #define STRINGIFY(x) _STR(x) +#ifndef WITH_SEASTAR CephContext *common_preinit(const CephInitParameters &iparams, enum code_environment_t code_env, int flags) { @@ -71,6 +72,7 @@ CephContext *common_preinit(const CephInitParameters &iparams, return cct; } +#endif // #ifndef WITH_SEASTAR void complain_about_parse_errors(CephContext *cct, std::deque *parse_errors) @@ -93,6 +95,8 @@ void complain_about_parse_errors(CephContext *cct, } } +#ifndef WITH_SEASTAR + /* Please be sure that this can safely be called multiple times by the * same application. */ void common_init_finish(CephContext *cct) @@ -133,3 +137,5 @@ void common_init_finish(CephContext *cct) } } } + +#endif // #ifndef WITH_SEASTAR diff --git a/src/common/common_init.h b/src/common/common_init.h index 1a4207b0ec7..133533bb27d 100644 --- a/src/common/common_init.h +++ b/src/common/common_init.h @@ -20,7 +20,6 @@ #include "common/code_environment.h" class CephContext; -class CephInitParameters; enum common_init_flags_t { // Set up defaults that make sense for an unprivileged daemon @@ -42,6 +41,9 @@ enum common_init_flags_t { CINIT_FLAG_NO_MON_CONFIG = 0x20, }; +#ifndef WITH_SEASTAR +class CephInitParameters; + /* * NOTE: If you are writing a Ceph daemon, ignore this function and call * global_init instead. It will call common_preinit for you. @@ -61,11 +63,13 @@ enum common_init_flags_t { */ CephContext *common_preinit(const CephInitParameters &iparams, enum code_environment_t code_env, int flags); +#endif // #ifndef WITH_SEASTAR /* Print out some parse errors. */ void complain_about_parse_errors(CephContext *cct, std::deque *parse_errors); +#ifndef WITH_SEASTAR /* This function is called after you have done your last * fork. When you make this call, the system will initialize everything that * cannot be initialized before a fork. @@ -79,5 +83,6 @@ void complain_about_parse_errors(CephContext *cct, * the Ceph libraries would be destroyed by a fork(). */ void common_init_finish(CephContext *cct); +#endif // #ifndef WITH_SEASTAR #endif diff --git a/src/global/global_context.cc b/src/global/global_context.cc index 624d24136db..0eb6e62bf3d 100644 --- a/src/global/global_context.cc +++ b/src/global/global_context.cc @@ -20,7 +20,11 @@ */ CephContext *g_ceph_context = NULL; ConfigProxy& g_conf() { +#ifdef WITH_SEASTAR + return ceph::common::local_conf(); +#else return g_ceph_context->_conf; +#endif } const char *g_assert_file = 0; From 9b26bdaa53920ee1ddb9651f9b1707b7cd404c90 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 28 Aug 2018 15:37:21 +0800 Subject: [PATCH 2/9] auth: instantiate the templates if WITH_SEASTAR specialize class/method of LockPolicy::SINGLE `#ifdef WITH_SEASTAR`. in long term, probably we can remove `LockPolicy`, as WITH_SEASTAR implies `LockPolicy::SINGLE`. Signed-off-by: Kefu Chai --- src/auth/AuthClientHandler.cc | 8 ++++++++ src/auth/RotatingKeyRing.cc | 4 ++++ src/auth/cephx/CephxClientHandler.cc | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/src/auth/AuthClientHandler.cc b/src/auth/AuthClientHandler.cc index 1ac96a50c4f..fe0a5238f54 100644 --- a/src/auth/AuthClientHandler.cc +++ b/src/auth/AuthClientHandler.cc @@ -36,8 +36,16 @@ AuthClientHandler::create(CephContext *cct, int proto, } // explicitly instantiate only the classes we need +#ifdef WITH_SEASTAR +template AuthClientHandler* +AuthClientHandler::create( + CephContext *cct, + int proto, + RotatingKeyRing *rkeys); +#else template AuthClientHandler* AuthClientHandler::create( CephContext *cct, int proto, RotatingKeyRing *rkeys); +#endif diff --git a/src/auth/RotatingKeyRing.cc b/src/auth/RotatingKeyRing.cc index 196b1a12052..6fade65c8a0 100644 --- a/src/auth/RotatingKeyRing.cc +++ b/src/auth/RotatingKeyRing.cc @@ -79,4 +79,8 @@ KeyRing *RotatingKeyRing::get_keyring() } // explicitly instantiate only the classes we need +#ifdef WITH_SEASTAR +template class RotatingKeyRing; +#else template class RotatingKeyRing; +#endif diff --git a/src/auth/cephx/CephxClientHandler.cc b/src/auth/cephx/CephxClientHandler.cc index 73e4c7e16d9..3559fd73728 100644 --- a/src/auth/cephx/CephxClientHandler.cc +++ b/src/auth/cephx/CephxClientHandler.cc @@ -252,4 +252,8 @@ bool CephxClientHandler::need_tickets() } // explicitly instantiate only the classes we need +#ifdef WITH_SEASTAR +template class CephxClientHandler; +#else template class CephxClientHandler; +#endif From 0b354a966e52d8c3af8008b6e78b864909cd9ae1 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 3 Sep 2018 17:23:33 +0800 Subject: [PATCH 3/9] mds/FSMap: specialize for WITH_SEASTAR FSMap.{h,cc} is pulled in as a dependency of src/msg/Messages.cc, where a handful of Messages types used by MDS and its client are referenced. so we need to compile the referenced source files as well. another option is to enable a subset of messages for different kinds of server/client, but that needs more work. Signed-off-by: Kefu Chai --- src/mds/FSMap.cc | 4 ++++ src/mds/FSMap.h | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mds/FSMap.cc b/src/mds/FSMap.cc index 666a282d025..69109d0524e 100644 --- a/src/mds/FSMap.cc +++ b/src/mds/FSMap.cc @@ -16,7 +16,11 @@ #include "FSMap.h" #include +#ifdef WITH_SEASTAR +#include "crimson/common/config_proxy.h" +#else #include "common/config_proxy.h" +#endif #include "global/global_context.h" #include "mon/health_check.h" diff --git a/src/mds/FSMap.h b/src/mds/FSMap.h index a60b7076ac6..57355ea1ba7 100644 --- a/src/mds/FSMap.h +++ b/src/mds/FSMap.h @@ -27,8 +27,6 @@ #include "common/Clock.h" #include "mds/MDSMap.h" -#include "common/config.h" - #include "include/CompatSet.h" #include "include/ceph_features.h" #include "common/Formatter.h" From f59cb91264bca91a840c1aa84dba4c6165cbceaf Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 28 Aug 2018 20:06:46 +0800 Subject: [PATCH 4/9] common,crimson: add a seastar backend for logging this logging backend serves as an intemediate solution before the LTTng backend is ready. it maps - -1 to error() - 0 to warn() - [1,5) to info() - [5,10) to debug() - [20,200] to trace() Signed-off-by: Kefu Chai --- src/common/dout.h | 43 +++++++++++++++++++++++++++++++++----- src/crimson/CMakeLists.txt | 3 ++- src/crimson/common/log.cc | 18 ++++++++++++++++ src/crimson/common/log.h | 6 ++++++ 4 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 src/crimson/common/log.cc create mode 100644 src/crimson/common/log.h diff --git a/src/common/dout.h b/src/common/dout.h index c423c0818b8..0ac365abe01 100644 --- a/src/common/dout.h +++ b/src/common/dout.h @@ -18,12 +18,19 @@ #include +#include "include/assert.h" +#ifdef WITH_SEASTAR +#include +#include "crimson/common/log.h" +#include "crimson/common/config_proxy.h" +#else #include "global/global_context.h" #include "common/ceph_context.h" #include "common/config.h" #include "common/likely.h" #include "common/Clock.h" #include "log/Log.h" +#endif extern void dout_emergency(const char * const str); extern void dout_emergency(const std::string &str); @@ -69,6 +76,31 @@ struct is_dynamic> : public std::true_type {}; // generic macros #define dout_prefix *_dout +#ifdef WITH_SEASTAR +#define dout_impl(cct, sub, v) \ + do { \ + if (ceph::common::local_conf()->subsys.should_gather(sub, v)) { \ + seastar::logger& _logger = ceph::get_logger(sub); \ + const auto _lv = v; \ + std::ostringstream _out; \ + std::ostream* _dout = &_out; +#define dendl_impl \ + ""; \ + const std::string _s = _out.str(); \ + if (_lv < 0) { \ + _logger.error(_s.c_str()); \ + } else if (_lv < 1) { \ + _logger.warn(_s.c_str()); \ + } else if (_lv < 5) { \ + _logger.info(_s.c_str()); \ + } else if (_lv < 10) { \ + _logger.debug(_s.c_str()); \ + } else { \ + _logger.trace(_s.c_str()); \ + } \ + } \ + } while (0) +#else #define dout_impl(cct, sub, v) \ do { \ const bool should_gather = [&](const auto cctX) { \ @@ -93,6 +125,12 @@ struct is_dynamic> : public std::true_type {}; auto _dout_cct = cct; \ std::ostream* _dout = &_dout_e->get_ostream(); +#define dendl_impl std::flush; \ + _dout_cct->_log->submit_entry(_dout_e); \ + } \ + } while (0) +#endif // WITH_SEASTAR + #define lsubdout(cct, sub, v) dout_impl(cct, ceph_subsys_##sub, v) dout_prefix #define ldout(cct, v) dout_impl(cct, dout_subsys, v) dout_prefix #define lderr(cct) dout_impl(cct, ceph_subsys_, -1) dout_prefix @@ -109,11 +147,6 @@ struct is_dynamic> : public std::true_type {}; #define ldlog_p1(cct, sub, lvl) \ (cct->_conf->subsys.should_gather((sub), (lvl))) -#define dendl_impl std::flush; \ - _dout_cct->_log->submit_entry(_dout_e); \ - } \ - } while (0) - #define dendl dendl_impl #endif diff --git a/src/crimson/CMakeLists.txt b/src/crimson/CMakeLists.txt index d7b347ffcc6..020fea969ed 100644 --- a/src/crimson/CMakeLists.txt +++ b/src/crimson/CMakeLists.txt @@ -7,7 +7,8 @@ set(crimson_thread_srcs thread/ThreadPool.cc thread/Throttle.cc) set(crimson_common_srcs - common/config_proxy.cc) + common/config_proxy.cc + common/log.cc) add_library(crimson STATIC ${crimson_common_srcs} ${crimson_net_srcs} diff --git a/src/crimson/common/log.cc b/src/crimson/common/log.cc new file mode 100644 index 00000000000..6a57b233516 --- /dev/null +++ b/src/crimson/common/log.cc @@ -0,0 +1,18 @@ +#include "log.h" + +static std::array loggers{ +#define SUBSYS(name, log_level, gather_level) \ + seastar::logger(#name), +#define DEFAULT_SUBSYS(log_level, gather_level) \ + seastar::logger("none"), + #include "common/subsys.h" +#undef SUBSYS +#undef DEFAULT_SUBSYS +}; + +namespace ceph { +seastar::logger& get_logger(int subsys) { + assert(subsys < ceph_subsys_max); + return loggers[subsys]; +} +} diff --git a/src/crimson/common/log.h b/src/crimson/common/log.h new file mode 100644 index 00000000000..64ff33654ed --- /dev/null +++ b/src/crimson/common/log.h @@ -0,0 +1,6 @@ +#include +#include "common/subsys_types.h" + +namespace ceph { +seastar::logger& get_logger(int subsys); +} From 029be76e0886c9ab12c54b318baf43fdaca5d201 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 5 Sep 2018 15:50:47 +0800 Subject: [PATCH 5/9] crimson/net: add logging to SocketConnection Signed-off-by: Kefu Chai --- src/crimson/net/SocketConnection.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/crimson/net/SocketConnection.cc b/src/crimson/net/SocketConnection.cc index a3d459ca15a..3a9cb1f5834 100644 --- a/src/crimson/net/SocketConnection.cc +++ b/src/crimson/net/SocketConnection.cc @@ -27,6 +27,8 @@ #include "auth/AuthSessionHandler.h" #include "msg/Message.h" +#include "crimson/common/log.h" + using namespace ceph::net; template @@ -34,6 +36,12 @@ seastar::net::packet make_static_packet(const T& value) { return { reinterpret_cast(&value), sizeof(value) }; } +namespace { + seastar::logger& logger() { + return ceph::get_logger(ceph_subsys_ms); + } +} + SocketConnection::SocketConnection(Messenger *messenger, const entity_addr_t& my_addr, const entity_addr_t& peer_addr, @@ -663,6 +671,7 @@ seastar::future<> SocketConnection::handle_connect_reply(msgr_tag_t tag) return fault(); case CEPH_MSGR_TAG_BADAUTHORIZER: if (h.got_bad_auth) { + logger().error("{} got bad authorizer", __func__); throw std::system_error(make_error_code(error::negotiation_failure)); } h.got_bad_auth = true; @@ -724,6 +733,7 @@ seastar::future<> SocketConnection::handle_connect_reply(msgr_tag_t tag) return seastar::now(); } else { // unknown tag + logger().error("{} got unknown tag", __func__, int(tag)); throw std::system_error(make_error_code(error::negotiation_failure)); } } @@ -789,6 +799,7 @@ seastar::future<> SocketConnection::connect(entity_type_t peer_type, if (h.authorizer) { auto reply = bl.cbegin(); if (!h.authorizer->verify_reply(reply)) { + logger().error("{} authorizer failed to verify reply", __func__); throw std::system_error(make_error_code(error::negotiation_failure)); } } From e5793e1a6aff7041cc8ef60f5412800d67585e6e Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 31 Aug 2018 21:59:03 +0800 Subject: [PATCH 6/9] crimson: port assert.cc to seastar Signed-off-by: Kefu Chai --- src/crimson/CMakeLists.txt | 1 + src/crimson/common/assert.cc | 56 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/crimson/common/assert.cc diff --git a/src/crimson/CMakeLists.txt b/src/crimson/CMakeLists.txt index 020fea969ed..39c6615529f 100644 --- a/src/crimson/CMakeLists.txt +++ b/src/crimson/CMakeLists.txt @@ -8,6 +8,7 @@ set(crimson_thread_srcs thread/Throttle.cc) set(crimson_common_srcs common/config_proxy.cc + common/assert.cc common/log.cc) add_library(crimson STATIC ${crimson_common_srcs} diff --git a/src/crimson/common/assert.cc b/src/crimson/common/assert.cc new file mode 100644 index 00000000000..9b34cb52902 --- /dev/null +++ b/src/crimson/common/assert.cc @@ -0,0 +1,56 @@ +#include + +#include +#include + +#include "include/assert.h" + +#include "crimson/common/log.h" + +namespace ceph { + [[gnu::cold]] void __ceph_assert_fail(const ceph::assert_data &ctx) + { + __ceph_assert_fail(ctx.assertion, ctx.file, ctx.line, ctx.function); + } + + [[gnu::cold]] void __ceph_assert_fail(const char* assertion, + const char* file, int line, + const char* func) + { + seastar::logger& logger = ceph::get_logger(0); + logger.error("{}:{} : In function '{}', ceph_assert(%s)\n" + "{}", + file, line, func, assertion, + seastar::current_backtrace()); + abort(); + } + [[gnu::cold]] void __ceph_assertf_fail(const char *assertion, + const char *file, int line, + const char *func, const char* msg, + ...) + { + char buf[8096]; + va_list args; + va_start(args, msg); + std::vsnprintf(buf, sizeof(buf), msg, args); + va_end(args); + + seastar::logger& logger = ceph::get_logger(0); + logger.error("{}:{} : In function '{}', ceph_assert(%s)\n" + "{}", + file, line, func, assertion, + seastar::current_backtrace()); + abort(); + } + + [[gnu::cold]] void __ceph_abort(const char* file, int line, + const char* func, const std::string& msg) + { + seastar::logger& logger = ceph::get_logger(0); + logger.error("{}:{} : In function '{}', abort(%s)\n" + "{}", + file, line, func, msg, + seastar::current_backtrace()); + abort(); + } +} From 283c739b1abd8342077f6b6607a5138ddfa17064 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 25 Aug 2018 00:04:12 +0800 Subject: [PATCH 7/9] common/config: cleanup config_fwd.h * define an alias for ceph::common::ConfigProxy * remove obs bits from config_fwd.h, as the users of obs will always need to include config_obs.h anyway. Signed-off-by: Kefu Chai --- src/common/config.h | 1 - src/common/config_fwd.h | 13 ++++++------- src/common/config_obs.h | 3 +++ src/common/config_proxy.h | 2 +- src/common/config_values.h | 1 - src/mon/MonMap.h | 8 ++++++-- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/common/config.h b/src/common/config.h index 503e57b1473..76886cd2d1d 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -23,7 +23,6 @@ #include "log/SubsystemMap.h" #include "common/options.h" #include "common/subsys_types.h" -#include "common/config_fwd.h" #include "common/config_tracker.h" #include "common/config_values.h" diff --git a/src/common/config_fwd.h b/src/common/config_fwd.h index 7b7ff28e536..817d1a0f8b0 100644 --- a/src/common/config_fwd.h +++ b/src/common/config_fwd.h @@ -2,12 +2,11 @@ #pragma once -#include "lock_policy.h" - -namespace ceph { -template class md_config_obs_impl; +#ifdef WITH_SEASTAR +namespace ceph::common { + class ConfigProxy; } - -struct md_config_t; +using ConfigProxy = ceph::common::ConfigProxy; +#else class ConfigProxy; -using md_config_obs_t = ceph::md_config_obs_impl; +#endif diff --git a/src/common/config_obs.h b/src/common/config_obs.h index 0cbbdb37397..20d12ad8334 100644 --- a/src/common/config_obs.h +++ b/src/common/config_obs.h @@ -44,4 +44,7 @@ public: const std::set& changed) { } }; } + +using md_config_obs_t = ceph::md_config_obs_impl; + #endif diff --git a/src/common/config_proxy.h b/src/common/config_proxy.h index d6f75b10b87..e9b6b39b626 100644 --- a/src/common/config_proxy.h +++ b/src/common/config_proxy.h @@ -4,7 +4,6 @@ #include #include "common/config.h" -#include "common/config_fwd.h" #include "common/config_obs.h" #include "common/config_obs_mgr.h" #include "common/Mutex.h" @@ -17,6 +16,7 @@ class ConfigProxy { * The current values of all settings described by the schema */ ConfigValues values; + using md_config_obs_t = ceph::md_config_obs_impl; ObserverMgr obs_mgr; md_config_t config; /** A lock that protects the md_config_t internals. It is diff --git a/src/common/config_values.h b/src/common/config_values.h index b5f10b6cb47..2614d2ef159 100644 --- a/src/common/config_values.h +++ b/src/common/config_values.h @@ -8,7 +8,6 @@ #include #include -#include "common/config_fwd.h" #include "common/entity_name.h" #include "common/options.h" #include "log/SubsystemMap.h" diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h index 5b6e2702c50..0bde9f014ba 100644 --- a/src/mon/MonMap.h +++ b/src/mon/MonMap.h @@ -15,11 +15,15 @@ #ifndef CEPH_MONMAP_H #define CEPH_MONMAP_H -#include "include/err.h" -#include "msg/Message.h" +#include "common/config_fwd.h" + +#include "include/err.h" #include "include/types.h" + #include "mon/mon_types.h" +#include "msg/Message.h" + namespace ceph { class Formatter; From 4488b504d6c7911645f3381b17ef67b720168983 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 6 Sep 2018 19:07:26 +0800 Subject: [PATCH 8/9] crimson/common: add some missing method for ConfigProxy OSDMap.cc uses them when WITH_SEASTAR is defined. Signed-off-by: Kefu Chai --- src/crimson/common/config_proxy.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/crimson/common/config_proxy.h b/src/crimson/common/config_proxy.h index 53fa2b0a3ee..a8d7eeacd2a 100644 --- a/src/crimson/common/config_proxy.h +++ b/src/crimson/common/config_proxy.h @@ -111,6 +111,21 @@ public: return get_config().template get_val(*values, key); } + int get_all_sections(std::vector& sections) const { + return get_config().get_all_sections(sections); + } + + int get_val_from_conf_file(const std::vector& sections, + const std::string& key, std::string& out, + bool expand_meta) const { + return get_config().get_val_from_conf_file(*values, sections, key, + out, expand_meta); + } + + unsigned get_osd_pool_default_min_size() const { + return get_config().get_osd_pool_default_min_size(*values); + } + seastar::future<> set_mon_vals(const std::map& kv) { return do_change([kv, this](ConfigValues& values) { get_config().set_mon_vals(nullptr, values, obs_mgr, kv, nullptr); From 6fdc2c13de24e1c4d7fdb4efb666c43004d2861e Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 6 Sep 2018 17:46:55 +0800 Subject: [PATCH 9/9] cmake: compile crimson-specific libraries - add crimson::cflags target for populating WITH_SEASTAR=1 macro so any library linking against crimson::cflags will have WITH_SEASTAR=1 defined. but we still need to set the definition and include directories for object targets. - there are two ways to use the seastar logging backend, to specify the backend at run-time, or to do so at compile-time. if we do so at run-time, we would need to include seastar specific headers in dout.h. this will force the non-seastar-osd components to pull in seastar header file or linkage dependencies. and it's not performant, as we need to check the option everytime we are about the print a log message as the ceph::common::ConfigProxy for seastar is not compatible ::ConfigProxy at binary level -- they don't inherit from the same parent class, and ceph_context does not keep a reference of this nonexistent parent class. if we respect WITH_SEASTAR preprocessor macro, the only downside is that we need to re-compile all compilation units using logging with WITH_SEASTAR=1. and this implies a side effect, we don't need to use template techniques to specialize for seastar anymore, we can just conditionalize the seastar/alien specific behavior on `#ifdef WITH_SEASTAR`. so in this change, we compile crimson-common and crimson-auth as the alternatives of ceph-common and common-auth-objs respectively. and WITH_SEASTAR=1 is defined when compiling them. Signed-off-by: Kefu Chai --- src/CMakeLists.txt | 3 + src/auth/CMakeLists.txt | 7 +++ src/crimson/CMakeLists.txt | 125 +++++++++++++++++++++++++++++++++++-- src/crush/CMakeLists.txt | 8 +++ 4 files changed, 137 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7380a92906a..4b33242d6b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -307,6 +307,9 @@ if(WITH_SEASTAR) endif() endmacro () add_subdirectory(seastar) + # create the directory so cmake won't complain when looking at the imported + # target: Seastar exports this directory created at build-time + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/seastar/gen") add_subdirectory(crimson) endif() diff --git a/src/auth/CMakeLists.txt b/src/auth/CMakeLists.txt index 113a956193c..5e19d8963b7 100644 --- a/src/auth/CMakeLists.txt +++ b/src/auth/CMakeLists.txt @@ -14,3 +14,10 @@ set(auth_srcs unknown/AuthUnknownAuthorizeHandler.cc) add_library(common-auth-objs OBJECT ${auth_srcs}) +if(WITH_SEASTAR) + add_library(crimson-auth OBJECT ${auth_srcs}) + target_compile_definitions(crimson-auth PRIVATE + "WITH_SEASTAR=1") + target_include_directories(crimson-auth PRIVATE + $) +endif() diff --git a/src/crimson/CMakeLists.txt b/src/crimson/CMakeLists.txt index 39c6615529f..4d6302f41b6 100644 --- a/src/crimson/CMakeLists.txt +++ b/src/crimson/CMakeLists.txt @@ -1,3 +1,115 @@ +add_library(crimson::cflags INTERFACE IMPORTED) +set_target_properties(crimson::cflags PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "WITH_SEASTAR=1" + INTERFACE_LINK_LIBRARIES Seastar::seastar) + +set(crimson_common_srcs + common/config_proxy.cc + common/assert.cc + common/log.cc) + +# the specialized version of ceph-common, where +# - the logging is sent to Seastar backend +# - and the template parameter of lock_policy is SINGLE +add_library(crimson-common STATIC + ${PROJECT_SOURCE_DIR}/src/common/addr_parsing.c + ${PROJECT_SOURCE_DIR}/src/common/admin_socket.cc + ${PROJECT_SOURCE_DIR}/src/common/admin_socket_client.cc + ${PROJECT_SOURCE_DIR}/src/common/armor.c + ${PROJECT_SOURCE_DIR}/src/common/bit_str.cc + ${PROJECT_SOURCE_DIR}/src/common/bloom_filter.cc + ${PROJECT_SOURCE_DIR}/src/common/ceph_argparse.cc + ${PROJECT_SOURCE_DIR}/src/common/ceph_context.cc + ${PROJECT_SOURCE_DIR}/src/common/ceph_crypto.cc + ${PROJECT_SOURCE_DIR}/src/common/ceph_hash.cc + ${PROJECT_SOURCE_DIR}/src/common/ceph_time.cc + ${PROJECT_SOURCE_DIR}/src/common/ceph_strings.cc + ${PROJECT_SOURCE_DIR}/src/common/cmdparse.cc + ${PROJECT_SOURCE_DIR}/src/common/common_init.cc + ${PROJECT_SOURCE_DIR}/src/common/code_environment.cc + ${PROJECT_SOURCE_DIR}/src/common/config.cc + ${PROJECT_SOURCE_DIR}/src/common/config_values.cc + ${PROJECT_SOURCE_DIR}/src/common/dout.cc + ${PROJECT_SOURCE_DIR}/src/common/entity_name.cc + ${PROJECT_SOURCE_DIR}/src/common/environment.cc + ${PROJECT_SOURCE_DIR}/src/common/errno.cc + ${PROJECT_SOURCE_DIR}/src/common/escape.cc + ${PROJECT_SOURCE_DIR}/src/common/hex.cc + ${PROJECT_SOURCE_DIR}/src/common/fs_types.cc + ${PROJECT_SOURCE_DIR}/src/common/histogram.cc + ${PROJECT_SOURCE_DIR}/src/common/hobject.cc + ${PROJECT_SOURCE_DIR}/src/common/hostname.cc + ${PROJECT_SOURCE_DIR}/src/common/ipaddr.cc + ${PROJECT_SOURCE_DIR}/src/common/io_priority.cc + ${PROJECT_SOURCE_DIR}/src/common/lockdep.cc + ${PROJECT_SOURCE_DIR}/src/common/mutex_debug.cc + ${PROJECT_SOURCE_DIR}/src/common/mempool.cc + ${PROJECT_SOURCE_DIR}/src/common/options.cc + ${PROJECT_SOURCE_DIR}/src/common/perf_counters.cc + ${PROJECT_SOURCE_DIR}/src/common/perf_histogram.cc + ${PROJECT_SOURCE_DIR}/src/common/page.cc + ${PROJECT_SOURCE_DIR}/src/common/pipe.c + ${PROJECT_SOURCE_DIR}/src/common/snap_types.cc + ${PROJECT_SOURCE_DIR}/src/common/safe_io.c + ${PROJECT_SOURCE_DIR}/src/common/signal.cc + ${PROJECT_SOURCE_DIR}/src/common/str_list.cc + ${PROJECT_SOURCE_DIR}/src/common/str_map.cc + ${PROJECT_SOURCE_DIR}/src/common/strtol.cc + ${PROJECT_SOURCE_DIR}/src/common/reverse.c + ${PROJECT_SOURCE_DIR}/src/common/types.cc + ${PROJECT_SOURCE_DIR}/src/common/utf8.c + ${PROJECT_SOURCE_DIR}/src/common/version.cc + ${PROJECT_SOURCE_DIR}/src/common/BackTrace.cc + ${PROJECT_SOURCE_DIR}/src/common/CachedPrebufferedStreambuf.cc + ${PROJECT_SOURCE_DIR}/src/common/ConfUtils.cc + ${PROJECT_SOURCE_DIR}/src/common/DecayCounter.cc + ${PROJECT_SOURCE_DIR}/src/common/HTMLFormatter.cc + ${PROJECT_SOURCE_DIR}/src/common/Formatter.cc + ${PROJECT_SOURCE_DIR}/src/common/Graylog.cc + ${PROJECT_SOURCE_DIR}/src/common/LogEntry.cc + ${PROJECT_SOURCE_DIR}/src/common/Mutex.cc + ${PROJECT_SOURCE_DIR}/src/common/RefCountedObj.cc + ${PROJECT_SOURCE_DIR}/src/common/SubProcess.cc + ${PROJECT_SOURCE_DIR}/src/common/TextTable.cc + ${PROJECT_SOURCE_DIR}/src/common/Thread.cc + ${PROJECT_SOURCE_DIR}/src/common/HeartbeatMap.cc + ${PROJECT_SOURCE_DIR}/src/common/PluginRegistry.cc + ${PROJECT_SOURCE_DIR}/src/librbd/Features.cc + ${PROJECT_SOURCE_DIR}/src/log/Log.cc + ${PROJECT_SOURCE_DIR}/src/mgr/ServiceMap.cc + ${PROJECT_SOURCE_DIR}/src/mds/inode_backtrace.cc + ${PROJECT_SOURCE_DIR}/src/mds/mdstypes.cc + ${PROJECT_SOURCE_DIR}/src/mds/FSMap.cc + ${PROJECT_SOURCE_DIR}/src/mds/FSMapUser.cc + ${PROJECT_SOURCE_DIR}/src/mds/MDSMap.cc + ${PROJECT_SOURCE_DIR}/src/msg/msg_types.cc + ${PROJECT_SOURCE_DIR}/src/msg/Message.cc + ${PROJECT_SOURCE_DIR}/src/mon/MonCap.cc + ${PROJECT_SOURCE_DIR}/src/osd/osd_types.cc + ${PROJECT_SOURCE_DIR}/src/osd/ECMsgTypes.cc + ${PROJECT_SOURCE_DIR}/src/osd/HitSet.cc + ${PROJECT_SOURCE_DIR}/src/osd/OSDMap.cc + ${PROJECT_SOURCE_DIR}/src/osd/PGPeeringEvent.cc + ${crimson_common_srcs} + $ + $ + $ + $) + +target_compile_definitions(crimson-common PRIVATE + "CEPH_LIBDIR=\"${CMAKE_INSTALL_FULL_LIBDIR}\"" + "CEPH_PKGLIBDIR=\"${CMAKE_INSTALL_FULL_PKGLIBDIR}\"") + +target_link_libraries(crimson-common + PUBLIC + json_spirit + PRIVATE + crc32 + crimson::cflags + Boost::iostreams + Boost::random + ${NSS_LIBRARIES} ${NSPR_LIBRARIES} ${OPENSSL_LIBRARIES}) + set(crimson_net_srcs net/Dispatcher.cc net/Errors.cc @@ -6,13 +118,14 @@ set(crimson_net_srcs set(crimson_thread_srcs thread/ThreadPool.cc thread/Throttle.cc) -set(crimson_common_srcs - common/config_proxy.cc - common/assert.cc - common/log.cc) add_library(crimson STATIC - ${crimson_common_srcs} ${crimson_net_srcs} ${crimson_thread_srcs} ${CMAKE_SOURCE_DIR}/src/common/buffer_seastar.cc) -target_link_libraries(crimson Seastar::seastar ceph-common) +target_compile_options(crimson PRIVATE + "-ftemplate-backtrace-limit=0") +target_link_libraries(crimson + PUBLIC + crimson-common Seastar::seastar + PRIVATE + crimson::cflags) diff --git a/src/crush/CMakeLists.txt b/src/crush/CMakeLists.txt index 1c875d59474..ae9b9f472be 100644 --- a/src/crush/CMakeLists.txt +++ b/src/crush/CMakeLists.txt @@ -9,3 +9,11 @@ set(crush_srcs CrushLocation.cc) add_library(crush_objs OBJECT ${crush_srcs}) + +if(WITH_SEASTAR) + add_library(crimson-crush OBJECT ${crush_srcs}) + target_compile_definitions(crimson-crush PRIVATE + "WITH_SEASTAR=1") + target_include_directories(crimson-crush PRIVATE + $) +endif()