ivshmem: simplify a bit the code
Use some more explicit variables to simplify the code. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Claudio Fontana <claudio.fontana@huawei.com>
This commit is contained in:
parent
ffa99afd6e
commit
9a2f0e64ae
@ -488,9 +488,10 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
|
|||||||
{
|
{
|
||||||
IVShmemState *s = opaque;
|
IVShmemState *s = opaque;
|
||||||
int incoming_fd;
|
int incoming_fd;
|
||||||
int guest_max_eventfd;
|
int new_eventfd;
|
||||||
long incoming_posn;
|
long incoming_posn;
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
|
Peer *peer;
|
||||||
|
|
||||||
if (!fifo_update_and_get(s, buf, size,
|
if (!fifo_update_and_get(s, buf, size,
|
||||||
&incoming_posn, sizeof(incoming_posn))) {
|
&incoming_posn, sizeof(incoming_posn))) {
|
||||||
@ -517,6 +518,8 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
peer = &s->peers[incoming_posn];
|
||||||
|
|
||||||
if (incoming_fd == -1) {
|
if (incoming_fd == -1) {
|
||||||
/* if posn is positive and unseen before then this is our posn*/
|
/* if posn is positive and unseen before then this is our posn*/
|
||||||
if (incoming_posn >= 0 && s->vm_id == -1) {
|
if (incoming_posn >= 0 && s->vm_id == -1) {
|
||||||
@ -564,27 +567,24 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* each guest has an array of eventfds, and we keep track of how many
|
/* each peer has an associated array of eventfds, and we keep
|
||||||
* guests for each VM */
|
* track of how many eventfds received so far */
|
||||||
guest_max_eventfd = s->peers[incoming_posn].nb_eventfds;
|
/* get a new eventfd: */
|
||||||
|
new_eventfd = peer->nb_eventfds++;
|
||||||
|
|
||||||
/* this is an eventfd for a particular guest VM */
|
/* this is an eventfd for a particular guest VM */
|
||||||
IVSHMEM_DPRINTF("eventfds[%ld][%d] = %d\n", incoming_posn,
|
IVSHMEM_DPRINTF("eventfds[%ld][%d] = %d\n", incoming_posn,
|
||||||
guest_max_eventfd, incoming_fd);
|
new_eventfd, incoming_fd);
|
||||||
event_notifier_init_fd(&s->peers[incoming_posn].eventfds[guest_max_eventfd],
|
event_notifier_init_fd(&peer->eventfds[new_eventfd], incoming_fd);
|
||||||
incoming_fd);
|
|
||||||
|
|
||||||
/* increment count for particular guest */
|
|
||||||
s->peers[incoming_posn].nb_eventfds++;
|
|
||||||
|
|
||||||
if (incoming_posn == s->vm_id) {
|
if (incoming_posn == s->vm_id) {
|
||||||
s->eventfd_chr[guest_max_eventfd] = create_eventfd_chr_device(s,
|
s->eventfd_chr[new_eventfd] = create_eventfd_chr_device(s,
|
||||||
&s->peers[s->vm_id].eventfds[guest_max_eventfd],
|
&s->peers[s->vm_id].eventfds[new_eventfd],
|
||||||
guest_max_eventfd);
|
new_eventfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) {
|
if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) {
|
||||||
ivshmem_add_eventfd(s, incoming_posn, guest_max_eventfd);
|
ivshmem_add_eventfd(s, incoming_posn, new_eventfd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user