From b3be28969b797b27d7f7f806827e9898e4ee08f0 Mon Sep 17 00:00:00 2001 From: Liang Li Date: Thu, 5 May 2016 15:32:54 +0800 Subject: qemu-file: Fix qemu_put_compression_data flaw Current qemu_put_compression_data can only work with no writable QEMUFile, and can't work with the writable QEMUFile. But it does not provide any measure to prevent users from using it with a writable QEMUFile. We should fix this flaw to make it works with writable QEMUFile. Signed-off-by: Liang Li Suggested-by: Juan Quintela Message-Id: <1462433579-13691-5-git-send-email-liang.z.li@intel.com> Signed-off-by: Amit Shah --- migration/ram.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'migration/ram.c') diff --git a/migration/ram.c b/migration/ram.c index 6416e60412..d30c923195 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -821,7 +821,13 @@ static int do_compress_ram_page(CompressParam *param) RAM_SAVE_FLAG_COMPRESS_PAGE); blen = qemu_put_compression_data(param->file, p, TARGET_PAGE_SIZE, migrate_compress_level()); - bytes_sent += blen; + if (blen < 0) { + bytes_sent = 0; + qemu_file_set_error(migrate_get_current()->to_dst_file, blen); + error_report("compressed data failed!"); + } else { + bytes_sent += blen; + } return bytes_sent; } @@ -965,10 +971,12 @@ static int ram_save_compressed_page(QEMUFile *f, PageSearchStatus *pss, * first page is sent out before other pages */ bytes_xmit = do_compress_ram_page(&comp_param[0]); - acct_info.norm_pages++; - qemu_put_qemu_file(f, comp_param[0].file); - *bytes_transferred += bytes_xmit; - pages = 1; + if (bytes_xmit > 0) { + acct_info.norm_pages++; + qemu_put_qemu_file(f, comp_param[0].file); + *bytes_transferred += bytes_xmit; + pages = 1; + } } } else { pages = save_zero_page(f, block, offset, p, bytes_transferred); -- cgit 1.4.1