Skip to contentSkip to conversation

migration: invalidate cache before source start

PATCH In review Vladimir Sementsov-Ogievskiy 3 participants 12 messages Jun 9, 2018 – Oct 8, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 migration: invalidate cache before source start

Invalidate cache before source start in case of failed migration.

---

 migration/migration.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
migration/migration.c +8 -1
index 1e99ec9b7e..8f39e0dc02 100644
@@ -2806,7 +2806,14 @@ static void migration_iteration_finish(MigrationState *s)
     case MIGRATION_STATUS_FAILED:
     case MIGRATION_STATUS_CANCELLED:
         if (s->vm_was_running) {
-            vm_start();
+            Error *local_err = NULL;
+            bdrv_invalidate_cache_all(&local_err);
+            if (local_err) {
+                error_reportf_err(local_err, "Can't invalidate disks before "
+                                  "source vm start");
+            } else {
+                vm_start();
+            }
         } else {
             if (runstate_check(RUN_STATE_FINISH_MIGRATE)) {
                 runstate_set(RUN_STATE_POSTMIGRATE);
Signature · 1 line
2.11.1
#1 lore raw
Quoted 3 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:

Invalidate cache before source start in case of failed migration.

Why doesn't the code at the bottom of migration_completion,
fail_invalidate: and the code in migrate_fd_cancel handle this?

What case did you see it in that those didn't handle? (Also I guess it probably should set s->block_inactive = false)

Dave

Quoted 28 lines

---

 migration/migration.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
migration/migration.c +8 -1
index 1e99ec9b7e..8f39e0dc02 100644
@@ -2806,7 +2806,14 @@ static void migration_iteration_finish(MigrationState *s)
     case MIGRATION_STATUS_FAILED:
     case MIGRATION_STATUS_CANCELLED:
         if (s->vm_was_running) {
-            vm_start();
+            Error *local_err = NULL;
+            bdrv_invalidate_cache_all(&local_err);
+            if (local_err) {
+                error_reportf_err(local_err, "Can't invalidate disks before "
+                                  "source vm start");
+            } else {
+                vm_start();
+            }
         } else {
             if (runstate_check(RUN_STATE_FINISH_MIGRATE)) {
                 runstate_set(RUN_STATE_POSTMIGRATE);
Signature · 1 line
2.11.1

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

#2 lore raw
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 3 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:

Invalidate cache before source start in case of failed migration.

Why doesn't the code at the bottom of migration_completion,
fail_invalidate: and the code in migrate_fd_cancel handle this?

What case did you see it in that those didn't handle? (Also I guess it probably should set s->block_inactive = false)

on source I see:

[email protected]:migrate_set_state new state 7 [email protected]:migration_thread_file_err [email protected]:migration_thread_after_loop

so, we are leaving loop on
        if (qemu_file_get_error(s->to_dst_file)) { migrate_set_state(&s->state, current_active_state, MIGRATION_STATUS_FAILED); trace_migration_thread_file_err();
break;
        }

and skip migration_completion()

Quoted 33 lines

Dave

Quoted 28 lines

---

  migration/migration.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
migration/migration.c +8 -1
index 1e99ec9b7e..8f39e0dc02 100644
@@ -2806,7 +2806,14 @@ static void migration_iteration_finish(MigrationState *s)
      case MIGRATION_STATUS_FAILED:
      case MIGRATION_STATUS_CANCELLED:
          if (s->vm_was_running) {
-            vm_start();
+            Error *local_err = NULL;
+            bdrv_invalidate_cache_all(&local_err);
+            if (local_err) {
+                error_reportf_err(local_err, "Can't invalidate disks before "
+                                  "source vm start");
+            } else {
+                vm_start();
+            }
          } else {
              if (runstate_check(RUN_STATE_FINISH_MIGRATE)) {
                  runstate_set(RUN_STATE_POSTMIGRATE);
Signature · 1 line
2.11.1

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

Signature · 2 lines
Best regards,
Vladimir
#3 lore raw
Quoted 25 lines · Vladimir Sementsov-Ogievskiy
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 3 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:

Invalidate cache before source start in case of failed migration.

Why doesn't the code at the bottom of migration_completion, fail_invalidate:   and the code in migrate_fd_cancel   handle this?

What case did you see it in that those didn't handle? (Also I guess it probably should set s->block_inactive = false)

on source I see:

[email protected]:migrate_set_state new state 7 [email protected]:migration_thread_file_err [email protected]:migration_thread_after_loop

so, we are leaving loop on
        if (qemu_file_get_error(s->to_dst_file)) { migrate_set_state(&s->state, current_active_state, MIGRATION_STATUS_FAILED); trace_migration_thread_file_err();
break;
        }

Quoted 2 lines

and skip migration_completion()

OK, so you're saying that in migration_thread;

`

        thr_error = migration_detect_error(s);
        if (thr_error == MIG_THR_ERR_FATAL) {
	    /* Stop migration */
            break;
	}

`

is triggering, so then we jump right away to

`

    trace_migration_thread_after_loop();
    migration_iteration_finish(s);

`

and in so doing, we fail before we get a chance for migration_iteration_run to call migration_completion, which was otherwise the mechanism that invalidated the images.

Seems like a legitimate concern that early failures versus late failures trigger different error pathways.

David?

--js

Quoted 38 lines
Quoted 36 lines

Dave

Quoted 30 lines

---

  migration/migration.c | 9 ++++++++-

  1 file changed, 8 insertions(+), 1 deletion(-)
migration/migration.c +0 -0
index 1e99ec9b7e..8f39e0dc02 100644
@@ -2806,7 +2806,14 @@ static void
 migration_iteration_finish(MigrationState *s)

      case MIGRATION_STATUS_FAILED:
      case MIGRATION_STATUS_CANCELLED:
          if (s->vm_was_running) {
-            vm_start();
+            Error *local_err = NULL;
+            bdrv_invalidate_cache_all(&local_err);
+            if (local_err) {
+                error_reportf_err(local_err, "Can't invalidate disks before "
+                                  "source vm start");
+            } else {
+                vm_start();
+            }
          } else {
              if (runstate_check(RUN_STATE_FINISH_MIGRATE)) { runstate_set(RUN_STATE_POSTMIGRATE);
--
2.11.1

Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#4 lore raw
In reply to Vladimir Sementsov-Ogievskiy
Quoted 25 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 3 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:

Invalidate cache before source start in case of failed migration.

Why doesn't the code at the bottom of migration_completion,
fail_invalidate: and the code in migrate_fd_cancel handle this?

What case did you see it in that those didn't handle? (Also I guess it probably should set s->block_inactive = false)

on source I see:

[email protected]:migrate_set_state new state 7 [email protected]:migration_thread_file_err [email protected]:migration_thread_after_loop

so, we are leaving loop on
        if (qemu_file_get_error(s->to_dst_file)) { migrate_set_state(&s->state, current_active_state, MIGRATION_STATUS_FAILED); trace_migration_thread_file_err();
break;
        }

Quoted 1 line

and skip migration_completion()

Yeh, OK; I'd seen soemthing else a few days ago, where a cancellation test that had previously ended with a 'cancelled' state has now ended up in 'failed' (which is the state 7 you have above).
I suspect there's something else going on as well; I think what is supposed to happen in the case of 'cancel' is that it spins in 'cancelling' for a while in migrate_fd_cancel and then at the bottom of migrate_fd_cancel it does the recovery, but because it's going to failed instead, then it's jumping over that recovery.

Dave

Quoted 26 lines
Quoted 26 lines

Dave

Quoted 22 lines

---

  migration/migration.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
migration/migration.c +8 -1
index 1e99ec9b7e..8f39e0dc02 100644
@@ -2806,7 +2806,14 @@ static void migration_iteration_finish(MigrationState *s)
      case MIGRATION_STATUS_FAILED:
      case MIGRATION_STATUS_CANCELLED:
          if (s->vm_was_running) {
-            vm_start();
+            Error *local_err = NULL;
+            bdrv_invalidate_cache_all(&local_err);
+            if (local_err) {
+                error_reportf_err(local_err, "Can't invalidate disks before "
+                                  "source vm start");
+            } else {
+                vm_start();
+            }
Quoted 14 lines
Quoted 8 lines
Quoted 6 lines
migration/migration.c +0 -0
          } else {
              if (runstate_check(RUN_STATE_FINISH_MIGRATE)) {
                  runstate_set(RUN_STATE_POSTMIGRATE);
Signature · 1 line
2.11.1

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

Signature · 2 lines
Best regards,
Vladimir

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

#5 lore raw
Quoted 28 lines · * Dr. David Alan Gilbert ([email protected]) wrote:
Quoted 25 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 3 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:

Invalidate cache before source start in case of failed migration.

Why doesn't the code at the bottom of migration_completion,
fail_invalidate: and the code in migrate_fd_cancel handle this?

What case did you see it in that those didn't handle? (Also I guess it probably should set s->block_inactive = false)

on source I see:

[email protected]:migrate_set_state new state 7 [email protected]:migration_thread_file_err [email protected]:migration_thread_after_loop

so, we are leaving loop on
        if (qemu_file_get_error(s->to_dst_file)) { migrate_set_state(&s->state, current_active_state, MIGRATION_STATUS_FAILED); trace_migration_thread_file_err();
break;
        }

Quoted 1 line

and skip migration_completion()

Quoted 8 lines

Yeh, OK; I'd seen soemthing else a few days ago, where a cancellation test that had previously ended with a 'cancelled' state has now ended up in 'failed' (which is the state 7 you have above).
I suspect there's something else going on as well; I think what is supposed to happen in the case of 'cancel' is that it spins in 'cancelling' for a while in migrate_fd_cancel and then at the bottom of migrate_fd_cancel it does the recovery, but because it's going to failed instead, then it's jumping over that recovery.

Going back and actually looking at the patch again;
can I ask for 1 small change;
Can you set s->block_inactive = false in the case where you
don't get the local_err (Like we do at the bottom of migrate_fd_cancel)

Does that make sense?

Thanks,

Dave

Quoted 38 lines

Dave

Quoted 36 lines
Quoted 34 lines

Dave

Quoted 28 lines

---

  migration/migration.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
migration/migration.c +8 -1
index 1e99ec9b7e..8f39e0dc02 100644
@@ -2806,7 +2806,14 @@ static void migration_iteration_finish(MigrationState *s)
      case MIGRATION_STATUS_FAILED:
      case MIGRATION_STATUS_CANCELLED:
          if (s->vm_was_running) {
-            vm_start();
+            Error *local_err = NULL;
+            bdrv_invalidate_cache_all(&local_err);
+            if (local_err) {
+                error_reportf_err(local_err, "Can't invalidate disks before "
+                                  "source vm start");
+            } else {
+                vm_start();
+            }
          } else {
              if (runstate_check(RUN_STATE_FINISH_MIGRATE)) {
                  runstate_set(RUN_STATE_POSTMIGRATE);
Signature · 1 line
2.11.1

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

Quoted 6 lines
Quoted 4 lines
Signature · 2 lines
Best regards,
Vladimir

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

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

#6 lore raw
Quoted 44 lines · Dr. David Alan Gilbert
Quoted 28 lines · * Dr. David Alan Gilbert ([email protected]) wrote:
Quoted 25 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 3 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:

Invalidate cache before source start in case of failed migration.

Why doesn't the code at the bottom of migration_completion,
fail_invalidate: and the code in migrate_fd_cancel handle this?

What case did you see it in that those didn't handle? (Also I guess it probably should set s->block_inactive = false)

on source I see:

[email protected]:migrate_set_state new state 7 [email protected]:migration_thread_file_err [email protected]:migration_thread_after_loop

so, we are leaving loop on
        if (qemu_file_get_error(s->to_dst_file)) { migrate_set_state(&s->state, current_active_state, MIGRATION_STATUS_FAILED); trace_migration_thread_file_err();
break;
        }

Quoted 1 line

and skip migration_completion()

Quoted 8 lines

Yeh, OK; I'd seen soemthing else a few days ago, where a cancellation test that had previously ended with a 'cancelled' state has now ended up in 'failed' (which is the state 7 you have above).
I suspect there's something else going on as well; I think what is supposed to happen in the case of 'cancel' is that it spins in 'cancelling' for a while in migrate_fd_cancel and then at the bottom of migrate_fd_cancel it does the recovery, but because it's going to failed instead, then it's jumping over that recovery.

Going back and actually looking at the patch again;
can I ask for 1 small change;
Can you set s->block_inactive = false in the case where you
don't get the local_err (Like we do at the bottom of migrate_fd_cancel)

Quoted 6 lines

Does that make sense?

Thanks,

Dave

Vladimir, one more question for you because I'm not as familiar with this code:

In the normal case we need to invalidate the qcow2 cache as a way to re-engage the disk (yes?) when we have failed during the late-migration steps.

In this case, we seem to be observing a failure during the bulk transfer loop. Why is it important to invalidate the cache at this step -- would the disk have been inactivated yet? It shouldn't, because it's in the bulk transfer phase -- or am I missing something?

I feel like this code is behaving in a way that's fairly surprising for a casual reader so I was hoping you could elaborate for me.

--js

#7 lore raw
Quoted 61 lines · John Snow
Quoted 38 lines · Dr. David Alan Gilbert
Quoted 26 lines · * Dr. David Alan Gilbert ([email protected]) wrote:
Quoted 24 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 3 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:

Invalidate cache before source start in case of failed migration.

Why doesn't the code at the bottom of migration_completion,
fail_invalidate: and the code in migrate_fd_cancel handle this?

What case did you see it in that those didn't handle? (Also I guess it probably should set s->block_inactive = false)

on source I see:

[email protected]:migrate_set_state new state 7 [email protected]:migration_thread_file_err [email protected]:migration_thread_after_loop

so, we are leaving loop on
        if (qemu_file_get_error(s->to_dst_file)) { migrate_set_state(&s->state, current_active_state,
MIGRATION_STATUS_FAILED); trace_migration_thread_file_err();
break;
        }

Quoted 1 line

and skip migration_completion()

Quoted 8 lines

Yeh, OK; I'd seen soemthing else a few days ago, where a cancellation test that had previously ended with a 'cancelled' state has now ended up in 'failed' (which is the state 7 you have above).
I suspect there's something else going on as well; I think what is supposed to happen in the case of 'cancel' is that it spins in 'cancelling' for a while in migrate_fd_cancel and then at the bottom of migrate_fd_cancel it does the recovery, but because it's going to failed instead, then it's jumping over that recovery.

Going back and actually looking at the patch again; can I ask for 1 small change;

    Can you set s->block_inactive = false   in the case where you
Quoted 9 lines

don't get the local_err (Like we do at the bottom of migrate_fd_cancel)

Does that make sense?

Thanks,

Dave

Vladimir, one more question for you because I'm not as familiar with this code:

In the normal case we need to invalidate the qcow2 cache as a way to re-engage the disk (yes?) when we have failed during the late-migration steps.

In this case, we seem to be observing a failure during the bulk transfer loop. Why is it important to invalidate the cache at this step -- would the disk have been inactivated yet? It shouldn't, because it's in the bulk transfer phase -- or am I missing something?

Quoted 4 lines

I feel like this code is behaving in a way that's fairly surprising for a casual reader so I was hoping you could elaborate for me.

--js

In my case, source is already in postcopy state, when error occured, so it is inactivated.

Signature · 2 lines
Best regards,
Vladimir
#8 lore raw
Quoted 62 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:
Quoted 61 lines · John Snow
Quoted 38 lines · Dr. David Alan Gilbert
Quoted 26 lines · * Dr. David Alan Gilbert ([email protected]) wrote:
Quoted 24 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 3 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:

Invalidate cache before source start in case of failed migration.

Why doesn't the code at the bottom of migration_completion,
fail_invalidate: and the code in migrate_fd_cancel handle this?

What case did you see it in that those didn't handle? (Also I guess it probably should set s->block_inactive = false)

on source I see:

[email protected]:migrate_set_state new state 7 [email protected]:migration_thread_file_err [email protected]:migration_thread_after_loop

so, we are leaving loop on
        if (qemu_file_get_error(s->to_dst_file)) { migrate_set_state(&s->state, current_active_state,
MIGRATION_STATUS_FAILED); trace_migration_thread_file_err();
break;
        }

Quoted 1 line

and skip migration_completion()

Quoted 8 lines

Yeh, OK; I'd seen soemthing else a few days ago, where a cancellation test that had previously ended with a 'cancelled' state has now ended up in 'failed' (which is the state 7 you have above).
I suspect there's something else going on as well; I think what is supposed to happen in the case of 'cancel' is that it spins in 'cancelling' for a while in migrate_fd_cancel and then at the bottom of migrate_fd_cancel it does the recovery, but because it's going to failed instead, then it's jumping over that recovery.

Going back and actually looking at the patch again; can I ask for 1 small change;

    Can you set s->block_inactive = false   in the case where you
Quoted 9 lines

don't get the local_err (Like we do at the bottom of migrate_fd_cancel)

Does that make sense?

Thanks,

Dave

Vladimir, one more question for you because I'm not as familiar with this code:

In the normal case we need to invalidate the qcow2 cache as a way to re-engage the disk (yes?) when we have failed during the late-migration steps.

In this case, we seem to be observing a failure during the bulk transfer loop. Why is it important to invalidate the cache at this step -- would the disk have been inactivated yet? It shouldn't, because it's in the bulk transfer phase -- or am I missing something?

Quoted 7 lines
Quoted 4 lines

I feel like this code is behaving in a way that's fairly surprising for a casual reader so I was hoping you could elaborate for me.

--js

In my case, source is already in postcopy state, when error occured, so it is inactivated.

Ah, that explains why I couldn't understand the path that got you there; I never think about restarting the source once we're in postcopy - because once the destination is running all is lost.
But, you might be in the gap efore management has actually started the destination so it does need fixing.

Dave

Quoted 4 lines
Signature · 2 lines
Best regards,
Vladimir

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

#9 lore raw
In reply to Dr. David Alan Gilbert
Quoted 26 lines · Dr. David Alan Gilbert
Quoted 25 lines · * Dr. David Alan Gilbert ([email protected]) wrote:
Quoted 24 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 3 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:

Invalidate cache before source start in case of failed migration.

Why doesn't the code at the bottom of migration_completion,
fail_invalidate: and the code in migrate_fd_cancel handle this?

What case did you see it in that those didn't handle? (Also I guess it probably should set s->block_inactive = false)

on source I see:

[email protected]:migrate_set_state new state 7 [email protected]:migration_thread_file_err [email protected]:migration_thread_after_loop

so, we are leaving loop on
        if (qemu_file_get_error(s->to_dst_file)) { migrate_set_state(&s->state, current_active_state,
MIGRATION_STATUS_FAILED); trace_migration_thread_file_err();
break;
        }

Quoted 1 line
Quoted 1 line
Quoted 1 line

and skip migration_completion()

John is right, this ls an unrelated log, here we fail before inactivation and there are no problems.

Actual problem is when we fail in postcopy_start, at the end. And source log looks like:

[email protected]:migrate_set_state new state 1 [email protected]:migration_fd_outgoing fd=101 [email protected]:migration_set_outgoing_channel ioc=0x56363454d630 ioctype=qio-channel-socket hostname=(null) [email protected]:migration_bitmap_sync_start [email protected]:migration_bitmap_sync_end dirty_pages 932 [email protected]:migrate_set_state new state 4 [email protected]:migration_thread_setup_complete
[email protected]:migrate_pending pending size 1107976192 max 0 (pre = 0 compat=1107976192 post=0) [email protected]:migrate_set_state new state 5
Tap fd 33 disable, ret 0
[email protected]:migration_bitmap_sync_start [email protected]:migration_bitmap_sync_end dirty_pages 1091 [email protected]:migrate_global_state_pre_save saved state: running

2018-06-26T08:29:56.439134Z qemu-kvm: postcopy_start: Migration stream errored -5

[email protected]:migrate_set_state new state 7 [email protected]:migration_thread_after_loop
Tap fd 33 enable, ret 0
[email protected]:migrate_fd_cleanup
qemu-kvm: block/io.c:1655: bdrv_co_pwritev: Assertion `!(bs->open_flags & 0x0800)' failed.

2018-06-26 08:29:56.605+0000: shutting down, reason=crashed
Quoted 8 lines
Quoted 8 lines

Yeh, OK; I'd seen soemthing else a few days ago, where a cancellation test that had previously ended with a 'cancelled' state has now ended up in 'failed' (which is the state 7 you have above).
I suspect there's something else going on as well; I think what is supposed to happen in the case of 'cancel' is that it spins in 'cancelling' for a while in migrate_fd_cancel and then at the bottom of migrate_fd_cancel it does the recovery, but because it's going to failed instead, then it's jumping over that recovery.

Quoted 7 lines

Going back and actually looking at the patch again; can I ask for 1 small change;

    Can you set s->block_inactive = false   in the case where you

don't get the local_err (Like we do at the bottom of migrate_fd_cancel)

Does that make sense?

Ok, I'll resend.

Hm, looks like I'm fixing an outdated version (based on v2.9.0) And my reproduce isn't appropriate for upstream. But looks like current code have a possibility of the same fail:

postcopy_start()
    ....
    ret = qemu_file_get_error(ms->to_dst_file);
    if (ret) {
        error_report("postcopy_start: Migration stream errored");

leads to "return MIG_ITERATE_SKIP;" in migration_iteration_run

then the loop should finish, as state should be MIGRATION_STATUS_FAILED, so we will not call migration_completion.

Hm, I have questions now:

1. should we check s->block_inactive, and if it is false, don't invalidate? it is done in migrate_fd_cancel(), but not don in migration_completion().
2. should we call qemu_mutex_lock_iothread() like in migration_completion()? Why is it needed in migration_completion(), when vm is not running?

Quoted 48 lines

Thanks,

Dave

Quoted 35 lines

Dave

Quoted 33 lines
Quoted 32 lines

Dave

Quoted 28 lines

---

   migration/migration.c | 9 ++++++++-
   1 file changed, 8 insertions(+), 1 deletion(-)
migration/migration.c +8 -1
index 1e99ec9b7e..8f39e0dc02 100644
@@ -2806,7 +2806,14 @@ static void migration_iteration_finish(MigrationState *s)
       case MIGRATION_STATUS_FAILED:
       case MIGRATION_STATUS_CANCELLED:
           if (s->vm_was_running) {
-            vm_start();
+            Error *local_err = NULL;
+            bdrv_invalidate_cache_all(&local_err);
+            if (local_err) {
+                error_reportf_err(local_err, "Can't invalidate disks before "
+                                  "source vm start");
+            } else {
+                vm_start();
+            }
           } else {
               if (runstate_check(RUN_STATE_FINISH_MIGRATE)) {
                   runstate_set(RUN_STATE_POSTMIGRATE);
Signature · 1 line
2.11.1

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

Quoted 6 lines
Quoted 4 lines
Signature · 2 lines
Best regards,
Vladimir

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

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

Signature · 2 lines
Best regards,
Vladimir
#10 lore raw
Quoted 100 lines · Vladimir Sementsov-Ogievskiy
Quoted 27 lines · Dr. David Alan Gilbert
Quoted 26 lines · * Dr. David Alan Gilbert ([email protected]) wrote:
Quoted 25 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:
Quoted 10 lines · Dr. David Alan Gilbert
Quoted 4 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:

Invalidate cache before source start in case of failed migration.

Signed-off-by: Vladimir Sementsov-Ogievskiy
<[email protected]>

Why doesn't the code at the bottom of migration_completion, fail_invalidate:   and the code in migrate_fd_cancel handle this?

What case did you see it in that those didn't handle? (Also I guess it probably should set s->block_inactive = false)

on source I see:

[email protected]:migrate_set_state new state 7 [email protected]:migration_thread_file_err [email protected]:migration_thread_after_loop

so, we are leaving loop on
         if (qemu_file_get_error(s->to_dst_file)) { migrate_set_state(&s->state, current_active_state, MIGRATION_STATUS_FAILED); trace_migration_thread_file_err();
break;
         }

Quoted 1 line
Quoted 1 line
Quoted 1 line

and skip migration_completion()

John is right, this ls an unrelated log, here we fail before inactivation and there are no problems.

Actual problem is when we fail in postcopy_start, at the end. And source log looks like:

[email protected]:migrate_set_state new state 1 [email protected]:migration_fd_outgoing fd=101 [email protected]:migration_set_outgoing_channel ioc=0x56363454d630 ioctype=qio-channel-socket hostname=(null) [email protected]:migration_bitmap_sync_start [email protected]:migration_bitmap_sync_end dirty_pages 932 [email protected]:migrate_set_state new state 4 [email protected]:migration_thread_setup_complete [email protected]:migrate_pending pending size 1107976192 max 0 (pre = 0 compat=1107976192 post=0) [email protected]:migrate_set_state new state 5
Tap fd 33 disable, ret 0 [email protected]:migration_bitmap_sync_start [email protected]:migration_bitmap_sync_end dirty_pages 1091 [email protected]:migrate_global_state_pre_save saved state:
running

2018-06-26T08:29:56.439134Z qemu-kvm: postcopy_start: Migration stream 

errored -5 [email protected]:migrate_set_state new state 7 [email protected]:migration_thread_after_loop Tap fd 33 enable, ret 0 [email protected]:migrate_fd_cleanup
qemu-kvm: block/io.c:1655: bdrv_co_pwritev: Assertion `!(bs->open_flags & 0x0800)' failed.

2018-06-26 08:29:56.605+0000: shutting down, reason=crashed
Quoted 11 lines
Quoted 11 lines

Yeh, OK; I'd seen soemthing else a few days ago, where a cancellation test that had previously ended with a 'cancelled' state has now ended up
in 'failed' (which is the state 7 you have above).
I suspect there's something else going on as well; I think what is supposed to happen in the case of 'cancel' is that it spins in 'cancelling' for
a while in migrate_fd_cancel and then at the bottom of migrate_fd_cancel
it does the recovery, but because it's going to failed instead, then it's jumping over that recovery.

Quoted 7 lines

Going back and actually looking at the patch again;
can I ask for 1 small change;
    Can you set s->block_inactive = false   in the case where you don't get the local_err (Like we do at the bottom of migrate_fd_cancel)

Does that make sense?

Ok, I'll resend.

Hm, looks like I'm fixing an outdated version (based on v2.9.0) And my reproduce isn't appropriate for upstream.
But looks like current code have a possibility of the same fail:

postcopy_start()
    ....
    ret = qemu_file_get_error(ms->to_dst_file);
    if (ret) {
        error_report("postcopy_start: Migration stream errored");

leads to "return MIG_ITERATE_SKIP;" in migration_iteration_run

then the loop should finish, as state should be MIGRATION_STATUS_FAILED, so we will not call migration_completion.

Quoted 8 lines

Hm, I have questions now:

1. should we check s->block_inactive, and if it is false, don't invalidate? it is done in migrate_fd_cancel(), but not don in migration_completion().
2. should we call qemu_mutex_lock_iothread() like in migration_completion()? Why is it needed in migration_completion(), when vm is not running?

Hm, forgotten thread, I should resend, but what do you think about these questions?

Quoted 53 lines
Quoted 51 lines

Thanks,

Dave

Quoted 43 lines

Dave

Quoted 39 lines
Quoted 34 lines

Dave

Quoted 30 lines

---

   migration/migration.c | 9 ++++++++-

   1 file changed, 8 insertions(+), 1 deletion(-)
migration/migration.c +0 -0
index 1e99ec9b7e..8f39e0dc02 100644
@@ -2806,7 +2806,14 @@ static void 
 migration_iteration_finish(MigrationState *s)

       case MIGRATION_STATUS_FAILED:
       case MIGRATION_STATUS_CANCELLED:
           if (s->vm_was_running) {
-            vm_start();
+            Error *local_err = NULL;
+            bdrv_invalidate_cache_all(&local_err);
+            if (local_err) {
+                error_reportf_err(local_err, "Can't invalidate disks before "
+                                  "source vm start"); +            } else {
+                vm_start();
+            }
           } else {
               if (runstate_check(RUN_STATE_FINISH_MIGRATE)) { runstate_set(RUN_STATE_POSTMIGRATE);

Signature · 1 line
2.11.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Signature · 2 lines
Best regards,
Vladimir
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Signature · 2 lines
Best regards,
Vladimir
#11 lore raw
Quoted 111 lines · Vladimir Sementsov-Ogievskiy
Quoted 100 lines · Vladimir Sementsov-Ogievskiy
Quoted 27 lines · Dr. David Alan Gilbert
Quoted 26 lines · * Dr. David Alan Gilbert ([email protected]) wrote:
Quoted 25 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:
Quoted 10 lines · Dr. David Alan Gilbert
Quoted 4 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:

Invalidate cache before source start in case of failed migration.

Signed-off-by: Vladimir Sementsov-Ogievskiy
<[email protected]>

Why doesn't the code at the bottom of migration_completion, fail_invalidate:   and the code in migrate_fd_cancel handle this?

What case did you see it in that those didn't handle? (Also I guess it probably should set s->block_inactive = false)

on source I see:

[email protected]:migrate_set_state new state 7 [email protected]:migration_thread_file_err [email protected]:migration_thread_after_loop

so, we are leaving loop on
         if (qemu_file_get_error(s->to_dst_file)) { migrate_set_state(&s->state, current_active_state, MIGRATION_STATUS_FAILED); trace_migration_thread_file_err();
break;
         }

Quoted 1 line
Quoted 1 line
Quoted 1 line

and skip migration_completion()

John is right, this ls an unrelated log, here we fail before inactivation and there are no problems.

Actual problem is when we fail in postcopy_start, at the end. And source log looks like:

[email protected]:migrate_set_state new state 1 [email protected]:migration_fd_outgoing fd=101 [email protected]:migration_set_outgoing_channel ioc=0x56363454d630 ioctype=qio-channel-socket hostname=(null) [email protected]:migration_bitmap_sync_start [email protected]:migration_bitmap_sync_end dirty_pages 932 [email protected]:migrate_set_state new state 4 [email protected]:migration_thread_setup_complete [email protected]:migrate_pending pending size 1107976192 max 0 (pre = 0 compat=1107976192 post=0) [email protected]:migrate_set_state new state 5
Tap fd 33 disable, ret 0 [email protected]:migration_bitmap_sync_start [email protected]:migration_bitmap_sync_end dirty_pages 1091 [email protected]:migrate_global_state_pre_save saved state:
running

2018-06-26T08:29:56.439134Z qemu-kvm: postcopy_start: Migration stream 

errored -5 [email protected]:migrate_set_state new state 7 [email protected]:migration_thread_after_loop Tap fd 33 enable, ret 0 [email protected]:migrate_fd_cleanup
qemu-kvm: block/io.c:1655: bdrv_co_pwritev: Assertion `!(bs->open_flags & 0x0800)' failed.

2018-06-26 08:29:56.605+0000: shutting down, reason=crashed
Quoted 11 lines
Quoted 11 lines

Yeh, OK; I'd seen soemthing else a few days ago, where a cancellation test that had previously ended with a 'cancelled' state has now ended up
in 'failed' (which is the state 7 you have above).
I suspect there's something else going on as well; I think what is supposed to happen in the case of 'cancel' is that it spins in 'cancelling' for
a while in migrate_fd_cancel and then at the bottom of migrate_fd_cancel
it does the recovery, but because it's going to failed instead, then it's jumping over that recovery.

Quoted 7 lines

Going back and actually looking at the patch again;
can I ask for 1 small change;
    Can you set s->block_inactive = false   in the case where you don't get the local_err (Like we do at the bottom of migrate_fd_cancel)

Does that make sense?

Ok, I'll resend.

Hm, looks like I'm fixing an outdated version (based on v2.9.0) And my reproduce isn't appropriate for upstream.
But looks like current code have a possibility of the same fail:

postcopy_start()
    ....
    ret = qemu_file_get_error(ms->to_dst_file);
    if (ret) {
        error_report("postcopy_start: Migration stream errored");

leads to "return MIG_ITERATE_SKIP;" in migration_iteration_run

then the loop should finish, as state should be MIGRATION_STATUS_FAILED, so we will not call migration_completion.

Quoted 8 lines

Hm, I have questions now:

1. should we check s->block_inactive, and if it is false, don't invalidate? it is done in migrate_fd_cancel(), but not don in migration_completion().
2. should we call qemu_mutex_lock_iothread() like in migration_completion()? Why is it needed in migration_completion(), when vm is not running?

Quoted 3 lines

Hm, forgotten thread, I should resend, but what do you think about these questions?

Personally, I can't remember where we stand on this thread at all. If you have changes that you think are still important (because you ran into the issue again), probably best to send a respin (with a new cover letter and updated justification) and we'll take it from there.

(I seem to recall we were working off of different versions which handled migration differently, which was causing confusion...)

--js