accel: cleanup error output

Only emit "XXX accelerator not found", if there are not
further accelerators listed. eg

   accel=kvm:tcg

doesn't print a "KVM accelerator not found" warning
when it falls back to tcg, but a

   accel=kvm

prints a warning, since no fallback is given.

Suggested-by: Daniel P. Berrange <berrange@redhat.com>
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Message-Id: <20170717144527.24534-1-lvivier@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Laurent Vivier 2017-07-17 16:45:27 +02:00 committed by Paolo Bonzini
parent f70d3451fe
commit d73f024722

View File

@ -33,6 +33,7 @@
#include "sysemu/qtest.h" #include "sysemu/qtest.h"
#include "hw/xen/xen.h" #include "hw/xen/xen.h"
#include "qom/object.h" #include "qom/object.h"
#include "qemu/error-report.h"
static const TypeInfo accel_type = { static const TypeInfo accel_type = {
.name = TYPE_ACCEL, .name = TYPE_ACCEL,
@ -69,19 +70,20 @@ static int accel_init_machine(AccelClass *acc, MachineState *ms)
void configure_accelerator(MachineState *ms) void configure_accelerator(MachineState *ms)
{ {
const char *p; const char *accel, *p;
char buf[10]; char buf[10];
int ret; int ret;
bool accel_initialised = false; bool accel_initialised = false;
bool init_failed = false; bool init_failed = false;
AccelClass *acc = NULL; AccelClass *acc = NULL;
p = qemu_opt_get(qemu_get_machine_opts(), "accel"); accel = qemu_opt_get(qemu_get_machine_opts(), "accel");
if (p == NULL) { if (accel == NULL) {
/* Use the default "accelerator", tcg */ /* Use the default "accelerator", tcg */
p = "tcg"; accel = "tcg";
} }
p = accel;
while (!accel_initialised && *p != '\0') { while (!accel_initialised && *p != '\0') {
if (*p == ':') { if (*p == ':') {
p++; p++;
@ -89,7 +91,6 @@ void configure_accelerator(MachineState *ms)
p = get_opt_name(buf, sizeof(buf), p, ':'); p = get_opt_name(buf, sizeof(buf), p, ':');
acc = accel_find(buf); acc = accel_find(buf);
if (!acc) { if (!acc) {
fprintf(stderr, "\"%s\" accelerator not found.\n", buf);
continue; continue;
} }
if (acc->available && !acc->available()) { if (acc->available && !acc->available()) {
@ -100,9 +101,8 @@ void configure_accelerator(MachineState *ms)
ret = accel_init_machine(acc, ms); ret = accel_init_machine(acc, ms);
if (ret < 0) { if (ret < 0) {
init_failed = true; init_failed = true;
fprintf(stderr, "failed to initialize %s: %s\n", error_report("failed to initialize %s: %s",
acc->name, acc->name, strerror(-ret));
strerror(-ret));
} else { } else {
accel_initialised = true; accel_initialised = true;
} }
@ -110,13 +110,13 @@ void configure_accelerator(MachineState *ms)
if (!accel_initialised) { if (!accel_initialised) {
if (!init_failed) { if (!init_failed) {
fprintf(stderr, "No accelerator found!\n"); error_report("-machine accel=%s: No accelerator found", accel);
} }
exit(1); exit(1);
} }
if (init_failed) { if (init_failed) {
fprintf(stderr, "Back to %s accelerator.\n", acc->name); error_report("Back to %s accelerator", acc->name);
} }
} }