qemu-patch-raspberry4/migration
zhanghailiang 1d2acc3162 migration: re-active images while migration been canceled after inactive them
commit fe904ea824 fixed a case
which migration aborted QEMU because it didn't regain the control
of images while some errors happened.

Actually, there are another two cases can trigger the same error reports:
" bdrv_co_do_pwritev: Assertion `!(bs->open_flags & 0x0800)' failed",

Case 1, codes path:
migration_thread()
    migration_completion()
        bdrv_inactivate_all() ----------------> inactivate images
        qemu_savevm_state_complete_precopy()
            socket_writev_buffer() --------> error because destination fails
                qemu_fflush() ----------------> set error on migration stream
-> qmp_migrate_cancel() ----------------> user cancelled migration concurrently
    -> migrate_set_state() ------------------> set migrate CANCELLIN
    migration_completion() -----------------> go on to fail_invalidate
	if (s->state == MIGRATION_STATUS_ACTIVE) -> Jump this branch

Case 2, codes path:
migration_thread()
    migration_completion()
        bdrv_inactivate_all() ----------------> inactivate images
    migreation_completion() finished
-> qmp_migrate_cancel() ---------------> user cancelled migration concurrently
    qemu_mutex_lock_iothread();
    qemu_bh_schedule (s->cleanup_bh);

As we can see from above, qmp_migrate_cancel can slip in whenever
migration_thread does not hold the global lock. If this happens after
bdrv_inactive_all() been called, the above error reports will appear.

To prevent this, we can call bdrv_invalidate_cache_all() in qmp_migrate_cancel()
directly if we find images become inactive.

Besides, bdrv_invalidate_cache_all() in migration_completion() doesn't have the
protection of big lock, fix it by add the missing qemu_mutex_lock_iothread();

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Message-Id: <1485244792-11248-1-git-send-email-zhang.zhanghailiang@huawei.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2017-01-24 18:00:31 +00:00
..
block.c migration/block: Convert saving to BlockBackend 2016-06-08 10:21:08 +02:00
colo-comm.c COLO: Add 'x-colo-lost-heartbeat' command to trigger failover 2016-10-30 15:17:39 +05:30
colo-failover.c COLO: Implement the process of failover for primary VM 2016-10-30 15:17:39 +05:30
colo.c migration: fix compiler warning on uninitialized variable 2016-11-01 09:31:53 +00:00
exec.c migration: set name for all I/O channels created 2016-10-27 09:13:10 +02:00
fd.c migration: set name for all I/O channels created 2016-10-27 09:13:10 +02:00
Makefile.objs build: remove --enable-colo/--disable-colo 2017-01-16 17:52:35 +01:00
migration.c migration: re-active images while migration been canceled after inactive them 2017-01-24 18:00:31 +00:00
postcopy-ram.c migration/postcopy: Explicitly disallow huge pages 2016-10-13 17:23:53 +02:00
qemu-file-channel.c migration: introduce a new QEMUFile impl based on QIOChannel 2016-05-26 11:31:24 +05:30
qemu-file.c migration: fix live migration failure with compression 2016-08-11 16:59:53 +05:30
qjson.c qjson: free str 2016-08-08 00:00:24 +04:00
ram.c migration: Fix return code of ram_save_iterate() 2016-11-14 19:35:41 +01:00
rdma.c migration/rdma: Don't flag an error when we've been told about one 2016-10-13 17:22:38 +02:00
savevm.c migration: extend VMStateInfo 2017-01-24 17:54:47 +00:00
socket.c io: change the QIOTask callback signature 2017-01-23 15:32:18 +00:00
tls.c io: change the QIOTask callback signature 2017-01-23 15:32:18 +00:00
trace-events migration: migrate QTAILQ 2017-01-24 17:54:47 +00:00
vmstate.c migration: add error_report 2017-01-24 17:54:47 +00:00
xbzrle.c util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00