diff options
author | Miaomiao Liu <miaomiao.liu@intel.com> | 2022-01-19 08:27:07 +0100 |
---|---|---|
committer | Miaomiao Liu <miaomiao.liu@intel.com> | 2022-02-18 10:45:30 +0100 |
commit | 9a9001a08fdc05361057e7880dac98210fffe1fc (patch) | |
tree | 2bbd9113169bff280a28a47a132c6937c201c085 /src/compressor | |
parent | compressor: replace snappy and lz4 compressors with zlib for QAT based compre... (diff) | |
download | ceph-9a9001a08fdc05361057e7880dac98210fffe1fc.tar.xz ceph-9a9001a08fdc05361057e7880dac98210fffe1fc.zip |
compressor: fix compilation issues about QATzip
Signed-off-by: Miaomiao Liu <miaomiao.liu@intel.com>
Signed-off-by: Hualong Feng <hualong.feng@intel.com>
Diffstat (limited to 'src/compressor')
-rw-r--r-- | src/compressor/CMakeLists.txt | 12 | ||||
-rw-r--r-- | src/compressor/QatAccel.cc | 36 | ||||
-rw-r--r-- | src/compressor/QatAccel.h | 12 | ||||
-rw-r--r-- | src/compressor/zlib/ZlibCompressor.cc | 4 |
4 files changed, 39 insertions, 25 deletions
diff --git a/src/compressor/CMakeLists.txt b/src/compressor/CMakeLists.txt index d8b9fd83cda..9b10fff5330 100644 --- a/src/compressor/CMakeLists.txt +++ b/src/compressor/CMakeLists.txt @@ -5,6 +5,13 @@ if (HAVE_QATZIP) list(APPEND compressor_srcs QatAccel.cc) endif() add_library(compressor_objs OBJECT ${compressor_srcs}) +if(HAVE_QATZIP AND HAVE_QATDRV) + target_link_libraries(compressor_objs PRIVATE + QatDrv::qat_s + QatDrv::usdm_drv_s + qatzip::qatzip + ) +endif() ## compressor plugins @@ -22,10 +29,7 @@ if(HAVE_BROTLI) add_subdirectory(brotli) endif() -add_library(compressor STATIC ${compressor_srcs}) -if(HAVE_QATZIP) - target_link_libraries(compressor PRIVATE ${QATZIP_LIBRARIES}) -endif() +add_library(compressor STATIC $<TARGET_OBJECTS:compressor_objs>) set(ceph_compressor_libs ceph_snappy diff --git a/src/compressor/QatAccel.cc b/src/compressor/QatAccel.cc index 79de9e3445c..e9b8d453113 100644 --- a/src/compressor/QatAccel.cc +++ b/src/compressor/QatAccel.cc @@ -11,19 +11,27 @@ * Foundation. See file COPYING. * */ - +#include <qatzip.h> #include "QatAccel.h" +void QzSessionDeleter::operator() (struct QzSession_S *session) { + if (NULL != session->internal) { + qzTeardownSession(session); + qzClose(session); + } + delete session; +} + /* Estimate data expansion after decompression */ static const unsigned int expansion_ratio[] = {5, 20, 50, 100, 200}; -QatAccel::~QatAccel() { - if (NULL != session.internal) { - qzTeardownSession(&session); - qzClose(&session); - } +QatAccel::QatAccel() { + session.reset(new struct QzSession_S); + memset(session.get(), 0, sizeof(struct QzSession_S)); } +QatAccel::~QatAccel() {} + bool QatAccel::init(const std::string &alg) { QzSessionParams_T params = {(QzHuffmanHdr_T)0,}; int rc; @@ -41,14 +49,14 @@ bool QatAccel::init(const std::string &alg) { if (rc != QZ_OK) return false; - rc = qzInit(&session, QZ_SW_BACKUP_DEFAULT); + rc = qzInit(session.get(), QZ_SW_BACKUP_DEFAULT); if (rc != QZ_OK && rc != QZ_DUPLICATE && rc != QZ_NO_HW) return false; - rc = qzSetupSession(&session, ¶ms); + rc = qzSetupSession(session.get(), ¶ms); if (rc != QZ_OK && rc != QZ_DUPLICATE && rc != QZ_NO_HW ) { - qzTeardownSession(&session); - qzClose(&session); + qzTeardownSession(session.get()); + qzClose(session.get()); return false; } @@ -59,10 +67,10 @@ int QatAccel::compress(const bufferlist &in, bufferlist &out, boost::optional<in for (auto &i : in.buffers()) { const unsigned char* c_in = (unsigned char*) i.c_str(); unsigned int len = i.length(); - unsigned int out_len = qzMaxCompressedLength(len); + unsigned int out_len = qzMaxCompressedLength(len, session.get()); bufferptr ptr = buffer::create_small_page_aligned(out_len); - int rc = qzCompress(&session, c_in, &len, (unsigned char *)ptr.c_str(), &out_len, 1); + int rc = qzCompress(session.get(), c_in, &len, (unsigned char *)ptr.c_str(), &out_len, 1); if (rc != QZ_OK) return -1; out.append(ptr, 0, out_len); @@ -103,9 +111,9 @@ int QatAccel::decompress(bufferlist::const_iterator &p, bufferptr ptr = buffer::create_small_page_aligned(out_len); if (joint) - rc = qzDecompress(&session, (const unsigned char*)tmp.c_str(), &len, (unsigned char*)ptr.c_str(), &out_len); + rc = qzDecompress(session.get(), (const unsigned char*)tmp.c_str(), &len, (unsigned char*)ptr.c_str(), &out_len); else - rc = qzDecompress(&session, (const unsigned char*)cur_ptr.c_str(), &len, (unsigned char*)ptr.c_str(), &out_len); + rc = qzDecompress(session.get(), (const unsigned char*)cur_ptr.c_str(), &len, (unsigned char*)ptr.c_str(), &out_len); if (rc == QZ_DATA_ERROR) { if (!joint) { tmp.append(cur_ptr.c_str(), cur_ptr.length()); diff --git a/src/compressor/QatAccel.h b/src/compressor/QatAccel.h index 3f7ccd25d10..ff99e200046 100644 --- a/src/compressor/QatAccel.h +++ b/src/compressor/QatAccel.h @@ -15,15 +15,21 @@ #ifndef CEPH_QATACCEL_H #define CEPH_QATACCEL_H -#include <qatzip.h> +#include <memory> #include <boost/optional.hpp> #include "include/buffer.h" +extern "C" struct QzSession_S; //struct QzSession_S comes from QAT libraries + +struct QzSessionDeleter { + void operator() (struct QzSession_S *session); +}; + class QatAccel { - QzSession_T session; + std::unique_ptr<struct QzSession_S, QzSessionDeleter> session; public: - QatAccel() : session({0}) {} + QatAccel(); ~QatAccel(); bool init(const std::string &alg); diff --git a/src/compressor/zlib/ZlibCompressor.cc b/src/compressor/zlib/ZlibCompressor.cc index 27b43c49cbe..d1ee1549977 100644 --- a/src/compressor/zlib/ZlibCompressor.cc +++ b/src/compressor/zlib/ZlibCompressor.cc @@ -246,10 +246,6 @@ int ZlibCompressor::decompress(bufferlist::const_iterator &p, size_t compressed_ int ZlibCompressor::decompress(const bufferlist &in, bufferlist &out, boost::optional<int32_t> compressor_message) { -#ifdef HAVE_QATZIP - if (qat_enabled) - return qat_accel.decompress(in, out, compressor_message); -#endif auto i = std::cbegin(in); return decompress(i, in.length(), out, compressor_message); } |