[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v11 04/34] fw_cfg: add fw_cfg_machine_reset func
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH v11 04/34] fw_cfg: add fw_cfg_machine_reset function |
Date: |
Thu, 09 Oct 2014 13:12:11 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.1 |
Il 07/10/2014 10:00, address@hidden ha scritto:
> From: Gonglei <address@hidden>
>
> 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 <address@hidden>
> Signed-off-by: Gonglei <address@hidden>
> Reviewed-by: Gerd Hoffmann <address@hidden>
> ---
> hw/nvram/fw_cfg.c | 55
> ++++++++++++++++++++++++++++++++++++++++++++---
> include/hw/nvram/fw_cfg.h | 2 ++
> 2 files changed, 54 insertions(+), 3 deletions(-)
>
> diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
> index b71d251..e7ed27e 100644
> --- a/hw/nvram/fw_cfg.c
> +++ b/hw/nvram/fw_cfg.c
> @@ -402,6 +402,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 +519,42 @@ 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);
> +}
> +
> +static void fw_cfg_machine_ready(struct Notifier *n, void *data)
> +{
> + FWCfgState *s = container_of(n, FWCfgState, machine_ready);
> + qemu_register_reset(fw_cfg_machine_reset, s);
> }
>
> FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
> 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);
>
>
Acked-by: Paolo Bonzini <address@hidden>
- [Qemu-devel] [PATCH v11 09/34] e1000: add bootindex to qom property, (continued)
- [Qemu-devel] [PATCH v11 09/34] e1000: add bootindex to qom property, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 06/34] bootindex: support to set a existent device's bootindex to -1, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 24/34] scsi: add bootindex to qom property, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 30/34] nvma: ide: add bootindex to qom property, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 22/34] redirect: remove bootindex property from qdev to qom, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 21/34] vfio: remove bootindex property from qdev to qom, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 26/34] virtio-blk: add bootindex to qom property, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 33/34] bootindex: delete bootindex when device is removed, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 05/34] bootindex: rework add_boot_device_path function, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 04/34] fw_cfg: add fw_cfg_machine_reset function, arei.gonglei, 2014/10/07
- Re: [Qemu-devel] [PATCH v11 04/34] fw_cfg: add fw_cfg_machine_reset function,
Paolo Bonzini <=
- [Qemu-devel] [PATCH v11 17/34] net: remove bootindex property from qdev to qom, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 28/34] virtio-blk: alias bootindex property explicitly for virt-blk-pci/ccw/s390, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 34/34] bootindex: change fprintf to error_report, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 23/34] isa-fdc: remove bootindexA/B property from qdev to qom, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 25/34] ide: add bootindex to qom property, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 29/34] usb-storage: add bootindex to qom property, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 32/34] bootindex: move calling add_boot_device_patch to bootindex setter function, arei.gonglei, 2014/10/07
- [Qemu-devel] [PATCH v11 27/34] block: remove bootindex property from qdev to qom, arei.gonglei, 2014/10/07