From: minyard@acm.org
To: qemu-devel@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: Corey Minyard <cminyard@mvista.com>, Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH v2] Sort the fw_cfg file list
Date: Mon, 14 Mar 2016 23:55:31 +0700 [thread overview]
Message-ID: <1457974531-8768-1-git-send-email-minyard@acm.org> (raw)
From: Gerd Hoffmann <kraxel@redhat.com>
Entries are inserted at the correct place instead of being
appended to the end in case sorting is enabled.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Added a machine type handling for compatibility.
Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
Don't add a new machine type in this version, just use the 2.6 one.
hw/i386/pc_piix.c | 1 +
hw/i386/pc_q35.c | 1 +
hw/nvram/fw_cfg.c | 32 ++++++++++++++++++++++++++------
include/hw/boards.h | 3 ++-
4 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 6f8c2cd..6c68e63 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -429,6 +429,7 @@ static void pc_i440fx_2_5_machine_options(MachineClass *m)
m->alias = NULL;
m->is_default = 0;
pcmc->save_tsc_khz = false;
+ m->dont_sort_fw_cfgs = 1;
SET_MACHINE_COMPAT(m, PC_COMPAT_2_5);
}
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 208a224..417fb57 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -354,6 +354,7 @@ static void pc_q35_2_5_machine_options(MachineClass *m)
pc_q35_2_6_machine_options(m);
m->alias = NULL;
pcmc->save_tsc_khz = false;
+ m->dont_sort_fw_cfgs = 1;
SET_MACHINE_COMPAT(m, PC_COMPAT_2_5);
}
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 79c5742..10dab77 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -28,6 +28,7 @@
#include "hw/isa/isa.h"
#include "hw/nvram/fw_cfg.h"
#include "hw/sysbus.h"
+#include "hw/boards.h"
#include "trace.h"
#include "qemu/error-report.h"
#include "qemu/config-file.h"
@@ -669,8 +670,9 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
FWCfgReadCallback callback, void *callback_opaque,
void *data, size_t len)
{
- int i, index;
+ int i, index, count;
size_t dsize;
+ MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
if (!s->files) {
dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;
@@ -678,13 +680,31 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, s->files, dsize);
}
- index = be32_to_cpu(s->files->count);
- assert(index < FW_CFG_FILE_SLOTS);
+ count = be32_to_cpu(s->files->count);
+ assert(count < FW_CFG_FILE_SLOTS);
+
+ index = count;
+ if (!mc->dont_sort_fw_cfgs) {
+ while (index > 0 && strcmp(filename, s->files->f[index-1].name) < 0) {
+ s->files->f[index] =
+ s->files->f[index - 1];
+ s->files->f[index].select =
+ cpu_to_be16(FW_CFG_FILE_FIRST + index);
+ s->entries[0][FW_CFG_FILE_FIRST + index] =
+ s->entries[0][FW_CFG_FILE_FIRST + index - 1];
+ index--;
+ }
+ memset(&s->files->f[index],
+ 0, sizeof(FWCfgFile));
+ memset(&s->entries[0][FW_CFG_FILE_FIRST + index],
+ 0, sizeof(FWCfgEntry));
+ }
pstrcpy(s->files->f[index].name, sizeof(s->files->f[index].name),
filename);
- for (i = 0; i < index; i++) {
- if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
+ for (i = 0; i <= count; i++) {
+ if (i != index &&
+ strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
error_report("duplicate fw_cfg file name: %s",
s->files->f[index].name);
exit(1);
@@ -698,7 +718,7 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
trace_fw_cfg_add_file(s, index, s->files->f[index].name, len);
- s->files->count = cpu_to_be32(index+1);
+ s->files->count = cpu_to_be32(count+1);
}
void fw_cfg_add_file(FWCfgState *s, const char *filename,
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 0f30959..f8d99d2 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -85,7 +85,8 @@ struct MachineClass {
no_sdcard:1,
has_dynamic_sysbus:1,
no_tco:1,
- pci_allow_0_address:1;
+ pci_allow_0_address:1,
+ dont_sort_fw_cfgs:1;
int is_default;
const char *default_machine_opts;
const char *default_boot_order;
--
2.5.0
next reply other threads:[~2016-03-14 16:55 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-14 16:55 minyard [this message]
2016-03-15 6:57 ` [Qemu-devel] [PATCH v2] Sort the fw_cfg file list Michael S. Tsirkin
2016-03-15 7:04 ` Gerd Hoffmann
2016-03-15 7:17 ` Michael S. Tsirkin
2016-03-15 7:34 ` Gerd Hoffmann
2016-03-15 7:45 ` Michael S. Tsirkin
2016-03-15 8:45 ` Gerd Hoffmann
2016-03-15 9:37 ` Michael S. Tsirkin
2016-03-15 12:38 ` Corey Minyard
2016-03-15 12:45 ` Michael S. Tsirkin
2016-03-15 12:56 ` Corey Minyard
2016-03-15 13:47 ` Michael S. Tsirkin
2016-03-15 14:43 ` Michael S. Tsirkin
2016-03-15 16:36 ` Corey Minyard
2016-03-15 17:01 ` Michael S. Tsirkin
2016-03-16 15:21 ` Corey Minyard
2016-03-16 15:34 ` Paolo Bonzini
2016-03-16 15:37 ` Michael S. Tsirkin
2016-03-15 13:03 ` Gerd Hoffmann
2016-03-15 13:19 ` Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457974531-8768-1-git-send-email-minyard@acm.org \
--to=minyard@acm.org \
--cc=cminyard@mvista.com \
--cc=kraxel@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).