qemu/migration/yank_functions.c
Fabiano Rosas 0a5d1108ab migration/yank: Use channel features
Stop using outside knowledge about the io channels when registering
yank functions. Query for features instead.

The yank method for all channels used with migration code currently is
to call the qio_channel_shutdown() function, so query for
QIO_CHANNEL_FEATURE_SHUTDOWN. We could add a separate feature in the
future for indicating whether a channel supports yanking, but that
seems overkill at the moment.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Peter Xu <peterx@redhat.com>
Link: https://lore.kernel.org/r/20230911171320.24372-9-farosas@suse.de
Signed-off-by: Peter Xu <peterx@redhat.com>
2024-01-29 11:02:12 +08:00

59 lines
1.5 KiB
C

/*
* migration yank functions
*
* Copyright (c) Lukas Straub <lukasstraub2@web.de>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
#include "qemu/osdep.h"
#include "io/channel.h"
#include "yank_functions.h"
#include "qemu/yank.h"
#include "qemu-file.h"
void migration_yank_iochannel(void *opaque)
{
QIOChannel *ioc = QIO_CHANNEL(opaque);
qio_channel_shutdown(ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);
}
/* Return whether yank is supported on this ioc */
static bool migration_ioc_yank_supported(QIOChannel *ioc)
{
return qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN);
}
void migration_ioc_register_yank(QIOChannel *ioc)
{
if (migration_ioc_yank_supported(ioc)) {
yank_register_function(MIGRATION_YANK_INSTANCE,
migration_yank_iochannel,
ioc);
}
}
void migration_ioc_unregister_yank(QIOChannel *ioc)
{
if (migration_ioc_yank_supported(ioc)) {
yank_unregister_function(MIGRATION_YANK_INSTANCE,
migration_yank_iochannel,
ioc);
}
}
void migration_ioc_unregister_yank_from_file(QEMUFile *file)
{
QIOChannel *ioc = qemu_file_get_ioc(file);
if (ioc) {
/*
* For migration qemufiles, we'll always reach here. Though we'll skip
* calls from e.g. savevm/loadvm as they don't use yank.
*/
migration_ioc_unregister_yank(ioc);
}
}