All of lore.kernel.org
 help / color / mirror / Atom feed
From: <arei.gonglei@huawei.com>
To: qemu-devel@nongnu.org
Cc: chenliang88@huawei.com, weidong.huang@huawei.com, mst@redhat.com,
	aik@ozlabs.ru, hutao@cn.fujitsu.com, armbru@redhat.com,
	kraxel@redhat.com, akong@redhat.com, agraf@suse.de,
	Gonglei <arei.gonglei@huawei.com>,
	aliguori@amazon.com, gaowanlong@cn.fujitsu.com,
	ehabkost@redhat.com, luonengjun@huawei.com,
	peter.huangpeng@huawei.com, hani@linux.com, stefanha@redhat.com,
	pbonzini@redhat.com, lcapitulino@redhat.com, kwolf@redhat.com,
	peter.crosthwaite@xilinx.com, imammedo@redhat.com,
	afaerber@suse.de
Subject: [Qemu-devel] [PATCH v5 3/8] fw_cfg: add fw_cfg_machine_reset function
Date: Mon, 4 Aug 2014 20:46:17 +0800	[thread overview]
Message-ID: <1407156382-2836-4-git-send-email-arei.gonglei@huawei.com> (raw)
In-Reply-To: <1407156382-2836-1-git-send-email-arei.gonglei@huawei.com>

From: Gonglei <arei.gonglei@huawei.com>

We must assure that the changed bootindex can take effect
when guest is rebooted. So we introduce fw_cfg_machine_reset(),
which change the fw_cfg file's bootindex data using the new
global fw_boot_order list.

Signed-off-by: Chenliang <chenliang88@huawei.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/nvram/fw_cfg.c         | 54 +++++++++++++++++++++++++++++++++++++++++------
 include/hw/nvram/fw_cfg.h |  2 ++
 2 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index b71d251..a24a44d 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -56,7 +56,6 @@ struct FWCfgState {
     FWCfgFiles *files;
     uint16_t cur_entry;
     uint32_t cur_offset;
-    Notifier machine_ready;
 };
 
 #define JPG_FILE 0
@@ -402,6 +401,26 @@ static void fw_cfg_add_bytes_read_callback(FWCfgState *s, uint16_t key,
     s->entries[arch][key].callback_opaque = callback_opaque;
 }
 
+static void *fw_cfg_modify_bytes_read(FWCfgState *s, uint16_t key,
+                                              void *data, size_t len)
+{
+    void *ptr;
+    int arch = !!(key & FW_CFG_ARCH_LOCAL);
+
+    key &= FW_CFG_ENTRY_MASK;
+
+    assert(key < FW_CFG_MAX_ENTRY && len < UINT32_MAX);
+
+    /* return the old data to the function caller, avoid memory leak */
+    ptr = s->entries[arch][key].data;
+    s->entries[arch][key].data = data;
+    s->entries[arch][key].len = len;
+    s->entries[arch][key].callback_opaque = NULL;
+    s->entries[arch][key].callback = NULL;
+
+    return ptr;
+}
+
 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len)
 {
     fw_cfg_add_bytes_read_callback(s, key, NULL, NULL, data, len);
@@ -499,13 +518,36 @@ void fw_cfg_add_file(FWCfgState *s,  const char *filename,
     fw_cfg_add_file_callback(s, filename, NULL, NULL, data, len);
 }
 
-static void fw_cfg_machine_ready(struct Notifier *n, void *data)
+void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
+                        void *data, size_t len)
+{
+    int i, index;
+
+    assert(s->files);
+
+    index = be32_to_cpu(s->files->count);
+    assert(index < FW_CFG_FILE_SLOTS);
+
+    for (i = 0; i < index; i++) {
+        if (strcmp(filename, s->files->f[i].name) == 0) {
+            return fw_cfg_modify_bytes_read(s, FW_CFG_FILE_FIRST + i,
+                                     data, len);
+        }
+    }
+    /* add new one */
+    fw_cfg_add_file_callback(s, filename, NULL, NULL, data, len);
+    return NULL;
+}
+
+static void fw_cfg_machine_reset(void *opaque)
 {
+    void *ptr;
     size_t len;
-    FWCfgState *s = container_of(n, FWCfgState, machine_ready);
+    FWCfgState *s = opaque;
     char *bootindex = get_boot_devices_list(&len, false);
 
-    fw_cfg_add_file(s, "bootorder", (uint8_t*)bootindex, len);
+    ptr = fw_cfg_modify_file(s, "bootorder", (uint8_t *)bootindex, len);
+    g_free(ptr);
 }
 
 FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
