From 9bc16ddde256971d6070c49899ce38d45ec43a89 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Thu, 12 Dec 2024 08:47:12 -0800 Subject: [PATCH 1/6] run_qemu.sh: move prepare_ndctl_build() invocation Regroup all ndctl stuff in the same place. Zero-functional change yet; bug-for-bug compatible. This including the bad error handling when $ndctl is not a directory. Signed-off-by: Marc Herbert --- run_qemu.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/run_qemu.sh b/run_qemu.sh index 8da4f67..b4cf9a4 100755 --- a/run_qemu.sh +++ b/run_qemu.sh @@ -1063,6 +1063,7 @@ make_rootfs() if [ -d "$ndctl" ]; then rsync "${rsync_opts[@]}" "$ndctl/" mkosi.extra/root/ndctl fi + prepare_ndctl_build fi if [ -f /etc/localtime ]; then mkdir -p mkosi.extra/etc/ @@ -1091,10 +1092,6 @@ make_rootfs() setup_depmod "mkosi.extra" setup_autorun "mkosi.extra" - if [[ $_arg_ndctl_build == "on" ]]; then - prepare_ndctl_build - fi - if [[ $_arg_gcp == "off" ]]; then mkosi_opts+=("--autologin") fi From 9b64ef4d2df8c532618edb0bf7c33759a3b19377 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Thu, 12 Dec 2024 10:30:55 -0800 Subject: [PATCH 2/6] run_qemu.sh: fail immediately when $ndctl is invalid Obvious typos and misconfiguration should not be reported after minutes. Signed-off-by: Marc Herbert --- run_qemu.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/run_qemu.sh b/run_qemu.sh index b4cf9a4..98d4572 100755 --- a/run_qemu.sh +++ b/run_qemu.sh @@ -407,6 +407,8 @@ process_options_logic() if [[ $_arg_kvm = "off" ]]; then accel="tcg" fi + + check_ndctl_dir } make_install_kernel() @@ -922,6 +924,14 @@ setup_network() EOF } +check_ndctl_dir() +{ + if [ -n "$ndctl" ]; then + [ -f "$ndctl/meson.build" ] || + fail 'ndctl="%s" is not a valid source directory\n' "$ndctl" + fi +} + prepare_ndctl_build() { cat <<- EOF > mkosi.postinst @@ -1060,7 +1070,7 @@ make_rootfs() rsync "${rsync_opts[@]}" ~/git/extra-scripts/bin/* mkosi.extra/root/bin/ fi if [[ $_arg_ndctl_build == "on" ]]; then - if [ -d "$ndctl" ]; then + if [ -n "$ndctl" ]; then rsync "${rsync_opts[@]}" "$ndctl/" mkosi.extra/root/ndctl fi prepare_ndctl_build From ae1ae57642d3f45d5b7be868ac18337201d6396b Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Thu, 12 Dec 2024 10:13:31 -0800 Subject: [PATCH 3/6] run_qemu.sh: do not silently fail to compile missing ndctl/ Abort when trying to compile a missing ndctl/ This unhides the current mkosi.postinst incompatibility with mkosi v15 (see https://github.com/systemd/mkosi/commit/9b626c647037bc8a) Simplify the ndctl logic: 1. either we really try to copy, compile and install ndctl - and abort when anything goes wrong; 2. or we don't try any of that at all. Remove intermediate, very confusing and very time-consuming states like this "opportunistic" compilation logic. Signed-off-by: Marc Herbert --- run_qemu.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/run_qemu.sh b/run_qemu.sh index 98d4572..b012ea0 100755 --- a/run_qemu.sh +++ b/run_qemu.sh @@ -937,9 +937,6 @@ prepare_ndctl_build() cat <<- EOF > mkosi.postinst #!/bin/bash -ex - if [[ ! -d /root/ndctl ]]; then - exit 0 - fi pushd /root/ndctl rm -rf build meson setup build @@ -1072,8 +1069,8 @@ make_rootfs() if [[ $_arg_ndctl_build == "on" ]]; then if [ -n "$ndctl" ]; then rsync "${rsync_opts[@]}" "$ndctl/" mkosi.extra/root/ndctl + prepare_ndctl_build # create mkosi.postinst which compiles fi - prepare_ndctl_build fi if [ -f /etc/localtime ]; then mkdir -p mkosi.extra/etc/ From b1e69b8abe3052437b0dabc77f3dcc729ffae730 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Thu, 12 Dec 2024 12:48:41 -0800 Subject: [PATCH 4/6] run_qemu.sh: make ndctl compilation compatible with mkosi v15+ mkosi v15 moved .postinst and others outside the container, see https://github.com/systemd/mkosi/commit/9b626c647037bc8a Extract new, re-usable "reinstall.sh" script. This is left in the image for either interactive testing, use or possibly by update_existing_rootfs() in the future. Prefix reinstall.sh invocation with 'mkosi-chroot' when needed. Signed-off-by: Marc Herbert --- mkosi/extra/root/ndctl/reinstall.sh | 18 ++++++++++++++++++ run_qemu.sh | 23 ++++++++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) create mode 100755 mkosi/extra/root/ndctl/reinstall.sh diff --git a/mkosi/extra/root/ndctl/reinstall.sh b/mkosi/extra/root/ndctl/reinstall.sh new file mode 100755 index 0000000..c66f72a --- /dev/null +++ b/mkosi/extra/root/ndctl/reinstall.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -e +set -x + +MYDIR=$(dirname "$0") + +main() +{ + cd "$MYDIR" + rm -rf build + meson setup build + meson configure -Dtest=enabled -Ddestructive=enabled build + meson compile -C build + meson install -C build +} + +main diff --git a/run_qemu.sh b/run_qemu.sh index b012ea0..d34f55e 100755 --- a/run_qemu.sh +++ b/run_qemu.sh @@ -934,15 +934,20 @@ check_ndctl_dir() prepare_ndctl_build() { - cat <<- EOF > mkosi.postinst - #!/bin/bash -ex - - pushd /root/ndctl - rm -rf build - meson setup build - meson configure -Dtest=enabled -Ddestructive=enabled build - meson compile -C build - meson install -C build + cp "${script_dir}"/mkosi/extra/root/ndctl/reinstall.sh \ + mkosi.extra/root/ndctl/ + cat <<- 'EOF' > mkosi.postinst + # v14: 'systemd-nspawn"; v15: "mkosi" + printf 'container=%s\n' "$container" + # .postinst and others moved outside container in mkosi v15, see + # https://github.com/systemd/mkosi/commit/9b626c647037bc8a + if [ -n "$container" ]; then + /root/ndctl/reinstall.sh + else + # The magic, short-lived $SCRIPT variable is already deprecated + # and we don't need it. + mkosi-chroot /root/ndctl/reinstall.sh + fi EOF chmod +x mkosi.postinst } From c179841a889b3ac45bf58c025036010ab4b208a1 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Thu, 12 Dec 2024 14:14:21 -0800 Subject: [PATCH 5/6] mkosi.ubuntu: add new pkgconf needed by ndctl on 24.04 pkg-config is gone in 24.04. Ubuntu 22.04 can install either. Signed-off-by: Marc Herbert --- mkosi.ubuntu.default.tmpl | 1 + 1 file changed, 1 insertion(+) diff --git a/mkosi.ubuntu.default.tmpl b/mkosi.ubuntu.default.tmpl index 0995aff..01d6ea6 100644 --- a/mkosi.ubuntu.default.tmpl +++ b/mkosi.ubuntu.default.tmpl @@ -20,6 +20,7 @@ Packages= libkeyutils-dev python3 cmake + pkgconf openssh-server gdb git From 30e18000205e7213dd3a14dd7486e85f0eb5094e Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Thu, 12 Dec 2024 08:41:22 -0800 Subject: [PATCH 6/6] .github: enable ndctl build As --ndctl-build is on by default, the "real" way to enable ndctl is to define $ndctl. Add --ndctl-build anyway in case the default ever changes. Signed-off-by: Marc Herbert --- .github/workflows/main.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3f9811f..416f681 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: img_distro: ubuntu img_rel: noble arch: [x86_64] - run_opts: [--cxl] + run_opts: [--cxl --ndctl-build] steps: - uses: actions/checkout@v4 @@ -79,6 +79,13 @@ jobs: sudo apt install -y autoconf sudo make -C argbash-${AB_VER}/resources install PREFIX=/usr/local/ + - name: download ndctl + uses: actions/checkout@v4 + with: + repository: pmem/ndctl + ref: v80 + path: ndctl + - name: download kernel uses: actions/checkout@v4 with: @@ -105,6 +112,7 @@ jobs: mkosi --version cd kernel distro=${{ matrix.cfg.img_distro }} rev=${{ matrix.cfg.img_rel }} \ + ndctl='${{ github.workspace }}'/ndctl \ ../run_qemu/run_qemu.sh -v --no-run ${{ matrix.run_opts }} # TODO: drop --no-run thanks to "nested KVM" or something?