[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 12/47] ivshmem: simplify around increase_dynamic_
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [PATCH v4 12/47] ivshmem: simplify around increase_dynamic_storage() |
Date: |
Thu, 24 Sep 2015 13:37:14 +0200 |
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>
Reviewed-by: Claudio Fontana <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 3787398..6f41960 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 *));
--
2.4.3
- [Qemu-devel] [PATCH v4 02/47] msix: add VMSTATE_MSIX_TEST, (continued)
- [Qemu-devel] [PATCH v4 02/47] msix: add VMSTATE_MSIX_TEST, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 03/47] ivhsmem: read do not accept more than sizeof(long), marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 05/47] ivshmem: factor out the incoming fifo handling, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 04/47] ivshmem: fix number of bytes to push to fifo, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 06/47] ivshmem: remove unnecessary dup(), marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 07/47] ivshmem: remove superflous ivshmem_attr field, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 08/47] ivshmem: remove useless doorbell field, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 10/47] ivshmem: remove last exit(1), marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 09/47] ivshmem: more qdev conversion, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 11/47] ivshmem: limit maximum number of peers to G_MAXUINT16, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 12/47] ivshmem: simplify around increase_dynamic_storage(),
marcandre . lureau <=
- [Qemu-devel] [PATCH v4 14/47] ivshmem: remove useless ivshmem_update_irq() val argument, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 13/47] ivshmem: allocate eventfds in resize_peers(), marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 16/47] ivshmem: remove max_peer field, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 15/47] ivshmem: initialize max_peer to -1, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 17/47] ivshmem: improve debug messages, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 18/47] ivshmem: improve error handling, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 19/47] ivshmem: print error on invalid peer id, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 20/47] ivshmem: simplify a bit the code, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 21/47] ivshmem: use common return, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 22/47] ivshmem: use common is_power_of_2(), marcandre . lureau, 2015/09/24