before: support kvm for aarch64 after: support kvm for aarch64, x86_64, riscv64
test: /srv/result/host-info/2021-01-12/vm-2p8g/debian-sid-aarch64/z9.318111 /srv/result/host-info/2021-01-12/vm-2p8g/debian-sid-x86_64/z9.318142 /srv/result/host-info/2021-01-12/vm-2p8g/debian-sid-riscv64/z9.319551
[how] put public options like $kernel, $initrd, $smp together, set individual options like $machine, $bios, $nic according to different qemu command, then merge all options to run qemu.
Signed-off-by: Liu Yinsi liuyinsi@163.com --- providers/qemu/kvm.sh | 121 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 106 insertions(+), 15 deletions(-)
diff --git a/providers/qemu/kvm.sh b/providers/qemu/kvm.sh index 577bca1..a61acab 100755 --- a/providers/qemu/kvm.sh +++ b/providers/qemu/kvm.sh @@ -18,12 +18,6 @@ check_logfile() } }
-qemu_command() -{ - qemu=qemu-system-aarch64 - command -v $qemu >/dev/null || qemu=qemu-kvm -} - write_logfile() { ipxe_script=ipxe_script @@ -66,12 +60,57 @@ check_option_value() [ -n "$initrds" ] || exit }
-get_initrd() +set_initrd() { initrd=initrd cat $initrds > $initrd }
+set_bios() +{ + bios=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd + [ -f "$bios" ] || bios=/usr/share/ovmf/OVMF.fd +} + +set_helper() +{ + helper=/usr/libexec/qemu-bridge-helper + [ -f "$helper" ] || helper=/usr/lib/qemu/qemu-bridge-helper +} + +set_nic() +{ + nic="tap,model=virtio-net-pci,helper=$helper,br=br0,mac=${mac}" +} + +set_device() +{ + device="virtio-net-device,netdev=net0,mac=${mac}" +} + +set_netdev() +{ + netdev="bridge,br=br0,id=net0,helper=${helper}" +} + +set_qemu() +{ + qemus=( + qemu-system-aarch64 + qemu-kvm + qemu-system-x86_64 + qemu-system-riscv64 + ) + + for qemu in "${qemus[@]}" + do + [ -n "$(command -v ${qemu})" ] && break + done + + # debian has both qemu-system-x86_64 and qemu-system-riscv64 command + [[ $kernel =~ 'riscv64' ]] && qemu=qemu-system-riscv64 +} + print_message() { echo $SCHED_PORT @@ -83,36 +122,88 @@ print_message() sleep 5 }
-run_qemu() +public_option() { kvm=( $qemu - -machine virt-4.0,accel=kvm,gic-version=3 -kernel $kernel -initrd $initrd -smp $nr_cpu -m $memory - -cpu Kunpeng-920 - -bios /usr/share/qemu-efi-aarch64/QEMU_EFI.fd - -nic tap,model=virtio-net-pci,helper=/usr/libexec/qemu-bridge-helper,br=br0,mac=${mac} -k en-us -no-reboot -nographic -serial file:${log_file} -monitor null ) +} + +individual_option() +{ + case "$qemu" in + qemu-system-aarch64) + arch_option=( + -machine virt-4.0,accel=kvm,gic-version=3 + -cpu Kunpeng-920 + -bios $bios + -nic $nic + ) + ;; + qemu-kvm) + [ "$(arch)" == "aarch64" ] && arch_option=( + -machine virt-4.0,accel=kvm,gic-version=3 + -cpu Kunpeng-920 + -bios $bios + -nic $nic + ) + [ "$(arch)" == "x86_64" ] && arch_option=( + -bios $bios + -nic $nic + ) + ;; + qemu-system-x86_64) + arch_option=( + -bios $bios + -nic $nic + ) + ;; + qemu-system-riscv64) + arch_option=( + -machine virt + -device $device + -netdev $netdev + ) + ;; + esac +}
- "${kvm[@]}" --append "${append}" +run_qemu() +{ + "${kvm[@]}" "${arch_option[@]}" --append "${append}" +} + +set_options() +{ + set_initrd + set_bios + set_helper + set_nic + set_device + set_netdev + set_qemu }
check_logfile write_logfile
-qemu_command parse_ipxe_script check_option_value -get_initrd + +set_options
print_message
+public_option +individual_option + run_qemu
+set_qemu() +{
- qemus=(
qemu-system-aarch64
qemu-kvm
qemu-system-x86_64
qemu-system-riscv64
- )
- for qemu in "${qemus[@]}"
- do
[ -n "$(command -v ${qemu})" ] && break
This looks a bit easier:
command -v "$qemu" >/dev/null && break
- done
The above/below logics are completely differnt logics. It looks the below one looks more reasonable.
How about first test qemu-system-$arch, then try qemu-kvm?
- # debian has both qemu-system-x86_64 and qemu-system-riscv64 command
- [[ $kernel =~ 'riscv64' ]] && qemu=qemu-system-riscv64
+}
On Tue, Jan 12, 2021 at 06:10:57PM +0800, Wu Fengguang wrote:
+set_qemu() +{
- qemus=(
qemu-system-$arch
qemu-kvm
- )
- for qemu in "${qemus[@]}"
- do
[ -n "$(command -v ${qemu})" ] && break
This looks a bit easier:
command -v "$qemu" >/dev/null && break
ok, got it
- done
The above/below logics are completely differnt logics.
ok, i will sperate below to other function
It looks the below one looks more reasonable.
How about first test qemu-system-$arch, then try qemu-kvm?
ok, i will try
Thanks, Yinsi
- # debian has both qemu-system-x86_64 and qemu-system-riscv64 command
- [[ $kernel =~ 'riscv64' ]] && qemu=qemu-system-riscv64
+}