summaryrefslogtreecommitdiffstats
path: root/src/compressor/Compressor.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/compressor/Compressor.h
parentInitial commit. (diff)
downloadceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz
ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/compressor/Compressor.h')
-rw-r--r--src/compressor/Compressor.h109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/compressor/Compressor.h b/src/compressor/Compressor.h
new file mode 100644
index 000000000..0a45a990a
--- /dev/null
+++ b/src/compressor/Compressor.h
@@ -0,0 +1,109 @@
+// -*- 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 Haomai Wang <haomaiwang@gmail.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#ifndef CEPH_COMPRESSOR_H
+#define CEPH_COMPRESSOR_H
+
+#include <memory>
+#include <string>
+#include <string_view>
+#include <boost/optional.hpp>
+#include "include/ceph_assert.h" // boost clobbers this
+#include "include/common_fwd.h"
+#include "include/buffer.h"
+#include "include/int_types.h"
+#ifdef HAVE_QATZIP
+ #include "QatAccel.h"
+#endif
+
+namespace TOPNSPC {
+
+class Compressor;
+typedef std::shared_ptr<Compressor> CompressorRef;
+
+class Compressor {
+public:
+ enum CompressionAlgorithm {
+ COMP_ALG_NONE = 0,
+ COMP_ALG_SNAPPY = 1,
+ COMP_ALG_ZLIB = 2,
+ COMP_ALG_ZSTD = 3,
+#ifdef HAVE_LZ4
+ COMP_ALG_LZ4 = 4,
+#endif
+#ifdef HAVE_BROTLI
+ COMP_ALG_BROTLI = 5,
+#endif
+ COMP_ALG_LAST //the last value for range checks
+ };
+
+ using pair_type = std::pair<const char*, CompressionAlgorithm>;
+ static constexpr std::initializer_list<pair_type> compression_algorithms {
+ { "none", COMP_ALG_NONE },
+ { "snappy", COMP_ALG_SNAPPY },
+ { "zlib", COMP_ALG_ZLIB },
+ { "zstd", COMP_ALG_ZSTD },
+#ifdef HAVE_LZ4
+ { "lz4", COMP_ALG_LZ4 },
+#endif
+#ifdef HAVE_BROTLI
+ { "brotli", COMP_ALG_BROTLI },
+#endif
+ };
+
+ // compression options
+ enum CompressionMode {
+ COMP_NONE, ///< compress never
+ COMP_PASSIVE, ///< compress if hinted COMPRESSIBLE
+ COMP_AGGRESSIVE, ///< compress unless hinted INCOMPRESSIBLE
+ COMP_FORCE ///< compress always
+ };
+
+#ifdef HAVE_QATZIP
+ bool qat_enabled;
+ QatAccel qat_accel;
+#endif
+
+ static const char* get_comp_alg_name(int a);
+ static boost::optional<CompressionAlgorithm> get_comp_alg_type(std::string_view s);
+
+ static const char *get_comp_mode_name(int m);
+ static boost::optional<CompressionMode> get_comp_mode_type(std::string_view s);
+
+ Compressor(CompressionAlgorithm a, const char* t) : alg(a), type(t) {
+ }
+ virtual ~Compressor() {}
+ const std::string& get_type_name() const {
+ return type;
+ }
+ CompressionAlgorithm get_type() const {
+ return alg;
+ }
+ virtual int compress(const ceph::bufferlist &in, ceph::bufferlist &out, boost::optional<int32_t> &compressor_message) = 0;
+ virtual int decompress(const ceph::bufferlist &in, ceph::bufferlist &out, boost::optional<int32_t> compressor_message) = 0;
+ // this is a bit weird but we need non-const iterator to be in
+ // alignment with decode methods
+ virtual int decompress(ceph::bufferlist::const_iterator &p, size_t compressed_len, ceph::bufferlist &out, boost::optional<int32_t> compressor_message) = 0;
+
+ static CompressorRef create(CephContext *cct, const std::string &type);
+ static CompressorRef create(CephContext *cct, int alg);
+
+protected:
+ CompressionAlgorithm alg;
+ std::string type;
+
+};
+
+} // namespace TOPNSPC
+#endif