yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
218e99
From 3a4932455a7f7926b673089170f55de437eec5fa Mon Sep 17 00:00:00 2001
218e99
From: Markus Armbruster <armbru@redhat.com>
218e99
Date: Sat, 2 Nov 2013 10:01:22 +0100
218e99
Subject: [PATCH 22/29] smbios: Improve diagnostics for conflicting entries
218e99
218e99
RH-Author: Markus Armbruster <armbru@redhat.com>
218e99
Message-id: <1383386488-29789-6-git-send-email-armbru@redhat.com>
218e99
Patchwork-id: 55243
218e99
O-Subject: [PATCH 7.0 qemu-kvm 05/11] smbios: Improve diagnostics for conflicting entries
218e99
Bugzilla: 994490
218e99
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
218e99
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
218e99
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
218e99
From: Markus Armbruster <armbru@redhat.com>
218e99
218e99
We allow either tables or fields for the same type.  Makes sense,
218e99
because SeaBIOS uses fields only when no tables are present.
218e99
218e99
We do this by searching the SMBIOS blob for a previously added table
218e99
or field.  Error messages look like this:
218e99
218e99
    qemu-system-x86_64: -smbios type=1,serial=42: SMBIOS type 1 table already defined, cannot add field
218e99
218e99
User needs to know that "table" is defined by -smbios file=..., and
218e99
"field" by -smbios type=...
218e99
218e99
Instead of searching the blob, record additions of interest, and check
218e99
that.  Simpler, and makes better error messages possible:
218e99
218e99
    qemu-system-x86_64: -smbios file=smbios_type_1.bin: Can't mix file= and type= for same type
218e99
    qemu-system-x86_64: -smbios type=1,serial=42,serial=99: This is the conflicting setting
218e99
218e99
Signed-off-by: Markus Armbruster <armbru@redhat.com>
218e99
Reviewed-by: Eric Blake <eblake@redhat.com>
218e99
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
218e99
(cherry picked from commit ec2df8c10a4585ba4641ae482cf2f5f13daa810e)
218e99
---
218e99
 hw/i386/smbios.c | 43 +++++++++++++++++--------------------------
218e99
 1 file changed, 17 insertions(+), 26 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 hw/i386/smbios.c |   43 +++++++++++++++++--------------------------
218e99
 1 files changed, 17 insertions(+), 26 deletions(-)
218e99
218e99
diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c
218e99
index abfd6f7..4263551 100644
218e99
--- a/hw/i386/smbios.c
218e99
+++ b/hw/i386/smbios.c
218e99
@@ -48,6 +48,12 @@ static uint8_t *smbios_entries;
218e99
 static size_t smbios_entries_len;
218e99
 static int smbios_type4_count = 0;
218e99
 
218e99
+static struct {
218e99
+    bool seen;
218e99
+    int headertype;
218e99
+    Location loc;
218e99
+} first_opt[2];
218e99
+
218e99
 static QemuOptsList qemu_smbios_opts = {
218e99
     .name = "smbios",
218e99
     .head = QTAILQ_HEAD_INITIALIZER(qemu_smbios_opts.head),
218e99
@@ -159,35 +165,20 @@ uint8_t *smbios_get_table(size_t *length)
218e99
  */
218e99
 static void smbios_check_collision(int type, int entry)
218e99
 {
218e99
-    uint16_t *num_entries = (uint16_t *)smbios_entries;
218e99
-    struct smbios_header *header;
218e99
-    char *p;
218e99
-    int i;
218e99
-
218e99
-    if (!num_entries)
218e99
-        return;
218e99
-
218e99
-    p = (char *)(num_entries + 1);
218e99
-
218e99
-    for (i = 0; i < *num_entries; i++) {
218e99
-        header = (struct smbios_header *)p;
218e99
-        if (entry == SMBIOS_TABLE_ENTRY && header->type == SMBIOS_FIELD_ENTRY) {
218e99
-            struct smbios_field *field = (void *)header;
218e99
-            if (type == field->type) {
218e99
-                error_report("SMBIOS type %d field already defined, "
218e99
-                             "cannot add table", type);
218e99
-                exit(1);
218e99
-            }
218e99
-        } else if (entry == SMBIOS_FIELD_ENTRY &&
218e99
-                   header->type == SMBIOS_TABLE_ENTRY) {
218e99
-            struct smbios_structure_header *table = (void *)(header + 1);
218e99
-            if (type == table->type) {
218e99
-                error_report("SMBIOS type %d table already defined, "
218e99
-                             "cannot add field", type);
218e99
+    if (type < ARRAY_SIZE(first_opt)) {
218e99
+        if (first_opt[type].seen) {
218e99
+            if (first_opt[type].headertype != entry) {
218e99
+                error_report("Can't mix file= and type= for same type");
218e99
+                loc_push_restore(&first_opt[type].loc);
218e99
+                error_report("This is the conflicting setting");
218e99
+                loc_pop(&first_opt[type].loc);
218e99
                 exit(1);
218e99
             }
218e99
+        } else {
218e99
+            first_opt[type].seen = true;
218e99
+            first_opt[type].headertype = entry;
218e99
+            loc_save(&first_opt[type].loc);
218e99
         }
218e99
-        p += le16_to_cpu(header->length);
218e99
     }
218e99
 }
218e99
 
218e99
-- 
218e99
1.7.1
218e99