Skip to contentSkip to conversation

migrtion: define MigrationState/MigrationIncomingState.state as MigrationStatus

PATCH In review Wei Yang 4 participants 11 messages Jun 21, 2019 – Aug 24, 2019

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 migrtion: define MigrationState/MigrationIncomingState.state as MigrationStatus

No functional change. Add default case to fix warning.

---
 migration/migration.c | 8 +++++++-
 migration/migration.h | 6 +++---
 2 files changed, 10 insertions(+), 4 deletions(-)
migration/migration.c +7 -1
index 2865ae3fa9..0fd2364961 100644
@@ -946,6 +946,8 @@ static void fill_source_migration_info(MigrationInfo *info)
     case MIGRATION_STATUS_CANCELLED:
         info->has_status = true;
         break;
+    default:
+        return;
     }
     info->status = s->state;
 }
@@ -1054,6 +1056,8 @@ static void fill_destination_migration_info(MigrationInfo *info)
         info->has_status = true;
         fill_destination_postcopy_migration_info(info);
         break;
+    default:
+        return;
     }
     info->status = mis->state;
 }
@@ -1446,7 +1450,7 @@ void qmp_migrate_start_postcopy(Error **errp)
 
 /* shared migration helpers */
 
-void migrate_set_state(int *state, int old_state, int new_state)
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state)
 {
     assert(new_state < MIGRATION_STATUS__MAX);
     if (atomic_cmpxchg(state, old_state, new_state) == old_state) {
@@ -1683,6 +1687,8 @@ bool migration_is_idle(void)
         return false;
     case MIGRATION_STATUS__MAX:
         g_assert_not_reached();
+    default:
+        g_assert_not_reached();
     }
 
     return false;
migration/migration.h +3 -3
index 5e8f09c6db..418ee00053 100644
@@ -65,7 +65,7 @@ struct MigrationIncomingState {
 
     QEMUBH *bh;
 
-    int state;
+    MigrationStatus state;
 
     bool have_colo_incoming_thread;
     QemuThread colo_incoming_thread;
@@ -151,7 +151,7 @@ struct MigrationState
     /* params from 'migrate-set-parameters' */
     MigrationParameters parameters;
 
-    int state;
+    MigrationStatus state;
 
     /* State related to return path */
     struct {
@@ -234,7 +234,7 @@ struct MigrationState
     bool decompress_error_check;
 };
 
-void migrate_set_state(int *state, int old_state, int new_state);
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state);
 
 void migration_fd_process_incoming(QEMUFile *f);
 void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp);
Signature · 1 line
2.19.1
author
#1 lore raw
Quoted 2 lines · Wei Yang

No functional change. Add default case to fix warning.

Hi, David & Juan

Do you like this?

Quoted 79 lines

---
migration/migration.c | 8 +++++++-
migration/migration.h | 6 +++---

2 files changed, 10 insertions(+), 4 deletions(-)
migration/migration.c +7 -1
index 2865ae3fa9..0fd2364961 100644
@@ -946,6 +946,8 @@ static void fill_source_migration_info(MigrationInfo *info)
    case MIGRATION_STATUS_CANCELLED:
        info->has_status = true;
        break;
+    default:
+        return;
    }
    info->status = s->state;
 }
@@ -1054,6 +1056,8 @@ static void fill_destination_migration_info(MigrationInfo *info)
        info->has_status = true;
        fill_destination_postcopy_migration_info(info);
        break;
+    default:
+        return;
    }
    info->status = mis->state;
 }
@@ -1446,7 +1450,7 @@ void qmp_migrate_start_postcopy(Error **errp)
 
 /* shared migration helpers */
 
