[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v3 13/51] ivshmem: simplify around increase_dynamic_s
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [PULL v3 13/51] ivshmem: simplify around increase_dynamic_storage() |
Date: |
Tue, 13 Oct 2015 16:25:40 +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] [PULL v3 36/51] ivshmem-server: fix hugetlbfs support, (continued)
- [Qemu-devel] [PULL v3 36/51] ivshmem-server: fix hugetlbfs support, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 37/51] docs: update ivshmem device spec, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 42/51] glib-compat: add 2.38/2.40/2.46 asserts, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 48/51] ivshmem: rename MSI eventfd_table, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 50/51] ivshmem: use little-endian int64_t for the protocol, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 47/51] ivshmem: remove EventfdEntry.vector, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 51/51] doc: document ivshmem & hugepages, marcandre . lureau, 2015/10/13
- [Qemu-devel] [PULL v3 12/51] ivshmem: limit maximum number of peers to G_MAXUINT16, marcandre . lureau, 2015/10/15
- [Qemu-devel] [PULL v3 14/51] ivshmem: allocate eventfds in resize_peers(), marcandre . lureau, 2015/10/15
- [Qemu-devel] [PULL v3 27/51] ivshmem: add device description, marcandre . lureau, 2015/10/15
- [Qemu-devel] [PULL v3 13/51] ivshmem: simplify around increase_dynamic_storage(),
marcandre . lureau <=
- [Qemu-devel] [PULL v3 16/51] ivshmem: initialize max_peer to -1, marcandre . lureau, 2015/10/15
- [Qemu-devel] [PULL v3 32/51] util: const event_notifier_get_fd() argument, marcandre . lureau, 2015/10/15
- [Qemu-devel] [PULL v3 40/51] msix: implement pba write (but read-only), marcandre . lureau, 2015/10/15
- [Qemu-devel] [PULL v3 39/51] contrib: remove unnecessary strdup(), marcandre . lureau, 2015/10/15
- [Qemu-devel] [PULL v3 38/51] ivshmem: add check on protocol version in QEMU, marcandre . lureau, 2015/10/15
- [Qemu-devel] [PULL v3 41/51] qtest: add qtest_add_abrt_handler(), marcandre . lureau, 2015/10/15
- [Qemu-devel] [PULL v3 46/51] ivshmem: add hostmem backend, marcandre . lureau, 2015/10/15
- [Qemu-devel] [PULL v3 45/51] ivshmem: use qemu_strtosz(), marcandre . lureau, 2015/10/15
- [Qemu-devel] [PULL v3 49/51] ivshmem: use kvm irqfd for msi notifications, marcandre . lureau, 2015/10/15
- Re: [Qemu-devel] [PULL v3 00/51] Ivshmem patches, Peter Maydell, 2015/10/15