aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2023-02-16 13:09:51 +0000
committerPeter Maydell <peter.maydell@linaro.org>2023-02-16 13:09:51 +0000
commit6dffbe36af79e26a4d23f94a9a1c1201de99c261 (patch)
treefaf6a88f7db02294f91c1aa717cf35cce2e06218
parent003ba52a8b327180e284630b289c6ece5a3e08b9 (diff)
parent24beea4efe6e6b65fd6248ede936cd3278b2bf8a (diff)
Merge tag 'migration-20230215-pull-request' of https://gitlab.com/juan.quintela/qemu into staging
Migration Pull request This pull request contains: * Add qemu_file_get_to_fd() a.k.a. make vfio happy(Avihai) * migration/block is now DPRINTF() free zone (Philippe) * remove res_compat and improve docs (me) Please apply. # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCAAdFiEEGJn/jt6/WMzuA0uC9IfvGFhy1yMFAmPtOxgACgkQ9IfvGFhy # 1yM+8w/+Nrm40o8B+0M1X/2O8SPaXE0Oxll5qk5AgfC+2Ef/n5661ZzOM1xQcqzv # CN3bj3g7dKN05nGhqW5ZFrEZliJCGksx2FBKMq9H6R5YBSMo/+GHT4ugPqsujudl # RBafIHzp4h4nTh/4aJ4Kr2Vn/bVQzGVyv5c6yUdUhKhE1QfCLu9AMC5vN1hfWxBz # IQBvMkLNXXhWOTdkVAElVlFOM6GZzWb1UYDkBaQHjjw/dN0MdCFFj7tIaBIyU2Eb # KyQCoYeJjjWrljsrfzfCucrW+mbVGmCe1TiCEnaAmmgzOI0NwARmUcdYdCyZ4Nhh # flNjpqQB6H4/ekI0mus2YPMPEkHyVgBMuF8fHV3YDwxcQ25U39RLymVfAoKPNg88 # S1EcQ9h2QVqdML7bR9vTmPOZKk5vD25H7B8LQIJpT8PHVg3ZzzRaOIR8UHmmFXx/ # PSL1rGfPcCLJ3P1XlVjwBApebMHyid9c+Sohda9L9HPer0jlB+mGQUEV8J67DJiT # xlffFgJmYu3+AJu9BoqrG0AUW6zA78jSs4Tbp78qbIVA4uzGkWI9JvROMfG9Qcc7 # vruuL0sUXHVUhzW2F+0M+b1rVhaHHQYvFo3mIqdHrd5mGicdgh1HUbaJuEJxeJnh # oFt6SZbIx3N/pllcvMsxQa+rFI/po+FEkRwIF02SzTRWYHB0qos= # =KpKO # -----END PGP SIGNATURE----- # gpg: Signature made Wed 15 Feb 2023 20:05:44 GMT # gpg: using RSA key 1899FF8EDEBF58CCEE034B82F487EF185872D723 # gpg: Good signature from "Juan Quintela <quintela@redhat.com>" [full] # gpg: aka "Juan Quintela <quintela@trasno.org>" [full] # Primary key fingerprint: 1899 FF8E DEBF 58CC EE03 4B82 F487 EF18 5872 D723 * tag 'migration-20230215-pull-request' of https://gitlab.com/juan.quintela/qemu: migration: Rename res_{postcopy,precopy}_only migration: Remove unused res_compatible migration: In case of postcopy, the memory ends in res_postcopy_only migration/block: Convert remaining DPRINTF() debug macro to trace events migration/qemu-file: Add qemu_file_get_to_fd() Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--hw/s390x/s390-stattrib.c8
-rw-r--r--hw/vfio/migration.c11
-rw-r--r--hw/vfio/trace-events2
-rw-r--r--include/migration/register.h30
-rw-r--r--migration/block-dirty-bitmap.c7
-rw-r--r--migration/block.c20
-rw-r--r--migration/migration.c20
-rw-r--r--migration/qemu-file.c34
-rw-r--r--migration/qemu-file.h1
-rw-r--r--migration/ram.c20
-rw-r--r--migration/savevm.c28
-rw-r--r--migration/savevm.h10
-rw-r--r--migration/trace-events5
13 files changed, 99 insertions, 97 deletions
diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
index 3e32002eab..aed919ad7d 100644
--- a/hw/s390x/s390-stattrib.c
+++ b/hw/s390x/s390-stattrib.c
@@ -182,17 +182,15 @@ static int cmma_save_setup(QEMUFile *f, void *opaque)
return 0;
}
-static void cmma_state_pending(void *opaque,
- uint64_t *res_precopy_only,
- uint64_t *res_compatible,
- uint64_t *res_postcopy_only)
+static void cmma_state_pending(void *opaque, uint64_t *must_precopy,
+ uint64_t *can_postcopy)
{
S390StAttribState *sas = S390_STATTRIB(opaque);
S390StAttribClass *sac = S390_STATTRIB_GET_CLASS(sas);
long long res = sac->get_dirtycount(sas);
if (res >= 0) {
- *res_precopy_only += res;
+ *must_precopy += res;
}
}
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index b3318f0f20..83d2d44080 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -456,10 +456,8 @@ static void vfio_save_cleanup(void *opaque)
trace_vfio_save_cleanup(vbasedev->name);
}
-static void vfio_state_pending(void *opaque,
- uint64_t *res_precopy_only,
- uint64_t *res_compatible,
- uint64_t *res_postcopy_only)
+static void vfio_state_pending(void *opaque, uint64_t *must_precopy,
+ uint64_t *can_postcopy)
{
VFIODevice *vbasedev = opaque;
VFIOMigration *migration = vbasedev->migration;
@@ -470,10 +468,9 @@ static void vfio_state_pending(void *opaque,
return;
}
- *res_precopy_only += migration->pending_bytes;
+ *must_precopy += migration->pending_bytes;
- trace_vfio_state_pending(vbasedev->name, *res_precopy_only,
- *res_postcopy_only, *res_compatible);
+ trace_vfio_state_pending(vbasedev->name, *must_precopy, *can_postcopy);
}
static int vfio_save_iterate(QEMUFile *f, void *opaque)
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index 52de1c84f8..90a8aecb37 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -157,7 +157,7 @@ vfio_save_cleanup(const char *name) " (%s)"
vfio_save_buffer(const char *name, uint64_t data_offset, uint64_t data_size, uint64_t pending) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64" pending 0x%"PRIx64
vfio_update_pending(const char *name, uint64_t pending) " (%s) pending 0x%"PRIx64
vfio_save_device_config_state(const char *name) " (%s)"
-vfio_state_pending(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compatible 0x%"PRIx64
+vfio_state_pending(const char *name, uint64_t precopy, uint64_t postcopy) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64
vfio_save_iterate(const char *name, int data_size) " (%s) data_size %d"
vfio_save_complete_precopy(const char *name) " (%s)"
vfio_load_device_config_state(const char *name) " (%s)"
diff --git a/include/migration/register.h b/include/migration/register.h
index b91a0cdbf8..a8dfd8fefd 100644
--- a/include/migration/register.h
+++ b/include/migration/register.h
@@ -47,25 +47,25 @@ typedef struct SaveVMHandlers {
/* This runs outside the iothread lock! */
int (*save_setup)(QEMUFile *f, void *opaque);
/* Note for save_live_pending:
- * - res_precopy_only is for data which must be migrated in precopy phase
- * or in stopped state, in other words - before target vm start
- * - res_compatible is for data which may be migrated in any phase
- * - res_postcopy_only is for data which must be migrated in postcopy phase
- * or in stopped state, in other words - after source vm stop
+ * must_precopy:
+ * - must be migrated in precopy or in stopped state
+ * - i.e. must be migrated before target start
*
- * Sum of res_postcopy_only, res_compatible and res_postcopy_only is the
- * whole amount of pending data.
+ * can_postcopy:
+ * - can migrate in postcopy or in stopped state
+ * - i.e. can migrate after target start
+ * - some can also be migrated during precopy (RAM)
+ * - some must be migrated after source stops (block-dirty-bitmap)
+ *
+ * Sum of can_postcopy and must_postcopy is the whole amount of
+ * pending data.
*/
/* This estimates the remaining data to transfer */
- void (*state_pending_estimate)(void *opaque,
- uint64_t *res_precopy_only,
- uint64_t *res_compatible,
- uint64_t *res_postcopy_only);
+ void (*state_pending_estimate)(void *opaque, uint64_t *must_precopy,
+ uint64_t *can_postcopy);
/* This calculate the exact remaining data to transfer */
- void (*state_pending_exact)(void *opaque,
- uint64_t *res_precopy_only,
- uint64_t *res_compatible,
- uint64_t *res_postcopy_only);
+ void (*state_pending_exact)(void *opaque, uint64_t *must_precopy,
+ uint64_t *can_postcopy);
LoadStateHandler *load_state;
int (*load_setup)(QEMUFile *f, void *opaque);
int (*load_cleanup)(void *opaque);
diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c
index 5a621419d3..fe73aa94b1 100644
--- a/migration/block-dirty-bitmap.c
+++ b/migration/block-dirty-bitmap.c
@@ -763,9 +763,8 @@ static int dirty_bitmap_save_complete(QEMUFile *f, void *opaque)
}
static void dirty_bitmap_state_pending(void *opaque,
- uint64_t *res_precopy_only,
- uint64_t *res_compatible,
- uint64_t *res_postcopy_only)
+ uint64_t *must_precopy,
+ uint64_t *can_postcopy)
{
DBMSaveState *s = &((DBMState *)opaque)->save;
SaveBitmapState *dbms;
@@ -785,7 +784,7 @@ static void dirty_bitmap_state_pending(void *opaque,
trace_dirty_bitmap_state_pending(pending);
- *res_postcopy_only += pending;
+ *can_postcopy += pending;
}
/* First occurrence of this bitmap. It should be created if doesn't exist */
diff --git a/migration/block.c b/migration/block.c
index 29f69025af..426a25bb19 100644
--- a/migration/block.c
+++ b/migration/block.c
@@ -42,16 +42,6 @@
#define MAX_IO_BUFFERS 512
#define MAX_PARALLEL_IO 16
-/* #define DEBUG_BLK_MIGRATION */
-
-#ifdef DEBUG_BLK_MIGRATION
-#define DPRINTF(fmt, ...) \
- do { printf("blk_migration: " fmt, ## __VA_ARGS__); } while (0)
-#else
-#define DPRINTF(fmt, ...) \
- do { } while (0)
-#endif
-
typedef struct BlkMigDevState {
/* Written during setup phase. Can be read without a lock. */
BlockBackend *blk;
@@ -502,7 +492,7 @@ static int blk_mig_save_bulked_block(QEMUFile *f)
block_mig_state.prev_progress = progress;
qemu_put_be64(f, (progress << BDRV_SECTOR_BITS)
| BLK_MIG_FLAG_PROGRESS);
- DPRINTF("Completed %d %%\r", progress);
+ trace_migration_block_progression(progress);
}
return ret;
@@ -863,10 +853,8 @@ static int block_save_complete(QEMUFile *f, void *opaque)
return 0;
}
-static void block_state_pending(void *opaque,
- uint64_t *res_precopy_only,
- uint64_t *res_compatible,
- uint64_t *res_postcopy_only)
+static void block_state_pending(void *opaque, uint64_t *must_precopy,
+ uint64_t *can_postcopy)
{
/* Estimate pending number of bytes to send */
uint64_t pending;
@@ -887,7 +875,7 @@ static void block_state_pending(void *opaque,
trace_migration_block_state_pending(pending);
/* We don't do postcopy */
- *res_precopy_only += pending;
+ *must_precopy += pending;
}
static int block_load(QEMUFile *f, void *opaque, int version_id)
diff --git a/migration/migration.c b/migration/migration.c
index 90fca70cb7..ae2025d9d8 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -3863,20 +3863,18 @@ typedef enum {
*/
static MigIterateState migration_iteration_run(MigrationState *s)
{
- uint64_t pend_pre, pend_compat, pend_post;
+ uint64_t must_precopy, can_postcopy;
bool in_postcopy = s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE;
- qemu_savevm_state_pending_estimate(&pend_pre, &pend_compat, &pend_post);
- uint64_t pending_size = pend_pre + pend_compat + pend_post;
+ qemu_savevm_state_pending_estimate(&must_precopy, &can_postcopy);
+ uint64_t pending_size = must_precopy + can_postcopy;
- trace_migrate_pending_estimate(pending_size,
- pend_pre, pend_compat, pend_post);
+ trace_migrate_pending_estimate(pending_size, must_precopy, can_postcopy);
- if (pend_pre + pend_compat <= s->threshold_size) {
- qemu_savevm_state_pending_exact(&pend_pre, &pend_compat, &pend_post);
- pending_size = pend_pre + pend_compat + pend_post;
- trace_migrate_pending_exact(pending_size,
- pend_pre, pend_compat, pend_post);
+ if (must_precopy <= s->threshold_size) {
+ qemu_savevm_state_pending_exact(&must_precopy, &can_postcopy);
+ pending_size = must_precopy + can_postcopy;
+ trace_migrate_pending_exact(pending_size, must_precopy, can_postcopy);
}
if (!pending_size || pending_size < s->threshold_size) {
@@ -3886,7 +3884,7 @@ static MigIterateState migration_iteration_run(MigrationState *s)
}
/* Still a significant amount to transfer */
- if (!in_postcopy && pend_pre <= s->threshold_size &&
+ if (!in_postcopy && must_precopy <= s->threshold_size &&
qatomic_read(&s->start_postcopy)) {
if (postcopy_start(s)) {
error_report("%s: postcopy failed to start", __func__);
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 2d5f74ffc2..102ab3b439 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -940,3 +940,37 @@ QIOChannel *qemu_file_get_ioc(QEMUFile *file)
{
return file->ioc;
}
+
+/*
+ * Read size bytes from QEMUFile f and write them to fd.
+ */
+int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size)
+{
+ while (size) {
+ size_t pending = f->buf_size - f->buf_index;
+ ssize_t rc;
+
+ if (!pending) {
+ rc = qemu_fill_buffer(f);
+ if (rc < 0) {
+ return rc;
+ }
+ if (rc == 0) {
+ return -EIO;
+ }
+ continue;
+ }
+
+ rc = write(fd, f->buf + f->buf_index, MIN(pending, size));
+ if (rc < 0) {
+ return -errno;
+ }
+ if (rc == 0) {
+ return -EIO;
+ }
+ f->buf_index += rc;
+ size -= rc;
+ }
+
+ return 0;
+}
diff --git a/migration/qemu-file.h b/migration/qemu-file.h
index fa13d04d78..9d0155a2a1 100644
--- a/migration/qemu-file.h
+++ b/migration/qemu-file.h
@@ -148,6 +148,7 @@ int qemu_file_shutdown(QEMUFile *f);
QEMUFile *qemu_file_get_return_path(QEMUFile *f);
void qemu_fflush(QEMUFile *f);
void qemu_file_set_blocking(QEMUFile *f, bool block);
+int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size);
void ram_control_before_iterate(QEMUFile *f, uint64_t flags);
void ram_control_after_iterate(QEMUFile *f, uint64_t flags);
diff --git a/migration/ram.c b/migration/ram.c
index 521912385d..96e8a19a58 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -3489,10 +3489,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
return 0;
}
-static void ram_state_pending_estimate(void *opaque,
- uint64_t *res_precopy_only,
- uint64_t *res_compatible,
- uint64_t *res_postcopy_only)
+static void ram_state_pending_estimate(void *opaque, uint64_t *must_precopy,
+ uint64_t *can_postcopy)
{
RAMState **temp = opaque;
RAMState *rs = *temp;
@@ -3501,16 +3499,14 @@ static void ram_state_pending_estimate(void *opaque,
if (migrate_postcopy_ram()) {
/* We can do postcopy, and all the data is postcopiable */
- *res_postcopy_only += remaining_size;
+ *can_postcopy += remaining_size;
} else {
- *res_precopy_only += remaining_size;
+ *must_precopy += remaining_size;
}
}
-static void ram_state_pending_exact(void *opaque,
- uint64_t *res_precopy_only,
- uint64_t *res_compatible,
- uint64_t *res_postcopy_only)
+static void ram_state_pending_exact(void *opaque, uint64_t *must_precopy,
+ uint64_t *can_postcopy)
{
RAMState **temp = opaque;
RAMState *rs = *temp;
@@ -3528,9 +3524,9 @@ static void ram_state_pending_exact(void *opaque,
if (migrate_postcopy_ram()) {
/* We can do postcopy, and all the data is postcopiable */
- *res_compatible += remaining_size;
+ *can_postcopy += remaining_size;
} else {
- *res_precopy_only += remaining_size;
+ *must_precopy += remaining_size;
}
}
diff --git a/migration/savevm.c b/migration/savevm.c
index b5e6962bb6..aa54a67fda 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1541,15 +1541,13 @@ flush:
* the result is split into the amount for units that can and
* for units that can't do postcopy.
*/
-void qemu_savevm_state_pending_estimate(uint64_t *res_precopy_only,
- uint64_t *res_compatible,
- uint64_t *res_postcopy_only)
+void qemu_savevm_state_pending_estimate(uint64_t *must_precopy,
+ uint64_t *can_postcopy)
{
SaveStateEntry *se;
- *res_precopy_only = 0;
- *res_compatible = 0;
- *res_postcopy_only = 0;
+ *must_precopy = 0;
+ *can_postcopy = 0;
QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
if (!se->ops || !se->ops->state_pending_estimate) {
@@ -1560,21 +1558,17 @@ void qemu_savevm_state_pending_estimate(uint64_t *res_precopy_only,
continue;
}
}
- se->ops->state_pending_estimate(se->opaque,
- res_precopy_only, res_compatible,
- res_postcopy_only);
+ se->ops->state_pending_estimate(se->opaque, must_precopy, can_postcopy);
}
}
-void qemu_savevm_state_pending_exact(uint64_t *res_precopy_only,
- uint64_t *res_compatible,
- uint64_t *res_postcopy_only)
+void qemu_savevm_state_pending_exact(uint64_t *must_precopy,
+ uint64_t *can_postcopy)
{
SaveStateEntry *se;
- *res_precopy_only = 0;
- *res_compatible = 0;
- *res_postcopy_only = 0;
+ *must_precopy = 0;
+ *can_postcopy = 0;
QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
if (!se->ops || !se->ops->state_pending_exact) {
@@ -1585,9 +1579,7 @@ void qemu_savevm_state_pending_exact(uint64_t *res_precopy_only,
continue;
}
}
- se->ops->state_pending_exact(se->opaque,
- res_precopy_only, res_compatible,
- res_postcopy_only);
+ se->ops->state_pending_exact(se->opaque, must_precopy, can_postcopy);
}
}
diff --git a/migration/savevm.h b/migration/savevm.h
index b1901e68d5..fb636735f0 100644
--- a/migration/savevm.h
+++ b/migration/savevm.h
@@ -40,12 +40,10 @@ void qemu_savevm_state_cleanup(void);
void qemu_savevm_state_complete_postcopy(QEMUFile *f);
int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only,
bool inactivate_disks);
-void qemu_savevm_state_pending_exact(uint64_t *res_precopy_only,
- uint64_t *res_compatible,
- uint64_t *res_postcopy_only);
-void qemu_savevm_state_pending_estimate(uint64_t *res_precopy_only,
- uint64_t *res_compatible,
- uint64_t *res_postcopy_only);
+void qemu_savevm_state_pending_exact(uint64_t *must_precopy,
+ uint64_t *can_postcopy);
+void qemu_savevm_state_pending_estimate(uint64_t *must_precopy,
+ uint64_t *can_postcopy);
void qemu_savevm_send_ping(QEMUFile *f, uint32_t value);
void qemu_savevm_send_open_return_path(QEMUFile *f);
int qemu_savevm_send_packaged(QEMUFile *f, const uint8_t *buf, size_t len);
diff --git a/migration/trace-events b/migration/trace-events
index 67b65a70ff..92161eeac5 100644
--- a/migration/trace-events
+++ b/migration/trace-events
@@ -150,8 +150,8 @@ migrate_fd_cleanup(void) ""
migrate_fd_error(const char *error_desc) "error=%s"
migrate_fd_cancel(void) ""
migrate_handle_rp_req_pages(const char *rbname, size_t start, size_t len) "in %s at 0x%zx len 0x%zx"
-migrate_pending_exact(uint64_t size, uint64_t pre, uint64_t compat, uint64_t post) "exact pending size %" PRIu64 " (pre = %" PRIu64 " compat=%" PRIu64 " post=%" PRIu64 ")"
-migrate_pending_estimate(uint64_t size, uint64_t pre, uint64_t compat, uint64_t post) "estimate pending size %" PRIu64 " (pre = %" PRIu64 " compat=%" PRIu64 " post=%" PRIu64 ")"
+migrate_pending_exact(uint64_t size, uint64_t pre, uint64_t post) "exact pending size %" PRIu64 " (pre = %" PRIu64 " post=%" PRIu64 ")"
+migrate_pending_estimate(uint64_t size, uint64_t pre, uint64_t post) "estimate pending size %" PRIu64 " (pre = %" PRIu64 " post=%" PRIu64 ")"
migrate_send_rp_message(int msg_type, uint16_t len) "%d: len %d"
migrate_send_rp_recv_bitmap(char *name, int64_t size) "block '%s' size 0x%"PRIi64
migration_completion_file_err(void) ""
@@ -357,6 +357,7 @@ migration_block_flush_blks(const char *action, int submitted, int read_done, int
migration_block_save(const char *mig_stage, int submitted, int transferred) "Enter save live %s submitted %d transferred %d"
migration_block_save_complete(void) "Block migration completed"
migration_block_state_pending(uint64_t pending) "Enter save live pending %" PRIu64
+migration_block_progression(unsigned percent) "Completed %u%%"
# page_cache.c
migration_pagecache_init(int64_t max_num_items) "Setting cache buckets to %" PRId64