Currently if you set these flags and have any shared memory object, saving
a snapshot will fail with:
Failed to write bitmap to file: Unable to write to file: Bad address
We need to skip writing RAMBlocks that are backed by shared objects.
Also, we should mark these RAMBlocks as skipped, so the snapshot format stays
readable to tools that later don't know QEMU's command line (for example
scripts/analyze-migration.py). I used bitmap_offset=0 pages_offset=0 for this.
This minor change to snapshot format should be safe, as offset=0 should not
have ever been possible.
Signed-off-by: Pawel Zmarzly <[email protected]>
---
This requires my previous patch "migration: fix parsing snapshots with
x-ignore-shared flag". To make things easier, you can see the stack at
https://gitlab.com/pzmarzly/qemu/-/commits/pzmarzly?ref_type=heads
---
migration/ram.c | 51 ++++++++++++++++++++++++++++++++-----------------
1 file changed, 33 insertions(+), 18 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index 7d024b88b5..8063522a14 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -3042,28 +3042,36 @@ static void mapped_ram_setup_ramblock(QEMUFile *file,
RAMBlock *block)
header = g_new0(MappedRamHeader, 1);
header_size = sizeof(MappedRamHeader);
- num_pages = block->used_length >> TARGET_PAGE_BITS;
- bitmap_size = BITS_TO_LONGS(num_pages) * sizeof(unsigned long);
-
- /*
- * Save the file offsets of where the bitmap and the pages should
- * go as they are written at the end of migration and during the
- * iterative phase, respectively.
- */
- block->bitmap_offset = qemu_get_offset(file) + header_size;
- block->pages_offset = ROUND_UP(block->bitmap_offset +
- bitmap_size,
- MAPPED_RAM_FILE_OFFSET_ALIGNMENT);
-
header->version = cpu_to_be32(MAPPED_RAM_HDR_VERSION);
header->page_size = cpu_to_be64(TARGET_PAGE_SIZE);
- header->bitmap_offset = cpu_to_be64(block->bitmap_offset);
- header->pages_offset = cpu_to_be64(block->pages_offset);
+
+ if (migrate_ram_is_ignored(block)) {
+ header->bitmap_offset = 0;
+ header->pages_offset = 0;
+ } else {
+ num_pages = block->used_length >> TARGET_PAGE_BITS;
+ bitmap_size = BITS_TO_LONGS(num_pages) * sizeof(unsigned long);
+
+ /*
+ * Save the file offsets of where the bitmap and the pages should
+ * go as they are written at the end of migration and during the
+ * iterative phase, respectively.
+ */
+ block->bitmap_offset = qemu_get_offset(file) + header_size;
+ block->pages_offset = ROUND_UP(block->bitmap_offset +
+ bitmap_size,
+ MAPPED_RAM_FILE_OFFSET_ALIGNMENT);
+
+ header->bitmap_offset = cpu_to_be64(block->bitmap_offset);
+ header->pages_offset = cpu_to_be64(block->pages_offset);
+ }
qemu_put_buffer(file, (uint8_t *) header, header_size);
- /* prepare offset for next ramblock */
- qemu_set_offset(file, block->pages_offset + block->used_length, SEEK_SET);
+ if (!migrate_ram_is_ignored(block)) {
+ /* leave space for block data */
+ qemu_set_offset(file, block->pages_offset + block->used_length,
SEEK_SET);
+ }
}
static bool mapped_ram_read_header(QEMUFile *file, MappedRamHeader *header,
@@ -3146,7 +3154,6 @@ static int ram_save_setup(QEMUFile *f, void *opaque,
Error **errp)
if (migrate_ignore_shared()) {
qemu_put_be64(f, block->mr->addr);
}
-
if (migrate_mapped_ram()) {
mapped_ram_setup_ramblock(f, block);
}
@@ -3217,6 +3224,10 @@ static void ram_save_file_bmap(QEMUFile *f)
RAMBlock *block;
RAMBLOCK_FOREACH_MIGRATABLE(block) {
+ if (migrate_ram_is_ignored(block)) {
+ continue;
+ }
+
long num_pages = block->used_length >> TARGET_PAGE_BITS;
long bitmap_size = BITS_TO_LONGS(num_pages) * sizeof(unsigned long);
@@ -4162,6 +4173,10 @@ static void parse_ramblock_mapped_ram(QEMUFile *f,
RAMBlock *block,
return;
}
+ if (migrate_ignore_shared() && header.bitmap_offset == 0 &&
header.pages_offset == 0) {
+ return;
+ }
+
block->pages_offset = header.pages_offset;
/*
--
2.52.0