-void migrate_set_state(int *state, int old_state, int new_state)
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state)
 {
    assert(new_state < MIGRATION_STATUS__MAX);
    if (atomic_cmpxchg(state, old_state, new_state) == old_state) {
@@ -1683,6 +1687,8 @@ bool migration_is_idle(void)
        return false;
    case MIGRATION_STATUS__MAX:
        g_assert_not_reached();
+    default:
+        g_assert_not_reached();
    }
 
    return false;
migration/migration.h +3 -3
index 5e8f09c6db..418ee00053 100644
@@ -65,7 +65,7 @@ struct MigrationIncomingState {
 
    QEMUBH *bh;
 
-    int state;
+    MigrationStatus state;
 
    bool have_colo_incoming_thread;
    QemuThread colo_incoming_thread;
@@ -151,7 +151,7 @@ struct MigrationState
    /* params from 'migrate-set-parameters' */
    MigrationParameters parameters;
 
-    int state;
+    MigrationStatus state;
 
    /* State related to return path */
    struct {
@@ -234,7 +234,7 @@ struct MigrationState
    bool decompress_error_check;
 };
 
-void migrate_set_state(int *state, int old_state, int new_state);
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state);
 
 void migration_fd_process_incoming(QEMUFile *f);
 void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp);
Signature · 1 line
2.19.1
Signature · 2 lines
Wei Yang
Help you, Help me
#2 lore raw
Quoted 7 lines · * Wei Yang ([email protected]) wrote:
Quoted 2 lines · Wei Yang

No functional change. Add default case to fix warning.

Hi, David & Juan

Do you like this?

See other reply; but you are making patches a bit faster than I can review them!

Dave

Quoted 72 lines
Quoted 72 lines

---
migration/migration.c | 8 +++++++-
migration/migration.h | 6 +++---

2 files changed, 10 insertions(+), 4 deletions(-)
migration/migration.c +7 -1
index 2865ae3fa9..0fd2364961 100644
@@ -946,6 +946,8 @@ static void fill_source_migration_info(MigrationInfo *info)
    case MIGRATION_STATUS_CANCELLED:
        info->has_status = true;
        break;
+    default:
+        return;
    }
    info->status = s->state;
 }
@@ -1054,6 +1056,8 @@ static void fill_destination_migration_info(MigrationInfo *info)
        info->has_status = true;
        fill_destination_postcopy_migration_info(info);
        break;
+    default:
+        return;
    }
    info->status = mis->state;
 }
@@ -1446,7 +1450,7 @@ void qmp_migrate_start_postcopy(Error **errp)
 
 /* shared migration helpers */
 
-void migrate_set_state(int *state, int old_state, int new_state)
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state)
 {
    assert(new_state < MIGRATION_STATUS__MAX);
    if (atomic_cmpxchg(state, old_state, new_state) == old_state) {
@@ -1683,6 +1687,8 @@ bool migration_is_idle(void)
        return false;
    case MIGRATION_STATUS__MAX:
        g_assert_not_reached();
+    default:
+        g_assert_not_reached();
    }
 
    return false;
migration/migration.h +2 -2
index 5e8f09c6db..418ee00053 100644
@@ -65,7 +65,7 @@ struct MigrationIncomingState {
 
    QEMUBH *bh;
 
-    int state;
+    MigrationStatus state;
 
    bool have_colo_incoming_thread;
    QemuThread colo_incoming_thread;
@@ -151,7 +151,7 @@ struct MigrationState
    /* params from 'migrate-set-parameters' */
    MigrationParameters parameters;
 
-    int state;
+    MigrationStatus state;
 
    /* State related to return path */
    struct {
@@ -234,7 +234,7 @@ struct MigrationState
    bool decompress_error_check;
 };
 
Quoted 11 lines
Quoted 7 lines
migration/migration.h +1 -1
-void migrate_set_state(int *state, int old_state, int new_state);
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state);
 
 void migration_fd_process_incoming(QEMUFile *f);
 void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp);
Signature · 1 line
2.19.1
Signature · 2 lines
Wei Yang
Help you, Help me

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#3 lore raw
Quoted 5 lines · Dr. David Alan Gilbert
Quoted 4 lines · * Wei Yang ([email protected]) wrote:
Quoted 2 lines · Wei Yang

No functional change. Add default case to fix warning.

Quoted 7 lines
Quoted 3 lines

Hi, David & Juan

Do you like this?

See other reply; but you are making patches a bit faster than I can review them!

Sorry for that, my fault.

