[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 04/16] qemu-file: Add compression functions to QEMUFi
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PULL 04/16] qemu-file: Add compression functions to QEMUFile |
Date: |
Thu, 7 May 2015 13:50:32 +0200 |
From: Liang Li <address@hidden>
qemu_put_compression_data() compress the data and put it to QEMUFile.
qemu_put_qemu_file() put the data in the buffer of source QEMUFile to
destination QEMUFile.
Signed-off-by: Liang Li <address@hidden>
Signed-off-by: Yang Zhang <address@hidden>
Reviewed-by: Juan Quintela <address@hidden>
Signed-off-by: Juan Quintela <address@hidden>
---
include/migration/qemu-file.h | 3 +++
migration/qemu-file.c | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index 745a850..a01c5b8 100644
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -159,6 +159,9 @@ void qemu_put_be32(QEMUFile *f, unsigned int v);
void qemu_put_be64(QEMUFile *f, uint64_t v);
int qemu_peek_buffer(QEMUFile *f, uint8_t *buf, int size, size_t offset);
int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
+ssize_t qemu_put_compression_data(QEMUFile *f, const uint8_t *p, size_t size,
+ int level);
+int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src);
/*
* Note that you can only peek continuous bytes from where the current pointer
* is; you aren't guaranteed to be able to peak to +n bytes unless you've
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 1a4f986..2750365 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+#include <zlib.h>
#include "qemu-common.h"
#include "qemu/iov.h"
#include "qemu/sockets.h"
@@ -546,3 +547,41 @@ uint64_t qemu_get_be64(QEMUFile *f)
v |= qemu_get_be32(f);
return v;
}
+
+/* compress size bytes of data start at p with specific compression
+ * level and store the compressed data to the buffer of f.
+ */
+
+ssize_t qemu_put_compression_data(QEMUFile *f, const uint8_t *p, size_t size,
+ int level)
+{
+ ssize_t blen = IO_BUF_SIZE - f->buf_index - sizeof(int32_t);
+
+ if (blen < compressBound(size)) {
+ return 0;
+ }
+ if (compress2(f->buf + f->buf_index + sizeof(int32_t), (uLongf *)&blen,
+ (Bytef *)p, size, level) != Z_OK) {
+ error_report("Compress Failed!");
+ return 0;
+ }
+ qemu_put_be32(f, blen);
+ f->buf_index += blen;
+ return blen + sizeof(int32_t);
+}
+
+/* Put the data in the buffer of f_src to the buffer of f_des, and
+ * then reset the buf_index of f_src to 0.
+ */
+
+int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src)
+{
+ int len = 0;
+
+ if (f_src->buf_index > 0) {
+ len = f_src->buf_index;
+ qemu_put_buffer(f_des, f_src->buf, f_src->buf_index);
+ f_src->buf_index = 0;
+ }
+ return len;
+}
--
2.4.0
- [Qemu-devel] [PULL 00/16] Migration pull request (v2), Juan Quintela, 2015/05/07
- [Qemu-devel] [PULL 01/16] docs: Add a doc about multiple thread compression, Juan Quintela, 2015/05/07
- [Qemu-devel] [PULL 02/16] migration: Add the framework of multi-thread compression, Juan Quintela, 2015/05/07
- [Qemu-devel] [PULL 03/16] migration: Add the framework of multi-thread decompression, Juan Quintela, 2015/05/07
- [Qemu-devel] [PULL 04/16] qemu-file: Add compression functions to QEMUFile,
Juan Quintela <=
- [Qemu-devel] [PULL 06/16] arch_init: Add and free data struct for decompression, Juan Quintela, 2015/05/07
- [Qemu-devel] [PULL 07/16] migration: Split save_zero_page from ram_save_page, Juan Quintela, 2015/05/07
- [Qemu-devel] [PULL 05/16] arch_init: Alloc and free data struct for compression, Juan Quintela, 2015/05/07
- [Qemu-devel] [PULL 08/16] migration: Add the core code of multi-thread compression, Juan Quintela, 2015/05/07
- [Qemu-devel] [PULL 09/16] migration: Make compression co-work with xbzrle, Juan Quintela, 2015/05/07
- [Qemu-devel] [PULL 11/16] migration: Add interface to control compression, Juan Quintela, 2015/05/07
- [Qemu-devel] [PULL 10/16] migration: Add the core code for decompression, Juan Quintela, 2015/05/07
- [Qemu-devel] [PULL 12/16] migration: Use an array instead of 3 parameters, Juan Quintela, 2015/05/07
- [Qemu-devel] [PULL 15/16] migration: avoid divide by zero in xbzrle cache miss rate, Juan Quintela, 2015/05/07
- [Qemu-devel] [PULL 13/16] migration: Add qmp commands to set and query parameters, Juan Quintela, 2015/05/07