From 3aa70dccea7a018e9074702a478798b1f68d846f Mon Sep 17 00:00:00 2001 From: Berthold Gunreben Date: Wed, 8 Feb 2023 13:27:04 +0100 Subject: [PATCH 1/3] Add function ".log" for debugging and information Each log message created with .log will contain a severity, the originating file and the function where the log had been called. The function is called with: .log where severity is defined in https://en.wikipedia.org/wiki/Syslog#Severity_level --- common_functions | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/common_functions b/common_functions index 544db3cd6..1f96a6b07 100755 --- a/common_functions +++ b/common_functions @@ -20,6 +20,18 @@ # ################################################################ +.log() { + local LEVEL=${1} + __VERBOSE=${__VERBOSE:-4} + # https://en.wikipedia.org/wiki/Syslog#Severity_level + LOG_LEVELS=([0]="emerg" [1]="alert" [2]="crit" [3]="err" [4]="warning" [5]="notice" [6]="info" [7]="debug") + shift + if [ ${__VERBOSE} -ge ${LEVEL} ]; then + printf "[%-7s][%s:%s]: " ${LOG_LEVELS[$LEVEL]} ${BASH_SOURCE[1]} "${FUNCNAME[1]}()" + echo "$@" + fi +} + build_host_arch() { : ${BUILD_HOST_ARCH:=`uname -m`} # the linux kernel only knows armv7l, armv7hl is a userland definition From a0569af5d7a05f771d95bd4cd329fe4fdf679122 Mon Sep 17 00:00:00 2001 From: Berthold Gunreben Date: Wed, 8 Feb 2023 13:54:11 +0100 Subject: [PATCH 2/3] Fix z/VM Worker In z/VM, the system representation of the SWAP device is just a four digit hex number. However, the build script expects a partition within a disk instead. This change rewrites the device number into a block device when needed. --- build-vm | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/build-vm b/build-vm index 7d72e446b..51805d066 100644 --- a/build-vm +++ b/build-vm @@ -309,6 +309,9 @@ vm_parse_options() { } vm_set_buildstatus() { + .log 5 "VM_SWAP: $VM_SWAP" + .log 5 "VM_SWAPDEV: $VM_SWAPDEV" + .log 5 "BUILDSTATUS: $BUILDSTATUS" if test -n "$VM_ROOT" -a -n "$VM_SWAP" -a "$VM_SWAP_TYPE" != unattached -a -e "$VM_SWAP" ; then echo -n "BUILDSTATUS$1" >"$VM_SWAP" fi @@ -352,7 +355,16 @@ vm_shutdown() { test -n "$VM_WATCHDOG" && echo "### VM INTERACTION START ###" exec >&0 2>&0 # so that the logging tee finishes cd / + .log 5 "vm_shutdown called with $1. VM_SWAP is set to $VM_SWAP" test -n "$1" || set 1 + if test "$VM_TYPE" = "zvm"; then + if test ${#VM_SWAP} -eq 4; then + if (( 16#$VM_SWAP )); then + VM_SWAP="/dev/$(ls /sys/bus/ccw/devices/0.0.${VM_SWAP}/block/)1" + fi + fi + fi + .log 5 "Writing BUILDSTATUS ${BUILDSTATUS}$1 to SWAP $VM_SWAP" if test -n "$VM_SWAP" -a -e "$VM_SWAP" ; then swapoff "$VM_SWAP" 2>/dev/null echo -n "BUILDSTATUS$1" >"$VM_SWAP" @@ -669,6 +681,19 @@ vm_detect_2nd_stage() { echo "resolved swap device $VM_SWAP to $i" VM_SWAP=$i fi + # for zvm, there is just a 4-digig hex number + if test "$VM_TYPE" = "zvm"; then + if (( 16#$VM_SWAP )); then + if test ${#VM_SWAP} -eq 4; then + .log 5 "VM_SWAP id in z/VM is: $VM_SWAP" + # first, set the swap disk online, and then read the device node + test -d /sys/bus/ccw/devices/0.0.${VM_SWAP} && echo 1 > /sys/bus/ccw/devices/0.0.${VM_SWAP}/online + VM_SWAP="/dev/$(ls /sys/bus/ccw/devices/0.0.${VM_SWAP}/block/)1" + VM_SWAPDEV="${VM_SWAP}" + .log 5 "resolved swap device to ${VM_SWAP}" + fi + fi + fi for i in 1 2 3 4 5 6 7 8 9 10 ; do test -e "$VM_SWAP" && break test $i = 1 && echo "waiting for $VM_SWAP to appear" @@ -771,6 +796,7 @@ vm_set_defaults() { VM_ROOT_TYPE=file test -b "$VM_ROOT" && VM_ROOT_TYPE=device fi + .log 5 "VM_SWAP: $VM_SWAP" if test -n "$VM_SWAP" -a -z "$VM_SWAP_TYPE" ; then VM_SWAP_TYPE=file test -b "$VM_SWAP" && VM_SWAP_TYPE=device @@ -1003,7 +1029,14 @@ vm_first_stage() { echo "KIWI_PARAMETERS='${KIWI_PARAMETERS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data echo "VM_TELNET='${VM_TELNET//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data echo "VM_CONSOLE_INPUT='${VM_CONSOLE_INPUT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data - test -n "$VM_SWAP" && echo "VM_SWAP='${VM_SWAPDEV//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data + case $VM_TYPE in + zvm) + echo VM_SWAP=${ZVM_VOLUME_SWAP} >> $BUILD_ROOT/.build/build.data + ;; + *) + test -n "$VM_SWAP" && echo "VM_SWAP='${VM_SWAPDEV//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data + ;; + esac test -n "$VMDISK_MOUNT_OPTIONS" && echo "VMDISK_MOUNT_OPTIONS='${VMDISK_MOUNT_OPTIONS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data PERSONALITY=0 test -n "$PERSONALITY_SYSCALL" && PERSONALITY=`perl -e 'print syscall('$PERSONALITY_SYSCALL', 0)."\n"'` @@ -1110,6 +1143,7 @@ vm_first_stage() { vm_startup "${VM_ARGS[@]}" + .log 5 "Worker has been shutdown" # kill watchdog again if test -n "$VM_WATCHDOG" ; then echo "### VM INTERACTION END ###" @@ -1119,6 +1153,8 @@ vm_first_stage() { vm_attach_root if test -n "$VM_SWAP" -a -z "$RUN_SHELL" ; then vm_attach_swap + .log 5 "$(cat /proc/partitions)" + .log 5 "VM_SWAP: $VM_SWAP" BUILDSTATUS=$(dd if="$VM_SWAP" bs=12 count=1 status=none | tr '\0' a) case $BUILDSTATUS in BUILDSTATUS[029]) @@ -1200,6 +1236,15 @@ vm_save_statistics() { # args: resultdirs vm_wrapup_build() { test "$DO_STATISTICS" = 1 && vm_save_statistics + # in zvm, VM_SWAP is replaced by the actual device during the build. Unfortunately, build calls + # this function without the replacement taking place, thus lets do it anyways: + if test "$VM_TYPE" = "zvm"; then + if (( 16#$VM_SWAP )); then + if test ${#VM_SWAP} -eq 4; then + VM_SWAP="/dev/$(ls /sys/bus/ccw/devices/0.0.${VM_SWAP}/block/)1" + fi + fi + fi if test -n "$VM_SWAP"; then echo "... saving built packages" swapoff "$VM_SWAP" From 4bb87c73c075ee5a32ef9e5d96b1729a1cba177d Mon Sep 17 00:00:00 2001 From: Berthold Gunreben Date: Wed, 8 Feb 2023 13:57:03 +0100 Subject: [PATCH 3/3] Fix z/VM Worker The IUCV console connection is not always responding fast enough, therefore loop until the connection works. This change also removes the creation of a specific initrd, since the default has all needed modules available. --- build-vm-zvm | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/build-vm-zvm b/build-vm-zvm index 04d999db0..58ac76887 100644 --- a/build-vm-zvm +++ b/build-vm-zvm @@ -45,7 +45,7 @@ zvm_fatal() { } zvm_prevent_detach() { - if test "$1" = "150" -o "$1" = "0150"; then + if test "$1" = "100" -o "$1" = "0100"; then zvm_fatal "don't detach local root" fi } @@ -295,12 +295,17 @@ vm_startup_zvm() { # link root/swap to the worker zvm_cp volume_attach $VM_WORKER $ZVM_VOLUME_ROOT zvm_cp volume_attach $VM_WORKER $ZVM_VOLUME_SWAP + sleep 0.100 + .log 5 "IPL of worker $VM_WORKER" zvm_cp ipl $VM_WORKER $ZVM_VOLUME_ROOT - # start IUCV Console - # IPL needs some time until IPL really starts... - sleep 5 - # start iucv console. This blocks until build process is finished. - iucvconn $VM_WORKER lnxhvc0 + sleep 3 + .log 5 "Start iucv connection to $VM_WORKER" + # start iucv console multiple times, until guest starts. If connected, it blocks until build process is finished. + for start in {1..10}; do + sleep 1 + iucvconn $VM_WORKER lnxhvc0 && break + done + .log 5 "iucv connection to $VM_WORKER finished" # sleep some time before taking root and swap devices from worker # This might be critical regarding timing (IUCV_CONSOLE down, but machine still running) sleep 5 @@ -373,11 +378,9 @@ vm_fixup_zvm() { vm_kernel="/.build.kernel.kvm" test -e "${BUILD_ROOT}${vm_kernel}" -a ! -L "${BUILD_ROOT}${vm_kernel}" || cleanup_and_exit 1 "${vm_kernel} does not exist" kernel_version=$(get_kernel_version "${BUILD_ROOT}${vm_kernel}") - # add kernel modules to existing initrd - vm_initrd_obs_modules_zvm "${BUILD_ROOT}" "${vm_initrd}" "${kernel_version}" vm_initrd="${vm_initrd}-${kernel_version}" # copy initrd to build worker: - echo "copy $vm_initrd to $BUILD_ROOT" + .log 5 "copy $vm_initrd to $BUILD_ROOT" cp --remove-destination -a "${vm_initrd}" "${BUILD_ROOT}/boot/${vm_initrd}" # finally, install bootloader to the worker disk # XXX/TODO: does zipl read or write ${BUILD_ROOT}${vm_initrd}? Either @@ -406,6 +409,7 @@ vm_attach_swap_zvm() { VM_SWAP="/dev/$VM_SWAPDEV" VM_SWAPDEV="/dev/$VM_SWAPDEV" VM_SWAP_TYPE=device + sleep 0.100 } vm_detach_root_zvm () {