Quoted 87 lines

Dave

Quoted 72 lines
Quoted 72 lines

---
migration/migration.c | 8 +++++++-
migration/migration.h | 6 +++---

2 files changed, 10 insertions(+), 4 deletions(-)
migration/migration.c +7 -1
index 2865ae3fa9..0fd2364961 100644
@@ -946,6 +946,8 @@ static void fill_source_migration_info(MigrationInfo *info)
    case MIGRATION_STATUS_CANCELLED:
        info->has_status = true;
        break;
+    default:
+        return;
    }
    info->status = s->state;
 }
@@ -1054,6 +1056,8 @@ static void fill_destination_migration_info(MigrationInfo *info)
        info->has_status = true;
        fill_destination_postcopy_migration_info(info);
        break;
+    default:
+        return;
    }
    info->status = mis->state;
 }
@@ -1446,7 +1450,7 @@ void qmp_migrate_start_postcopy(Error **errp)
 
 /* shared migration helpers */
 
-void migrate_set_state(int *state, int old_state, int new_state)
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state)
 {
    assert(new_state < MIGRATION_STATUS__MAX);
    if (atomic_cmpxchg(state, old_state, new_state) == old_state) {
@@ -1683,6 +1687,8 @@ bool migration_is_idle(void)
        return false;
    case MIGRATION_STATUS__MAX:
        g_assert_not_reached();
+    default:
+        g_assert_not_reached();
    }
 
    return false;
migration/migration.h +2 -2
index 5e8f09c6db..418ee00053 100644
@@ -65,7 +65,7 @@ struct MigrationIncomingState {
 
    QEMUBH *bh;
 
-    int state;
+    MigrationStatus state;
 
    bool have_colo_incoming_thread;
    QemuThread colo_incoming_thread;
@@ -151,7 +151,7 @@ struct MigrationState
    /* params from 'migrate-set-parameters' */
    MigrationParameters parameters;
 
-    int state;
+    MigrationStatus state;
 
    /* State related to return path */
    struct {
@@ -234,7 +234,7 @@ struct MigrationState
    bool decompress_error_check;
 };
 
Quoted 11 lines
Quoted 7 lines
migration/migration.h +1 -1
-void migrate_set_state(int *state, int old_state, int new_state);
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state);
 
 void migration_fd_process_incoming(QEMUFile *f);
 void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp);
Signature · 1 line
2.19.1
Signature · 2 lines
Wei Yang
Help you, Help me

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me
author
#4 lore raw
In reply to Dr. David Alan Gilbert
Quoted 11 lines · Dr. David Alan Gilbert
Quoted 7 lines · * Wei Yang ([email protected]) wrote:
Quoted 2 lines · Wei Yang

No functional change. Add default case to fix warning.

Hi, David & Juan

Do you like this?

See other reply; but you are making patches a bit faster than I can review them!

Can I post v2 with new_state changed to use MigrationStatus?

Or when you prefer me to send a v2?

Quoted 2 lines

Dave

Signature · 2 lines
Wei Yang
Help you, Help me
#5 lore raw
In reply to Wei Yang
Quoted 1 line · * Wei Yang ([email protected]) wrote:

No functional change. Add default case to fix warning.

I think the problem with this is that migrate_set_state uses an atomic_cmpxchg and so we have to be careful that the type we use is compatible with that.
MigrationStatus is an enum and I think compilers are allowed to choose the types of that; so I'm not sure we're guaranteed that an enum is always OK for the atomic_cmpxchg, and if it is then we also might have to make the old_state and new_state variables match.

Dave

Quoted 80 lines
---
 migration/migration.c | 8 +++++++-
 migration/migration.h | 6 +++---
 2 files changed, 10 insertions(+), 4 deletions(-)
migration/migration.c +7 -1
index 2865ae3fa9..0fd2364961 100644
@@ -946,6 +946,8 @@ static void fill_source_migration_info(MigrationInfo *info)
     case MIGRATION_STATUS_CANCELLED:
         info->has_status = true;
         break;
+    default:
+        return;
     }
     info->status = s->state;
 }
