From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [kvm-unit-tests PATCH v2 5/5] arch/run: unify accelerator detection Date: Thu, 29 Jun 2017 16:28:24 +0200 Message-ID: <20170629142824.13666-1-rkrcmar@redhat.com> References: <20170628200857.1718-6-rkrcmar@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Paolo Bonzini , Drew Jones , Laurent Vivier , Thomas Huth , David Hildenbrand To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:37730 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751974AbdF2O2q (ORCPT ); Thu, 29 Jun 2017 10:28:46 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 777CFA6493 for ; Thu, 29 Jun 2017 14:28:46 +0000 (UTC) In-Reply-To: <20170628200857.1718-6-rkrcmar@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 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ář --- arm/run | 22 ++-------------------- powerpc/run | 20 ++------------------ s390x/run | 20 ++------------------ scripts/arch-run.bash | 26 ++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 56 deletions(-) diff --git a/arm/run b/arm/run index 6fc9bb6bb111..fd280ee19837 100755 --- a/arm/run +++ b/arm/run @@ -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 $? diff --git a/powerpc/run b/powerpc/run index 288504e0c330..597ab96ed8a8 100755 --- a/powerpc/run +++ b/powerpc/run @@ -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 $? diff --git a/s390x/run b/s390x/run index af22e8b269d6..0980504448ce 100755 --- a/s390x/run +++ b/s390x/run @@ -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 $? diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index 994c1aa9c0cd..afad43d2d1ad 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -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 +} -- 2.13.2