Lukas Straub | 1a92d6d | 2021-03-23 18:52:42 +0100 | [diff] [blame] | 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" |
Lukas Straub | 1a92d6d | 2021-03-23 18:52:42 +0100 | [diff] [blame] | 11 | #include "io/channel.h" |
| 12 | #include "yank_functions.h" |
Peter Xu | 1871140 | 2021-07-22 13:58:39 -0400 | [diff] [blame] | 13 | #include "qemu/yank.h" |
Peter Xu | 39675ff | 2021-07-22 13:58:41 -0400 | [diff] [blame] | 14 | #include "qemu-file.h" |
Lukas Straub | 1a92d6d | 2021-03-23 18:52:42 +0100 | [diff] [blame] | 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 | } |
Peter Xu | 1871140 | 2021-07-22 13:58:39 -0400 | [diff] [blame] | 22 | |
| 23 | /* Return whether yank is supported on this ioc */ |
| 24 | static bool migration_ioc_yank_supported(QIOChannel *ioc) |
| 25 | { |
Fabiano Rosas | 0a5d110 | 2023-09-11 14:13:18 -0300 | [diff] [blame] | 26 | return qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN); |
Peter Xu | 1871140 | 2021-07-22 13:58:39 -0400 | [diff] [blame] | 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, |
Philippe Mathieu-Daudé | 7d5b0d6 | 2023-06-01 11:34:52 +0200 | [diff] [blame] | 34 | ioc); |
Peter Xu | 1871140 | 2021-07-22 13:58:39 -0400 | [diff] [blame] | 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, |
Philippe Mathieu-Daudé | 7d5b0d6 | 2023-06-01 11:34:52 +0200 | [diff] [blame] | 43 | ioc); |
Peter Xu | 1871140 | 2021-07-22 13:58:39 -0400 | [diff] [blame] | 44 | } |
| 45 | } |
Peter Xu | 39675ff | 2021-07-22 13:58:41 -0400 | [diff] [blame] | 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 | } |