Skip to contentSkip to conversation

runstate/migrate: Two more transitions

PATCH In review Dr. David Alan Gilbert (git) 4 participants 8 messages Aug 4, 2017 – Sep 9, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 runstate/migrate: Two more transitions

From: "Dr. David Alan Gilbert" <[email protected]>

There's a race if someone does a 'stop' near the end of migrate; the migration process goes through two runstates:
'finish migrate'
'postmigrate'

If the user issues a 'stop' between the two we end up with invalid state transitions.
Add the transitions as valid.

---
 vl.c | 2 ++
 1 file changed, 2 insertions(+)
vl.c +2 -0
index 99fcfa0442..bacb03f49d 100644
@@ -621,6 +621,7 @@ static const RunStateTransition runstate_transitions_def[] = {
 
     { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
     { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
+    { RUN_STATE_PAUSED, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_PAUSED, RUN_STATE_PRELAUNCH },
     { RUN_STATE_PAUSED, RUN_STATE_COLO},
 
@@ -633,6 +634,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
 
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
+    { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PAUSED },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_COLO},
Signature · 1 line
2.13.3
#1 lore raw
Quoted 29 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

There's a race if someone does a 'stop' near the end of migrate; the migration process goes through two runstates:
'finish migrate'
'postmigrate'

If the user issues a 'stop' between the two we end up with invalid state transitions.
Add the transitions as valid.

---
 vl.c | 2 ++
 1 file changed, 2 insertions(+)
vl.c +1 -0
index 99fcfa0442..bacb03f49d 100644
@@ -621,6 +621,7 @@ static const RunStateTransition runstate_transitions_def[] = {
 
     { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
     { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
+    { RUN_STATE_PAUSED, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_PAUSED, RUN_STATE_PRELAUNCH },
     { RUN_STATE_PAUSED, RUN_STATE_COLO},
 

vl.c static const RunStateTransition runstate_transitions_def[] = { · line 640

Quoted 7 lines
vl.c +1 -0
@@ -633,6 +634,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
 
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
+    { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PAUSED },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_COLO},

Do we need this as well?

{ RUN_STATE_POSTMIGRATE, RUN_STATE_PAUSED },

Signature · 1 line
Peter Xu
#2 lore raw
Quoted 40 lines · * Peter Xu ([email protected]) wrote:
Quoted 29 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

There's a race if someone does a 'stop' near the end of migrate; the migration process goes through two runstates:
'finish migrate'
'postmigrate'

If the user issues a 'stop' between the two we end up with invalid state transitions.
Add the transitions as valid.

---
 vl.c | 2 ++
 1 file changed, 2 insertions(+)
vl.c +1 -0
index 99fcfa0442..bacb03f49d 100644
@@ -621,6 +621,7 @@ static const RunStateTransition runstate_transitions_def[] = {
 
     { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
     { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
+    { RUN_STATE_PAUSED, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_PAUSED, RUN_STATE_PRELAUNCH },
     { RUN_STATE_PAUSED, RUN_STATE_COLO},
 

vl.c static const RunStateTransition runstate_transitions_def[] = { · line 640

Quoted 7 lines
vl.c +1 -0
@@ -633,6 +634,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
 
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
+    { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PAUSED },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_COLO},

Do we need this as well?

Quoted 1 line

{ RUN_STATE_POSTMIGRATE, RUN_STATE_PAUSED },

Apparently not:

(qemu) migrate "exec:cat > /dev/null"
(qemu) infomigrate
unknown command: 'infomigrate'
(qemu) info status
VM status: paused (postmigrate)
(qemu) stop
(qemu) info status
VM status: paused (postmigrate)
(qemu)

so doing a stop at that point doesn't seem to cause any problem.

Dave

Quoted 2 lines
Signature · 1 line
Peter Xu

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

Reviewed-by
#3 lore raw
Quoted 56 lines · Dr. David Alan Gilbert
Quoted 40 lines · * Peter Xu ([email protected]) wrote:
Quoted 29 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

There's a race if someone does a 'stop' near the end of migrate; the migration process goes through two runstates:
'finish migrate'
'postmigrate'

If the user issues a 'stop' between the two we end up with invalid state transitions.
Add the transitions as valid.

---
 vl.c | 2 ++
 1 file changed, 2 insertions(+)
vl.c +1 -0
index 99fcfa0442..bacb03f49d 100644
@@ -621,6 +621,7 @@ static const RunStateTransition runstate_transitions_def[] = {
 
     { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
     { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
+    { RUN_STATE_PAUSED, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_PAUSED, RUN_STATE_PRELAUNCH },
     { RUN_STATE_PAUSED, RUN_STATE_COLO},
 

vl.c static const RunStateTransition runstate_transitions_def[] = { · line 640

Quoted 7 lines
vl.c +1 -0
@@ -633,6 +634,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
 
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
+    { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PAUSED },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_COLO},

Do we need this as well?

Quoted 1 line

{ RUN_STATE_POSTMIGRATE, RUN_STATE_PAUSED },

Apparently not:

(qemu) migrate "exec:cat > /dev/null"
(qemu) infomigrate
unknown command: 'infomigrate'
(qemu) info status
VM status: paused (postmigrate)
(qemu) stop
(qemu) info status
VM status: paused (postmigrate)
(qemu)

Quoted 1 line

so doing a stop at that point doesn't seem to cause any problem.

Yes. Thanks.

Signature · 1 line
Peter Xu
Reviewed-by on v1 1/1
#4 lore raw
In reply to Dr. David Alan Gilbert (git)
Quoted 7 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

There's a race if someone does a 'stop' near the end of migrate; the migration process goes through two runstates:
'finish migrate'
'postmigrate'

Quoted 5 lines

If the user issues a 'stop' between the two we end up with invalid state transitions.
Add the transitions as valid.

To answer Peter question:

int vm_stop(RunState state)
{
.... we don't care about this case ....

return do_vm_stop(state);
}

static int do_vm_stop(RunState state)

{
    int ret = 0;

    if (runstate_is_running()) {
        cpu_disable_ticks();
        pause_all_vcpus();
        runstate_set(state);
        vm_state_notify(0, state);
        qapi_event_send_stop(&error_abort);
    }

    bdrv_drain_all();
    replay_disable_events();
    ret = bdrv_flush_all();

    return ret;
}

int runstate_is_running(void)

{
    return runstate_check(RUN_STATE_RUNNING);
}

So, "stop" only changes states when we are in RUNNING state. The idea was that after migration, the only valid command (as in the film "it should do something")is "run".

Later, Juan.

#5 lore raw
Quoted 46 lines · Juan Quintela
Quoted 7 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

There's a race if someone does a 'stop' near the end of migrate; the migration process goes through two runstates:
'finish migrate'
'postmigrate'

Quoted 5 lines

If the user issues a 'stop' between the two we end up with invalid state transitions.
Add the transitions as valid.

To answer Peter question:

int vm_stop(RunState state)
{
.... we don't care about this case ....

return do_vm_stop(state);
}

static int do_vm_stop(RunState state)

{
    int ret = 0;

    if (runstate_is_running()) {
        cpu_disable_ticks();
        pause_all_vcpus();
        runstate_set(state);
        vm_state_notify(0, state);
        qapi_event_send_stop(&error_abort);
    }

    bdrv_drain_all();
    replay_disable_events();
    ret = bdrv_flush_all();

    return ret;
}

int runstate_is_running(void)

Quoted 8 lines
{
    return runstate_check(RUN_STATE_RUNNING);
}

So, "stop" only changes states when we are in RUNNING state. The idea was that after migration, the only valid command (as in the film "it should do something")is "run".

Thanks for the details. :)

Signature · 1 line
Peter Xu
#6 lore raw
In reply to Dr. David Alan Gilbert (git)
Quoted 7 lines · * Dr. David Alan Gilbert (git) ([email protected]) wrote:

From: "Dr. David Alan Gilbert" <[email protected]>

There's a race if someone does a 'stop' near the end of migrate; the migration process goes through two runstates:
'finish migrate'
'postmigrate'

Quoted 5 lines

If the user issues a 'stop' between the two we end up with invalid state transitions.
Add the transitions as valid.

Queued

Quoted 28 lines
---
 vl.c | 2 ++
 1 file changed, 2 insertions(+)
vl.c +2 -0
index 99fcfa0442..bacb03f49d 100644
@@ -621,6 +621,7 @@ static const RunStateTransition runstate_transitions_def[] = {
 
     { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
     { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
+    { RUN_STATE_PAUSED, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_PAUSED, RUN_STATE_PRELAUNCH },
     { RUN_STATE_PAUSED, RUN_STATE_COLO},
 
@@ -633,6 +634,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
 
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
+    { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PAUSED },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_COLO},
Signature · 1 line
2.13.3

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

#7 lore raw
Quoted 22 lines · Dr. David Alan Gilbert
Quoted 10 lines

There's a race if someone does a 'stop' near the end of migrate; the migration process goes through two runstates:
'finish migrate'
'postmigrate'

If the user issues a 'stop' between the two we end up with invalid state transitions.
Add the transitions as valid.

Queued

Quoted 10 lines
---
 vl.c | 2 ++
 1 file changed, 2 insertions(+)
vl.c +0 -0
index 99fcfa0442..bacb03f49d 100644
@@ -621,6 +621,7 @@ static const RunStateTransition runstate_transitions_def[] = {
 
Quoted 3 lines

vl.c static const RunStateTransition runstate_transitions_def[] = { · line 624

Quoted 3 lines
vl.c +1 -0
     { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
     { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
+    { RUN_STATE_PAUSED, RUN_STATE_POSTMIGRATE },

There is:

    if (s->state == MIGRATION_STATUS_COMPLETED) {
        ...
        runstate_set(RUN_STATE_POSTMIGRATE);
    } else {
        ...
        if (old_vm_running && !entered_postcopy) {
            vm_start();
        } else {
            if (runstate_check(RUN_STATE_FINISH_MIGRATE)) {
                runstate_set(RUN_STATE_POSTMIGRATE);
            }
        }
    }

Maybe the runstate_check should be in the "then" branch too, instead of adding this transition?

Paolo

Quoted 15 lines
Quoted 15 lines
vl.c +1 -0
     { RUN_STATE_PAUSED, RUN_STATE_PRELAUNCH },
     { RUN_STATE_PAUSED, RUN_STATE_COLO},
 
@@ -633,6 +634,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
 
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
+    { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PAUSED },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_PRELAUNCH },
     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_COLO},
Signature · 1 line
2.13.3