[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4 06/13] vfio: Add migration state change notif
From: |
Dr. David Alan Gilbert |
Subject: |
Re: [Qemu-devel] [PATCH v4 06/13] vfio: Add migration state change notifier |
Date: |
Thu, 27 Jun 2019 11:33:01 +0100 |
User-agent: |
Mutt/1.12.0 (2019-05-25) |
* Kirti Wankhede (address@hidden) wrote:
> Added migration state change notifier to get notification on migration state
> change. These states are translated to VFIO device state and conveyed to
> vendor
> driver.
>
> Signed-off-by: Kirti Wankhede <address@hidden>
> Reviewed-by: Neo Jia <address@hidden>
Just a general thought; be careful when following migration states;
For example 'device' and 'pre_switchover' - just be careful to think
about all the different states and how you might get a 'failed'
anywhere.
Dave
> ---
> hw/vfio/migration.c | 49
> +++++++++++++++++++++++++++++++++++++++++++
> include/hw/vfio/vfio-common.h | 1 +
> 2 files changed, 50 insertions(+)
>
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index 15af218c23d1..7f9858e6c995 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -112,6 +112,48 @@ static void vfio_vmstate_change(void *opaque, int
> running, RunState state)
> vbasedev->vm_running = running;
> }
>
> +static void vfio_migration_state_notifier(Notifier *notifier, void *data)
> +{
> + MigrationState *s = data;
> + VFIODevice *vbasedev = container_of(notifier, VFIODevice,
> migration_state);
> + int ret;
> +
> + switch (s->state) {
> + case MIGRATION_STATUS_ACTIVE:
> + if (vbasedev->device_state & VFIO_DEVICE_STATE_RUNNING) {
> + if (vbasedev->vm_running) {
> + ret = vfio_migration_set_state(vbasedev,
> + VFIO_DEVICE_STATE_RUNNING |
> VFIO_DEVICE_STATE_SAVING);
> + if (ret) {
> + error_report("Failed to set state RUNNING and SAVING");
> + }
> + } else {
> + ret = vfio_migration_set_state(vbasedev,
> + VFIO_DEVICE_STATE_SAVING);
> + if (ret) {
> + error_report("Failed to set state STOP and SAVING");
> + }
> + }
> + } else {
> + ret = vfio_migration_set_state(vbasedev,
> + VFIO_DEVICE_STATE_RESUMING);
> + if (ret) {
> + error_report("Failed to set state RESUMING");
> + }
> + }
> + return;
> +
> + case MIGRATION_STATUS_CANCELLING:
> + case MIGRATION_STATUS_CANCELLED:
> + case MIGRATION_STATUS_FAILED:
> + ret = vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_RUNNING);
> + if (ret) {
> + error_report("Failed to set state RUNNING");
> + }
> + return;
> + }
> +}
> +
> static int vfio_migration_init(VFIODevice *vbasedev,
> struct vfio_region_info *info)
> {
> @@ -131,6 +173,9 @@ static int vfio_migration_init(VFIODevice *vbasedev,
> vbasedev->vm_state =
> qemu_add_vm_change_state_handler(vfio_vmstate_change,
> vbasedev);
>
> + vbasedev->migration_state.notify = vfio_migration_state_notifier;
> + add_migration_state_change_notifier(&vbasedev->migration_state);
> +
> return 0;
> }
>
> @@ -167,6 +212,10 @@ void vfio_migration_finalize(VFIODevice *vbasedev)
> return;
> }
>
> + if (vbasedev->migration_state.notify) {
> + remove_migration_state_change_notifier(&vbasedev->migration_state);
> + }
> +
> if (vbasedev->vm_state) {
> qemu_del_vm_change_state_handler(vbasedev->vm_state);
> }
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index f2392e97fa57..1d26e6be8d48 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -133,6 +133,7 @@ typedef struct VFIODevice {
> uint32_t device_state;
> VMChangeStateEntry *vm_state;
> int vm_running;
> + Notifier migration_state;
> } VFIODevice;
>
> struct VFIODeviceOps {
> --
> 2.7.0
>
--
Dr. David Alan Gilbert / address@hidden / Manchester, UK
- Re: [Qemu-devel] [PATCH v4 01/13] vfio: KABI for migration interface, (continued)
[Qemu-devel] [PATCH v4 03/13] vfio: Add save and load functions for VFIO PCI devices, Kirti Wankhede, 2019/06/20
[Qemu-devel] [PATCH v4 07/13] vfio: Register SaveVMHandlers for VFIO device, Kirti Wankhede, 2019/06/20
[Qemu-devel] [PATCH v4 06/13] vfio: Add migration state change notifier, Kirti Wankhede, 2019/06/20
- Re: [Qemu-devel] [PATCH v4 06/13] vfio: Add migration state change notifier,
Dr. David Alan Gilbert <=
[Qemu-devel] [PATCH v4 04/13] vfio: Add migration region initialization and finalize function, Kirti Wankhede, 2019/06/20
[Qemu-devel] [PATCH v4 08/13] vfio: Add save state functions to SaveVMHandlers, Kirti Wankhede, 2019/06/20
- Re: [Qemu-devel] [PATCH v4 08/13] vfio: Add save state functions to SaveVMHandlers, Alex Williamson, 2019/06/20
- Re: [Qemu-devel] [PATCH v4 08/13] vfio: Add save state functions to SaveVMHandlers, Kirti Wankhede, 2019/06/21
- Re: [Qemu-devel] [PATCH v4 08/13] vfio: Add save state functions to SaveVMHandlers, Alex Williamson, 2019/06/21
- Re: [Qemu-devel] [PATCH v4 08/13] vfio: Add save state functions to SaveVMHandlers, Kirti Wankhede, 2019/06/21
- Re: [Qemu-devel] [PATCH v4 08/13] vfio: Add save state functions to SaveVMHandlers, Alex Williamson, 2019/06/21
- Re: [Qemu-devel] [PATCH v4 08/13] vfio: Add save state functions to SaveVMHandlers, Kirti Wankhede, 2019/06/21