Split ram_save_block
ram_save_block is getting a bit too complicated, and does two separate things: 1) Finds a page to send 2) Sends the page (dealing with compression etc) Split into 'ram_save_page' to send the page and deal with compression (2) Rename remaining function to 'ram_find_and_save_block' Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Signed-off-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
parent
fb626663da
commit
14bcfdc7f1
87
arch_init.c
87
arch_init.c
|
@ -560,45 +560,22 @@ static void migration_bitmap_sync(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ram_save_block: Writes a page of memory to the stream f
|
* ram_save_page: Send the given page to the stream
|
||||||
*
|
*
|
||||||
* Returns: The number of bytes written.
|
* Returns: Number of bytes written.
|
||||||
* 0 means no dirty pages
|
|
||||||
*/
|
*/
|
||||||
|
static int ram_save_page(QEMUFile *f, RAMBlock* block, ram_addr_t offset,
|
||||||
static int ram_save_block(QEMUFile *f, bool last_stage)
|
bool last_stage)
|
||||||
{
|
{
|
||||||
RAMBlock *block = last_seen_block;
|
int bytes_sent;
|
||||||
ram_addr_t offset = last_offset;
|
int cont;
|
||||||
bool complete_round = false;
|
|
||||||
int bytes_sent = 0;
|
|
||||||
MemoryRegion *mr;
|
|
||||||
ram_addr_t current_addr;
|
ram_addr_t current_addr;
|
||||||
|
MemoryRegion *mr = block->mr;
|
||||||
if (!block)
|
|
||||||
block = QTAILQ_FIRST(&ram_list.blocks);
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
mr = block->mr;
|
|
||||||
offset = migration_bitmap_find_and_reset_dirty(mr, offset);
|
|
||||||
if (complete_round && block == last_seen_block &&
|
|
||||||
offset >= last_offset) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (offset >= block->length) {
|
|
||||||
offset = 0;
|
|
||||||
block = QTAILQ_NEXT(block, next);
|
|
||||||
if (!block) {
|
|
||||||
block = QTAILQ_FIRST(&ram_list.blocks);
|
|
||||||
complete_round = true;
|
|
||||||
ram_bulk_stage = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int ret;
|
|
||||||
uint8_t *p;
|
uint8_t *p;
|
||||||
|
int ret;
|
||||||
bool send_async = true;
|
bool send_async = true;
|
||||||
int cont = (block == last_sent_block) ?
|
|
||||||
RAM_SAVE_FLAG_CONTINUE : 0;
|
cont = (block == last_sent_block) ? RAM_SAVE_FLAG_CONTINUE : 0;
|
||||||
|
|
||||||
p = memory_region_get_ram_ptr(mr) + offset;
|
p = memory_region_get_ram_ptr(mr) + offset;
|
||||||
|
|
||||||
|
@ -652,6 +629,46 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
|
||||||
}
|
}
|
||||||
|
|
||||||
XBZRLE_cache_unlock();
|
XBZRLE_cache_unlock();
|
||||||
|
|
||||||
|
return bytes_sent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ram_find_and_save_block: Finds a page to send and sends it to f
|
||||||
|
*
|
||||||
|
* Returns: The number of bytes written.
|
||||||
|
* 0 means no dirty pages
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int ram_find_and_save_block(QEMUFile *f, bool last_stage)
|
||||||
|
{
|
||||||
|
RAMBlock *block = last_seen_block;
|
||||||
|
ram_addr_t offset = last_offset;
|
||||||
|
bool complete_round = false;
|
||||||
|
int bytes_sent = 0;
|
||||||
|
MemoryRegion *mr;
|
||||||
|
|
||||||
|
if (!block)
|
||||||
|
block = QTAILQ_FIRST(&ram_list.blocks);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
mr = block->mr;
|
||||||
|
offset = migration_bitmap_find_and_reset_dirty(mr, offset);
|
||||||
|
if (complete_round && block == last_seen_block &&
|
||||||
|
offset >= last_offset) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (offset >= block->length) {
|
||||||
|
offset = 0;
|
||||||
|
block = QTAILQ_NEXT(block, next);
|
||||||
|
if (!block) {
|
||||||
|
block = QTAILQ_FIRST(&ram_list.blocks);
|
||||||
|
complete_round = true;
|
||||||
|
ram_bulk_stage = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bytes_sent = ram_save_page(f, block, offset, last_stage);
|
||||||
|
|
||||||
/* if page is unmodified, continue to the next */
|
/* if page is unmodified, continue to the next */
|
||||||
if (bytes_sent > 0) {
|
if (bytes_sent > 0) {
|
||||||
last_sent_block = block;
|
last_sent_block = block;
|
||||||
|
@ -850,7 +867,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
|
||||||
while ((ret = qemu_file_rate_limit(f)) == 0) {
|
while ((ret = qemu_file_rate_limit(f)) == 0) {
|
||||||
int bytes_sent;
|
int bytes_sent;
|
||||||
|
|
||||||
bytes_sent = ram_save_block(f, false);
|
bytes_sent = ram_find_and_save_block(f, false);
|
||||||
/* no more blocks to sent */
|
/* no more blocks to sent */
|
||||||
if (bytes_sent == 0) {
|
if (bytes_sent == 0) {
|
||||||
break;
|
break;
|
||||||
|
@ -912,7 +929,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
|
||||||
while (true) {
|
while (true) {
|
||||||
int bytes_sent;
|
int bytes_sent;
|
||||||
|
|
||||||
bytes_sent = ram_save_block(f, true);
|
bytes_sent = ram_find_and_save_block(f, true);
|
||||||
/* no more blocks to sent */
|
/* no more blocks to sent */
|
||||||
if (bytes_sent == 0) {
|
if (bytes_sent == 0) {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue