smbios: Convert to error_report()

Improves diagnistics from ad hoc messages like

    Invalid SMBIOS UUID string

to

    qemu-system-x86_64: -smbios type=1,uuid=gaga: Invalid UUID

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Laszlo "ever the optimist" Ersek <lersek@redhat.com>
Message-id: 1370610036-10577-4-git-send-email-armbru@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Markus Armbruster 2013-06-07 15:00:33 +02:00 committed by Anthony Liguori
parent f3eededb2f
commit 5bb95e4186
2 changed files with 12 additions and 13 deletions

View file

@ -1053,7 +1053,6 @@ void do_smbios_option(const char *optarg)
{ {
#ifdef TARGET_I386 #ifdef TARGET_I386
if (smbios_entry_add(optarg) < 0) { if (smbios_entry_add(optarg) < 0) {
fprintf(stderr, "Wrong smbios provided\n");
exit(1); exit(1);
} }
#endif #endif

View file

@ -13,6 +13,7 @@
* GNU GPL, version 2 or (at your option) any later version. * GNU GPL, version 2 or (at your option) any later version.
*/ */
#include "qemu/error-report.h"
#include "sysemu/sysemu.h" #include "sysemu/sysemu.h"
#include "hw/i386/smbios.h" #include "hw/i386/smbios.h"
#include "hw/loader.h" #include "hw/loader.h"
@ -48,8 +49,7 @@ static int smbios_type4_count = 0;
static void smbios_validate_table(void) static void smbios_validate_table(void)
{ {
if (smbios_type4_count && smbios_type4_count != smp_cpus) { if (smbios_type4_count && smbios_type4_count != smp_cpus) {
fprintf(stderr, error_report("Number of SMBIOS Type 4 tables must match cpu count");
"Number of SMBIOS Type 4 tables must match cpu count.\n");
exit(1); exit(1);
} }
} }
@ -82,16 +82,16 @@ static void smbios_check_collision(int type, int entry)
if (entry == SMBIOS_TABLE_ENTRY && header->type == SMBIOS_FIELD_ENTRY) { if (entry == SMBIOS_TABLE_ENTRY && header->type == SMBIOS_FIELD_ENTRY) {
struct smbios_field *field = (void *)header; struct smbios_field *field = (void *)header;
if (type == field->type) { if (type == field->type) {
fprintf(stderr, "SMBIOS type %d field already defined, " error_report("SMBIOS type %d field already defined, "
"cannot add table\n", type); "cannot add table", type);
exit(1); exit(1);
} }
} else if (entry == SMBIOS_FIELD_ENTRY && } else if (entry == SMBIOS_FIELD_ENTRY &&
header->type == SMBIOS_TABLE_ENTRY) { header->type == SMBIOS_TABLE_ENTRY) {
struct smbios_structure_header *table = (void *)(header + 1); struct smbios_structure_header *table = (void *)(header + 1);
if (type == table->type) { if (type == table->type) {
fprintf(stderr, "SMBIOS type %d table already defined, " error_report("SMBIOS type %d table already defined, "
"cannot add field\n", type); "cannot add field", type);
exit(1); exit(1);
} }
} }
@ -166,7 +166,7 @@ static void smbios_build_type_1_fields(const char *t)
strlen(buf) + 1, buf); strlen(buf) + 1, buf);
if (get_param_value(buf, sizeof(buf), "uuid", t)) { if (get_param_value(buf, sizeof(buf), "uuid", t)) {
if (qemu_uuid_parse(buf, qemu_uuid) != 0) { if (qemu_uuid_parse(buf, qemu_uuid) != 0) {
fprintf(stderr, "Invalid SMBIOS UUID string\n"); error_report("Invalid UUID");
exit(1); exit(1);
} }
} }
@ -188,7 +188,7 @@ int smbios_entry_add(const char *t)
int size = get_image_size(buf); int size = get_image_size(buf);
if (size == -1 || size < sizeof(struct smbios_structure_header)) { if (size == -1 || size < sizeof(struct smbios_structure_header)) {
fprintf(stderr, "Cannot read smbios file %s\n", buf); error_report("Cannot read SMBIOS file %s", buf);
exit(1); exit(1);
} }
@ -204,7 +204,7 @@ int smbios_entry_add(const char *t)
table->header.length = cpu_to_le16(sizeof(*table) + size); table->header.length = cpu_to_le16(sizeof(*table) + size);
if (load_image(buf, table->data) != size) { if (load_image(buf, table->data) != size) {
fprintf(stderr, "Failed to load smbios file %s", buf); error_report("Failed to load SMBIOS file %s", buf);
exit(1); exit(1);
} }
@ -230,12 +230,12 @@ int smbios_entry_add(const char *t)
smbios_build_type_1_fields(t); smbios_build_type_1_fields(t);
return 0; return 0;
default: default:
fprintf(stderr, "Don't know how to build fields for SMBIOS type " error_report("Don't know how to build fields for SMBIOS type %ld",
"%ld\n", type); type);
exit(1); exit(1);
} }
} }
fprintf(stderr, "smbios: must specify type= or file=\n"); error_report("Must specify type= or file=");
return -1; return -1;
} }