From 76c35c6dd947a09ad6744a2159ac835958307a0c Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 25 Dec 2021 15:47:22 +0800 Subject: [PATCH] cmake: detect linux/blk/zoned support * add find_package() support for detecting the existence of linux/blkzoned.h before using it. * link against Linux::ZNS for adding the compilation definition of HAVE_ZNS instead of including it in the global config.h * move the CMake option closer to where it is used for better readability. as this option takes effect only if crimson is compiled. * make WITH_ZNS an option which depends on the value of CMAKE_SYSTEM_NAME. it is hidden and off if CMAKE_SYSTEM_NAME is not "Linux". Signed-off-by: Kefu Chai --- CMakeLists.txt | 6 ------ cmake/modules/FindLinuxZNS.cmake | 18 ++++++++++++++++++ src/crimson/os/seastore/CMakeLists.txt | 10 +++++++++- src/include/config-h.in.cmake | 3 --- 4 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 cmake/modules/FindLinuxZNS.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 73547fe1ec9..9bbcb5c7767 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -193,12 +193,6 @@ if(WITH_ZFS) set(HAVE_LIBZFS ${ZFS_FOUND}) endif() -option(WITH_ZNS "enable zns support" OFF) -if (WITH_ZNS) - # TODO: add detection, need kernel header >= 5.5 - set(HAVE_ZNS ON) -endif() - option(WITH_BLUESTORE "Bluestore OSD backend" ON) if(WITH_BLUESTORE) if(LINUX) diff --git a/cmake/modules/FindLinuxZNS.cmake b/cmake/modules/FindLinuxZNS.cmake new file mode 100644 index 00000000000..e0c3bba0316 --- /dev/null +++ b/cmake/modules/FindLinuxZNS.cmake @@ -0,0 +1,18 @@ +# Try to find linux/blkzoned.h + +find_path(LinuxZNS_INCLUDE_DIR NAMES + "linux/blkzoned.h") + +find_package_handle_standard_args(LinuxZNS + REQUIRED_VARS + LinuxZNS_INCLUDE_DIR) + +mark_as_advanced( + LinuxZNS_INCLUDE_DIR) + +if(LinuxZNS_FOUND AND NOT (TARGET Linux::ZNS)) + add_library(Linux::ZNS INTERFACE IMPORTED) + set_target_properties(Linux::ZNS PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LinuxZNS_INCLUDE_DIR}" + INTERFACE_COMPILE_DEFINITIONS HAVE_ZNS=1) +endif() diff --git a/src/crimson/os/seastore/CMakeLists.txt b/src/crimson/os/seastore/CMakeLists.txt index e28a1a8a7c5..55cfd425d84 100644 --- a/src/crimson/os/seastore/CMakeLists.txt +++ b/src/crimson/os/seastore/CMakeLists.txt @@ -43,7 +43,10 @@ set(crimson_seastore_srcs ${PROJECT_SOURCE_DIR}/src/os/Transaction.cc ) -if(HAVE_ZNS) +CMAKE_DEPENDENT_OPTION(WITH_ZNS "enable Linux ZNS support" OFF + "CMAKE_SYSTEM_NAME STREQUAL Linux" OFF) +if(WITH_ZNS) + find_package(LinuxZNS REQUIRED) list(APPEND crimson_seastore_srcs segment_manager/zns.cc) endif() @@ -53,5 +56,10 @@ add_library(crimson-seastore STATIC target_link_libraries(crimson-seastore crimson) +if(WITH_ZNS) + target_link_libraries(crimson-seastore + Linux::ZNS) +endif() + set_target_properties(crimson-seastore PROPERTIES JOB_POOL_COMPILE heavy_compile_job_pool) diff --git a/src/include/config-h.in.cmake b/src/include/config-h.in.cmake index c0f240492ea..6834c8a1a71 100644 --- a/src/include/config-h.in.cmake +++ b/src/include/config-h.in.cmake @@ -108,9 +108,6 @@ /* Define to 1 if you have libxfs */ #cmakedefine HAVE_LIBXFS 1 -/* Define to 1 if zns support enabled */ -#cmakedefine HAVE_ZNS - /* SPDK conditional compilation */ #cmakedefine HAVE_SPDK -- 2.47.3