]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
compressor: zlib compressor plugin cleanup 9782/head
authorVed-vampir <akiselyova@mirantis.com>
Fri, 10 Jun 2016 14:13:23 +0000 (17:13 +0300)
committerVed-vampir <akiselyova@mirantis.com>
Fri, 17 Jun 2016 14:20:48 +0000 (17:20 +0300)
Signed-off-by: Alyona Kiseleva <akiselyova@mirantis.com>
src/compressor/zlib/CMakeLists.txt
src/compressor/zlib/CompressionPluginZlib.cc
src/compressor/zlib/CompressionZlib.cc [deleted file]
src/compressor/zlib/CompressionZlib.h [deleted file]
src/compressor/zlib/Makefile.am
src/compressor/zlib/ZlibCompressor.cc [new file with mode: 0644]
src/compressor/zlib/ZlibCompressor.h [new file with mode: 0644]
src/test/compressor/test_compression_zlib.cc

index 77766dc9fa0e2ca8a07c296a643aeef10c6984d1..f80131e7b6082ba5438ae819f33e8ae62d3a2186 100644 (file)
@@ -2,7 +2,7 @@
 
 set(zlib_sources
   CompressionPluginZlib.cc
-  CompressionZlib.cc
+  ZlibCompressor.cc
 )
 
 add_library(ceph_zlib SHARED ${zlib_sources})
index 90fd561d2d617ec0c7f0025423d6334174fb68ba..7140fccba2f7bc2bcf8212342e8ae0ae5a989f59 100644 (file)
@@ -16,7 +16,7 @@
 // -----------------------------------------------------------------------------
 #include "ceph_ver.h"
 #include "compressor/CompressionPlugin.h"
-#include "CompressionZlib.h"
+#include "ZlibCompressor.h"
 #include "common/debug.h"
 
 #define dout_subsys ceph_subsys_mon
