vl: Only choose enabled accelerators in configure_accelerators

By choosing "tcg:kvm" when kvm is not enabled, we generate
an incorrect warning: "invalid accelerator kvm".

At the same time, use g_str_has_suffix rather than open-coding
the same operation.

Presumably the inverse is also true with --disable-tcg.

Fixes: 28a0961757
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed by: Aleksandar Markovic <amarkovic@wavecomp.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2020-01-09 12:07:30 +11:00
parent a024b09067
commit 755ee1f301
1 changed files with 13 additions and 8 deletions

21
vl.c
View File

@ -2766,21 +2766,26 @@ static void configure_accelerators(const char *progname)
if (accel == NULL) {
/* Select the default accelerator */
if (!accel_find("tcg") && !accel_find("kvm")) {
error_report("No accelerator selected and"
" no default accelerator available");
exit(1);
} else {
int pnlen = strlen(progname);
if (pnlen >= 3 && g_str_equal(&progname[pnlen - 3], "kvm")) {
bool have_tcg = accel_find("tcg");
bool have_kvm = accel_find("kvm");
if (have_tcg && have_kvm) {
if (g_str_has_suffix(progname, "kvm")) {
/* If the program name ends with "kvm", we prefer KVM */
accel = "kvm:tcg";
} else {
accel = "tcg:kvm";
}
} else if (have_kvm) {
accel = "kvm";
} else if (have_tcg) {
accel = "tcg";
} else {
error_report("No accelerator selected and"
" no default accelerator available");
exit(1);
}
}
accel_list = g_strsplit(accel, ":", 0);
for (tmp = accel_list; *tmp; tmp++) {