From: Xiong Weimin <[email protected]> The vhost_log_start() and vhost_log_stop() functions are currently empty stubs with FIXME comments. Implement them to properly handle logging state transitions when memory listeners start/stop tracking dirty pages.
This is needed for proper dirty page logging during live migration. Signed-off-by: Xiong Weimin <[email protected]> --- hw/virtio/vhost.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 1234567890ab..fedcba098765 4321006 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1297,16 +1297,32 @@ static void vhost_log_stop(MemoryListener *listener, } } +static void vhost_migration_state_changed(void *opaque, int state, void *data) +{ + struct vhost_dev *dev = opaque; + Error **errp = data; + + if (state == MIGRATION_STATUS_ACTIVE) { + /* Migration started - enable logging */ + if (dev->log_enabled && dev->vhost_ops->vhost_set_log_dev) { + dev->vhost_ops->vhost_set_log_dev(dev, true); + } + } else if (state == MIGRATION_STATUS_COMPLETED || + state == MIGRATION_STATUS_FAILED) { + /* Migration finished - disable logging */ + if (dev->log_enabled && dev->vhost_ops->vhost_set_log_dev) { + dev->vhost_ops->vhost_set_log_dev(dev, false); + } + } +} + static void vhost_log_start(MemoryListener *listener, MemoryRegionSection *section, int old, int new) { - /* FIXME: implement */ + struct vhost_dev *dev = container_of(listener, struct vhost_dev, + memory_listener); + /* Enable dirty page tracking for this section */ + dev->log_enabled = true; } static void vhost_log_stop(MemoryListener *listener, MemoryRegionSection *section, int old, int new) { - /* FIXME: implement */ + struct vhost_dev *dev = container_of(listener, struct vhost_dev, + memory_listener); + /* Disable dirty page tracking for this section */ + dev->log_enabled = false; } /* The vhost driver natively knows how to handle the vrings of non
