Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Z vm fixes #916

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion build-vm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"'`
Expand Down Expand Up @@ -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 ###"
Expand All @@ -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])
Expand Down Expand Up @@ -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"
Expand Down
22 changes: 13 additions & 9 deletions build-vm-zvm
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 () {
Expand Down
12 changes: 12 additions & 0 deletions common_functions
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down