diff options
author | Manuel Bentele | 2020-09-09 16:53:48 +0200 |
---|---|---|
committer | Manuel Bentele | 2020-09-16 07:37:56 +0200 |
commit | 87c9cd859ca10ccbe109e09fe01a03b08932a887 (patch) | |
tree | 31bdd21158857dcecbf91d85b1e5ade62033d8f2 | |
parent | Added patched losetup utility to configure xloop devices (diff) | |
download | xloop-87c9cd859ca10ccbe109e09fe01a03b08932a887.tar.gz xloop-87c9cd859ca10ccbe109e09fe01a03b08932a887.tar.xz xloop-87c9cd859ca10ccbe109e09fe01a03b08932a887.zip |
Added CMake files to build xloop kernel modules and xlosetup utility
-rw-r--r-- | CMakeLists.txt | 26 | ||||
-rw-r--r-- | kernel/CMakeLists.txt | 71 | ||||
-rw-r--r-- | kernel/Kbuild (renamed from kernel/Kbuild.in) | 5 | ||||
-rw-r--r-- | kernel/Kconfig | 93 | ||||
-rw-r--r-- | kernel/Makefile | 2 | ||||
-rw-r--r-- | kernel/cmake/kernel.cmake | 43 | ||||
-rw-r--r-- | kernel/loop_main.c | 16 | ||||
-rw-r--r-- | utils/CMakeLists.txt | 4 | ||||
-rw-r--r-- | utils/sys-utils/CMakeLists.txt | 5 |
9 files changed, 161 insertions, 104 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b136eca..3a9f07a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,32 @@ cmake_minimum_required(VERSION 3.10) # set the project name project(xloop) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug") +endif() + +# define packaging +set(CPACK_GENERATOR "DEB") +set(CPACK_SOURCE_GENERATOR "TGZ") +set(CPACK_IGNORE_FILES "*.gitignore") +set(CPACK_PACKAGE_NAME "xloop") +set(CPACK_PACKAGE_DESCRIPTION "xloop Kernel modules and utility") +set(CPACK_PACKAGE_VERSION_MAJOR 0) +set(CPACK_PACKAGE_VERSION_MINOR 1) +set(CPACK_PACKAGE_SECTION admin) +set(CPACK_PACKAGE_VENDOR "University of Freiburg") +set(CPACK_PACKAGE_CONTACT "Christian Rößler <christian.roessler@rz.uni-freiburg.de>") +set(CPACK_PACKAGE_HOMEPAGE_URL "https://git.openslx.org/openslx-ng/xloop.git/") +set(CPACK_PACKAGE_CHECKSUM SHA256) +set(CPACK_STRIP_FILES TRUE) +set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) +set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6") +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postinst "depmod -a\n") +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postrm "depmod -a\n") +set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postinst + ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postrm) +include(CPack) + # add subprojects add_subdirectory(kernel) add_subdirectory(utils) diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 3c91af4..c850f0a 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -1,4 +1,73 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.12) # set the project name 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 kernel sources to compile against") + +# define xloop device specific options +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") + +# print configured settings +message(STATUS "Kernel module path is " ${KERNEL_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}) + +# 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}" + CACHE STRING "C flags to be used for building the kernel module") +# set C flags for the debug mode of a Linux kernel module +set(KERNEL_C_FLAGS_DEBUG "-g -DDEBUG" + CACHE STRING "Additional C flags to be used for building the kernel module in debug mode") + +# append debug C flags if debug mode is enabled +if(CMAKE_BUILD_TYPE MATCHES Debug) + set(KERNEL_C_FLAGS "${KERNEL_C_FLAGS} ${KERNEL_C_FLAGS_DEBUG}") +endif(CMAKE_BUILD_TYPE MATCHES Debug) + +# preparation of the Kbuild file +add_kernel_build(prepare ${CMAKE_CURRENT_SOURCE_DIR}/Kbuild) + +# xloop main Linux kernel module +set(KERNEL_MODULE_XLOOP_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/loop_file_fmt.c + ${CMAKE_CURRENT_SOURCE_DIR}/loop_main.c) +set(KERNEL_MODULE_XLOOP_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/loop_file_fmt.h + ${CMAKE_CURRENT_SOURCE_DIR}/loop_main.h + ${CMAKE_CURRENT_SOURCE_DIR}/uapi) +add_kernel_module(xloop "${KERNEL_DIR}" + "CONFIG_BLK_DEV_XLOOP=m" + "${KERNEL_MODULE_XLOOP_SOURCE_FILES}" + "${KERNEL_MODULE_XLOOP_HEADER_FILES}" + ${CMAKE_CURRENT_BINARY_DIR}/Kbuild) + +# xloop_file_fmt_raw Linux kernel module +set(KERNEL_MODULE_XLOOP_RAW_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/loop_file_fmt_raw.c) +set(KERNEL_MODULE_XLOOP_RAW_HEADER_FILES ) +add_kernel_module(loop_file_fmt_raw "${KERNEL_DIR}" + "CONFIG_BLK_DEV_XLOOP_FILE_FMT_RAW=m" + "${KERNEL_MODULE_XLOOP_RAW_SOURCE_FILES}" + "${KERNEL_MODULE_XLOOP_RAW_HEADER_FILES}" + ${CMAKE_CURRENT_BINARY_DIR}/Kbuild + xloop) + +# xloop_file_fmt_qcow Linux kernel module +set(KERNEL_MODULE_XLOOP_QCOW_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/loop_file_fmt_qcow_cache.c + ${CMAKE_CURRENT_SOURCE_DIR}/loop_file_fmt_qcow_cluster.c + ${CMAKE_CURRENT_SOURCE_DIR}/loop_file_fmt_qcow_main.c) +set(KERNEL_MODULE_XLOOP_QCOW_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/loop_file_fmt_qcow_cache.h + ${CMAKE_CURRENT_SOURCE_DIR}/loop_file_fmt_qcow_cluster.h + ${CMAKE_CURRENT_SOURCE_DIR}/loop_file_fmt_qcow_main.h) +add_kernel_module(loop_file_fmt_qcow "${KERNEL_DIR}" + "CONFIG_BLK_DEV_XLOOP_FILE_FMT_QCOW=m" + "${KERNEL_MODULE_XLOOP_QCOW_SOURCE_FILES}" + "${KERNEL_MODULE_XLOOP_QCOW_HEADER_FILES}" + ${CMAKE_CURRENT_BINARY_DIR}/Kbuild + xloop) diff --git a/kernel/Kbuild.in b/kernel/Kbuild index b61f7a0..a216066 100644 --- a/kernel/Kbuild.in +++ b/kernel/Kbuild @@ -1,9 +1,12 @@ # SPDX-License-Identifier: GPL-2.0 +# Linux kernel module xloop obj-$(CONFIG_BLK_DEV_XLOOP) += xloop.o xloop-objs += loop_main.o loop_file_fmt.o +# Linux kernel module loop_file_fmt_raw obj-$(CONFIG_BLK_DEV_XLOOP_FILE_FMT_RAW) += loop_file_fmt_raw.o -loop_file_fmt_qcow-y += loop_file_fmt_qcow_main.o loop_file_fmt_qcow_cluster.o loop_file_fmt_qcow_cache.o +# Linux kernel module loop_file_fmt_qcow obj-$(CONFIG_BLK_DEV_XLOOP_FILE_FMT_QCOW) += loop_file_fmt_qcow.o +loop_file_fmt_qcow-objs += loop_file_fmt_qcow_main.o loop_file_fmt_qcow_cluster.o loop_file_fmt_qcow_cache.o
\ No newline at end of file diff --git a/kernel/Kconfig b/kernel/Kconfig deleted file mode 100644 index 2fe8cb5..0000000 --- a/kernel/Kconfig +++ /dev/null @@ -1,93 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# Loop device driver configuration -# - -config BLK_DEV_XLOOP - tristate "Loopback device support" - ---help--- - Saying Y here will allow you to use a regular file as a block - device; you can then create a file system on that block device and - mount it just as you would mount other block devices such as hard - drive partitions, CD-ROM drives or floppy drives. The loop devices - are block special device files with major number 7 and typically - called /dev/loop0, /dev/loop1 etc. - - This is useful if you want to check an ISO 9660 file system before - burning the CD, or if you want to use floppy images without first - writing them to floppy. Furthermore, some Linux distributions avoid - the need for a dedicated Linux partition by keeping their complete - root file system inside a DOS FAT file using this loop device - driver. - - To use the loop device, you need the losetup utility, found in the - util-linux package, see - <https://www.kernel.org/pub/linux/utils/util-linux/>. - - The loop device driver can also be used to "hide" a file system in - a disk partition, floppy, or regular file, either using encryption - (scrambling the data) or steganography (hiding the data in the low - bits of, say, a sound file). This is also safe if the file resides - on a remote file server. - - There are several ways of encrypting disks. Some of these require - kernel patches. The vanilla kernel offers the cryptoloop option - and a Device Mapper target (which is superior, as it supports all - file systems). If you want to use the cryptoloop, say Y to both - LOOP and CRYPTOLOOP, and make sure you have a recent (version 2.12 - or later) version of util-linux. Additionally, be aware that - the cryptoloop is not safe for storing journaled filesystems. - - Note that this loop device has nothing to do with the loopback - device used for network connections from the machine to itself. - - To compile this driver as a module, choose M here: the - module will be called loop. - - Most users will answer N here. - -config BLK_DEV_XLOOP_MIN_COUNT - int "Number of loop devices to pre-create at init time" - depends on BLK_DEV_XLOOP - default 8 - help - Static number of loop devices to be unconditionally pre-created - at init time. - - This default value can be overwritten on the kernel command - line or with module-parameter loop.max_loop. - - The historic default is 8. If a late 2011 version of losetup(8) - is used, it can be set to 0, since needed loop devices can be - dynamically allocated with the /dev/loop-control interface. - -config BLK_DEV_CRYPTOLOOP - tristate "Cryptoloop Support" - select CRYPTO - select CRYPTO_CBC - depends on BLK_DEV_XLOOP - ---help--- - Say Y here if you want to be able to use the ciphers that are - provided by the CryptoAPI as loop transformation. This might be - used as hard disk encryption. - - WARNING: This device is not safe for journaled file systems like - ext3 or Reiserfs. Please use the Device Mapper crypto module - instead, which can be configured to be on-disk compatible with the - cryptoloop device. - -config BLK_DEV_XLOOP_FILE_FMT_RAW - tristate "Loop device binary file format support" - depends on BLK_DEV_XLOOP - ---help--- - Say Y or M here if you want to enable the binary (RAW) file format - support of the loop device module. - -config BLK_DEV_XLOOP_FILE_FMT_QCOW - tristate "Loop device QCOW file format support" - depends on BLK_DEV_XLOOP - select ZLIB_INFLATE - select ZLIB_DEFLATE - ---help--- - Say Y or M here if you want to enable the QEMU's copy on write (QCOW) - file format support of the loop device module. diff --git a/kernel/Makefile b/kernel/Makefile index b7f2191..ca9019a 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -include $(PWD)/Kbuild.in +include $(PWD)/Kbuild ifndef KDIR KDIR = /lib/modules/$(shell uname -r)/build diff --git a/kernel/cmake/kernel.cmake b/kernel/cmake/kernel.cmake new file mode 100644 index 0000000..dd45b12 --- /dev/null +++ b/kernel/cmake/kernel.cmake @@ -0,0 +1,43 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# CMake macros to build and install Linux kernel modules +# Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de> +# + +# macro to define target for preparing the Kbuild file +macro(add_kernel_build BUILD_SOURCE_TARGET BUILD_SOURCE_FILE) + get_filename_component(BUILD_SOURCE_FILE_NAME ${BUILD_SOURCE_FILE} NAME) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${BUILD_SOURCE_FILE_NAME} + COMMAND ${CMAKE_COMMAND} + ARGS -E copy ${BUILD_SOURCE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${BUILD_SOURCE_FILE_NAME} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${BUILD_SOURCE_FILE} + VERBATIM) + add_custom_target(${BUILD_SOURCE_TARGET} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${BUILD_SOURCE_FILE_NAME}) +endmacro(add_kernel_build) + +# macro to define kernel module targets +macro(add_kernel_module MODULE_NAME KERNEL_DIR MODULE_MACRO MODULE_SOURCE_FILES MODULE_HEADER_FILES BUILD_SOURCE_TARGET) + # copy source files + foreach(MODULE_SOURCE_FILE ${MODULE_SOURCE_FILES}) + file(COPY ${MODULE_SOURCE_FILE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + endforeach() + # copy header files + foreach(MODULE_HEADER_FILE ${MODULE_HEADER_FILES}) + file(COPY ${MODULE_HEADER_FILE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + endforeach() + # define build command + set(MODULE_BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} ${MODULE_MACRO} + -C ${KERNEL_DIR}/build + M=${CMAKE_CURRENT_BINARY_DIR} modules + EXTRA_CFLAGS=${KERNEL_C_FLAGS}) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}.ko + COMMAND ${MODULE_BUILD_COMMAND} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${MODULE_SOURCE_FILES} ${MODULE_HEADER_FILES} ${BUILD_SOURCE_TARGET} + VERBATIM) + add_custom_target(${MODULE_NAME} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}.ko ${ARGV6}) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}.ko + DESTINATION ${KERNEL_DIR}/extra + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) +endmacro(add_kernel_module)
\ No newline at end of file diff --git a/kernel/loop_main.c b/kernel/loop_main.c index 9cd9c99..221b59f 100644 --- a/kernel/loop_main.c +++ b/kernel/loop_main.c @@ -357,7 +357,7 @@ static inline int is_xloop_device(struct file *file) { struct inode *i = file->f_mapping->host; - return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR; + return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == XLOOP_MAJOR; } static int xloop_validate_file(struct file *file, struct block_device *bdev) @@ -1698,7 +1698,7 @@ 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_ALIAS_BLOCKDEV_MAJOR(LOOP_MAJOR); +MODULE_ALIAS_BLOCKDEV_MAJOR(XLOOP_MAJOR); int xloop_register_transfer(struct xloop_func_table *funcs) { @@ -1923,7 +1923,7 @@ static int xloop_add(struct xloop_device **l, int i) atomic_set(&xlo->xlo_refcnt, 0); xlo->xlo_number = i; spin_lock_init(&xlo->xlo_lock); - disk->major = LOOP_MAJOR; + disk->major = XLOOP_MAJOR; disk->first_minor = i << part_shift; disk->fops = &xlo_fops; disk->private_data = xlo; @@ -2136,7 +2136,7 @@ static int __init xloop_init(void) * a 'dead' device node. */ if (max_xloop) { - nr = CONFIG_BLK_DEV_LOOP_MIN_COUNT; + nr = CONFIG_BLK_DEV_XLOOP_MIN_COUNT; range = 1UL << MINORBITS; } @@ -2145,7 +2145,7 @@ static int __init xloop_init(void) goto err_out; - if (register_blkdev(LOOP_MAJOR, "xloop")) { + if (register_blkdev(XLOOP_MAJOR, "xloop")) { err = -EIO; goto misc_out; } @@ -2158,7 +2158,7 @@ static int __init xloop_init(void) } #endif - blk_register_region(MKDEV(LOOP_MAJOR, 0), range, + blk_register_region(MKDEV(XLOOP_MAJOR, 0), range, THIS_MODULE, xloop_probe, NULL, NULL); /* pre-create number of devices given by config or max_xloop */ @@ -2195,8 +2195,8 @@ static void __exit xloop_exit(void) idr_for_each(&xloop_index_idr, &xloop_exit_cb, NULL); idr_destroy(&xloop_index_idr); - blk_unregister_region(MKDEV(LOOP_MAJOR, 0), range); - unregister_blkdev(LOOP_MAJOR, "xloop"); + blk_unregister_region(MKDEV(XLOOP_MAJOR, 0), range); + unregister_blkdev(XLOOP_MAJOR, "xloop"); #ifdef CONFIG_DEBUG_FS debugfs_remove(xloop_dbgfs_dir); diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index d1e359d..93fc41c 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -13,3 +13,7 @@ add_compile_options(-include ${CMAKE_CURRENT_SOURCE_DIR}/config.h) add_subdirectory(lib) add_subdirectory(libsmartcols) add_subdirectory(sys-utils) + +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/bash-completion/losetup + DESTINATION /usr/share/bash-completion/completions + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
\ No newline at end of file diff --git a/utils/sys-utils/CMakeLists.txt b/utils/sys-utils/CMakeLists.txt index 1e007dc..a36e88c 100644 --- a/utils/sys-utils/CMakeLists.txt +++ b/utils/sys-utils/CMakeLists.txt @@ -7,3 +7,8 @@ project(xloop-utils-sys-utils) add_executable(xlosetup ${CMAKE_CURRENT_SOURCE_DIR}/losetup.c) target_link_libraries(xlosetup LINK_PUBLIC libcommon libsmartcols) target_include_directories(xlosetup PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../lib ${CMAKE_CURRENT_SOURCE_DIR}/../libsmartcols) +install(TARGETS xlosetup DESTINATION bin) + +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/losetup.8 + DESTINATION /usr/share/man/man8 + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
\ No newline at end of file |