mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
migration/multifd: Device state transfer support - send side
A new function multifd_queue_device_state() is provided for device to queue its state for transmission via a multifd channel. Reviewed-by: Peter Xu <peterx@redhat.com> Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com> Link: https://lore.kernel.org/qemu-devel/ebd55768d3e5fecb5eb3f197bad9c0c07e5bc084.1741124640.git.maciej.szmigiero@oracle.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
parent
7ecfab1ddd
commit
0525b91a0b
6 changed files with 197 additions and 16 deletions
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/iov.h"
|
||||
#include "qemu/rcu.h"
|
||||
#include "exec/target_page.h"
|
||||
#include "system/system.h"
|
||||
|
@ -19,6 +20,7 @@
|
|||
#include "qemu/error-report.h"
|
||||
#include "qapi/error.h"
|
||||
#include "file.h"
|
||||
#include "migration/misc.h"
|
||||
#include "migration.h"
|
||||
#include "migration-stats.h"
|
||||
#include "savevm.h"
|
||||
|
@ -111,7 +113,9 @@ MultiFDSendData *multifd_send_data_alloc(void)
|
|||
* added to the union in the future are larger than
|
||||
* (MultiFDPages_t + flex array).
|
||||
*/
|
||||
max_payload_size = MAX(multifd_ram_payload_size(), sizeof(MultiFDPayload));
|
||||
max_payload_size = MAX(multifd_ram_payload_size(),
|
||||
multifd_device_state_payload_size());
|
||||
max_payload_size = MAX(max_payload_size, sizeof(MultiFDPayload));
|
||||
|
||||
/*
|
||||
* Account for any holes the compiler might insert. We can't pack
|
||||
|
@ -130,6 +134,9 @@ void multifd_send_data_clear(MultiFDSendData *data)
|
|||
}
|
||||
|
||||
switch (data->type) {
|
||||
case MULTIFD_PAYLOAD_DEVICE_STATE:
|
||||
multifd_send_data_clear_device_state(&data->u.device_state);
|
||||
break;
|
||||
default:
|
||||
/* Nothing to do */
|
||||
break;
|
||||
|
@ -232,6 +239,7 @@ static int multifd_recv_initial_packet(QIOChannel *c, Error **errp)
|
|||
return msg.id;
|
||||
}
|
||||
|
||||
/* Fills a RAM multifd packet */
|
||||
void multifd_send_fill_packet(MultiFDSendParams *p)
|
||||
{
|
||||
MultiFDPacket_t *packet = p->packet;
|
||||
|
@ -524,6 +532,7 @@ static bool multifd_send_cleanup_channel(MultiFDSendParams *p, Error **errp)
|
|||
p->name = NULL;
|
||||
g_clear_pointer(&p->data, multifd_send_data_free);
|
||||
p->packet_len = 0;
|
||||
g_clear_pointer(&p->packet_device_state, g_free);
|
||||
g_free(p->packet);
|
||||
p->packet = NULL;
|
||||
multifd_send_state->ops->send_cleanup(p, errp);
|
||||
|
@ -536,6 +545,7 @@ static void multifd_send_cleanup_state(void)
|
|||
{
|
||||
file_cleanup_outgoing_migration();
|
||||
socket_cleanup_outgoing_migration();
|
||||
multifd_device_state_send_cleanup();
|
||||
qemu_sem_destroy(&multifd_send_state->channels_created);
|
||||
qemu_sem_destroy(&multifd_send_state->channels_ready);
|
||||
qemu_mutex_destroy(&multifd_send_state->multifd_send_mutex);
|
||||
|
@ -694,16 +704,32 @@ static void *multifd_send_thread(void *opaque)
|
|||
* qatomic_store_release() in multifd_send().
|
||||
*/
|
||||
if (qatomic_load_acquire(&p->pending_job)) {
|
||||
bool is_device_state = multifd_payload_device_state(p->data);
|
||||
size_t total_size;
|
||||
|
||||
p->flags = 0;
|
||||
p->iovs_num = 0;
|
||||
assert(!multifd_payload_empty(p->data));
|
||||
|
||||
ret = multifd_send_state->ops->send_prepare(p, &local_err);
|
||||
if (ret != 0) {
|
||||
break;
|
||||
if (is_device_state) {
|
||||
multifd_device_state_send_prepare(p);
|
||||
} else {
|
||||
ret = multifd_send_state->ops->send_prepare(p, &local_err);
|
||||
if (ret != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The packet header in the zerocopy RAM case is accounted for
|
||||
* in multifd_nocomp_send_prepare() - where it is actually
|
||||
* being sent.
|
||||
*/
|
||||
total_size = iov_size(p->iov, p->iovs_num);
|
||||
|
||||
if (migrate_mapped_ram()) {
|
||||
assert(!is_device_state);
|
||||
|
||||
ret = file_write_ramblock_iov(p->c, p->iov, p->iovs_num,
|
||||
&p->data->u.ram, &local_err);
|
||||
} else {
|
||||
|
@ -716,8 +742,7 @@ static void *multifd_send_thread(void *opaque)
|
|||
break;
|
||||
}
|
||||
|
||||
stat64_add(&mig_stats.multifd_bytes,
|
||||
(uint64_t)p->next_packet_size + p->packet_len);
|
||||
stat64_add(&mig_stats.multifd_bytes, total_size);
|
||||
|
||||
p->next_packet_size = 0;
|
||||
multifd_send_data_clear(p->data);
|
||||
|
@ -938,6 +963,9 @@ bool multifd_send_setup(void)
|
|||
p->packet_len = sizeof(MultiFDPacket_t)
|
||||
+ sizeof(uint64_t) * page_count;
|
||||
p->packet = g_malloc0(p->packet_len);
|
||||
p->packet_device_state = g_malloc0(sizeof(*p->packet_device_state));
|
||||
p->packet_device_state->hdr.magic = cpu_to_be32(MULTIFD_MAGIC);
|
||||
p->packet_device_state->hdr.version = cpu_to_be32(MULTIFD_VERSION);
|
||||
}
|
||||
p->name = g_strdup_printf(MIGRATION_THREAD_SRC_MULTIFD, i);
|
||||
p->write_flags = 0;
|
||||
|
@ -973,6 +1001,8 @@ bool multifd_send_setup(void)
|
|||
assert(p->iov);
|
||||
}
|
||||
|
||||
multifd_device_state_send_setup();
|
||||
|
||||
return true;
|
||||
|
||||
err:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue