aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2015-09-15 17:23:07 +0200
committerMarc-André Lureau <marcandre.lureau@redhat.com>2015-10-24 18:02:48 +0200
commit81e507f0bc584f417cb671e88da3f049cb4defb1 (patch)
tree26ceca643aaa7b732d51dda3a587e8c7348e9372
parent1300b2733a297f9a59deb4eebbd437a5833f3f41 (diff)
ivshmem: allocate eventfds in resize_peers()
It simplifies a bit the code to allocate the array when setting the number of peers instead of lazily when receiving the first vector. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Claudio Fontana <claudio.fontana@huawei.com>
-rw-r--r--hw/misc/ivshmem.c11
1 files changed, 2 insertions, 9 deletions
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 6f41960095..19640bb175 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -437,9 +437,8 @@ static int resize_peers(IVShmemState *s, int new_min_size)
s->peers = g_realloc(s->peers, s->nb_peers * sizeof(Peer));
- /* zero out new pointers */
for (j = old_size; j < s->nb_peers; j++) {
- s->peers[j].eventfds = NULL;
+ s->peers[j].eventfds = g_new0(EventNotifier, s->vectors);
s->peers[j].nb_eventfds = 0;
}
@@ -517,8 +516,7 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
if (incoming_fd == -1) {
/* if posn is positive and unseen before then this is our posn*/
- if ((incoming_posn >= 0) &&
- (s->peers[incoming_posn].eventfds == NULL)) {
+ if (incoming_posn >= 0 && s->vm_id == -1) {
/* receive our posn */
s->vm_id = incoming_posn;
return;
@@ -569,11 +567,6 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
* guests for each VM */
guest_max_eventfd = s->peers[incoming_posn].nb_eventfds;
- if (guest_max_eventfd == 0) {
- /* one eventfd per MSI vector */
- s->peers[incoming_posn].eventfds = g_new(EventNotifier, s->vectors);
- }
-
/* this is an eventfd for a particular guest VM */
IVSHMEM_DPRINTF("eventfds[%ld][%d] = %d\n", incoming_posn,
guest_max_eventfd, incoming_fd);