Skip to contentSkip to conversation

qmp: handle stop/cont in INMIGRATE state

PATCH Superseded Paolo Bonzini 2 participants 6 messages Oct 18, 2012 – Oct 19, 2012

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qmp: handle stop/cont in INMIGRATE state

Right now, stop followed by an incoming migration will let the virtual machine start. cont before an incoming migration instead will fail.

This is bad because the actual behavior is not predictable; it is racy with respect to the start of the incoming migration. That's because incoming migration is blocking, and thus will delay the processing of stop/cont until the end of the migration.

In addition, there's nothing that really prevents the user from typing the block device's passwords before incoming migration is done, so we may as well allow that.

Both things can be fixed by just toggling the autostart variable when stop/cont are called in INMIGRATE state.

---
 qmp.c | 17 +++++++++++------

1 file modificato, 11 inserzioni(+), 6 rimozioni(-)

qmp.c +11 -6
index 36c54c5..2c8d559 100644
@@ -85,7 +85,11 @@ void qmp_quit(Error **err)
 
 void qmp_stop(Error **errp)
 {
-    vm_stop(RUN_STATE_PAUSED);
+    if (runstate_check(RUN_STATE_INMIGRATE)) {
+        autostart = 0;
+    } else {
+        vm_stop(RUN_STATE_PAUSED);
+    }
 }
 
 void qmp_system_reset(Error **errp)
@@ -144,10 +148,7 @@ void qmp_cont(Error **errp)
 {
     Error *local_err = NULL;
 
-    if (runstate_check(RUN_STATE_INMIGRATE)) {
-        error_set(errp, QERR_MIGRATION_EXPECTED);
-        return;
-    } else if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
+    if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
                runstate_check(RUN_STATE_SHUTDOWN)) {
         error_set(errp, QERR_RESET_REQUIRED);
         return;
@@ -162,7 +163,11 @@ void qmp_cont(Error **errp)
         return;
     }
 
-    vm_start();
+    if (runstate_check(RUN_STATE_INMIGRATE)) {
+        autostart = 1;
+    } else {
+        vm_start();
+    }
 }
 
 void qmp_system_wakeup(Error **errp)
Signature · 1 line
1.7.12.1
#1 lore raw
Quoted 8 lines · On Thu, 18 Oct 2012 11:14:22 +0200 Paolo Bonzini <[email protected]> wrote:

Right now, stop followed by an incoming migration will let the virtual machine start. cont before an incoming migration instead will fail.

This is bad because the actual behavior is not predictable; it is racy with respect to the start of the incoming migration. That's because incoming migration is blocking, and thus will delay the processing of stop/cont until the end of the migration.

That's not correct if "delay" means "it will be queued" (I guess you didn't mean that, but "blocking" followed "will delay the processing" gives that impression).

What happens is that a stop command while in INMIGRATE state will just be ignored. Actually, any stops while in a state that pauses vCPUs are ignored.

Also, I don't understand what you meant by "racy", care to elaborate?

Quoted 3 lines

In addition, there's nothing that really prevents the user from typing the block device's passwords before incoming migration is done, so we may as well allow that.

Have you tried it? We seem to support that already.

Quoted 13 lines

Both things can be fixed by just toggling the autostart variable when stop/cont are called in INMIGRATE state.

---
 qmp.c | 17 +++++++++++------

1 file modificato, 11 inserzioni(+), 6 rimozioni(-)

qmp.c +0 -0
index 36c54c5..2c8d559 100644

qmp.c void qmp_quit(Error **err) · line 89

Quoted 6 lines
qmp.c +2 -1
@@ -85,7 +85,11 @@ void qmp_quit(Error **err)
 
 void qmp_stop(Error **errp)
 {
-    vm_stop(RUN_STATE_PAUSED);
+    if (runstate_check(RUN_STATE_INMIGRATE)) {
+        autostart = 0;

I'm not against this change, but it has two issues. First, after the incoming migration ends, the state will be PRELAUNCH; so we have to decide if this is a good state for this and if it is, then we have to update its schema doc.

The other (possible) problem is that we're changing the semantics of the stop command on INMIGRATE. I can't tell if this actually matters, but it could come back in the form of compatibility breakage. This is also true for the cont change below.

qmp.c void qmp_cont(Error **errp) · line 148

Quoted 12 lines
qmp.c +3 -2
+    } else {
+        vm_stop(RUN_STATE_PAUSED);
+    }
 }
 
 void qmp_system_reset(Error **errp)