@@ -1054,6 +1056,8 @@ static void fill_destination_migration_info(MigrationInfo *info)
         info->has_status = true;
         fill_destination_postcopy_migration_info(info);
         break;
+    default:
+        return;
     }
     info->status = mis->state;
 }
@@ -1446,7 +1450,7 @@ void qmp_migrate_start_postcopy(Error **errp)
 
 /* shared migration helpers */
 
-void migrate_set_state(int *state, int old_state, int new_state)
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state)
 {
     assert(new_state < MIGRATION_STATUS__MAX);
     if (atomic_cmpxchg(state, old_state, new_state) == old_state) {
@@ -1683,6 +1687,8 @@ bool migration_is_idle(void)
         return false;
     case MIGRATION_STATUS__MAX:
         g_assert_not_reached();
+    default:
+        g_assert_not_reached();
     }
 
     return false;
migration/migration.h +3 -3
index 5e8f09c6db..418ee00053 100644
@@ -65,7 +65,7 @@ struct MigrationIncomingState {
 
     QEMUBH *bh;
 
-    int state;
+    MigrationStatus state;
 
     bool have_colo_incoming_thread;
     QemuThread colo_incoming_thread;
@@ -151,7 +151,7 @@ struct MigrationState
     /* params from 'migrate-set-parameters' */
     MigrationParameters parameters;
 
-    int state;
+    MigrationStatus state;
 
     /* State related to return path */
     struct {
@@ -234,7 +234,7 @@ struct MigrationState
     bool decompress_error_check;
 };
 
-void migrate_set_state(int *state, int old_state, int new_state);
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state);
 
 void migration_fd_process_incoming(QEMUFile *f);
 void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp);
Signature · 1 line
2.19.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#6 lore raw
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 1 line · * Wei Yang ([email protected]) wrote:

No functional change. Add default case to fix warning.

I think the problem with this is that migrate_set_state uses an atomic_cmpxchg and so we have to be careful that the type we use is compatible with that.
MigrationStatus is an enum and I think compilers are allowed to choose the types of that; so I'm not sure we're guaranteed that an enum is always OK for the atomic_cmpxchg, and if it is

Took a look into the definition of atomic_cmpxchg, which finally calls

* __atomic_compare_exchange_n for c++11
* __sync_val_compare_and_swap

Both of them take two pointers to compare and exchange its content.

Per C99 standard, http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf,
it mentioned:

Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.

Based on this, I think atomic_cmpxchg should work fine with enum.

Quoted 3 lines

then we also might have to make the old_state and new_state variables match.

You are right.

Quoted 84 lines

Dave

Quoted 80 lines
---
 migration/migration.c | 8 +++++++-
 migration/migration.h | 6 +++---
 2 files changed, 10 insertions(+), 4 deletions(-)
migration/migration.c +7 -1
index 2865ae3fa9..0fd2364961 100644
@@ -946,6 +946,8 @@ static void fill_source_migration_info(MigrationInfo *info)
     case MIGRATION_STATUS_CANCELLED:
         info->has_status = true;
         break;
+    default:
+        return;
     }
     info->status = s->state;
 }
@@ -1054,6 +1056,8 @@ static void fill_destination_migration_info(MigrationInfo *info)
         info->has_status = true;
         fill_destination_postcopy_migration_info(info);
         break;
+    default:
+        return;
     }
     info->status = mis->state;
 }
@@ -1446,7 +1450,7 @@ void qmp_migrate_start_postcopy(Error **errp)
 
 /* shared migration helpers */
 