@@ -542,9 +584,7 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
     fw_cfg_bootsplash(s);
     fw_cfg_reboot(s);
 
-    s->machine_ready.notify = fw_cfg_machine_ready;
-    qemu_add_machine_init_done_notifier(&s->machine_ready);
-
+    qemu_register_reset(fw_cfg_machine_reset, s);
     return s;
 }
 
diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
index 72b1549..56e1ed7 100644
--- a/include/hw/nvram/fw_cfg.h
+++ b/include/hw/nvram/fw_cfg.h
@@ -76,6 +76,8 @@ void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
 void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
                               FWCfgReadCallback callback, void *callback_opaque,
                               void *data, size_t len);
+void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
+                         size_t len);
 FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
                         hwaddr crl_addr, hwaddr data_addr);
 
-- 
1.7.12.4

  parent reply	other threads:[~2014-08-04 12:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-04 12:46 [Qemu-devel] [PATCH v5 0/8] modify boot order of guest, and take effect after rebooting arei.gonglei
2014-08-04 12:46 ` [Qemu-devel] [PATCH v5 1/8] bootindex: add modify_boot_device_path function arei.gonglei
2014-08-04 12:46 ` [Qemu-devel] [PATCH v5 2/8] bootindex: add del_boot_device_path function arei.gonglei
2014-08-04 12:46 ` arei.gonglei [this message]
2014-08-04 12:46 ` [Qemu-devel] [PATCH v5 4/8] bootindex: delete bootindex when device is removed arei.gonglei
2014-08-04 12:46 ` [Qemu-devel] [PATCH v5 5/8] qmp: add set-bootindex command arei.gonglei
2014-08-04 12:46 ` [Qemu-devel] [PATCH v5 6/8] qemu-monitor: HMP set-bootindex wrapper arei.gonglei
2014-08-04 12:46 ` [Qemu-devel] [PATCH v5 7/8] qmp: add query-bootindex command arei.gonglei
2014-08-04 12:46 ` [Qemu-devel] [PATCH v5 8/8] qemu-monitor: add HMP "info-bootindex" command arei.gonglei
2014-08-04 12:53 ` [Qemu-devel] [PATCH v5 0/8] modify boot order of guest, and take effect after rebooting Gonglei (Arei)
2014-08-07 11:50 ` Gonglei (Arei)
2014-08-07 12:57   ` Paolo Bonzini
2014-08-07 13:01     ` Gonglei (Arei)
2014-08-26  6:36 ` Gerd Hoffmann
2014-08-26  9:07   ` Gonglei (Arei)
2014-08-26 10:00     ` Gerd Hoffmann
2014-08-26 11:24       ` Markus Armbruster
2014-08-27  2:11         ` Gonglei (Arei)
2014-08-27 14:23           ` Gerd Hoffmann
2014-08-28  4:50             ` Gonglei (Arei)

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=1407156382-2836-4-git-send-email-arei.gonglei@huawei.com \
    --to=arei.gonglei@huawei.com \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=aik@ozlabs.ru \
    --cc=akong@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=armbru@redhat.com \
    --cc=chenliang88@huawei.com \
    --cc=ehabkost@redhat.com \
    --cc=gaowanlong@cn.fujitsu.com \
    --cc=hani@linux.com \
    --cc=hutao@cn.fujitsu.com \
    --cc=imammedo@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=luonengjun@huawei.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=weidong.huang@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.