diff mbox series

[V2,03/11] migration: save cpr mode

Message ID 1719776434-435013-4-git-send-email-steven.sistare@oracle.com (mailing list archive)
State New, archived
Headers show
Series Live update: cpr-exec | expand

Commit Message

Steven Sistare June 30, 2024, 7:40 p.m. UTC
Save the mode in CPR state, so the user does not need to explicitly specify
it for the target.  Modify migrate_mode() so it returns the incoming mode on
the target.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
 include/migration/cpr.h |  7 +++++++
 migration/cpr.c         | 23 ++++++++++++++++++++++-
 migration/migration.c   |  1 +
 migration/options.c     |  9 +++++++--
 4 files changed, 37 insertions(+), 3 deletions(-)

Comments

Fabiano Rosas July 17, 2024, 6:39 p.m. UTC | #1
Steve Sistare <steven.sistare@oracle.com> writes:

> Save the mode in CPR state, so the user does not need to explicitly specify
> it for the target.  Modify migrate_mode() so it returns the incoming mode on
> the target.
>
> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
> ---
>  include/migration/cpr.h |  7 +++++++
>  migration/cpr.c         | 23 ++++++++++++++++++++++-
>  migration/migration.c   |  1 +
>  migration/options.c     |  9 +++++++--
>  4 files changed, 37 insertions(+), 3 deletions(-)
>
> diff --git a/include/migration/cpr.h b/include/migration/cpr.h
> index 8e7e705..42b4019 100644
> --- a/include/migration/cpr.h
> +++ b/include/migration/cpr.h
> @@ -8,6 +8,13 @@
>  #ifndef MIGRATION_CPR_H
>  #define MIGRATION_CPR_H
>  
> +#include "qapi/qapi-types-migration.h"
> +
> +#define MIG_MODE_NONE MIG_MODE__MAX

What happens when a QEMU that knows about a new mode migrates into a
QEMU that doesn't know that mode, i.e. sees it as MIG_MODE__MAX?

I'd just use -1.