-void migrate_set_state(int *state, int old_state, int new_state)
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state)
 {
     assert(new_state < MIGRATION_STATUS__MAX);
     if (atomic_cmpxchg(state, old_state, new_state) == old_state) {
@@ -1683,6 +1687,8 @@ bool migration_is_idle(void)
         return false;
     case MIGRATION_STATUS__MAX:
         g_assert_not_reached();
+    default:
+        g_assert_not_reached();
     }
 
     return false;
migration/migration.h +3 -3
index 5e8f09c6db..418ee00053 100644
@@ -65,7 +65,7 @@ struct MigrationIncomingState {
 
     QEMUBH *bh;
 
-    int state;
+    MigrationStatus state;
 
     bool have_colo_incoming_thread;
     QemuThread colo_incoming_thread;
@@ -151,7 +151,7 @@ struct MigrationState
     /* params from 'migrate-set-parameters' */
     MigrationParameters parameters;
 
-    int state;
+    MigrationStatus state;
 
     /* State related to return path */
     struct {
@@ -234,7 +234,7 @@ struct MigrationState
     bool decompress_error_check;
 };
 
-void migrate_set_state(int *state, int old_state, int new_state);
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state);
 
 void migration_fd_process_incoming(QEMUFile *f);
 void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp);
Signature · 1 line
2.19.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me
#7 lore raw
Quoted 21 lines · * Wei Yang ([email protected]) wrote:
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 1 line · * Wei Yang ([email protected]) wrote:

No functional change. Add default case to fix warning.

I think the problem with this is that migrate_set_state uses an atomic_cmpxchg and so we have to be careful that the type we use is compatible with that.
MigrationStatus is an enum and I think compilers are allowed to choose the types of that; so I'm not sure we're guaranteed that an enum is always OK for the atomic_cmpxchg, and if it is

Took a look into the definition of atomic_cmpxchg, which finally calls

* __atomic_compare_exchange_n for c++11
* __sync_val_compare_and_swap

Both of them take two pointers to compare and exchange its content.

Per C99 standard, http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf,
it mentioned:

Quoted 6 lines

Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.

Based on this, I think atomic_cmpxchg should work fine with enum.

Hmm OK, but I'd need you to test n some 32bit and other comp=ilers etc; make sure it works on 32bit, clang, gcc, 32bit ARM etc - because otherwise I'm going to have to worry about checking all those.

Dave

Quoted 82 lines
Quoted 3 lines

then we also might have to make the old_state and new_state variables match.

You are right.

Quoted 77 lines

Dave

Quoted 75 lines
---
 migration/migration.c | 8 +++++++-
 migration/migration.h | 6 +++---
 2 files changed, 10 insertions(+), 4 deletions(-)
migration/migration.c +7 -1
index 2865ae3fa9..0fd2364961 100644
@@ -946,6 +946,8 @@ static void fill_source_migration_info(MigrationInfo *info)
     case MIGRATION_STATUS_CANCELLED:
         info->has_status = true;
         break;
+    default:
+        return;
     }
     info->status = s->state;
 }
@@ -1054,6 +1056,8 @@ static void fill_destination_migration_info(MigrationInfo *info)
         info->has_status = true;
         fill_destination_postcopy_migration_info(info);
         break;
+    default:
+        return;
     }
     info->status = mis->state;
 }
@@ -1446,7 +1450,7 @@ void qmp_migrate_start_postcopy(Error **errp)
 
 /* shared migration helpers */
 
-void migrate_set_state(int *state, int old_state, int new_state)
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state)
 {
     assert(new_state < MIGRATION_STATUS__MAX);
     if (atomic_cmpxchg(state, old_state, new_state) == old_state) {
@@ -1683,6 +1687,8 @@ bool migration_is_idle(void)
         return false;
     case MIGRATION_STATUS__MAX:
         g_assert_not_reached();
+    default:
+        g_assert_not_reached();
     }
 
     return false;
migration/migration.h +3 -3
index 5e8f09c6db..418ee00053 100644
@@ -65,7 +65,7 @@ struct MigrationIncomingState {
 
     QEMUBH *bh;
 
-    int state;
+    MigrationStatus state;
 
     bool have_colo_incoming_thread;
     QemuThread colo_incoming_thread;
@@ -151,7 +151,7 @@ struct MigrationState
     /* params from 'migrate-set-parameters' */
     MigrationParameters parameters;
 
-    int state;
+    MigrationStatus state;
 
     /* State related to return path */
     struct {
@@ -234,7 +234,7 @@ struct MigrationState
     bool decompress_error_check;
 };
 
-void migrate_set_state(int *state, int old_state, int new_state);
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state);
 
Quoted 11 lines
Quoted 7 lines
Quoted 5 lines
migration/migration.h +0 -0
 void migration_fd_process_incoming(QEMUFile *f);
 void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp);
