[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v3 12/46] ivshmem: simplify around increase_dyna
From: |
Claudio Fontana |
Subject: |
Re: [Qemu-devel] [PATCH v3 12/46] ivshmem: simplify around increase_dynamic_storage() |
Date: |
Tue, 22 Sep 2015 16:10:44 +0200 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 |
On 15.09.2015 18:07, address@hidden wrote:
> From: Marc-André Lureau <address@hidden>
>
> Set the number of peers and array allocation in a single place. Rename
> to better reflect the function content.
>
> Signed-off-by: Marc-André Lureau <address@hidden>
> ---
> hw/misc/ivshmem.c | 27 +++++++++++----------------
> 1 file changed, 11 insertions(+), 16 deletions(-)
>
> diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
> index cd2c4bc..889a199 100644
> --- a/hw/misc/ivshmem.c
> +++ b/hw/misc/ivshmem.c
> @@ -417,30 +417,28 @@ static void close_guest_eventfds(IVShmemState *s, int
> posn)
>
> /* this function increase the dynamic storage need to store data about other
> * guests */
> -static int increase_dynamic_storage(IVShmemState *s, int new_min_size)
> +static int resize_peers(IVShmemState *s, int new_min_size)
> {
>
> - int j, old_nb_alloc;
> + int j, old_size;
>
> /* limit number of max peers */
> if (new_min_size <= 0 || new_min_size > IVSHMEM_MAX_PEERS) {
> return -1;
> }
> -
> - old_nb_alloc = s->nb_peers;
> -
> - if (new_min_size >= s->nb_peers) {
> - /* +1 because #new_min_size is used as last array index */
> - s->nb_peers = new_min_size + 1;
> - } else {
> + if (new_min_size <= s->nb_peers) {
> return 0;
> }
>
> + old_size = s->nb_peers;
> + s->nb_peers = new_min_size;
> +
> IVSHMEM_DPRINTF("bumping storage to %d guests\n", s->nb_peers);
> +
> s->peers = g_realloc(s->peers, s->nb_peers * sizeof(Peer));
>
> /* zero out new pointers */
> - for (j = old_nb_alloc; j < s->nb_peers; j++) {
> + for (j = old_size; j < s->nb_peers; j++) {
> s->peers[j].eventfds = NULL;
> s->peers[j].nb_eventfds = 0;
> }
> @@ -508,8 +506,8 @@ static void ivshmem_read(void *opaque, const uint8_t
> *buf, int size)
>
> /* make sure we have enough space for this guest */
> if (incoming_posn >= s->nb_peers) {
> - if (increase_dynamic_storage(s, incoming_posn) < 0) {
> - error_report("increase_dynamic_storage() failed");
> + if (resize_peers(s, incoming_posn + 1) < 0) {
> + error_report("failed to resize peers array");
> if (incoming_fd != -1) {
> close(incoming_fd);
> }
> @@ -812,12 +810,9 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error
> **errp)
> }
>
> /* we allocate enough space for 16 guests and grow as needed */
> - s->nb_peers = 16;
> + resize_peers(s, 16);
> s->vm_id = -1;
>
> - /* allocate/initialize space for interrupt handling */
> - s->peers = g_malloc0(s->nb_peers * sizeof(Peer));
> -
> pci_register_bar(dev, 2, attr, &s->bar);
>
> s->eventfd_chr = g_malloc0(s->vectors * sizeof(CharDriverState *));
>
Reviewed-by: Claudio Fontana <address@hidden>
- Re: [Qemu-devel] [PATCH v3 08/46] ivshmem: remove useless doorbell field, (continued)
- [Qemu-devel] [PATCH v3 09/46] ivshmem: more qdev conversion, marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 10/46] ivshmem: remove last exit(1), marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 11/46] ivshmem: limit maximum number of peers to G_MAXUINT16, marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 12/46] ivshmem: simplify around increase_dynamic_storage(), marcandre . lureau, 2015/09/15
- Re: [Qemu-devel] [PATCH v3 12/46] ivshmem: simplify around increase_dynamic_storage(),
Claudio Fontana <=
- [Qemu-devel] [PATCH v3 13/46] ivshmem: allocate eventfds in resize_peers(), marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 14/46] ivshmem: remove useless ivshmem_update_irq() val argument, marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 15/46] ivshmem: initialize max_peer to -1, marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 16/46] ivshmem: remove max_peer field, marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 18/46] ivshmem: improve error, marcandre . lureau, 2015/09/15