]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
embedded: add compression and EC plugins to libcephd
authorBassam Tabbara <bassam.tabbara@quantum.com>
Sat, 5 Nov 2016 01:10:08 +0000 (18:10 -0700)
committerBassam Tabbara <bassam.tabbara@quantum.com>
Tue, 29 Nov 2016 07:48:02 +0000 (23:48 -0800)
Compression and erasure coding plugins are now statically compiled
into libcephd. A new method is added to load them into the
respective registry.

The static libraries are only built when WITH_EMBEDDED is enabled
and existing plugins are unaffected.

Signed-off-by: Bassam Tabbara <bassam.tabbara@quantum.com>
19 files changed:
src/ceph_osd.cc
src/compressor/CMakeLists.txt
src/compressor/snappy/CMakeLists.txt
src/compressor/snappy/CompressionPluginSnappy.cc
src/compressor/snappy/CompressionPluginSnappy.h [new file with mode: 0644]
src/compressor/zlib/CMakeLists.txt
src/compressor/zlib/CompressionPluginZlib.cc
src/compressor/zlib/CompressionPluginZlib.h [new file with mode: 0644]
src/erasure-code/CMakeLists.txt
src/erasure-code/isa/CMakeLists.txt
src/erasure-code/isa/ErasureCodePluginIsa.cc
src/erasure-code/jerasure/CMakeLists.txt
src/erasure-code/jerasure/ErasureCodePluginJerasure.cc
src/erasure-code/lrc/CMakeLists.txt
src/erasure-code/lrc/ErasureCodePluginLrc.cc
src/erasure-code/shec/CMakeLists.txt
src/erasure-code/shec/ErasureCodePluginShec.cc
src/libcephd/CMakeLists.txt
src/libcephd/libcephd.cc

index b7724e8eb49486400da48a19b5e4ca8c7c04ade6..5f1f26e16d6774cf8fcf4eece42eccab66679fe1 100644 (file)
@@ -249,6 +249,10 @@ int main(int argc, const char **argv)
     return -ENODEV;
   }
 
+#ifdef BUILDING_FOR_EMBEDDED
+  cephd_preload_embedded_plugins();
+#endif
+
   if (mkfs) {
     common_init_finish(g_ceph_context);
     MonClient mc(g_ceph_context);
@@ -603,6 +607,10 @@ int main(int argc, const char **argv)
     return 1;
   }
 
+#ifdef BUILDING_FOR_EMBEDDED
+  cephd_preload_rados_classes(osd);
+#endif
+
   // install signal handlers
   init_async_signal_handler();
   register_async_signal_handler(SIGHUP, sighup_handler);
index 36b0a90ceb4b3e905ec4d7a6522e0974f88e7317..436ea3eb1df30f68ef338fcd740013e367b14dff 100644 (file)
@@ -14,3 +14,10 @@ add_subdirectory(zlib)
 add_custom_target(compressor_plugins DEPENDS
     ceph_snappy
     ceph_zlib)
+
+if(WITH_EMBEDDED)
+  include(MergeStaticLibraries)
+  add_library(cephd_compressor_base STATIC ${compressor_srcs})
+  set_target_properties(cephd_compressor_base PROPERTIES COMPILE_DEFINITIONS BUILDING_FOR_EMBEDDED)
+  merge_static_libraries(cephd_compressor cephd_compressor_base cephd_compressor_snappy cephd_compressor_zlib)
+endif()
index 1fa07c237b4accf3ad225cb59cfd4204bb883f6c..108aea204020a45f1f19cade62dcf6ac1fb75a43 100644 (file)
@@ -9,3 +9,8 @@ add_dependencies(ceph_snappy ${CMAKE_SOURCE_DIR}/src/ceph_ver.h)
 target_link_libraries(ceph_snappy snappy common)
 set_target_properties(ceph_snappy PROPERTIES VERSION 2.0.0 SOVERSION 2)
 install(TARGETS ceph_snappy DESTINATION ${compressor_plugin_dir})
