xref: /qemu/hw/vfio/cpr.c (revision 03f50d7ee756eecbd4481c3008b5e01e999729c7)
1 /*
2  * Copyright (c) 2021-2024 Oracle and/or its affiliates.
3  *
4  * This work is licensed under the terms of the GNU GPL, version 2 or later.
5  * See the COPYING file in the top-level directory.
6  */
7 
8 #include "qemu/osdep.h"
9 #include "hw/vfio/vfio-device.h"
10 #include "migration/misc.h"
11 #include "qapi/error.h"
12 #include "system/runstate.h"
13 #include "vfio-cpr.h"
14 
15 static int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier,
16                                     MigrationEvent *e, Error **errp)
17 {
18     if (e->type == MIG_EVENT_PRECOPY_SETUP &&
19         !runstate_check(RUN_STATE_SUSPENDED) && !vm_get_suspended()) {
20 
21         error_setg(errp,
22             "VFIO device only supports cpr-reboot for runstate suspended");
23 
24         return -1;
25     }
26     return 0;
27 }
28 
29 bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **errp)
30 {
31     migration_add_notifier_mode(&bcontainer->cpr_reboot_notifier,
32                                 vfio_cpr_reboot_notifier,
33                                 MIG_MODE_CPR_REBOOT);
34     return true;
35 }
36 
37 void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer)
38 {
39     migration_remove_notifier(&bcontainer->cpr_reboot_notifier);
40 }
41