@@ -10,26 +10,8 @@ if [ -z "$STANDALONE" ]; then
fi
processor="$PROCESSOR"
-if [ -c /dev/kvm ]; then
- if [ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]; then
- kvm_available=yes
- elif [ "$HOST" = "aarch64" ]; then
- kvm_available=yes
- fi
-fi
-
-if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
- echo "KVM is needed, but not available on this host"
- exit 2
-fi
-
-if [ -z "$ACCEL" ]; then
- if [ "$kvm_available" = "yes" ]; then
- ACCEL="kvm"
- else
- ACCEL="tcg"
- fi
-fi
+ACCEL=$(get_qemu_accelerator) ||
+ exit $?
qemu=$(search_qemu_binary) ||
exit $?
@@ -9,24 +9,8 @@ if [ -z "$STANDALONE" ]; then
source scripts/arch-run.bash
fi
-if [ -c /dev/kvm ]; then
- if [ "$HOST" = "ppc64" ] && [ "$ARCH" = "ppc64" ]; then
- kvm_available=yes
- fi
-fi
-
-if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
- echo "KVM is needed, but not available on this host"
- exit 2
-fi
-
-if [ -z "$ACCEL" ]; then
- if [ "$kvm_available" = "yes" ]; then
- ACCEL="kvm"
- else
- ACCEL="tcg"
- fi
-fi
+ACCEL=$(get_qemu_accelerator) ||
+ exit $?
qemu=$(search_qemu_binary) ||
exit $?
@@ -9,24 +9,8 @@ if [ -z "$STANDALONE" ]; then
source scripts/arch-run.bash
fi
-if [ -c /dev/kvm ]; then
- if [ "$HOST" = "s390x" ] && [ "$ARCH" = "s390x" ]; then
- kvm_available=yes
- fi
-fi
-
-if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
- echo "KVM is needed, but not available on this host"
- exit 2
-fi
-
-if [ -z "$ACCEL" ]; then
- if [ "$kvm_available" = "yes" ]; then
- ACCEL="kvm"
- else
- ACCEL="tcg"
- fi
-fi
+ACCEL=$(get_qemu_accelerator) ||
+ exit $?
qemu=$(search_qemu_binary) ||
exit $?
@@ -272,3 +272,29 @@ trap_exit_push ()
local old_exit=$(trap -p EXIT | sed "s/^[^']*'//;s/'[^']*$//")
trap -- "$1; $old_exit" EXIT
}
+
+kvm_available ()
+{
+ [ -c /dev/kvm ] ||
+ return 1
+
+ [ "$HOST" = "$ARCH_NAME" ] ||
+ [ "$HOST" = aarch64 -a "$ARCH" = arm ] ||
+ [ "$HOST" = x86_64 -a "$ARCH" = i386 ]
+}
+
+get_qemu_accelerator ()
+{
+ if [ "$ACCEL" = "kvm" ] && ! kvm_available; then
+ echo "KVM is needed, but not available on this host" >&2
+ return 2
+ fi
+
+ if [ "$ACCEL" ]; then
+ echo $ACCEL
+ elif kvm_available; then
+ echo kvm
+ else
+ echo tcg
+ fi
+}
Use the same mechanism as search_qemu_binary(). The simplified [ "$HOST" = "$ARCH_NAME" ] check will mishandle a case if you compile for $arch on $arch then try to run it with $other_arch/run, but that isn't really worth checking. Signed-off-by: Radim Krčmář <rkrcmar@redhat.com> --- arm/run | 22 ++-------------------- powerpc/run | 20 ++------------------ s390x/run | 20 ++------------------ scripts/arch-run.bash | 26 ++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 56 deletions(-)