Signature · 1 line
2.19.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#8 lore raw
Quoted 27 lines · * Dr. David Alan Gilbert ([email protected]) wrote:
Quoted 26 lines · * Wei Yang ([email protected]) wrote:
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 1 line · * Wei Yang ([email protected]) wrote:

No functional change. Add default case to fix warning.

I think the problem with this is that migrate_set_state uses an atomic_cmpxchg and so we have to be careful that the type we use is compatible with that.
MigrationStatus is an enum and I think compilers are allowed to choose the types of that; so I'm not sure we're guaranteed that an enum is always OK for the atomic_cmpxchg, and if it is

Took a look into the definition of atomic_cmpxchg, which finally calls

* __atomic_compare_exchange_n for c++11
* __sync_val_compare_and_swap

Both of them take two pointers to compare and exchange its content.

Per C99 standard, http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf,
it mentioned:

Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.

Quoted 5 lines
Quoted 1 line

Based on this, I think atomic_cmpxchg should work fine with enum.

Hmm OK, but I'd need you to test n some 32bit and other comp=ilers etc; make sure it works on 32bit, clang, gcc, 32bit ARM etc - because otherwise I'm going to have to worry about checking all those.

Actually since QEMU is defined to be C99, the test is to check with some C99 compilers; eblake assures me that in theory C11 should be OK, but C99 and our atomics are more of an interesting question.

Dave

Quoted 92 lines

Dave

Quoted 90 lines
Quoted 3 lines

then we also might have to make the old_state and new_state variables match.

You are right.

Quoted 84 lines

Dave

Quoted 80 lines
---
 migration/migration.c | 8 +++++++-
 migration/migration.h | 6 +++---
 2 files changed, 10 insertions(+), 4 deletions(-)
migration/migration.c +7 -1
index 2865ae3fa9..0fd2364961 100644
@@ -946,6 +946,8 @@ static void fill_source_migration_info(MigrationInfo *info)
     case MIGRATION_STATUS_CANCELLED:
         info->has_status = true;
         break;
+    default:
+        return;
     }
     info->status = s->state;
 }
@@ -1054,6 +1056,8 @@ static void fill_destination_migration_info(MigrationInfo *info)
         info->has_status = true;
         fill_destination_postcopy_migration_info(info);
         break;
+    default:
+        return;
     }
     info->status = mis->state;
 }
@@ -1446,7 +1450,7 @@ void qmp_migrate_start_postcopy(Error **errp)
 
 /* shared migration helpers */
 
