@@ -191,7 +191,7 @@ ivshmem_server_handle_new_conn(IvshmemServer *server)
QTAILQ_FOREACH(other_peer, &server->peer_list, next) {
for (i = 0; i < peer->vectors_count; i++) {
ivshmem_server_send_one_msg(other_peer->sock_fd, peer->id,
- event_notifier_get_fd(&peer->vectors[i]));
+ peer->vectors[i].wfd);
}
}
@@ -199,7 +199,7 @@ ivshmem_server_handle_new_conn(IvshmemServer *server)
QTAILQ_FOREACH(other_peer, &server->peer_list, next) {
for (i = 0; i < peer->vectors_count; i++) {
ivshmem_server_send_one_msg(peer->sock_fd, other_peer->id,
- event_notifier_get_fd(&other_peer->vectors[i]));
+ other_peer->vectors[i].wfd);
}
}
@@ -232,15 +232,14 @@ static int
ivshmem_server_ftruncate(int fd, unsigned shmsize)
{
int ret;
+ struct stat mapstat;
/* align shmsize to next power of 2 */
- shmsize--;
- shmsize |= shmsize >> 1;
- shmsize |= shmsize >> 2;
- shmsize |= shmsize >> 4;
- shmsize |= shmsize >> 8;
- shmsize |= shmsize >> 16;
- shmsize++;
+ shmsize = pow2ceil(shmsize);
+
+ if (fstat(fd, &mapstat) != -1 && mapstat.st_size == shmsize) {
+ return 0;
+ }
while (shmsize <= IVSHMEM_SERVER_MAX_HUGEPAGE_SIZE) {
ret = ftruncate(fd, shmsize);
@@ -262,6 +261,7 @@ ivshmem_server_init(IvshmemServer *server, const char *unix_sock_path,
int ret;
memset(server, 0, sizeof(*server));
+ server->verbose = verbose;
ret = snprintf(server->unix_sock_path, sizeof(server->unix_sock_path),
"%s", unix_sock_path);
@@ -278,7 +278,6 @@ ivshmem_server_init(IvshmemServer *server, const char *unix_sock_path,
server->shm_size = shm_size;
server->n_vectors = n_vectors;
- server->verbose = verbose;
QTAILQ_INIT(&server->peer_list);
@@ -299,10 +298,6 @@ static long gethugepagesize(const char *path)
} while (ret != 0 && errno == EINTR);
if (ret != 0) {
- if (errno != ENOENT) {
- fprintf(stderr, "cannot stat shm file %s: %s\n", path,
- strerror(errno));
- }
return -1;
}
@@ -326,16 +321,22 @@ ivshmem_server_start(IvshmemServer *server)
long hpagesize;
hpagesize = gethugepagesize(server->shm_path);
+ if (hpagesize < 0 && errno != ENOENT) {
+ IVSHMEM_SERVER_DEBUG(server, "cannot stat shm file %s: %s\n",
+ server->shm_path, strerror(errno));
+ }
+
if (hpagesize > 0) {
gchar *filename = g_strdup_printf("%s/ivshmem.XXXXXX", server->shm_path);
- fprintf(stdout, "Using hugepages: %s\n", server->shm_path);
+ IVSHMEM_SERVER_DEBUG(server, "Using hugepages: %s\n", server->shm_path);
shm_fd = mkstemp(filename);
unlink(filename);
g_free(filename);
} else
#endif
{
- fprintf(stdout, "Using POSIX shared memory: %s\n", server->shm_path);
+ IVSHMEM_SERVER_DEBUG(server, "Using POSIX shared memory: %s\n",
+ server->shm_path);
shm_fd = shm_open(server->shm_path, O_CREAT|O_RDWR, S_IRWXU);
}
@@ -35,5 +35,5 @@ CONFIG_SDHCI=y
CONFIG_EDU=y
CONFIG_VGA=y
CONFIG_VGA_PCI=y
-CONFIG_IVSHMEM=$(CONFIG_KVM)
+CONFIG_IVSHMEM=$(CONFIG_POSIX)
CONFIG_ROCKER=y
@@ -623,13 +623,14 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
}
if (incoming_posn < -1) {
- IVSHMEM_DPRINTF("invalid incoming_posn %ld\n", incoming_posn);
+ IVSHMEM_DPRINTF("invalid incoming_posn %" PRId64 "\n", incoming_posn);
return;
}
/* pick off s->server_chr->msgfd and store it, posn should accompany msg */
incoming_fd = qemu_chr_fe_get_msgfd(s->server_chr);
- IVSHMEM_DPRINTF("posn is %ld, fd is %d\n", incoming_posn, incoming_fd);
+ IVSHMEM_DPRINTF("posn is %" PRId64 ", fd is %d\n",
+ incoming_posn, incoming_fd);
/* make sure we have enough space for this peer */
if (incoming_posn >= s->nb_peers) {
@@ -651,7 +652,7 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
s->vm_id = incoming_posn;
} else {
/* otherwise an fd == -1 means an existing peer has gone away */
- IVSHMEM_DPRINTF("posn %ld has gone away\n", incoming_posn);
+ IVSHMEM_DPRINTF("posn %" PRId64 " has gone away\n", incoming_posn);
close_peer_eventfds(s, incoming_posn);
}
return;
@@ -697,7 +698,6 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
/* each peer has an associated array of eventfds, and we keep
* track of how many eventfds received so far */
/* get a new eventfd: */
- /* get a new eventfd */
if (peer->nb_eventfds >= s->vectors) {
error_report("Too many eventfd received, device has %d vectors",
s->vectors);
@@ -708,7 +708,7 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
new_eventfd = peer->nb_eventfds++;
/* this is an eventfd for a particular peer VM */
- IVSHMEM_DPRINTF("eventfds[%ld][%d] = %d\n", incoming_posn,
+ IVSHMEM_DPRINTF("eventfds[%" PRId64 "][%d] = %d\n", incoming_posn,
new_eventfd, incoming_fd);
event_notifier_init_fd(&peer->eventfds[new_eventfd], incoming_fd);
fcntl_setfl(incoming_fd, O_NONBLOCK); /* msix/irqfd poll non block */
@@ -149,7 +149,7 @@ gcov-files-pci-y += hw/display/virtio-gpu-pci.c
gcov-files-pci-$(CONFIG_VIRTIO_VGA) += hw/display/virtio-vga.c
check-qtest-pci-y += tests/intel-hda-test$(EXESUF)
gcov-files-pci-y += hw/audio/intel-hda.c hw/audio/hda-codec.c
-check-qtest-pci-$(CONFIG_IVSHMEM) += tests/ivshmem-test$(EXESUF)
+check-qtest-pci-$(CONFIG_POSIX) += tests/ivshmem-test$(EXESUF)
gcov-files-pci-y += hw/misc/ivshmem.c
check-qtest-i386-y = tests/endianness-test$(EXESUF)
@@ -288,11 +288,12 @@ static void test_ivshmem_server(void)
IvshmemServer server;
int ret, vm1, vm2;
int nvectors = 2;
+ guint64 end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
memset(tmpshmem, 0x42, TMPSHMSIZE);
ret = ivshmem_server_init(&server, tmpserver, tmpshm,
TMPSHMSIZE, nvectors,
- getenv("QTEST_LOG") != NULL);
+ g_test_verbose());
g_assert_cmpint(ret, ==, 0);
ret = ivshmem_server_start(&server);
@@ -315,7 +316,7 @@ static void test_ivshmem_server(void)
g_assert(thread.thread != NULL);
/* waiting until mapping is done */
- while (true) {
+ while (g_get_monotonic_time() < end_time) {
g_usleep(1000);
if (qtest_readb(s1->qtest, (uintptr_t)s1->mem_base) == 0x42 &&
@@ -337,8 +338,10 @@ static void test_ivshmem_server(void)
ret = qpci_msix_pending(s1->dev, 0);
g_assert_cmpuint(ret, ==, 0);
out_reg(s2, DOORBELL, vm1 << 16);
- g_usleep(10000);
- ret = qpci_msix_pending(s1->dev, 0);
+ do {
+ g_usleep(10000);
+ ret = qpci_msix_pending(s1->dev, 0);
+ } while (ret == 0 && g_get_monotonic_time() < end_time);
g_assert_cmpuint(ret, !=, 0);
/* ping vm1 -> vm2 */
@@ -346,15 +349,13 @@ static void test_ivshmem_server(void)
ret = qpci_msix_pending(s2->dev, 0);
g_assert_cmpuint(ret, ==, 0);
out_reg(s1, DOORBELL, vm2 << 16);
- g_usleep(10000);
- ret = qpci_msix_pending(s2->dev, 0);
+ do {
+ g_usleep(10000);
+ ret = qpci_msix_pending(s2->dev, 0);
+ } while (ret == 0 && g_get_monotonic_time() < end_time);
g_assert_cmpuint(ret, !=, 0);
- /* remove vm2 */
qtest_quit(s2->qtest);
- /* XXX wait enough time for vm1 to be notified */
- g_usleep(1000);
-
qtest_quit(s1->qtest);
if (qemu_write_full(thread.pipe[1], "q", 1) != 1) {