From: Kefu Chai Date: Mon, 3 Sep 2018 09:15:16 +0000 (+0800) Subject: common: specialize for WITH_SEASTAR X-Git-Tag: v14.0.1~345^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5368e7e0e5a0900961b0ad0652b4e21a91c83d13;p=ceph.git 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 --- diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index e311eae3880d1..41d1f47bf11ae 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 88318bce3f805..e2e91bb4e1824 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 30dd2b28d8377..5625fd584896d 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 1a4207b0ec7fb..133533bb27d45 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 624d24136db88..0eb6e62bf3dd2 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;