From e26f47019e645155bf60175b3b310808f798c999 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Tue, 17 Nov 2020 11:07:47 +0100 Subject: [dnbd3-rootfs] cmake refactor for dnbd3/xloop --- build-initramfs.sh | 9 +--- modules.d/dnbd3-rootfs/helper/build.inc | 84 ++++++++++++--------------------- modules.d/dnbd3-rootfs/module-setup.sh | 55 ++++++++++++--------- 3 files changed, 64 insertions(+), 84 deletions(-) diff --git a/build-initramfs.sh b/build-initramfs.sh index ce6521b3..f24d9b2e 100755 --- a/build-initramfs.sh +++ b/build-initramfs.sh @@ -76,19 +76,12 @@ declare -A module_xmount=( [commit]="0151375" ) -declare -A module_kernel_qcow2_linux=( +declare -A module_xloop=( [handler]="git" [url]="git://git.openslx.org/openslx-ng/xloop.git" [path]="${_repo_dir}/modules.d/dnbd3-rootfs/binaries/xloop" ) -declare -A module_kernel_qcow2_util_linux=( - [handler]="git" - [url]="git://git.openslx.org/openslx/kernel-qcow2-util-linux.git" - [path]="${_repo_dir}/modules.d/dnbd3-rootfs/binaries/kernel-qcow2-util-linux" - [branch]="xloop-hack" -) - declare -A override bootstrap() { diff --git a/modules.d/dnbd3-rootfs/helper/build.inc b/modules.d/dnbd3-rootfs/helper/build.inc index d549b8d1..9fe05cbf 100644 --- a/modules.d/dnbd3-rootfs/helper/build.inc +++ b/modules.d/dnbd3-rootfs/helper/build.inc @@ -10,10 +10,10 @@ build_initialize_components() { _deps_base_dir="${_mainmoddir}/binaries" # We might want to move the "binaries" repos from the dnbd3-rootfs module to main repo one day... # TODO check for its existence using modinfo -k - if [[ ! -f "${_deps_base_dir}/dnbd3/build/dnbd3.ko" ]] || \ - [[ ! -f "${_deps_base_dir}/dnbd3/build/dnbd3-client" ]]; then + if [[ ! -f "${_deps_base_dir}/dnbd3/build/src/kernel/dnbd3/dnbd3.ko" ]] || \ + [[ ! -f "${_deps_base_dir}/dnbd3/build/src/client/dnbd3-client" ]]; then echo "Could not find dnbd3, building it..." - if ! CMAKE_FLAGS="-DKERNEL_DIR=${kernel_headers}" \ + if ! CMAKE_FLAGS="-DKERNEL_BUILD_DIR=${kernel_headers}" \ build_compile_dnbd3 "${_deps_base_dir}/dnbd3/"; then echo "Failed to build dnbd3." return 1 @@ -169,83 +169,61 @@ build_compile_dnbd3() { local __doc__=' Compiles dnbd3 kernel module and client. - Provides the following file: - "$1/build/dnbd3.ko" - "$1/build/dnbd3-client" - Examples: `build_compile_dnbd3 path/to/dnbd3/source/` Passing the kernel version to cmake: - `CMAKE_FLAGS="-DKERNEL_VERSION=4.14.6-openslx+" \ + `CMAKE_FLAGS="-DKERNEL_BUILD_DIR=" \ build_compile_dnbd3 path/to/dnbd3/source/` ' + [ -z "$1" ] && return 1 pushd "$1" - # NOTE: The generic way would be: "./build.sh" but this tries to build - # more than we really need and takes more time. - mkdir --parents build - cd build - # Inject CMAKE_FLAGS as a way to control how cmake is called, - # e.g. to pass the kernel version - cmake ${CMAKE_FLAGS} \ - -DBUILD_FUSE_CLIENT=OFF \ - -DBUILD_KERNEL_MODULE=ON \ - -DBUILD_SERVER=OFF \ - -DBUILD_STRESSTEST=OFF \ - ../ - make -j dnbd3 dnbd3-client + ( + mkdir --parents build + cd build + # Inject CMAKE_FLAGS as a way to control how cmake is called, + # e.g. to pass the kernel version + cmake ${CMAKE_FLAGS} \ + -DDNBD3_KERNEL_MODULE=ON \ + -DDNBD3_CLIENT_FUSE=OFF \ + -DDNBD3_SERVER=OFF \ + -DDNBD3_SERVER_FUSE=OFF \ + .. + make -j + ) local ret=$? popd return $ret } build_clean_dnbd3() { - local __doc__='Clean the build of `build_compile_dnbd3`.' - rm --recursive --force "$1/build" - return $? + [ -z "$1" ] && return 1 + rm -rf "$1/build" } build_compile_xloop() { + [ -z "$1" ] && return 1 pushd "$1" - # https://lab.ks.uni-freiburg.de/projects/kernel-qcow2/wiki if [ -z "$kernel_headers" ]; then echo "Kernel header directory not set, ignoring." return 1 fi - make \ - KDIR="$kernel_headers" \ - CONFIG_BLK_DEV_LOOP=m \ - CONFIG_BLK_DEV_LOOP_FILE_FMT_RAW=m \ - CONFIG_BLK_DEV_LOOP_FILE_FMT_QCOW=m - local ret=$? - popd - return $ret -} -build_clean_xloop() { - pushd "$1" - make clean - local ret=$? - popd - return $ret -} -build_compile_xlosetup() { - pushd "$1" ( set -o errexit - ./autogen.sh - ./configure - make -j losetup - gcc -I./libsmartcols/src -O2 -o .libs/losetup sys-utils/losetup-losetup.o .libs/libcommon.a .libs/libsmartcols.a + mkdir -p build + cd build + cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DKERNEL_BUILD_DIR="$kernel_headers" \ + .. + make -j ) local ret=$? popd return $ret } -build_clean_xlosetup() { - pushd "$1" - make clean - local ret=$? - popd - return $ret +build_clean_xloop() { + [ -z "$1" ] && return 1 + rm -rf "$1/build" } build_compile_systemd_preserve_process_marker() { local __doc__=' diff --git a/modules.d/dnbd3-rootfs/module-setup.sh b/modules.d/dnbd3-rootfs/module-setup.sh index 955fd9b9..bc1daf0c 100755 --- a/modules.d/dnbd3-rootfs/module-setup.sh +++ b/modules.d/dnbd3-rootfs/module-setup.sh @@ -57,12 +57,13 @@ check() { # non-critical if failed $xmount_is_built || echo "Compiling 'xmount'/'libxmount_input_qemu' failed." - if [[ ! -f "$moddir/binaries/dnbd3/build/dnbd3.ko" ]] || \ - [[ ! -f "$moddir/binaries/dnbd3/build/dnbd3-client" ]]; then - CMAKE_FLAGS="-DKERNEL_VERSION=${kernel}" \ + if [[ ! -f "$moddir/binaries/dnbd3/build/src/kernel/dnbd3/dnbd3.ko" ]] || \ + [[ ! -f "$moddir/binaries/dnbd3/build/src/client/dnbd3-client" ]]; then + CMAKE_FLAGS="-DKERNEL_BUILD_DIR=${kernel}" \ build_compile_dnbd3 "$moddir/binaries/dnbd3/" [[ $? != 0 ]] && return 1 fi + # TODO xloop checks & remove them from installkernel if [[ ! -f "$moddir/binaries/systemd-preserve-process-marker/systemd-preserve-process-marker" ]]; then build_compile_systemd_preserve_process_marker \ "$moddir/binaries/systemd-preserve-process-marker/" @@ -90,31 +91,39 @@ depends() { echo base bash kernel-modules shutdown slx-dmsetup slx-network } installkernel() { - local block_kmod_dir="/lib/modules/${kernel}/kernel/drivers/block" + local extra_kmod_dir="/lib/modules/${kernel}/extra" # dnbd3 - mkdir -p "${initdir}/${block_kmod_dir}" - inst "${moddir}/binaries/dnbd3/build/dnbd3.ko" "${block_kmod_dir}/dnbd3.ko" + mkdir -p "${initdir}/${extra_kmod_dir}" + inst "${moddir}/binaries/dnbd3/build/src/kernel/dnbd3/dnbd3.ko" "${extra_kmod_dir}/dnbd3.ko" # kqcow2 kernel - local kqcow_loop_kmod_dir="${moddir}/binaries/xloop" - if [ -e "${kqcow_loop_kmod_dir}/xloop.ko" ] && \ - [ -e "${kqcow_loop_kmod_dir}/loop_file_fmt_raw.ko" ] && \ - [ -e "${kqcow_loop_kmod_dir}/loop_file_fmt_qcow.ko" ]; then - mkdir -p "${initdir}/${block_kmod_dir}/xloop" - for kmod in "${kqcow_loop_kmod_dir}/"*.ko ; do - inst "$kmod" "${block_kmod_dir}/xloop/$(basename $kmod)" - done - fi + local xloop_kmod_build_dir="${moddir}/binaries/xloop/build/src/kernel" + + for mod in xloop xloop_file_fmt_raw xloop_file_fmt_qcow; do + if [ ! -e "${xloop_kmod_build_dir}/${mod}/${mod}.ko" ]; then + derror "Failed to find '$mod' in '$xloop_kmod_build_dir'." + continue + # TODO fatal fail once we move completely to xloop + fi + inst "${xloop_kmod_build_dir}/${mod}/${mod}.ko" "${extra_kmod_dir}" + done +# if [ -e "${xloop_build_dir}/xloop.ko" ] && \ +# [ -e "${xloop_build_dir}/loop_file_fmt_raw.ko" ] && \ +# [ -e "${xloop_build_dir}/loop_file_fmt_qcow.ko" ]; then +# for kmod in "${kqcow_loop_kmod_dir}/"*.ko ; do +# inst "$kmod" "${block_kmod_dir}/xloop/$(basename $kmod)" +# done +# fi } install() { # region binaries - inst "$moddir/binaries/dnbd3/build/dnbd3-client" /usr/local/bin/dnbd3-client - inst "$moddir/binaries/systemd-preserve-process-marker/systemd-preserve-process-marker" \ + inst "${moddir}/binaries/dnbd3/build/src/client/dnbd3-client" /usr/local/bin/dnbd3-client + inst "${moddir}/binaries/systemd-preserve-process-marker/systemd-preserve-process-marker" \ /usr/local/bin/systemd-preserve-process-marker # xmount local \ - xmount_installation="$moddir/binaries/xmount/trunk/build/release_build" + xmount_installation="${moddir}/binaries/xmount/trunk/build/release_build" if [ -f "${xmount_installation}/usr/bin/xmount" ]; then inst "${xmount_installation}/usr/bin/xmount" /usr/bin/xmount for file in ${xmount_installation}/usr/lib/xmount/*; do @@ -127,12 +136,12 @@ install() { inst_libdir_file 'libafflib.so*' inst_libdir_file 'libewf.so*' fi - # kqcow2 losetup - local losetup_qcow2_dir="$moddir/binaries/kernel-qcow2-util-linux" - if [ -f "${losetup_qcow2_dir}/.libs/losetup" ]; then - inst "${losetup_qcow2_dir}/.libs/losetup" /usr/local/bin/xlosetup + # xlosetup + local xlosetup_build_path="${moddir}/binaries/xloop/build/src/utils/sys-utils/xlosetup" + if [ -f "$xlosetup_build_path" ]; then + inst "$xlosetup_build_path}" /usr/local/bin/xlosetup fi - local xloop_udev_rule="${moddir}/binaries/xloop/udev/50-xloop.rules" + local xloop_udev_rule="${moddir}/binaries/xloop/src/kernel/udev/50-xloop.rules" if [ -f "$xloop_udev_rule" ]; then inst "$xloop_udev_rule" "/etc/udev/rules.d/${xloop_udev_rule##*/}" fi -- cgit v1.2.3-55-g7522