89 lines
2.9 KiB
Diff
89 lines
2.9 KiB
Diff
From 8d78f01d644446cfeae62995169220060d738fd6 Mon Sep 17 00:00:00 2001
|
|
From: libai <libai12@huawei.com>
|
|
Date: Mon, 4 Dec 2023 15:55:53 +0800
|
|
Subject: [PATCH 09/16] vhost: implement migration state notifier for vdpa
|
|
device
|
|
|
|
Register migration state notifier to support triggered by
|
|
migration exceptions
|
|
|
|
Signed-off-by: libai <libai12@huawei.com>
|
|
---
|
|
hw/virtio/vdpa-dev-mig.c | 29 +++++++++++++++++++++++++++++
|
|
include/hw/virtio/vdpa-dev.h | 1 +
|
|
2 files changed, 30 insertions(+)
|
|
|
|
diff --git a/hw/virtio/vdpa-dev-mig.c b/hw/virtio/vdpa-dev-mig.c
|
|
index 1872f11..9b47e3e 100644
|
|
--- a/hw/virtio/vdpa-dev-mig.c
|
|
+++ b/hw/virtio/vdpa-dev-mig.c
|
|
@@ -23,6 +23,7 @@
|
|
#include "hw/virtio/virtio-bus.h"
|
|
#include "migration/register.h"
|
|
#include "migration/migration.h"
|
|
+#include "migration/misc.h"
|
|
#include "qemu/error-report.h"
|
|
#include "hw/virtio/vdpa-dev-mig.h"
|
|
#include "migration/qemu-file-types.h"
|
|
@@ -354,6 +355,31 @@ static SaveVMHandlers savevm_vdpa_handlers = {
|
|
.load_setup = vdpa_load_setup,
|
|
};
|
|
|
|
+static void vdpa_migration_state_notifier(Notifier *notifier, void *data)
|
|
+{
|
|
+ MigrationState *s = data;
|
|
+ VhostVdpaDevice *vdev = container_of(notifier,
|
|
+ VhostVdpaDevice,
|
|
+ migration_state);
|
|
+ struct vhost_dev *hdev = &vdev->dev;
|
|
+ int ret;
|
|
+
|
|
+ switch (s->state) {
|
|
+ case MIGRATION_STATUS_CANCELLING:
|
|
+ case MIGRATION_STATUS_CANCELLED:
|
|
+ case MIGRATION_STATUS_FAILED:
|
|
+ ret = vhost_vdpa_set_mig_state(hdev, VDPA_DEVICE_CANCEL);
|
|
+ if (ret) {
|
|
+ error_report("Failed to set state CANCEL\n");
|
|
+ }
|
|
+
|
|
+ break;
|
|
+ case MIGRATION_STATUS_COMPLETED:
|
|
+ default:
|
|
+ break;
|
|
+ }
|
|
+}
|
|
+
|
|
void vdpa_migration_register(VhostVdpaDevice *vdev)
|
|
{
|
|
vdev->vmstate = qdev_add_vm_change_state_handler(DEVICE(vdev),
|
|
@@ -361,10 +387,13 @@ void vdpa_migration_register(VhostVdpaDevice *vdev)
|
|
DEVICE(vdev));
|
|
register_savevm_live("vdpa", -1, 1,
|
|
&savevm_vdpa_handlers, DEVICE(vdev));
|
|
+ vdev->migration_state.notify = vdpa_migration_state_notifier;
|
|
+ migration_add_notifier(&vdev->migration_state, vdpa_migration_state_notifier);
|
|
}
|
|
|
|
void vdpa_migration_unregister(VhostVdpaDevice *vdev)
|
|
{
|
|
+ migration_remove_notifier(&vdev->migration_state);
|
|
unregister_savevm(VMSTATE_IF(&vdev->parent_obj.parent_obj), "vdpa", DEVICE(vdev));
|
|
qemu_del_vm_change_state_handler(vdev->vmstate);
|
|
}
|
|
diff --git a/include/hw/virtio/vdpa-dev.h b/include/hw/virtio/vdpa-dev.h
|
|
index 43cbcef..20f50c7 100644
|
|
--- a/include/hw/virtio/vdpa-dev.h
|
|
+++ b/include/hw/virtio/vdpa-dev.h
|
|
@@ -39,6 +39,7 @@ struct VhostVdpaDevice {
|
|
bool started;
|
|
int (*post_init)(VhostVdpaDevice *v, Error **errp);
|
|
VMChangeStateEntry *vmstate;
|
|
+ Notifier migration_state;
|
|
};
|
|
|
|
#endif
|
|
--
|
|
2.46.0.windows.1
|
|
|