blob: 979e60c7620c640076ebc97612869306b25f1b42 [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"
Lukas Straub1a92d6d2021-03-23 18:52:42 +010011#include "io/channel.h"
12#include "yank_functions.h"
Peter Xu18711402021-07-22 13:58:39 -040013#include "qemu/yank.h"
Peter Xu39675ff2021-07-22 13:58:41 -040014#include "qemu-file.h"
Lukas Straub1a92d6d2021-03-23 18:52:42 +010015
16void migration_yank_iochannel(void *opaque)
17{
18 QIOChannel *ioc = QIO_CHANNEL(opaque);
19
20 qio_channel_shutdown(ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);
21}
Peter Xu18711402021-07-22 13:58:39 -040022
23/* Return whether yank is supported on this ioc */
24static bool migration_ioc_yank_supported(QIOChannel *ioc)
25{
Fabiano Rosas0a5d1102023-09-11 14:13:18 -030026 return qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN);
Peter Xu18711402021-07-22 13:58:39 -040027}
28
29void 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,
Philippe Mathieu-Daudé7d5b0d62023-06-01 11:34:52 +020034 ioc);
Peter Xu18711402021-07-22 13:58:39 -040035 }
36}
37
38void 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,
Philippe Mathieu-Daudé7d5b0d62023-06-01 11:34:52 +020043 ioc);
Peter Xu18711402021-07-22 13:58:39 -040044 }
45}
Peter Xu39675ff2021-07-22 13:58:41 -040046
47void 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}