@@ -144,10 +148,7 @@ void qmp_cont(Error **errp)
 {
     Error *local_err = NULL;
 
-    if (runstate_check(RUN_STATE_INMIGRATE)) {
-        error_set(errp, QERR_MIGRATION_EXPECTED);

Please, drop QERR_MIGRATION_EXPECTED.

Quoted 19 lines
qmp.c +6 -3
-        return;
-    } else if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
+    if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
                runstate_check(RUN_STATE_SHUTDOWN)) {
         error_set(errp, QERR_RESET_REQUIRED);
         return;
@@ -162,7 +163,11 @@ void qmp_cont(Error **errp)
         return;
     }
 
-    vm_start();
+    if (runstate_check(RUN_STATE_INMIGRATE)) {
+        autostart = 1;
+    } else {
+        vm_start();
+    }
 }
 
 void qmp_system_wakeup(Error **errp)
#2 lore raw
Quoted 5 lines

What happens is that a stop command while in INMIGRATE state will just be ignored. Actually, any stops while in a state that pauses vCPUs are ignored.

Also, I don't understand what you meant by "racy", care to elaborate?

    Case 1:                               Case 2:
    user runs qemu -incoming -S           user runs qemu -incoming -S
    source connects                       cont command received
    cont command received                 source connects

In case 1, the VM is resumed at the end of migration, in case 2 it is not and an error is reported on QMP. After this patch, it is always resumed.

    Case 1:                               Case 2:
    user runs qemu -incoming              user runs qemu -incoming
    source connects                       stop command received
    stop command received                 source connects

In case 1, the VM runs for a blink of an eye and then stops. In case 2 it just starts, with no error reported.

Quoted 5 lines
Quoted 3 lines

In addition, there's nothing that really prevents the user from typing the block device's passwords before incoming migration is done, so we may as well allow that.

Have you tried it? We seem to support that already.

With HMP yes, with QMP no. You just get "An incoming migration is expected before this command can be executed" and no clue that disks are encrypted.

Paolo

#3 lore raw
Quoted 27 lines · On Fri, 19 Oct 2012 05:27:29 -0400 (EDT) Paolo Bonzini <[email protected]>…
Quoted 5 lines

What happens is that a stop command while in INMIGRATE state will just be ignored. Actually, any stops while in a state that pauses vCPUs are ignored.

Also, I don't understand what you meant by "racy", care to elaborate?

    Case 1:                               Case 2:
    user runs qemu -incoming -S           user runs qemu -incoming -S
    source connects                       cont command received
    cont command received                 source connects

In case 1, the VM is resumed at the end of migration, in case 2 it is not and an error is reported on QMP. After this patch, it is always resumed.

    Case 1:                               Case 2:
    user runs qemu -incoming              user runs qemu -incoming
    source connects                       stop command received
    stop command received                 source connects

In case 1, the VM runs for a blink of an eye and then stops. In case 2 it just starts, with no error reported.

Quoted 4 lines
Quoted 3 lines

In addition, there's nothing that really prevents the user from typing the block device's passwords before incoming migration is done, so we may as well allow that.

Quoted 5 lines
Quoted 1 line

Have you tried it? We seem to support that already.

With HMP yes, with QMP no. You just get "An incoming migration is expected before this command can be executed" and no clue that disks are encrypted.

We could move the bdrv_iterate() calls before the RUN_STATE_INMIGRATE check in qmp_cont(), but if this patch fixes all the cases you mention then let's just apply it.

#4 lore raw

Il 19/10/2012 15:23, Luiz Capitulino ha scritto:

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

With HMP yes, with QMP no. You just get "An incoming migration is expected before this command can be executed" and no clue that disks are encrypted.

We could move the bdrv_iterate() calls before the RUN_STATE_INMIGRATE check in qmp_cont(), but if this patch fixes all the cases you mention then let's just apply it.

I'm all for that. :)

Paolo

#5 lore raw
Quoted 10 lines · On Fri, 19 Oct 2012 15:50:17 +0200 Paolo Bonzini <[email protected]> wrote:

Il 19/10/2012 15:23, Luiz Capitulino ha scritto:

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

With HMP yes, with QMP no. You just get "An incoming migration is expected before this command can be executed" and no clue that disks are encrypted.

We could move the bdrv_iterate() calls before the RUN_STATE_INMIGRATE check in qmp_cont(), but if this patch fixes all the cases you mention then let's just apply it.

I'm all for that. :)

I guess it won't have any affects on the -S races.