diff mbox series

[v3,4/8] migration: Drop migration_is_setup_or_active()

Message ID 20241024213056.1395400-5-peterx@redhat.com (mailing list archive)
State New
Headers show
Series Migration: Make misc.h helpers available for whole VM lifecycle | expand

Commit Message

Peter Xu Oct. 24, 2024, 9:30 p.m. UTC
This helper is mostly the same as migration_is_running(), except that one
has COLO reported as true, the other has CANCELLING reported as true.

Per my past years experience on the state changes, none of them should
matter.

To make it slightly safer, report both COLO || CANCELLING to be true in
migration_is_running(), then drop the other one.  We kept the 1st only
because the name is simpler, and clear enough.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 include/migration/misc.h |  4 ++--
 hw/vfio/common.c         |  2 +-
 migration/migration.c    | 35 +++--------------------------------
 migration/ram.c          |  5 ++---
 net/vhost-vdpa.c         |  3 +--
 5 files changed, 9 insertions(+), 40 deletions(-)

Comments

Cédric Le Goater Oct. 25, 2024, 8:59 a.m. UTC | #1
On 10/24/24 23:30, Peter Xu wrote:
> This helper is mostly the same as migration_is_running(), except that one
> has COLO reported as true, the other has CANCELLING reported as true.
> 
> Per my past years experience on the state changes, none of them should
> matter.
> 
> To make it slightly safer, report both COLO || CANCELLING to be true in
> migration_is_running(), then drop the other one.  We kept the 1st only
> because the name is simpler, and clear enough.
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>

It is preferable to reduce the API of the core migration subsystem.

