cryptospore / rpms / qemu-kvm

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