From patchwork Thu Apr 5 10:47:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v8,03/10] Add save_block_hdr function X-Patchwork-Submitter: Orit Wasserman X-Patchwork-Id: 151016 Message-Id: <1333622879-12055-4-git-send-email-owasserm@redhat.com> To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com, blauwirbel@gmail.com, Orit Wasserman , avi@redhat.com Date: Thu, 5 Apr 2012 13:47:52 +0300 From: Orit Wasserman List-Id: Signed-off-by: Orit Wasserman --- arch_init.c | 25 +++++++++++++------------ 1 files changed, 13 insertions(+), 12 deletions(-) diff --git a/arch_init.c b/arch_init.c index 42d4f17..5f60fa9 100644 --- a/arch_init.c +++ b/arch_init.c @@ -301,6 +301,17 @@ static void cache_insert(unsigned long addr, uint8_t *pdata) it->it_addr = addr; } +static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset, + int cont, int flag) +{ + qemu_put_be64(f, offset | cont | flag); + if (!cont) { + qemu_put_byte(f, strlen(block->idstr)); + qemu_put_buffer(f, (uint8_t *)block->idstr, + strlen(block->idstr)); + } +} + static RAMBlock *last_block; static ram_addr_t last_offset; @@ -327,21 +338,11 @@ static int ram_save_block(QEMUFile *f) p = memory_region_get_ram_ptr(mr) + offset; if (is_dup_page(p)) { - qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_COMPRESS); - if (!cont) { - qemu_put_byte(f, strlen(block->idstr)); - qemu_put_buffer(f, (uint8_t *)block->idstr, - strlen(block->idstr)); - } + save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS); qemu_put_byte(f, *p); bytes_sent = 1; } else { - qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_PAGE); - if (!cont) { - qemu_put_byte(f, strlen(block->idstr)); - qemu_put_buffer(f, (uint8_t *)block->idstr, - strlen(block->idstr)); - } + save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE); qemu_put_buffer(f, p, TARGET_PAGE_SIZE); bytes_sent = TARGET_PAGE_SIZE; }