[PATCH v3 15/35] arch_init/ram_save_setup: factor out bitmap alloc/free

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This will be used by postcopy.

Signed-off-by: Isaku Yamahata <yamahata@xxxxxxxxxxxxx>
---
Changes v2 -> v3:
- new
---
 arch_init.c |   25 ++++++++++++++++++-------
 migration.h |    2 ++
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index ad1b01b..7e6d84e 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -330,6 +330,22 @@ static unsigned long *migration_bitmap;
 static uint64_t migration_dirty_pages;
 static uint32_t last_version;
 
+void migration_bitmap_init(void)
+{
+    int64_t ram_pages = last_ram_offset() >> TARGET_PAGE_BITS;
+    if (!migration_bitmap) {
+        migration_bitmap = bitmap_new(ram_pages);
+    }
+    bitmap_set(migration_bitmap, 1, ram_pages);
+    migration_dirty_pages = ram_pages;
+}
+
+void migration_bitmap_free(void)
+{
+    g_free(migration_bitmap);
+    migration_bitmap = NULL;
+}
+
 static inline bool migration_bitmap_test_and_reset_dirty(MemoryRegion *mr,
                                                          ram_addr_t offset)
 {
@@ -575,11 +591,7 @@ static void reset_ram_globals(void)
 static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     RAMBlock *block;
-    int64_t ram_pages = last_ram_offset() >> TARGET_PAGE_BITS;
-
-    migration_bitmap = bitmap_new(ram_pages);
-    bitmap_set(migration_bitmap, 1, ram_pages);
-    migration_dirty_pages = ram_pages;
+    migration_bitmap_init();
 
     qemu_mutex_lock_ramlist();
     bytes_transferred = 0;
@@ -704,8 +716,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
     qemu_mutex_unlock_ramlist();
     qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
 
-    g_free(migration_bitmap);
-    migration_bitmap = NULL;
+    migration_bitmap_free();
 
     return 0;
 }
diff --git a/migration.h b/migration.h
index 7d1b62d..73416ba 100644
--- a/migration.h
+++ b/migration.h
@@ -95,6 +95,8 @@ bool ram_save_block(QEMUFile *f, bool last_stage);
 uint64_t ram_bytes_remaining(void);
 uint64_t ram_bytes_transferred(void);
 uint64_t ram_bytes_total(void);
+void migration_bitmap_init(void);
+void migration_bitmap_free(void);
 
 extern SaveVMHandlers savevm_ram_handlers;
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux