]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: specialize for WITH_SEASTAR
authorKefu Chai <kchai@redhat.com>
Mon, 3 Sep 2018 09:15:16 +0000 (17:15 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 6 Sep 2018 14:03:33 +0000 (22:03 +0800)
* 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 <kchai@redhat.com>
src/common/ceph_context.cc
src/common/ceph_context.h
src/common/common_init.cc
src/common/common_init.h
src/global/global_context.cc

index e311eae3880d1f5ae190e2ace03f8c4c13726e5c..41d1f47bf11ae6941ced6466231a43503b324241 100644 (file)
 using ceph::bufferlist;
 using ceph::HeartbeatMap;
 
+#ifdef WITH_SEASTAR
+CephContext::CephContext()
+  : _conf{ceph::common::local_conf()},
+    _crypto_random{std::make_unique<CryptoRandom>()}
+{}
+
+// 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
index 88318bce3f805153c39772e327ade44bc4b7945a..e2e91bb4e182484635835d4b6148e6ace5a7d80b 100644 (file)
 
 #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<CryptoRandom> _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<ConfigProxy>;
+
   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
index 30dd2b28d83779a0d65c284a805d7cb0a55ec150..5625fd584896de4aad734dbca63725cfe421fbdb 100644 (file)
@@ -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<std::string> *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
index 1a4207b0ec7fba50225f2236b50c35b52b797d87..133533bb27d45e0099d0dd3fed9cd8ef15516452 100644 (file)
@@ -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<std::string> *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
index 624d24136db885c2b67058a656d557e0f0de7b23..0eb6e62bf3dd23441f26d66eede9125df6ce0b52 100644 (file)
  */
 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;