From patchwork Fri Dec 12 01:28:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Liang Z" X-Patchwork-Id: 420325 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0258A1400EA for ; Fri, 12 Dec 2014 12:37:03 +1100 (AEDT) Received: from localhost ([::1]:54992 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzFAC-0004e0-Qa for incoming@patchwork.ozlabs.org; Thu, 11 Dec 2014 20:37:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48123) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzF9Q-0003Sq-RO for qemu-devel@nongnu.org; Thu, 11 Dec 2014 20:36:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XzF9L-0004mB-O3 for qemu-devel@nongnu.org; Thu, 11 Dec 2014 20:36:12 -0500 Received: from mga01.intel.com ([192.55.52.88]:12346) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzF9L-0004m3-IV for qemu-devel@nongnu.org; Thu, 11 Dec 2014 20:36:07 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 11 Dec 2014 17:36:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,561,1413270000"; d="scan'208";a="646398297" Received: from lil.sh.intel.com (HELO localhost) ([10.239.36.68]) by fmsmga002.fm.intel.com with ESMTP; 11 Dec 2014 17:36:05 -0800 From: Liang Li To: qemu-devel@nongnu.org Date: Fri, 12 Dec 2014 09:28:57 +0800 Message-Id: <1418347746-15829-5-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418347746-15829-1-git-send-email-liang.z.li@intel.com> References: <1418347746-15829-1-git-send-email-liang.z.li@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 Cc: quintela@redhat.com, Liang Li , armbru@redhat.com, lcapitulino@redhat.com, yang.z.zhang@intel.com, dgilbert@redhat.com Subject: [Qemu-devel] [v3 04/13] qemu-file: Add tow function will be used in migration X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org migrate_qemu_add_compression_data() compress the data and put it to QEMUFile. migrate_qemu_flush() put the data in the source QEMUFile to destination QEMUFile. The two function can help to do live migration. Signed-off-by: Liang Li Signed-off-by: Yang Zhang --- include/migration/qemu-file.h | 3 +++ qemu-file.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h index 401676b..d70fb8d 100644 --- a/include/migration/qemu-file.h +++ b/include/migration/qemu-file.h @@ -150,6 +150,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); +size_t migrate_qemu_add_compression_data(QEMUFile *f, + const uint8_t *p, size_t size, int level); +int migrate_qemu_flush(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/qemu-file.c b/qemu-file.c index f938e36..2668ad0 100644 --- a/qemu-file.c +++ b/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 #include "qemu-common.h" #include "qemu/iov.h" #include "qemu/sockets.h" @@ -993,3 +994,34 @@ QEMUFile *qemu_bufopen(const char *mode, QEMUSizedBuffer *input) } return s->file; } + +/* compress size bytes of data start at p with specific compression + * leve and store the compressed data to the buffer of f. + */ + +size_t migrate_qemu_add_compression_data(QEMUFile *f, + const uint8_t *p, size_t size, int level) +{ + size_t blen = IO_BUF_SIZE - f->buf_index - sizeof(int); + + if (compress2(f->buf + f->buf_index + sizeof(int), &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(int); +} + +int migrate_qemu_flush(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; +}