[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 08/41] arch_init/ram_load: refactor ram_load
From: |
Isaku Yamahata |
Subject: |
[Qemu-devel] [PATCH v2 08/41] arch_init/ram_load: refactor ram_load |
Date: |
Mon, 4 Jun 2012 18:57:10 +0900 |
Signed-off-by: Isaku Yamahata <address@hidden>
---
arch_init.c | 67 +++++++++++++++++++++++++++++++++-------------------------
arch_init.h | 1 +
2 files changed, 39 insertions(+), 29 deletions(-)
diff --git a/arch_init.c b/arch_init.c
index c861e30..bb0cd52 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -438,6 +438,41 @@ static inline void *host_from_stream_offset(QEMUFile *f,
return ram_load_host_from_stream_offset(f, offset, flags, &block);
}
+int ram_load_mem_size(QEMUFile *f, ram_addr_t total_ram_bytes)
+{
+ /* Synchronize RAM block list */
+ char id[256];
+ ram_addr_t length;
+
+ while (total_ram_bytes) {
+ RAMBlock *block;
+ uint8_t len;
+
+ len = qemu_get_byte(f);
+ qemu_get_buffer(f, (uint8_t *)id, len);
+ id[len] = 0;
+ length = qemu_get_be64(f);
+
+ QLIST_FOREACH(block, &ram_list.blocks, next) {
+ if (!strncmp(id, block->idstr, sizeof(id))) {
+ if (block->length != length)
+ return -EINVAL;
+ break;
+ }
+ }
+
+ if (!block) {
+ fprintf(stderr, "Unknown ramblock \"%s\", cannot "
+ "accept migration\n", id);
+ return -EINVAL;
+ }
+
+ total_ram_bytes -= length;
+ }
+
+ return 0;
+}
+
int ram_load(QEMUFile *f, void *opaque, int version_id)
{
ram_addr_t addr;
@@ -456,35 +491,9 @@ int ram_load(QEMUFile *f, void *opaque, int version_id)
if (flags & RAM_SAVE_FLAG_MEM_SIZE) {
if (version_id == 4) {
- /* Synchronize RAM block list */
- char id[256];
- ram_addr_t length;
- ram_addr_t total_ram_bytes = addr;
-
- while (total_ram_bytes) {
- RAMBlock *block;
- uint8_t len;
-
- len = qemu_get_byte(f);
- qemu_get_buffer(f, (uint8_t *)id, len);
- id[len] = 0;
- length = qemu_get_be64(f);
-
- QLIST_FOREACH(block, &ram_list.blocks, next) {
- if (!strncmp(id, block->idstr, sizeof(id))) {
- if (block->length != length)
- return -EINVAL;
- break;
- }
- }
-
- if (!block) {
- fprintf(stderr, "Unknown ramblock \"%s\", cannot "
- "accept migration\n", id);
- return -EINVAL;
- }
-
- total_ram_bytes -= length;
+ error = ram_load_mem_size(f, addr);
+ if (error) {
+ return error;
}
}
}
diff --git a/arch_init.h b/arch_init.h
index 0a39082..507f110 100644
--- a/arch_init.h
+++ b/arch_init.h
@@ -45,6 +45,7 @@ void *ram_load_host_from_stream_offset(QEMUFile *f,
ram_addr_t offset,
int flags,
RAMBlock **last_blockp);
+int ram_load_mem_size(QEMUFile *f, ram_addr_t total_ram_bytes);
#endif
#endif
--
1.7.1.1
- [Qemu-devel] [PATCH v2 32/41] savevm: add new section that is used by postcopy, (continued)
- [Qemu-devel] [PATCH v2 32/41] savevm: add new section that is used by postcopy, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 15/41] savevm: export qemu_peek_buffer, qemu_peek_byte, qemu_file_skip, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 25/41] migration: factor out parameters into MigrationParams, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 30/41] update-linux-headers.sh: teach umem.h to update-linux-headers.sh, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 38/41] postcopy/outgoing: add forward, backward option to specify the size of prefault, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 10/41] arch_init: simplify a bit by ram_find_block(), Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 34/41] postcopy outgoing: add -p and -n option to migrate command, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 39/41] postcopy/outgoing: implement prefault, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 26/41] buffered_file: factor out buffer management logic, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 14/41] exec.c: export last_ram_offset(), Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 08/41] arch_init/ram_load: refactor ram_load,
Isaku Yamahata <=
- [Qemu-devel] [PATCH v2 28/41] buffered_file: add qemu_file to read/write to buffer in memory, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 33/41] postcopy: introduce -postcopy and -postcopy-flags option, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 12/41] arch_init: factor out setting last_block, last_offset, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 36/41] postcopy: implement incoming part of postcopy live migration, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 41/41] migration/postcopy: add movebg mode, Isaku Yamahata, 2012/06/04
- [Qemu-devel] [PATCH v2 40/41] migrate: add -m (movebg) option to migrate command, Isaku Yamahata, 2012/06/04