Skip to contentSkip to conversation

privatize migration.h

PATCH In review Steve Sistare 3 participants 18 messages Mar 11, 2024 – Mar 12, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover privatize migration.h

migration/migration.h is the private interface for code in the migration sub-directory, but many other clients include it because they need accessors that are not exported by the publc interface in include/migration/misc.h. Fix that by refactoring accessors and defining new ones as needed.

After these fixes, no code outside of migration includes migration.h, and no code outside of migration uses MigrationState.

This series depends on the following:
* singleton patch "migration: export fewer options"

Changes in V2:
* rebase to migration-next, add RB
* split last patch

Steve Sistare (11):
migration: remove migration.h references
migration: export migration_is_setup_or_active
migration: export migration_is_active
migration: export migration_is_running
migration: export vcpu_dirty_limit_period
migration: migration_thread_is_self
migration: migration_is_device
migration: migration_file_set_error
migration: privatize colo interfaces
migration: delete unused accessors
migration: purge MigrationState from public interface

 hw/vfio/common.c                   | 17 +++-------
 hw/vfio/container.c                |  1 -
 hw/vfio/migration.c                | 11 ++-----
 hw/virtio/vhost-user.c             |  1 -
 hw/virtio/virtio-balloon.c         |  1 -
 include/migration/client-options.h |  1 +
 include/migration/misc.h           | 17 +++++-----
 migration/colo.c                   | 17 ++++++----
 migration/migration.c              | 67 ++++++++++++++++++++++++--------------
 migration/migration.h              |  7 ++--
 migration/options.c                | 11 +++++--
 migration/ram.c                    |  5 ++-
 migration/savevm.c                 |  2 +-
 net/colo-compare.c                 |  3 +-
 net/vhost-vdpa.c                   |  3 +-
 stubs/colo.c                       |  1 -
 system/dirtylimit.c                | 12 +++----
 system/qdev-monitor.c              |  1 -
 target/loongarch/kvm/kvm.c         |  1 -
 target/riscv/kvm/kvm-cpu.c         |  4 +--
 tests/unit/test-vmstate.c          |  1 -
 21 files changed, 96 insertions(+), 88 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v2 1/11 migration: remove migration.h references

Remove migration.h from files that no longer need it due to previous commits.

---
 hw/vfio/container.c        | 1 -
 hw/virtio/vhost-user.c     | 1 -
 hw/virtio/virtio-balloon.c | 1 -
 system/qdev-monitor.c      | 1 -
 target/loongarch/kvm/kvm.c | 1 -
 tests/unit/test-vmstate.c  | 1 -
 6 files changed, 6 deletions(-)
hw/vfio/container.c +0 -1
index bd25b9f..ff081a1 100644
@@ -32,7 +32,6 @@
 #include "sysemu/reset.h"
 #include "trace.h"
 #include "qapi/error.h"
-#include "migration/migration.h"
 #include "pci.h"
 
 VFIOGroupList vfio_group_list =
hw/virtio/vhost-user.c +0 -1
index a1eea85..1af8621 100644
@@ -26,7 +26,6 @@
 #include "qemu/sockets.h"
 #include "sysemu/runstate.h"
 #include "sysemu/cryptodev.h"
-#include "migration/migration.h"
 #include "migration/postcopy-ram.h"
 #include "trace.h"
 #include "exec/ramblock.h"
hw/virtio/virtio-balloon.c +0 -1
index a59ff17..609e39a 100644
@@ -31,7 +31,6 @@
 #include "trace.h"
 #include "qemu/error-report.h"
 #include "migration/misc.h"
-#include "migration/migration.h"
 
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
system/qdev-monitor.c +0 -1
index a13db76..948d393 100644
@@ -38,7 +38,6 @@
 #include "qemu/option_int.h"
 #include "sysemu/block-backend.h"
 #include "migration/misc.h"
-#include "migration/migration.h"
 #include "qemu/cutils.h"
 #include "hw/qdev-properties.h"
 #include "hw/clock.h"
target/loongarch/kvm/kvm.c +0 -1
index c19978a..11a69a3 100644
@@ -22,7 +22,6 @@
 #include "hw/irq.h"
 #include "qemu/log.h"
 #include "hw/loader.h"
-#include "migration/migration.h"
 #include "sysemu/runstate.h"
 #include "cpu-csr.h"
 #include "kvm_loongarch.h"
tests/unit/test-vmstate.c +0 -1
index c4f9faa..63f28f2 100644
@@ -24,7 +24,6 @@
 
 #include "qemu/osdep.h"
 
-#include "../migration/migration.h"
 #include "migration/vmstate.h"
 #include "migration/qemu-file-types.h"
 #include "../migration/qemu-file.h"
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v2 2/11 migration: export migration_is_setup_or_active

In reply to Steve Sistare

Delete the MigrationState parameter from migration_is_setup_or_active and move it to the public API in misc.h.

---
 hw/vfio/common.c         |  2 +-
 include/migration/misc.h |  1 +
 migration/migration.c    | 12 ++++++------
 migration/migration.h    |  1 -
 migration/ram.c          |  5 ++---
 net/vhost-vdpa.c         |  3 +--
 6 files changed, 11 insertions(+), 13 deletions(-)
