before: support kvm for aarch64 after: support kvm for aarch64, x86_64, riscv64
test: /srv/result/host-info/2021-01-07/vm-8p64g/debian-sid-riscv64/z9.288315 /srv/result/host-info/2021-01-07/vm-8p64g/debian-sid-x86_64/z9.288332 /srv/result/host-info/2021-01-07/vm-8p64g/debian-sid-aarch64/z9.288335
[how] put public options like $kernel, $initrd, $smp together, list different options like $machine, $bios, $nic according to different qemu command, then merge all options.
Signed-off-by: Liu Yinsi liuyinsi@163.com --- providers/qemu/kvm.sh | 110 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 95 insertions(+), 15 deletions(-)
diff --git a/providers/qemu/kvm.sh b/providers/qemu/kvm.sh index c926d3d..a8a2b33 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,56 @@ 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() +{ + qemu=( + qemu-system-aarch64 + qemu-kvm + qemu-system-x86_64 + ) + + for qemu in "${qemu[@]}" + 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 +121,78 @@ 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 ) +}
- "${kvm[@]}" --append "${append}" +run_qemu() +{ + 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 virtio-net-device,netdev=net0,mac=${mac} + -netdev bridge,br=br0,id=net0,helper=${helper} + ) + ;; + esac + + "${kvm[@]}" "${arch_option[@]}" --append "${append}" }
check_logfile write_logfile
-qemu_command parse_ipxe_script check_option_value -get_initrd + +set_initrd +set_bios +set_helper +set_nic +set_device +set_netdev +set_qemu
print_message
+public_option run_qemu
+run_qemu() +{
The below "case ... arch_option= esac" lines can be made a standalone function too.
- 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 virtio-net-device,netdev=net0,mac=${mac}
-netdev bridge,br=br0,id=net0,helper=${helper}
)
;;
- esac
Then let run_qemu() only call the below line.
- "${kvm[@]}" "${arch_option[@]}" --append "${append}"
Thanks, Fengguang
}
check_logfile write_logfile
-qemu_command parse_ipxe_script check_option_value -get_initrd
+set_initrd +set_bios +set_helper +set_nic +set_device +set_netdev +set_qemu
print_message
+public_option run_qemu -- 2.23.0
On Thu, Jan 07, 2021 at 05:05:39PM +0800, Wu Fengguang wrote:
+run_qemu() +{
The below "case ... arch_option= esac" lines can be made a standalone function too.
ok.
Then let run_qemu() only call the below line.
got it.
Thanks, Yinsi
- "${kvm[@]}" "${arch_option[@]}" --append "${append}"
Thanks, Fengguang
}
check_logfile write_logfile
-qemu_command parse_ipxe_script check_option_value -get_initrd
+set_initrd +set_bios +set_helper +set_nic +set_device +set_netdev +set_qemu
print_message
+public_option run_qemu -- 2.23.0
On Thu, Jan 07, 2021 at 12:25:38PM +0800, Liu Yinsi wrote:
before: support kvm for aarch64 after: support kvm for aarch64, x86_64, riscv64
test: /srv/result/host-info/2021-01-07/vm-8p64g/debian-sid-riscv64/z9.288315 /srv/result/host-info/2021-01-07/vm-8p64g/debian-sid-x86_64/z9.288332 /srv/result/host-info/2021-01-07/vm-8p64g/debian-sid-aarch64/z9.288335
[how] put public options like $kernel, $initrd, $smp together, list different options like $machine, $bios, $nic according to different qemu command, then merge all options.
Signed-off-by: Liu Yinsi liuyinsi@163.com
providers/qemu/kvm.sh | 110 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 95 insertions(+), 15 deletions(-)
diff --git a/providers/qemu/kvm.sh b/providers/qemu/kvm.sh index c926d3d..a8a2b33 100755 --- a/providers/qemu/kvm.sh +++ b/providers/qemu/kvm.sh @@ -18,12 +18,6 @@ check_logfile() } }
+set_qemu() +{
- qemu=(
qemu-system-aarch64
qemu-kvm
qemu-system-x86_64
- )
- for qemu in "${qemu[@]}"
- 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
If 'qemu-system-riscv64' might be used, would it be better to put it in 'qemu=()' ?
Thanks, Chenglong
+{
- qemu=(
qemu-system-aarch64
qemu-kvm
qemu-system-x86_64
- )
- for qemu in "${qemu[@]}"
- 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
If 'qemu-system-riscv64' might be used, would it be better to put it in 'qemu=()' ?
ok Thanks, Yinsi
Thanks, Chenglong