+
+if(WITH_EMBEDDED)
+  add_library(cephd_compressor_snappy STATIC ${snappy_sources})
+  set_target_properties(cephd_compressor_snappy PROPERTIES COMPILE_DEFINITIONS BUILDING_FOR_EMBEDDED)
+endif()
index e53444aa04af7afb796cb88138f668efca23b850..f4e8c3819d9ea633081c4c82a117b565bb1683c8 100644 (file)
 
 
 // -----------------------------------------------------------------------------
+#include "acconfig.h"
 #include "ceph_ver.h"
-#include "compressor/CompressionPlugin.h"
-#include "SnappyCompressor.h"
-// -----------------------------------------------------------------------------
-
-class CompressionPluginSnappy : public CompressionPlugin {
-
-public:
+#include "CompressionPluginSnappy.h"
 
-  explicit CompressionPluginSnappy(CephContext* cct) : CompressionPlugin(cct)
-  {}
-
-  virtual int factory(CompressorRef *cs,
-                      std::ostream *ss)
-  {
-    if (compressor == 0) {
-      SnappyCompressor *interface = new SnappyCompressor();
-      compressor = CompressorRef(interface);
-    }
-    *cs = compressor;
-    return 0;
-  }
-};
+#ifndef BUILDING_FOR_EMBEDDED
 
 // -----------------------------------------------------------------------------
 
@@ -55,3 +37,5 @@ int __ceph_plugin_init(CephContext *cct,
 
   return instance->add(type, name, new CompressionPluginSnappy(cct));
 }
+
+#endif // !BUILDING_FOR_EMBEDDED
\ No newline at end of file
diff --git a/src/compressor/snappy/CompressionPluginSnappy.h b/src/compressor/snappy/CompressionPluginSnappy.h
new file mode 100644 (file)
index 0000000..a744a5d
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2015 Mirantis, Inc.
+ *
+ * Author: Alyona Kiseleva <akiselyova@mirantis.com>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+
+#ifndef CEPH_COMPRESSION_PLUGIN_SNAPPY_H
+#define CEPH_COMPRESSION_PLUGIN_SNAPPY_H
+
+// -----------------------------------------------------------------------------
+#include "compressor/CompressionPlugin.h"
+#include "SnappyCompressor.h"
+// -----------------------------------------------------------------------------
+
+class CompressionPluginSnappy : public CompressionPlugin {
+
+public:
+
+  explicit CompressionPluginSnappy(CephContext* cct) : CompressionPlugin(cct)
+  {}
+
+  virtual int factory(CompressorRef *cs,
+                      std::ostream *ss)
+  {
+    if (compressor == 0) {
+      SnappyCompressor *interface = new SnappyCompressor();
+      compressor = CompressorRef(interface);
+    }
+    *cs = compressor;
+    return 0;
+  }
+};
+
+#endif
index 72d6086d383d4e95c04cd7fc9f14c083a20ea55d..19a84da51a54f607a0b00369e99290aab5535ec4 100644 (file)
@@ -33,3 +33,9 @@ target_link_libraries(ceph_zlib z common)
 target_include_directories(ceph_zlib PRIVATE "${CMAKE_SOURCE_DIR}/src/isa-l/include")
 set_target_properties(ceph_zlib PROPERTIES VERSION 2.0.0 SOVERSION 2)
 install(TARGETS ceph_zlib DESTINATION ${compressor_plugin_dir})
+
+if(WITH_EMBEDDED)
+  add_library(cephd_compressor_zlib STATIC ${zlib_sources})
+       target_include_directories(cephd_compressor_zlib PRIVATE "${CMAKE_SOURCE_DIR}/src/isa-l/include")
+  set_target_properties(cephd_compressor_zlib PROPERTIES COMPILE_DEFINITIONS BUILDING_FOR_EMBEDDED)
+endif()
index 7146bf9dca96db84138c326907bfb58e384e9e64..26969f8377a291bca6d47ee194a3426beb58328e 100644 (file)
 
 
 // -----------------------------------------------------------------------------
