This patch saves the config buffer and its length of a virtio-net
device's VirtIODevice to compare with later during the stop-and-copy
phase.
Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
---
hw/net/virtio-net.c | 21 +++++++++++++++++++++
include/hw/virtio/virtio.h | 4 ++++
2 files changed, 25 insertions(+)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 2733e0130c..ca4385df1a 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -3871,6 +3871,15 @@ static int virtio_net_early_pre_save(void *opaque)
VirtIODevMigration *vdev_mig = vdev->migration;
vdev_mig->status_early = vdev->status;
+
+ /* VirtIODevice config buffer snapshot */
+ g_free(vdev_mig->config_early);
+ vdev_mig->config_len_early = vdev->config_len;
+ if (vdev->config_len) {
+ vdev_mig->config_early = g_memdup2(vdev->config, vdev->config_len);
+ } else {
+ vdev_mig->config_early = NULL;
+ }
return 0;
}
@@ -4150,6 +4159,9 @@ static void virtio_net_device_unrealize(DeviceState *dev)
virtio_cleanup(vdev);
if (n->early_mig) {
+ g_free(vdev->migration->config_early);
+ vdev->migration->config_early = NULL;
+
g_free(vdev->migration);
vdev->migration = NULL;
@@ -4251,6 +4263,15 @@ static bool virtio_net_has_delta(VirtIONet *n, VirtIODevice *vdev)
return true;
}
+ /* Has the VirtIODevice's config buffer changed? */
+ if (vdev->config_len != vdev_mig->config_len_early) {
+ return true;
+ }
+ if (vdev->config_len && memcmp(vdev->config, vdev_mig->config_early,
+ vdev->config_len) != 0) {
+ return true;
+ }
+
/*
* Always return true for now until we're able to detect all possible
* changes to a VirtIONet device.
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 752c46ce53..9949b94b64 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -103,10 +103,14 @@ enum virtio_device_endian {
* struct VirtIODevMigration - Common VirtIODevice migration structure
* @early_load: Flag to indicate an early virtio_load for the device.
* @status_early: Device status at the time it was sent early.
+ * @config_len_early: Length of the config buffer at the time it was sent early.
+ * @config_early: Config buffer at the time it was sent early.
*/
typedef struct VirtIODevMigration {
bool early_load;
uint8_t status_early;
+ size_t config_len_early;
+ uint8_t *config_early;
} VirtIODevMigration;
/**
--
2.51.0