From: Miaomiao Liu Date: Wed, 19 Jan 2022 07:27:07 +0000 (+0800) Subject: compressor: fix compilation issues about QATzip X-Git-Tag: v18.0.0~1365^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9a9001a08fdc05361057e7880dac98210fffe1fc;p=ceph.git compressor: fix compilation issues about QATzip Signed-off-by: Miaomiao Liu Signed-off-by: Hualong Feng --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 531660102218..7a8b084b6e87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -279,7 +279,7 @@ endif() option(WITH_QATZIP "Enable QATZIP" OFF) if(WITH_QATZIP) find_package(qatzip REQUIRED) - set(HAVE_QATZIP ${QATZIP_FOUND}) + set(HAVE_QATZIP ${qatzip_FOUND}) endif(WITH_QATZIP) # needs mds and? XXX diff --git a/cmake/modules/Findqatzip.cmake b/cmake/modules/Findqatzip.cmake index 3a593228dd01..2d0f2ace3887 100644 --- a/cmake/modules/Findqatzip.cmake +++ b/cmake/modules/Findqatzip.cmake @@ -1,17 +1,24 @@ -# - Find Qatzip +# - Find qatzip # Find the qatzip compression library and includes # -# QATZIP_INCLUDE_DIR - where to find qatzip.h, etc. -# QATZIP_LIBRARIES - List of libraries when using qatzip. -# QATZIP_FOUND - True if qatzip found. +# qatzip_INCLUDE_DIR - where to find qatzip.h, etc. +# qatzip_LIBRARIES - List of libraries when using qatzip. +# qatzip_FOUND - True if qatzip found. -find_path(QATZIP_INCLUDE_DIR NAMES qatzip.h) - -find_library(QATZIP_LIBRARIES NAMES qatzip) +find_path(qatzip_INCLUDE_DIR NAMES qatzip.h) +find_library(qatzip_LIBRARIES NAMES qatzip HINTS /usr/local/lib64/) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(qatzip DEFAULT_MSG QATZIP_LIBRARIES QATZIP_INCLUDE_DIR) +find_package_handle_standard_args(qatzip DEFAULT_MSG qatzip_LIBRARIES qatzip_INCLUDE_DIR) mark_as_advanced( - QATZIP_LIBRARIES - QATZIP_INCLUDE_DIR) + qatzip_LIBRARIES + qatzip_INCLUDE_DIR) + +if(qatzip_FOUND AND NOT TARGET qatzip::qatzip) + add_library(qatzip::qatzip SHARED IMPORTED) + set_target_properties(qatzip::qatzip PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${qatzip_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${qatzip_LIBRARIES}") +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1157df00a199..abace5f0b19a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -490,7 +490,7 @@ if(NOT WITH_SYSTEM_BOOST) endif() if(HAVE_QATZIP) - list(APPEND ceph_common_deps ${QATZIP_LIBRARIES}) + list(APPEND ceph_common_deps ${qatzip_LIBRARIES}) endif() if(WITH_DPDK) diff --git a/src/compressor/CMakeLists.txt b/src/compressor/CMakeLists.txt index d8b9fd83cdac..9b10fff53301 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 $) set(ceph_compressor_libs ceph_snappy diff --git a/src/compressor/QatAccel.cc b/src/compressor/QatAccel.cc index 79de9e3445c6..e9b8d4531132 100644 --- a/src/compressor/QatAccel.cc +++ b/src/compressor/QatAccel.cc @@ -11,19 +11,27 @@ * Foundation. See file COPYING. * */ - +#include #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 +#include #include #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 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 27b43c49cbec..d1ee1549977b 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 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); }