xref: /openbmc/qemu/migration/yank_functions.c (revision b91a0fa7)
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 "qapi/error.h"
12 #include "io/channel.h"
13 #include "yank_functions.h"
14 #include "qemu/yank.h"
15 #include "io/channel-socket.h"
16 #include "io/channel-tls.h"
17 #include "qemu-file.h"
18 
19 void migration_yank_iochannel(void *opaque)
20 {
21     QIOChannel *ioc = QIO_CHANNEL(opaque);
22 
23     qio_channel_shutdown(ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);
24 }
25 
26 /* Return whether yank is supported on this ioc */
27 static bool migration_ioc_yank_supported(QIOChannel *ioc)
28 {
29     return object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET) ||
30         object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_TLS);
31 }
32 
33 void migration_ioc_register_yank(QIOChannel *ioc)
34 {
35     if (migration_ioc_yank_supported(ioc)) {
36         yank_register_function(MIGRATION_YANK_INSTANCE,
37                                migration_yank_iochannel,
38                                QIO_CHANNEL(ioc));
39     }
40 }
41 
42 void migration_ioc_unregister_yank(QIOChannel *ioc)
43 {
44     if (migration_ioc_yank_supported(ioc)) {
45         yank_unregister_function(MIGRATION_YANK_INSTANCE,
46                                  migration_yank_iochannel,
47                                  QIO_CHANNEL(ioc));
48     }
49 }
50 
51 void migration_ioc_unregister_yank_from_file(QEMUFile *file)
52 {
53     QIOChannel *ioc = qemu_file_get_ioc(file);
54 
55     if (ioc) {
56         /*
57          * For migration qemufiles, we'll always reach here.  Though we'll skip
58          * calls from e.g. savevm/loadvm as they don't use yank.
59          */
60         migration_ioc_unregister_yank(ioc);
61     }
62 }
63