From ebbb3d75300d77cd14959e38f26131281a0b46de Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 8 Apr 2026 18:35:35 +0800 Subject: [PATCH 1/3] cmake/erasure-code: provide vendored jerasure as Jerasure::jerasure target Wrap the vendored jerasure and gf-complete object libraries into a static library (jerasure_vendored) and expose it via a Jerasure::jerasure alias target. This prepares for an upcoming WITH_SYSTEM_JERASURE option that will provide the same target backed by system libraries. Split jerasure_init.cc (ceph's own galois field initialization glue) into a separate jerasure_init_objs target, since it is not part of the jerasure library and must always be built from ceph's source. Normalize shec's include paths to use bare #include "jerasure.h" instead of #include "jerasure/include/jerasure.h", consistent with the jerasure plugin and compatible with both vendored and system headers. No functional change: ec_jerasure, ec_shec, and their legacy flavor variants produce identical binaries. Signed-off-by: Kefu Chai --- src/erasure-code/jerasure/CMakeLists.txt | 30 +++++++++++++++++------- src/erasure-code/shec/CMakeLists.txt | 14 +++++------ src/erasure-code/shec/ErasureCodeShec.cc | 4 ++-- src/erasure-code/shec/determinant.c | 2 +- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/erasure-code/jerasure/CMakeLists.txt b/src/erasure-code/jerasure/CMakeLists.txt index 023ffbf8a37..acd063c5924 100644 --- a/src/erasure-code/jerasure/CMakeLists.txt +++ b/src/erasure-code/jerasure/CMakeLists.txt @@ -7,6 +7,10 @@ set(jerasure_utils_src add_library(jerasure_utils OBJECT ${jerasure_utils_src}) target_link_libraries(jerasure_utils legacy-option-headers) +# jerasure_init is ceph's own glue code for galois field initialization, +# not part of the jerasure library itself. +add_library(jerasure_init_objs OBJECT jerasure_init.cc) + # Set the CFLAGS correctly for gf-complete based on SIMD compiler support set(GF_COMPILE_FLAGS) if(HAVE_ARMV8_SIMD) @@ -67,9 +71,9 @@ if(HAVE_ARM_NEON OR HAVE_ARMV8_SIMD) endif() add_library(gf-complete_objs OBJECT ${gf-complete_srcs}) -set_target_properties(gf-complete_objs PROPERTIES +set_target_properties(gf-complete_objs PROPERTIES COMPILE_FLAGS "${SIMD_COMPILE_FLAGS}") -set_target_properties(gf-complete_objs PROPERTIES +set_target_properties(gf-complete_objs PROPERTIES COMPILE_DEFINITIONS "${GF_COMPILE_FLAGS}") set(jerasure_srcs @@ -77,21 +81,28 @@ set(jerasure_srcs jerasure/src/galois.c jerasure/src/jerasure.c jerasure/src/liberation.c - jerasure/src/reed_sol.c - jerasure_init.cc) -add_library(jerasure_objs OBJECT ${jerasure_srcs}) -target_compile_options(jerasure_objs PRIVATE "-Wno-unused-but-set-variable") + jerasure/src/reed_sol.c) +add_library(jerasure_lib_objs OBJECT ${jerasure_srcs}) +target_compile_options(jerasure_lib_objs PRIVATE "-Wno-unused-but-set-variable") -set(ec_jerasure_objs +# Provide the vendored jerasure + gf-complete as a single static library +# target, using the same Jerasure::jerasure name that FindJerasure.cmake +# provides for the system library case. +add_library(jerasure_vendored STATIC $ - $ + $) +add_library(Jerasure::jerasure ALIAS jerasure_vendored) + +# ec_jerasure plugin +set(ec_jerasure_objs + $ $ $) add_library(ec_jerasure SHARED ${ec_jerasure_objs}) set_target_properties(ec_jerasure PROPERTIES INSTALL_RPATH "") -target_link_libraries(ec_jerasure ${EXTRALIBS}) +target_link_libraries(ec_jerasure Jerasure::jerasure ${EXTRALIBS}) install(TARGETS ec_jerasure DESTINATION ${erasure_plugin_dir}) # legacy libraries @@ -100,6 +111,7 @@ foreach(flavor ${jerasure_legacy_flavors}) add_library(${plugin_name} SHARED ${ec_jerasure_objs}) set_target_properties(${plugin_name} PROPERTIES INSTALL_RPATH "") + target_link_libraries(${plugin_name} Jerasure::jerasure) install(TARGETS ${plugin_name} DESTINATION ${erasure_plugin_dir}) add_dependencies(ec_jerasure ${plugin_name}) endforeach() diff --git a/src/erasure-code/shec/CMakeLists.txt b/src/erasure-code/shec/CMakeLists.txt index e7521542e31..d2ba32d2eb2 100644 --- a/src/erasure-code/shec/CMakeLists.txt +++ b/src/erasure-code/shec/CMakeLists.txt @@ -3,10 +3,10 @@ include_directories(.) set(shec_utils_srcs - ${CMAKE_SOURCE_DIR}/src/erasure-code/ErasureCode.cc - ErasureCodePluginShec.cc - ErasureCodeShec.cc - ErasureCodeShecTableCache.cc + ${CMAKE_SOURCE_DIR}/src/erasure-code/ErasureCode.cc + ErasureCodePluginShec.cc + ErasureCodeShec.cc + ErasureCodeShecTableCache.cc determinant.c) add_library(shec_utils OBJECT ${shec_utils_srcs}) @@ -14,14 +14,13 @@ target_link_libraries(shec_utils PRIVATE legacy-option-headers) set(ec_shec_objs - $ - $ + $ $) add_library(ec_shec SHARED ${ec_shec_objs}) set_target_properties(ec_shec PROPERTIES INSTALL_RPATH "") -target_link_libraries(ec_shec ${EXTRALIBS}) +target_link_libraries(ec_shec Jerasure::jerasure ${EXTRALIBS}) install(TARGETS ec_shec DESTINATION ${erasure_plugin_dir}) # legacy libraries @@ -30,6 +29,7 @@ foreach(flavor ${jerasure_legacy_flavors}) add_library(${plugin_name} SHARED ${ec_shec_objs}) set_target_properties(${plugin_name} PROPERTIES INSTALL_RPATH "") + target_link_libraries(${plugin_name} Jerasure::jerasure) install(TARGETS ${plugin_name} DESTINATION ${erasure_plugin_dir}) add_dependencies(ec_shec ${plugin_name}) endforeach() diff --git a/src/erasure-code/shec/ErasureCodeShec.cc b/src/erasure-code/shec/ErasureCodeShec.cc index 4146ba59f95..d61ae8804e9 100644 --- a/src/erasure-code/shec/ErasureCodeShec.cc +++ b/src/erasure-code/shec/ErasureCodeShec.cc @@ -28,8 +28,8 @@ #include "common/strtol.h" #include "ErasureCodeShec.h" extern "C" { -#include "jerasure/include/jerasure.h" -#include "jerasure/include/galois.h" +#include "jerasure.h" +#include "galois.h" extern int calc_determinant(int *matrix, int dim); extern int* reed_sol_vandermonde_coding_matrix(int k, int m, int w); diff --git a/src/erasure-code/shec/determinant.c b/src/erasure-code/shec/determinant.c index f923e7db0a5..4d962519830 100644 --- a/src/erasure-code/shec/determinant.c +++ b/src/erasure-code/shec/determinant.c @@ -20,7 +20,7 @@ #include #include -#include "jerasure/include/galois.h" +#include "galois.h" void print_matrix(int *mat, int dim) { From e35375b67324a875bd5e99a7758faf07259cc9ca Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 8 Apr 2026 18:37:25 +0800 Subject: [PATCH 2/3] cmake: add WITH_SYSTEM_JERASURE option for system jerasure and gf-complete Add a cmake option to build ceph's erasure code plugins (ec_jerasure and ec_shec) against system-provided jerasure and gf-complete libraries instead of the vendored copies. This allows downstream distributions to build with their own packaged versions of these libraries. For instance, Debian has shipped libjerasure-dev and libgf-complete-dev as build dependencies for ceph since 2021, but the build always used the vendored copies because there was no cmake option to use the system ones. Using system libraries also lets distributions benefit from any optimizations or fixes applied to their packages without having to carry patches against ceph's vendored copies. For example, the vendored gf-complete requires a downstream -O1 workaround to avoid emitting SSE 4.1 instructions that crash on older CPUs. But with system libraries, that becomes the library package's responsibility. The option is OFF by default, preserving the current behavior of building from vendored sources. A new FindJerasure.cmake module locates the system jerasure and gf-complete headers and libraries, and creates the Jerasure::jerasure imported target with the same target name that the vendored build now provides (see previous commit). Signed-off-by: Kefu Chai --- CMakeLists.txt | 6 +++ cmake/modules/FindJerasure.cmake | 66 ++++++++++++++++++++++++ src/erasure-code/CMakeLists.txt | 8 ++- src/erasure-code/jerasure/CMakeLists.txt | 2 + 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 cmake/modules/FindJerasure.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7217da88de5..3c7b3b579c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -733,6 +733,12 @@ if(sanitizers) string(APPEND CMAKE_SHARED_LINKER_FLAGS " ${sanitiers_compile_flags}") endif() +# Jerasure & GF-Complete +option(WITH_SYSTEM_JERASURE "require and build with system jerasure and gf-complete" OFF) +if(WITH_SYSTEM_JERASURE) + find_package(Jerasure REQUIRED) +endif() + # Rocksdb option(WITH_SYSTEM_ROCKSDB "require and build with system rocksdb" OFF) if (WITH_SYSTEM_ROCKSDB) diff --git a/cmake/modules/FindJerasure.cmake b/cmake/modules/FindJerasure.cmake new file mode 100644 index 00000000000..b27b687e8c8 --- /dev/null +++ b/cmake/modules/FindJerasure.cmake @@ -0,0 +1,66 @@ +# - Find Jerasure and GF-Complete +# Find the jerasure and gf-complete libraries and includes +# +# Jerasure_INCLUDE_DIR - where to find jerasure.h +# Jerasure_SUBHEADER_DIR - where to find galois.h, cauchy.h, etc. +# Jerasure_LIBRARY - the jerasure library +# GFComplete_INCLUDE_DIR - where to find gf_complete.h +# GFComplete_LIBRARY - the gf-complete library +# Jerasure_FOUND - True if both jerasure and gf-complete found. + +find_path(Jerasure_INCLUDE_DIR jerasure.h) + +# jerasure sub-headers (galois.h, cauchy.h, etc.) may be installed in a +# jerasure/ subdirectory. The main jerasure.h includes them with bare +# #include "galois.h", so this directory must be on the include path. +find_path(Jerasure_SUBHEADER_DIR galois.h + PATH_SUFFIXES jerasure) + +find_library(Jerasure_LIBRARY NAMES Jerasure) + +find_path(GFComplete_INCLUDE_DIR gf_complete.h) + +find_library(GFComplete_LIBRARY NAMES gf_complete) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Jerasure + REQUIRED_VARS + Jerasure_INCLUDE_DIR + Jerasure_SUBHEADER_DIR + Jerasure_LIBRARY + GFComplete_INCLUDE_DIR + GFComplete_LIBRARY) + +if(Jerasure_FOUND) + set(Jerasure_INCLUDE_DIRS + ${Jerasure_INCLUDE_DIR} + ${Jerasure_SUBHEADER_DIR} + ${GFComplete_INCLUDE_DIR}) + set(Jerasure_LIBRARIES + ${Jerasure_LIBRARY} + ${GFComplete_LIBRARY}) + + if(NOT TARGET Jerasure::jerasure) + add_library(Jerasure::jerasure UNKNOWN IMPORTED GLOBAL) + set_target_properties(Jerasure::jerasure PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${Jerasure_INCLUDE_DIR};${Jerasure_SUBHEADER_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${Jerasure_LIBRARY}" + INTERFACE_LINK_LIBRARIES "${GFComplete_LIBRARY}") + endif() + + if(NOT TARGET Jerasure::GFComplete) + add_library(Jerasure::GFComplete UNKNOWN IMPORTED GLOBAL) + set_target_properties(Jerasure::GFComplete PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${GFComplete_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${GFComplete_LIBRARY}") + endif() +endif() + +mark_as_advanced( + Jerasure_INCLUDE_DIR + Jerasure_SUBHEADER_DIR + Jerasure_LIBRARY + GFComplete_INCLUDE_DIR + GFComplete_LIBRARY) diff --git a/src/erasure-code/CMakeLists.txt b/src/erasure-code/CMakeLists.txt index cc5a84e9dc1..167a1ba39a8 100644 --- a/src/erasure-code/CMakeLists.txt +++ b/src/erasure-code/CMakeLists.txt @@ -3,8 +3,12 @@ set(erasure_plugin_dir ${CEPH_INSTALL_PKGLIBDIR}/erasure-code) #jerasure subdir must be before shec so jerasure & neon obj libs are declared -include_directories(SYSTEM jerasure/jerasure/include) -include_directories(SYSTEM jerasure/gf-complete/include) +if(WITH_SYSTEM_JERASURE) + include_directories(SYSTEM ${Jerasure_INCLUDE_DIRS}) +else() + include_directories(SYSTEM jerasure/jerasure/include) + include_directories(SYSTEM jerasure/gf-complete/include) +endif() include_directories(jerasure) # legacy jerasure flavors. these are left here for backward compatibility diff --git a/src/erasure-code/jerasure/CMakeLists.txt b/src/erasure-code/jerasure/CMakeLists.txt index acd063c5924..c97888fd989 100644 --- a/src/erasure-code/jerasure/CMakeLists.txt +++ b/src/erasure-code/jerasure/CMakeLists.txt @@ -11,6 +11,7 @@ target_link_libraries(jerasure_utils legacy-option-headers) # not part of the jerasure library itself. add_library(jerasure_init_objs OBJECT jerasure_init.cc) +if(NOT WITH_SYSTEM_JERASURE) # Set the CFLAGS correctly for gf-complete based on SIMD compiler support set(GF_COMPILE_FLAGS) if(HAVE_ARMV8_SIMD) @@ -92,6 +93,7 @@ add_library(jerasure_vendored STATIC $ $) add_library(Jerasure::jerasure ALIAS jerasure_vendored) +endif() # ec_jerasure plugin set(ec_jerasure_objs From 11e45a45f5e14b472acde31168a30bed5e60cf8b Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 9 Apr 2026 08:21:02 +0800 Subject: [PATCH 3/3] debian: build with system jerasure and gf-complete Add libjerasure-dev to Build-Depends and enable WITH_SYSTEM_JERASURE so that the Debian package builds ec_jerasure and ec_shec plugins against the distribution-provided libraries instead of the vendored copies. libjerasure-dev pulls in libgf-complete-dev, so both libraries are covered by a single build dependency. Add libjerasure2 to ceph-base's Depends for the runtime shared libraries. libjerasure2 in turn depends on libgf-complete1t64. The explicit dependency is needed because dh_shlibdeps excludes erasure-code plugins from automatic dependency scanning (they are loaded via dlopen at runtime). The distro-packaged jerasure and gf-complete are from the same upstream git snapshots (2017/04/10) as ceph's vendored copies. gf-complete source is byte-identical. jerasure differs only in additional null-pointer checks and error handling in jerasure.c, plus an extra galois_uninit_field() function that ceph does not use. All function signatures ceph depends on are present and compatible. Signed-off-by: Kefu Chai --- debian/control | 2 ++ debian/rules | 1 + 2 files changed, 3 insertions(+) diff --git a/debian/control b/debian/control index 3d4c84984dd..46918575f7e 100644 --- a/debian/control +++ b/debian/control @@ -49,6 +49,7 @@ Build-Depends: automake, libhwloc-dev , libibverbs-dev, libicu-dev, + libjerasure-dev, librdmacm-dev, libkeyutils-dev, libldap2-dev, @@ -144,6 +145,7 @@ Package: ceph-base Architecture: linux-any Depends: binutils, ceph-common (= ${binary:Version}), + libjerasure2, logrotate, parted, psmisc, diff --git a/debian/rules b/debian/rules index 4d31ffd069f..21b4d8ab3f0 100755 --- a/debian/rules +++ b/debian/rules @@ -20,6 +20,7 @@ ifneq ($(filter pkg.ceph.crimson,$(DEB_BUILD_PROFILES)),) endif extraopts += -DWITH_JAEGER=ON +extraopts += -DWITH_SYSTEM_JERASURE=ON extraopts += -DWITH_SYSTEM_UTF8PROC=ON extraopts += -DWITH_OCF=ON -DWITH_LTTNG=ON extraopts += -DWITH_MGR_DASHBOARD_FRONTEND=OFF