[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 13/13] vfio/migration: make the region and plugin member of s
From: |
Lei Rao |
Subject: |
[RFC PATCH 13/13] vfio/migration: make the region and plugin member of struct VFIOMigration to be a union |
Date: |
Tue, 24 May 2022 14:18:48 +0800 |
Since a VFIO device either uses In-Band or Out-of-Band live migration. So, the
region and plugin in VFIOMigration can be put into a union.
Signed-off-by: Lei Rao <lei.rao@intel.com>
Reviewed-by: Eddie Dong <eddie.dong@intel.com>
---
hw/vfio/migration-local.c | 33 ++++++++++++++++++---------------
include/hw/vfio/vfio-common.h | 6 ++++--
2 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/hw/vfio/migration-local.c b/hw/vfio/migration-local.c
index 46c8baed50..13d1abee5a 100644
--- a/hw/vfio/migration-local.c
+++ b/hw/vfio/migration-local.c
@@ -98,7 +98,7 @@ static int vfio_migration_set_state_local(VFIODevice
*vbasedev, uint32_t mask,
uint32_t value)
{
VFIOMigration *migration = vbasedev->migration;
- VFIORegion *region = &migration->region;
+ VFIORegion *region = migration->region;
off_t dev_state_off = region->fd_offset +
VFIO_MIG_STRUCT_OFFSET(device_state);
uint32_t device_state;
@@ -184,7 +184,7 @@ static int vfio_migration_save_buffer_local(QEMUFile *f,
VFIODevice *vbasedev,
uint64_t *size)
{
VFIOMigration *migration = vbasedev->migration;
- VFIORegion *region = &migration->region;
+ VFIORegion *region = migration->region;
uint64_t data_offset = 0, data_size = 0, sz;
int ret;
@@ -250,7 +250,7 @@ static int vfio_migration_save_buffer_local(QEMUFile *f,
VFIODevice *vbasedev,
static int vfio_migration_load_buffer_local(QEMUFile *f, VFIODevice *vbasedev,
uint64_t data_size)
{
- VFIORegion *region = &vbasedev->migration->region;
+ VFIORegion *region = vbasedev->migration->region;
uint64_t data_offset = 0, size, report_size;
int ret;
@@ -322,7 +322,7 @@ static int vfio_migration_load_buffer_local(QEMUFile *f,
VFIODevice *vbasedev,
static int vfio_migration_update_pending_local(VFIODevice *vbasedev)
{
VFIOMigration *migration = vbasedev->migration;
- VFIORegion *region = &migration->region;
+ VFIORegion *region = migration->region;
uint64_t pending_bytes = 0;
int ret;
@@ -342,8 +342,8 @@ static void vfio_migration_cleanup_local(VFIODevice
*vbasedev)
{
VFIOMigration *migration = vbasedev->migration;
- if (migration->region.mmaps) {
- vfio_region_unmap(&migration->region);
+ if (migration->region->mmaps) {
+ vfio_region_unmap(migration->region);
}
}
@@ -352,14 +352,14 @@ static int vfio_migration_save_setup_local(VFIODevice
*vbasedev)
VFIOMigration *migration = vbasedev->migration;
int ret = -1;
- if (migration->region.mmaps) {
+ if (migration->region->mmaps) {
/*
* Calling vfio_region_mmap() from migration thread. Memory API called
* from this function require locking the iothread when called from
* outside the main loop thread.
*/
qemu_mutex_lock_iothread();
- ret = vfio_region_mmap(&migration->region);
+ ret = vfio_region_mmap(migration->region);
qemu_mutex_unlock_iothread();
if (ret) {
error_report("%s: Failed to mmap VFIO migration region: %s",
@@ -375,11 +375,11 @@ static int vfio_migration_load_setup_local(VFIODevice
*vbasedev)
VFIOMigration *migration = vbasedev->migration;
int ret = -1;
- if (migration->region.mmaps) {
- ret = vfio_region_mmap(&migration->region);
+ if (migration->region->mmaps) {
+ ret = vfio_region_mmap(migration->region);
if (ret) {
error_report("%s: Failed to mmap VFIO migration region %d: %s",
- vbasedev->name, migration->region.nr,
+ vbasedev->name, migration->region->nr,
strerror(-ret));
error_report("%s: Falling back to slow path", vbasedev->name);
}
@@ -391,8 +391,10 @@ static void vfio_migration_exit_local(VFIODevice *vbasedev)
{
VFIOMigration *migration = vbasedev->migration;
- vfio_region_exit(&migration->region);
- vfio_region_finalize(&migration->region);
+ vfio_region_exit(migration->region);
+ vfio_region_finalize(migration->region);
+ g_free(migration->region);
+ migration->region = NULL;
}
static VFIOMigrationOps vfio_local_method = {
@@ -426,7 +428,8 @@ int vfio_migration_probe_local(VFIODevice *vbasedev)
return -EINVAL;
}
- ret = vfio_region_setup(obj, vbasedev, &vbasedev->migration->region,
+ migration->region = g_new0(VFIORegion, 1);
+ ret = vfio_region_setup(obj, vbasedev, vbasedev->migration->region,
info->index, "migration");
if (ret) {
error_report("%s: Failed to setup VFIO migration region %d: %s",
@@ -434,7 +437,7 @@ int vfio_migration_probe_local(VFIODevice *vbasedev)
goto err;
}
- if (!vbasedev->migration->region.size) {
+ if (!vbasedev->migration->region->size) {
error_report("%s: Invalid zero-sized VFIO migration region %d",
vbasedev->name, info->index);
ret = -EINVAL;
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 2ea016a894..bded2b4908 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -78,9 +78,11 @@ typedef struct VFIOMigrationOps VFIOMigrationOps;
typedef struct VFIOMigration {
struct VFIODevice *vbasedev;
VMChangeStateEntry *vm_state;
- VFIORegion region;
VFIOMigrationOps *ops;
- VFIOMigrationPlugin *plugin;
+ union {
+ VFIORegion *region;
+ VFIOMigrationPlugin *plugin;
+ };
uint32_t device_state;
int vm_running;
Notifier migration_state;
--
2.32.0
- [RFC PATCH 04/13] vfio/migration: Separated functions that relate to the In-Band approach, (continued)
- [RFC PATCH 04/13] vfio/migration: Separated functions that relate to the In-Band approach, Lei Rao, 2022/05/24
- [RFC PATCH 01/13] vfio/migration: put together checks of migration initialization conditions, Lei Rao, 2022/05/24
- [RFC PATCH 05/13] vfio/migration: rename functions that relate to the In-Band approach, Lei Rao, 2022/05/24
- [RFC PATCH 06/13] vfio/migration: introduce VFIOMigrationOps layer in VFIO live migration framework, Lei Rao, 2022/05/24
- [RFC PATCH 07/13] vfio/migration: move the statistics of bytes_transferred to generic VFIO migration layer, Lei Rao, 2022/05/24
- [RFC PATCH 08/13] vfio/migration: split migration handler registering from vfio_migration_init, Lei Rao, 2022/05/24
- [RFC PATCH 09/13] vfio/migration: move the functions of In-Band approach to a new file, Lei Rao, 2022/05/24
- [RFC PATCH 12/13] vfio/migration: add some trace-events for vfio migration plugin, Lei Rao, 2022/05/24
- [RFC PATCH 11/13] vfio/migration: add a plugin layer to support out-of-band live migration, Lei Rao, 2022/05/24
- [RFC PATCH 10/13] vfio/pci: introduce command-line parameters to specify migration method, Lei Rao, 2022/05/24
- [RFC PATCH 13/13] vfio/migration: make the region and plugin member of struct VFIOMigration to be a union,
Lei Rao <=
- Re: [RFC PATCH 00/13] Add a plugin to support out-of-band live migration for VFIO pass-through device, Alex Williamson, 2022/05/26