diff options
author | Peter Xu | 2018-02-08 11:31:05 +0100 |
---|---|---|
committer | Dr. David Alan Gilbert | 2018-02-14 11:34:56 +0100 |
commit | 7a9ddfbfae4aaf8a7e4dafb57ac9fecad807a6b7 (patch) | |
tree | 1a678f726395f20f2bda3e9018efa1e15a4b365a /migration/ram.c | |
parent | tests/migration: Add test for migration to bad destination (diff) | |
download | qemu-7a9ddfbfae4aaf8a7e4dafb57ac9fecad807a6b7.tar.gz qemu-7a9ddfbfae4aaf8a7e4dafb57ac9fecad807a6b7.tar.xz qemu-7a9ddfbfae4aaf8a7e4dafb57ac9fecad807a6b7.zip |
migration: better error handling with QEMUFile
If the postcopy down due to some reason, we can always see this on dst:
qemu-system-x86_64: RP: Received invalid message 0x0000 length 0x0000
However in most cases that's not the real issue. The problem is that
qemu_get_be16() has no way to show whether the returned data is valid or
not, and we are _always_ assuming it is valid. That's possibly not wise.
The best approach to solve this would be: refactoring QEMUFile interface
to allow the APIs to return error if there is. However it needs quite a
bit of work and testing. For now, let's explicitly check the validity
first before using the data in all places for qemu_get_*().
This patch tries to fix most of the cases I can see. Only if we are with
this, can we make sure we are processing the valid data, and also can we
make sure we can capture the channel down events correctly.
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20180208103132.28452-2-peterx@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Diffstat (limited to 'migration/ram.c')
-rw-r--r-- | migration/ram.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/migration/ram.c b/migration/ram.c index 7095c1040e..5e33e5cc79 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2700,6 +2700,16 @@ static int ram_load_postcopy(QEMUFile *f) uint8_t ch; addr = qemu_get_be64(f); + + /* + * If qemu file error, we should stop here, and then "addr" + * may be invalid + */ + ret = qemu_file_get_error(f); + if (ret) { + break; + } + flags = addr & ~TARGET_PAGE_MASK; addr &= TARGET_PAGE_MASK; @@ -2780,9 +2790,15 @@ static int ram_load_postcopy(QEMUFile *f) error_report("Unknown combination of migration flags: %#x" " (postcopy mode)", flags); ret = -EINVAL; + break; + } + + /* Detect for any possible file errors */ + if (!ret && qemu_file_get_error(f)) { + ret = qemu_file_get_error(f); } - if (place_needed) { + if (!ret && place_needed) { /* This gets called at the last target page in the host page */ void *place_dest = host + TARGET_PAGE_SIZE - block->page_size; @@ -2794,9 +2810,6 @@ static int ram_load_postcopy(QEMUFile *f) place_source, block); } } - if (!ret) { - ret = qemu_file_get_error(f); - } } return ret; |