]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
objclass, osd: turn ClassHandler into singleton.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 26 Jul 2019 14:36:58 +0000 (16:36 +0200)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Mon, 29 Jul 2019 16:06:49 +0000 (18:06 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/CMakeLists.txt
src/objclass/class_api.cc
src/osd/CMakeLists.txt
src/osd/ClassHandler.cc
src/osd/ClassHandler.h
src/osd/OSD.cc
src/osd/OSD.h
src/osd/PrimaryLogPG.cc

index 6e3b18e4182850040cd843bb34bf72481f293d2f..476c8e69bc3eed268b7d27b6ac2b463a35419275 100644 (file)
@@ -512,6 +512,9 @@ add_subdirectory(os)
 add_subdirectory(osd)
 
 set(ceph_osd_srcs
+  # Link the Object Class API implementation directly as intermediary
+  # static library (like libosd.a) nullifies the effect of `-rdynamic`.
+  objclass/class_api.cc
   ceph_osd.cc)
 add_executable(ceph-osd ${ceph_osd_srcs})
 add_dependencies(ceph-osd erasure_code_plugins)
index 2a202291dfdd5355c273ba502360aa5f6a0b7ae5..0aed64f81ab8ce2c4ea455bc42928325072664b2 100644 (file)
 #include "auth/Crypto.h"
 #include "common/armor.h"
 
-static constexpr int dout_subsys = ceph_subsys_objclass;
-
-static ClassHandler *ch;
-
-void cls_initialize(ClassHandler *h)
-{
-  ch = h;
-}
+#define dout_context ClassHandler::get_instance().cct
 
+static constexpr int dout_subsys = ceph_subsys_objclass;
 
 void *cls_alloc(size_t size)
 {
@@ -35,7 +29,8 @@ void cls_free(void *p)
 
 int cls_register(const char *name, cls_handle_t *handle)
 {
-  ClassHandler::ClassData *cls = ch->register_class(name);
+  ClassHandler::ClassData *cls = \
+    ClassHandler::get_instance().register_class(name);
   *handle = (cls_handle_t)cls;
   return (cls != NULL);
 }
@@ -43,7 +38,7 @@ int cls_register(const char *name, cls_handle_t *handle)
 int cls_unregister(cls_handle_t handle)
 {
   ClassHandler::ClassData *cls = (ClassHandler::ClassData *)handle;
-  ch->unregister_class(cls);
+  ClassHandler::get_instance().unregister_class(cls);
   return 1;
 }
 
@@ -631,7 +626,7 @@ int cls_cxx_list_watchers(cls_method_context_t hctx,
 
 int cls_gen_random_bytes(char *buf, int size)
 {
-  ch->cct->random()->get_bytes(buf, size);
+  ClassHandler::get_instance().cct->random()->get_bytes(buf, size);
   return 0;
 }
 
@@ -643,14 +638,14 @@ int cls_gen_rand_base64(char *dest, int size) /* size should be the required str
 
   ret = cls_gen_random_bytes(buf, sizeof(buf));
   if (ret < 0) {
-    lgeneric_derr(ch->cct) << "cannot get random bytes: " << ret << dendl;
+    derr << "cannot get random bytes: " << ret << dendl;
     return -1;
   }
 
   ret = ceph_armor(tmp_dest, &tmp_dest[sizeof(tmp_dest)],
                   (const char *)buf, ((const char *)buf) + ((size - 1) * 3 + 4 - 1) / 4);
   if (ret < 0) {
-    lgeneric_derr(ch->cct) << "ceph_armor failed" << dendl;
+    derr << "ceph_armor failed" << dendl;
     return -1;
   }
   tmp_dest[ret] = '\0';
@@ -727,7 +722,7 @@ int cls_log(int level, const char *format, ...)
      va_end(ap);
 #define MAX_SIZE 8196
      if ((n > -1 && n < size) || size > MAX_SIZE) {
-       ldout(ch->cct, ceph::dout::need_dynamic(level)) << buf << dendl;
+       dout(ceph::dout::need_dynamic(level)) << buf << dendl;
        return n;
      }
      size *= 2;
index ab28c63e0dccc06351c22a8bd8ecff937542f386..f3125600eb230c7a1e22e8475a9392700b4ffafb 100644 (file)
@@ -38,7 +38,6 @@ set(osd_srcs
   MissingLoc.cc
   osd_perf_counters.cc
   ${CMAKE_SOURCE_DIR}/src/common/TrackedOp.cc
-  ${CMAKE_SOURCE_DIR}/src/objclass/class_api.cc
   ${CMAKE_SOURCE_DIR}/src/mgr/OSDPerfMetricTypes.cc
   ${osd_cyg_functions_src}
   ${osdc_osd_srcs})
index e83dfd08ce700e0346f25fadabc9e804a3111a1a..4f11e51f1116d289f9463e7e81b2b642b41a0c55 100644 (file)
@@ -327,3 +327,8 @@ int ClassHandler::ClassMethod::exec(cls_method_context_t ctx, bufferlist& indata
   return ret;
 }
 
+ClassHandler& ClassHandler::get_instance()
+{
+  static ClassHandler single(g_ceph_context);
+  return single;
+}
index 94950940058c9249868284fc6f3b51f66d19e670..c80c4c0c47bc67fb6bbce0ca91dc19c687b5120b 100644 (file)
@@ -127,6 +127,8 @@ public:
   void unregister_class(ClassData *cls);
 
   void shutdown();
+
+  static ClassHandler& get_instance();
 };
 
 
index 67c0834d58758705156eaf591a8e0901b6ebd65c..e2f6325e52a671c3cc2790cd881b3160e0f4dd46 100644 (file)
@@ -221,7 +221,6 @@ OSDService::OSDService(OSD *osd) :
   logger(osd->logger),
   recoverystate_perf(osd->recoverystate_perf),
   monc(osd->monc),
-  class_handler(osd->class_handler),
   osd_max_object_size(cct->_conf, "osd_max_object_size"),
   osd_skip_data_digest(cct->_conf, "osd_skip_data_digest"),
   publish_lock{ceph::make_mutex("OSDService::publish_lock")},
@@ -2177,7 +2176,6 @@ OSD::~OSD()
     delete shards.back();
     shards.pop_back();
   }
-  delete class_handler;
   cct->get_perfcounters_collection()->remove(recoverystate_perf);
   cct->get_perfcounters_collection()->remove(logger);
   delete recoverystate_perf;
@@ -2193,8 +2191,6 @@ double OSD::get_tick_interval() const
          ceph::util::generate_random_number(1.0 - delta, 1.0 + delta));
 }
 
-void cls_initialize(ClassHandler *ch);
-
 void OSD::handle_signal(int signum)
 {
   ceph_assert(signum == SIGINT || signum == SIGTERM);
@@ -2869,11 +2865,8 @@ int OSD::init()
       goto out;
   }
 
-  class_handler = new ClassHandler(cct);
-  cls_initialize(class_handler);
-
   if (cct->_conf->osd_open_classes_on_start) {
-    int r = class_handler->open_all_classes();
+    int r = ClassHandler::get_instance().open_all_classes();
     if (r)
       dout(1) << "warning: got an error loading one or more classes: " << cpp_strerror(r) << dendl;
   }
@@ -3525,7 +3518,7 @@ int OSD::shutdown()
 
   op_tracker.on_shutdown();
 
-  class_handler->shutdown();
+  ClassHandler::get_instance().shutdown();
   client_messenger->shutdown();
   cluster_messenger->shutdown();
   hb_front_client_messenger->shutdown();
@@ -9633,7 +9626,7 @@ int OSD::init_op_flags(OpRequestRef& op)
        bp.copy(iter->op.cls.method_len, mname);
 
        ClassHandler::ClassData *cls;
-       int r = class_handler->open_class(cname, &cls);
+       int r = ClassHandler::get_instance().open_class(cname, &cls);
        if (r) {
          derr << "class " << cname << " open got " << cpp_strerror(r) << dendl;
          if (r == -ENOENT)
index 40b6a07eacd8846a369f5500e915020cb27b782f..d3ad786d0a81c64e34798c820e98cccef694ddcd 100644 (file)
@@ -121,7 +121,6 @@ public:
   PerfCounters *&logger;
   PerfCounters *&recoverystate_perf;
   MonClient   *&monc;
-  ClassHandler  *&class_handler;
 
   md_config_cacher_t<Option::size_t> osd_max_object_size;
   md_config_cacher_t<bool> osd_skip_data_digest;
@@ -1163,7 +1162,6 @@ protected:
                    std::string_view format, std::ostream& ss);
 
 public:
-  ClassHandler  *class_handler = nullptr;
   int get_nodeid() { return whoami; }
   
   static ghobject_t get_osdmap_pobject_name(epoch_t epoch) {
index 1874220bfcac24c1f48e861bc5aa28af8ff35ef3..e7dd9aee77ec90069b800e26cf8e8241cc84134e 100644 (file)
@@ -887,7 +887,7 @@ int PrimaryLogPG::get_pgls_filter(bufferlist::const_iterator& iter, PGLSFilter *
     const std::string class_name = type.substr(0, dot);
     const std::string filter_name = type.substr(dot + 1);
     ClassHandler::ClassData *cls = NULL;
-    int r = osd->class_handler->open_class(class_name, &cls);
+    int r = ClassHandler::get_instance().open_class(class_name, &cls);
     if (r != 0) {
       derr << "Error opening class '" << class_name << "': "
            << cpp_strerror(r) << dendl;
@@ -5767,7 +5767,7 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
        tracepoint(osd, do_osd_op_pre_call, soid.oid.name.c_str(), soid.snap.val, cname.c_str(), mname.c_str());
 
        ClassHandler::ClassData *cls;
-       result = osd->class_handler->open_class(cname, &cls);
+       result = ClassHandler::get_instance().open_class(cname, &cls);
        ceph_assert(result == 0);   // init_op_flags() already verified this works.
 
        ClassHandler::ClassMethod *method = cls->get_method(mname.c_str());