vfio/migration: Multifd device state transfer support - config loading support

Load device config received via multifd using the existing machinery
behind vfio_load_device_config_state().

Also, make sure to process the relevant main migration channel flags.

Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Link: https://lore.kernel.org/qemu-devel/5dbd3f3703ec1097da2cf82a7262233452146fee.1741124640.git.maciej.szmigiero@oracle.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
Maciej S. Szmigiero 2025-03-04 23:03:56 +01:00 committed by Cédric Le Goater
parent fda70ed83d
commit b659c07c53
3 changed files with 57 additions and 3 deletions

View file

@ -17,6 +17,7 @@
#include "qemu/lockable.h"
#include "qemu/main-loop.h"
#include "qemu/thread.h"
#include "io/channel-buffer.h"
#include "migration/qemu-file.h"
#include "migration-multifd.h"
#include "trace.h"
@ -193,8 +194,52 @@ bool vfio_multifd_load_state_buffer(void *opaque, char *data, size_t data_size,
static bool vfio_load_bufs_thread_load_config(VFIODevice *vbasedev,
Error **errp)
{
error_setg(errp, "not yet there");
return false;
VFIOMigration *migration = vbasedev->migration;
VFIOMultifd *multifd = migration->multifd;
VFIOStateBuffer *lb;
g_autoptr(QIOChannelBuffer) bioc = NULL;
g_autoptr(QEMUFile) f_out = NULL, f_in = NULL;
uint64_t mig_header;
int ret;
assert(multifd->load_buf_idx == multifd->load_buf_idx_last);
lb = vfio_state_buffers_at(&multifd->load_bufs, multifd->load_buf_idx);
assert(lb->is_present);
bioc = qio_channel_buffer_new(lb->len);
qio_channel_set_name(QIO_CHANNEL(bioc), "vfio-device-config-load");
f_out = qemu_file_new_output(QIO_CHANNEL(bioc));
qemu_put_buffer(f_out, (uint8_t *)lb->data, lb->len);
ret = qemu_fflush(f_out);
if (ret) {
error_setg(errp, "%s: load config state flush failed: %d",
vbasedev->name, ret);
return false;
}
qio_channel_io_seek(QIO_CHANNEL(bioc), 0, 0, NULL);
f_in = qemu_file_new_input(QIO_CHANNEL(bioc));
mig_header = qemu_get_be64(f_in);
if (mig_header != VFIO_MIG_FLAG_DEV_CONFIG_STATE) {
error_setg(errp, "%s: expected FLAG_DEV_CONFIG_STATE but got %" PRIx64,
vbasedev->name, mig_header);
return false;
}
bql_lock();
ret = vfio_load_device_config_state(f_in, vbasedev);
bql_unlock();
if (ret < 0) {
error_setg(errp, "%s: vfio_load_device_config_state() failed: %d",
vbasedev->name, ret);
return false;
}
return true;
}
static VFIOStateBuffer *vfio_load_state_buffer_get(VFIOMultifd *multifd)