[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 07/19] vhost-user: Monitor slave channel in vhost_user_read()
From: |
Michael S. Tsirkin |
Subject: |
[PULL v2 07/19] vhost-user: Monitor slave channel in vhost_user_read() |
Date: |
Mon, 22 Mar 2021 19:00:08 -0400 |
From: Greg Kurz <groug@kaod.org>
Now that everything is in place, have the nested event loop to monitor
the slave channel. The source in the main event loop is destroyed and
recreated to ensure any pending even for the slave channel that was
previously detected is purged. This guarantees that the main loop
wont invoke slave_read() based on an event that was already handled
by the nested loop.
Signed-off-by: Greg Kurz <groug@kaod.org>
Message-Id: <20210312092212.782255-7-groug@kaod.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/virtio/vhost-user.c | 35 ++++++++++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 00256fa318..ded0c10453 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -345,6 +345,35 @@ end:
return G_SOURCE_REMOVE;
}
+static gboolean slave_read(QIOChannel *ioc, GIOCondition condition,
+ gpointer opaque);
+
+/*
+ * This updates the read handler to use a new event loop context.
+ * Event sources are removed from the previous context : this ensures
+ * that events detected in the previous context are purged. They will
+ * be re-detected and processed in the new context.
+ */
+static void slave_update_read_handler(struct vhost_dev *dev,
+ GMainContext *ctxt)
+{
+ struct vhost_user *u = dev->opaque;
+
+ if (!u->slave_ioc) {
+ return;
+ }
+
+ if (u->slave_src) {
+ g_source_destroy(u->slave_src);
+ g_source_unref(u->slave_src);
+ }
+
+ u->slave_src = qio_channel_add_watch_source(u->slave_ioc,
+ G_IO_IN | G_IO_HUP,
+ slave_read, dev, NULL,
+ ctxt);
+}
+
static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
{
struct vhost_user *u = dev->opaque;
@@ -366,6 +395,7 @@ static int vhost_user_read(struct vhost_dev *dev,
VhostUserMsg *msg)
* be prepared for re-entrancy. So we create a new one and switch chr
* to use it.
*/
+ slave_update_read_handler(dev, ctxt);
qemu_chr_be_update_read_handlers(chr->chr, ctxt);
qemu_chr_fe_add_watch(chr, G_IO_IN | G_IO_HUP, vhost_user_read_cb, &data);
@@ -377,6 +407,7 @@ static int vhost_user_read(struct vhost_dev *dev,
VhostUserMsg *msg)
* context that have been processed by the nested loop are purged.
*/
qemu_chr_be_update_read_handlers(chr->chr, prev_ctxt);
+ slave_update_read_handler(dev, NULL);
g_main_loop_unref(loop);
g_main_context_unref(ctxt);
@@ -1580,9 +1611,7 @@ static int vhost_setup_slave_channel(struct vhost_dev
*dev)
return -1;
}
u->slave_ioc = ioc;
- u->slave_src = qio_channel_add_watch_source(u->slave_ioc,
- G_IO_IN | G_IO_HUP,
- slave_read, dev, NULL, NULL);
+ slave_update_read_handler(dev, NULL);
if (reply_supported) {
msg.hdr.flags |= VHOST_USER_NEED_REPLY_MASK;
--
MST
- [PULL v2 00/19] pc,virtio,pci: fixes, features, Michael S. Tsirkin, 2021/03/22
- [PULL v2 02/19] vhost-user: Drop misleading EAGAIN checks in slave_read(), Michael S. Tsirkin, 2021/03/22
- [PULL v2 01/19] virtio: Fix virtio_mmio_read()/virtio_mmio_write(), Michael S. Tsirkin, 2021/03/22
- [PULL v2 04/19] vhost-user: Factor out duplicated slave_fd teardown code, Michael S. Tsirkin, 2021/03/22
- [PULL v2 03/19] vhost-user: Fix double-close on slave_read() error path, Michael S. Tsirkin, 2021/03/22
- [PULL v2 05/19] vhost-user: Convert slave channel to QIOChannelSocket, Michael S. Tsirkin, 2021/03/22
- [PULL v2 06/19] vhost-user: Introduce nested event loop in vhost_user_read(), Michael S. Tsirkin, 2021/03/22
- [PULL v2 07/19] vhost-user: Monitor slave channel in vhost_user_read(),
Michael S. Tsirkin <=
- [PULL v2 08/19] virtio-pmem: fix virtio_pmem_resp assign problem, Michael S. Tsirkin, 2021/03/22
- [PULL v2 09/19] tests: acpi: temporary whitelist DSDT changes, Michael S. Tsirkin, 2021/03/22
- [PULL v2 10/19] pci: introduce acpi-index property for PCI device, Michael S. Tsirkin, 2021/03/22
- [PULL v2 12/19] acpi: add aml_to_decimalstring() and aml_call6() helpers, Michael S. Tsirkin, 2021/03/22
- [PULL v2 11/19] pci: acpi: ensure that acpi-index is unique, Michael S. Tsirkin, 2021/03/22
- [PULL v2 15/19] acpi: Set proper maximum size for "etc/table-loader" blob, Michael S. Tsirkin, 2021/03/22
- [PULL v2 13/19] pci: acpi: add _DSM method to PCI devices, Michael S. Tsirkin, 2021/03/22
- [PULL v2 17/19] acpi: Move maximum size logic into acpi_add_rom_blob(), Michael S. Tsirkin, 2021/03/22
- [PULL v2 18/19] acpi: Set proper maximum size for "etc/acpi/rsdp" blob, Michael S. Tsirkin, 2021/03/22
- [PULL v2 14/19] tests: acpi: update expected blobs, Michael S. Tsirkin, 2021/03/22