@@ -762,6 +762,19 @@ static int load_xbzrle(QEMUFile *f, void *host)
return rc;
}
+RAMBlock *ram_find_block(const char *id, uint8_t len)
+{
+ RAMBlock *block;
+
+ QLIST_FOREACH(block, &ram_list.blocks, next) {
+ if (!strncmp(id, block->idstr, len)) {
+ return block;
+ }
+ }
+
+ return NULL;
+}
+
static inline void *host_from_stream_offset(QEMUFile *f,
ram_addr_t offset,
int flags)
@@ -783,9 +796,9 @@ static inline void *host_from_stream_offset(QEMUFile *f,
qemu_get_buffer(f, (uint8_t *)id, len);
id[len] = 0;
- QLIST_FOREACH(block, &ram_list.blocks, next) {
- if (!strncmp(id, block->idstr, sizeof(id)))
- return memory_region_get_ram_ptr(block->mr) + offset;
+ block = ram_find_block(id, len);
+ if (block) {
+ return memory_region_get_ram_ptr(block->mr) + offset;
}
fprintf(stderr, "Can't find block %s!\n", id);
@@ -807,19 +820,15 @@ int ram_load_mem_size(QEMUFile *f, ram_addr_t total_ram_bytes)
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;
- }
- }
-
+ block = ram_find_block(id, len);
if (!block) {
fprintf(stderr, "Unknown ramblock \"%s\", cannot "
"accept migration\n", id);
return -EINVAL;
}
+ if (block->length != length) {
+ return -EINVAL;
+ }
total_ram_bytes -= length;
}
@@ -51,6 +51,7 @@ int ram_load_page(QEMUFile *f, void *host, int flags);
#if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY)
bool ram_save_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
bool last_stage);
+RAMBlock *ram_find_block(const char *id, uint8_t len);
int ram_load_mem_size(QEMUFile *f, ram_addr_t total_ram_bytes);
#endif
@@ -33,6 +33,7 @@
#include "kvm.h"
#include "hw/xen.h"
#include "qemu-timer.h"
+#include "arch_init.h"
#include "memory.h"
#include "exec-memory.h"
#if defined(CONFIG_USER_ONLY)
@@ -2517,12 +2518,11 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev)
pstrcat(new_block->idstr, sizeof(new_block->idstr), name);
qemu_mutex_lock_ramlist();
- QLIST_FOREACH(block, &ram_list.blocks, next) {
- if (block != new_block && !strcmp(block->idstr, new_block->idstr)) {
- fprintf(stderr, "RAMBlock \"%s\" already registered, abort!\n",
- new_block->idstr);
- abort();
- }
+ block = ram_find_block(new_block->idstr, strlen(new_block->idstr));
+ if (block != new_block) {
+ fprintf(stderr, "RAMBlock \"%s\" already registered, abort!\n",
+ new_block->idstr);
+ abort();
}
qemu_mutex_unlock_ramlist();
}
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp> --- arch_init.c | 31 ++++++++++++++++++++----------- arch_init.h | 1 + exec.c | 12 ++++++------ 3 files changed, 27 insertions(+), 17 deletions(-)