[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v9 12/56] ram_load: Factor out host_from_stream_offs
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v9 12/56] ram_load: Factor out host_from_stream_offset call and check |
Date: |
Thu, 5 Nov 2015 18:10:39 +0000 |
From: "Dr. David Alan Gilbert" <address@hidden>
The main RAM load loop has a call to host_from_stream_offset for
each page type that actually loads data with the same test;
factor it out before the switch.
The host = NULL is to silence a bogus gcc warning of
an unitialised in the RAM_SAVE_COMPRESS_PAGE case, it
doesn't seem to realise that host is always initialised by the if at
the top in the cases the switch takes.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
migration/ram.c | 41 +++++++++++++++--------------------------
1 file changed, 15 insertions(+), 26 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index 86bf657..298332c 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1592,13 +1592,23 @@ static int ram_load(QEMUFile *f, void *opaque, int
version_id)
rcu_read_lock();
while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) {
ram_addr_t addr, total_ram_bytes;
- void *host;
+ void *host = NULL;
uint8_t ch;
addr = qemu_get_be64(f);
flags = addr & ~TARGET_PAGE_MASK;
addr &= TARGET_PAGE_MASK;
+ if (flags & (RAM_SAVE_FLAG_COMPRESS | RAM_SAVE_FLAG_PAGE |
+ RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) {
+ host = host_from_stream_offset(f, addr, flags);
+ if (!host) {
+ error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
+ ret = -EINVAL;
+ break;
+ }
+ }
+
switch (flags & ~RAM_SAVE_FLAG_CONTINUE) {
case RAM_SAVE_FLAG_MEM_SIZE:
/* Synchronize RAM block list */
@@ -1635,33 +1645,17 @@ static int ram_load(QEMUFile *f, void *opaque, int
version_id)
total_ram_bytes -= length;
}
break;
+
case RAM_SAVE_FLAG_COMPRESS:
- host = host_from_stream_offset(f, addr, flags);
- if (!host) {
- error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
- ret = -EINVAL;
- break;
- }
ch = qemu_get_byte(f);
ram_handle_compressed(host, ch, TARGET_PAGE_SIZE);
break;
+
case RAM_SAVE_FLAG_PAGE:
- host = host_from_stream_offset(f, addr, flags);
- if (!host) {
- error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
- ret = -EINVAL;
- break;
- }
qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
break;
- case RAM_SAVE_FLAG_COMPRESS_PAGE:
- host = host_from_stream_offset(f, addr, flags);
- if (!host) {
- error_report("Invalid RAM offset " RAM_ADDR_FMT, addr);
- ret = -EINVAL;
- break;
- }
+ case RAM_SAVE_FLAG_COMPRESS_PAGE:
len = qemu_get_be32(f);
if (len < 0 || len > compressBound(TARGET_PAGE_SIZE)) {
error_report("Invalid compressed data length: %d", len);
@@ -1671,13 +1665,8 @@ static int ram_load(QEMUFile *f, void *opaque, int
version_id)
qemu_get_buffer(f, compressed_data_buf, len);
decompress_data_with_multi_threads(compressed_data_buf, host, len);
break;
+
case RAM_SAVE_FLAG_XBZRLE:
- host = host_from_stream_offset(f, addr, flags);
- if (!host) {
- error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
- ret = -EINVAL;
- break;
- }
if (load_xbzrle(f, addr, host) < 0) {
error_report("Failed to decompress XBZRLE page at "
RAM_ADDR_FMT, addr);
--
2.5.0
- Re: [Qemu-devel] [PATCH v9 04/56] Move page_size_init earlier, (continued)
- [Qemu-devel] [PATCH v9 05/56] qemu_ram_block_from_host, Dr. David Alan Gilbert (git), 2015/11/05
- [Qemu-devel] [PATCH v9 06/56] qemu_ram_block_by_name, Dr. David Alan Gilbert (git), 2015/11/05
- [Qemu-devel] [PATCH v9 08/56] Add qemu_get_buffer_in_place to avoid copies some of the time, Dr. David Alan Gilbert (git), 2015/11/05
- [Qemu-devel] [PATCH v9 07/56] Rename mis->file to from_src_file, Dr. David Alan Gilbert (git), 2015/11/05
- [Qemu-devel] [PATCH v9 09/56] Add wrapper for setting blocking status on a QEMUFile, Dr. David Alan Gilbert (git), 2015/11/05
- [Qemu-devel] [PATCH v9 10/56] Add QEMU_MADV_NOHUGEPAGE, Dr. David Alan Gilbert (git), 2015/11/05
- [Qemu-devel] [PATCH v9 11/56] ram_debug_dump_bitmap: Dump a migration bitmap as text, Dr. David Alan Gilbert (git), 2015/11/05
- [Qemu-devel] [PATCH v9 12/56] ram_load: Factor out host_from_stream_offset call and check,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH v9 13/56] migrate_init: Call from savevm, Dr. David Alan Gilbert (git), 2015/11/05
- [Qemu-devel] [PATCH v9 16/56] Return path: Open a return path on QEMUFile for sockets, Dr. David Alan Gilbert (git), 2015/11/05
- [Qemu-devel] [PATCH v9 15/56] Add Linux userfaultfd.h header, Dr. David Alan Gilbert (git), 2015/11/05
- [Qemu-devel] [PATCH v9 14/56] Rename save_live_complete to save_live_complete_precopy, Dr. David Alan Gilbert (git), 2015/11/05
- [Qemu-devel] [PATCH v9 17/56] Return path: socket_writev_buffer: Block even on non-blocking fd's, Dr. David Alan Gilbert (git), 2015/11/05
- [Qemu-devel] [PATCH v9 18/56] Migration commands, Dr. David Alan Gilbert (git), 2015/11/05
- [Qemu-devel] [PATCH v9 19/56] Return path: Control commands, Dr. David Alan Gilbert (git), 2015/11/05
- [Qemu-devel] [PATCH v9 20/56] Return path: Send responses from destination to source, Dr. David Alan Gilbert (git), 2015/11/05