xref: /openbmc/qemu/migration/yank_functions.c (revision be355a44)
1 /*
2  * migration yank functions
3  *
4  * Copyright (c) Lukas Straub <lukasstraub2@web.de>
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7  * See the COPYING file in the top-level directory.
8  */
9 
10 #include "qemu/osdep.h"
11 #include "io/channel.h"
12 #include "yank_functions.h"
13 #include "qemu/yank.h"
14 #include "qemu-file.h"
15 
16 void migration_yank_iochannel(void *opaque)
17 {
18     QIOChannel *ioc = QIO_CHANNEL(opaque);
19 
20     qio_channel_shutdown(ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);
21 }
22 
23 /* Return whether yank is supported on this ioc */
24 static bool migration_ioc_yank_supported(QIOChannel *ioc)
25 {
26     return qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN);
27 }
28 
29 void migration_ioc_register_yank(QIOChannel *ioc)
30 {
31     if (migration_ioc_yank_supported(ioc)) {
32         yank_register_function(MIGRATION_YANK_INSTANCE,
33                                migration_yank_iochannel,
34                                ioc);
35     }
36 }
37 
38 void migration_ioc_unregister_yank(QIOChannel *ioc)
39 {
40     if (migration_ioc_yank_supported(ioc)) {
41         yank_unregister_function(MIGRATION_YANK_INSTANCE,
42                                  migration_yank_iochannel,
43                                  ioc);
44     }
45 }
46 
47 void migration_ioc_unregister_yank_from_file(QEMUFile *file)
48 {
49     QIOChannel *ioc = qemu_file_get_ioc(file);
50 
51     if (ioc) {
52         /*
53          * For migration qemufiles, we'll always reach here.  Though we'll skip
54          * calls from e.g. savevm/loadvm as they don't use yank.
55          */
56         migration_ioc_unregister_yank(ioc);
57     }
58 }
59