migration: re-active images while migration been canceled after inactive them
PATCH v2 1/1 migration: re-active images while migration been canceled after inactive them
commit fe904ea8242cbae2d7e69c052c754b8f5f1ba1d6 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 branchCase 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();
---
v2:
- Fix a bug introduced by commit fe904 which didn't get big lock before call bdrv_invalidate_cache_all. (Suggested by Dave)
--- include/migration/migration.h | 3 +++ migration/migration.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+)
include/migration/migration.h +3 -0
@@ -177,6 +177,9 @@ struct MigrationState/* Flag set once the migration thread is running (and needs joining) */ bool migration_thread_running; +/* Flag set once the migration thread called bdrv_inactivate_all */ +bool block_inactive; +/* Queue of outstanding page requests from the destination */ QemuMutex src_page_req_mutex; QSIMPLEQ_HEAD(src_page_requests, MigrationSrcPageRequest) src_page_requests;
migration/migration.c +15 -0
@@ -1006,6 +1006,16 @@ static void migrate_fd_cancel(MigrationState *s)if (s->state ==MIGRATION_STATUS_CANCELLING && f) {qemu_file_shutdown (f); } +if (s->state ==MIGRATION_STATUS_CANCELLING && s->block_inactive) { +Error *local_err =NULL ; + +bdrv_invalidate_cache_all (&local_err); +if (local_err) { +error_report_err (local_err); + }else { + s->block_inactive = false; + } + } }void add_migration_state_change_notifier (Notifier *notify)
@@ -1705,6 +1715,7 @@ static void migration_completion(MigrationState *s, int current_active_state,if (ret >=0 ) {qemu_file_set_rate_limit (s->to_dst_file,INT64_MAX );qemu_savevm_state_complete_precopy (s->to_dst_file, false); + s->block_inactive = true; } }qemu_mutex_unlock_iothread ();
@@ -1755,10 +1766,14 @@ fail_invalidate:if (s->state ==MIGRATION_STATUS_ACTIVE ) {Error *local_err =NULL ; +qemu_mutex_lock_iothread ();bdrv_invalidate_cache_all (&local_err);if (local_err) {error_report_err (local_err); + }else { + s->block_inactive = false; } +qemu_mutex_unlock_iothread (); } fail:
Signature · 1 line
1.8.3.1
Quoted 32 lines · * zhanghailiang ([email protected]) wrote:
commit
fe904ea8242cbae2d7e69c052c754b8f5f1ba1d6fixed 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 branchCase 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_cancelcan slip in whenevermigration_threaddoes not hold the global lock. If this happens afterbdrv_inactive_all()been called, the above error reports will appear.
Quoted 7 lines
To prevent this, we can call
bdrv_invalidate_cache_all()inqmp_migrate_cancel()directly if we find images become inactive.Besides,
bdrv_invalidate_cache_all()inmigration_completion()doesn't have the protection of big lock, fix it by add the missingqemu_mutex_lock_iothread();Signed-off-by zhanghailiang <[email protected]>
Yes, I think tht's better:
Quoted 71 lines
---
v2:
- Fix a bug introduced by commit fe904 which didn't get big lock before callbdrv_invalidate_cache_all. (Suggested by Dave)--- include/migration/migration.h | 3 +++ migration/migration.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+)include/migration/migration.h +3
-0@@ -177,6 +177,9 @@ struct MigrationState/* Flag set once the migration thread is running (and needs joining) */ bool migration_thread_running; +/* Flag set once the migration thread called bdrv_inactivate_all */ +bool block_inactive; +/* Queue of outstanding page requests from the destination */ QemuMutex src_page_req_mutex; QSIMPLEQ_HEAD(src_page_requests, MigrationSrcPageRequest) src_page_requests;migration/migration.c +15
-0@@ -1006,6 +1006,16 @@ static void migrate_fd_cancel(MigrationState *s)if (s->state ==MIGRATION_STATUS_CANCELLING && f) {qemu_file_shutdown (f); } +if (s->state ==MIGRATION_STATUS_CANCELLING && s->block_inactive) { +Error *local_err =NULL ; + +bdrv_invalidate_cache_all (&local_err); +if (local_err) { +error_report_err (local_err); + }else { + s->block_inactive = false; + } + } }void add_migration_state_change_notifier (Notifier *notify)@@ -1705,6 +1715,7 @@ static void migration_completion(MigrationState *s, int current_active_state,if (ret >=0 ) {qemu_file_set_rate_limit (s->to_dst_file,INT64_MAX );qemu_savevm_state_complete_precopy (s->to_dst_file, false); + s->block_inactive = true; } }qemu_mutex_unlock_iothread ();@@ -1755,10 +1766,14 @@ fail_invalidate:if (s->state ==MIGRATION_STATUS_ACTIVE ) {Error *local_err =NULL ; +qemu_mutex_lock_iothread ();bdrv_invalidate_cache_all (&local_err);if (local_err) {error_report_err (local_err); + }else { + s->block_inactive = false; } +qemu_mutex_unlock_iothread (); } fail:Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 6 lines · * zhanghailiang ([email protected]) wrote:
commit
fe904ea8242cbae2d7e69c052c754b8f5f1ba1d6fixed 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",
Queued.
Dave
Quoted 105 lines
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 branchCase 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_cancelcan slip in whenevermigration_threaddoes not hold the global lock. If this happens afterbdrv_inactive_all()been called, the above error reports will appear.To prevent this, we can call
bdrv_invalidate_cache_all()inqmp_migrate_cancel()directly if we find images become inactive.Besides,
bdrv_invalidate_cache_all()inmigration_completion()doesn't have the protection of big lock, fix it by add the missingqemu_mutex_lock_iothread();Signed-off-by zhanghailiang <[email protected]>---
v2:
- Fix a bug introduced by commit fe904 which didn't get big lock before callbdrv_invalidate_cache_all. (Suggested by Dave)--- include/migration/migration.h | 3 +++ migration/migration.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+)include/migration/migration.h +3
-0@@ -177,6 +177,9 @@ struct MigrationState/* Flag set once the migration thread is running (and needs joining) */ bool migration_thread_running; +/* Flag set once the migration thread called bdrv_inactivate_all */ +bool block_inactive; +/* Queue of outstanding page requests from the destination */ QemuMutex src_page_req_mutex; QSIMPLEQ_HEAD(src_page_requests, MigrationSrcPageRequest) src_page_requests;migration/migration.c +15
-0@@ -1006,6 +1006,16 @@ static void migrate_fd_cancel(MigrationState *s)if (s->state ==MIGRATION_STATUS_CANCELLING && f) {qemu_file_shutdown (f); } +if (s->state ==MIGRATION_STATUS_CANCELLING && s->block_inactive) { +Error *local_err =NULL ; + +bdrv_invalidate_cache_all (&local_err); +if (local_err) { +error_report_err (local_err); + }else { + s->block_inactive = false; + } + } }void add_migration_state_change_notifier (Notifier *notify)@@ -1705,6 +1715,7 @@ static void migration_completion(MigrationState *s, int current_active_state,if (ret >=0 ) {qemu_file_set_rate_limit (s->to_dst_file,INT64_MAX );qemu_savevm_state_complete_precopy (s->to_dst_file, false); + s->block_inactive = true; } }qemu_mutex_unlock_iothread ();@@ -1755,10 +1766,14 @@ fail_invalidate:if (s->state ==MIGRATION_STATUS_ACTIVE ) {Error *local_err =NULL ; +qemu_mutex_lock_iothread ();bdrv_invalidate_cache_all (&local_err);if (local_err) {error_report_err (local_err); + }else { + s->block_inactive = false; } +qemu_mutex_unlock_iothread (); } fail:Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 39 lines · zhanghailiang
commit
fe904ea8242cbae2d7e69c052c754b8f5f1ba1d6fixed 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 branchCase 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_cancelcan slip in whenevermigration_threaddoes not hold the global lock. If this happens afterbdrv_inactive_all()been called, the above error reports will appear.To prevent this, we can call
bdrv_invalidate_cache_all()inqmp_migrate_cancel()directly if we find images become inactive.Besides,
bdrv_invalidate_cache_all()inmigration_completion()doesn't have the protection of big lock, fix it by add the missingqemu_mutex_lock_iothread();Signed-off-by zhanghailiang <[email protected]>
Quoted 8 lines
---
v2:
- Fix a bug introduced by commit fe904 which didn't get big lock before callbdrv_invalidate_cache_all. (Suggested by Dave)--- include/migration/migration.h | 3 +++ migration/migration.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+)