diff options
author | Manuel Bentele | 2020-10-12 16:44:52 +0200 |
---|---|---|
committer | Manuel Bentele | 2020-10-12 16:44:52 +0200 |
commit | ccb981c4b403d7bbd962b281082b656b741e905f (patch) | |
tree | c57e6301bb9d520aeb47aab57c4e6b378f8a4970 | |
parent | Added debug support for xlosetup and documented debugging in README (diff) | |
download | xloop-ccb981c4b403d7bbd962b281082b656b741e905f.tar.gz xloop-ccb981c4b403d7bbd962b281082b656b741e905f.tar.xz xloop-ccb981c4b403d7bbd962b281082b656b741e905f.zip |
Added separate Linux kernel install directory and added version to kernel modules
-rw-r--r-- | CMakeLists.txt | 27 | ||||
-rw-r--r-- | README.md | 15 | ||||
-rw-r--r-- | cmake/version.cmake | 9 | ||||
-rw-r--r-- | kernel/CMakeLists.txt | 23 | ||||
-rw-r--r-- | kernel/cmake/kernel.cmake | 12 | ||||
-rw-r--r-- | kernel/xloop_file_fmt_qcow_main.c | 1 | ||||
-rw-r--r-- | kernel/xloop_file_fmt_raw.c | 1 | ||||
-rw-r--r-- | kernel/xloop_main.c | 2 |
8 files changed, 48 insertions, 42 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index fa32699..e1f8eac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,15 +9,28 @@ project(xloop DESCRIPTION "xloop Linux kernel modules and utility" LANGUAGES C) +include(GNUInstallDirs) + # define project specific settings set(BLK_DEV_XLOOP_MIN_COUNT 8 CACHE STRING "Number of xloop devices to pre-create at init time") set(XLOOP_MAJOR 120 CACHE STRING "Major number for xloop devices") +set(XLOOP_CTRL_MINOR 15 + CACHE STRING "Minor number for the xloop-control device") + +# set Linux kernel directories +set(KERNEL_BUILD_DIR "/${CMAKE_INSTALL_LIBDIR}/modules/${CMAKE_SYSTEM_VERSION}/build" + CACHE PATH "Path to Linux kernel modules to compile against") +set(KERNEL_INSTALL_DIR "/${CMAKE_INSTALL_LIBDIR}/modules/${CMAKE_SYSTEM_VERSION}/extra" + CACHE PATH "Path to install Linux kernel modules") # print configured settings +message(STATUS "Path to Linux kernel modules to compile against is " ${KERNEL_BUILD_DIR}) +message(STATUS "Path to install Linux kernel modules is " ${KERNEL_INSTALL_DIR}) message(STATUS "Number of xloop devices to pre-create at init time is " ${BLK_DEV_XLOOP_MIN_COUNT}) message(STATUS "Major number for xloop devices is " ${XLOOP_MAJOR}) +message(STATUS "Minor number for the xloop-control device is " ${XLOOP_CTRL_MINOR}) # set supported build configurations set(CMAKE_CONFIGURATION_TYPES Debug Release) @@ -29,7 +42,7 @@ if(NOT CMAKE_BUILD_TYPE) endif() # get versions to define project version -get_kernel_version(LINUX_KERNEL_VERSION) +get_kernel_version(LINUX_KERNEL_VERSION ${KERNEL_BUILD_DIR}) get_repository_version(REPOSITORY_VERSION) set(VERSION ${LINUX_KERNEL_VERSION}-${REPOSITORY_VERSION} CACHE STRING "Version of xloop package") @@ -61,12 +74,12 @@ if(${CMAKE_BUILD_TYPE} MATCHES Release) set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postinst ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postrm) # set RPM generator specific packaging options - set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/lib" - "/lib/modules" - "/lib/udev" - "/lib/modules/${CMAKE_SYSTEM_VERSION}" - "/lib/modules/${CMAKE_SYSTEM_VERSION}/extra" - "/lib/udev/rules.d" + set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/${CMAKE_INSTALL_LIBDIR}" + "/${CMAKE_INSTALL_LIBDIR}/modules" + "/${CMAKE_INSTALL_LIBDIR}/modules/${CMAKE_SYSTEM_VERSION}" + "/${CMAKE_INSTALL_LIBDIR}/modules/${CMAKE_SYSTEM_VERSION}/extra" + "/${CMAKE_INSTALL_LIBDIR}/udev" + "/${CMAKE_INSTALL_LIBDIR}/udev/rules.d" "${CPACK_PACKAGING_INSTALL_PREFIX}/share/bash-completion" "${CPACK_PACKAGING_INSTALL_PREFIX}/share/bash-completion/completions" "${CPACK_PACKAGING_INSTALL_PREFIX}/share/man" @@ -73,13 +73,14 @@ cd build ### Configuration A build of the xloop Linux kernel modules and the xlosetup utility can be configured and customized by the following configuration variables (CMake cache entries): -| Variable | Type | Values | Default value | Description | -|:--------------------------|:-------|:----------------------------------------|:------------------------|-----------------------------------------------------| -| `CMAKE_BUILD_TYPE` | STRING | {`Debug`, `Release`} | `Debug` | Build configuration of the xloop project. | -| `KERNEL_DIR` | PATH | {`a` .. `z`, `A` .. `Z`, `/`, `_`, `-`} | /lib/modules/`uname -r` | Path to Linux kernel modules to compile against. | -| `XLOOP_MAJOR` | NUMBER | {`0` .. `255`} | `120` | Major number for xloop devices. | -| `XLOOP_CTRL_MINOR` | NUMBER | {`0` .. `255`} | `15` | Minor number for the xloop-control device. | -| `BLK_DEV_XLOOP_MIN_COUNT` | NUMBER | {`0` .. `255`} | `8` | Number of xloop devices to pre-create at init time. | +| Variable | Type | Values | Default value | Description | +|:--------------------------|:-------|:----------------------------------------|:--------------------------------------------------|-----------------------------------------------------| +| `CMAKE_BUILD_TYPE` | STRING | {`Debug`, `Release`} | `Debug` | Build configuration of the xloop project. | +| `KERNEL_BUILD_DIR` | PATH | {`a` .. `z`, `A` .. `Z`, `/`, `_`, `-`} | /${CMAKE_INSTALL_LIBDIR}/modules/`uname -r`/build | Path to Linux kernel modules to compile against. | +| `KERNEL_INSTALL_DIR` | PATH | {`a` .. `z`, `A` .. `Z`, `/`, `_`, `-`} | /${CMAKE_INSTALL_LIBDIR}/modules/`uname -r`/extra | Path to install Linux kernel modules. | +| `XLOOP_MAJOR` | NUMBER | {`0` .. `255`} | `120` | Major number for xloop devices. | +| `XLOOP_CTRL_MINOR` | NUMBER | {`0` .. `255`} | `15` | Minor number for the xloop-control device. | +| `BLK_DEV_XLOOP_MIN_COUNT` | NUMBER | {`0` .. `255`} | `8` | Number of xloop devices to pre-create at init time. | A value from the range of appropriate values can be assigend to each configuration variable by executing CMake once with the following command pattern: diff --git a/cmake/version.cmake b/cmake/version.cmake index da3951d..1cae665 100644 --- a/cmake/version.cmake +++ b/cmake/version.cmake @@ -4,12 +4,9 @@ # Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de> # -# macro to get Linux kernel version -macro(get_kernel_version LINUX_KERNEL_VERSION) - execute_process(COMMAND uname -r - OUTPUT_VARIABLE UNAME_RESULT - OUTPUT_STRIP_TRAILING_WHITESPACE) - string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" LINUX_KERNEL_VERSION ${UNAME_RESULT}) +# macro to get Linux kernel version from KERNEL_BUILD_DIR +macro(get_kernel_version LINUX_KERNEL_VERSION KERNEL_BUILD_DIR) + string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" LINUX_KERNEL_VERSION ${KERNEL_BUILD_DIR}) endmacro(get_kernel_version) # macro to get short hash of latest commit diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 0cf209c..1f266f6 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -6,18 +6,6 @@ project(xloop-kernel) set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(kernel) -# set Linux kernel directory -set(KERNEL_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}" - CACHE PATH "Path to Linux kernel modules to compile against") - -# define xloop device specific options -set(XLOOP_CTRL_MINOR 15 - CACHE STRING "Minor number for the xloop-control device") - -# print configured settings -message(STATUS "Path to Linux kernel modules to compile against is " ${KERNEL_DIR}) -message(STATUS "Minor number for the xloop-control device is " ${XLOOP_CTRL_MINOR}) - # set C flags for a Linux kernel module set(KERNEL_C_FLAGS "-DCONFIG_BLK_DEV_XLOOP_MIN_COUNT=${BLK_DEV_XLOOP_MIN_COUNT} -DXLOOP_MAJOR=${XLOOP_MAJOR} -DXLOOP_CTRL_MINOR=${XLOOP_CTRL_MINOR} -DVERSION=${VERSION}" CACHE STRING "C flags to be used for building the kernel module") @@ -36,7 +24,8 @@ set(KERNEL_MODULE_XLOOP_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/xloop_file_fmt. set(KERNEL_MODULE_XLOOP_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/xloop_file_fmt.h ${CMAKE_CURRENT_SOURCE_DIR}/xloop_main.h ${CMAKE_CURRENT_SOURCE_DIR}/uapi) -add_kernel_module(xloop "${KERNEL_DIR}" +add_kernel_module(xloop "${KERNEL_BUILD_DIR}" + "${KERNEL_INSTALL_DIR}" "CONFIG_BLK_DEV_XLOOP=m" "${KERNEL_MODULE_XLOOP_SOURCE_FILES}" "${KERNEL_MODULE_XLOOP_HEADER_FILES}" @@ -47,7 +36,8 @@ set(KERNEL_MODULE_XLOOP_RAW_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/xloop_file_ set(KERNEL_MODULE_XLOOP_RAW_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/xloop_file_fmt.h ${CMAKE_CURRENT_SOURCE_DIR}/xloop_main.h ${CMAKE_CURRENT_SOURCE_DIR}/uapi) -add_kernel_module(xloop_file_fmt_raw "${KERNEL_DIR}" +add_kernel_module(xloop_file_fmt_raw "${KERNEL_BUILD_DIR}" + "${KERNEL_INSTALL_DIR}" "CONFIG_BLK_DEV_XLOOP_FILE_FMT_RAW=m" "${KERNEL_MODULE_XLOOP_RAW_SOURCE_FILES}" "${KERNEL_MODULE_XLOOP_RAW_HEADER_FILES}" @@ -64,7 +54,8 @@ set(KERNEL_MODULE_XLOOP_QCOW_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/xloop_file ${CMAKE_CURRENT_SOURCE_DIR}/xloop_file_fmt.h ${CMAKE_CURRENT_SOURCE_DIR}/xloop_main.h ${CMAKE_CURRENT_SOURCE_DIR}/uapi) -add_kernel_module(xloop_file_fmt_qcow "${KERNEL_DIR}" +add_kernel_module(xloop_file_fmt_qcow "${KERNEL_BUILD_DIR}" + "${KERNEL_INSTALL_DIR}" "CONFIG_BLK_DEV_XLOOP_FILE_FMT_QCOW=m" "${KERNEL_MODULE_XLOOP_QCOW_SOURCE_FILES}" "${KERNEL_MODULE_XLOOP_QCOW_HEADER_FILES}" @@ -77,6 +68,6 @@ endif() # install udev rules for xloop devices exposed by the xloop kernel module install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/udev/50-xloop.rules - DESTINATION /lib/udev/rules.d + DESTINATION /${CMAKE_INSTALL_LIBDIR}/udev/rules.d PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ COMPONENT main) diff --git a/kernel/cmake/kernel.cmake b/kernel/cmake/kernel.cmake index 3ac7633..0d843e6 100644 --- a/kernel/cmake/kernel.cmake +++ b/kernel/cmake/kernel.cmake @@ -5,7 +5,7 @@ # # macro to define kernel module targets -macro(add_kernel_module MODULE_NAME KERNEL_DIR MODULE_MACRO MODULE_SOURCE_FILES MODULE_HEADER_FILES BUILD_SOURCE_FILE) +macro(add_kernel_module MODULE_NAME KERNEL_BUILD_DIR KERNEL_INSTALL_DIR MODULE_MACRO MODULE_SOURCE_FILES MODULE_HEADER_FILES BUILD_SOURCE_FILE) # copy build source file file(COPY ${BUILD_SOURCE_FILE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}) # copy source files @@ -17,12 +17,12 @@ macro(add_kernel_module MODULE_NAME KERNEL_DIR MODULE_MACRO MODULE_SOURCE_FILES file(COPY ${MODULE_HEADER_FILE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}) endforeach() # check if module depends on another module - if(NOT ${ARGV6} STREQUAL "") - set(MODULE_EXTRA_SYMBOLS ${CMAKE_CURRENT_BINARY_DIR}/${ARGV6}/Module.symvers) + if(NOT ${ARGV7} STREQUAL "") + set(MODULE_EXTRA_SYMBOLS ${CMAKE_CURRENT_BINARY_DIR}/${ARGV7}/Module.symvers) endif() # define build command set(MODULE_BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} ${MODULE_MACRO} - -C ${KERNEL_DIR}/build + -C ${KERNEL_BUILD_DIR} M=${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME} modules EXTRA_CFLAGS=${KERNEL_C_FLAGS} KBUILD_EXTRA_SYMBOLS=${MODULE_EXTRA_SYMBOLS}) @@ -31,9 +31,9 @@ macro(add_kernel_module MODULE_NAME KERNEL_DIR MODULE_MACRO MODULE_SOURCE_FILES WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME} DEPENDS ${MODULE_SOURCE_FILES} ${MODULE_HEADER_FILES} ${BUILD_SOURCE_FILE} VERBATIM) - add_custom_target(${MODULE_NAME} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_NAME}.ko ${ARGV6}) + add_custom_target(${MODULE_NAME} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_NAME}.ko ${ARGV7}) install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_NAME}.ko - DESTINATION ${KERNEL_DIR}/extra + DESTINATION ${KERNEL_INSTALL_DIR} PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ COMPONENT main) endmacro(add_kernel_module) diff --git a/kernel/xloop_file_fmt_qcow_main.c b/kernel/xloop_file_fmt_qcow_main.c index fbc49f5..38fe1af 100644 --- a/kernel/xloop_file_fmt_qcow_main.c +++ b/kernel/xloop_file_fmt_qcow_main.c @@ -1280,3 +1280,4 @@ MODULE_LICENSE("GPL"); MODULE_AUTHOR("Manuel Bentele <development@manuel-bentele.de>"); MODULE_DESCRIPTION("xloop device QCOW file format driver"); MODULE_SOFTDEP("pre: xloop"); +MODULE_VERSION(__stringify(VERSION)); diff --git a/kernel/xloop_file_fmt_raw.c b/kernel/xloop_file_fmt_raw.c index f963e92..76ab39e 100644 --- a/kernel/xloop_file_fmt_raw.c +++ b/kernel/xloop_file_fmt_raw.c @@ -473,3 +473,4 @@ MODULE_LICENSE("GPL"); MODULE_AUTHOR("Manuel Bentele <development@manuel-bentele.de>"); MODULE_DESCRIPTION("xloop device RAW file format driver"); MODULE_SOFTDEP("pre: xloop"); +MODULE_VERSION(__stringify(VERSION)); diff --git a/kernel/xloop_main.c b/kernel/xloop_main.c index 001b759..a3e20a6 100644 --- a/kernel/xloop_main.c +++ b/kernel/xloop_main.c @@ -1718,6 +1718,8 @@ MODULE_PARM_DESC(max_xloop, "Maximum number of xloop devices"); module_param(max_part, int, 0444); MODULE_PARM_DESC(max_part, "Maximum number of partitions per xloop device"); MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Manuel Bentele <development@manuel-bentele.de>"); +MODULE_VERSION(__stringify(VERSION)); MODULE_ALIAS_BLOCKDEV_MAJOR(XLOOP_MAJOR); int xloop_register_transfer(struct xloop_func_table *funcs) |