Merge tag 'migration-20261029-pull-request' of https://gitlab.com/farosas/qemu into staging
Migration pull-request - Compatibility fix for multifd+postcopy migration against older versions - Rework of early connection code - Adjustment to snapshot thread name # -----BEGIN PGP SIGNATURE----- # # iQJEBAABCAAuFiEEqhtIsKIjJqWkw2TPx5jcdBvsMZ0FAmrjlD0QHGZhcm9zYXNA # c3VzZS5kZQAKCRDHmNx0G+wxnUZ5D/94kaE3L9ZTGp3zCOlZgiKXwkpvyYu4on2v # 9lCMa39lEgFy3B0ASjPCdeHiJoa8sGDIBsmkpB20M+WsiP4T7TgfZbzPcEjKtsZe # Xl5vn5LcupVsH0VBpLnkgYEqV24czLxPIQh3wXMXCY7df2nrHQpK8s+0P28TShiQ # ZBLahqQWVvDXOesGTuH1yD0AIxDjQ4yIlTPaTiDTC/EEDh5uaeS48SpJLektNdoP # ZCsC7VBghH9fqIf2c0D/j9ewKUW67h5XaMVyXULNs0rup18qhu+tjLHwD7HuT6fL # 1UBnqqJykbiP4C9Ac7N7Uqb548MVl1s5Yv3pz82SU5vz09vxwLMzDfRcUmAZBcUH # hgIiZzKEvRgQK86iWaUmVVwM5AcQwREVu+ohayxfI6tBieCHLEO5EkVQ1WEkuo3X # v6NXxsokXJ1K2gs3SzooDlSAFu9MHTCFBFGcnmIlMEeBLrVpJTqPc0bMounuIJ52 # aPvdjpyAiYDAxTWK0Pl/UDcRSW90HeI+2ibQtYWn9ZHcTVLqRd8yb3dntrcMNzmO # udcbVlIsqyCs6n/T/vuGshHOVXjJiuPj/1CFCsvyM9E5Fj7sNG7EV2vZxzt24+Ho # mjROo1pwep/WftCj6b41pCA3RT9VYRMUKyZm3NOPsoiJCYU9DRnUOF4spYVuwxUf # 4CpMfEU6kg== # =WmGN # -----END PGP SIGNATURE----- # gpg: Signature made Thu 29 Oct 2026 01:45:17 PM CDT # gpg: using RSA key AA1B48B0A22326A5A4C364CFC798DC741BEC319D # gpg: issuer "farosas@suse.de" # gpg: Good signature from "Fabiano Rosas <farosas@suse.de>" [unknown] # gpg: aka "Fabiano Almeida Rosas <fabiano.rosas@suse.com>" [unknown] # gpg: WARNING: The key's User ID is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: AA1B 48B0 A223 26A5 A4C3 64CF C798 DC74 1BEC 319D * tag 'migration-20261029-pull-request' of https://gitlab.com/farosas/qemu: migration: Postpone the outgoing preempt channel for preempt_pre_7_2 migration: Fix incoming channel race with multifd and preempt_pre_7_2 migration: Dump type of channel in set_incoming_channel tracepoint migration: Split migration_channel_process_incoming() migration: Fix socket listen backlog migration: Add two more trace points for incoming channel mgmt tests/migration-test: Add multifd+postcopy test for preempt recovery migration: shorten dst snapshot load thread name Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
commit
6bf67e6b2c
7 files changed
+511
-89
No files matched your search
+384
-62
@@ -12,6 +12,8 @@
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "channel.h"
|
||||
#include "exec.h"
|
||||
#include "fd.h"
|
||||
@@ -34,6 +36,13 @@
|
||||
#include "trace.h"
|
||||
#include "yank_functions.h"
|
||||
|
||||
static const char *const mig_channel_str[CH_NUM] = {
|
||||
[CH_NONE] = "NONE",
|
||||
[CH_MAIN] = "MAIN",
|
||||
[CH_MULTIFD] = "MULTIFD",
|
||||
[CH_POSTCOPY] = "PREEMPT",
|
||||
};
|
||||
|
||||
void migration_connect_outgoing(MigrationState *s, MigrationAddress *addr,
|
||||
Error **errp)
|
||||
{
|
||||
@@ -139,62 +148,350 @@ bool migration_has_all_channels(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
static MigChannelType migration_channel_identify(MigrationIncomingState *mis,
|
||||
QIOChannel *ioc, Error **errp)
|
||||
static bool qio_channel_is_peekable(QIOChannel *ioc)
|
||||
{
|
||||
return qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_READ_MSG_PEEK);
|
||||
}
|
||||
|
||||
/*
|
||||
* With multiple channels, it is possible that we receive channels out of
|
||||
* order on destination side, causing incorrect mapping of source channels
|
||||
* on destination side.
|
||||
*
|
||||
* When the channel is peekable (e.g. non-TLS socket channels), check
|
||||
* channel MAGIC to decide type of channel.
|
||||
*
|
||||
* Please note this is best effort, postcopy preempt channel does not send
|
||||
* any magic number so avoid it for postcopy live migration.
|
||||
*
|
||||
* Returns: >0 if success, ==0 (CH_NONE) if error. If error happened,
|
||||
* *errp must be set.
|
||||
*/
|
||||
static MigChannelType migration_channel_peek(MigrationIncomingState *mis,
|
||||
QIOChannel *ioc,
|
||||
Error **errp)
|
||||
{
|
||||
MigChannelType channel = CH_NONE;
|
||||
uint32_t channel_magic = 0;
|
||||
int ret = 0;
|
||||
|
||||
if (!migration_has_main_and_multifd_channels()) {
|
||||
if (qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_READ_MSG_PEEK)) {
|
||||
/*
|
||||
* With multiple channels, it is possible that we receive channels
|
||||
* out of order on destination side, causing incorrect mapping of
|
||||
* source channels on destination side. Check channel MAGIC to
|
||||
* decide type of channel. Please note this is best effort,
|
||||
* postcopy preempt channel does not send any magic number so
|
||||
* avoid it for postcopy live migration. Also tls live migration
|
||||
* already does tls handshake while initializing main channel so
|
||||
* with tls this issue is not possible.
|
||||
*/
|
||||
ret = migration_channel_read_peek(ioc, (void *)&channel_magic,
|
||||
sizeof(channel_magic), errp);
|
||||
if (ret != 0) {
|
||||
goto out;
|
||||
}
|
||||
assert(qio_channel_is_peekable(ioc));
|
||||
|
||||
channel_magic = be32_to_cpu(channel_magic);
|
||||
if (channel_magic == QEMU_VM_FILE_MAGIC) {
|
||||
channel = CH_MAIN;
|
||||
} else if (channel_magic == MULTIFD_MAGIC) {
|
||||
assert(migrate_multifd());
|
||||
channel = CH_MULTIFD;
|
||||
} else if (!mis->from_src_file &&
|
||||
mis->state == MIGRATION_STATUS_POSTCOPY_PAUSED) {
|
||||
/* reconnect main channel for postcopy recovery */
|
||||
channel = CH_MAIN;
|
||||
} else {
|
||||
error_setg(errp, "unknown channel magic: %u", channel_magic);
|
||||
}
|
||||
} else if (mis->from_src_file && migrate_multifd()) {
|
||||
/*
|
||||
* Non-peekable channels like tls/file are processed as
|
||||
* multifd channels when multifd is enabled.
|
||||
*/
|
||||
channel = CH_MULTIFD;
|
||||
} else if (!mis->from_src_file) {
|
||||
channel = CH_MAIN;
|
||||
} else {
|
||||
error_setg(errp, "non-peekable channel used without multifd");
|
||||
}
|
||||
ret = migration_channel_read_peek(ioc, (void *)&channel_magic,
|
||||
sizeof(channel_magic), errp);
|
||||
if (ret != 0) {
|
||||
/* Failed */
|
||||
return channel;
|
||||
}
|
||||
|
||||
channel_magic = be32_to_cpu(channel_magic);
|
||||
|
||||
if (channel_magic == QEMU_VM_FILE_MAGIC) {
|
||||
channel = CH_MAIN;
|
||||
} else if (channel_magic == MULTIFD_MAGIC) {
|
||||
assert(migrate_multifd());
|
||||
channel = CH_MULTIFD;
|
||||
} else if (!mis->from_src_file &&
|
||||
mis->state == MIGRATION_STATUS_POSTCOPY_PAUSED) {
|
||||
/* reconnect main channel for postcopy recovery */
|
||||
channel = CH_MAIN;
|
||||
} else {
|
||||
assert(migrate_postcopy_preempt());
|
||||
channel = CH_POSTCOPY;
|
||||
error_setg(errp, "Unknown channel magic: %u", channel_magic);
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns: >0 if success, ==0 (CH_NONE) if error. If error happened,
|
||||
* *errp must be set. NOTE: preempt channel is done separately.
|
||||
*/
|
||||
static MigChannelType migration_channel_identify(MigrationIncomingState *mis,
|
||||
QIOChannel *ioc, Error **errp)
|
||||
{
|
||||
MigChannelType channel = CH_NONE;
|
||||
|
||||
if (!mis->from_src_file) {
|
||||
channel = CH_MAIN;
|
||||
} else if (migrate_multifd()) {
|
||||
/*
|
||||
* Non-peekable channels like tls/file are processed as
|
||||
* multifd channels when multifd is enabled.
|
||||
*/
|
||||
channel = CH_MULTIFD;
|
||||
} else {
|
||||
error_setg(errp, "Unexpected non-peekable channel observed");
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
static void migration_incoming_error_propagate(MigrationIncomingState *mis,
|
||||
Error *error)
|
||||
{
|
||||
error_report_err(error);
|
||||
migrate_set_state(&mis->state, mis->state, MIGRATION_STATUS_FAILED);
|
||||
if (mis->exit_on_error) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Must be with mis->channels_early.mutex held */
|
||||
static void
|
||||
migration_incoming_early_channel_insert(MigrationIncomingState *mis,
|
||||
QIOChannel *ioc,
|
||||
GSource *source)
|
||||
{
|
||||
MigEarlyIncomingChannel chan = {
|
||||
.source = source,
|
||||
.ioc = ioc,
|
||||
};
|
||||
|
||||
object_ref(OBJECT(ioc));
|
||||
g_source_ref(source);
|
||||
|
||||
g_array_append_val(mis->channels_early.channels, chan);
|
||||
}
|
||||
|
||||
static void migration_incoming_early_channel_free(GArray *channels, int i)
|
||||
{
|
||||
MigEarlyIncomingChannel *chan;
|
||||
|
||||
chan = &g_array_index(channels, MigEarlyIncomingChannel, i);
|
||||
|
||||
g_source_destroy(chan->source);
|
||||
g_source_unref(chan->source);
|
||||
object_unref(OBJECT(chan->ioc));
|
||||
|
||||
g_array_remove_index_fast(channels, i);
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove this channel from the monitoring of @channels_early array.
|
||||
* Return true if found and successful, false otherwise.
|
||||
*/
|
||||
static bool
|
||||
migration_incoming_early_channel_remove(MigrationIncomingState *mis,
|
||||
QIOChannel *ioc)
|
||||
{
|
||||
GArray *channels = mis->channels_early.channels;
|
||||
MigEarlyIncomingChannel *chan;
|
||||
int i;
|
||||
|
||||
QEMU_LOCK_GUARD(&mis->channels_early.mutex);
|
||||
|
||||
for (i = 0; i < channels->len; i++) {
|
||||
chan = &g_array_index(channels, MigEarlyIncomingChannel, i);
|
||||
if (chan->ioc != ioc) {
|
||||
continue;
|
||||
}
|
||||
migration_incoming_early_channel_free(channels, i);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void migration_incoming_free_early_channels(MigrationIncomingState *mis)
|
||||
{
|
||||
GArray *channels = mis->channels_early.channels;
|
||||
|
||||
QEMU_LOCK_GUARD(&mis->channels_early.mutex);
|
||||
|
||||
while (channels->len) {
|
||||
migration_incoming_early_channel_free(channels, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static bool migration_incoming_setup_channel(QIOChannel *ioc,
|
||||
MigChannelType ch,
|
||||
Error **errp)
|
||||
{
|
||||
trace_migration_incoming_channel_set(ioc,
|
||||
object_get_typename(OBJECT(ioc)),
|
||||
mig_channel_str[ch]);
|
||||
migration_ioc_register_yank(ioc);
|
||||
|
||||
return migration_incoming_setup(ioc, ch, errp);
|
||||
}
|
||||
|
||||
static bool migration_incoming_channel_install(MigrationIncomingState *mis,
|
||||
QIOChannel *ioc,
|
||||
MigChannelType ch,
|
||||
Error **errp)
|
||||
{
|
||||
if (!migration_incoming_setup_channel(ioc, ch, errp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Installation succeeded, kickoff migration if needed */
|
||||
if (migration_has_main_and_multifd_channels()) {
|
||||
migration_start_incoming();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
migration_incoming_channel_preempt_setup(QIOChannel *ioc)
|
||||
{
|
||||
assert(migrate_postcopy_preempt());
|
||||
/* Installation of preempt channel should never fail */
|
||||
migration_incoming_setup_channel(ioc, CH_POSTCOPY, &error_abort);
|
||||
}
|
||||
|
||||
static void
|
||||
migration_incoming_detect_preempt_channel(MigrationIncomingState *mis)
|
||||
{
|
||||
GArray *channels = mis->channels_early.channels;
|
||||
MigEarlyIncomingChannel *chan;
|
||||
|
||||
QEMU_LOCK_GUARD(&mis->channels_early.mutex);
|
||||
|
||||
/* When preempt mode not enabled, nothing to detect.. */
|
||||
if (!migrate_postcopy_preempt()) {
|
||||
/*
|
||||
* .. but if we found something pending, throw an error only, which
|
||||
* should not happen. Even if it happens, resources will still be
|
||||
* released after incoming migration is completedly.
|
||||
*/
|
||||
if (channels->len) {
|
||||
error_report("%s: Found %u unused channels",
|
||||
__func__, channels->len);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Preempt channel hasn't yet arrived? Process it later */
|
||||
if (!channels->len) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* More than one channel should never happen.. capture it in case if
|
||||
* it happens, then there's not much we can do.
|
||||
*/
|
||||
if (channels->len > 1) {
|
||||
error_report("%s: Found %u unused channels, "
|
||||
"can't identify preempt channel",
|
||||
__func__, channels->len);
|
||||
return;
|
||||
}
|
||||
|
||||
assert(channels->len == 1);
|
||||
/* This is the preempt channel, install it directly */
|
||||
chan = &g_array_index(channels, MigEarlyIncomingChannel, 0);
|
||||
migration_incoming_channel_preempt_setup(chan->ioc);
|
||||
migration_incoming_early_channel_free(channels, 0);
|
||||
}
|
||||
|
||||
static gboolean migration_incoming_channel_readable(QIOChannel *ioc,
|
||||
GIOCondition condition,
|
||||
gpointer opaque)
|
||||
{
|
||||
MigrationIncomingState *mis = opaque;
|
||||
Error *local_err = NULL;
|
||||
MigChannelType ch;
|
||||
|
||||
/*
|
||||
* No need to monitor this channel anymore as long as anything arrived,
|
||||
* remove it from tracking.
|
||||
*
|
||||
* NOTE: this means if partial data arrived we may still block here,
|
||||
* but it shouldn't happen in production, only malicious stream. Since
|
||||
* migration stream is trusted (either due to trusted network, or TLS),
|
||||
* that's non-issue.
|
||||
*
|
||||
* NOTE2: it's theoretically possible that this entry is gone reaching
|
||||
* here. Example: the main thread is doing incoming cleanup having this
|
||||
* one removed, while this watch can be registered on the monitor
|
||||
* iothread's context and fired at the exact same time but in the
|
||||
* iothread instead. If it happens, skip the rest. I'm not sure if
|
||||
* this could happen at all, may depend on iothread lifespan management
|
||||
* in the main thread, but be prepared.
|
||||
*/
|
||||
if (!migration_incoming_early_channel_remove(mis, ioc)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ch = migration_channel_peek(mis, ioc, &local_err);
|
||||
if (!ch) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!migration_incoming_channel_install(mis, ioc, ch, &local_err)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (migration_has_main_and_multifd_channels()) {
|
||||
/*
|
||||
* Possibilities when reaching here:
|
||||
*
|
||||
* (1) if preempt not enabled, this should be no-op, all done,
|
||||
* (2) if preempt enabled,
|
||||
* (2.a) preempt channel arrived @channels_early, handle it now
|
||||
* (2.b) preempt channel not arrived, to be handled in
|
||||
* migration_channel_process_incoming() later
|
||||
*/
|
||||
migration_incoming_detect_preempt_channel(mis);
|
||||
}
|
||||
|
||||
out:
|
||||
return channel;
|
||||
if (local_err) {
|
||||
migration_incoming_error_propagate(mis, local_err);
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: we should have already detached the GSource, returning
|
||||
* G_SOURCE_REMOVE to be logically consistent only.
|
||||
*/
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void migration_incoming_channel_watch(MigrationIncomingState *mis,
|
||||
QIOChannel *ioc)
|
||||
{
|
||||
GMainContext *context = g_main_context_get_thread_default();
|
||||
GSource *source;
|
||||
guint io_tag;
|
||||
|
||||
trace_migration_incoming_channel_watch(ioc,
|
||||
object_get_typename(OBJECT(ioc)));
|
||||
|
||||
/*
|
||||
* Careful: this can be run from either the main thread or the monitor
|
||||
* iothread when migrate_recover is used with OOB=on, so we need to
|
||||
* take the lock and use the full version to specify the correct
|
||||
* context.
|
||||
*/
|
||||
QEMU_LOCK_GUARD(&mis->channels_early.mutex);
|
||||
|
||||
/*
|
||||
* We should never watch an @ioc that is not peekable, because there's
|
||||
* no point. What is worse is we lose the real order of accept()s via
|
||||
* the asynchronous IO watch operation.
|
||||
*
|
||||
* Another note is TLS channel (non-peekable) may or may not work
|
||||
* properly with IO watch due to its current .io_create_watch() impl,
|
||||
* which is another story. Just guard both points.
|
||||
*/
|
||||
assert(qio_channel_is_peekable(ioc));
|
||||
io_tag = qio_channel_add_watch_full(ioc, G_IO_IN,
|
||||
migration_incoming_channel_readable,
|
||||
mis, NULL, context);
|
||||
|
||||
/*
|
||||
* Replace this if one day qio_channel_add_watch*() API can directly
|
||||
* return the GSource*.. for now, stick with it.
|
||||
*/
|
||||
source = g_main_context_find_source_by_id(context, io_tag);
|
||||
/*
|
||||
* Nothing can race with adding the IO watch, aka, concurrent removal
|
||||
* is not possible when we have the lock. So it must be present.
|
||||
*/
|
||||
assert(source);
|
||||
|
||||
migration_incoming_early_channel_insert(mis, ioc, source);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,35 +508,60 @@ void migration_channel_process_incoming(QIOChannel *ioc)
|
||||
Error *local_err = NULL;
|
||||
MigChannelType ch;
|
||||
|
||||
trace_migration_set_incoming_channel(
|
||||
trace_migration_incoming_channel_process(
|
||||
ioc, object_get_typename(OBJECT(ioc)));
|
||||
|
||||
if (migrate_channel_requires_tls_upgrade(ioc)) {
|
||||
migration_tls_channel_process_incoming(ioc, &local_err);
|
||||
} else {
|
||||
migration_ioc_register_yank(ioc);
|
||||
ch = migration_channel_identify(mis, ioc, &local_err);
|
||||
if (!ch) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (migration_incoming_setup(ioc, ch, &local_err)) {
|
||||
migration_start_incoming();
|
||||
if (migration_has_main_and_multifd_channels()) {
|
||||
/*
|
||||
* If all main+multifd channels are present already, this must
|
||||
* be the preempt channel.
|
||||
*
|
||||
* QEMU can't register an IO watch for it if there is only the
|
||||
* last preempt channel left, because it means the IO watch
|
||||
* will never fire and nobody will pick it up: we rely on the
|
||||
* one before the last one to pick both.
|
||||
*
|
||||
* See comment in migration_incoming_channel_readable() on
|
||||
* the migration_incoming_detect_preempt_channel() call.
|
||||
*/
|
||||
migration_incoming_channel_preempt_setup(ioc);
|
||||
} else {
|
||||
if (qio_channel_is_peekable(ioc)) {
|
||||
/*
|
||||
* Register an IO watch for the peekable channel, deciding
|
||||
* the type of channel later by peeking at it whenever
|
||||
* possible. migration_incoming_channel_install() will be
|
||||
* postponed.
|
||||
*/
|
||||
migration_incoming_channel_watch(mis, ioc);
|
||||
} else {
|
||||
/*
|
||||
* Non-peekable channels (file, TLS, etc.), cannot register
|
||||
* IO watch because (1) there's nothing to peek, (2) after
|
||||
* registering IO watch, QEMU will lose the real ordering
|
||||
* it gets from accept(), which is still so far the only
|
||||
* source of truth to identify a channel in this case.
|
||||
*/
|
||||
ch = migration_channel_identify(mis, ioc, &local_err);
|
||||
if (ch) {
|
||||
migration_incoming_channel_install(mis, ioc, ch,
|
||||
&local_err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
out:
|
||||
|
||||
if (local_err) {
|
||||
error_report_err(local_err);
|
||||
migrate_set_state(&mis->state, mis->state, MIGRATION_STATUS_FAILED);
|
||||
if (mis->exit_on_error) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
migration_incoming_error_propagate(mis, local_err);
|
||||
}
|
||||
}
|
||||
|
||||
void migration_channel_connect_outgoing(MigrationState *s, QIOChannel *ioc)
|
||||
{
|
||||
trace_migration_set_outgoing_channel(ioc, object_get_typename(OBJECT(ioc)));
|
||||
trace_migration_outgoing_channel_set(ioc, object_get_typename(OBJECT(ioc)));
|
||||
|
||||
if (migrate_channel_requires_tls_upgrade(ioc)) {
|
||||
Error *local_err = NULL;
|
||||
|
||||
+5
-1
@@ -24,7 +24,8 @@ typedef enum {
|
||||
CH_NONE,
|
||||
CH_MAIN,
|
||||
CH_MULTIFD,
|
||||
CH_POSTCOPY
|
||||
CH_POSTCOPY,
|
||||
CH_NUM,
|
||||
} MigChannelType;
|
||||
|
||||
void migration_channel_process_incoming(QIOChannel *ioc);
|
||||
@@ -48,4 +49,7 @@ bool migration_channel_parse_input(const char *uri,
|
||||
MigrationChannel **main_channelp,
|
||||
MigrationChannel **cpr_channelp,
|
||||
Error **errp);
|
||||
|
||||
void migration_incoming_free_early_channels(MigrationIncomingState *mis);
|
||||
|
||||
#endif
|
||||
+51
-16
@@ -334,6 +334,10 @@ void migration_object_init(void)
|
||||
current_incoming->page_requested = g_tree_new(page_request_addr_cmp);
|
||||
|
||||
current_incoming->exit_on_error = INMIGRATE_DEFAULT_EXIT_ON_ERROR;
|
||||
/* zero_terminated=false, clear_=true (NOTE, "clear_" is not a typo) */
|
||||
current_incoming->channels_early.channels =
|
||||
g_array_new(FALSE, TRUE, sizeof(MigEarlyIncomingChannel));
|
||||
qemu_mutex_init(¤t_incoming->channels_early.mutex);
|
||||
|
||||
migration_object_check(current_migration, &error_fatal);
|
||||
|
||||
@@ -447,6 +451,24 @@ void migration_incoming_state_destroy(void)
|
||||
MigrationIncomingState *mis = migration_incoming_get_current();
|
||||
PostcopyState ps = postcopy_state_get();
|
||||
|
||||
/* Cleanup listener to make sure no further accept() for sockets */
|
||||
migration_incoming_transport_cleanup(mis);
|
||||
|
||||
/*
|
||||
* It's safer to free channel watches earlier than most of the rest, in
|
||||
* case the IO watches could fire in the monitor iothread concurrently
|
||||
* against this function.
|
||||
*
|
||||
* Above migration_incoming_transport_cleanup() should have disarmed
|
||||
* anything that we could accept() new sockets.
|
||||
*
|
||||
* Here return of migration_incoming_free_early_channels() makes sure
|
||||
* even if something already fired concurrently, it won't really do
|
||||
* anything but return - see migration_incoming_early_channel_remove()
|
||||
* and its return code for details.
|
||||
*/
|
||||
migration_incoming_free_early_channels(mis);
|
||||
|
||||
multifd_recv_cleanup();
|
||||
|
||||
if (ps != POSTCOPY_INCOMING_NONE) {
|
||||
@@ -491,7 +513,6 @@ void migration_incoming_state_destroy(void)
|
||||
mis->postcopy_remote_fds = NULL;
|
||||
}
|
||||
|
||||
migration_incoming_transport_cleanup(mis);
|
||||
qemu_event_reset(&mis->main_thread_load_event);
|
||||
|
||||
if (mis->page_requested) {
|
||||
@@ -843,10 +864,6 @@ out:
|
||||
migrate_incoming_unref_outgoing_state();
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns whether all the necessary channels to proceed with the
|
||||
* incoming migration have been established without error.
|
||||
*/
|
||||
bool migration_incoming_setup(QIOChannel *ioc, uint8_t channel, Error **errp)
|
||||
{
|
||||
MigrationIncomingState *mis = migration_incoming_get_current();
|
||||
@@ -862,6 +879,7 @@ bool migration_incoming_setup(QIOChannel *ioc, uint8_t channel, Error **errp)
|
||||
assert(!mis->from_src_file);
|
||||
mis->from_src_file = f;
|
||||
qemu_file_set_blocking(f, false, &error_abort);
|
||||
trace_migration_main_channel_received();
|
||||
break;
|
||||
|
||||
case CH_MULTIFD:
|
||||
@@ -874,13 +892,13 @@ bool migration_incoming_setup(QIOChannel *ioc, uint8_t channel, Error **errp)
|
||||
assert(!mis->postcopy_qemufile_dst);
|
||||
f = qemu_file_new_input(ioc);
|
||||
postcopy_preempt_new_channel(mis, f);
|
||||
return false;
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
return migration_has_main_and_multifd_channels();
|
||||
return true;
|
||||
}
|
||||
|
||||
void migration_outgoing_setup(QIOChannel *ioc)
|
||||
@@ -928,6 +946,8 @@ static bool postcopy_try_recover(void)
|
||||
|
||||
void migration_start_incoming(void)
|
||||
{
|
||||
trace_migration_start_incoming();
|
||||
|
||||
if (postcopy_try_recover()) {
|
||||
return;
|
||||
}
|
||||
@@ -3719,6 +3739,21 @@ static void *migration_thread(void *opaque)
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Only for old 7.1/7.2 machine types (preempt mode supported since
|
||||
* 7.1). Connect the preempt channel only after multifd channels,
|
||||
* because some QEMU versions (v10.1 to v11.1) will assume the order of
|
||||
* channels to be: (1) main, then (2) multifd channels, then (3)
|
||||
* preempt channel. IOW, (3) must be after (2).
|
||||
*
|
||||
* multifd_send_setup() makes sure all multifd channels be connected
|
||||
* first, then initiate preempt channel here guarantees the ordering to
|
||||
* those QEMU binaries.
|
||||
*/
|
||||
if (migrate_postcopy_preempt() && s->preempt_pre_7_2) {
|
||||
postcopy_preempt_setup(s);
|
||||
}
|
||||
|
||||
bql_lock();
|
||||
qemu_savevm_state_header(s->to_dst_file);
|
||||
bql_unlock();
|
||||
@@ -3999,16 +4034,16 @@ void migration_start_outgoing(MigrationState *s)
|
||||
open_return_path_on_source(s);
|
||||
}
|
||||
|
||||
/*
|
||||
* This needs to be done before resuming a postcopy. Note: for newer
|
||||
* QEMUs we will delay the channel creation until postcopy_start(), to
|
||||
* avoid disorder of channel creations.
|
||||
*/
|
||||
if (migrate_postcopy_preempt() && s->preempt_pre_7_2) {
|
||||
postcopy_preempt_setup(s);
|
||||
}
|
||||
|
||||
if (resume) {
|
||||
/*
|
||||
* This needs to be done before resuming a postcopy. Note: for newer
|
||||
* QEMUs we will delay the channel creation until postcopy_start(), to
|
||||
* avoid disorder of channel creations.
|
||||
*/
|
||||
if (migrate_postcopy_preempt() && s->preempt_pre_7_2) {
|
||||
postcopy_preempt_setup(s);
|
||||
}
|
||||
|
||||
/* Wakeup the main migration thread to do the recovery */
|
||||
migrate_set_state(&s->state, MIGRATION_STATUS_POSTCOPY_RECOVER_SETUP,
|
||||
MIGRATION_STATUS_POSTCOPY_RECOVER);
|
||||
|
||||
+36
-1
@@ -42,7 +42,7 @@
|
||||
#define MIGRATION_THREAD_DST_FAULT "mig/dst/fault"
|
||||
#define MIGRATION_THREAD_DST_LISTEN "mig/dst/listen"
|
||||
#define MIGRATION_THREAD_DST_PREEMPT "mig/dst/preempt"
|
||||
#define MIGRATION_THREAD_DST_SNAPSHOT_LOAD "mig/dst/snapshot_load"
|
||||
#define MIGRATION_THREAD_DST_SNAPSHOT_LOAD "mig/dst/snapld"
|
||||
|
||||
struct PostcopyBlocktimeContext;
|
||||
typedef struct ThreadPool ThreadPool;
|
||||
@@ -90,6 +90,28 @@ typedef enum {
|
||||
PREEMPT_THREAD_QUIT,
|
||||
} PreemptThreadStatus;
|
||||
|
||||
typedef struct {
|
||||
/*
|
||||
* The GSource we have allocated to track G_IO_IN events for the
|
||||
* channel. Note: it may not be attached to the default main gcontext,
|
||||
* for example, when in case of io watch created during an OOB
|
||||
* migrate-recover command.
|
||||
*/
|
||||
GSource *source;
|
||||
/* The channel we will identify later after getting some buffers to read */
|
||||
QIOChannel *ioc;
|
||||
} MigEarlyIncomingChannel;
|
||||
|
||||
typedef struct {
|
||||
GArray *channels;
|
||||
/*
|
||||
* In most cases, channels are only operated with BQl, but since we
|
||||
* have OOB command support, don't assume it, just use a standalone
|
||||
* mutex to protect any access to the channels array.
|
||||
*/
|
||||
QemuMutex mutex;
|
||||
} MigEarlyIncomingChannels;
|
||||
|
||||
/* State for the incoming migration */
|
||||
struct MigrationIncomingState {
|
||||
QEMUFile *from_src_file;
|
||||
@@ -255,6 +277,19 @@ struct MigrationIncomingState {
|
||||
|
||||
/* Do exit on incoming migration failure */
|
||||
bool exit_on_error;
|
||||
|
||||
/*
|
||||
* Maintains all channels only at early stage. After incoming
|
||||
* migration started, this should be an empty array and no use anymore.
|
||||
*
|
||||
* TODO: we logically only need this to make new QEMU binaries work for
|
||||
* old machines who have @preempt_pre_7_2 set on the source, but it's
|
||||
* also good to have this early stage anyway, making sure when peek the
|
||||
* channel there will be something in the channel. Ideally, we should
|
||||
* manage all migration channels in the future with proper headers,
|
||||
* then we can drop this.
|
||||
*/
|
||||
MigEarlyIncomingChannels channels_early;
|
||||
};
|
||||
|
||||
MigrationIncomingState *migration_incoming_get_current(void);
|
||||
|
||||
+18
-7
@@ -139,21 +139,32 @@ socket_incoming_migration_end(void *opaque)
|
||||
object_unref(OBJECT(listener));
|
||||
}
|
||||
|
||||
static int socket_get_max_channels(void)
|
||||
{
|
||||
/* The main channel is always wanted */
|
||||
int num = 1;
|
||||
|
||||
if (migrate_multifd()) {
|
||||
num += migrate_multifd_channels();
|
||||
}
|
||||
|
||||
if (migrate_postcopy_preempt()) {
|
||||
/* The preempt channel */
|
||||
num += 1;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
void socket_connect_incoming(SocketAddress *saddr, Error **errp)
|
||||
{
|
||||
QIONetListener *listener = qio_net_listener_new();
|
||||
MigrationIncomingState *mis = migration_incoming_get_current();
|
||||
size_t i;
|
||||
int num = 1;
|
||||
int num = socket_get_max_channels();
|
||||
|
||||
qio_net_listener_set_name(listener, "migration-socket-listener");
|
||||
|
||||
if (migrate_multifd()) {
|
||||
num = migrate_multifd_channels();
|
||||
} else if (migrate_postcopy_preempt()) {
|
||||
num = RAM_CHANNEL_MAX;
|
||||
}
|
||||
|
||||
if (qio_net_listener_open_sync(listener, saddr, num, errp) < 0) {
|
||||
object_unref(OBJECT(listener));
|
||||
return;
|
||||
|
||||
@@ -200,13 +200,17 @@ postcopy_preempt_enabled(bool value) "%d"
|
||||
migration_precopy_complete(void) ""
|
||||
migration_call_notifiers(int type) "type=%d"
|
||||
migration_request_switchover_ack_legacy(const char *requester, unsigned int switchover_ack_pending_num_legacy) "Requester %s, switchover_ack_pending_num_legacy %u"
|
||||
migration_main_channel_received(void) ""
|
||||
migration_start_incoming(void) ""
|
||||
|
||||
# migration-stats
|
||||
migration_transferred_bytes(uint64_t qemu_file, uint64_t multifd, uint64_t rdma) "qemu_file %" PRIu64 " multifd %" PRIu64 " RDMA %" PRIu64
|
||||
|
||||
# channel.c
|
||||
migration_set_incoming_channel(void *ioc, const char *ioctype) "ioc=%p ioctype=%s"
|
||||
migration_set_outgoing_channel(void *ioc, const char *ioctype) "ioc=%p ioctype=%s"
|
||||
migration_outgoing_channel_set(void *ioc, const char *ioctype) "ioc=%p ioctype=%s"
|
||||
migration_incoming_channel_process(void *ioc, const char *ioctype) "ioc=%p ioctype=%s"
|
||||
migration_incoming_channel_set(void *ioc, const char *ioctype, const char *type) "ioc=%p ioctype=%s type=%s"
|
||||
migration_incoming_channel_watch(void *ioc, const char *ioctype) "ioc=%p ioctype=%s"
|
||||
|
||||
# global_state.c
|
||||
migrate_state_too_big(void) ""
|
||||
|
||||
@@ -89,6 +89,15 @@ static void test_multifd_postcopy_preempt(char *name, MigrateCommon *args)
|
||||
test_postcopy_common(args);
|
||||
}
|
||||
|
||||
static void test_multifd_postcopy_preempt_recovery(char *name,
|
||||
MigrateCommon *args)
|
||||
{
|
||||
args->start.caps[MIGRATION_CAPABILITY_MULTIFD] = true;
|
||||
args->start.caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT] = true;
|
||||
|
||||
test_postcopy_recovery_common(args, POSTCOPY_FAIL_NONE);
|
||||
}
|
||||
|
||||
void migration_test_add_postcopy(MigrationTestEnv *env)
|
||||
{
|
||||
migration_test_add_postcopy_smoke(env);
|
||||
@@ -113,6 +122,8 @@ void migration_test_add_postcopy(MigrationTestEnv *env)
|
||||
test_multifd_postcopy);
|
||||
migration_test_add("/migration/multifd+postcopy/preempt/plain",
|
||||
test_multifd_postcopy_preempt);
|
||||
migration_test_add("/migration/multifd+postcopy/preempt/recovery/plain",
|
||||
test_multifd_postcopy_preempt_recovery);
|
||||
if (env->is_x86) {
|
||||
migration_test_add("/migration/postcopy/suspend",
|
||||
test_postcopy_suspend);
|
||||
|
||||
Reference in new issue
Block a user