]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: share compression/csum enums and corresponding stuff for common use
authorIgor Fedotov <ifedotov@mirantis.com>
Mon, 1 Aug 2016 11:32:50 +0000 (14:32 +0300)
committerIgor Fedotov <ifedotov@mirantis.com>
Wed, 19 Oct 2016 14:33:29 +0000 (14:33 +0000)
Signed-off-by: Igor Fedotov <ifedotov@mirantis.com>
15 files changed:
src/common/Checksummer.h
src/compressor/CompressionPlugin.h
src/compressor/Compressor.cc
src/compressor/Compressor.h
src/compressor/snappy/CompressionPluginSnappy.cc
src/compressor/snappy/SnappyCompressor.h
src/compressor/zlib/CompressionPluginZlib.cc
src/compressor/zlib/ZlibCompressor.h
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h
src/os/bluestore/bluestore_types.cc
src/os/bluestore/bluestore_types.h
src/osd/osd_types.cc
src/test/compressor/compressor_example.h
src/test/objectstore/test_bluestore_types.cc

index 6ddbf1d12dee537a9ee8323801a89427ee7a2648..09280f929d975a40d89f8cdac80dfa50c2ebd529 100644 (file)
@@ -9,6 +9,53 @@
 
 class Checksummer {
 public:
+  enum CSumType {
+    CSUM_NONE = 1,     //intentionally set to 1 to be aligned with OSDMnitor's pool_opts_t handling - it treats 0 as unset while we need to distinguish none and unset cases
+    CSUM_XXHASH32 = 2,
+    CSUM_XXHASH64 = 3,
+    CSUM_CRC32C = 4,
+    CSUM_CRC32C_16 = 5, // low 16 bits of crc32c
+    CSUM_CRC32C_8 = 6,  // low 8 bits of crc32c
+    CSUM_MAX,
+  };
+  static const char *get_csum_type_string(unsigned t) {
+    switch (t) {
+    case CSUM_NONE: return "none";
+    case CSUM_XXHASH32: return "xxhash32";
+    case CSUM_XXHASH64: return "xxhash64";
+    case CSUM_CRC32C: return "crc32c";
+    case CSUM_CRC32C_16: return "crc32c_16";
+    case CSUM_CRC32C_8: return "crc32c_8";
+    default: return "???";
+    }
+  }
+  static int get_csum_string_type(const std::string &s) {
+    if (s == "none")
+      return CSUM_NONE;
+    if (s == "xxhash32")
+      return CSUM_XXHASH32;
+    if (s == "xxhash64")
+      return CSUM_XXHASH64;
+    if (s == "crc32c")
+      return CSUM_CRC32C;
+    if (s == "crc32c_16")
+      return CSUM_CRC32C_16;
+    if (s == "crc32c_8")
+      return CSUM_CRC32C_8;
+    return -EINVAL;
+  }
+  static size_t get_csum_value_size(int csum_type) {
+    switch (csum_type) {
+    case CSUM_NONE: return 0;
+    case CSUM_XXHASH32: return 4;
+    case CSUM_XXHASH64: return 8;
+    case CSUM_CRC32C: return 4;
+    case CSUM_CRC32C_16: return 2;
+    case CSUM_CRC32C_8: return 1;
+    default: return 0;
+    }
+  }
+
   struct crc32c {
     typedef __le32 value_t;
 
index be1f6b83a8baa82d0886375de0ee946faec71c67..299840aa3ffc1df1fa5d184c57c3bf4a8890c785 100644 (file)
@@ -18,6 +18,7 @@
 #ifndef COMPRESSION_PLUGIN_H
 #define COMPRESSION_PLUGIN_H
 
+#include <iostream>
 #include "common/Mutex.h"
 #include "common/PluginRegistry.h"
 #include "Compressor.h"
@@ -35,7 +36,7 @@ namespace ceph {
     virtual ~CompressionPlugin() {}
 
     virtual int factory(CompressorRef *cs,
-                                         ostream *ss) = 0;
+                                         std::ostream *ss) = 0;
 
     virtual const char* name() {return "CompressionPlugin";}
   };
index 2ef817c57cbdb7409333e677c2f9aa9d44989fc1..46fddd9670c1f77fd717226d6bd2fe36a53112c1 100644 (file)
 
 #include "Compressor.h"
 #include "CompressionPlugin.h"
+#include "common/dout.h"
 
+const char * Compressor::get_comp_alg_name(int a) {
+  switch (a) {
+    case COMP_ALG_NONE: return "none";
+    case COMP_ALG_SNAPPY: return "snappy";
+    case COMP_ALG_ZLIB: return "zlib";
+    default: return "???";
+  }
+}
 
-CompressorRef Compressor::create(CephContext *cct, const string &type)
+boost::optional<Compressor::CompressionAlgorithm> Compressor::get_comp_alg_type(const std::string &s) {
+  if (s == "snappy")
+    return COMP_ALG_SNAPPY;
+  if (s == "zlib")
+    return COMP_ALG_ZLIB;
+  if (s == "")
+    return COMP_ALG_NONE;
+
+  return boost::optional<CompressionAlgorithm>();
+}
+
+const char *Compressor::get_comp_mode_name(int m) {
+  switch (m) {
+    case COMP_NONE: return "none";
+    case COMP_PASSIVE: return "passive";
+    case COMP_AGGRESSIVE: return "aggressive";
+    case COMP_FORCE: return "force";
+    default: return "???";
+  }
+}
+boost::optional<Compressor::CompressionMode> Compressor::get_comp_mode_type(const std::string &s) {
+  if (s == "force")
+    return COMP_FORCE;
+  if (s == "aggressive")
+    return COMP_AGGRESSIVE;
+  if (s == "passive")
+    return COMP_PASSIVE;
+  if (s == "none")
+    return COMP_NONE;
+  return boost::optional<CompressionMode>();
+}
+
+CompressorRef Compressor::create(CephContext *cct, const std::string &type)
 {
   CompressorRef cs_impl = NULL;
-  stringstream ss;
+  std::stringstream ss;
   PluginRegistry *reg = cct->get_plugin_registry();
   CompressionPlugin *factory = dynamic_cast<CompressionPlugin*>(reg->get_with_load("compressor", type));
   if (factory == NULL) {
@@ -31,3 +72,13 @@ CompressorRef Compressor::create(CephContext *cct, const string &type)
     lderr(cct) << __func__ << " factory return error " << err << dendl;
   return cs_impl;
 }
+
+CompressorRef Compressor::create(CephContext *cct, int alg)
+{
+  if (alg < 0 || alg >= COMP_ALG_LAST) {
+    lderr(cct) << __func__ << " invalid algorithm value:" << alg << dendl;
+    return CompressorRef();
+  }
+  std::string type_name = get_comp_alg_name(alg);
+  return create(cct, type_name);
+}
index a9f91038938bb14ae5e5c14fa2b8a603f8f75f58..89687f2ddc9910de9f3673ea810deda4201ef9f8 100644 (file)
 #ifndef CEPH_COMPRESSOR_H
 #define CEPH_COMPRESSOR_H
 
-#include "include/int_types.h"
-#include "include/Context.h"
+#include <string>
+#include <boost/optional.hpp>
+#include "include/memory.h"
+#include "include/buffer.h"
 
 class Compressor;
 typedef shared_ptr<Compressor> CompressorRef;
 
 class Compressor {
-protected:
-  string type;
 public:
-  Compressor(string t) : type(t) {}
+  enum CompressionAlgorithm {
+    COMP_ALG_NONE = 0,
+    COMP_ALG_SNAPPY = 1,
+    COMP_ALG_ZLIB = 2,
+    COMP_ALG_LAST      //the last value for range checks
+  };
+  // compression options
+  enum CompressionMode {
+    COMP_NONE,                  ///< compress never
+    COMP_PASSIVE,               ///< compress if hinted COMPRESSIBLE
+    COMP_AGGRESSIVE,            ///< compress unless hinted INCOMPRESSIBLE
+    COMP_FORCE                  ///< compress always
+  };
+
+  static const char * get_comp_alg_name(int a);
+  static boost::optional<CompressionAlgorithm> get_comp_alg_type(const std::string &s);
+
+  static const char *get_comp_mode_name(int m);
+  static boost::optional<CompressionMode> get_comp_mode_type(const std::string &s);
+
+  Compressor(CompressionAlgorithm a, const char* t) : alg(a), type(t) {
+  }
   virtual ~Compressor() {}
-  const string& get_type() const {
+  const std::string& get_type_name() const {
     return type;
   }
+  CompressionAlgorithm get_type() const {
+    return alg;
+  }
   virtual int compress(const bufferlist &in, bufferlist &out) = 0;
   virtual int decompress(const bufferlist &in, bufferlist &out) = 0;
   // this is a bit weird but we need non-const iterator to be in
   // alignment with decode methods
   virtual int decompress(bufferlist::iterator &p, size_t compressed_len, bufferlist &out) = 0;
 
-  static CompressorRef create(CephContext *cct, const string &type);
+  static CompressorRef create(CephContext *cct, const std::string &type);
+  static CompressorRef create(CephContext *cct, int alg);
+
+protected:
+  CompressionAlgorithm alg;
+  std::string type;
+
 };
 
 #endif
index d0780f38d31b4491dfe88fc4175febd2583ac7fa..e53444aa04af7afb796cb88138f668efca23b850 100644 (file)
@@ -27,7 +27,7 @@ public:
   {}
 
   virtual int factory(CompressorRef *cs,
-                      ostream *ss)
+                      std::ostream *ss)
   {
     if (compressor == 0) {
       SnappyCompressor *interface = new SnappyCompressor();
index f842fc9c526aadf854143b7e9859af9cc74faabf..dadd17902b8bae0dd1c2d5276b9cb1e371cb573d 100644 (file)
@@ -56,7 +56,7 @@ class CEPH_BUFFER_API BufferlistSource : public snappy::Source {
 
 class SnappyCompressor : public Compressor {
  public:
-  SnappyCompressor() : Compressor("snappy") {}
+  SnappyCompressor() : Compressor(COMP_ALG_SNAPPY, "snappy") {}
 
   int compress(const bufferlist &src, bufferlist &dst) override {
     BufferlistSource source(const_cast<bufferlist&>(src).begin(), src.length());
index d0e90eca1976c36bdb606e550f08c35c5412bb75..7146bf9dca96db84138c326907bfb58e384e9e64 100644 (file)
@@ -33,7 +33,7 @@ public:
   {}
 
   virtual int factory(CompressorRef *cs,
-                      ostream *ss)
+                      std::ostream *ss)
   {
     bool isal;
     if (cct->_conf->compressor_zlib_isal) {
index c6ef12c82ba892baeb0f546060f5b42886693a73..35f9df3ef156be47fba8d8551b6a297702b9a1f5 100644 (file)
@@ -22,7 +22,7 @@
 class ZlibCompressor : public Compressor {
   bool isal_enabled;
 public:
-  ZlibCompressor(bool isal) : Compressor("zlib"), isal_enabled(isal) {}
+  ZlibCompressor(bool isal) : Compressor(COMP_ALG_ZLIB, "zlib"), isal_enabled(isal) {}
 
   int compress(const bufferlist &in, bufferlist &out) override;
   int decompress(const bufferlist &in, bufferlist &out) override;
index e1fd1f8b32113814b6d47a9536f74b0c65e2e4a4..91576a754d7dd084497403bfd8217cd6e4b52e64 100644 (file)
@@ -2475,7 +2475,7 @@ BlueStore::BlueStore(CephContext *cct, const string& path)
     kv_stop(false),
     logger(NULL),
     debug_read_error_lock("BlueStore::debug_read_error_lock"),
-    csum_type(bluestore_blob_t::CSUM_CRC32C),
+    csum_type(Checksummer::CSUM_CRC32C),
     sync_wal_apply(cct->_conf->bluestore_sync_wal_apply)
 {
   _init_logger();
@@ -2546,67 +2546,47 @@ void BlueStore::_set_compression()
   comp_min_blob_size = g_conf->bluestore_compression_min_blob_size;
   comp_max_blob_size = g_conf->bluestore_compression_max_blob_size;
 
-  if (g_conf->bluestore_compression == "force") {
-    comp_mode = COMP_FORCE;
-  } else if (g_conf->bluestore_compression == "aggressive") {
-    comp_mode = COMP_AGGRESSIVE;
-  } else if (g_conf->bluestore_compression == "passive") {
-    comp_mode = COMP_PASSIVE;
-  } else if (g_conf->bluestore_compression == "none") {
-    comp_mode = COMP_NONE;
+  auto m = Compressor::get_comp_mode_type(g_conf->bluestore_compression);
+  if (m) {
+    comp_mode = *m;
   } else {
     derr << __func__ << " unrecognized value '"
          << g_conf->bluestore_compression
          << "' for bluestore_compression, reverting to 'none'"
          << dendl;
-    comp_mode = COMP_NONE;
+    comp_mode = Compressor::COMP_NONE;
   }
 
   compressor = nullptr;
-  if (comp_mode.load() != COMP_NONE) {
-    const char *alg = 0;
-    if (g_conf->bluestore_compression_algorithm == "snappy") {
-      alg = "snappy";
-    } else if (g_conf->bluestore_compression_algorithm == "zlib") {
-      alg = "zlib";
-    } else if (g_conf->bluestore_compression_algorithm.length()) {
-      derr << __func__ << " unrecognized compression algorithm '"
-          << g_conf->bluestore_compression_algorithm << "'"
-           << ", reverting compression mode to 'none'"
-           << dendl;
-      comp_mode = COMP_NONE;
-    } else {
-      derr << __func__ << " compression algorithm not specified, "
-           << "reverting compression mode to 'none'"
-           << dendl;
-      comp_mode = COMP_NONE;
-    }
+  if (comp_mode.load() != Compressor::COMP_NONE) {    
+
+    auto& alg_name = g_conf->bluestore_compression_algorithm;
 
-    if (alg) {
-      compressor = Compressor::create(cct, alg);
+    if (!alg_name.empty()) {
+      compressor = Compressor::create(cct, alg_name);
       if (!compressor) {
-        derr << __func__ << " unable to initialize " << alg << " compressor"
+        derr << __func__ << " unable to initialize " << alg_name << " compressor"
              << ", reverting compression mode to 'none'" 
             << dendl;
-        comp_mode = COMP_NONE;
+        comp_mode = Compressor::COMP_NONE;
       }
     }
   }
  
-  dout(10) << __func__ << " mode " << get_comp_mode_name(comp_mode)
-          << " alg " << (compressor ? compressor->get_type() : "(none)")
+  dout(10) << __func__ << " mode " << Compressor::get_comp_mode_name(comp_mode)
+          << " alg " << (compressor ? compressor->get_type_name() : "(none)")
           << dendl;
 }
 
 void BlueStore::_set_csum()
 {
-  csum_type = bluestore_blob_t::CSUM_NONE;
-  int t = bluestore_blob_t::get_csum_string_type(g_conf->bluestore_csum_type);
-  if (t > bluestore_blob_t::CSUM_NONE)
+  csum_type = Checksummer::CSUM_NONE;
+  int t = Checksummer::get_csum_string_type(g_conf->bluestore_csum_type);
+  if (t > Checksummer::CSUM_NONE)
     csum_type = t;
 
   dout(10) << __func__ << " csum_type "
-          << bluestore_blob_t::get_csum_type_string(csum_type)
+          << Checksummer::get_csum_type_string(csum_type)
           << dendl;
 }
 
@@ -5168,7 +5148,7 @@ int BlueStore::_verify_csum(OnodeRef& o,
           return 0;
        });
       assert(r == 0);
-      derr << __func__ << " bad " << blob->get_csum_type_string(blob->csum_type)
+      derr << __func__ << " bad " << Checksummer::get_csum_type_string(blob->csum_type)
           << "/0x" << std::hex << blob->get_csum_chunk_size()
           << " checksum at blob offset 0x" << bad
           << ", got 0x" << bad_csum << ", expected 0x"
@@ -5190,15 +5170,16 @@ int BlueStore::_decompress(bufferlist& source, bufferlist* result)
   bufferlist::iterator i = source.begin();
   bluestore_compression_header_t chdr;
   ::decode(chdr, i);
-  string name = bluestore_blob_t::get_comp_alg_name(chdr.type);
+  int alg = int(chdr.type);
   CompressorRef cp = compressor;
-  if (!cp || cp->get_type() != name)
-    cp = Compressor::create(cct, name);
+  if (!cp || (int)cp->get_type() != alg) {
+    cp = Compressor::create(cct, alg);
+  }
 
   if (!cp.get()) {
     // if compressor isn't available - error, because cannot return
     // decompressed data?
-    derr << __func__ << " can't load decompressor " << (int)chdr.type << dendl;
+    derr << __func__ << " can't load decompressor " << alg << dendl;
     r = -EIO;
   } else {
     r = cp->decompress(i, chdr.length, *result);
@@ -7611,7 +7592,7 @@ int BlueStore::_do_alloc_write(
       assert(b_off == 0);
       assert(wi.blob_length == l->length());
       bluestore_compression_header_t chdr;
-      chdr.type = bluestore_blob_t::get_comp_alg_type(c->get_type());
+      chdr.type = c->get_type();
       // FIXME: memory alignment here is bad
       bufferlist t;
 
@@ -7880,10 +7861,10 @@ int BlueStore::_do_write(
   unsigned alloc_hints = o->onode.alloc_hint_flags;
   int comp = comp_mode.load();
   wctx.compress =
-    (comp == COMP_FORCE) ||
-    (comp == COMP_AGGRESSIVE &&
+    (comp == Compressor::COMP_FORCE) ||
+    (comp == Compressor::COMP_AGGRESSIVE &&
      (alloc_hints & CEPH_OSD_ALLOC_HINT_FLAG_INCOMPRESSIBLE) == 0) ||
-    (comp == COMP_PASSIVE &&
+    (comp == Compressor::COMP_PASSIVE &&
      (alloc_hints & CEPH_OSD_ALLOC_HINT_FLAG_COMPRESSIBLE));
 
   if ((alloc_hints & CEPH_OSD_ALLOC_HINT_FLAG_SEQUENTIAL_READ) &&
index 39ddef7a712486abc05117bf6f17432d601a450c..acdb8e17b91bcb6feb9b1852e15eaa723f93f85d 100644 (file)
@@ -1466,23 +1466,7 @@ private:
 
   bool sync_wal_apply;   ///< see config option bluestore_sync_wal_apply
 
-  // compression options
-  enum CompressionMode {
-    COMP_NONE,                  ///< compress never
-    COMP_PASSIVE,               ///< compress if hinted COMPRESSIBLE
-    COMP_AGGRESSIVE,            ///< compress unless hinted INCOMPRESSIBLE
-    COMP_FORCE                  ///< compress always
-  };
-  const char *get_comp_mode_name(int m) {
-    switch (m) {
-    case COMP_NONE: return "none";
-    case COMP_PASSIVE: return "passive";
-    case COMP_AGGRESSIVE: return "aggressive";
-    case COMP_FORCE: return "force";
-    default: return "???";
-    }
-  }
-  std::atomic<int> comp_mode = {COMP_NONE}; ///< compression mode
+  std::atomic<Compressor::CompressionMode> comp_mode = {Compressor::COMP_NONE}; ///< compression mode
   CompressorRef compressor;
   std::atomic<uint64_t> comp_min_blob_size = {0};
   std::atomic<uint64_t> comp_max_blob_size = {0};
index c7be9a2f5f7c6117e577256852ea34f9c74a3a16..f24a94fd6b1172d2d212ed099b2a1aa47b1d8ad8 100644 (file)
@@ -388,6 +388,11 @@ string bluestore_blob_t::get_flags_string(unsigned flags)
   return s;
 }
 
+size_t bluestore_blob_t::get_csum_value_size() const 
+{
+  return Checksummer::get_csum_value_size(csum_type);
+}
+
 void bluestore_blob_t::dump(Formatter *f) const
 {
   f->open_array_section("extents");
@@ -416,7 +421,7 @@ void bluestore_blob_t::generate_test_instances(list<bluestore_blob_t*>& ls)
   ls.push_back(new bluestore_blob_t);
   ls.back()->extents.push_back(bluestore_pextent_t(111, 222));
   ls.push_back(new bluestore_blob_t);
-  ls.back()->init_csum(CSUM_XXHASH32, 16, 65536);
+  ls.back()->init_csum(Checksummer::CSUM_XXHASH32, 16, 65536);
   ls.back()->csum_data = buffer::claim_malloc(4, strdup("abcd"));
   ls.back()->add_unused(0, 3);
   ls.back()->add_unused(8, 8);
@@ -443,7 +448,7 @@ ostream& operator<<(ostream& out, const bluestore_blob_t& o)
     out << " " << o.get_flags_string();
   }
   if (o.csum_type) {
-    out << " " << o.get_csum_type_string(o.csum_type)
+    out << " " << Checksummer::get_csum_type_string(o.csum_type)
        << "/0x" << std::hex << (1ull << o.csum_chunk_order) << std::dec;
   }
   if (o.has_unused())
@@ -455,23 +460,23 @@ ostream& operator<<(ostream& out, const bluestore_blob_t& o)
 void bluestore_blob_t::calc_csum(uint64_t b_off, const bufferlist& bl)
 {
   switch (csum_type) {
-  case CSUM_XXHASH32:
+  case Checksummer::CSUM_XXHASH32:
     Checksummer::calculate<Checksummer::xxhash32>(
       get_csum_chunk_size(), b_off, bl.length(), bl, &csum_data);
     break;
-  case CSUM_XXHASH64:
+  case Checksummer::CSUM_XXHASH64:
     Checksummer::calculate<Checksummer::xxhash64>(
       get_csum_chunk_size(), b_off, bl.length(), bl, &csum_data);
     break;;
-  case CSUM_CRC32C:
+  case Checksummer::CSUM_CRC32C:
     Checksummer::calculate<Checksummer::crc32c>(
       get_csum_chunk_size(), b_off, bl.length(), bl, &csum_data);
     break;
-  case CSUM_CRC32C_16:
+  case Checksummer::CSUM_CRC32C_16:
     Checksummer::calculate<Checksummer::crc32c_16>(
       get_csum_chunk_size(), b_off, bl.length(), bl, &csum_data);
     break;
-  case CSUM_CRC32C_8:
+  case Checksummer::CSUM_CRC32C_8:
     Checksummer::calculate<Checksummer::crc32c_8>(
       get_csum_chunk_size(), b_off, bl.length(), bl, &csum_data);
     break;
@@ -485,25 +490,25 @@ int bluestore_blob_t::verify_csum(uint64_t b_off, const bufferlist& bl,
 
   *b_bad_off = -1;
   switch (csum_type) {
-  case CSUM_NONE:
+  case Checksummer::CSUM_NONE:
     break;
-  case CSUM_XXHASH32:
+  case Checksummer::CSUM_XXHASH32:
     *b_bad_off = Checksummer::verify<Checksummer::xxhash32>(
       get_csum_chunk_size(), b_off, bl.length(), bl, csum_data, bad_csum);
     break;
-  case CSUM_XXHASH64:
+  case Checksummer::CSUM_XXHASH64:
     *b_bad_off = Checksummer::verify<Checksummer::xxhash64>(
       get_csum_chunk_size(), b_off, bl.length(), bl, csum_data, bad_csum);
     break;
-  case CSUM_CRC32C:
+  case Checksummer::CSUM_CRC32C:
     *b_bad_off = Checksummer::verify<Checksummer::crc32c>(
       get_csum_chunk_size(), b_off, bl.length(), bl, csum_data, bad_csum);
     break;
-  case CSUM_CRC32C_16:
+  case Checksummer::CSUM_CRC32C_16:
     *b_bad_off = Checksummer::verify<Checksummer::crc32c_16>(
       get_csum_chunk_size(), b_off, bl.length(), bl, csum_data, bad_csum);
     break;
-  case CSUM_CRC32C_8:
+  case Checksummer::CSUM_CRC32C_8:
     *b_bad_off = Checksummer::verify<Checksummer::crc32c_8>(
       get_csum_chunk_size(), b_off, bl.length(), bl, csum_data, bad_csum);
     break;
index e1babc66ba447f3d9b793713fb99760d20aefaf3..470dcd0e0b680c160e83cd2be4571a2bba47e91f 100644 (file)
@@ -22,6 +22,8 @@
 #include "include/utime.h"
 #include "include/small_encoding.h"
 #include "common/hobject.h"
+#include "compressor/Compressor.h"
+#include "common/Checksummer.h"
 
 namespace ceph {
   class Formatter;
@@ -273,76 +275,13 @@ struct bluestore_blob_t {
   };
   static string get_flags_string(unsigned flags);
 
-  enum CSumType {
-    CSUM_NONE = 0,
-    CSUM_XXHASH32 = 1,
-    CSUM_XXHASH64 = 2,
-    CSUM_CRC32C = 3,
-    CSUM_CRC32C_16 = 4, // low 16 bits of crc32c
-    CSUM_CRC32C_8 = 5,  // low 8 bits of crc32c
-    CSUM_MAX,
-  };
-  static const char *get_csum_type_string(unsigned t) {
-    switch (t) {
-    case CSUM_NONE: return "none";
-    case CSUM_XXHASH32: return "xxhash32";
-    case CSUM_XXHASH64: return "xxhash64";
-    case CSUM_CRC32C: return "crc32c";
-    case CSUM_CRC32C_16: return "crc32c_16";
-    case CSUM_CRC32C_8: return "crc32c_8";
-    default: return "???";
-    }
-  }
-  static int get_csum_string_type(const std::string &s) {
-    if (s == "none")
-      return CSUM_NONE;
-    if (s == "xxhash32")
-      return CSUM_XXHASH32;
-    if (s == "xxhash64")
-      return CSUM_XXHASH64;
-    if (s == "crc32c")
-      return CSUM_CRC32C;
-    if (s == "crc32c_16")
-      return CSUM_CRC32C_16;
-    if (s == "crc32c_8")
-      return CSUM_CRC32C_8;
-    return -EINVAL;
-  }
-
-  enum CompressionAlgorithm {
-    COMP_ALG_NONE = 0,
-    COMP_ALG_SNAPPY = 1,
-    COMP_ALG_ZLIB = 2,
-  };
-
-  static const char * get_comp_alg_name(int a) {
-    switch (a) {
-    case COMP_ALG_NONE: return "none";
-    case COMP_ALG_SNAPPY: return "snappy";
-    case COMP_ALG_ZLIB: return "zlib";
-    default: return "???";
-    }
-  }
-
-  static int get_comp_alg_type(const std::string &s) {
-    if (s == "none")
-      return COMP_ALG_NONE;
-    if (s == "snappy")
-      return COMP_ALG_SNAPPY;
-    if (s == "zlib")
-      return COMP_ALG_ZLIB;
-
-    assert(0 == "invalid compression algorithm");
-    return COMP_ALG_NONE;
-  }
-
   vector<bluestore_pextent_t> extents;///< raw data position on device
   uint64_t sbid = 0;                  ///< shared blob id (if shared)
   uint32_t compressed_length_orig = 0;///< original length of compressed blob if any
   uint32_t compressed_length = 0;     ///< compressed length if any
   uint32_t flags = 0;                 ///< FLAG_*
 
-  uint8_t csum_type = CSUM_NONE;      ///< CSUM_*
+  uint8_t csum_type = Checksummer::CSUM_NONE;      ///< CSUM_*
   uint8_t csum_chunk_order = 0;       ///< csum block size is 1<<block_order bytes
 
   bufferptr csum_data;                ///< opaque vector of csum data
@@ -627,18 +566,8 @@ struct bluestore_blob_t {
       return get_ondisk_length();
     }
   }
+  size_t get_csum_value_size() const;
 
-  size_t get_csum_value_size() const {
-    switch (csum_type) {
-    case CSUM_NONE: return 0;
-    case CSUM_XXHASH32: return 4;
-    case CSUM_XXHASH64: return 8;
-    case CSUM_CRC32C: return 4;
-    case CSUM_CRC32C_16: return 2;
-    case CSUM_CRC32C_8: return 1;
-    default: return 0;
-    }
-  }
   size_t get_csum_count() const {
     size_t vs = get_csum_value_size();
     if (!vs)
@@ -823,7 +752,7 @@ struct bluestore_wal_transaction_t {
 WRITE_CLASS_DENC(bluestore_wal_transaction_t)
 
 struct bluestore_compression_header_t {
-  uint8_t type = bluestore_blob_t::COMP_ALG_NONE;
+  uint8_t type = Compressor::COMP_ALG_NONE;
   uint32_t length = 0;
 
   bluestore_compression_header_t() {}
index f5510c776e9ffefe4fede17442fdbcfe77f3a18b..e8054957a49d32549cf48f470f0e2ce013af6f3b 100644 (file)
@@ -5407,4 +5407,4 @@ ostream& operator<<(ostream& out, const store_statfs_t &s)
       << std::dec
       << ")";
   return out;
-}
+}
\ No newline at end of file
index 40ab660878c42ab32a0da533619fb88588fd6586..058dbcaf0cbb2679ef4887ff1a97d93cc1aa2b3c 100644 (file)
@@ -29,7 +29,7 @@
 
 class CompressorExample : public Compressor {
 public:
-  CompressorExample() : Compressor("example") {}
+  CompressorExample() : Compressor(COMP_ALG_NONE, "example") {}
   virtual ~CompressorExample() {}
 
   virtual int compress(const bufferlist &in, bufferlist &out)
index 878c09e007fe11005c9b05ab23405924e77c6f13..8221880b15c5c724d79746d77a29f1e8dee05147 100644 (file)
@@ -236,9 +236,9 @@ TEST(bluestore_blob_t, calc_csum)
   n.append("12345678");
 
   for (unsigned csum_type = 1;
-       csum_type < bluestore_blob_t::CSUM_MAX;
+       csum_type < Checksummer::CSUM_MAX;
        ++csum_type) {
-    cout << "csum_type " << bluestore_blob_t::get_csum_type_string(csum_type)
+    cout << "csum_type " << Checksummer::get_csum_type_string(csum_type)
         << std::endl;
 
     bluestore_blob_t b;
@@ -297,7 +297,7 @@ TEST(bluestore_blob_t, csum_bench)
   bl.append(bp);
   int count = 256;
   for (unsigned csum_type = 1;
-       csum_type < bluestore_blob_t::CSUM_MAX;
+       csum_type < Checksummer::CSUM_MAX;
        ++csum_type) {
     bluestore_blob_t b;
     b.init_csum(csum_type, 12, bl.length());
@@ -308,7 +308,7 @@ TEST(bluestore_blob_t, csum_bench)
     ceph::mono_clock::time_point end = ceph::mono_clock::now();
     auto dur = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start);
     double mbsec = (double)count * (double)bl.length() / 1000000.0 / (double)dur.count() * 1000000000.0;
-    cout << "csum_type " << bluestore_blob_t::get_csum_type_string(csum_type)
+    cout << "csum_type " << Checksummer::get_csum_type_string(csum_type)
         << ", " << dur << " seconds, "
         << mbsec << " MB/sec" << std::endl;
   }
@@ -682,7 +682,7 @@ TEST(Blob, put_ref)
     bluestore_blob_t& b = B.dirty_blob();
     vector<bluestore_pextent_t> r;
     b.extents.push_back(bluestore_pextent_t(0, mas*4));
-    b.init_csum(bluestore_blob_t::CSUM_CRC32C, 14, mas * 4);
+    b.init_csum(Checksummer::CSUM_CRC32C, 14, mas * 4);
     B.get_ref(0, mas*4);
     ASSERT_TRUE(b.is_allocated(0, mas*4));
     B.put_ref(0, mas*3, mrs, &r);
@@ -715,7 +715,7 @@ TEST(bluestore_blob_t, can_split_at)
   a.extents.emplace_back(bluestore_pextent_t(0x20000, 0x2000));
   ASSERT_TRUE(a.can_split_at(0x1000));
   ASSERT_TRUE(a.can_split_at(0x1800));
-  a.init_csum(bluestore_blob_t::CSUM_CRC32C, 12, 0x4000);
+  a.init_csum(Checksummer::CSUM_CRC32C, 12, 0x4000);
   ASSERT_TRUE(a.can_split_at(0x1000));
   ASSERT_TRUE(a.can_split_at(0x2000));
   ASSERT_TRUE(a.can_split_at(0x3000));
@@ -739,7 +739,7 @@ TEST(bluestore_blob_t, prune_tail)
 
   a.extents.emplace_back(
     bluestore_pextent_t(bluestore_pextent_t::INVALID_OFFSET, 0x2000));
-  a.init_csum(bluestore_blob_t::CSUM_CRC32C_8, 12, 0x6000);
+  a.init_csum(Checksummer::CSUM_CRC32C_8, 12, 0x6000);
   ASSERT_EQ(6u, a.csum_data.length());
   ASSERT_TRUE(a.can_prune_tail());
   a.prune_tail();
@@ -764,7 +764,7 @@ TEST(Blob, split)
     R.shared_blob = new BlueStore::SharedBlob(-1, string(), cache);
     R.shared_blob->get();  // hack to avoid dtor from running
     L.dirty_blob().extents.emplace_back(bluestore_pextent_t(0x2000, 0x2000));
-    L.dirty_blob().init_csum(bluestore_blob_t::CSUM_CRC32C, 12, 0x2000);
+    L.dirty_blob().init_csum(Checksummer::CSUM_CRC32C, 12, 0x2000);
     L.split(0x1000, &R);
     ASSERT_EQ(0x1000u, L.get_blob().get_logical_length());
     ASSERT_EQ(4u, L.get_blob().csum_data.length());
@@ -785,7 +785,7 @@ TEST(Blob, split)
     R.shared_blob->get();  // hack to avoid dtor from running
     L.dirty_blob().extents.emplace_back(bluestore_pextent_t(0x2000, 0x1000));
     L.dirty_blob().extents.emplace_back(bluestore_pextent_t(0x12000, 0x1000));
-    L.dirty_blob().init_csum(bluestore_blob_t::CSUM_CRC32C, 12, 0x2000);
+    L.dirty_blob().init_csum(Checksummer::CSUM_CRC32C, 12, 0x2000);
     L.split(0x1000, &R);
     ASSERT_EQ(0x1000u, L.get_blob().get_logical_length());
     ASSERT_EQ(4u, L.get_blob().csum_data.length());