[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 06/57] qemu_ram_block_by_name
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PULL 06/57] qemu_ram_block_by_name |
Date: |
Tue, 10 Nov 2015 15:24:55 +0100 |
From: "Dr. David Alan Gilbert" <address@hidden>
Add a function to find a RAMBlock by name; use it in two
of the places that already open code that loop; we've
got another use later in postcopy.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
Reviewed-by: Juan Quintela <address@hidden>
Signed-off-by: Juan Quintela <address@hidden>
---
exec.c | 20 ++++++++++++++++++++
include/exec/cpu-common.h | 1 +
migration/ram.c | 35 +++++++++++++++--------------------
3 files changed, 36 insertions(+), 20 deletions(-)
diff --git a/exec.c b/exec.c
index 53d3848..36886ee 100644
--- a/exec.c
+++ b/exec.c
@@ -1946,6 +1946,26 @@ found:
return block;
}
+/*
+ * Finds the named RAMBlock
+ *
+ * name: The name of RAMBlock to find
+ *
+ * Returns: RAMBlock (or NULL if not found)
+ */
+RAMBlock *qemu_ram_block_by_name(const char *name)
+{
+ RAMBlock *block;
+
+ QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
+ if (!strcmp(name, block->idstr)) {
+ return block;
+ }
+ }
+
+ return NULL;
+}
+
/* Some of the softmmu routines need to translate from a host pointer
(typically a TLB entry) back to a ram offset. */
MemoryRegion *qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr)
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 94d1f8a..85aa403 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -64,6 +64,7 @@ typedef uint32_t CPUReadMemoryFunc(void *opaque, hwaddr addr);
void qemu_ram_remap(ram_addr_t addr, ram_addr_t length);
/* This should not be used by devices. */
MemoryRegion *qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr);
+RAMBlock *qemu_ram_block_by_name(const char *name);
RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
ram_addr_t *ram_addr, ram_addr_t *offset);
void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev);
diff --git a/migration/ram.c b/migration/ram.c
index df3df9e..d654a73 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1420,14 +1420,12 @@ static inline void *host_from_stream_offset(QEMUFile *f,
qemu_get_buffer(f, (uint8_t *)id, len);
id[len] = 0;
- QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
- if (!strncmp(id, block->idstr, sizeof(id)) &&
- block->max_length > offset) {
- return block->host + offset;
- }
+ block = qemu_ram_block_by_name(id);
+ if (block && block->max_length > offset) {
+ return block->host + offset;
}
- error_report("Can't find block %s!", id);
+ error_report("Can't find block %s", id);
return NULL;
}
@@ -1576,23 +1574,20 @@ static int ram_load(QEMUFile *f, void *opaque, int
version_id)
id[len] = 0;
length = qemu_get_be64(f);
- QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
- if (!strncmp(id, block->idstr, sizeof(id))) {
- if (length != block->used_length) {
- Error *local_err = NULL;
+ block = qemu_ram_block_by_name(id);
+ if (block) {
+ if (length != block->used_length) {
+ Error *local_err = NULL;
- ret = qemu_ram_resize(block->offset, length,
&local_err);
- if (local_err) {
- error_report_err(local_err);
- }
+ ret = qemu_ram_resize(block->offset, length,
+ &local_err);
+ if (local_err) {
+ error_report_err(local_err);
}
- ram_control_load_hook(f, RAM_CONTROL_BLOCK_REG,
- block->idstr);
- break;
}
- }
-
- if (!block) {
+ ram_control_load_hook(f, RAM_CONTROL_BLOCK_REG,
+ block->idstr);
+ } else {
error_report("Unknown ramblock \"%s\", cannot "
"accept migration", id);
ret = -EINVAL;
--
2.5.0
- [Qemu-devel] [PULL 00/57] Migration pull (take 2), Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 01/57] Add postcopy documentation, Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 03/57] Move configuration section writing, Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 02/57] Provide runtime Target page information, Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 05/57] qemu_ram_block_from_host, Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 04/57] Move page_size_init earlier, Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 06/57] qemu_ram_block_by_name,
Juan Quintela <=
- [Qemu-devel] [PULL 08/57] Add qemu_get_buffer_in_place to avoid copies some of the time, Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 09/57] Add wrapper for setting blocking status on a QEMUFile, Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 10/57] Add QEMU_MADV_NOHUGEPAGE, Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 07/57] Rename mis->file to from_src_file, Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 11/57] ram_debug_dump_bitmap: Dump a migration bitmap as text, Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 12/57] ram_load: Factor out host_from_stream_offset call and check, Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 14/57] Rename save_live_complete to save_live_complete_precopy, Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 15/57] Add Linux userfaultfd.h header, Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 13/57] migrate_init: Call from savevm, Juan Quintela, 2015/11/10
- [Qemu-devel] [PULL 16/57] Return path: Open a return path on QEMUFile for sockets, Juan Quintela, 2015/11/10