Looks safe for vfio.

Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   include/migration/misc.h |  4 ++--
>   hw/vfio/common.c         |  2 +-
>   migration/migration.c    | 35 +++--------------------------------
>   migration/ram.c          |  5 ++---
>   net/vhost-vdpa.c         |  3 +--
>   5 files changed, 9 insertions(+), 40 deletions(-)
> 
> diff --git a/include/migration/misc.h b/include/migration/misc.h
> index e8490e3af5..86ef160f19 100644
> --- a/include/migration/misc.h
> +++ b/include/migration/misc.h
> @@ -52,11 +52,12 @@ void dump_vmstate_json_to_file(FILE *out_fp);
>   /* migration/migration.c */
>   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_is_running(void);
>   bool migration_thread_is_self(void);
> -bool migration_is_setup_or_active(void);
>   
>   typedef enum MigrationEventType {
>       MIG_EVENT_PRECOPY_SETUP,
> @@ -95,7 +96,6 @@ void migration_add_notifier_mode(NotifierWithReturn *notify,
>                                    MigrationNotifyFunc func, MigMode mode);
>   
>   void migration_remove_notifier(NotifierWithReturn *notify);
> -bool migration_is_running(void);
>   void migration_file_set_error(int ret, Error *err);
>   
>   /* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 36d0cf6585..dcef44fe55 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -149,7 +149,7 @@ bool vfio_viommu_preset(VFIODevice *vbasedev)
>   
>   static void vfio_set_migration_error(int ret)
>   {
> -    if (migration_is_setup_or_active()) {
> +    if (migration_is_running()) {
>           migration_file_set_error(ret, NULL);
>       }
>   }
> diff --git a/migration/migration.c b/migration/migration.c
> index e82ffa8cf3..3365195def 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -1116,33 +1116,6 @@ void migrate_send_rp_resume_ack(MigrationIncomingState *mis, uint32_t value)
>       migrate_send_rp_message(mis, MIG_RP_MSG_RESUME_ACK, sizeof(buf), &buf);
>   }
>   
> -/*
> - * 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(void)
> -{
> -    MigrationState *s = current_migration;
> -
> -    switch (s->state) {
> -    case MIGRATION_STATUS_ACTIVE:
> -    case MIGRATION_STATUS_POSTCOPY_ACTIVE:
> -    case MIGRATION_STATUS_POSTCOPY_PAUSED:
> -    case MIGRATION_STATUS_POSTCOPY_RECOVER_SETUP:
> -    case MIGRATION_STATUS_POSTCOPY_RECOVER:
> -    case MIGRATION_STATUS_SETUP:
> -    case MIGRATION_STATUS_PRE_SWITCHOVER:
> -    case MIGRATION_STATUS_DEVICE:
> -    case MIGRATION_STATUS_WAIT_UNPLUG:
> -    case MIGRATION_STATUS_COLO:
> -        return true;
> -
> -    default:
> -        return false;
> -
> -    }
> -}
> -
>   bool migration_is_running(void)
>   {
>       MigrationState *s = current_migration;
> @@ -1158,11 +1131,10 @@ bool migration_is_running(void)
>       case MIGRATION_STATUS_DEVICE:
>       case MIGRATION_STATUS_WAIT_UNPLUG:
>       case MIGRATION_STATUS_CANCELLING:
> +    case MIGRATION_STATUS_COLO:
>           return true;
> -
>       default:
>           return false;
> -
>       }
>   }
>   
> @@ -1661,8 +1633,7 @@ bool migration_incoming_postcopy_advised(void)
>   
>   bool migration_in_bg_snapshot(void)
>   {
> -    return migrate_background_snapshot() &&
> -           migration_is_setup_or_active();
> +    return migrate_background_snapshot() && migration_is_running();
>   }
>   
>   bool migration_is_idle(void)
> @@ -2335,7 +2306,7 @@ static void *source_return_path_thread(void *opaque)
>       trace_source_return_path_thread_entry();
>       rcu_register_thread();
>   
> -    while (migration_is_setup_or_active()) {
> +    while (migration_is_running()) {
>           trace_source_return_path_thread_loop_top();
>   
>           header_type = qemu_get_be16(rp);
> diff --git a/migration/ram.c b/migration/ram.c
> index d284f63854..5646a0b882 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -2860,7 +2860,7 @@ void qemu_guest_free_page_hint(void *addr, size_t len)
>       size_t used_len, start, npages;
>   
>       /* This function is currently expected to be used during live migration */
> -    if (!migration_is_setup_or_active()) {
> +    if (!migration_is_running()) {
>           return;
>       }
>   
> @@ -3208,8 +3208,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
>       }
>   
>   out:
> -    if (ret >= 0
> -        && migration_is_setup_or_active()) {
> +    if (ret >= 0 && migration_is_running()) {
>           if (migrate_multifd() && migrate_multifd_flush_after_each_section() &&
>               !migrate_mapped_ram()) {
>               ret = multifd_ram_flush_and_sync();
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 46b02c50be..231b45246c 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -375,8 +375,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()) {
> +    if (s->always_svq || migration_is_running()) {
>           v->shadow_vqs_enabled = true;
>       } else {
>           v->shadow_vqs_enabled = false;
diff mbox series

Patch

diff --git a/include/migration/misc.h b/include/migration/misc.h
index e8490e3af5..86ef160f19 100644
--- a/include/migration/misc.h
+++ b/include/migration/misc.h
@@ -52,11 +52,12 @@  void dump_vmstate_json_to_file(FILE *out_fp);
 /* migration/migration.c */
 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_is_running(void);
 bool migration_thread_is_self(void);
-bool migration_is_setup_or_active(void);
 
 typedef enum MigrationEventType {
     MIG_EVENT_PRECOPY_SETUP,
@@ -95,7 +96,6 @@  void migration_add_notifier_mode(NotifierWithReturn *notify,
                                  MigrationNotifyFunc func, MigMode mode);
 
 void migration_remove_notifier(NotifierWithReturn *notify);
-bool migration_is_running(void);
 void migration_file_set_error(int ret, Error *err);
 
 /* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 36d0cf6585..dcef44fe55 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -149,7 +149,7 @@  bool vfio_viommu_preset(VFIODevice *vbasedev)
 
 static void vfio_set_migration_error(int ret)
 {
-    if (migration_is_setup_or_active()) {
+    if (migration_is_running()) {
         migration_file_set_error(ret, NULL);
     }
 }
diff --git a/migration/migration.c b/migration/migration.c
index e82ffa8cf3..3365195def 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1116,33 +1116,6 @@  void migrate_send_rp_resume_ack(MigrationIncomingState *mis, uint32_t value)
     migrate_send_rp_message(mis, MIG_RP_MSG_RESUME_ACK, sizeof(buf), &buf);
 }
 
-/*
- * 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(void)
-{
-    MigrationState *s = current_migration;
-
-    switch (s->state) {
-    case MIGRATION_STATUS_ACTIVE:
-    case MIGRATION_STATUS_POSTCOPY_ACTIVE:
-    case MIGRATION_STATUS_POSTCOPY_PAUSED:
-    case MIGRATION_STATUS_POSTCOPY_RECOVER_SETUP:
-    case MIGRATION_STATUS_POSTCOPY_RECOVER:
-    case MIGRATION_STATUS_SETUP:
-    case MIGRATION_STATUS_PRE_SWITCHOVER:
-    case MIGRATION_STATUS_DEVICE:
-    case MIGRATION_STATUS_WAIT_UNPLUG:
-    case MIGRATION_STATUS_COLO:
-        return true;
-
-    default:
-        return false;
-
-    }
-}
-
 bool migration_is_running(void)
 {
     MigrationState *s = current_migration;
@@ -1158,11 +1131,10 @@  bool migration_is_running(void)
     case MIGRATION_STATUS_DEVICE:
     case MIGRATION_STATUS_WAIT_UNPLUG:
     case MIGRATION_STATUS_CANCELLING:
+    case MIGRATION_STATUS_COLO:
         return true;
-
     default:
         return false;
-
     }
 }
 
@@ -1661,8 +1633,7 @@  bool migration_incoming_postcopy_advised(void)
 
 bool migration_in_bg_snapshot(void)
 {
-    return migrate_background_snapshot() &&
-           migration_is_setup_or_active();
+    return migrate_background_snapshot() && migration_is_running();
 }
 
 bool migration_is_idle(void)
@@ -2335,7 +2306,7 @@  static void *source_return_path_thread(void *opaque)
     trace_source_return_path_thread_entry();
     rcu_register_thread();
 
-    while (migration_is_setup_or_active()) {
+    while (migration_is_running()) {
         trace_source_return_path_thread_loop_top();
 
         header_type = qemu_get_be16(rp);
diff --git a/migration/ram.c b/migration/ram.c
index d284f63854..5646a0b882 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -2860,7 +2860,7 @@  void qemu_guest_free_page_hint(void *addr, size_t len)
     size_t used_len, start, npages;
 
     /* This function is currently expected to be used during live migration */
-    if (!migration_is_setup_or_active()) {
+    if (!migration_is_running()) {
         return;
     }
 
@@ -3208,8 +3208,7 @@  static int ram_save_iterate(QEMUFile *f, void *opaque)
     }
 
 out:
-    if (ret >= 0
-        && migration_is_setup_or_active()) {
+    if (ret >= 0 && migration_is_running()) {
         if (migrate_multifd() && migrate_multifd_flush_after_each_section() &&
             !migrate_mapped_ram()) {
             ret = multifd_ram_flush_and_sync();
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 46b02c50be..231b45246c 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -375,8 +375,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()) {
+    if (s->always_svq || migration_is_running()) {
         v->shadow_vqs_enabled = true;
     } else {
         v->shadow_vqs_enabled = false;