migration: Refactoring multi-thread compress migration
PATCH v2 2/6 migration: Refactoring multi-thread compress migration
Code refactor for the compression procedure which includes:
1. Move qemu_compress_data and qemu_put_compression_data from qemu-file.c to ram.c, for the reason that most part of the code logical has nothing to do with qemu-file. Besides, the decompression code is located at ram.c only.
2. Simplify the function input arguments for compression and decompression. Wrap the input into the param structure which already exists. This change also makes the function much more flexible for other compression methods.
Signed-off-by Zeyu Jin <[email protected]>
Signed-off-by Ying Fang <[email protected]>
--- migration/qemu-file.c | 62 ++++++------------------------- migration/qemu-file.h | 4 +- migration/ram.c | 86 ++++++++++++++++++++++++++++++------------- 3 files changed, 75 insertions(+), 77 deletions(-)
migration/qemu-file.c +12 -50
@@ -737,56 +737,6 @@ uint64_t qemu_get_be64(QEMUFile *f)return v; } -/* return the size after compression, or negative value on error */ -static int qemu_compress_data (z_stream *stream,uint8_t *dest,size_t dest_len, -const uint8_t *source,size_t source_len) -{ -int err; - - err =deflateReset (stream); -if (err !=Z_OK ) { -return -1 ; - } - - stream->avail_in = source_len; - stream->next_in = (uint8_t *)source; - stream->avail_out = dest_len; - stream->next_out = dest; - - err =deflate (stream,Z_FINISH ); -if (err !=Z_STREAM_END ) { -return -1 ; - } - -return stream->next_out - dest; -} - -/* Compress size bytes of data start at p and store the compressed -* data to the buffer of f. -* -* Since the file is dummy file with empty_ops, return -1 if f has no space to -* save the compressed data. -*/ -ssize_t qemu_put_compression_data (QEMUFile *f,z_stream *stream, -const uint8_t *p,size_t size) -{ -ssize_t blen =IO_BUF_SIZE - f->buf_index -sizeof (int32_t ); - -if (blen <compressBound (size)) { -return -1 ; - } - - blen =qemu_compress_data (stream, f->buf + f->buf_index +sizeof (int32_t ), - blen, p, size); -if (blen <0 ) { -return -1 ; - } - -qemu_put_be32 (f, blen); -add_buf_to_iovec (f, 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. */
@@ -846,3 +796,15 @@ void qemu_file_set_blocking(QEMUFile *f, bool block) f->ops->set_blocking (f->opaque, block,NULL ); } } + +ssize_t qemu_put_compress_start (QEMUFile *f,uint8_t **dest_ptr) +{ + *dest_ptr = f->buf + f->buf_index +sizeof (int32_t ); +return IO_BUF_SIZE - f->buf_index -sizeof (int32_t ); +} + +void qemu_put_compress_end (QEMUFile *f,unsigned int v) +{ +qemu_put_be32 (f, v); +add_buf_to_iovec (f, v); +}
migration/qemu-file.h +2 -2
@@ -138,8 +138,6 @@ bool qemu_file_is_writable(QEMUFile *f);size_t qemu_peek_buffer (QEMUFile *f,uint8_t **buf,size_t size,size_t offset);size_t qemu_get_buffer_in_place (QEMUFile *f,uint8_t **buf,size_t size); -ssize_t qemu_put_compression_data (QEMUFile *f,z_stream *stream, -const uint8_t *p,size_t size);int qemu_put_qemu_file (QEMUFile *f_des,QEMUFile *f_src);/*
@@ -166,6 +164,8 @@ void ram_control_before_iterate(QEMUFile *f, uint64_t flags);void ram_control_after_iterate (QEMUFile *f,uint64_t flags);void ram_control_load_hook (QEMUFile *f,uint64_t flags,void *data); +ssize_t qemu_put_compress_start (QEMUFile *f,uint8_t **dest_ptr); +void qemu_put_compress_end (QEMUFile *f,unsigned int v);/* Whenever this is found in the data stream, the flags * will be passed to ram_control_load_hook in the incoming-migration * side. This lets before_ram_iterate/after_ram_iterate add
migration/ram.c +61 -25
157 lines not on this page · raw message
Signature · 1 line
2.27.0