Skip to content

Commit 7d5e4c0

Browse files
authored
Pass VM-specific extra args to VM using --vm-args option. (openSUSE#825)
Works only if --vm-type option is specified. Sometimes it's necessary to add extra options to a VM running on a specific worker. For example, Oracle Linux 8 runs quite old systemd-nspawn that knows nothing about faccessat2 system call and filters it out using seccomp system call filter, breaking newer glibc. A workaround is to pass --system-call-filter=faccessat2 option to nspawn VM on OBS workers running on these systems. This change implements --vm-args option that allows to pass extra arguments to many (but not all) VM types. Other VM types just ignore this option. Signed-off-by: Oleg Girko <[email protected]> Signed-off-by: Oleg Girko <[email protected]> Co-authored-by: Oleg Girko <[email protected]>
1 parent 097cc68 commit 7d5e4c0

File tree

10 files changed

+23
-12
lines changed

10 files changed

+23
-12
lines changed

build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ Known Parameters:
345345
Use virtual machine instead of chroot
346346
TYPE is one of xen|kvm|uml|qemu|lxc|zvm|openstack|ec2|docker|pvm|nspawn
347347
348+
--vm-args ARGS
349+
Pass extra arguments to virtual machine
350+
To pass multiple arguments, separate them with spaces
351+
Use regular shell quotes if arguments contain spaces
352+
348353
--vm-worker GUEST
349354
GUEST is a z/VM build worker controlled by the controlling
350355
z/VM build machine.

build-vm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ VM_ROOTDEV=/dev/hda1
3232
VM_SWAPDEV=/dev/hda2
3333

3434
VM_TYPE=
35+
declare -a VM_ARGS
3536
VM_TYPE_PRIVILEGED=
3637
VM_ROOT=
3738
VM_SWAP=
@@ -160,6 +161,11 @@ vm_parse_options() {
160161
esac
161162
shift
162163
;;
164+
-vm-args)
165+
needarg
166+
eval "VM_ARGS=($ARG)"
167+
shift
168+
;;
163169
-vm-worker)
164170
needarg
165171
VM_WORKER="$ARG"
@@ -1096,7 +1102,7 @@ vm_first_stage() {
10961102
echo "### VM INTERACTION START ###"
10971103
fi
10981104

1099-
vm_startup
1105+
vm_startup "${VM_ARGS[@]}"
11001106

11011107
# kill watchdog again
11021108
if test -n "$VM_WATCHDOG" ; then

build-vm-docker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ vm_startup_docker() {
3737
--mount "type=bind,source=$BUILD_ROOT,destination=/mnt" \
3838
--mount "type=bind,source=/proc,destination=/mnt/proc" \
3939
--mount "type=bind,source=/dev/pts,destination=/mnt/dev/pts" \
40-
busybox chroot /mnt "$vm_init_script"
40+
"$@" busybox chroot /mnt "$vm_init_script"
4141
BUILDSTATUS="$?"
4242
test "$BUILDSTATUS" != 255 || BUILDSTATUS=3
4343
cleanup_and_exit "$BUILDSTATUS"

build-vm-emulator

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ vm_startup_emulator() {
3636
elif test "${EMULATOR_SCRIPT:0:1}" != / ; then
3737
EMULATOR_SCRIPT="./$EMULATOR_SCRIPT"
3838
fi
39-
set -- "$EMULATOR_SCRIPT" "$VM_ROOT" "$VM_SWAP"
39+
set -- "$EMULATOR_SCRIPT" "$@" "$VM_ROOT" "$VM_SWAP"
4040
echo "$@"
4141
if ! "$@"; then
4242
popd

build-vm-kvm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ kvm_add_console_args() {
292292

293293
vm_startup_kvm() {
294294
qemu_bin="$kvm_bin"
295-
qemu_args=(-drive file="$VM_ROOT",format=raw,if=none,id=disk,$kvm_drive_opts -device "$kvm_device$kvm_device_opts",drive=disk,serial=0)
295+
qemu_args=("$@" -drive file="$VM_ROOT",format=raw,if=none,id=disk,$kvm_drive_opts -device "$kvm_device$kvm_device_opts",drive=disk,serial=0)
296296
if [ -n "$VM_USER" ] ; then
297297
getent passwd "$VM_USER" > /dev/null || cleanup_and_exit 3 "cannot find KVM user '$VM_USER'"
298298
elif test $UID = 0 ; then

build-vm-lxc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ vm_startup_lxc() {
4545
lxc_get_id
4646
LXCCONF="$BUILD_ROOT/.build.lxc.conf"
4747
buildroot_rm .build.lxc.conf
48-
vm_startup_lxc_$LXC_TYPE
48+
vm_startup_lxc_$LXC_TYPE "$@"
4949
BUILDSTATUS="$?"
5050
test "$BUILDSTATUS" != 255 || BUILDSTATUS=3
5151
cleanup_and_exit "$BUILDSTATUS"
@@ -83,11 +83,11 @@ vm_startup_lxc_standalone() {
8383
case "$LXCVERSION" in
8484
1.0.8|1.1.*|[234].*)
8585
lxc-create -n "$LXCID" -f "$LXCCONF" -t none || cleanup_and_exit 1
86-
lxc-start -n "$LXCID" -F "$vm_init_script"
86+
lxc-start -n "$LXCID" -F "$@" "$vm_init_script"
8787
;;
8888
1.0.*)
8989
lxc-create -n "$LXCID" -f "$LXCCONF" || cleanup_and_exit 1
90-
lxc-start -n "$LXCID" "$vm_init_script"
90+
lxc-start -n "$LXCID" "$@" "$vm_init_script"
9191
;;
9292
*)
9393
echo "Unsupported lxc version $LXCVERSION!" >&2
@@ -152,7 +152,7 @@ vm_startup_lxc_libvirt() {
152152
buildroot_rm /etc/mtab
153153
echo "rootfs / rootfs rw 0 0" > $BUILD_ROOT/etc/mtab
154154
# could LOGFILE be used instead?
155-
lxcsh create --console $LXCCONF | sed -ure 's/\x0d//g;:redo /.\x08/{s/.\x08//; b redo}'
155+
lxcsh create --console "$@" $LXCCONF | sed -ure 's/\x0d//g;:redo /.\x08/{s/.\x08//; b redo}'
156156
exitcode="${PIPESTATUS[0]}"
157157
if [ "$exitcode" -gt 0 ]; then
158158
return $exitcode # libvirt errors

build-vm-nspawn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ vm_startup_nspawn() {
3737
if test -n "$VM_TYPE_PRIVILEGED"; then
3838
privileged_opt=--privileged
3939
fi
40-
systemd-nspawn -D "$BUILD_ROOT" -M "$name" --private-network $pipe_opt $privileged_opt "$vm_init_script"
40+
systemd-nspawn -D "$BUILD_ROOT" -M "$name" --private-network $pipe_opt $privileged_opt "$@" "$vm_init_script"
4141
BUILDSTATUS="$?"
4242
cleanup_and_exit "$BUILDSTATUS"
4343
}

build-vm-qemu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ vm_startup_qemu() {
144144
qemu_options="$qemu_options -object rng-random,filename=$rng_dev,id=rng0 -device $qemu_rng_device,rng=rng0"
145145
fi
146146

147-
qemu_args=(-drive file="$VM_ROOT",format=raw,if=none,id=disk,cache=unsafe -device "$qemu_device",drive=disk,serial=0)
147+
qemu_args=($@ -drive file="$VM_ROOT",format=raw,if=none,id=disk,cache=unsafe -device "$qemu_device",drive=disk,serial=0)
148148
if [ -n "$VM_USER" ] ; then
149149
getent passwd "$VM_USER" > /dev/null || cleanup_and_exit 3 "cannot find KVM user '$VM_USER'"
150150
elif test $UID = 0 ; then

build-vm-uml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ vm_verify_options_uml() {
2929
}
3030

3131
vm_startup_uml() {
32-
set -- $uml_kernel initrd=$uml_initrd root=ubda init="$vm_init_script" $vm_linux_always_append elevator=noop ubda=$VM_ROOT ubdb=$VM_SWAP ${VM_MEMSIZE:+mem=$VM_MEMSIZE}
32+
set -- $uml_kernel "$@" initrd=$uml_initrd root=ubda init="$vm_init_script" $vm_linux_always_append elevator=noop ubda=$VM_ROOT ubdb=$VM_SWAP ${VM_MEMSIZE:+mem=$VM_MEMSIZE}
3333
echo "$@"
3434
"$@"
3535
}

build-vm-xen

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ vm_startup_xen() {
8282
XLDISK=
8383
XLDISK="\"${XMROOT#disk=}\""
8484
test -n "$XMSWAP" && XLDISK="$XLDISK, \"${XMSWAP#disk=}\""
85-
set -- xl create -c $XEN_CONF_FILE name="\"build_$XENID\"" "disk=[ $XLDISK ]" extra=\""$vm_linux_always_append init="$vm_init_script" rd.driver.pre=binfmt_misc $vm_linux_kernel_parameter console=$VM_CONSOLE"\"
85+
set -- xl create -c $XEN_CONF_FILE "$@" name="\"build_$XENID\"" "disk=[ $XLDISK ]" extra=\""$vm_linux_always_append init="$vm_init_script" rd.driver.pre=binfmt_misc $vm_linux_kernel_parameter console=$VM_CONSOLE"\"
8686
fi
8787
if test "$PERSONALITY" != 0 ; then
8888
# have to switch back to PER_LINUX to make xm work

0 commit comments

Comments
 (0)