> +
> +MigMode cpr_get_incoming_mode(void);
> +void cpr_set_incoming_mode(MigMode mode);
> +
>  typedef int (*cpr_walk_fd_cb)(int fd);
>  void cpr_save_fd(const char *name, int id, int fd);
>  void cpr_delete_fd(const char *name, int id);
> diff --git a/migration/cpr.c b/migration/cpr.c
> index 313e74e..1c296c6 100644
> --- a/migration/cpr.c
> +++ b/migration/cpr.c
> @@ -21,10 +21,23 @@
>  typedef QLIST_HEAD(CprFdList, CprFd) CprFdList;
>  
>  typedef struct CprState {
> +    MigMode mode;
>      CprFdList fds;
>  } CprState;
>  
> -static CprState cpr_state;
> +static CprState cpr_state = {
> +    .mode = MIG_MODE_NONE,
> +};
> +
> +MigMode cpr_get_incoming_mode(void)
> +{
> +    return cpr_state.mode;
> +}
> +
> +void cpr_set_incoming_mode(MigMode mode)
> +{
> +    cpr_state.mode = mode;
> +}
>  
>  /****************************************************************************/
>  
> @@ -124,11 +137,19 @@ void cpr_resave_fd(const char *name, int id, int fd)
>  /*************************************************************************/
>  #define CPR_STATE "CprState"
>  
> +static int cpr_state_presave(void *opaque)
> +{
> +    cpr_state.mode = migrate_mode();
> +    return 0;
> +}
> +
>  static const VMStateDescription vmstate_cpr_state = {
>      .name = CPR_STATE,
>      .version_id = 1,
>      .minimum_version_id = 1,
> +    .pre_save = cpr_state_presave,
>      .fields = (VMStateField[]) {
> +        VMSTATE_UINT32(mode, CprState),
>          VMSTATE_QLIST_V(fds, CprState, 1, vmstate_cpr_fd, CprFd, next),
>          VMSTATE_END_OF_LIST()
>      }
> diff --git a/migration/migration.c b/migration/migration.c
> index e394ad7..0f47765 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -411,6 +411,7 @@ void migration_incoming_state_destroy(void)
>          mis->postcopy_qemufile_dst = NULL;
>      }
>  
> +    cpr_set_incoming_mode(MIG_MODE_NONE);
>      yank_unregister_instance(MIGRATION_YANK_INSTANCE);
>  }
>  
> diff --git a/migration/options.c b/migration/options.c
> index 645f550..305397a 100644
> --- a/migration/options.c
> +++ b/migration/options.c
> @@ -22,6 +22,7 @@
>  #include "qapi/qmp/qnull.h"
>  #include "sysemu/runstate.h"
>  #include "migration/colo.h"
> +#include "migration/cpr.h"
>  #include "migration/misc.h"
>  #include "migration.h"
>  #include "migration-stats.h"
> @@ -758,8 +759,12 @@ uint64_t migrate_max_postcopy_bandwidth(void)
>  
>  MigMode migrate_mode(void)
>  {
> -    MigrationState *s = migrate_get_current();
> -    MigMode mode = s->parameters.mode;
> +    MigMode mode = cpr_get_incoming_mode();
> +
> +    if (mode == MIG_MODE_NONE) {
> +        MigrationState *s = migrate_get_current();
> +        mode = s->parameters.mode;
> +    }
>  
>      assert(mode >= 0 && mode < MIG_MODE__MAX);
>      return mode;
Steven Sistare July 18, 2024, 3:47 p.m. UTC | #2
On 7/17/2024 2:39 PM, Fabiano Rosas wrote:
> Steve Sistare <steven.sistare@oracle.com> writes:
> 
>> Save the mode in CPR state, so the user does not need to explicitly specify
>> it for the target.  Modify migrate_mode() so it returns the incoming mode on
>> the target.
>>
>> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
>> ---
>>   include/migration/cpr.h |  7 +++++++
>>   migration/cpr.c         | 23 ++++++++++++++++++++++-
>>   migration/migration.c   |  1 +
>>   migration/options.c     |  9 +++++++--
>>   4 files changed, 37 insertions(+), 3 deletions(-)
>>
>> diff --git a/include/migration/cpr.h b/include/migration/cpr.h
>> index 8e7e705..42b4019 100644
>> --- a/include/migration/cpr.h
>> +++ b/include/migration/cpr.h
>> @@ -8,6 +8,13 @@
>>   #ifndef MIGRATION_CPR_H
>>   #define MIGRATION_CPR_H
>>   
>> +#include "qapi/qapi-types-migration.h"
>> +
>> +#define MIG_MODE_NONE MIG_MODE__MAX
> 
> What happens when a QEMU that knows about a new mode migrates into a
> QEMU that doesn't know that mode, i.e. sees it as MIG_MODE__MAX?
> 
> I'd just use -1.

Good idea, thanks - steve

>> +
>> +MigMode cpr_get_incoming_mode(void);
>> +void cpr_set_incoming_mode(MigMode mode);
>> +
>>   typedef int (*cpr_walk_fd_cb)(int fd);
>>   void cpr_save_fd(const char *name, int id, int fd);
>>   void cpr_delete_fd(const char *name, int id);
>> diff --git a/migration/cpr.c b/migration/cpr.c
>> index 313e74e..1c296c6 100644
>> --- a/migration/cpr.c
>> +++ b/migration/cpr.c
>> @@ -21,10 +21,23 @@
>>   typedef QLIST_HEAD(CprFdList, CprFd) CprFdList;
>>   
>>   typedef struct CprState {
>> +    MigMode mode;
>>       CprFdList fds;
>>   } CprState;
>>   
>> -static CprState cpr_state;
>> +static CprState cpr_state = {
>> +    .mode = MIG_MODE_NONE,
>> +};
>> +
>> +MigMode cpr_get_incoming_mode(void)
>> +{
>> +    return cpr_state.mode;
>> +}
>> +
>> +void cpr_set_incoming_mode(MigMode mode)
>> +{
>> +    cpr_state.mode = mode;
>> +}
>>   
>>   /****************************************************************************/
>>   
>> @@ -124,11 +137,19 @@ void cpr_resave_fd(const char *name, int id, int fd)
>>   /*************************************************************************/
>>   #define CPR_STATE "CprState"
>>   
>> +static int cpr_state_presave(void *opaque)
>> +{
>> +    cpr_state.mode = migrate_mode();
>> +    return 0;
>> +}
>> +
>>   static const VMStateDescription vmstate_cpr_state = {
>>       .name = CPR_STATE,
>>       .version_id = 1,
>>       .minimum_version_id = 1,
>> +    .pre_save = cpr_state_presave,
>>       .fields = (VMStateField[]) {
>> +        VMSTATE_UINT32(mode, CprState),
>>           VMSTATE_QLIST_V(fds, CprState, 1, vmstate_cpr_fd, CprFd, next),
>>           VMSTATE_END_OF_LIST()
>>       }
>> diff --git a/migration/migration.c b/migration/migration.c
>> index e394ad7..0f47765 100644
>> --- a/migration/migration.c
>> +++ b/migration/migration.c
>> @@ -411,6 +411,7 @@ void migration_incoming_state_destroy(void)
>>           mis->postcopy_qemufile_dst = NULL;
>>       }
>>   
>> +    cpr_set_incoming_mode(MIG_MODE_NONE);
>>       yank_unregister_instance(MIGRATION_YANK_INSTANCE);
>>   }
>>   
>> diff --git a/migration/options.c b/migration/options.c
>> index 645f550..305397a 100644
>> --- a/migration/options.c
>> +++ b/migration/options.c
>> @@ -22,6 +22,7 @@
>>   #include "qapi/qmp/qnull.h"
>>   #include "sysemu/runstate.h"
>>   #include "migration/colo.h"
>> +#include "migration/cpr.h"
>>   #include "migration/misc.h"
>>   #include "migration.h"
>>   #include "migration-stats.h"
>> @@ -758,8 +759,12 @@ uint64_t migrate_max_postcopy_bandwidth(void)
>>   
>>   MigMode migrate_mode(void)
>>   {
>> -    MigrationState *s = migrate_get_current();
>> -    MigMode mode = s->parameters.mode;
>> +    MigMode mode = cpr_get_incoming_mode();
>> +
>> +    if (mode == MIG_MODE_NONE) {
>> +        MigrationState *s = migrate_get_current();
>> +        mode = s->parameters.mode;
>> +    }
>>   
>>       assert(mode >= 0 && mode < MIG_MODE__MAX);
>>       return mode;
diff mbox series

Patch

diff --git a/include/migration/cpr.h b/include/migration/cpr.h
index 8e7e705..42b4019 100644
--- a/include/migration/cpr.h
+++ b/include/migration/cpr.h
@@ -8,6 +8,13 @@ 
 #ifndef MIGRATION_CPR_H
 #define MIGRATION_CPR_H
 
+#include "qapi/qapi-types-migration.h"
+
+#define MIG_MODE_NONE MIG_MODE__MAX
+
+MigMode cpr_get_incoming_mode(void);
+void cpr_set_incoming_mode(MigMode mode);
+
 typedef int (*cpr_walk_fd_cb)(int fd);
 void cpr_save_fd(const char *name, int id, int fd);
 void cpr_delete_fd(const char *name, int id);
diff --git a/migration/cpr.c b/migration/cpr.c
index 313e74e..1c296c6 100644
--- a/migration/cpr.c
+++ b/migration/cpr.c
@@ -21,10 +21,23 @@ 
 typedef QLIST_HEAD(CprFdList, CprFd) CprFdList;
 
 typedef struct CprState {
+    MigMode mode;
     CprFdList fds;
 } CprState;
 
-static CprState cpr_state;
+static CprState cpr_state = {
+    .mode = MIG_MODE_NONE,
+};
+
+MigMode cpr_get_incoming_mode(void)
+{
+    return cpr_state.mode;
+}
+
+void cpr_set_incoming_mode(MigMode mode)
+{
+    cpr_state.mode = mode;
+}
 
 /****************************************************************************/
 
@@ -124,11 +137,19 @@  void cpr_resave_fd(const char *name, int id, int fd)
 /*************************************************************************/
 #define CPR_STATE "CprState"
 
+static int cpr_state_presave(void *opaque)
+{
+    cpr_state.mode = migrate_mode();
+    return 0;
+}
+
 static const VMStateDescription vmstate_cpr_state = {
     .name = CPR_STATE,
     .version_id = 1,
     .minimum_version_id = 1,
+    .pre_save = cpr_state_presave,
     .fields = (VMStateField[]) {
+        VMSTATE_UINT32(mode, CprState),
         VMSTATE_QLIST_V(fds, CprState, 1, vmstate_cpr_fd, CprFd, next),
         VMSTATE_END_OF_LIST()
     }
diff --git a/migration/migration.c b/migration/migration.c
index e394ad7..0f47765 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -411,6 +411,7 @@  void migration_incoming_state_destroy(void)
         mis->postcopy_qemufile_dst = NULL;
     }
 
+    cpr_set_incoming_mode(MIG_MODE_NONE);
     yank_unregister_instance(MIGRATION_YANK_INSTANCE);
 }
 
diff --git a/migration/options.c b/migration/options.c
index 645f550..305397a 100644
--- a/migration/options.c
+++ b/migration/options.c
@@ -22,6 +22,7 @@ 
 #include "qapi/qmp/qnull.h"
 #include "sysemu/runstate.h"
 #include "migration/colo.h"
+#include "migration/cpr.h"
 #include "migration/misc.h"
 #include "migration.h"
 #include "migration-stats.h"
@@ -758,8 +759,12 @@  uint64_t migrate_max_postcopy_bandwidth(void)
 
 MigMode migrate_mode(void)
 {
-    MigrationState *s = migrate_get_current();
-    MigMode mode = s->parameters.mode;
+    MigMode mode = cpr_get_incoming_mode();
+
+    if (mode == MIG_MODE_NONE) {
+        MigrationState *s = migrate_get_current();
+        mode = s->parameters.mode;
+    }
 
     assert(mode >= 0 && mode < MIG_MODE__MAX);
     return mode;