hw/vfio/common.c +1 -1
index 059bfdc..896eab8 100644
@@ -152,7 +152,7 @@ static void vfio_set_migration_error(int err)
 {
     MigrationState *ms = migrate_get_current();
 
-    if (migration_is_setup_or_active(ms->state)) {
+    if (migration_is_setup_or_active()) {
         WITH_QEMU_LOCK_GUARD(&ms->qemu_file_lock) {
             if (ms->to_dst_file) {
                 qemu_file_set_error(ms->to_dst_file, err);
include/migration/misc.h +1 -0
index 4c226a4..79cff62 100644
@@ -61,6 +61,7 @@ void migration_object_init(void);
 void migration_shutdown(void);
 bool migration_is_idle(void);
 bool migration_is_active(MigrationState *);
+bool migration_is_setup_or_active(void);
 bool migrate_mode_is_cpr(MigrationState *);
 
 typedef enum MigrationEventType {
migration/migration.c +6 -6
index a49fcd5..af21403 100644
@@ -1081,9 +1081,11 @@ void migrate_send_rp_resume_ack(MigrationIncomingState *mis, uint32_t value)
  * Return true if we're already in the middle of a migration
  * (i.e. any of the active or setup states)
  */
-bool migration_is_setup_or_active(int state)
+bool migration_is_setup_or_active(void)
 {
-    switch (state) {
+    MigrationState *s = current_migration;
+
+    switch (s->state) {
     case MIGRATION_STATUS_ACTIVE:
     case MIGRATION_STATUS_POSTCOPY_ACTIVE:
     case MIGRATION_STATUS_POSTCOPY_PAUSED:
@@ -1601,10 +1603,8 @@ bool migration_incoming_postcopy_advised(void)
 
 bool migration_in_bg_snapshot(void)
 {
-    MigrationState *s = migrate_get_current();
-
     return migrate_background_snapshot() &&
-            migration_is_setup_or_active(s->state);
+           migration_is_setup_or_active();
 }
 
 bool migration_is_idle(void)
@@ -2297,7 +2297,7 @@ static void *source_return_path_thread(void *opaque)
     trace_source_return_path_thread_entry();
     rcu_register_thread();
 
-    while (migration_is_setup_or_active(ms->state)) {
+    while (migration_is_setup_or_active()) {
         trace_source_return_path_thread_loop_top();
 
         header_type = qemu_get_be16(rp);
migration/migration.h +0 -1
index 65c0b61..736460a 100644
@@ -479,7 +479,6 @@ bool migrate_has_error(MigrationState *s);
 
 void migrate_fd_connect(MigrationState *s, Error *error_in);
 
-bool migration_is_setup_or_active(int state);
 bool migration_is_running(int state);
 
 int migrate_init(MigrationState *s, Error **errp);
migration/ram.c +2 -3
index c79e3de..b8a5b67 100644
@@ -2909,10 +2909,9 @@ void qemu_guest_free_page_hint(void *addr, size_t len)
     RAMBlock *block;
     ram_addr_t offset;
     size_t used_len, start, npages;
-    MigrationState *s = migrate_get_current();
 
     /* This function is currently expected to be used during live migration */
-    if (!migration_is_setup_or_active(s->state)) {
+    if (!migration_is_setup_or_active()) {
         return;
     }
 
@@ -3257,7 +3256,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
 
 out:
     if (ret >= 0
-        && migration_is_setup_or_active(migrate_get_current()->state)) {
+        && migration_is_setup_or_active()) {
         if (migrate_multifd() && migrate_multifd_flush_after_each_section() &&
             !migrate_mapped_ram()) {
             ret = multifd_send_sync_main();
net/vhost-vdpa.c +1 -2
index e6bdb45..8564817 100644
@@ -26,7 +26,6 @@
 #include <err.h>
 #include "standard-headers/linux/virtio_net.h"
 #include "monitor/monitor.h"
-#include "migration/migration.h"
 #include "migration/misc.h"
 #include "hw/virtio/vhost.h"
 
@@ -355,7 +354,7 @@ static int vhost_vdpa_net_data_start(NetClientState *nc)
     assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA);
 
     if (s->always_svq ||
-        migration_is_setup_or_active(migrate_get_current()->state)) {
+        migration_is_setup_or_active()) {
         v->shadow_vqs_enabled = true;
     } else {
         v->shadow_vqs_enabled = false;
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v2 3/11 migration: export migration_is_active

In reply to Steve Sistare

Delete the MigrationState parameter from migration_is_active so it can be exported and used without including migration.h.

---
 hw/vfio/common.c         |  4 ++--
 include/migration/misc.h |  2 +-
 migration/migration.c    | 10 ++++++----
 system/dirtylimit.c      |  2 +-
 4 files changed, 10 insertions(+), 8 deletions(-)
hw/vfio/common.c +2 -2
index 896eab8..2dbbf62 100644
@@ -182,7 +182,7 @@ static bool vfio_devices_all_dirty_tracking(VFIOContainerBase *bcontainer)
     VFIODevice *vbasedev;
     MigrationState *ms = migrate_get_current();
 
-    if (ms->state != MIGRATION_STATUS_ACTIVE &&
+    if (!migration_is_active() &&
         ms->state != MIGRATION_STATUS_DEVICE) {
         return false;
     }
@@ -225,7 +225,7 @@ vfio_devices_all_running_and_mig_active(const VFIOContainerBase *bcontainer)
 {
     VFIODevice *vbasedev;
 
-    if (!migration_is_active(migrate_get_current())) {
+    if (!migration_is_active()) {
         return false;
     }
 
include/migration/misc.h +1 -1
index 79cff62..e1f1bf8 100644
@@ -60,7 +60,7 @@ void dump_vmstate_json_to_file(FILE *out_fp);
 void migration_object_init(void);
 void migration_shutdown(void);
 bool migration_is_idle(void);
-bool migration_is_active(MigrationState *);
+bool migration_is_active(void);
 bool migration_is_setup_or_active(void);
 bool migrate_mode_is_cpr(MigrationState *);
 
migration/migration.c +6 -4
index af21403..17859cb 100644
@@ -1406,7 +1406,7 @@ static void migrate_fd_cleanup(MigrationState *s)
         qemu_fclose(tmp);
     }
 
-    assert(!migration_is_active(s));
+    assert(!migration_is_active());
 
     if (s->state == MIGRATION_STATUS_CANCELLING) {
         migrate_set_state(&s->state, MIGRATION_STATUS_CANCELLING,
@@ -1637,8 +1637,10 @@ bool migration_is_idle(void)
     return false;
 }
 
-bool migration_is_active(MigrationState *s)
+bool migration_is_active(void)
 {
+    MigrationState *s = current_migration;
+
     return (s->state == MIGRATION_STATUS_ACTIVE ||
             s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE);
 }
@@ -3461,7 +3463,7 @@ static void *migration_thread(void *opaque)
 
     trace_migration_thread_setup_complete();
 
-    while (migration_is_active(s)) {
+    while (migration_is_active()) {
         if (urgent || !migration_rate_exceeded(s->to_dst_file)) {
             MigIterateState iter_state = migration_iteration_run(s);
             if (iter_state == MIG_ITERATE_SKIP) {
@@ -3607,7 +3609,7 @@ static void *bg_migration_thread(void *opaque)
     migration_bh_schedule(bg_migration_vm_start_bh, s);
     bql_unlock();
 
-    while (migration_is_active(s)) {
+    while (migration_is_active()) {
         MigIterateState iter_state = bg_migration_iteration_run(s);
         if (iter_state == MIG_ITERATE_SKIP) {
             continue;
system/dirtylimit.c +1 -1
index 774ff44..051e031 100644
@@ -83,7 +83,7 @@ static void vcpu_dirty_rate_stat_collect(void)
     int64_t period = DIRTYLIMIT_CALC_TIME_MS;
 
     if (migrate_dirty_limit() &&
-        migration_is_active(s)) {
+        migration_is_active()) {
         period = s->parameters.x_vcpu_dirty_limit_period;
     }
 
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH v2 4/11 migration: export migration_is_running

In reply to Steve Sistare

Delete the MigrationState parameter from migration_is_running and move it to the public API in misc.h.

---
 include/migration/misc.h   |  1 +
 migration/migration.c      | 10 ++++++----
 migration/migration.h      |  2 --
 migration/options.c        |  4 ++--
 migration/savevm.c         |  2 +-
 system/dirtylimit.c        |  2 +-
 target/riscv/kvm/kvm-cpu.c |  4 ++--
 7 files changed, 13 insertions(+), 12 deletions(-)
include/migration/misc.h +1 -0
index e1f1bf8..7526977 100644
@@ -106,6 +106,7 @@ int migration_call_notifiers(MigrationState *s, MigrationEventType type,
 bool migration_in_setup(MigrationState *);
 bool migration_has_finished(MigrationState *);
 bool migration_has_failed(MigrationState *);
+bool migration_is_running(void);
 /* ...and after the device transmission */
 /* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */
 bool migration_in_incoming_postcopy(void);
migration/migration.c +6 -4
index 17859cb..546ba86 100644
@@ -1103,9 +1103,11 @@ bool migration_is_setup_or_active(void)
     }
 }
 
-bool migration_is_running(int state)
+bool migration_is_running(void)
 {
-    switch (state) {
+    MigrationState *s = current_migration;
+
+    switch (s->state) {
     case MIGRATION_STATUS_ACTIVE:
     case MIGRATION_STATUS_POSTCOPY_ACTIVE:
     case MIGRATION_STATUS_POSTCOPY_PAUSED:
@@ -1477,7 +1479,7 @@ static void migrate_fd_cancel(MigrationState *s)
 
     do {
         old_state = s->state;
-        if (!migration_is_running(old_state)) {
+        if (!migration_is_running()) {
             break;
         }
         /* If the migration is paused, kick it out of the pause */
@@ -1962,7 +1964,7 @@ static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc,
         return true;
     }
 
-    if (migration_is_running(s->state)) {
+    if (migration_is_running()) {
         error_setg(errp, QERR_MIGRATION_ACTIVE);
         return false;
     }
migration/migration.h +0 -2
index 736460a..e4983db 100644
@@ -479,8 +479,6 @@ bool migrate_has_error(MigrationState *s);
 
 void migrate_fd_connect(MigrationState *s, Error *error_in);
 
-bool migration_is_running(int state);
-
 int migrate_init(MigrationState *s, Error **errp);
 bool migration_is_blocked(Error **errp);
 /* True if outgoing migration has entered postcopy phase */
migration/options.c +2 -2
index 40eb930..642cfb0 100644
@@ -681,7 +681,7 @@ bool migrate_cap_set(int cap, bool value, Error **errp)
     MigrationState *s = migrate_get_current();
     bool new_caps[MIGRATION_CAPABILITY__MAX];
 
-    if (migration_is_running(s->state)) {
+    if (migration_is_running()) {
         error_setg(errp, QERR_MIGRATION_ACTIVE);
         return false;
     }
@@ -725,7 +725,7 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
     MigrationCapabilityStatusList *cap;
     bool new_caps[MIGRATION_CAPABILITY__MAX];
 
-    if (migration_is_running(s->state) || migration_in_colo_state()) {
+    if (migration_is_running() || migration_in_colo_state()) {
         error_setg(errp, QERR_MIGRATION_ACTIVE);
         return;
     }
migration/savevm.c +1 -1
index dc1fb9c..71974b6 100644
@@ -1705,7 +1705,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
     MigrationState *ms = migrate_get_current();
     MigrationStatus status;
 
-    if (migration_is_running(ms->state)) {
+    if (migration_is_running()) {
         error_setg(errp, QERR_MIGRATION_ACTIVE);
         return -EINVAL;
     }
system/dirtylimit.c +1 -1
index 051e031..1622bb7 100644
@@ -451,7 +451,7 @@ static bool dirtylimit_is_allowed(void)
 {
     MigrationState *ms = migrate_get_current();
 
-    if (migration_is_running(ms->state) &&
+    if (migration_is_running() &&
         (!qemu_thread_is_self(&ms->thread)) &&
         migrate_dirty_limit() &&
         dirtylimit_in_service()) {
target/riscv/kvm/kvm-cpu.c +2 -2
index 422e4f1..cf046db 100644
@@ -44,7 +44,7 @@
 #include "kvm_riscv.h"
 #include "sbi_ecall_interface.h"
 #include "chardev/char-fe.h"
-#include "migration/migration.h"
+#include "migration/misc.h"
 #include "sysemu/runstate.h"
 #include "hw/riscv/numa.h"
 
@@ -700,7 +700,7 @@ static void kvm_riscv_put_regs_timer(CPUState *cs)
      * frequency. Therefore, we should check whether they are the same here
      * during the migration.
      */
-    if (migration_is_running(migrate_get_current()->state)) {
+    if (migration_is_running()) {
         KVM_RISCV_GET_TIMER(cs, frequency, reg);
         if (reg != env->kvm_timer_frequency) {
             error_report("Dst Hosts timer frequency != Src Hosts");
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH v2 5/11 migration: export vcpu_dirty_limit_period

In reply to Steve Sistare

Define and export vcpu_dirty_limit_period to eliminate a dependency on MigrationState.

---
 include/migration/client-options.h | 1 +
 migration/options.c                | 7 +++++++
 system/dirtylimit.c                | 3 +--
 3 files changed, 9 insertions(+), 2 deletions(-)
include/migration/client-options.h +1 -0
index 887fea1..59f4b55 100644
@@ -20,5 +20,6 @@ bool migrate_switchover_ack(void);
 /* parameters */
 
 MigMode migrate_mode(void);
+uint64_t migrate_vcpu_dirty_limit_period(void);
 
 #endif
migration/options.c +7 -0
index 642cfb0..09178c6 100644
@@ -924,6 +924,13 @@ const char *migrate_tls_hostname(void)
     return s->parameters.tls_hostname;
 }
 
+uint64_t migrate_vcpu_dirty_limit_period(void)
+{
+    MigrationState *s = migrate_get_current();
+
+    return s->parameters.x_vcpu_dirty_limit_period;
+}
+
 uint64_t migrate_xbzrle_cache_size(void)
 {
     MigrationState *s = migrate_get_current();
system/dirtylimit.c +1 -2
index 1622bb7..b0afaa0 100644
@@ -77,14 +77,13 @@ static bool dirtylimit_quit;
 
 static void vcpu_dirty_rate_stat_collect(void)
 {
-    MigrationState *s = migrate_get_current();
     VcpuStat stat;
     int i = 0;
     int64_t period = DIRTYLIMIT_CALC_TIME_MS;
 
     if (migrate_dirty_limit() &&
         migration_is_active()) {
-        period = s->parameters.x_vcpu_dirty_limit_period;
+        period = migrate_vcpu_dirty_limit_period();
     }
 
     /* calculate vcpu dirtyrate */
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH v2 6/11 migration: migration_thread_is_self

In reply to Steve Sistare

Define and export migration_thread_is_self to eliminate a dependency on MigrationState.

---
 include/migration/misc.h | 1 +
 migration/migration.c    | 7 +++++++
 system/dirtylimit.c      | 5 +----
 3 files changed, 9 insertions(+), 4 deletions(-)
include/migration/misc.h +1 -0
index 7526977..c4b5416 100644
@@ -61,6 +61,7 @@ void migration_object_init(void);
 void migration_shutdown(void);
 bool migration_is_idle(void);
 bool migration_is_active(void);
+bool migration_thread_is_self(void);
 bool migration_is_setup_or_active(void);
 bool migrate_mode_is_cpr(MigrationState *);
 
migration/migration.c +7 -0
index 546ba86..afe72af 100644
@@ -1647,6 +1647,13 @@ bool migration_is_active(void)
             s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE);
 }
 
+bool migration_thread_is_self(void)
+{
+    MigrationState *s = current_migration;
+
+    return qemu_thread_is_self(&s->thread);
+}
+
 bool migrate_mode_is_cpr(MigrationState *s)
 {
     return s->parameters.mode == MIG_MODE_CPR_REBOOT;
system/dirtylimit.c +1 -4
index b0afaa0..ab20da3 100644
@@ -25,7 +25,6 @@
 #include "sysemu/kvm.h"
 #include "trace.h"
 #include "migration/misc.h"
-#include "migration/migration.h"
 
 /*
  * Dirtylimit stop working if dirty page rate error
@@ -448,10 +447,8 @@ static void dirtylimit_cleanup(void)
  */
 static bool dirtylimit_is_allowed(void)
 {
-    MigrationState *ms = migrate_get_current();
-
     if (migration_is_running() &&
-        (!qemu_thread_is_self(&ms->thread)) &&
+        !migration_thread_is_self() &&
         migrate_dirty_limit() &&
         dirtylimit_in_service()) {
         return false;
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH v2 7/11 migration: migration_is_device

In reply to Steve Sistare

Define and export migration_is_device to eliminate a dependency on MigrationState.

---
 hw/vfio/common.c         | 4 +---
 include/migration/misc.h | 1 +
 migration/migration.c    | 7 +++++++
 3 files changed, 9 insertions(+), 3 deletions(-)
hw/vfio/common.c +1 -3
index 2dbbf62..de01068 100644
@@ -180,10 +180,8 @@ bool vfio_device_state_is_precopy(VFIODevice *vbasedev)
 static bool vfio_devices_all_dirty_tracking(VFIOContainerBase *bcontainer)
 {
     VFIODevice *vbasedev;
-    MigrationState *ms = migrate_get_current();
 
-    if (!migration_is_active() &&
-        ms->state != MIGRATION_STATUS_DEVICE) {
+    if (!migration_is_active() && !migration_is_device()) {
         return false;
     }
 
include/migration/misc.h +1 -0
index c4b5416..28cfaed 100644
@@ -61,6 +61,7 @@ void migration_object_init(void);
 void migration_shutdown(void);
 bool migration_is_idle(void);
 bool migration_is_active(void);
+bool migration_is_device(void);
 bool migration_thread_is_self(void);
 bool migration_is_setup_or_active(void);
 bool migrate_mode_is_cpr(MigrationState *);
migration/migration.c +7 -0
index afe72af..db1e627 100644
@@ -1647,6 +1647,13 @@ bool migration_is_active(void)
             s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE);
 }
 
+bool migration_is_device(void)
+{
+    MigrationState *s = current_migration;
+
+    return s->state == MIGRATION_STATUS_DEVICE;
+}
+
 bool migration_thread_is_self(void)
 {
     MigrationState *s = current_migration;
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH v2 8/11 migration: migration_file_set_error

In reply to Steve Sistare

Define and export migration_file_set_error to eliminate a dependency on MigrationState.

---
 hw/vfio/common.c         |  9 +--------
 hw/vfio/migration.c      | 11 +++--------
 include/migration/misc.h |  2 ++
 migration/migration.c    | 11 +++++++++++
 4 files changed, 17 insertions(+), 16 deletions(-)
hw/vfio/common.c +1 -8
index de01068..b44204e 100644
@@ -39,7 +39,6 @@
 #include "sysemu/runstate.h"
 #include "trace.h"
 #include "qapi/error.h"
-#include "migration/migration.h"
 #include "migration/misc.h"
 #include "migration/blocker.h"
 #include "migration/qemu-file.h"
@@ -150,14 +149,8 @@ bool vfio_viommu_preset(VFIODevice *vbasedev)
 
 static void vfio_set_migration_error(int err)
 {
-    MigrationState *ms = migrate_get_current();
-
     if (migration_is_setup_or_active()) {
-        WITH_QEMU_LOCK_GUARD(&ms->qemu_file_lock) {
-            if (ms->to_dst_file) {
-                qemu_file_set_error(ms->to_dst_file, err);
-            }
-        }
+        migration_file_set_error(err);
     }
 }
 
hw/vfio/migration.c +3 -8
index 5d4a23c..c5cb61d 100644
@@ -17,13 +17,12 @@
 
 #include "sysemu/runstate.h"
 #include "hw/vfio/vfio-common.h"
-#include "migration/migration.h"
+#include "migration/misc.h"
 #include "migration/savevm.h"
 #include "migration/vmstate.h"
 #include "migration/qemu-file.h"
 #include "migration/register.h"
 #include "migration/blocker.h"
-#include "migration/misc.h"
 #include "qapi/error.h"
 #include "exec/ramlist.h"
 #include "exec/ram_addr.h"
@@ -712,9 +711,7 @@ static void vfio_vmstate_change_prepare(void *opaque, bool running,
          * Migration should be aborted in this case, but vm_state_notify()
          * currently does not support reporting failures.
          */
-        if (migrate_get_current()->to_dst_file) {
-            qemu_file_set_error(migrate_get_current()->to_dst_file, ret);
-        }
+        migration_file_set_error(ret);
     }
 
     trace_vfio_vmstate_change_prepare(vbasedev->name, running,
@@ -744,9 +741,7 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state)
          * Migration should be aborted in this case, but vm_state_notify()
          * currently does not support reporting failures.
          */
-        if (migrate_get_current()->to_dst_file) {
-            qemu_file_set_error(migrate_get_current()->to_dst_file, ret);
-        }
+        migration_file_set_error(ret);
     }
 
     trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state),
include/migration/misc.h +2 -0
index 28cfaed..e521cd5 100644
@@ -109,6 +109,8 @@ bool migration_in_setup(MigrationState *);
 bool migration_has_finished(MigrationState *);
 bool migration_has_failed(MigrationState *);
 bool migration_is_running(void);
+void migration_file_set_error(int err);
+
 /* ...and after the device transmission */
 /* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */
 bool migration_in_incoming_postcopy(void);
migration/migration.c +11 -0
index db1e627..216f63d 100644
@@ -3038,6 +3038,17 @@ static MigThrError postcopy_pause(MigrationState *s)
     }
 }
 
+void migration_file_set_error(int err)
+{
+    MigrationState *s = current_migration;
+
+    WITH_QEMU_LOCK_GUARD(&s->qemu_file_lock) {
+        if (s->to_dst_file) {
+            qemu_file_set_error(s->to_dst_file, err);
+        }
+    }
+}
+
 static MigThrError migration_detect_error(MigrationState *s)
 {
     int ret;
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH v2 9/11 migration: privatize colo interfaces

In reply to Steve Sistare

Remove private migration interfaces from net/colo-compare.c and push them to migration/colo.c.

---
 migration/colo.c   | 17 +++++++++++------
 net/colo-compare.c |  3 +--
 stubs/colo.c       |  1 -
 3 files changed, 12 insertions(+), 9 deletions(-)
migration/colo.c +11 -6
index 315e31f..84632a6 100644
@@ -63,9 +63,9 @@ static bool colo_runstate_is_stopped(void)
     return runstate_check(RUN_STATE_COLO) || !runstate_is_running();
 }
 
-static void colo_checkpoint_notify(void *opaque)
+static void colo_checkpoint_notify(void)
 {
-    MigrationState *s = opaque;
+    MigrationState *s = migrate_get_current();
     int64_t next_notify_time;
 
     qemu_event_set(&s->colo_checkpoint_event);
@@ -74,10 +74,15 @@ static void colo_checkpoint_notify(void *opaque)
     timer_mod(s->colo_delay_timer, next_notify_time);
 }
 
+static void colo_checkpoint_notify_timer(void *opaque)
+{
+    colo_checkpoint_notify();
+}
+
 void colo_checkpoint_delay_set(void)
 {
     if (migration_in_colo_state()) {
-        colo_checkpoint_notify(migrate_get_current());
+        colo_checkpoint_notify();
     }
 }
 
@@ -162,7 +167,7 @@ static void primary_vm_do_failover(void)
      * kick COLO thread which might wait at
      * qemu_sem_wait(&s->colo_checkpoint_sem).
      */
-    colo_checkpoint_notify(s);
+    colo_checkpoint_notify();
 
     /*
      * Wake up COLO thread which may blocked in recv() or send(),
@@ -518,7 +523,7 @@ out:
 
 static void colo_compare_notify_checkpoint(Notifier *notifier, void *data)
 {
-    colo_checkpoint_notify(data);
+    colo_checkpoint_notify();
 }
 
 static void colo_process_checkpoint(MigrationState *s)
@@ -642,7 +647,7 @@ void migrate_start_colo_process(MigrationState *s)
     bql_unlock();
     qemu_event_init(&s->colo_checkpoint_event, false);
     s->colo_delay_timer =  timer_new_ms(QEMU_CLOCK_HOST,
-                                colo_checkpoint_notify, s);
+                                colo_checkpoint_notify_timer, NULL);
 
     qemu_sem_init(&s->colo_exit_sem, 0);
     colo_process_checkpoint(s);
net/colo-compare.c +1 -2
index f2dfc0e..c4ad0ab 100644
@@ -28,7 +28,6 @@
 #include "sysemu/iothread.h"
 #include "net/colo-compare.h"
 #include "migration/colo.h"
-#include "migration/migration.h"
 #include "util.h"
 
 #include "block/aio-wait.h"
@@ -189,7 +188,7 @@ static void colo_compare_inconsistency_notify(CompareState *s)
         notify_remote_frame(s);
     } else {
         notifier_list_notify(&colo_compare_notifiers,
-                             migrate_get_current());
+                             NULL);
     }
 }
 
stubs/colo.c +0 -1
index 08c9f98..f8c069b 100644
@@ -2,7 +2,6 @@
 #include "qemu/notify.h"
 #include "net/colo-compare.h"
 #include "migration/colo.h"
-#include "migration/migration.h"
 #include "qemu/error-report.h"
 #include "qapi/qapi-commands-migration.h"
 
Signature · 1 line
1.8.3.1
Reviewed-by on v2 9/11
#10 lore raw

RE: [PATCH V2 09/11] migration: privatize colo interfaces

Quoted 16 lines

-----Original Message-----
From: Steve Sistare <[email protected]>
Sent: Tuesday, March 12, 2024 1:49 AM
To: [email protected]
Cc: Alex Williamson <[email protected]>; Cedric Le Goater <[email protected]>; Michael S. Tsirkin <[email protected]>; David Hildenbrand <[email protected]>; Peter Xu <[email protected]>; Fabiano Rosas <[email protected]>; Zhang, Hailiang <[email protected]>; Zhang, Chen <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; Hyman Huang <[email protected]>; Song Gao <[email protected]>; Alistair Francis <[email protected]>; Steve Sistare <[email protected]>
Subject: [PATCH V2 09/11] migration: privatize colo interfaces

Quoted 4 lines

Remove private migration interfaces from net/colo-compare.c and push them to migration/colo.c.

Thanks
Chen

Quoted 97 lines
---
 migration/colo.c   | 17 +++++++++++------
 net/colo-compare.c |  3 +--
 stubs/colo.c       |  1 -
 3 files changed, 12 insertions(+), 9 deletions(-)
migration/colo.c index 315e31f..84632a6 renamed from migration/colo.c +0 -0

100644

migration/colo.c +10 -5
@@ -63,9 +63,9 @@ static bool colo_runstate_is_stopped(void)
     return runstate_check(RUN_STATE_COLO) || !runstate_is_running();  }
 
-static void colo_checkpoint_notify(void *opaque)
+static void colo_checkpoint_notify(void)
 {
-    MigrationState *s = opaque;
+    MigrationState *s = migrate_get_current();
     int64_t next_notify_time;
 
     qemu_event_set(&s->colo_checkpoint_event);
@@ -74,10 +74,15 @@ static void colo_checkpoint_notify(void *opaque)
     timer_mod(s->colo_delay_timer, next_notify_time);  }
 
+static void colo_checkpoint_notify_timer(void *opaque) {
+    colo_checkpoint_notify();
+}
+
 void colo_checkpoint_delay_set(void)
 {
     if (migration_in_colo_state()) {
-        colo_checkpoint_notify(migrate_get_current());
+        colo_checkpoint_notify();
     }
 }
 
@@ -162,7 +167,7 @@ static void primary_vm_do_failover(void)
      * kick COLO thread which might wait at
      * qemu_sem_wait(&s->colo_checkpoint_sem).
      */
-    colo_checkpoint_notify(s);
+    colo_checkpoint_notify();
 
     /*
      * Wake up COLO thread which may blocked in recv() or send(), @@ -518,7
+523,7 @@ out:
 
 static void colo_compare_notify_checkpoint(Notifier *notifier, void *data)  {
-    colo_checkpoint_notify(data);
+    colo_checkpoint_notify();
 }
 
 static void colo_process_checkpoint(MigrationState *s) @@ -642,7 +647,7

@@ void migrate_start_colo_process(MigrationState *s)

     bql_unlock();
     qemu_event_init(&s->colo_checkpoint_event, false);
     s->colo_delay_timer =  timer_new_ms(QEMU_CLOCK_HOST,
migration/colo.c +1 -1
-                                colo_checkpoint_notify, s);
+                                colo_checkpoint_notify_timer, NULL);
 
     qemu_sem_init(&s->colo_exit_sem, 0);
     colo_process_checkpoint(s);
net/colo-compare.c index f2dfc0e..c4ad0ab renamed from net/colo-compare.c +0 -0

100644

net/colo-compare.c +1 -2
@@ -28,7 +28,6 @@
 #include "sysemu/iothread.h"
 #include "net/colo-compare.h"
 #include "migration/colo.h"
-#include "migration/migration.h"
 #include "util.h"
 
 #include "block/aio-wait.h"
@@ -189,7 +188,7 @@ static void
 colo_compare_inconsistency_notify(CompareState *s)
         notify_remote_frame(s);
     } else {
         notifier_list_notify(&colo_compare_notifiers,
-                             migrate_get_current());
+                             NULL);
     }
 }
stubs/colo.c +0 -2
@@ -2,7 +2,6 @@
 #include "qemu/notify.h"
 #include "net/colo-compare.h"
 #include "migration/colo.h"
-#include "migration/migration.h"
 #include "qemu/error-report.h"
 #include "qapi/qapi-commands-migration.h"
 
--

1.8.3.1

#11 lore raw

PATCH v2 10/11 migration: delete unused accessors

In reply to Steve Sistare
---
 include/migration/misc.h |  3 ---
 migration/migration.c    | 10 ----------
 2 files changed, 13 deletions(-)
include/migration/misc.h +0 -3
index e521cd5..d563d2c 100644
@@ -105,13 +105,10 @@ void migration_add_notifier_mode(NotifierWithReturn *notify,
 void migration_remove_notifier(NotifierWithReturn *notify);
 int migration_call_notifiers(MigrationState *s, MigrationEventType type,
                              Error **errp);
-bool migration_in_setup(MigrationState *);
-bool migration_has_finished(MigrationState *);
 bool migration_has_failed(MigrationState *);
 bool migration_is_running(void);
 void migration_file_set_error(int err);
 
-/* ...and after the device transmission */
 /* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */
 bool migration_in_incoming_postcopy(void);
 /* True if incoming migration entered POSTCOPY_INCOMING_ADVISE */
migration/migration.c +0 -10
index 216f63d..644e073 100644
@@ -1548,16 +1548,6 @@ int migration_call_notifiers(MigrationState *s, MigrationEventType type,
     return ret;
 }
 
-bool migration_in_setup(MigrationState *s)
-{
-    return s->state == MIGRATION_STATUS_SETUP;
-}
-
-bool migration_has_finished(MigrationState *s)
-{
-    return s->state == MIGRATION_STATUS_COMPLETED;
-}
-
 bool migration_has_failed(MigrationState *s)
 {
     return (s->state == MIGRATION_STATUS_CANCELLED ||
Signature · 1 line
1.8.3.1
#12 lore raw

PATCH v2 11/11 migration: purge MigrationState from public interface

In reply to Steve Sistare

Move remaining MigrationState references from the public file misc.h to the private file migration.h.

---
 include/migration/misc.h | 6 ++----
 migration/migration.h    | 6 ++++++
 2 files changed, 8 insertions(+), 4 deletions(-)
include/migration/misc.h +2 -4
index d563d2c..c9e200f 100644
@@ -64,7 +64,6 @@ bool migration_is_active(void);
 bool migration_is_device(void);
 bool migration_thread_is_self(void);
 bool migration_is_setup_or_active(void);
-bool migrate_mode_is_cpr(MigrationState *);
 
 typedef enum MigrationEventType {
     MIG_EVENT_PRECOPY_SETUP,
@@ -103,16 +102,15 @@ void migration_add_notifier_mode(NotifierWithReturn *notify,
                                  MigrationNotifyFunc func, MigMode mode);
 
 void migration_remove_notifier(NotifierWithReturn *notify);
-int migration_call_notifiers(MigrationState *s, MigrationEventType type,
-                             Error **errp);
-bool migration_has_failed(MigrationState *);
 bool migration_is_running(void);
 void migration_file_set_error(int err);
 
 /* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */
 bool migration_in_incoming_postcopy(void);
+
 /* True if incoming migration entered POSTCOPY_INCOMING_ADVISE */
 bool migration_incoming_postcopy_advised(void);
+
 /* True if background snapshot is active */
 bool migration_in_bg_snapshot(void);
 
migration/migration.h +6 -0
index e4983db..8045e39 100644
@@ -26,6 +26,7 @@
 #include "qom/object.h"
 #include "postcopy-ram.h"
 #include "sysemu/runstate.h"
+#include "migration/misc.h"
 
 struct PostcopyBlocktimeContext;
 
@@ -479,12 +480,17 @@ bool migrate_has_error(MigrationState *s);
 
 void migrate_fd_connect(MigrationState *s, Error *error_in);
 
+int migration_call_notifiers(MigrationState *s, MigrationEventType type,
+                             Error **errp);
+
 int migrate_init(MigrationState *s, Error **errp);
 bool migration_is_blocked(Error **errp);
 /* True if outgoing migration has entered postcopy phase */
 bool migration_in_postcopy(void);
 bool migration_postcopy_is_alive(int state);
 MigrationState *migrate_get_current(void);
+bool migration_has_failed(MigrationState *);
+bool migrate_mode_is_cpr(MigrationState *);
 
 uint64_t ram_get_total_transferred_pages(void);
 
Signature · 1 line
1.8.3.1
#13 lore raw
In reply to Steve Sistare

Steve,

Quoted 2 lines · Steve Sistare

Changes in V2:
* rebase to migration-next, add RB

Not apply even to master branch. Note that there're >=1 PULLs sent and merged since my last reply.. Perhaps you rebased to the "old" next?

Signature · 1 line
Peter Xu
#14 lore raw
Quoted 8 lines · Peter Xu

Steve,

Quoted 2 lines · Steve Sistare

Changes in V2:
* rebase to migration-next, add RB

Not apply even to master branch. Note that there're >=1 PULLs sent and merged since my last reply.. Perhaps you rebased to the "old" next?

I pulled from branch migration-next in https://gitlab.com/peterx/qemu a few hours ago, but I must have screwed up somewhere. I'll figure it out and post a V4.

- Steve

#15 lore raw
Quoted 4 lines · Steven Sistare
Quoted 3 lines · Peter Xu

Steve,

On Mon, Mar 11, 2024 at 10:48:47AM -0700, Steve Sistare wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Changes in V2:
   * rebase to migration-next, add RB

Not apply even to master branch.  Note that there're >=1 PULLs sent and merged since my last reply..  Perhaps you rebased to the "old" next?

I pulled from branch migration-next in https://gitlab.com/peterx/qemu a few hours ago, but I must have screwed up somewhere.  I'll figure it out and post a V4.

My pull was a fiew hours old, but my patches still apply cleanly to the most recent tip:
a1bb5dd169f4 ("migration: Fix format in error message")

I can sent that as V3, but ...
Note that you must apply "migration: export fewer options" before "privatize migration.h". If that does not help, I will send V3.

- Steve

#16 lore raw
Quoted 15 lines · Steven Sistare
Quoted 7 lines · Steven Sistare
Quoted 6 lines · Peter Xu

Steve,

Quoted 2 lines · Steve Sistare

Changes in V2:
   * rebase to migration-next, add RB

Quoted 6 lines
Quoted 2 lines

Not apply even to master branch.  Note that there're >=1 PULLs sent and merged since my last reply..  Perhaps you rebased to the "old" next?

I pulled from branch migration-next in https://gitlab.com/peterx/qemu a few hours ago, but I must have screwed up somewhere.  I'll figure it out and post a V4.

Quoted 7 lines

My pull was a fiew hours old, but my patches still apply cleanly to the most recent tip:
a1bb5dd169f4 ("migration: Fix format in error message")

I can sent that as V3, but ...
Note that you must apply "migration: export fewer options" before "privatize migration.h". If that does not help, I will send V3.

Ouch, I forgot that dependency... Sorry.

Yeah it works now. No need to resend for now.

Signature · 1 line
Peter Xu
#17 lore raw
Quoted 20 lines · Peter Xu
Quoted 19 lines · Steven Sistare
Quoted 7 lines · Steven Sistare
Quoted 6 lines · Peter Xu

Steve,

Quoted 2 lines · Steve Sistare

Changes in V2:
   * rebase to migration-next, add RB

Quoted 6 lines
Quoted 2 lines

Not apply even to master branch.  Note that there're >=1 PULLs sent and merged since my last reply..  Perhaps you rebased to the "old" next?

I pulled from branch migration-next in https://gitlab.com/peterx/qemu a few hours ago, but I must have screwed up somewhere.  I'll figure it out and post a V4.

My pull was a fiew hours old, but my patches still apply cleanly to the most recent tip:
a1bb5dd169f4 ("migration: Fix format in error message")

Quoted 7 lines
Quoted 3 lines

I can sent that as V3, but ...
Note that you must apply "migration: export fewer options" before "privatize migration.h". If that does not help, I will send V3.

Ouch, I forgot that dependency... Sorry.

Yeah it works now. No need to resend for now.

Great! - steve