We create a struct where to put all the ram state
Start with the following fields:
last_seen_block, last_sent_block, last_offset, last_version and
ram_bulk_stage are globals that are really related together.
Signed-off-by: Juan Quintela
Reviewed-by: Dr. David Alan Gilbert
--
Fix typo and warnings
Signed-off-by: Juan Quintela
---
migration/ram.c | 140 +---
1 file changed, 83 insertions(+), 57 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index 21047c5..a6e90d7 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -142,6 +142,23 @@ out:
return ret;
}
+/* State of RAM for migration */
+struct RAMState {
+/* Last block that we have visited searching for dirty pages */
+RAMBlock *last_seen_block;
+/* Last block from where we have sent data */
+RAMBlock *last_sent_block;
+/* Last offset we have sent data from */
+ram_addr_t last_offset;
+/* last ram version we have seen */
+uint32_t last_version;
+/* We are in the first round */
+bool ram_bulk_stage;
+};
+typedef struct RAMState RAMState;
+
+static RAMState ram_state;
+
/* accounting for migration statistics */
typedef struct AccountingInfo {
uint64_t dup_pages;
@@ -217,16 +234,8 @@ uint64_t xbzrle_mig_pages_overflow(void)
return acct_info.xbzrle_overflows;
}
-/* This is the last block that we have visited serching for dirty pages
- */
-static RAMBlock *last_seen_block;
-/* This is the last block from where we have sent data */
-static RAMBlock *last_sent_block;
-static ram_addr_t last_offset;
static QemuMutex migration_bitmap_mutex;
static uint64_t migration_dirty_pages;
-static uint32_t last_version;
-static bool ram_bulk_stage;
/* used by the search for pages to send */
struct PageSearchStatus {
@@ -444,6 +453,7 @@ static void mig_throttle_guest_down(void)
/**
* xbzrle_cache_zero_page: insert a zero page in the XBZRLE cache
*
+ * @rs: current RAM state
* @current_addr: address for the zero page
*
* Update the xbzrle cache to reflect a page that's been sent as all 0.
@@ -452,9 +462,9 @@ static void mig_throttle_guest_down(void)
* As a bonus, if the page wasn't in the cache it gets added so that
* when a small write is made into the 0'd page it gets XBZRLE sent.
*/
-static void xbzrle_cache_zero_page(ram_addr_t current_addr)
+static void xbzrle_cache_zero_page(RAMState *rs, ram_addr_t current_addr)
{
-if (ram_bulk_stage || !migrate_use_xbzrle()) {
+if (rs->ram_bulk_stage || !migrate_use_xbzrle()) {
return;
}
@@ -552,13 +562,14 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t
**current_data,
*
* Returns the byte offset within memory region of the start of a dirty page
*
+ * @rs: current RAM state
* @rb: RAMBlock where to search for dirty pages
* @start: starting address (typically so we can continue from previous page)
* @ram_addr_abs: pointer into which to store the address of the dirty page
*within the global ram_addr space
*/
static inline
-ram_addr_t migration_bitmap_find_dirty(RAMBlock *rb,
+ram_addr_t migration_bitmap_find_dirty(RAMState *rs, RAMBlock *rb,
ram_addr_t start,
ram_addr_t *ram_addr_abs)
{
@@ -571,7 +582,7 @@ ram_addr_t migration_bitmap_find_dirty(RAMBlock *rb,
unsigned long next;
bitmap = atomic_rcu_read(_bitmap_rcu)->bmap;
-if (ram_bulk_stage && nr > base) {
+if (rs->ram_bulk_stage && nr > base) {
next = nr + 1;
} else {
next = find_next_bit(bitmap, size, nr);
@@ -761,6 +772,7 @@ static void ram_release_pages(MigrationState *ms, const
char *rbname,
* >=0 - Number of pages written - this might legally be 0
*if xbzrle noticed the page was the same.
*
+ * @rs: current RAM state
* @ms: current migration state
* @f: QEMUFile where to send the data
* @block: block that contains the page we want to send
@@ -768,8 +780,9 @@ static void ram_release_pages(MigrationState *ms, const
char *rbname,
* @last_stage: if we are at the completion stage
* @bytes_transferred: increase it with the number of transferred bytes
*/
-static int ram_save_page(MigrationState *ms, QEMUFile *f, PageSearchStatus
*pss,
- bool last_stage, uint64_t *bytes_transferred)
+static int ram_save_page(RAMState *rs, MigrationState *ms, QEMUFile *f,
+ PageSearchStatus *pss, bool last_stage,
+ uint64_t *bytes_transferred)
{
int pages = -1;
uint64_t bytes_xmit;
@@ -795,7 +808,7 @@ static int ram_save_page(MigrationState *ms, QEMUFile *f,
PageSearchStatus *pss,
current_addr = block->offset + offset;
-if (block == last_sent_block) {
+if (block == rs->last_sent_block) {
offset |= RAM_SAVE_FLAG_CONTINUE;
}
if (ret !=