+#include "acconfig.h"
 #include "ceph_ver.h"
-#include "arch/probe.h"
-#include "arch/intel.h"
-#include "arch/arm.h"
-#include "compressor/CompressionPlugin.h"
-#include "ZlibCompressor.h"
-#include "common/debug.h"
-
-#define dout_subsys ceph_subsys_mon
-// -----------------------------------------------------------------------------
-
-class CompressionPluginZlib : public CompressionPlugin {
-public:
-  bool has_isal = false;
-
-  explicit CompressionPluginZlib(CephContext *cct) : CompressionPlugin(cct)
-  {}
-
-  virtual int factory(CompressorRef *cs,
-                      std::ostream *ss)
-  {
-    bool isal;
-    if (cct->_conf->compressor_zlib_isal) {
-      ceph_arch_probe();
-      isal = (ceph_arch_intel_pclmul && ceph_arch_intel_sse41);
-    } else {
-      isal = false;
-    }
-    if (compressor == 0 || has_isal != isal) {
-      compressor = CompressorRef(new ZlibCompressor(isal));
-      has_isal = isal;
-    }
-    *cs = compressor;
-    return 0;
-  }
-};
+#include "CompressionPluginZlib.h"
 
+#ifndef BUILDING_FOR_EMBEDDED
 // -----------------------------------------------------------------------------
 
 const char *__ceph_plugin_version()
@@ -68,3 +36,5 @@ int __ceph_plugin_init(CephContext *cct,
 
   return instance->add(type, name, new CompressionPluginZlib(cct));
 }
+
+#endif // !BUILDING_FOR_EMBEDDED
diff --git a/src/compressor/zlib/CompressionPluginZlib.h b/src/compressor/zlib/CompressionPluginZlib.h
new file mode 100644 (file)
index 0000000..e73afd8
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2015 Mirantis, Inc.
+ *
+ * Author: Alyona Kiseleva <akiselyova@mirantis.com>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+
+#ifndef CEPH_COMPRESSION_PLUGIN_ZLIB_H
+#define CEPH_COMPRESSION_PLUGIN_ZLIB_H
+
+// -----------------------------------------------------------------------------
+#include "arch/probe.h"
+#include "arch/intel.h"
+#include "arch/arm.h"
+#include "common/config.h"
+#include "compressor/CompressionPlugin.h"
+#include "ZlibCompressor.h"
+
+// -----------------------------------------------------------------------------
+
+class CompressionPluginZlib : public CompressionPlugin {
+public:
+  bool has_isal = false;
+
+  explicit CompressionPluginZlib(CephContext *cct) : CompressionPlugin(cct)
+  {}
+
+  virtual int factory(CompressorRef *cs,
+                      std::ostream *ss)
+  {
+    bool isal;
+    if (cct->_conf->compressor_zlib_isal) {
+      ceph_arch_probe();
+      isal = (ceph_arch_intel_pclmul && ceph_arch_intel_sse41);
+    } else {
+      isal = false;
+    }
+    if (compressor == 0 || has_isal != isal) {
+      compressor = CompressorRef(new ZlibCompressor(isal));
+      has_isal = isal;
+    }
+    *cs = compressor;
+    return 0;
+  }
+};
+
+#endif
index 1b4870403a366962214cbb97ec04ec4ab7d05ec4..450ec716973eb2de4300f8917122042f415ad331 100644 (file)
@@ -24,6 +24,7 @@ add_subdirectory(shec)
 if (HAVE_BETTER_YASM_ELF64)
   add_subdirectory(isa)
   set(EC_ISA_LIB ec_isa)
+  set(EC_ISA_EMBEDDED_LIB cephd_ec_isa)
 endif (HAVE_BETTER_YASM_ELF64)
 
 add_library(erasure_code STATIC ErasureCodePlugin.cc)
@@ -37,3 +38,10 @@ add_custom_target(erasure_code_plugins DEPENDS
     ec_lrc
     ec_jerasure
     ec_shec)
