aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorJohn Levon <john.levon@nutanix.com>2021-03-09 16:24:27 +0000
committerGitHub <noreply@github.com>2021-03-09 16:24:27 +0000
commit997536eee6609827b5053afef497f94bc6f6dbf4 (patch)
tree5f2c556a8a1a8f5f991f84bb6e4ba975f0574d37 /samples
parenta8242d117118d5191dad69a96e28a21d66fe8b50 (diff)
downloadlibvfio-user-997536eee6609827b5053afef497f94bc6f6dbf4.zip
libvfio-user-997536eee6609827b5053afef497f94bc6f6dbf4.tar.gz
libvfio-user-997536eee6609827b5053afef497f94bc6f6dbf4.tar.bz2
remove vfu_irq_message() (#389)
This sends a message to a vfio-user client to trigger an IRQ, instead of writing to an eventfd. However, this isn't necessary on the cases we care about, where eventfds *are* available. Furthermore, this isn't something an API user should need to know about: if we ever care, the better way to do this is to make vfu_irq_trigger() automatically use a message if an eventfd isn't available. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'samples')
-rw-r--r--samples/client.c59
-rw-r--r--samples/server.c10
2 files changed, 17 insertions, 52 deletions
diff --git a/samples/client.c b/samples/client.c
index 3fda9d3..309c193 100644
--- a/samples/client.c
+++ b/samples/client.c
@@ -516,47 +516,7 @@ access_region(int sock, int region, bool is_write, uint64_t offset,
}
static void
-wait_for_irqs(int sock, int irq_fd)
-{
- int ret;
- uint64_t val;
- size_t size;
- struct vfio_user_irq_info vfio_user_irq_info;
- struct vfio_user_header hdr;
- uint16_t msg_id = 0xbabe;
-
- if (read(irq_fd, &val, sizeof(val)) == -1) {
- err(EXIT_FAILURE, "failed to read from irqfd");
- }
- printf("INTx triggered!\n");
-
- size = sizeof(vfio_user_irq_info);
- ret = tran_sock_recv(sock, &hdr, false, &msg_id,
- &vfio_user_irq_info, &size);
- if (ret < 0) {
- errx(EXIT_FAILURE, "failed to receive IRQ message: %s",
- strerror(-ret));
- }
-
- if (hdr.cmd != VFIO_USER_VM_INTERRUPT) {
- errx(EXIT_FAILURE, "unexpected cmd %d\n", hdr.cmd);
- }
-
- if (vfio_user_irq_info.subindex >= 1) {
- errx(EXIT_FAILURE, "bad IRQ %d, max=1\n", vfio_user_irq_info.subindex);
- }
-
- // Is a NULL iovec like this OK?
- ret = tran_sock_send(sock, msg_id, true, hdr.cmd, NULL, 0);
- if (ret < 0) {
- errx(EXIT_FAILURE,
- "failed to send reply for VFIO_USER_VM_INTERRUPT: %s",
- strerror(-ret));
- }
-}
-
-static void
-access_bar0(int sock, int irq_fd, time_t *t)
+access_bar0(int sock, time_t *t)
{
int ret;
@@ -575,8 +535,17 @@ access_bar0(int sock, int irq_fd, time_t *t)
}
printf("read from BAR0: %ld\n", *t);
+}
- wait_for_irqs(sock, irq_fd);
+static void
+wait_for_irq(int irq_fd)
+{
+ uint64_t val;
+
+ if (read(irq_fd, &val, sizeof(val)) == -1) {
+ err(EXIT_FAILURE, "failed to read from irqfd");
+ }
+ printf("INTx triggered!\n");
}
static void
@@ -1249,7 +1218,9 @@ int main(int argc, char *argv[])
* via explicit messages.
*/
t = time(NULL) + 1;
- access_bar0(sock, irq_fd, &t);
+ access_bar0(sock, &t);
+
+ wait_for_irq(irq_fd);
/* FIXME check that above took at least 1s */
@@ -1340,7 +1311,7 @@ int main(int argc, char *argv[])
}
irq_fd = ret;
- wait_for_irqs(sock, irq_fd);
+ wait_for_irq(irq_fd);
handle_dma_io(sock, dma_regions + server_max_fds,
nr_dma_regions - server_max_fds,
diff --git a/samples/server.c b/samples/server.c
index 4391bca..cb966f5 100644
--- a/samples/server.c
+++ b/samples/server.c
@@ -580,15 +580,9 @@ int main(int argc, char *argv[])
if (ret == -1 && errno == EINTR) {
if (irq_triggered) {
irq_triggered = false;
- vfu_irq_trigger(vfu_ctx, 0);
- /*
- * Apart from triggering an IRQ via the eventfd, we also
- * trigger an IRQ via a message, simply for demonstrating how
- * it's done. The client expects this behavior from the server.
- */
- ret = vfu_irq_message(vfu_ctx, 0);
+ ret = vfu_irq_trigger(vfu_ctx, 0);
if (ret < 0) {
- err(EXIT_FAILURE, "vfu_irq_message() failed");
+ err(EXIT_FAILURE, "vfu_irq_trigger() failed");
}
/*