|
|
9ae3a8 |
From 82282810cd1209496183ccadfdaf0dba7d7621e8 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
Date: Fri, 7 Nov 2014 17:18:13 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 26/41] dump: simplify get_len_buf_out()
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Message-id: <1415380693-16593-27-git-send-email-lersek@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 62209
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.1 qemu-kvm PATCH 26/26] dump: simplify get_len_buf_out()
|
|
|
9ae3a8 |
Bugzilla: 1157798
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: dgibson <dgibson@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
We can (and should) rely on the fact that s->flag_compress is exactly one
|
|
|
9ae3a8 |
of DUMP_DH_COMPRESSED_ZLIB, DUMP_DH_COMPRESSED_LZO, and
|
|
|
9ae3a8 |
DUMP_DH_COMPRESSED_SNAPPY.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This is ensured by the QMP schema and dump_init() in combination.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit b87ef3518b2eeb9a57ee0d06d7e82a07ab5e4ffd)
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
dump.c | 46 ++++++++++++++++------------------------------
|
|
|
9ae3a8 |
1 file changed, 16 insertions(+), 30 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/dump.c b/dump.c
|
|
|
9ae3a8 |
index f980354..e9bd237 100644
|
|
|
9ae3a8 |
--- a/dump.c
|
|
|
9ae3a8 |
+++ b/dump.c
|
|
|
9ae3a8 |
@@ -1226,35 +1226,24 @@ static void free_data_cache(DataCache *data_cache)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static size_t get_len_buf_out(size_t page_size, uint32_t flag_compress)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- size_t len_buf_out_zlib, len_buf_out_lzo, len_buf_out_snappy;
|
|
|
9ae3a8 |
- size_t len_buf_out;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* init buf_out */
|
|
|
9ae3a8 |
- len_buf_out_zlib = len_buf_out_lzo = len_buf_out_snappy = 0;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* buf size for zlib */
|
|
|
9ae3a8 |
- len_buf_out_zlib = compressBound(page_size);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* buf size for lzo */
|
|
|
9ae3a8 |
-#ifdef CONFIG_LZO
|
|
|
9ae3a8 |
- /*
|
|
|
9ae3a8 |
- * LZO will expand incompressible data by a little amount. please check the
|
|
|
9ae3a8 |
- * following URL to see the expansion calculation:
|
|
|
9ae3a8 |
- * http://www.oberhumer.com/opensource/lzo/lzofaq.php
|
|
|
9ae3a8 |
- */
|
|
|
9ae3a8 |
- len_buf_out_lzo = page_size + page_size / 16 + 64 + 3;
|
|
|
9ae3a8 |
-#endif
|
|
|
9ae3a8 |
+ switch (flag_compress) {
|
|
|
9ae3a8 |
+ case DUMP_DH_COMPRESSED_ZLIB:
|
|
|
9ae3a8 |
+ return compressBound(page_size);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ case DUMP_DH_COMPRESSED_LZO:
|
|
|
9ae3a8 |
+ /*
|
|
|
9ae3a8 |
+ * LZO will expand incompressible data by a little amount. Please check
|
|
|
9ae3a8 |
+ * the following URL to see the expansion calculation:
|
|
|
9ae3a8 |
+ * http://www.oberhumer.com/opensource/lzo/lzofaq.php
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ return page_size + page_size / 16 + 64 + 3;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
#ifdef CONFIG_SNAPPY
|
|
|
9ae3a8 |
- /* buf size for snappy */
|
|
|
9ae3a8 |
- len_buf_out_snappy = snappy_max_compressed_length(page_size);
|
|
|
9ae3a8 |
+ case DUMP_DH_COMPRESSED_SNAPPY:
|
|
|
9ae3a8 |
+ return snappy_max_compressed_length(page_size);
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* get the biggest that can store all kinds of compressed page */
|
|
|
9ae3a8 |
- len_buf_out = MAX(len_buf_out_zlib,
|
|
|
9ae3a8 |
- MAX(len_buf_out_lzo, len_buf_out_snappy));
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- return len_buf_out;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ return 0;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/*
|
|
|
9ae3a8 |
@@ -1290,10 +1279,7 @@ static int write_dump_pages(DumpState *s)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* prepare buffer to store compressed data */
|
|
|
9ae3a8 |
len_buf_out = get_len_buf_out(TARGET_PAGE_SIZE, s->flag_compress);
|
|
|
9ae3a8 |
- if (len_buf_out == 0) {
|
|
|
9ae3a8 |
- dump_error(s, "dump: failed to get length of output buffer.\n");
|
|
|
9ae3a8 |
- goto out;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
+ assert(len_buf_out != 0);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
#ifdef CONFIG_LZO
|
|
|
9ae3a8 |
wrkmem = g_malloc(LZO1X_1_MEM_COMPRESS);
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|