+
+if(WITH_EMBEDDED)
+  include(MergeStaticLibraries)
+  add_library(cephd_ec_base STATIC $<TARGET_OBJECTS:erasure_code_objs>)
+  set_target_properties(cephd_ec_base PROPERTIES COMPILE_DEFINITIONS BUILDING_FOR_EMBEDDED)
+  merge_static_libraries(cephd_ec cephd_ec_base ${EC_ISA_EMBEDDED_LIB} cephd_ec_jerasure cephd_ec_lrc cephd_ec_shec)
+endif()
index 1cb530424393e7b26f42c3da189ed53a12612899..63292fa72e34b1cf370744b3737a84ea8041b8c3 100644 (file)
@@ -48,11 +48,17 @@ set(isa_srcs
   ErasureCodeIsaTableCache.cc
   ErasureCodePluginIsa.cc
   xor_op.cc
-  $<TARGET_OBJECTS:erasure_code_objs>
 )
 
-add_library(ec_isa SHARED ${isa_srcs})
+add_library(ec_isa SHARED
+  ${isa_srcs}
+  $<TARGET_OBJECTS:erasure_code_objs>)
 add_dependencies(ec_isa ${CMAKE_SOURCE_DIR}/src/ceph_ver.h)
 target_link_libraries(ec_isa ${EXTRALIBS})
 set_target_properties(ec_isa PROPERTIES VERSION 2.14.0 SOVERSION 2)
 install(TARGETS ec_isa DESTINATION ${erasure_plugin_dir})
+
+if(WITH_EMBEDDED)
+  add_library(cephd_ec_isa STATIC ${isa_srcs})
+  set_target_properties(cephd_ec_isa PROPERTIES COMPILE_DEFINITIONS BUILDING_FOR_EMBEDDED)
+endif()
index c4c37b1bf1d0f2e92c1da053967c967441bef443..1e95b0bc6a80e4263c3fee4e9af46068215785c9 100644 (file)
@@ -65,6 +65,8 @@ int ErasureCodePluginIsa::factory(const std::string &directory,
     return 0;
 }
 
+#ifndef BUILDING_FOR_EMBEDDED
+
 // -----------------------------------------------------------------------------
 
 const char *__erasure_code_version()
@@ -80,3 +82,5 @@ int __erasure_code_init(char *plugin_name, char *directory)
 
   return instance.add(plugin_name, new ErasureCodePluginIsa());
 }
+
+#endif
\ No newline at end of file
index 88c1ca40da8b445f9332bd58103ec8795edbdf74..968489e6592e39402c772205e7d83be3e895e6fd 100644 (file)
@@ -1,8 +1,10 @@
 # jerasure plugin
 
-add_library(jerasure_utils OBJECT
+set(jerasure_utils_src
   ErasureCodePluginJerasure.cc
   ErasureCodeJerasure.cc)
+
+add_library(jerasure_utils OBJECT ${jerasure_utils_src})
 add_dependencies(jerasure_utils ${CMAKE_SOURCE_DIR}/src/ceph_ver.h)
 
 # Set the CFLAGS correctly for gf-complete based on SIMD compiler support
@@ -97,3 +99,10 @@ foreach(flavor ${jerasure_legacy_flavors})
   add_dependencies(ec_jerasure ${plugin_name})
 endforeach()
 
+if(WITH_EMBEDDED)
+  add_library(cephd_ec_jerasure STATIC
+    $<TARGET_OBJECTS:gf-complete_objs>
+    $<TARGET_OBJECTS:jerasure_objs>
+    ${jerasure_utils_src})
+  set_target_properties(cephd_ec_jerasure PROPERTIES COMPILE_DEFINITIONS BUILDING_FOR_EMBEDDED)
+endif()
index 6029eef4ea9d3e05a7b3fa1d480d711cb9b156b6..3ccedb9699db444de6e696cd7ee817cb42a075f2 100644 (file)
@@ -70,6 +70,8 @@ int ErasureCodePluginJerasure::factory(const std::string& directory,
     return 0;
 }
 
+#ifndef BUILDING_FOR_EMBEDDED
+
 const char *__erasure_code_version() { return CEPH_GIT_NICE_VER; }
 
 int __erasure_code_init(char *plugin_name, char *directory)
@@ -82,3 +84,5 @@ int __erasure_code_init(char *plugin_name, char *directory)
   }
   return instance.add(plugin_name, new ErasureCodePluginJerasure());
 }