-void migrate_set_state(int *state, int old_state, int new_state)
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state)
 {
     assert(new_state < MIGRATION_STATUS__MAX);
     if (atomic_cmpxchg(state, old_state, new_state) == old_state) {
@@ -1683,6 +1687,8 @@ bool migration_is_idle(void)
         return false;
     case MIGRATION_STATUS__MAX:
         g_assert_not_reached();
+    default:
+        g_assert_not_reached();
     }
 
     return false;
migration/migration.h +3 -3
index 5e8f09c6db..418ee00053 100644
@@ -65,7 +65,7 @@ struct MigrationIncomingState {
 
     QEMUBH *bh;
 
-    int state;
+    MigrationStatus state;
 
     bool have_colo_incoming_thread;
     QemuThread colo_incoming_thread;
@@ -151,7 +151,7 @@ struct MigrationState
     /* params from 'migrate-set-parameters' */
     MigrationParameters parameters;
 
-    int state;
+    MigrationStatus state;
 
     /* State related to return path */
     struct {
@@ -234,7 +234,7 @@ struct MigrationState
     bool decompress_error_check;
 };
 
-void migrate_set_state(int *state, int old_state, int new_state);
+void migrate_set_state(MigrationStatus *state, int old_state, int new_state);
 
 void migration_fd_process_incoming(QEMUFile *f);
 void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp);
Signature · 1 line
2.19.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Quoted 5 lines
Quoted 3 lines
Signature · 2 lines
Wei Yang
Help you, Help me

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#9 lore raw
In reply to Wei Yang
Quoted 2 lines · Wei Yang
Quoted 1 line · Dr. David Alan Gilbert

* Wei Yang ([email protected]) wrote:

Typo in the subject line: migrtion should be migration

Quoted 9 lines
Quoted 8 lines
Quoted 1 line

No functional change. Add default case to fix warning.

I think the problem with this is that migrate_set_state uses an atomic_cmpxchg and so we have to be careful that the type we use is compatible with that.
MigrationStatus is an enum and I think compilers are allowed to choose the types of that; so I'm not sure we're guaranteed that an enum is always OK for the atomic_cmpxchg, and if it is

Quoted 4 lines

Took a look into the definition of atomic_cmpxchg, which finally calls

* __atomic_compare_exchange_n for c++11
* __sync_val_compare_and_swap

Those are compiler-defined macros, so you have to consult the compiler documentation to see if they state what happens when invoked on an enum type. You also have to check whether our macro typeof_strip_qual(enum_type) produces 'int' or something else.

C99 doesn't specify _Atomic at all (which is why we handrolled our own atomic.h built on top of compiler primitives, instead of using <stdatomic.h>). But reading C11, I see that 6.7.2.4 states that _Atomic(type) is okay except for:

"The type name in an atomic type specifier shall not refer to an array type, a function type, an atomic type, or a qualified type."

which does NOT preclude the use of _Atomic(enum_type), so presumably compilers have to be prepared to handle an atomic enum type. Still, it's rather shaky ground if you can't prove compilers handle it correctly.

Quoted 6 lines

Both of them take two pointers to compare and exchange its content.

Per C99 standard, http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf,
it mentioned:

Quoted 6 lines

Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.

Based on this, I think atomic_cmpxchg should work fine with enum.

What C99 says is rather weak; you really want to be basing your decisions on atomics based on C11 or later.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
author
#10 lore raw
Quoted 30 lines · Eric Blake
Quoted 2 lines · Wei Yang
Quoted 1 line · Dr. David Alan Gilbert

* Wei Yang ([email protected]) wrote:

Typo in the subject line: migrtion should be migration

Quoted 9 lines
Quoted 8 lines
Quoted 1 line

No functional change. Add default case to fix warning.

I think the problem with this is that migrate_set_state uses an atomic_cmpxchg and so we have to be careful that the type we use is compatible with that.
MigrationStatus is an enum and I think compilers are allowed to choose the types of that; so I'm not sure we're guaranteed that an enum is always OK for the atomic_cmpxchg, and if it is

Quoted 4 lines

Took a look into the definition of atomic_cmpxchg, which finally calls

* __atomic_compare_exchange_n for c++11
* __sync_val_compare_and_swap

Those are compiler-defined macros, so you have to consult the compiler documentation to see if they state what happens when invoked on an enum type. You also have to check whether our macro typeof_strip_qual(enum_type) produces 'int' or something else.

C99 doesn't specify _Atomic at all (which is why we handrolled our own atomic.h built on top of compiler primitives, instead of using <stdatomic.h>). But reading C11, I see that 6.7.2.4 states that _Atomic(type) is okay except for:

Quoted 7 lines

"The type name in an atomic type specifier shall not refer to an array type, a function type, an atomic type, or a qualified type."

which does NOT preclude the use of _Atomic(enum_type), so presumably compilers have to be prepared to handle an atomic enum type. Still, it's rather shaky ground if you can't prove compilers handle it correctly.

Sounds this is a dark area for all those compilers. I would keep the code untouched now.

Thanks

Quoted 23 lines
Quoted 7 lines

Both of them take two pointers to compare and exchange its content.

Per C99 standard, http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf,
it mentioned:

Quoted 6 lines

Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.

Based on this, I think atomic_cmpxchg should work fine with enum.

What C99 says is rather weak; you really want to be basing your decisions on atomics based on C11 or later.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Signature · 2 lines
Wei Yang
Help you, Help me