blob: 8c08aef14a87bf7f7e0073ab8cfe3682af0ab573 [file] [log] [blame]
Lukas Straub1a92d6d2021-03-23 18:52:42 +01001/*
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"
Peter Xu18711402021-07-22 13:58:39 -040014#include "qemu/yank.h"
15#include "io/channel-socket.h"
16#include "io/channel-tls.h"
Peter Xu39675ff2021-07-22 13:58:41 -040017#include "qemu-file.h"
Lukas Straub1a92d6d2021-03-23 18:52:42 +010018
19void migration_yank_iochannel(void *opaque)
20{
21 QIOChannel *ioc = QIO_CHANNEL(opaque);
22
23 qio_channel_shutdown(ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);
24}
Peter Xu18711402021-07-22 13:58:39 -040025
26/* Return whether yank is supported on this ioc */
27static 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
33void 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
42void 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}
Peter Xu39675ff2021-07-22 13:58:41 -040050
51void 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}