migration: Better error handling in rp thread, allow failures in recover
v3 cover migration: Better error handling in rp thread, allow failures in recover
v3:
- Rebase to master after majority of Fabiano's series merged
- Dropped patch 2: "migration: Let migrate_set_error() take ownership" (When looking again, I'm not happy with neither that of my patch nor current code. But in that case I prefer change nothing rather than changing from one ugly to another)
- Dropped a few Fabiano's R-b due to either rebase (return path thread now is recycled when pausing postcopy) or additional error_free() after I dropped patch 2
v1: https://lore.kernel.org/r/[email protected]
v2: https://lore.kernel.org/r/[email protected]
This series allow better error handling in the postcopy return path thread, so that we'll start to store the errors in MigrationState and can be seen from query-migrate later, comparing to before where we do error_report() and never remember the error.
Meanwhile, it allows double-failures to happen during postcopy recovery, IOW, one can fail again right during RECOVER phase on both sides, even if RECOVER phase should be an extremely small window.
Please have a look, thanks.
Fabiano Rosas (1):
tests/migration-test: Add a test for postcopy hangs during RECOVER
Peter Xu (9):
migration: Display error in query-migrate irrelevant of status
migration: Introduce migrate_has_error()
migration: Refactor error handling in source return path
migration: Deliver return path file error to migrate state too
qemufile: Always return a verbose error
migration: Remember num of ramblocks to sync during recovery
migration: Add migration_rp_wait|kick()
migration: Allow network to fail even during recovery
migration: Allow RECOVER->PAUSED convertion for dest qemu
qapi/migration.json | 5 +- migration/migration.h | 21 +++- migration/qemu-file.h | 1 + migration/ram.h | 5 +- migration/migration.c | 206 ++++++++++++++++++++++------------- migration/qemu-file.c | 17 ++- migration/ram.c | 76 +++++++------ migration/savevm.c | 3 +- tests/qtest/migration-test.c | 94 ++++++++++++++++ migration/trace-events | 4 +- 10 files changed, 312 insertions(+), 120 deletions(-)
Signature · 1 line
2.41.0
PATCH v3 1/10 migration: Display error in query-migrate irrelevant of status
Display it as long as being set, irrelevant of FAILED status. E.g., it may also be applicable to PAUSED stage of postcopy, to provide hint on what has gone wrong.
The error_mutex seems to be overlooked when referencing the error, add it to be very safe.
This will change QAPI behavior by showing up error message outside !FAILED status, but it's intended and doesn't expect to break anyone.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2018404
--- qapi/migration.json | 5 ++--- migration/migration.c | 8 +++++--- 2 files changed, 7 insertions(+), 6 deletions(-)
qapi/migration.json +2 -3
@@ -230,9 +230,8 @@ # throttled during auto-converge. This is only present when # auto-converge has started throttling guest cpus. (Since 2.7) # -# @error-desc: the human readable error description string, when -# @status is 'failed'. Clients should not attempt to parse the -# error strings. (Since 2.7) +# @error-desc: the human readable error description string. Clients +# should not attempt to parse the error strings. (Since 2.7) # # @postcopy-blocktime: total time when all vCPU were blocked during # postcopy live migration. This is only present when the
migration/migration.c +5 -3
@@ -1057,9 +1057,6 @@ static void fill_source_migration_info(MigrationInfo *info)break ;case MIGRATION_STATUS_FAILED : info->has_status = true; -if (s->error) { - info->error_desc =g_strdup (error_get_pretty (s->error)); - }break ;case MIGRATION_STATUS_CANCELLED : info->has_status = true;
@@ -1069,6 +1066,11 @@ static void fill_source_migration_info(MigrationInfo *info)break ; } info->status = state; + +QEMU_LOCK_GUARD (&s->error_mutex); +if (s->error) { + info->error_desc =g_strdup (error_get_pretty (s->error)); + } }static void fill_destination_migration_info (MigrationInfo *info)
Signature · 1 line
2.41.0
Re: [PATCH v3 01/10] migration: Display error in query-migrate irrelevant of status
Quoted 7 lines · Peter Xu
Display it as long as being set, irrelevant of FAILED status. E.g., it may also be applicable to PAUSED stage of postcopy, to provide hint on what has gone wrong.
The
error_mutexseems to be overlooked when referencing the error, add it to be very safe.
Quoted 6 lines
This will change QAPI behavior by showing up error message outside !FAILED status, but it's intended and doesn't expect to break anyone.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2018404
Reviewed-by Fabiano Rosas <[email protected]>Signed-off-by Peter Xu <[email protected]>
queued.
PATCH v3 2/10 migration: Introduce migrate_has_error()
In reply to Peter XuIntroduce a helper to detect whether MigrationState.error is set for whatever reason.
This is preparation work for any thread (e.g. source return path thread) to setup errors in an unified way to MigrationState, rather than relying on its own way to set errors (mark_source_rp_bad()).
--- migration/migration.h | 1 + migration/migration.c | 7 +++++++ 2 files changed, 8 insertions(+)
migration/migration.h +1 -0
@@ -476,6 +476,7 @@ bool migration_has_all_channels(void);uint64_t migrate_max_downtime (void );void migrate_set_error (MigrationState *s,const Error *error); +bool migrate_has_error (MigrationState *s);void migrate_fd_connect (MigrationState *s,Error *error_in);
migration/migration.c +7 -0
@@ -1231,6 +1231,13 @@ void migrate_set_error(MigrationState *s, const Error *error) } } +bool migrate_has_error (MigrationState *s) +{ +/* The lock is not helpful here, but still follow the rule */ +QEMU_LOCK_GUARD (&s->error_mutex); +return qatomic_read (&s->error); +} +static void migrate_error_free (MigrationState *s) {QEMU_LOCK_GUARD (&s->error_mutex);
Signature · 1 line
2.41.0
Re: [PATCH v3 02/10] migration: Introduce migrate_has_error()
Quoted 9 lines · Peter Xu
Introduce a helper to detect whether MigrationState.error is set for whatever reason.
This is preparation work for any thread (e.g. source return path thread) to setup errors in an unified way to MigrationState, rather than relying on its own way to set errors (
mark_source_rp_bad()).Reviewed-by Fabiano Rosas <[email protected]>Signed-off-by Peter Xu <[email protected]>
queued
PATCH v3 3/10 migration: Refactor error handling in source return path
In reply to Peter Xurp_state.error was a boolean used to show error happened in return path thread. That's not only duplicating error reporting (migrate_set_error), but also not good enough in that we only do error_report() and set it to true, we never can keep a history of the exact error and show it in query-migrate.
To make this better, a few things done:
- Use error_setg() rather than error_report() across the whole lifecycle of return path thread, keeping the error in an Error*.
- Use migrate_set_error() to apply that captured error to the global migration object when error occured in this thread.
- With above, no need to have mark_source_rp_bad(), remove it, alongside with rp_state.error itself.
--- migration/migration.h | 1 - migration/ram.h | 5 +- migration/migration.c | 123 ++++++++++++++++++----------------------- migration/ram.c | 41 +++++++------- migration/trace-events | 4 +- 5 files changed, 79 insertions(+), 95 deletions(-)
migration/migration.h +0 -1
@@ -308,7 +308,6 @@ struct MigrationState {/* Protected by qemu_file_lock */ QEMUFile *from_dst_file;QemuThread rp_thread; -bool error;/* * We can also check non-zero of rp_thread, but there's no "official" * way to do this, so this bool makes it slightly more elegant.
migration/ram.h +3 -2
@@ -51,7 +51,8 @@ uint64_t ram_bytes_total(void);void mig_throttle_counter_reset (void );uint64_t ram_pagesize_summary (void ); -int ram_save_queue_pages (const char *rbname,ram_addr_t start,ram_addr_t len); +int ram_save_queue_pages (const char *rbname,ram_addr_t start,ram_addr_t len, +Error **errp);void ram_postcopy_migrated_memory_release (MigrationState *ms);/* For outgoing discard bitmap */ void ram_postcopy_send_discard_bitmap (MigrationState *ms);
@@ -71,7 +72,7 @@ void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr);void ramblock_recv_bitmap_set_range (RAMBlock *rb,void *host_addr,size_t nr);int64_t ramblock_recv_bitmap_send (QEMUFile *file,const char *block_name); -int ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *rb); +int ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *rb,Error **errp);bool ramblock_page_is_discarded (RAMBlock *rb,ram_addr_t start);void postcopy_preempt_shutdown_file (MigrationState *s);void *postcopy_preempt_thread (void *opaque);
migration/migration.c +54 -69
270 lines not on this page · raw message
migration/ram.c +21 -20
100 lines not on this page · raw message
migration/trace-events +1 -3
@@ -147,8 +147,6 @@ multifd_tls_outgoing_handshake_complete(void *ioc) "ioc=%p" multifd_set_outgoing_channel(void *ioc, const char *ioctype, const char *hostname, void *err) "ioc=%p ioctype=%s hostname=%s err=%p" # migration.c -await_return_path_close_on_source_close(void) "" -await_return_path_close_on_source_joining(void) "" migrate_set_state(const char *new_state) "new state %s" migrate_fd_cleanup(void) "" migrate_fd_error(const char *error_desc) "error=%s"
@@ -165,7 +163,7 @@ migration_completion_postcopy_end_after_complete(void) "" migration_rate_limit_pre(int ms) "%d ms" migration_rate_limit_post(int urgent) "urgent: %d" migration_return_path_end_before(void) "" -migration_return_path_end_after(int rp_error) "%d" +migration_return_path_end_after(void) "" migration_thread_after_loop(void) "" migration_thread_file_err(void) "" migration_thread_setup_complete(void) ""
Signature · 1 line
2.41.0
Re: [PATCH v3 03/10] migration: Refactor error handling in source return path
Hi Peter,
Quoted 46 lines · Peter Xu
rp_state.error was a boolean used to show error happened in return path thread. That's not only duplicating error reporting (
migrate_set_error), but also not good enough in that we only doerror_report()and set it to true, we never can keep a history of the exact error and show it in query-migrate.To make this better, a few things done:
- Use
error_setg()rather thanerror_report()across the whole lifecycle of return path thread, keeping the error in an Error*.- Use
migrate_set_error()to apply that captured error to the global migration object when error occured in this thread.- With above, no need to have
mark_source_rp_bad(), remove it, alongside with rp_state.error itself.Signed-off-by Peter Xu <[email protected]>--- migration/migration.h | 1 - migration/ram.h | 5 +- migration/migration.c | 123 ++++++++++++++++++----------------------- migration/ram.c | 41 +++++++------- migration/trace-events | 4 +- 5 files changed, 79 insertions(+), 95 deletions(-)migration/ram.c +4
-4-int ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *block) +int ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *block,Error **errp) {int ret = -EINVAL ;/* from_dst_file is always valid because we're within rp_thread */ @@ -4193,16 +4194,16 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) ret =qemu_file_get_error (file);if (ret || size != local_size) { -error_report ("%s: read bitmap failed for ramblock '%s': %d" -" (size 0x%" PRIx64", got: 0x%" PRIx64")" , - __func__, block->idstr, ret, local_size, size); +error_setg (errp,"read bitmap failed for ramblock '%s': %d" +" (size 0x%" PRIx64", got: 0x%" PRIx64")" , + block->idstr, ret, local_size, size); ret = -EIO ; goto out;
migration/ram.c int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) · line 4209
Quoted 10 lines
migration/ram.c +2
-2}if (end_mark !=RAMBLOCK_RECV_BITMAP_ENDING ) { -error_report ("%s: ramblock '%s' end mark incorrect: 0x%" PRIx64, - __func__, block->idstr, end_mark); +error_setg (errp,"ramblock '%s' end mark incorrect: 0x%" PRIx64, + block->idstr, end_mark); ret = -EINVAL ; goto out; }
This function returns -EIO/-EINVAL errors, propagated to its 2 callers
- migrate_handle_rp_recv_bitmap()
- migrate_handle_rp_resume_ack()
which are only used in source_return_path_thread() where the return value is only checked as boolean.
Could we simplify them returning a boolean (which is the pattern with functions taking an Error** as last parameter)?
Regards,
Phil.
Re: [PATCH v3 03/10] migration: Refactor error handling in source return path
Quoted 53 lines · Philippe Mathieu-Daudé
Hi Peter,
Quoted 50 lines · Peter Xu
rp_state.error was a boolean used to show error happened in return path thread. That's not only duplicating error reporting (
migrate_set_error), but also not good enough in that we only doerror_report()and set it to true, we never can keep a history of the exact error and show it in query-migrate.To make this better, a few things done:
- Use
error_setg()rather thanerror_report()across the whole lifecycle of return path thread, keeping the error in an Error*.- Use
migrate_set_error()to apply that captured error to the global migration object when error occured in this thread.- With above, no need to have
mark_source_rp_bad(), remove it, alongside with rp_state.error itself.Signed-off-by Peter Xu <[email protected]>--- migration/migration.h | 1 - migration/ram.h | 5 +- migration/migration.c | 123 ++++++++++++++++++----------------------- migration/ram.c | 41 +++++++------- migration/trace-events | 4 +- 5 files changed, 79 insertions(+), 95 deletions(-)(quoted diff) +5
-6-int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) +int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp) { int ret = -EINVAL; /* from_dst_file is always valid because we're within rp_thread */@@ -4193,16 +4194,16 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) ret = qemu_file_get_error(file); if (ret || size != local_size) { - error_report("%s: read bitmap failed for ramblock '%s': %d" - " (size 0x%"PRIx64", got: 0x%"PRIx64")", - __func__, block->idstr, ret, local_size, size); + error_setg(errp, "read bitmap failed for ramblock '%s': %d" + " (size 0x%"PRIx64", got: 0x%"PRIx64")", + block->idstr, ret, local_size, size); ret = -EIO; goto out; } if (end_mark != RAMBLOCK_RECV_BITMAP_ENDING) { - error_report("%s: ramblock '%s' end mark incorrect: 0x%"PRIx64, - __func__, block->idstr, end_mark); + error_setg(errp, "ramblock '%s' end mark incorrect: 0x%"PRIx64,
Quoted 8 lines
Review int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) · line 4207
Quoted 4 lines
(quoted diff) +1
-0+ block->idstr, end_mark); ret = -EINVAL; goto out; }This function returns -EIO/-EINVAL errors, propagated to its 2 callers
-migrate_handle_rp_recv_bitmap()
-migrate_handle_rp_resume_ack()
It was only called in migrate_handle_rp_recv_bitmap(), but I think I see what you meant..
Quoted 5 lines
which are only used in
source_return_path_thread()where the return value is only checked as boolean.Could we simplify them returning a boolean (which is the pattern with functions taking an Error** as last parameter)?
Yes, with errp passed in, the "int" retcode is slightly duplicated. I can add one more patch on top of this as further cleanup, as below.
Thanks,
===8<===
From b1052befd72beb129012afddf5647339fe4e257c Mon Sep 17 00:00:00 2001
From: Peter Xu <[email protected]>
Date: Thu, 5 Oct 2023 12:03:44 -0400
Subject: [PATCH] migration: Change ram_dirty_bitmap_reload() retval to bool
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Now we have a Error** passed into the return path thread stack, which is even clearer than an int retval. Change ram_dirty_bitmap_reload() and the callers to use a bool instead to replace errnos.
--- migration/ram.h | 2 +- migration/migration.c | 18 +++++++++--------- migration/ram.c | 24 +++++++++++------------- 3 files changed, 21 insertions(+), 23 deletions(-)
migration/ram.h +1 -1
@@ -72,7 +72,7 @@ void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr);void ramblock_recv_bitmap_set_range (RAMBlock *rb,void *host_addr,size_t nr);int64_t ramblock_recv_bitmap_send (QEMUFile *file,const char *block_name); -int ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *rb,Error **errp); +bool ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *rb,Error **errp);bool ramblock_page_is_discarded (RAMBlock *rb,ram_addr_t start);void postcopy_preempt_shutdown_file (MigrationState *s);void *postcopy_preempt_thread (void *opaque);
migration/migration.c +9 -9
@@ -1837,29 +1837,29 @@ static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname,ram_save_queue_pages (rbname, start, len, errp); } -static int migrate_handle_rp_recv_bitmap (MigrationState *s,char *block_name, -Error **errp) +static bool migrate_handle_rp_recv_bitmap (MigrationState *s,char *block_name, +Error **errp) {RAMBlock *block =qemu_ram_block_by_name (block_name);if (!block) {error_setg (errp,"MIG_RP_MSG_RECV_BITMAP has invalid block name '%s'" , block_name); -return -EINVAL ; +return false; }/* Fetch the received bitmap and refresh the dirty bitmap */ return ram_dirty_bitmap_reload (s, block, errp); } -static int migrate_handle_rp_resume_ack (MigrationState *s, -uint32_t value,Error **errp) +static bool migrate_handle_rp_resume_ack (MigrationState *s, +uint32_t value,Error **errp) {trace_source_return_path_thread_resume_ack (value);if (value !=MIGRATION_RESUME_ACK_VALUE ) {error_setg (errp,"illegal resume_ack value %" PRIu32, value); -return -1 ; +return false; }/* Now both sides are active. */
@@ -1869,7 +1869,7 @@ static int migrate_handle_rp_resume_ack(MigrationState *s,/* Notify send thread that time to continue send pages */ migration_rp_kick (s); -return 0 ; +return true; }/*
@@ -2021,14 +2021,14 @@ static void *source_return_path_thread(void *opaque) }/* Format: len (1B) + idstr (<255B). This ends the idstr. */ buf[buf[0 ] +1 ] ='\0' ; -if (migrate_handle_rp_recv_bitmap (ms, (char *)(buf +1 ), &err)) { +if (!migrate_handle_rp_recv_bitmap (ms, (char *)(buf +1 ), &err)) { goto out; }break ;case MIG_RP_MSG_RESUME_ACK : tmp32 =ldl_be_p (buf); -if (migrate_handle_rp_resume_ack (ms, tmp32, &err)) { +if (!migrate_handle_rp_resume_ack (ms, tmp32, &err)) { goto out; }break ;
migration/ram.c +11 -13
@@ -4157,23 +4157,25 @@ static int ram_dirty_bitmap_sync_all(MigrationState *s, RAMState *rs)* Read the received bitmap, revert it as the initial dirty bitmap. * This is only used when the postcopy migration is paused but wants * to resume from a middle point. +* +* Returns true if succeeded, false for errors. */ -int ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *block,Error **errp) +bool ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *block,Error **errp) { -int ret = -EINVAL ;/* from_dst_file is always valid because we're within rp_thread */ QEMUFile *file = s->rp_state.from_dst_file;unsigned long *le_bitmap, nbits = block->used_length >>TARGET_PAGE_BITS ;uint64_t local_size =DIV_ROUND_UP (nbits,8 );uint64_t size, end_mark;RAMState *rs = ram_state; +bool result = false;trace_ram_dirty_bitmap_reload_begin (block->idstr);if (s->state !=MIGRATION_STATUS_POSTCOPY_RECOVER ) {error_setg (errp,"Reload bitmap in incorrect state %s" ,MigrationStatus_str (s->state)); -return -EINVAL ; +return false; }/*
@@ -4191,26 +4193,22 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp)if (size != local_size) {error_setg (errp,"ramblock '%s' bitmap size mismatch (0x%" PRIx64" != 0x%" PRIx64")" , block->idstr, size, local_size); - ret = -EINVAL ; goto out; } size =qemu_get_buffer (file, (uint8_t *)le_bitmap, local_size); end_mark =qemu_get_be64 (file); - ret =qemu_file_get_error (file); -if (ret || size != local_size) { -error_setg (errp,"read bitmap failed for ramblock '%s': %d" -" (size 0x%" PRIx64", got: 0x%" PRIx64")" , - block->idstr, ret, local_size, size); - ret = -EIO ; +if (qemu_file_get_error (file) || size != local_size) { +error_setg (errp,"read bitmap failed for ramblock '%s': " +"(size 0x%" PRIx64", got: 0x%" PRIx64")" , + block->idstr, local_size, size); goto out; }if (end_mark !=RAMBLOCK_RECV_BITMAP_ENDING ) {error_setg (errp,"ramblock '%s' end mark incorrect: 0x%" PRIx64, block->idstr, end_mark); - ret = -EINVAL ; goto out; }
@@ -4243,10 +4241,10 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp)*/ migration_rp_kick (s); - ret =0 ; + result = true; out:g_free (le_bitmap); -return ret; +return result; }static int ram_resume_prepare (MigrationState *s,void *opaque)
Signature · 5 lines
2.41.0 -- Peter Xu
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH v3 03/10] migration: Refactor error handling in source return path
Quoted 244 lines · Peter Xu
Quoted 53 lines · Philippe Mathieu-Daudé
Hi Peter,
Quoted 50 lines · Peter Xu
rp_state.error was a boolean used to show error happened in return path thread. That's not only duplicating error reporting (
migrate_set_error), but also not good enough in that we only doerror_report()and set it to true, we never can keep a history of the exact error and show it in query-migrate.To make this better, a few things done:
- Use
error_setg()rather thanerror_report()across the whole lifecycle of return path thread, keeping the error in an Error*.- Use
migrate_set_error()to apply that captured error to the global migration object when error occured in this thread.- With above, no need to have
mark_source_rp_bad(), remove it, alongside with rp_state.error itself.Signed-off-by Peter Xu <[email protected]>--- migration/migration.h | 1 - migration/ram.h | 5 +- migration/migration.c | 123 ++++++++++++++++++----------------------- migration/ram.c | 41 +++++++------- migration/trace-events | 4 +- 5 files changed, 79 insertions(+), 95 deletions(-)(quoted diff) +5
-6-int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) +int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp) { int ret = -EINVAL; /* from_dst_file is always valid because we're within rp_thread */@@ -4193,16 +4194,16 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) ret = qemu_file_get_error(file); if (ret || size != local_size) { - error_report("%s: read bitmap failed for ramblock '%s': %d" - " (size 0x%"PRIx64", got: 0x%"PRIx64")", - __func__, block->idstr, ret, local_size, size); + error_setg(errp, "read bitmap failed for ramblock '%s': %d" + " (size 0x%"PRIx64", got: 0x%"PRIx64")", + block->idstr, ret, local_size, size); ret = -EIO; goto out; } if (end_mark != RAMBLOCK_RECV_BITMAP_ENDING) { - error_report("%s: ramblock '%s' end mark incorrect: 0x%"PRIx64, - __func__, block->idstr, end_mark); + error_setg(errp, "ramblock '%s' end mark incorrect: 0x%"PRIx64,Quoted 8 lines
migration/migration.c static void *source_return_path_thread(void *opaque) · line 2026
Quoted 4 lines
migration/migration.c +1
-0+ block->idstr, end_mark); ret = -EINVAL ; goto out; }This function returns -EIO/-EINVAL errors, propagated to its 2 callers
-migrate_handle_rp_recv_bitmap()
-migrate_handle_rp_resume_ack()It was only called in
migrate_handle_rp_recv_bitmap(), but I think I see what you meant..Quoted 5 lines
which are only used in
source_return_path_thread()where the return value is only checked as boolean.Could we simplify them returning a boolean (which is the pattern with functions taking an Error** as last parameter)?
Yes, with errp passed in, the "int" retcode is slightly duplicated. I can add one more patch on top of this as further cleanup, as below.
Thanks,
===8<===
Fromb1052befd72beb129012afddf5647339fe4e257cMon Sep 17 00:00:00 2001
From: Peter Xu <[email protected]>
Date: Thu, 5 Oct 2023 12:03:44 -0400
Subject: [PATCH] migration: Changeram_dirty_bitmap_reload()retval to bool
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitNow we have a Error** passed into the return path thread stack, which is even clearer than an int retval. Change
ram_dirty_bitmap_reload()and the callers to use a bool instead to replace errnos.Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Peter Xu <[email protected]>--- migration/ram.h | 2 +- migration/migration.c | 18 +++++++++--------- migration/ram.c | 24 +++++++++++------------- 3 files changed, 21 insertions(+), 23 deletions(-)migration/ram.h +1
-1@@ -72,7 +72,7 @@ void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr);void ramblock_recv_bitmap_set_range (RAMBlock *rb,void *host_addr,size_t nr);int64_t ramblock_recv_bitmap_send (QEMUFile *file,const char *block_name); -int ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *rb,Error **errp); +bool ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *rb,Error **errp);bool ramblock_page_is_discarded (RAMBlock *rb,ram_addr_t start);void postcopy_preempt_shutdown_file (MigrationState *s);void *postcopy_preempt_thread (void *opaque);migration/migration.c +9
-9@@ -1837,29 +1837,29 @@ static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname,ram_save_queue_pages (rbname, start, len, errp); } -static int migrate_handle_rp_recv_bitmap (MigrationState *s,char *block_name, -Error **errp) +static bool migrate_handle_rp_recv_bitmap (MigrationState *s,char *block_name, +Error **errp) {RAMBlock *block =qemu_ram_block_by_name (block_name);if (!block) {error_setg (errp,"MIG_RP_MSG_RECV_BITMAP has invalid block name '%s'" , block_name); -return -EINVAL ; +return false; }/* Fetch the received bitmap and refresh the dirty bitmap */ return ram_dirty_bitmap_reload (s, block, errp); } -static int migrate_handle_rp_resume_ack (MigrationState *s, -uint32_t value,Error **errp) +static bool migrate_handle_rp_resume_ack (MigrationState *s, +uint32_t value,Error **errp) {trace_source_return_path_thread_resume_ack (value);if (value !=MIGRATION_RESUME_ACK_VALUE ) {error_setg (errp,"illegal resume_ack value %" PRIu32, value); -return -1 ; +return false; }/* Now both sides are active. */ @@ -1869,7 +1869,7 @@ static int migrate_handle_rp_resume_ack(MigrationState *s,/* Notify send thread that time to continue send pages */ migration_rp_kick (s); -return 0 ; +return true; }/* @@ -2021,14 +2021,14 @@ static void *source_return_path_thread(void *opaque) }/* Format: len (1B) + idstr (<255B). This ends the idstr. */ buf[buf[0 ] +1 ] ='\0' ; -if (migrate_handle_rp_recv_bitmap (ms, (char *)(buf +1 ), &err)) { +if (!migrate_handle_rp_recv_bitmap (ms, (char *)(buf +1 ), &err)) { goto out; }break ;case MIG_RP_MSG_RESUME_ACK : tmp32 =ldl_be_p (buf); -if (migrate_handle_rp_resume_ack (ms, tmp32, &err)) { +if (!migrate_handle_rp_resume_ack (ms, tmp32, &err)) { goto out; }break ;migration/ram.c +9
-11@@ -4157,23 +4157,25 @@ static int ram_dirty_bitmap_sync_all(MigrationState *s, RAMState *rs)* Read the received bitmap, revert it as the initial dirty bitmap. * This is only used when the postcopy migration is paused but wants * to resume from a middle point. +* +* Returns true if succeeded, false for errors. */ -int ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *block,Error **errp) +bool ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *block,Error **errp) { -int ret = -EINVAL ;/* from_dst_file is always valid because we're within rp_thread */ QEMUFile *file = s->rp_state.from_dst_file;unsigned long *le_bitmap, nbits = block->used_length >>TARGET_PAGE_BITS ;uint64_t local_size =DIV_ROUND_UP (nbits,8 );uint64_t size, end_mark;RAMState *rs = ram_state; +bool result = false;trace_ram_dirty_bitmap_reload_begin (block->idstr);if (s->state !=MIGRATION_STATUS_POSTCOPY_RECOVER ) {error_setg (errp,"Reload bitmap in incorrect state %s" ,MigrationStatus_str (s->state)); -return -EINVAL ; +return false; }/* @@ -4191,26 +4193,22 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp)if (size != local_size) {error_setg (errp,"ramblock '%s' bitmap size mismatch (0x%" PRIx64" != 0x%" PRIx64")" , block->idstr, size, local_size); - ret = -EINVAL ; goto out; } size =qemu_get_buffer (file, (uint8_t *)le_bitmap, local_size); end_mark =qemu_get_be64 (file); - ret =qemu_file_get_error (file); -if (ret || size != local_size) { -error_setg (errp,"read bitmap failed for ramblock '%s': %d" -" (size 0x%" PRIx64", got: 0x%" PRIx64")" , - block->idstr, ret, local_size, size); - ret = -EIO ; +if (qemu_file_get_error (file) || size != local_size) { +error_setg (errp,"read bitmap failed for ramblock '%s': " +"(size 0x%" PRIx64", got: 0x%" PRIx64")" , + block->idstr, local_size, size); goto out; }if (end_mark !=RAMBLOCK_RECV_BITMAP_ENDING ) {error_setg (errp,"ramblock '%s' end mark incorrect: 0x%" PRIx64, block->idstr, end_mark); - ret = -EINVAL ; goto out; }@@ -4243,10 +4241,10 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp)*/ migration_rp_kick (s);
migration/ram.c int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp) · line 4250
Quoted 10 lines
migration/ram.c +2
-2- ret =0 ; + result = true; out:g_free (le_bitmap); -return ret; +return result; }static int ram_resume_prepare (MigrationState *s,void *opaque)
Yes, exactly what I meant. For the embedded patch:
One step further is to use g_autofree for le_bitmap to remove this annoying 'out' label. I'll send the patch.
Re: [PATCH v3 03/10] migration: Refactor error handling in source return path
In reply to Peter XuQuoted 10 lines · Peter Xu
rp_state.error was a boolean used to show error happened in return path thread. That's not only duplicating error reporting (
migrate_set_error), but also not good enough in that we only doerror_report()and set it to true, we never can keep a history of the exact error and show it in query-migrate.To make this better, a few things done:
- Use
error_setg()rather thanerror_report()across the whole lifecycle of return path thread, keeping the error in an Error*.
Good.
Quoted 2 lines
- Use
migrate_set_error()to apply that captured error to the global migration object when error occured in this thread.
Good.
Quoted 2 lines
- With above, no need to have
mark_source_rp_bad(), remove it, alongside with rp_state.error itself.
Good.
migration/ram.h uint64_t ram_bytes_total(void); · line 55
Quoted 4 lines
uint64_tram_pagesize_summary(void);migration/ram.h +2
-1-int ram_save_queue_pages (const char *rbname,ram_addr_t start,ram_addr_t len); +int ram_save_queue_pages (const char *rbname,ram_addr_t start,ram_addr_t len, +Error **errp);
good.
Quoted 6 lines
migration/migration.c +0
-2@@ -1793,37 +1782,36 @@ static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname,*/ if (!QEMU_IS_ALIGNED (start, our_host_ps) || !QEMU_IS_ALIGNED (len, our_host_ps)) { -error_report ("%s: Misaligned page request, start: " RAM_ADDR_FMT -" len: %zd" , __func__, start, len);
migration/migration.c static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname, · line 1790
Quoted 10 lines
migration/migration.c +3
-4-mark_source_rp_bad (ms); +error_setg (errp,"MIG_RP_MSG_REQ_PAGES: Misaligned page request, start:" +RAM_ADDR_FMT " len: %zd" , start, len);return ; } -if (ram_save_queue_pages (rbname, start, len)) { -mark_source_rp_bad (ms); - } +ram_save_queue_pages (rbname, start, len, errp);
ram_save_queue_pages() returns an int.
I think this function should return an int.
Next is independent of this patch:
migration/migration.c static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname, · line 1801
Quoted 11 lines
migration/migration.c +4
-2-static int migrate_handle_rp_recv_bitmap (MigrationState *s,char *block_name) +static int migrate_handle_rp_recv_bitmap (MigrationState *s,char *block_name, +Error **errp) {RAMBlock *block =qemu_ram_block_by_name (block_name);if (!block) { -error_report ("%s: invalid block name '%s'" , __func__, block_name); +error_setg (errp,"MIG_RP_MSG_RECV_BITMAP has invalid block name '%s'" , + block_name);return -EINVAL ;
We sent -EINVAL.
Quoted 8 lines
migration/migration.c +1
-2}/* Fetch the received bitmap and refresh the dirty bitmap */ -return ram_dirty_bitmap_reload (s, block); +return ram_dirty_bitmap_reload (s, block, errp); } -static int migrate_handle_rp_resume_ack (MigrationState *s,uint32_t value)
migration/migration.c static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname, · line 1815
Quoted 10 lines
migration/migration.c +3
-2+static int migrate_handle_rp_resume_ack (MigrationState *s, +uint32_t value,Error **errp) {trace_source_return_path_thread_resume_ack (value);if (value !=MIGRATION_RESUME_ACK_VALUE ) { -error_report ("%s: illegal resume_ack value %" PRIu32, - __func__, value); +error_setg (errp,"illegal resume_ack value %" PRIu32, value);return -1 ;
And here -1.
On both callers we just check if it is different from zero. We never use the return value as errno, so I think we should move to -1, if there is an error, that is what errp is for.
Quoted 33 lines
migration/migration.c +3
-14-/* Returns 0 if the RP was ok, otherwise there was an error on the RP */ -static int await_return_path_close_on_source (MigrationState *ms) +static void await_return_path_close_on_source (MigrationState *ms) { -int ret; -if (!ms->rp_state.rp_thread_created) { -return 0 ; +return ; }trace_migration_return_path_end_before ();@@ -2060,18 +2050,10 @@ static int await_return_path_close_on_source(MigrationState *ms) } } -trace_await_return_path_close_on_source_joining ();qemu_thread_join (&ms->rp_state.rp_thread); ms->rp_state.rp_thread_created = false; -trace_await_return_path_close_on_source_close (); - - ret = ms->rp_state.error; - ms->rp_state.error = false; -migration_release_dst_files (ms); - -trace_migration_return_path_end_after (ret); -return ret; +trace_migration_return_path_end_after (); } static inline void
migration/migration.c static void migration_completion(MigrationState *s) · line 2357
Quoted 10 lines
migration/migration.c +4
-1@@ -2367,7 +2349,10 @@ static void migration_completion(MigrationState *s) goto fail; } -if (await_return_path_close_on_source (s)) { +await_return_path_close_on_source (s); + +/* If return path has error, should have been set here */ +if (migrate_has_error (s)) { goto fail; }
In general, I think this is bad. We are moving for
int foo(..)
{
}
....
if (foo()) {
goto fail;
}to:
void foo(..)
{
}
....
foo();
if (bar()) {
goto fail;
}I would preffer to move the other way around. Move the error synchrconously. My plan is that at some point in time qemu_file_get_error() dissapears, i.e. we return the error when we receive it and we handle it synchronously.
And yes, that is a something will take a lot of time, but I will hope we move on that direction, not in trusting more setting internal errors, use void functions and then check with yet another functions.
On top of your changes:
Quoted 6 lines
migration/ram.c +1
-1-int ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *block) +int ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *block,Error **errp){ int ret = -EINVAL; /* from_dst_file is always valid because we're within rp_thread */
migration/ram.c int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) · line 4170
Quoted 8 lines
migration/ram.c +2
-2@@ -4163,8 +4165,8 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block)trace_ram_dirty_bitmap_reload_begin (block->idstr);if (s->state !=MIGRATION_STATUS_POSTCOPY_RECOVER ) { -error_report ("%s: incorrect state %s" , __func__, -MigrationStatus_str (s->state)); +error_setg (errp,"Reload bitmap in incorrect state %s" , +MigrationStatus_str (s->state));return -EINVAL ;
return -1
same for the rest of the cases. Callers only check for != 0, and if you want details, you need to look at errp.
See the nice series for migration/rdma.c for why this is better (and more consistent).
Rest of the patch is very nice.
Thanks, Juan.
Re: [PATCH v3 03/10] migration: Refactor error handling in source return path
Quoted 44 lines · Juan Quintela
Quoted 10 lines · Peter Xu
rp_state.error was a boolean used to show error happened in return path thread. That's not only duplicating error reporting (
migrate_set_error), but also not good enough in that we only doerror_report()and set it to true, we never can keep a history of the exact error and show it in query-migrate.To make this better, a few things done:
- Use
error_setg()rather thanerror_report()across the whole lifecycle of return path thread, keeping the error in an Error*.Good.
Quoted 2 lines
- Use
migrate_set_error()to apply that captured error to the global migration object when error occured in this thread.Good.
Quoted 2 lines
- With above, no need to have
mark_source_rp_bad(), remove it, alongside with rp_state.error itself.Good.
migration/ram.h uint64_t ram_bytes_total(void); · line 55
Quoted 4 lines
uint64_tram_pagesize_summary(void);migration/ram.h +2
-1-int ram_save_queue_pages (const char *rbname,ram_addr_t start,ram_addr_t len); +int ram_save_queue_pages (const char *rbname,ram_addr_t start,ram_addr_t len, +Error **errp);good.
Quoted 12 lines
migration/migration.c +2
-3@@ -1793,37 +1782,36 @@ static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname,*/ if (!QEMU_IS_ALIGNED (start, our_host_ps) || !QEMU_IS_ALIGNED (len, our_host_ps)) { -error_report ("%s: Misaligned page request, start: " RAM_ADDR_FMT -" len: %zd" , __func__, start, len); -mark_source_rp_bad (ms); +error_setg (errp,"MIG_RP_MSG_REQ_PAGES: Misaligned page request, start:" +RAM_ADDR_FMT " len: %zd" , start, len);return ; }
Quoted 7 lines
migration/migration.c static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname, · line 1790
Quoted 4 lines
migration/migration.c +1
-3-if (ram_save_queue_pages (rbname, start, len)) { -mark_source_rp_bad (ms); - } +ram_save_queue_pages (rbname, start, len, errp);
ram_save_queue_pages()returns an int.
I think this function should return an int.
Phil suggested something similar for the other patch, instead of also let this function return int, I'll add one more patch to let it return boolean to show whether there's an error, keeping the real error in errp.
Quoted 38 lines
Next is independent of this patch:
migration/migration.c static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname, · line 1801
Quoted 11 lines
migration/migration.c +4
-2-static int migrate_handle_rp_recv_bitmap (MigrationState *s,char *block_name) +static int migrate_handle_rp_recv_bitmap (MigrationState *s,char *block_name, +Error **errp) {RAMBlock *block =qemu_ram_block_by_name (block_name);if (!block) { -error_report ("%s: invalid block name '%s'" , __func__, block_name); +error_setg (errp,"MIG_RP_MSG_RECV_BITMAP has invalid block name '%s'" , + block_name);return -EINVAL ;We sent
-EINVAL.Quoted 8 lines
migration/migration.c +1
-2}/* Fetch the received bitmap and refresh the dirty bitmap */ -return ram_dirty_bitmap_reload (s, block); +return ram_dirty_bitmap_reload (s, block, errp); } -static int migrate_handle_rp_resume_ack (MigrationState *s,uint32_t value)migration/migration.c static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname, · line 1815
Quoted 10 lines
migration/migration.c +3
-2+static int migrate_handle_rp_resume_ack (MigrationState *s, +uint32_t value,Error **errp) {trace_source_return_path_thread_resume_ack (value);if (value !=MIGRATION_RESUME_ACK_VALUE ) { -error_report ("%s: illegal resume_ack value %" PRIu32, - __func__, value); +error_setg (errp,"illegal resume_ack value %" PRIu32, value);return -1 ;And here -1.
Quoted 3 lines
On both callers we just check if it is different from zero. We never use the return value as errno, so I think we should move to -1, if there is an error, that is what errp is for.
Right. I'll switch all rp-return thread paths to use boolean as return, as long as there's errp.
Quoted 74 lines
Quoted 35 lines
migration/migration.c +3
-14-/* Returns 0 if the RP was ok, otherwise there was an error on the RP */ -static int await_return_path_close_on_source (MigrationState *ms) +static void await_return_path_close_on_source (MigrationState *ms) { -int ret; -if (!ms->rp_state.rp_thread_created) { -return 0 ; +return ; }trace_migration_return_path_end_before ();@@ -2060,18 +2050,10 @@ static int await_return_path_close_on_source(MigrationState *ms) } } -trace_await_return_path_close_on_source_joining ();qemu_thread_join (&ms->rp_state.rp_thread); ms->rp_state.rp_thread_created = false; -trace_await_return_path_close_on_source_close (); - - ret = ms->rp_state.error; - ms->rp_state.error = false; -migration_release_dst_files (ms); - -trace_migration_return_path_end_after (ret); -return ret; +trace_migration_return_path_end_after (); } static inline voidmigration/migration.c static void migration_completion(MigrationState *s) · line 2357
Quoted 10 lines
migration/migration.c +4
-1@@ -2367,7 +2349,10 @@ static void migration_completion(MigrationState *s) goto fail; } -if (await_return_path_close_on_source (s)) { +await_return_path_close_on_source (s); + +/* If return path has error, should have been set here */ +if (migrate_has_error (s)) { goto fail; }In general, I think this is bad. We are moving for
int foo(..)
{}
....
if (foo()) { goto fail; }to:
void foo(..)
{}
....
foo();if (bar()) { goto fail; }
Quoted 8 lines
I would preffer to move the other way around. Move the error synchrconously. My plan is that at some point in time
qemu_file_get_error()dissapears, i.e. we return the error when we receive it and we handle it synchronously.And yes, that is a something will take a lot of time, but I will hope we move on that direction, not in trusting more setting internal errors, use void functions and then check with yet another functions.
IIUC "synchronous" here means we can have the Error* returned from pthread_join(), but I worry that might be too late, that the real return path Error* doesn't get its chance to set into MigrationState.error because there can already be some error set.
I can at least move that check into await_return_path_close_on_source() again, so it keeps returning something. Does that sound like okay for now?
Quoted 21 lines
On top of your changes:
Quoted 6 lines
migration/ram.c +1
-1-int ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *block) +int ram_dirty_bitmap_reload (MigrationState *s,RAMBlock *block,Error **errp){ int ret = -EINVAL; /* from_dst_file is always valid because we're within rp_thread */migration/ram.c int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) · line 4170
Quoted 8 lines
migration/ram.c +2
-2@@ -4163,8 +4165,8 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block)trace_ram_dirty_bitmap_reload_begin (block->idstr);if (s->state !=MIGRATION_STATUS_POSTCOPY_RECOVER ) { -error_report ("%s: incorrect state %s" , __func__, -MigrationStatus_str (s->state)); +error_setg (errp,"Reload bitmap in incorrect state %s" , +MigrationStatus_str (s->state));return -EINVAL ;return -1
Quoted 2 lines
same for the rest of the cases. Callers only check for != 0, and if you want details, you need to look at errp.
I'll let them return boolean here too to be consistent.
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH v3 03/10] migration: Refactor error handling in source return path
In reply to Peter XuQuoted 12 lines · Peter Xu
migration/migration.c +2
-1@@ -1882,48 +1870,46 @@ static void *source_return_path_thread(void *opaque)uint32_t tmp32, sibling_error;ram_addr_t start =0 ;/* =0 to silence warning */ size_t len =0 , expected_len; +Error *err =NULL ;int res;trace_source_return_path_thread_entry ();rcu_register_thread (); - while (!ms->rp_state.error && !qemu_file_get_error(rp) && + while (!migrate_has_error(ms) && !qemu_file_get_error(rp) &&
migration/migration.c static void *source_return_path_thread(void *opaque) · line 1888
Quoted 10 lines
migration/migration.c +1
-1migration_is_setup_or_active(ms->state)) {trace_source_return_path_thread_loop_top (); + header_type =qemu_get_be16 (rp); header_len =qemu_get_be16 (rp);if (qemu_file_get_error (rp)) { -mark_source_rp_bad (ms); goto out; }
This error will be lost because outside the loop we only check for err.
Quoted 105 lines
migration/migration.c +24
-25if (header_type >=MIG_RP_MSG_MAX || header_type ==MIG_RP_MSG_INVALID ) { -error_report ("RP: Received invalid message 0x%04x length 0x%04x" , - header_type, header_len); -mark_source_rp_bad (ms); +error_setg (&err,"Received invalid message 0x%04x length 0x%04x" , + header_type, header_len); goto out; }if ((rp_cmd_args[header_type].len !=-1 && header_len != rp_cmd_args[header_type].len) || header_len >sizeof (buf)) { -error_report ("RP: Received '%s' message (0x%04x) with" -"incorrect length %d expecting %zu" , - rp_cmd_args[header_type].name, header_type, header_len, - (size_t )rp_cmd_args[header_type].len); -mark_source_rp_bad (ms); +error_setg (&err,"Received '%s' message (0x%04x) with" +"incorrect length %d expecting %zu" , + rp_cmd_args[header_type].name, header_type, header_len, + (size_t )rp_cmd_args[header_type].len); goto out; }/* We know we've got a valid header by this point */ res =qemu_get_buffer (rp, buf, header_len);if (res != header_len) { -error_report ("RP: Failed reading data for message 0x%04x" -" read %d expected %d" , - header_type, res, header_len); -mark_source_rp_bad (ms); +error_setg (&err,"Failed reading data for message 0x%04x" +" read %d expected %d" , + header_type, res, header_len); goto out; }@@ -1933,8 +1919,7 @@ static void *source_return_path_thread(void *opaque) sibling_error =ldl_be_p (buf);trace_source_return_path_thread_shut (sibling_error);if (sibling_error) { -error_report ("RP: Sibling indicated error %d" , sibling_error); -mark_source_rp_bad (ms); +error_setg (&err,"Sibling indicated error %d" , sibling_error); }/* * We'll let the main thread deal with closing the RP @@ -1952,7 +1937,10 @@ static void *source_return_path_thread(void *opaque)case MIG_RP_MSG_REQ_PAGES : start =ldq_be_p (buf); len =ldl_be_p (buf +8 ); -migrate_handle_rp_req_pages (ms,NULL , start, len); +migrate_handle_rp_req_pages (ms,NULL , start, len, &err); +if (err) { + goto out; + }break ;case MIG_RP_MSG_REQ_PAGES_ID :@@ -1967,32 +1955,32 @@ static void *source_return_path_thread(void *opaque) expected_len += tmp32; }if (header_len != expected_len) { -error_report ("RP: Req_Page_id with length %d expecting %zd" , - header_len, expected_len); -mark_source_rp_bad (ms); +error_setg (&err,"Req_Page_id with length %d expecting %zd" , + header_len, expected_len); + goto out; + } +migrate_handle_rp_req_pages (ms, (char *)&buf[13 ], start, len, + &err); +if (err) { goto out; } -migrate_handle_rp_req_pages (ms, (char *)&buf[13 ], start, len);break ;case MIG_RP_MSG_RECV_BITMAP :if (header_len <1 ) { -error_report ("%s: missing block name" , __func__); -mark_source_rp_bad (ms); +error_setg (&err,"MIG_RP_MSG_RECV_BITMAP missing block name" ); goto out; }/* Format: len (1B) + idstr (<255B). This ends the idstr. */ buf[buf[0 ] +1 ] ='\0' ; -if (migrate_handle_rp_recv_bitmap (ms, (char *)(buf +1 ))) { -mark_source_rp_bad (ms); +if (migrate_handle_rp_recv_bitmap (ms, (char *)(buf +1 ), &err)) { goto out; }break ;case MIG_RP_MSG_RESUME_ACK : tmp32 =ldl_be_p (buf); -if (migrate_handle_rp_resume_ack (ms, tmp32)) { -mark_source_rp_bad (ms); +if (migrate_handle_rp_resume_ack (ms, tmp32, &err)) { goto out; }break ;
migration/migration.c static void *source_return_path_thread(void *opaque) · line 1999
Quoted 5 lines
migration/migration.c +1
-1@@ -2008,9 +1996,14 @@ static void *source_return_path_thread(void *opaque) } out: -if (qemu_file_get_error (rp)) { +if (err) {
Need to keep both checks here.
Quoted 14 lines
migration/migration.c +6
-1+/* +* Collect any error in return-path thread and report it to the +* migration state object. +*/ +migrate_set_error (ms, err); +error_free (err);trace_source_return_path_thread_bad_end (); -mark_source_rp_bad (ms); }trace_source_return_path_thread_end ();@@ -2036,13 +2029,10 @@ static int open_return_path_on_source(MigrationState *ms)return 0 ; }
Re: [PATCH v3 03/10] migration: Refactor error handling in source return path
Quoted 8 lines · Fabiano Rosas
migration/migration.c static void *source_return_path_thread(void *opaque) · line 1999
Quoted 6 lines
migration/migration.c +1
-1@@ -2008,9 +1996,14 @@ static void *source_return_path_thread(void *opaque) } out: -if (qemu_file_get_error (rp)) { +if (err) {Need to keep both checks here.
The next patch did that. Let me squash that into this..
Thanks,
Signature · 1 line
Peter Xu
PATCH v3 4/10 migration: Deliver return path file error to migrate state too
In reply to Peter XuWe've already did this for most of the return path thread errors, but not yet for the IO errors happened on the return path qemufile. Do that too.
Re-export qemu_file_get_error_obj().
--- migration/qemu-file.h | 1 + migration/migration.c | 1 + migration/qemu-file.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-)
migration/qemu-file.h +1 -0
@@ -120,6 +120,7 @@ int coroutine_mixed_fn qemu_peek_byte(QEMUFile *f, int offset);void qemu_file_skip (QEMUFile *f,int size);int qemu_file_get_error_obj_any (QEMUFile *f1,QEMUFile *f2,Error **errp);void qemu_file_set_error_obj (QEMUFile *f,int ret,Error *err); +int qemu_file_get_error_obj (QEMUFile *f,Error **errp);void qemu_file_set_error (QEMUFile *f,int ret);int qemu_file_shutdown (QEMUFile *f);QEMUFile *qemu_file_get_return_path (QEMUFile *f);
migration/migration.c +1 -0
@@ -1884,6 +1884,7 @@ static void *source_return_path_thread(void *opaque) header_len =qemu_get_be16 (rp);if (qemu_file_get_error (rp)) { +qemu_file_get_error_obj (rp, &err); goto out; }
migration/qemu-file.c +1 -1
@@ -146,7 +146,7 @@ void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks)* is not 0. * */ -static int qemu_file_get_error_obj (QEMUFile *f,Error **errp) +int qemu_file_get_error_obj (QEMUFile *f,Error **errp) {if (errp) { *errp = f->last_error_obj ?error_copy (f->last_error_obj) :NULL ;
Signature · 1 line
2.41.0
Re: [PATCH v3 04/10] migration: Deliver return path file error to migrate state too
Quoted 6 lines · Peter Xu
We've already did this for most of the return path thread errors, but not yet for the IO errors happened on the return path qemufile. Do that too.
Re-export
qemu_file_get_error_obj().Signed-off-by Peter Xu <[email protected]>
PATCH v3 5/10 qemufile: Always return a verbose error
In reply to Peter XuThere're a lot of cases where we only have an errno set in last_error but without a detailed error description. When this happens, try to generate an error contains the errno as a descriptive error.
This will be helpful in cases where one relies on the Error*. E.g., migration state only caches Error* in MigrationState.error. With this, we'll display correct error messages in e.g. query-migrate when the error was only set by qemu_file_set_error().
--- migration/qemu-file.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
migration/qemu-file.c +12 -3
@@ -142,15 +142,24 @@ void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks)* * Return negative error value if there has been an error on previous * operations, return 0 if no error happened. -* Optional, it returns Error* in errp, but it may be NULL even if return value -* is not 0. * +* If errp is specified, a verbose error message will be copied over. */ int qemu_file_get_error_obj (QEMUFile *f,Error **errp) { +if (!f->last_error) { +return 0 ; + } + +/* There is an error */ if (errp) { - *errp = f->last_error_obj ?error_copy (f->last_error_obj) :NULL ; +if (f->last_error_obj) { + *errp =error_copy (f->last_error_obj); + }else { +error_setg_errno (errp, -f->last_error,"Channel error" ); + } } +return f->last_error; }
Signature · 1 line
2.41.0
Re: [PATCH v3 05/10] qemufile: Always return a verbose error
Quoted 11 lines · Peter Xu
There're a lot of cases where we only have an errno set in
last_errorbut without a detailed error description. When this happens, try to generate an error contains the errno as a descriptive error.This will be helpful in cases where one relies on the Error*. E.g., migration state only caches Error* in MigrationState.error. With this, we'll display correct error messages in e.g. query-migrate when the error was only set by
qemu_file_set_error().Reviewed-by Fabiano Rosas <[email protected]>Signed-off-by Peter Xu <[email protected]>
Have to adjust due to the static missing from previous patch.
PATCH v3 6/10 migration: Remember num of ramblocks to sync during recovery
In reply to Peter XuInstead of only relying on the count of rp_sem, make the counter be part of RAMState so it can be used in both threads to synchronize on the process.
rp_sem will be further reused in follow up patches, as a way to kick the main thread, e.g., on recovery failures.
--- migration/ram.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
migration/ram.c +14 -3
@@ -394,6 +394,14 @@ struct RAMState {/* Queue of outstanding page requests from the destination */ QemuMutex src_page_req_mutex; QSIMPLEQ_HEAD(, RAMSrcPageRequest) src_page_requests; + +/* +* This is only used when postcopy is in recovery phase, to communicate +* between the migration thread and the return path thread on dirty +* bitmap synchronizations. This field is unused in other stages of +* RAM migration. +*/ +unsigned int postcopy_bmap_sync_requested; };typedef struct RAMState RAMState ;
@@ -4121,20 +4129,20 @@ static int ram_dirty_bitmap_sync_all(MigrationState *s, RAMState *rs) {RAMBlock *block;QEMUFile *file = s->to_dst_file; -int ramblock_count =0 ;trace_ram_dirty_bitmap_sync_start (); +qatomic_set (&rs->postcopy_bmap_sync_requested,0 );RAMBLOCK_FOREACH_NOT_IGNORED (block) {qemu_savevm_send_recv_bitmap (file, block->idstr);trace_ram_dirty_bitmap_request (block->idstr); - ramblock_count++; +qatomic_inc (&rs->postcopy_bmap_sync_requested); }trace_ram_dirty_bitmap_sync_wait ();/* Wait until all the ramblocks' dirty bitmap synced */ -while (ramblock_count--) { +while (qatomic_read (&rs->postcopy_bmap_sync_requested)) {qemu_sem_wait (&s->rp_state.rp_sem); }
@@ -4161,6 +4169,7 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp)unsigned long *le_bitmap, nbits = block->used_length >>TARGET_PAGE_BITS ;uint64_t local_size =DIV_ROUND_UP (nbits,8 );uint64_t size, end_mark; +RAMState *rs = ram_state;trace_ram_dirty_bitmap_reload_begin (block->idstr);
@@ -4226,6 +4235,8 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp)/* We'll recalculate migration_dirty_pages in ram_state_resume_prepare(). */ trace_ram_dirty_bitmap_reload_complete (block->idstr); +qatomic_dec (&rs->postcopy_bmap_sync_requested); +/* * We succeeded to sync bitmap for current ramblock. If this is * the last one to sync, we need to notify the main send thread.
Signature · 1 line
2.41.0
Re: [PATCH v3 06/10] migration: Remember num of ramblocks to sync during recovery
Quoted 8 lines · Peter Xu
Instead of only relying on the count of
rp_sem, make the counter be part of RAMState so it can be used in both threads to synchronize on the process.
rp_semwill be further reused in follow up patches, as a way to kick the main thread, e.g., on recovery failures.Reviewed-by Fabiano Rosas <[email protected]>Signed-off-by Peter Xu <[email protected]>
queued.
PATCH v3 7/10 migration: Add migration_rp_wait|kick()
In reply to Peter XuIt's just a simple wrapper for rp_sem on either wait() or kick(), make it even clearer on how it is used. Prepared to be used even for other things.
--- migration/migration.h | 15 +++++++++++++++ migration/migration.c | 14 ++++++++++++-- migration/ram.c | 16 +++++++--------- 3 files changed, 34 insertions(+), 11 deletions(-)
migration/migration.h +15 -0
@@ -315,6 +315,12 @@ struct MigrationState {* be cleared in the rp_thread! */ bool rp_thread_created; +/* +* Used to synchronize between migration main thread and return +* path thread. The migration thread can wait() on this sem, while +* other threads (e.g., return path thread) can kick it using a +* post(). +*/ QemuSemaphore rp_sem;/* * We post to this when we got one PONG from dest. So far it's an
@@ -526,4 +532,13 @@ void migration_populate_vfio_info(MigrationInfo *info);void migration_reset_vfio_bytes_transferred (void );void postcopy_temp_page_reset (PostcopyTmpPage *tmp_page); +/* Migration thread waiting for return path thread. */ +void migration_rp_wait (MigrationState *s); +/* +* Kick the migration thread waiting for return path messages. NOTE: the +* name can be slightly confusing (when read as "kick the rp thread"), just +* to remember the target is always the migration thread. +*/ +void migration_rp_kick (MigrationState *s); +#endif
migration/migration.c +12 -2
@@ -1749,6 +1749,16 @@ void qmp_migrate_continue(MigrationStatus state, Error **errp)qemu_sem_post (&s->pause_sem); } +void migration_rp_wait (MigrationState *s) +{ +qemu_sem_wait (&s->rp_state.rp_sem); +} + +void migration_rp_kick (MigrationState *s) +{ +qemu_sem_post (&s->rp_state.rp_sem); +} + static struct rp_cmd_args { ssize_t len; /* -1 = variable */ const char *name;
@@ -1820,7 +1830,7 @@ static int migrate_handle_rp_resume_ack(MigrationState *s, MIGRATION_STATUS_POSTCOPY_ACTIVE);/* Notify send thread that time to continue send pages */ -qemu_sem_post (&s->rp_state.rp_sem); +migration_rp_kick (s);return 0 ; }
@@ -2447,7 +2457,7 @@ static int postcopy_resume_handshake(MigrationState *s)qemu_savevm_send_postcopy_resume (s->to_dst_file);while (s->state ==MIGRATION_STATUS_POSTCOPY_RECOVER ) { -qemu_sem_wait (&s->rp_state.rp_sem); +migration_rp_wait (s); }if (s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ) {
migration/ram.c +7 -9
@@ -4143,7 +4143,7 @@ static int ram_dirty_bitmap_sync_all(MigrationState *s, RAMState *rs)/* Wait until all the ramblocks' dirty bitmap synced */ while (qatomic_read (&rs->postcopy_bmap_sync_requested)) { -qemu_sem_wait (&s->rp_state.rp_sem); +migration_rp_wait (s); }trace_ram_dirty_bitmap_sync_complete ();
@@ -4151,11 +4151,6 @@ static int ram_dirty_bitmap_sync_all(MigrationState *s, RAMState *rs)return 0 ; } -static void ram_dirty_bitmap_reload_notify (MigrationState *s) -{ -qemu_sem_post (&s->rp_state.rp_sem); -} -/* * Read the received bitmap, revert it as the initial dirty bitmap. * This is only used when the postcopy migration is paused but wants
@@ -4238,10 +4233,13 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp)qatomic_dec (&rs->postcopy_bmap_sync_requested);/* -* We succeeded to sync bitmap for current ramblock. If this is -* the last one to sync, we need to notify the main send thread. +* We succeeded to sync bitmap for current ramblock. Always kick the +* migration thread to check whether all requested bitmaps are +* reloaded. NOTE: it's racy to only kick when requested==0, because +* we don't know whether the migration thread may still be increasing +* it. */ -ram_dirty_bitmap_reload_notify (s); +migration_rp_kick (s); ret =0 ; out:
Signature · 1 line
2.41.0
Re: [PATCH v3 07/10] migration: Add migration_rp_wait|kick()
Quoted 5 lines · Peter Xu
It's just a simple wrapper for
rp_semon eitherwait()orkick(), make it even clearer on how it is used. Prepared to be used even for other things.Reviewed-by Fabiano Rosas <[email protected]>Signed-off-by Peter Xu <[email protected]>
I agree with the idea, but I think that the problem is the name of the semaphore.
migration/migration.c void qmp_migrate_continue(MigrationStatus state, Error **errp) · line 1754
Quoted 3 lines
migration/migration.c +3
-0+void migration_rp_wait (MigrationState *s) +{ +qemu_sem_wait (&s->rp_state.rp_sem);
I am not sure if it would be better to have the wrappers or just rename
If we rename the remaphore to migration_thread, this becomes:
qemu_sem_wait(&s->rp_state.return_path_ready);
qemu_sem_post(&s->rp_state.return_path_ready);Or something similar?
Re: [PATCH v3 07/10] migration: Add migration_rp_wait|kick()
Quoted 18 lines · Juan Quintela
Quoted 5 lines · Peter Xu
It's just a simple wrapper for
rp_semon eitherwait()orkick(), make it even clearer on how it is used. Prepared to be used even for other things.Reviewed-by Fabiano Rosas <[email protected]>Signed-off-by Peter Xu <[email protected]>Reviewed-by Juan Quintela <[email protected]>I agree with the idea, but I think that the problem is the name of the semaphore.
migration/migration.c void qmp_migrate_continue(MigrationStatus state, Error **errp) · line 1754
Quoted 3 lines
migration/migration.c +3
-0+void migration_rp_wait (MigrationState *s) +{ +qemu_sem_wait (&s->rp_state.rp_sem);I am not sure if it would be better to have the wrappers or just rename
Quoted 7 lines
If we rename the remaphore to
migration_thread, this becomes:qemu_sem_wait(&s->rp_state.return_path_ready); qemu_sem_post(&s->rp_state.return_path_ready);Or something similar?
I'd prefer keeping a pair of helpers, but I'm open to other suggestions, e.g. I can rename the sem at the same time, or have a better name just for the helpers.
Thanks,
Signature · 1 line
Peter Xu
PATCH v3 8/10 migration: Allow network to fail even during recovery
In reply to Peter XuNormally the postcopy recover phase should only exist for a super short period, that's the duration when QEMU is trying to recover from an interrupted postcopy migration, during which handshake will be carried out for continuing the procedure with state changes from PAUSED -> RECOVER -> POSTCOPY_ACTIVE again.
Here RECOVER phase should be super small, that happens right after the admin specified a new but working network link for QEMU to reconnect to dest QEMU.
However there can still be case where the channel is broken in this small RECOVER window.
If it happens, with current code there's no way the src QEMU can got kicked out of RECOVER stage. No way either to retry the recover in another channel when established.
This patch allows the RECOVER phase to fail itself too - we're mostly ready, just some small things missing, e.g. properly kick the main migration thread out when sleeping on rp_sem when we found that we're at RECOVER stage. When this happens, it fails the RECOVER itself, and rollback to PAUSED stage. Then the user can retry another round of recovery.
To make it even stronger, teach QMP command migrate-pause to explicitly kick src/dst QEMU out when needed, so even if for some reason the migration thread didn't got kicked out already by a failing rethrn-path thread, the admin can also kick it out.
This will be an super, super corner case, but still try to cover that.
One can try to test this with two proxy channels for migration:
(a) socat unix-listen:/tmp/src.sock,reuseaddr,fork tcp:localhost:10000
(b) socat tcp-listen:10000,reuseaddr,fork unix:/tmp/dst.sock
So the migration channel will be:
(a) (b)
src -> /tmp/src.sock -> tcp:10000 -> /tmp/dst.sock -> dst
Then to make QEMU hang at RECOVER stage, one can do below:
(1) stop the postcopy using QMP command postcopy-pause
(2) kill the 2nd proxy (b)
(3) try to recover the postcopy using /tmp/src.sock on src
(4) src QEMU will go into RECOVER stage but won't be able to continue from there, because the channel is actually broken at (b)
Before this patch, step (4) will make src QEMU stuck in RECOVER stage, without a way to kick the QEMU out or continue the postcopy again. After this patch, (4) will quickly fail qemu and bounce back to PAUSED stage.
Admin can also kick QEMU from (4) into PAUSED when needed using migrate-pause when needed.
After bouncing back to PAUSED stage, one can recover again.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2111332
--- migration/migration.h | 8 ++++-- migration/migration.c | 63 +++++++++++++++++++++++++++++++++++++++---- migration/ram.c | 4 ++- 3 files changed, 67 insertions(+), 8 deletions(-)
migration/migration.h +6 -2
@@ -492,6 +492,7 @@ int migrate_init(MigrationState *s, Error **errp);bool migration_is_blocked (Error **errp);/* True if outgoing migration has entered postcopy phase */ bool migration_in_postcopy (void ); +bool migration_postcopy_is_alive (int state);MigrationState *migrate_get_current (void );uint64_t ram_get_total_transferred_pages (void );
@@ -532,8 +533,11 @@ void migration_populate_vfio_info(MigrationInfo *info);void migration_reset_vfio_bytes_transferred (void );void postcopy_temp_page_reset (PostcopyTmpPage *tmp_page); -/* Migration thread waiting for return path thread. */ -void migration_rp_wait (MigrationState *s); +/* +* Migration thread waiting for return path thread. Return non-zero if an +* error is detected. +*/ +int migration_rp_wait (MigrationState *s);/* * Kick the migration thread waiting for return path messages. NOTE: the * name can be slightly confusing (when read as "kick the rp thread"), just
migration/migration.c +58 -5
111 lines not on this page · raw message
migration/ram.c +3 -1
@@ -4143,7 +4143,9 @@ static int ram_dirty_bitmap_sync_all(MigrationState *s, RAMState *rs)/* Wait until all the ramblocks' dirty bitmap synced */ while (qatomic_read (&rs->postcopy_bmap_sync_requested)) { -migration_rp_wait (s); +if (migration_rp_wait (s)) { +return -1 ; + } }trace_ram_dirty_bitmap_sync_complete ();
Signature · 1 line
2.41.0
Re: [PATCH v3 08/10] migration: Allow network to fail even during recovery
Quoted 53 lines · Peter Xu
Normally the postcopy recover phase should only exist for a super short period, that's the duration when QEMU is trying to recover from an interrupted postcopy migration, during which handshake will be carried out for continuing the procedure with state changes from PAUSED -> RECOVER ->
POSTCOPY_ACTIVEagain.Here RECOVER phase should be super small, that happens right after the admin specified a new but working network link for QEMU to reconnect to dest QEMU.
However there can still be case where the channel is broken in this small RECOVER window.
If it happens, with current code there's no way the src QEMU can got kicked out of RECOVER stage. No way either to retry the recover in another channel when established.
This patch allows the RECOVER phase to fail itself too - we're mostly ready, just some small things missing, e.g. properly kick the main migration thread out when sleeping on
rp_semwhen we found that we're at RECOVER stage. When this happens, it fails the RECOVER itself, and rollback to PAUSED stage. Then the user can retry another round of recovery.To make it even stronger, teach QMP command migrate-pause to explicitly kick src/dst QEMU out when needed, so even if for some reason the migration thread didn't got kicked out already by a failing rethrn-path thread, the admin can also kick it out.
This will be an super, super corner case, but still try to cover that.
One can try to test this with two proxy channels for migration:
(a) socat unix-listen:/tmp/src.sock,reuseaddr,fork tcp:localhost:10000
(b) socat tcp-listen:10000,reuseaddr,fork unix:/tmp/dst.sockSo the migration channel will be:
(a) (b)
src ->/tmp/src.sock-> tcp:10000 ->/tmp/dst.sock-> dstThen to make QEMU hang at RECOVER stage, one can do below:
(1) stop the postcopy using QMP command postcopy-pause
(2) kill the 2nd proxy (b)
(3) try to recover the postcopy using/tmp/src.sockon src
(4) src QEMU will go into RECOVER stage but won't be able to continue from there, because the channel is actually broken at (b)Before this patch, step (4) will make src QEMU stuck in RECOVER stage, without a way to kick the QEMU out or continue the postcopy again. After this patch, (4) will quickly fail qemu and bounce back to PAUSED stage.
Quoted 8 lines
Admin can also kick QEMU from (4) into PAUSED when needed using migrate-pause when needed.
After bouncing back to PAUSED stage, one can recover again.
Reported-by Xiaohui Li <[email protected]>Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2111332
Signed-off-by Peter Xu <[email protected]>
PATCH v3 9/10 migration: Allow RECOVER->PAUSED convertion for dest qemu
In reply to Peter XuThere's a bug on dest that if a double fault triggered on dest qemu (a network issue during postcopy-recover), we won't set PAUSED correctly because we assumed we always came from ACTIVE.
Fix that by always overwriting the state to PAUSE.
We could also check for these two states, but maybe it's an overkill. We did the same on the src QEMU to unconditionally switch to PAUSE anyway.
--- migration/savevm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
migration/savevm.c +2 -1
@@ -2734,7 +2734,8 @@ static bool postcopy_pause_incoming(MigrationIncomingState *mis)qemu_mutex_unlock (&mis->postcopy_prio_thread_mutex); } -migrate_set_state (&mis->state,MIGRATION_STATUS_POSTCOPY_ACTIVE , +/* Current state can be either ACTIVE or RECOVER */ +migrate_set_state (&mis->state, mis->state,MIGRATION_STATUS_POSTCOPY_PAUSED );/* Notify the fault thread for the invalidated file handle */
Signature · 1 line
2.41.0
Re: [PATCH v3 09/10] migration: Allow RECOVER->PAUSED convertion for dest qemu
Quoted 11 lines · Peter Xu
There's a bug on dest that if a double fault triggered on dest qemu (a network issue during postcopy-recover), we won't set PAUSED correctly because we assumed we always came from ACTIVE.
Fix that by always overwriting the state to PAUSE.
We could also check for these two states, but maybe it's an overkill. We did the same on the src QEMU to unconditionally switch to PAUSE anyway.
Reviewed-by Fabiano Rosas <[email protected]>Signed-off-by Peter Xu <[email protected]>
queued
PATCH v3 10/10 tests/migration-test: Add a test for postcopy hangs during RECOVER
In reply to Peter XuFrom: Fabiano Rosas <[email protected]>
To do so, create two paired sockets, but make them not providing real data. Feed those fake sockets to src/dst QEMUs for recovery to let them go into RECOVER stage without going out. Test that we can always kick it out and recover again with the right ports.
This patch is based on Fabiano's version here:
https://lore.kernel.org/r/[email protected]
--- tests/qtest/migration-test.c | 94 ++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+)
tests/qtest/migration-test.c +94 -0
@@ -729,6 +729,7 @@ typedef struct {/* Postcopy specific fields */ void *postcopy_data;bool postcopy_preempt; +bool postcopy_recovery_test_fail; } MigrateCommon; static int test_migrate_start(QTestState **from, QTestState **to,
@@ -1381,6 +1382,78 @@ static void test_postcopy_preempt_tls_psk(void) }#endif +static void wait_for_postcopy_status (QTestState *one,const char *status) +{ +wait_for_migration_status (one, status, + (const char * []) {"failed" ,"active" , +"completed" ,NULL }); +} + +static void postcopy_recover_fail (QTestState *from,QTestState *to) +{ +int ret, pair1[2 ], pair2[2 ]; +char c; + +/* Create two unrelated socketpairs */ + ret =qemu_socketpair (PF_LOCAL ,SOCK_STREAM ,0 , pair1); + g_assert_cmpint(ret, ==, 0); + + ret =qemu_socketpair (PF_LOCAL ,SOCK_STREAM ,0 , pair2); + g_assert_cmpint(ret, ==, 0); + +/* +* Give the guests unpaired ends of the sockets, so they'll all blocked +* at reading. This mimics a wrong channel established. +*/ +qtest_qmp_fds_assert_success (from, &pair1[0 ],1 , +"{ 'execute': 'getfd'," +" 'arguments': { 'fdname': 'fd-mig' }}" ); +qtest_qmp_fds_assert_success (to, &pair2[0 ],1 , +"{ 'execute': 'getfd'," +" 'arguments': { 'fdname': 'fd-mig' }}" ); + +/* +* Write the 1st byte as QEMU_VM_COMMAND (0x8) for the dest socket, to +* emulate the 1st byte of a real recovery, but stops from there to +* keep dest QEMU in RECOVER. This is needed so that we can kick off +* the recover process on dest QEMU (by triggering the G_IO_IN event). +* +* NOTE: this trick is not needed on src QEMUs, because src doesn't +* rely on an pre-existing G_IO_IN event, so it will always trigger the +* upcoming recovery anyway even if it can read nothing. +*/ +#define QEMU_VM_COMMAND 0x08 + c =QEMU_VM_COMMAND ; + ret =send (pair2[1 ], &c,1 ,0 ); + g_assert_cmpint(ret, ==, 1); + +migrate_recover (to,"fd:fd-mig" ); +migrate_qmp (from,"fd:fd-mig" ,"{'resume': true}" ); + +/* +* Make sure both QEMU instances will go into RECOVER stage, then test +* kicking them out using migrate-pause. +*/ +wait_for_postcopy_status (from,"postcopy-recover" ); +wait_for_postcopy_status (to,"postcopy-recover" ); + +/* +* This would be issued by the admin upon noticing the hang, we should +* make sure we're able to kick this out. +*/ +migrate_pause (from); +wait_for_postcopy_status (from,"postcopy-paused" ); + +/* Do the same test on dest */ +migrate_pause (to); +wait_for_postcopy_status (to,"postcopy-paused" ); + +close (pair1[0 ]); +close (pair1[1 ]); +close (pair2[0 ]); +close (pair2[1 ]); +} +static void test_postcopy_recovery_common (MigrateCommon *args) {QTestState *from, *to;
@@ -1420,6 +1493,15 @@ static void test_postcopy_recovery_common(MigrateCommon *args) (const char * []) {"failed" ,"active" , "completed", NULL }); +if (args->postcopy_recovery_test_fail) { +/* +* Test when a wrong socket specified for recover, and then the +* ability to kick it out, and continue with a correct socket. +*/ +postcopy_recover_fail (from, to); +/* continue with a good recovery */ + } +/* * Create a new socket to emulate a new channel that is different * from the broken migration channel; tell the destination to
@@ -1459,6 +1541,15 @@ static void test_postcopy_recovery_compress(void)test_postcopy_recovery_common (&args); } +static void test_postcopy_recovery_double_fail (void ) +{ +MigrateCommon args = { + .postcopy_recovery_test_fail = true, + }; + +test_postcopy_recovery_common (&args); +} +#ifdef CONFIG_GNUTLS static void test_postcopy_recovery_tls_psk (void ) {
@@ -2841,6 +2932,9 @@ int main(int argc, char **argv)qtest_add_func ("/migration/postcopy/recovery/compress/plain" , test_postcopy_recovery_compress); } +qtest_add_func ("/migration/postcopy/recovery/double-failures" , + test_postcopy_recovery_double_fail); + }qtest_add_func ("/migration/bad_dest" , test_baddest);
Signature · 1 line
2.41.0
Re: [PATCH v3 10/10] tests/migration-test: Add a test for postcopy hangs during RECOVER
Quoted 78 lines · Peter Xu
From: Fabiano Rosas <[email protected]>
To do so, create two paired sockets, but make them not providing real data. Feed those fake sockets to src/dst QEMUs for recovery to let them go into RECOVER stage without going out. Test that we can always kick it out and recover again with the right ports.
This patch is based on Fabiano's version here:
https://lore.kernel.org/r/[email protected]
Signed-off-by Fabiano Rosas <[email protected]>[peterx: write commit message, remove case 1, fix bugs, and more]Signed-off-by Peter Xu <[email protected]>--- tests/qtest/migration-test.c | 94 ++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+)tests/qtest/migration-test.c +45
-0@@ -729,6 +729,7 @@ typedef struct {/* Postcopy specific fields */ void *postcopy_data;bool postcopy_preempt; +bool postcopy_recovery_test_fail; } MigrateCommon; static int test_migrate_start(QTestState **from, QTestState **to,@@ -1381,6 +1382,78 @@ static void test_postcopy_preempt_tls_psk(void) }#endif +static void wait_for_postcopy_status (QTestState *one,const char *status) +{ +wait_for_migration_status (one, status, + (const char * []) {"failed" ,"active" , +"completed" ,NULL }); +} + +static void postcopy_recover_fail (QTestState *from,QTestState *to) +{ +int ret, pair1[2 ], pair2[2 ]; +char c; + +/* Create two unrelated socketpairs */ + ret =qemu_socketpair (PF_LOCAL ,SOCK_STREAM ,0 , pair1); + g_assert_cmpint(ret, ==, 0); + + ret =qemu_socketpair (PF_LOCAL ,SOCK_STREAM ,0 , pair2); + g_assert_cmpint(ret, ==, 0); + +/* +* Give the guests unpaired ends of the sockets, so they'll all blocked +* at reading. This mimics a wrong channel established. +*/ +qtest_qmp_fds_assert_success (from, &pair1[0 ],1 , +"{ 'execute': 'getfd'," +" 'arguments': { 'fdname': 'fd-mig' }}" ); +qtest_qmp_fds_assert_success (to, &pair2[0 ],1 , +"{ 'execute': 'getfd'," +" 'arguments': { 'fdname': 'fd-mig' }}" ); + +/* +* Write the 1st byte as QEMU_VM_COMMAND (0x8) for the dest socket, to +* emulate the 1st byte of a real recovery, but stops from there to +* keep dest QEMU in RECOVER. This is needed so that we can kick off +* the recover process on dest QEMU (by triggering the G_IO_IN event). +* +* NOTE: this trick is not needed on src QEMUs, because src doesn't +* rely on an pre-existing G_IO_IN event, so it will always trigger the +* upcoming recovery anyway even if it can read nothing. +*/ +#define QEMU_VM_COMMAND 0x08 + c =QEMU_VM_COMMAND ; + ret =send (pair2[1 ], &c,1 ,0 ); + g_assert_cmpint(ret, ==, 1);
tests/qtest/migration-test.c static void test_postcopy_preempt_tls_psk(void) · line 1438
Quoted 10 lines
tests/qtest/migration-test.c +10
-0+ +migrate_recover (to,"fd:fd-mig" ); +migrate_qmp (from,"fd:fd-mig" ,"{'resume': true}" ); + +/* +* Make sure both QEMU instances will go into RECOVER stage, then test +* kicking them out using migrate-pause. +*/ +wait_for_postcopy_status (from,"postcopy-recover" ); +wait_for_postcopy_status (to,"postcopy-recover" );
Is this wait out of place? I think we're trying to resume too fast after migrate_recover():
# {
# "error": {
# "class": "GenericError",
# "desc": "Cannot resume if there is no paused migration"
# }
# }
Quoted 63 lines
tests/qtest/migration-test.c +39
-0+ +/* +* This would be issued by the admin upon noticing the hang, we should +* make sure we're able to kick this out. +*/ +migrate_pause (from); +wait_for_postcopy_status (from,"postcopy-paused" ); + +/* Do the same test on dest */ +migrate_pause (to); +wait_for_postcopy_status (to,"postcopy-paused" ); + +close (pair1[0 ]); +close (pair1[1 ]); +close (pair2[0 ]); +close (pair2[1 ]); +} +static void test_postcopy_recovery_common (MigrateCommon *args) {QTestState *from, *to;@@ -1420,6 +1493,15 @@ static void test_postcopy_recovery_common(MigrateCommon *args) (const char * []) {"failed" ,"active" , "completed", NULL }); +if (args->postcopy_recovery_test_fail) { +/* +* Test when a wrong socket specified for recover, and then the +* ability to kick it out, and continue with a correct socket. +*/ +postcopy_recover_fail (from, to); +/* continue with a good recovery */ + } +/* * Create a new socket to emulate a new channel that is different * from the broken migration channel; tell the destination to @@ -1459,6 +1541,15 @@ static void test_postcopy_recovery_compress(void)test_postcopy_recovery_common (&args); } +static void test_postcopy_recovery_double_fail (void ) +{ +MigrateCommon args = { + .postcopy_recovery_test_fail = true, + }; + +test_postcopy_recovery_common (&args); +} +#ifdef CONFIG_GNUTLS static void test_postcopy_recovery_tls_psk (void ) {@@ -2841,6 +2932,9 @@ int main(int argc, char **argv)qtest_add_func ("/migration/postcopy/recovery/compress/plain" , test_postcopy_recovery_compress); } +qtest_add_func ("/migration/postcopy/recovery/double-failures" , + test_postcopy_recovery_double_fail); + }qtest_add_func ("/migration/bad_dest" , test_baddest);
Re: [PATCH v3 10/10] tests/migration-test: Add a test for postcopy hangs during RECOVER
Quoted 94 lines · Fabiano Rosas
Quoted 78 lines · Peter Xu
From: Fabiano Rosas <[email protected]>
To do so, create two paired sockets, but make them not providing real data. Feed those fake sockets to src/dst QEMUs for recovery to let them go into RECOVER stage without going out. Test that we can always kick it out and recover again with the right ports.
This patch is based on Fabiano's version here:
https://lore.kernel.org/r/[email protected]
Signed-off-by Fabiano Rosas <[email protected]>[peterx: write commit message, remove case 1, fix bugs, and more]Signed-off-by Peter Xu <[email protected]>--- tests/qtest/migration-test.c | 94 ++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+)tests/qtest/migration-test.c +45
-0@@ -729,6 +729,7 @@ typedef struct {/* Postcopy specific fields */ void *postcopy_data;bool postcopy_preempt; +bool postcopy_recovery_test_fail; } MigrateCommon; static int test_migrate_start(QTestState **from, QTestState **to,@@ -1381,6 +1382,78 @@ static void test_postcopy_preempt_tls_psk(void) }#endif +static void wait_for_postcopy_status (QTestState *one,const char *status) +{ +wait_for_migration_status (one, status, + (const char * []) {"failed" ,"active" , +"completed" ,NULL }); +} + +static void postcopy_recover_fail (QTestState *from,QTestState *to) +{ +int ret, pair1[2 ], pair2[2 ]; +char c; + +/* Create two unrelated socketpairs */ + ret =qemu_socketpair (PF_LOCAL ,SOCK_STREAM ,0 , pair1); + g_assert_cmpint(ret, ==, 0); + + ret =qemu_socketpair (PF_LOCAL ,SOCK_STREAM ,0 , pair2); + g_assert_cmpint(ret, ==, 0); + +/* +* Give the guests unpaired ends of the sockets, so they'll all blocked +* at reading. This mimics a wrong channel established. +*/ +qtest_qmp_fds_assert_success (from, &pair1[0 ],1 , +"{ 'execute': 'getfd'," +" 'arguments': { 'fdname': 'fd-mig' }}" ); +qtest_qmp_fds_assert_success (to, &pair2[0 ],1 , +"{ 'execute': 'getfd'," +" 'arguments': { 'fdname': 'fd-mig' }}" ); + +/* +* Write the 1st byte as QEMU_VM_COMMAND (0x8) for the dest socket, to +* emulate the 1st byte of a real recovery, but stops from there to +* keep dest QEMU in RECOVER. This is needed so that we can kick off +* the recover process on dest QEMU (by triggering the G_IO_IN event). +* +* NOTE: this trick is not needed on src QEMUs, because src doesn't +* rely on an pre-existing G_IO_IN event, so it will always trigger the +* upcoming recovery anyway even if it can read nothing. +*/ +#define QEMU_VM_COMMAND 0x08 + c =QEMU_VM_COMMAND ; + ret =send (pair2[1 ], &c,1 ,0 ); + g_assert_cmpint(ret, ==, 1);tests/qtest/migration-test.c static void test_postcopy_preempt_tls_psk(void) · line 1438
Quoted 10 lines
tests/qtest/migration-test.c +10
-0+ +migrate_recover (to,"fd:fd-mig" ); +migrate_qmp (from,"fd:fd-mig" ,"{'resume': true}" ); + +/* +* Make sure both QEMU instances will go into RECOVER stage, then test +* kicking them out using migrate-pause. +*/ +wait_for_postcopy_status (from,"postcopy-recover" ); +wait_for_postcopy_status (to,"postcopy-recover" );Is this wait out of place? I think we're trying to resume too fast after
migrate_recover():
Quoted 7 lines
# {
# "error": {
# "class": "GenericError",
# "desc": "Cannot resume if there is no paused migration"
# }
# }
Ugh, sorry about the long lines:
{
"error": {
"class": "GenericError",
"desc": "Cannot resume if there is no paused migration"
}
}Re: [PATCH v3 10/10] tests/migration-test: Add a test for postcopy hangs during RECOVER
Quoted 18 lines · Fabiano Rosas
Quoted 10 lines
tests/qtest/migration-test.c static void test_postcopy_preempt_tls_psk(void) · line 1438
Quoted 6 lines
tests/qtest/migration-test.c +6
-0+/* +* Make sure both QEMU instances will go into RECOVER stage, then test +* kicking them out using migrate-pause. +*/ +wait_for_postcopy_status (from,"postcopy-recover" ); +wait_for_postcopy_status (to,"postcopy-recover" );Is this wait out of place? I think we're trying to resume too fast after
migrate_recover():Quoted 7 lines
# {
# "error": {
# "class": "GenericError",
# "desc": "Cannot resume if there is no paused migration"
# }
# }
Quoted 8 lines
Ugh, sorry about the long lines:
{ "error": { "class": "GenericError", "desc": "Cannot resume if there is no paused migration" } }
Sorry I didn't get you here. Could you elaborate your question?
Here we wait on both sides and make sure they'll all be in RECOVER stage, and we should know that they won't proceed further because the pipes contain mostly nothing so they'll just block at the pipes. What did I miss?
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH v3 10/10] tests/migration-test: Add a test for postcopy hangs during RECOVER
Quoted 21 lines · Peter Xu
Quoted 20 lines · Fabiano Rosas
Quoted 10 lines
tests/qtest/migration-test.c static void test_postcopy_preempt_tls_psk(void) · line 1438
Quoted 6 lines
tests/qtest/migration-test.c +6
-0+/* +* Make sure both QEMU instances will go into RECOVER stage, then test +* kicking them out using migrate-pause. +*/ +wait_for_postcopy_status (from,"postcopy-recover" ); +wait_for_postcopy_status (to,"postcopy-recover" );Is this wait out of place? I think we're trying to resume too fast after
migrate_recover():Quoted 7 lines
# {
# "error": {
# "class": "GenericError",
# "desc": "Cannot resume if there is no paused migration"
# }
# }Ugh, sorry about the long lines:
Quoted 9 lines
Quoted 6 lines
{ "error": { "class": "GenericError", "desc": "Cannot resume if there is no paused migration" } }Sorry I didn't get you here. Could you elaborate your question?
The test is sometimes failing with the above message.
But indeed my question doesn't make sense. I forgot migrate_recover happens on the destination. Nevermind.
The bug is still present nonetheless. We're going into migrate_prepare in some state other than POSTCOPY_PAUSED.
Re: [PATCH v3 10/10] tests/migration-test: Add a test for postcopy hangs during RECOVER
Quoted 33 lines · Fabiano Rosas
Quoted 21 lines · Peter Xu
Quoted 20 lines · Fabiano Rosas
Quoted 10 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ /* + * Make sure both QEMU instances will go into RECOVER stage, then test + * kicking them out using migrate-pause. + */ + wait_for_postcopy_status(from, "postcopy-recover"); + wait_for_postcopy_status(to, "postcopy-recover");Is this wait out of place? I think we're trying to resume too fast after
migrate_recover():Quoted 7 lines
# {
# "error": {
# "class": "GenericError",
# "desc": "Cannot resume if there is no paused migration"
# }
# }Ugh, sorry about the long lines:
Quoted 9 lines
Quoted 6 lines
{ "error": { "class": "GenericError", "desc": "Cannot resume if there is no paused migration" } }Sorry I didn't get you here. Could you elaborate your question?
Quoted 7 lines
The test is sometimes failing with the above message.
But indeed my question doesn't make sense. I forgot
migrate_recoverhappens on the destination. Nevermind.The bug is still present nonetheless. We're going into
migrate_preparein some state other thanPOSTCOPY_PAUSED.
Oh I see. Interestingly I cannot reproduce on my host, just like last time..
What is your setup for running the test? Anything special? Here's my cmdline:
$ cat reproduce.sh index=$1 loop=0
while :; do
echo "Starting loop=$loop..."
QTEST_QEMU_BINARY=./qemu-system-x86_64 ./tests/qtest/migration-test -p /x86_64/migration/postcopy/recovery/double-failures if [[ $? != 0 ]]; then
echo "index $index REPRODUCED (loop=$loop) !"
break
fi
loop=$(( loop + 1 ))
done
Survives 200+ loops and kept going.
However I think I saw what's wrong here, could you help try below fixup?
Thanks,
===8<===
From 52bd2cd5ddf472e0bb99789dba3660a626382630 Mon Sep 17 00:00:00 2001
From: Peter Xu <[email protected]>
Date: Thu, 5 Oct 2023 17:38:42 -0400
Subject: [PATCH] fixup! tests/migration-test: Add a test for postcopy hangs
during RECOVER
--- tests/qtest/migration-test.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
tests/qtest/migration-test.c +2 -6
@@ -1489,9 +1489,8 @@ static void test_postcopy_recovery_common(MigrateCommon *args)* migrate-recover command can only succeed if destination machine * is in the paused state */ -wait_for_migration_status (to,"postcopy-paused" , - (const char * []) {"failed" ,"active" , -"completed" ,NULL }); +wait_for_postcopy_status (to,"postcopy-paused" ); +wait_for_postcopy_status (from,"postcopy-paused" );if (args->postcopy_recovery_test_fail) {/*
@@ -1514,9 +1513,6 @@ static void test_postcopy_recovery_common(MigrateCommon *args)* Try to rebuild the migration channel using the resume flag and * the newly created channel */ -wait_for_migration_status (from,"postcopy-paused" , - (const char * []) {"failed" ,"active" , -"completed" ,NULL });migrate_qmp (from, uri,"{'resume': true}" );/* Restore the postcopy bandwidth to unlimited */
Signature · 4 lines
2.41.0 -- Peter Xu
Re: [PATCH v3 10/10] tests/migration-test: Add a test for postcopy hangs during RECOVER
Quoted 39 lines · Peter Xu
Quoted 38 lines · Fabiano Rosas
Quoted 21 lines · Peter Xu
Quoted 20 lines · Fabiano Rosas
Quoted 10 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ /* + * Make sure both QEMU instances will go into RECOVER stage, then test + * kicking them out using migrate-pause. + */ + wait_for_postcopy_status(from, "postcopy-recover"); + wait_for_postcopy_status(to, "postcopy-recover");Is this wait out of place? I think we're trying to resume too fast after
migrate_recover():Quoted 7 lines
# {
# "error": {
# "class": "GenericError",
# "desc": "Cannot resume if there is no paused migration"
# }
# }Ugh, sorry about the long lines:
Quoted 9 lines
Quoted 6 lines
{ "error": { "class": "GenericError", "desc": "Cannot resume if there is no paused migration" } }Sorry I didn't get you here. Could you elaborate your question?
The test is sometimes failing with the above message.
But indeed my question doesn't make sense. I forgot
migrate_recoverhappens on the destination. Nevermind.
Quoted 8 lines
Quoted 2 lines
The bug is still present nonetheless. We're going into
migrate_preparein some state other thanPOSTCOPY_PAUSED.Oh I see. Interestingly I cannot reproduce on my host, just like last time..
What is your setup for running the test? Anything special? Here's my cmdline:
The crudest oneliner:
for i in $(seq 1 9999); do echo "$i ============="; \
QTEST_QEMU_BINARY=./qemu-system-x86_64 \
./tests/qtest/migration-test -r /x86_64/migration/postcopy/recovery || break ; done
I suspect my system has something specific to it that affects the timing of the tests. But I have no idea what it could be.
$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 39 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: GenuineIntel
Model name: 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz
CPU family: 6
Model: 141
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
Stepping: 1
CPU max MHz: 4800.0000
CPU min MHz: 800.0000
BogoMIPS: 4992.00Quoted 15 lines
$ cat reproduce.sh index=$1 loop=0while :; do
echo "Starting loop=$loop..."
QTEST_QEMU_BINARY=./qemu-system-x86_64 ./tests/qtest/migration-test -p /x86_64/migration/postcopy/recovery/double-failures if [[ $? != 0 ]]; then
echo "index $index REPRODUCED (loop=$loop) !"
break
fi
loop=$(( loop + 1 ))
done
Quoted 4 lines
Survives 200+ loops and kept going.
However I think I saw what's wrong here, could you help try below fixup?
Sure. I won't get to it until tomorrow though.
Re: [PATCH v3 10/10] tests/migration-test: Add a test for postcopy hangs during RECOVER
Quoted 93 lines · Fabiano Rosas
Quoted 39 lines · Peter Xu
Quoted 38 lines · Fabiano Rosas
Quoted 21 lines · Peter Xu
Quoted 20 lines · Fabiano Rosas
Quoted 10 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ /* + * Make sure both QEMU instances will go into RECOVER stage, then test + * kicking them out using migrate-pause. + */ + wait_for_postcopy_status(from, "postcopy-recover"); + wait_for_postcopy_status(to, "postcopy-recover");Is this wait out of place? I think we're trying to resume too fast after
migrate_recover():Quoted 7 lines
# {
# "error": {
# "class": "GenericError",
# "desc": "Cannot resume if there is no paused migration"
# }
# }Ugh, sorry about the long lines:
Quoted 9 lines
Quoted 6 lines
{ "error": { "class": "GenericError", "desc": "Cannot resume if there is no paused migration" } }Sorry I didn't get you here. Could you elaborate your question?
The test is sometimes failing with the above message.
But indeed my question doesn't make sense. I forgot
migrate_recoverhappens on the destination. Nevermind.Quoted 8 lines
Quoted 2 lines
The bug is still present nonetheless. We're going into
migrate_preparein some state other thanPOSTCOPY_PAUSED.Oh I see. Interestingly I cannot reproduce on my host, just like last time..
What is your setup for running the test? Anything special? Here's my cmdline:
The crudest oneliner:
for i in $(seq 1 9999); do echo "$i ============="; \
QTEST_QEMU_BINARY=./qemu-system-x86_64 \
./tests/qtest/migration-test -r /x86_64/migration/postcopy/recovery || break ; doneI suspect my system has something specific to it that affects the timing of the tests. But I have no idea what it could be.
$ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 16 On-line CPU(s) list: 0-15 Vendor ID: GenuineIntel Model name: 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz CPU family: 6 Model: 141 Thread(s) per core: 2 Core(s) per socket: 8 Socket(s): 1 Stepping: 1 CPU max MHz: 4800.0000 CPU min MHz: 800.0000 BogoMIPS: 4992.00Quoted 15 lines
$ cat reproduce.sh index=$1 loop=0while :; do
echo "Starting loop=$loop..."
QTEST_QEMU_BINARY=./qemu-system-x86_64 ./tests/qtest/migration-test -p /x86_64/migration/postcopy/recovery/double-failures if [[ $? != 0 ]]; then
echo "index $index REPRODUCED (loop=$loop) !"
break
fi
loop=$(( loop + 1 ))
done
Quoted 6 lines
Quoted 4 lines
Survives 200+ loops and kept going.
However I think I saw what's wrong here, could you help try below fixup?
Sure. I won't get to it until tomorrow though.
It seems to have fixed the issue. 3500 iterations and still going.
Re: [PATCH v3 10/10] tests/migration-test: Add a test for postcopy hangs during RECOVER
Quoted 1 line · Fabiano Rosas
It seems to have fixed the issue. 3500 iterations and still going.
I'll go with that then, but feel free to report whenever that's hit again.
Thanks a lot.
Signature · 1 line
Peter Xu