+
+#endif
\ No newline at end of file
index 9c2ac7f81237ec5a8fda7c411200362721656ddc..80f9ffcf304205cb7358713cf742351ce68e503c 100644 (file)
@@ -11,3 +11,8 @@ add_library(ec_lrc SHARED ${lrc_srcs})
 add_dependencies(ec_lrc ${CMAKE_SOURCE_DIR}/src/ceph_ver.h)
 target_link_libraries(ec_lrc crush json_spirit)
 install(TARGETS ec_lrc DESTINATION ${erasure_plugin_dir})
+
+if(WITH_EMBEDDED)
+  add_library(cephd_ec_lrc STATIC ${lrc_srcs})
+  set_target_properties(cephd_ec_lrc PROPERTIES COMPILE_DEFINITIONS BUILDING_FOR_EMBEDDED)
+endif()
index 003b3dc19ddef90101191c553f30aca99a8f595a..c2be14b016a9b20c8cfaebf84f4c78868a7c657d 100644 (file)
@@ -42,6 +42,8 @@ int ErasureCodePluginLrc::factory(const std::string &directory,
     return 0;
 };
 
+#ifndef BUILDING_FOR_EMBEDDED
+
 const char *__erasure_code_version() { return CEPH_GIT_NICE_VER; }
 
 int __erasure_code_init(char *plugin_name, char *directory)
@@ -49,3 +51,5 @@ int __erasure_code_init(char *plugin_name, char *directory)
   ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
   return instance.add(plugin_name, new ErasureCodePluginLrc());
 }
+
+#endif
index 64cac19465fe92b27b201a5f330cd3b0e6a5f8bc..2ebc50e34c2417dade11d1b2d42bb7d93bafcdfa 100644 (file)
@@ -2,12 +2,14 @@
 
 include_directories(.)
 
-add_library(shec_utils OBJECT
+set(shec_utils_srcs
   ${CMAKE_SOURCE_DIR}/src/erasure-code/ErasureCode.cc 
   ErasureCodePluginShec.cc 
   ErasureCodeShec.cc 
   ErasureCodeShecTableCache.cc 
   determinant.c)
+
+add_library(shec_utils OBJECT ${shec_utils_srcs})
 add_dependencies(shec_utils ${CMAKE_SOURCE_DIR}/src/ceph_ver.h)
 
 set(ec_shec_objs
@@ -27,3 +29,9 @@ foreach(flavor ${jerasure_legacy_flavors})
   install(TARGETS ${plugin_name} DESTINATION ${erasure_plugin_dir})
   add_dependencies(ec_shec ${plugin_name})
 endforeach()
+
+if(WITH_EMBEDDED)
+  # note we rely on the fact this will always be statically linked with jerasure
+  add_library(cephd_ec_shec STATIC ${shec_utils_srcs})
+  set_target_properties(cephd_ec_shec PROPERTIES COMPILE_DEFINITIONS BUILDING_FOR_EMBEDDED)
+endif()
index d31777e50d6309355ba63a2ed1692eb916d0036f..b55be77392969696043b48c2f9548d3230173023 100644 (file)
@@ -66,6 +66,8 @@ int ErasureCodePluginShec::factory(const std::string &directory,
     return 0;
 }
 
+#ifndef BUILDING_FOR_EMBEDDED
+
 const char *__erasure_code_version() { return CEPH_GIT_NICE_VER; }
 
 int __erasure_code_init(char *plugin_name, char *directory = (char *)"")
@@ -78,3 +80,5 @@ int __erasure_code_init(char *plugin_name, char *directory = (char *)"")
   }
   return instance.add(plugin_name, new ErasureCodePluginShec());
 }