@@ -32,7 +32,7 @@ public:
                       ostream *ss)
   {
     if (compressor == 0) {
-      CompressionZlib *interface = new CompressionZlib();
+      ZlibCompressor *interface = new ZlibCompressor();
       compressor = CompressorRef(interface);
     }
     *cs = compressor;
diff --git a/src/compressor/zlib/CompressionZlib.cc b/src/compressor/zlib/CompressionZlib.cc
deleted file mode 100644 (file)
index 27aba8c..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * 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.
- *
- */
-
-// -----------------------------------------------------------------------------
-#include "common/debug.h"
-#include "CompressionZlib.h"
-#include "osd/osd_types.h"
-// -----------------------------------------------------------------------------
-
-#include <zlib.h>
-
-// -----------------------------------------------------------------------------
-#define dout_subsys ceph_subsys_compressor
-#undef dout_prefix
-#define dout_prefix _prefix(_dout)
-// -----------------------------------------------------------------------------
-
-// -----------------------------------------------------------------------------
-
-static ostream&
-_prefix(std::ostream* _dout)
-{
-  return *_dout << "CompressionZlib: ";
-}
-// -----------------------------------------------------------------------------
-
-const long unsigned int max_len = 2048;
-
-int CompressionZlib::compress(const bufferlist &in, bufferlist &out)
-{
-  int ret;
-  unsigned have;
-  z_stream strm;
-  unsigned char* c_in;
-  int level = 5;
-
-  /* allocate deflate state */
-  strm.zalloc = Z_NULL;
-  strm.zfree = Z_NULL;
-  strm.opaque = Z_NULL;
-  ret = deflateInit(&strm, level);
-  if (ret != Z_OK) {
-    dout(1) << "Compression init error: init return "
-         << ret << " instead of Z_OK" << dendl;
-    return -1;
-  }
-
-   unsigned char c_out [max_len];
-
-  for (std::list<buffer::ptr>::const_iterator i = in.buffers().begin();
-      i != in.buffers().end();) {
-
-    c_in = (unsigned char*) (*i).c_str();
-    long unsigned int len = (*i).length();
-    ++i;
-
-    strm.avail_in = len;
-    int flush = i != in.buffers().end() ? Z_NO_FLUSH : Z_FINISH;
-
-    strm.next_in = c_in;
-
-    do {
-      strm.avail_out = max_len;
-      strm.next_out = c_out;
-      ret = deflate(&strm, flush);    /* no bad return value */
-      if (ret == Z_STREAM_ERROR) {
-         dout(1) << "Compression error: compress return Z_STREAM_ERROR("
-              << ret << ")" << dendl;
-         deflateEnd(&strm);
-         return -1;
-      }
-      have = max_len - strm.avail_out;
-      out.append((char*)c_out, have);
-    } while (strm.avail_out == 0);
-    if (strm.avail_in != 0) {
-      dout(10) << "Compression error: unused input" << dendl;
-      deflateEnd(&strm);
-      return -1;
-    }
-  }
-
-  deflateEnd(&strm);
-  return 0;
-}
-
-int CompressionZlib::decompress(bufferlist::iterator &p, size_t compressed_size, bufferlist &out)
-{
-  int ret;
-  unsigned have;
-  z_stream strm;
-  const char* c_in;
-
-  /* allocate inflate state */
-  strm.zalloc = Z_NULL;
-  strm.zfree = Z_NULL;
-  strm.opaque = Z_NULL;
-  strm.avail_in = 0;
-  strm.next_in = Z_NULL;
-  ret = inflateInit(&strm);
-  if (ret != Z_OK) {
-    dout(1) << "Decompression init error: init return "
-         << ret << " instead of Z_OK" << dendl;
-    return -1;
-  }
-
-  unsigned char c_out[max_len];
-  size_t remaining = MIN( p.get_remaining(), compressed_size);
-  while(remaining) {
-
-    long unsigned int len = p.get_ptr_and_advance(remaining, &c_in);
-    remaining -= len;
-    strm.avail_in = len;
-    strm.next_in = (unsigned char*)c_in;
-
-    do {
-      strm.avail_out = max_len;
-      strm.next_out = c_out;
-      ret = inflate(&strm, Z_NO_FLUSH);
-      if (ret != Z_OK && ret != Z_STREAM_END && ret != Z_BUF_ERROR) {
-       dout(1) << "Decompression error: decompress return "
-            << ret << dendl;
-       inflateEnd(&strm);
-       return -1;
-      }
-      have = max_len - strm.avail_out;
-      out.append((char*)c_out, have);
-    } while (strm.avail_out == 0);
-
-  }
-
-  /* clean up and return */
-  (void)inflateEnd(&strm);
-  return 0;
-}
-
-int CompressionZlib::decompress(const bufferlist &in, bufferlist &out)
-{
-  bufferlist::iterator i = const_cast<bufferlist&>(in).begin();
-  return decompress(i, in.length(), out);
-}
diff --git a/src/compressor/zlib/CompressionZlib.h b/src/compressor/zlib/CompressionZlib.h
deleted file mode 100644 (file)
index 133f912..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * 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_ZLIB_H
-#define CEPH_COMPRESSION_ZLIB_H
-
-#include "compressor/Compressor.h"
-
-class CompressionZlib : public Compressor {
-  const char version = '1';
-
-public:
-  CompressionZlib() : Compressor("zlib") {}
-  int compress(const bufferlist &in, bufferlist &out) override;
-  int decompress(const bufferlist &in, bufferlist &out) override;
-  int decompress(bufferlist::iterator &p, size_t compressed_len, bufferlist &out) override;
- };
-
-
-#endif
index 7f97ea424a00361e53471e6c01610e8509001cc7..a0056123b89b3b901b71751d17d3c67da6844a53 100644 (file)
@@ -1,12 +1,12 @@
 # zlib plugin
 noinst_HEADERS += \
-  compressor/zlib/CompressionZlib.h
+  compressor/zlib/ZlibCompressor.h
 
 zlib_sources = \
   common/buffer.cc \
   compressor/Compressor.cc \
   compressor/zlib/CompressionPluginZlib.cc \
-  compressor/zlib/CompressionZlib.cc
+  compressor/zlib/ZlibCompressor.cc
 
 compressor/zlib/CompressionPluginZlib.cc: ./ceph_ver.h
 
diff --git a/src/compressor/zlib/ZlibCompressor.cc b/src/compressor/zlib/ZlibCompressor.cc
new file mode 100644 (file)
index 0000000..747ffae
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ * 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.
+ *
+ */
+
+// -----------------------------------------------------------------------------
+#include "common/debug.h"
+#include "ZlibCompressor.h"
+#include "osd/osd_types.h"
+// -----------------------------------------------------------------------------
+
+#include <zlib.h>
+
+// -----------------------------------------------------------------------------
+#define dout_subsys ceph_subsys_compressor
+#undef dout_prefix
+#define dout_prefix _prefix(_dout)
+// -----------------------------------------------------------------------------
+
+// -----------------------------------------------------------------------------
+
+static ostream&
+_prefix(std::ostream* _dout)
+{
+  return *_dout << "ZlibCompressor: ";
+}
+// -----------------------------------------------------------------------------
+
+const long unsigned int max_len = 2048;
+
+int ZlibCompressor::compress(const bufferlist &in, bufferlist &out)
+{
+  int ret;
+  unsigned have;
+  z_stream strm;
+  unsigned char* c_in;
+  int level = 5;
+
+  /* allocate deflate state */
+  strm.zalloc = Z_NULL;
+  strm.zfree = Z_NULL;
+  strm.opaque = Z_NULL;
+  ret = deflateInit(&strm, level);
+  if (ret != Z_OK) {
+    dout(1) << "Compression init error: init return "
+         << ret << " instead of Z_OK" << dendl;
+    return -1;
+  }
+
+  for (std::list<buffer::ptr>::const_iterator i = in.buffers().begin();
+      i != in.buffers().end();) {
+
+    c_in = (unsigned char*) (*i).c_str();
+    long unsigned int len = (*i).length();
+    ++i;
+
+    strm.avail_in = len;
+    int flush = i != in.buffers().end() ? Z_NO_FLUSH : Z_FINISH;
+
+    strm.next_in = c_in;
+
+    do {
+      strm.avail_out = max_len;
+      bufferptr ptr = buffer::create_page_aligned(max_len);
+      strm.next_out = (unsigned char*)ptr.c_str();
+      ret = deflate(&strm, flush);    /* no bad return value */
+      if (ret == Z_STREAM_ERROR) {
+         dout(1) << "Compression error: compress return Z_STREAM_ERROR("
+              << ret << ")" << dendl;
+         deflateEnd(&strm);
+         return -1;
+      }
+      have = max_len - strm.avail_out;
+      out.append(ptr, 0, have);
+    } while (strm.avail_out == 0);
+    if (strm.avail_in != 0) {
+      dout(10) << "Compression error: unused input" << dendl;
+      deflateEnd(&strm);
+      return -1;
+    }
+  }
+
+  deflateEnd(&strm);
+  return 0;
+}
+
+int ZlibCompressor::decompress(bufferlist::iterator &p, size_t compressed_size, bufferlist &out)
+{
+  int ret;
+  unsigned have;
+  z_stream strm;
+  const char* c_in;
+
+  /* allocate inflate state */
+  strm.zalloc = Z_NULL;
+  strm.zfree = Z_NULL;
+  strm.opaque = Z_NULL;
+  strm.avail_in = 0;
+  strm.next_in = Z_NULL;
+  ret = inflateInit(&strm);
+  if (ret != Z_OK) {
+    dout(1) << "Decompression init error: init return "
+         << ret << " instead of Z_OK" << dendl;
+    return -1;
+  }
+
+  size_t remaining = MIN(p.get_remaining(), compressed_size);
+  while(remaining) {
+
+    long unsigned int len = p.get_ptr_and_advance(remaining, &c_in);
+    remaining -= len;
+    strm.avail_in = len;
+    strm.next_in = (unsigned char*)c_in;
+
+    do {
+      strm.avail_out = max_len;
+      bufferptr ptr = buffer::create_page_aligned(max_len);
+      strm.next_out = (unsigned char*)ptr.c_str();
+      ret = inflate(&strm, Z_NO_FLUSH);
+      if (ret != Z_OK && ret != Z_STREAM_END && ret != Z_BUF_ERROR) {
+       dout(1) << "Decompression error: decompress return "
+            << ret << dendl;
+       inflateEnd(&strm);
+       return -1;
+      }
+      have = max_len - strm.avail_out;
+      out.append(ptr, 0, have);
+    } while (strm.avail_out == 0);
+
+  }
+
+  /* clean up and return */
+  (void)inflateEnd(&strm);
+  return 0;
+}
+
+int ZlibCompressor::decompress(const bufferlist &in, bufferlist &out)
+{
+  bufferlist::iterator i = const_cast<bufferlist&>(in).begin();
+  return decompress(i, in.length(), out);
+}
diff --git a/src/compressor/zlib/ZlibCompressor.h b/src/compressor/zlib/ZlibCompressor.h
new file mode 100644 (file)
index 0000000..7cac1a6
--- /dev/null
@@ -0,0 +1,32 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * 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_ZLIB_H
+#define CEPH_COMPRESSION_ZLIB_H
+
+#include "compressor/Compressor.h"
+
+class ZlibCompressor : public Compressor {
+public:
+  ZlibCompressor() : Compressor("zlib") {}
+
+  int compress(const bufferlist &in, bufferlist &out) override;
+  int decompress(const bufferlist &in, bufferlist &out) override;
+  int decompress(bufferlist::iterator &p, size_t compressed_len, bufferlist &out) override;
+ };
+
+
+#endif
index 642264b3380e55eba71c860e329dfcd06d4c4410..4932fbd6ff852deca1a8dd5a4f4560ec21330e73 100644 (file)
 #include <string.h>
 #include <gtest/gtest.h>
 #include "global/global_init.h"
-#include "compressor/zlib/CompressionZlib.h"
+#include "compressor/zlib/ZlibCompressor.h"
 #include "common/ceph_argparse.h"
 #include "global/global_context.h"
 #include "common/config.h"
 
-TEST(CompressionZlib, compress_decompress)
+TEST(ZlibCompressor, compress_decompress)
 {
-  CompressionZlib sp;
+  ZlibCompressor sp;
   EXPECT_STREQ(sp.get_type().c_str(), "zlib");
   const char* test = "This is test text";
   int len = strlen(test);
@@ -49,9 +49,9 @@ TEST(CompressionZlib, compress_decompress)
   EXPECT_TRUE(exp.contents_equal(after));
 }
 
-TEST(CompressionZlib, compress_decompress_chunk)
+TEST(ZlibCompressor, compress_decompress_chunk)
 {
-  CompressionZlib sp;
+  ZlibCompressor sp;
   EXPECT_STREQ(sp.get_type().c_str(), "zlib");
   const char* test = "This is test text";
   buffer::ptr test2 ("1234567890", 10);