+
+#endif
\ No newline at end of file
index 11c739836f313c9e690ecd95c524f15dc36f1412..675e2d386a5564f126fc84d5d7bbf1ab077f8191 100644 (file)
@@ -13,7 +13,10 @@ set(merge_libs
   kv
   global
   rocksdb
-  json_spirit)
+  json_spirit
+  erasure_code
+  cephd_compressor
+  cephd_ec)
 
 if(HAVE_ARMV8_CRC)
   list(APPEND merge_libs common_crc_aarch64)
index 09a87c71dfc7d64748953d1bf484592d2be74a86..f360017f5b69c438fa8f72185c6f81afbd1a40a1 100644 (file)
@@ -1,4 +1,16 @@
+#include "acconfig.h"
 #include "common/version.h"
+#include "common/PluginRegistry.h"
+#include "compressor/snappy/CompressionPluginSnappy.h"
+#include "compressor/zlib/CompressionPluginZlib.h"
+#include "erasure-code/ErasureCodePlugin.h"
+#if __x86_64__ && defined(HAVE_BETTER_YASM_ELF64)
+#include "erasure-code/isa/ErasureCodePluginIsa.h"
+#endif
+#include "erasure-code/jerasure/ErasureCodePluginJerasure.h"
+#include "erasure-code/jerasure/jerasure_init.h"
+#include "erasure-code/lrc/ErasureCodePluginLrc.h"
+#include "erasure-code/shec/ErasureCodePluginShec.h"
 #include "include/cephd/libcephd.h"
 
 extern "C" void cephd_version(int *pmajor, int *pminor, int *ppatch)
@@ -25,3 +37,75 @@ extern "C" const char *ceph_version(int *pmajor, int *pminor, int *ppatch)
     *ppatch = (n >= 3) ? patch : 0;
   return v;
 }
+
+// load the embedded plugins. This is safe to call multiple
+// times in the same process
+void cephd_preload_embedded_plugins()
+{
+  int r;
+
+  // load erasure coding plugins
+  {
+    ErasureCodePlugin* plugin;
+    ErasureCodePluginRegistry& reg = ErasureCodePluginRegistry::instance();
+    Mutex::Locker l(reg.lock);
+    reg.disable_dlclose = true;
+
+    // initialize jerasure (and gf-complete)
+    int w[] = { 4, 8, 16, 32 };
+    r = jerasure_init(4, w);
+    assert(r == 0);
+
+    plugin = new ErasureCodePluginJerasure();
+    r = reg.add("jerasure", plugin);
+    if (r == -EEXIST) {
+      delete plugin;
+    }
+    assert(r == 0);
+
+    plugin = new ErasureCodePluginLrc();
+    r = reg.add("lrc", plugin);
+    if (r == -EEXIST) {
+      delete plugin;
+    }
+    assert(r == 0);
+
+    plugin = new ErasureCodePluginShec();
+    r = reg.add("shec", plugin);
+    if (r == -EEXIST) {
+      delete plugin;
+    }
+    assert(r == 0);
+
+#if __x86_64__ && defined(HAVE_BETTER_YASM_ELF64)
+    plugin = new ErasureCodePluginIsa();
+    r = reg.add("isa", plugin);
+    if (r == -EEXIST) {
+      delete plugin;
+    }
+    assert(r == 0);
+#endif
+  }
+
+  // now load the compression plugins
+  {
+    Plugin *plugin;
+    PluginRegistry *reg = g_ceph_context->get_plugin_registry();
+    Mutex::Locker l(reg->lock);
+    reg->disable_dlclose = true;
+
+    plugin = new CompressionPluginSnappy(g_ceph_context);
+    r = reg->add("compressor", "snappy", plugin);
+    if (r == -EEXIST) {
+      delete plugin;
+    }
+    assert(r == 0);
+
+    plugin = new CompressionPluginZlib(g_ceph_context);
+    r = reg->add("compressor", "zlib", plugin);
+    if (r == -EEXIST) {
+      delete plugin;
+    }
+    assert(r == 0);
+  }
+}