From patchwork Wed Apr 27 10:05:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 8954661 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 05AACBF29F for ; Wed, 27 Apr 2016 10:22:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2F78320142 for ; Wed, 27 Apr 2016 10:22:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 244892013A for ; Wed, 27 Apr 2016 10:21:59 +0000 (UTC) Received: from localhost ([::1]:42366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avMbW-000052-DV for patchwork-qemu-devel@patchwork.kernel.org; Wed, 27 Apr 2016 06:21:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48514) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avMLr-0005Xj-LD for qemu-devel@nongnu.org; Wed, 27 Apr 2016 06:05:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avMLl-0004VS-CB for qemu-devel@nongnu.org; Wed, 27 Apr 2016 06:05:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48894) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avMLl-0004VM-4b for qemu-devel@nongnu.org; Wed, 27 Apr 2016 06:05:41 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D15CE80B56 for ; Wed, 27 Apr 2016 10:05:40 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (vpn1-6-18.ams2.redhat.com [10.36.6.18]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3RA5MRK030816; Wed, 27 Apr 2016 06:05:39 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Wed, 27 Apr 2016 11:05:01 +0100 Message-Id: <1461751518-12128-12-git-send-email-berrange@redhat.com> In-Reply-To: <1461751518-12128-1-git-send-email-berrange@redhat.com> References: <1461751518-12128-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 for-2.7 11/28] migration: convert post-copy to use QIOChannelBuffer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amit Shah , "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The post-copy code does some I/O to/from an intermediate in-memory buffer rather than direct to the underlying I/O channel. Switch this code to use QIOChannelBuffer instead of QEMUSizedBuffer. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrange --- docs/migration.txt | 4 ++-- include/sysemu/sysemu.h | 2 +- migration/migration.c | 15 +++++++-------- migration/savevm.c | 47 ++++++++++++++++------------------------------- 4 files changed, 26 insertions(+), 42 deletions(-) diff --git a/docs/migration.txt b/docs/migration.txt index 90209ab..6503c17 100644 --- a/docs/migration.txt +++ b/docs/migration.txt @@ -403,8 +403,8 @@ listen thread: --- page -- page -- page -- page -- page -- On receipt of CMD_PACKAGED (1) All the data associated with the package - the ( ... ) section in the -diagram - is read into memory (into a QEMUSizedBuffer), and the main thread -recurses into qemu_loadvm_state_main to process the contents of the package (2) +diagram - is read into memory, and the main thread recurses into +qemu_loadvm_state_main to process the contents of the package (2) which contains commands (3,6) and devices (4...) On receipt of 'postcopy listen' - 3 -(i.e. the 1st command in the package) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 38fb3ca..fba9c57 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -119,7 +119,7 @@ void qemu_savevm_command_send(QEMUFile *f, enum qemu_vm_cmd command, uint16_t len, uint8_t *data); void qemu_savevm_send_ping(QEMUFile *f, uint32_t value); void qemu_savevm_send_open_return_path(QEMUFile *f); -int qemu_savevm_send_packaged(QEMUFile *f, const QEMUSizedBuffer *qsb); +int qemu_savevm_send_packaged(QEMUFile *f, const uint8_t *buf, size_t len); void qemu_savevm_send_postcopy_advise(QEMUFile *f); void qemu_savevm_send_postcopy_listen(QEMUFile *f); void qemu_savevm_send_postcopy_run(QEMUFile *f); diff --git a/migration/migration.c b/migration/migration.c index 518423e..efe2dfb 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -34,6 +34,7 @@ #include "qom/cpu.h" #include "exec/memory.h" #include "exec/address-spaces.h" +#include "io/channel-buffer.h" #define MAX_THROTTLE (32 << 20) /* Migration transfer speed throttling */ @@ -1448,7 +1449,8 @@ static int await_return_path_close_on_source(MigrationState *ms) static int postcopy_start(MigrationState *ms, bool *old_vm_running) { int ret; - const QEMUSizedBuffer *qsb; + QIOChannelBuffer *bioc; + QEMUFile *fb; int64_t time_at_stop = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); migrate_set_state(&ms->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_POSTCOPY_ACTIVE); @@ -1507,11 +1509,9 @@ static int postcopy_start(MigrationState *ms, bool *old_vm_running) * So we wrap the device state up in a package with a length at the start; * to do this we use a qemu_buf to hold the whole of the device state. */ - QEMUFile *fb = qemu_bufopen("w", NULL); - if (!fb) { - error_report("Failed to create buffered file"); - goto fail; - } + bioc = qio_channel_buffer_new(4096); + fb = qemu_fopen_channel_output(QIO_CHANNEL(bioc)); + object_unref(OBJECT(bioc)); /* * Make sure the receiver can get incoming pages before we send the rest @@ -1525,10 +1525,9 @@ static int postcopy_start(MigrationState *ms, bool *old_vm_running) qemu_savevm_send_postcopy_run(fb); /* <><> end of stuff going into the package */ - qsb = qemu_buf_get(fb); /* Now send that blob */ - if (qemu_savevm_send_packaged(ms->to_dst_file, qsb)) { + if (qemu_savevm_send_packaged(ms->to_dst_file, bioc->data, bioc->usage)) { goto fail_closefb; } qemu_fclose(fb); diff --git a/migration/savevm.c b/migration/savevm.c index 16ba443..06746d0 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -50,6 +50,7 @@ #include "block/snapshot.h" #include "block/qapi.h" #include "qemu/cutils.h" +#include "io/channel-buffer.h" #ifndef ETH_P_RARP #define ETH_P_RARP 0x8035 @@ -759,10 +760,8 @@ void qemu_savevm_send_open_return_path(QEMUFile *f) * 0 on success * -ve on error */ -int qemu_savevm_send_packaged(QEMUFile *f, const QEMUSizedBuffer *qsb) +int qemu_savevm_send_packaged(QEMUFile *f, const uint8_t *buf, size_t len) { - size_t cur_iov; - size_t len = qsb_get_length(qsb); uint32_t tmp; if (len > MAX_VM_CMD_PACKAGED_SIZE) { @@ -776,18 +775,7 @@ int qemu_savevm_send_packaged(QEMUFile *f, const QEMUSizedBuffer *qsb) trace_qemu_savevm_send_packaged(); qemu_savevm_command_send(f, MIG_CMD_PACKAGED, 4, (uint8_t *)&tmp); - /* all the data follows (concatinating the iov's) */ - for (cur_iov = 0; cur_iov < qsb->n_iov; cur_iov++) { - /* The iov entries are partially filled */ - size_t towrite = MIN(qsb->iov[cur_iov].iov_len, len); - len -= towrite; - - if (!towrite) { - break; - } - - qemu_put_buffer(f, qsb->iov[cur_iov].iov_base, towrite); - } + qemu_put_buffer(f, buf, len); return 0; } @@ -1577,39 +1565,36 @@ static int loadvm_postcopy_handle_run(MigrationIncomingState *mis) static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis) { int ret; - uint8_t *buffer; - uint32_t length; - QEMUSizedBuffer *qsb; + size_t length; + QIOChannelBuffer *bioc; length = qemu_get_be32(mis->from_src_file); trace_loadvm_handle_cmd_packaged(length); if (length > MAX_VM_CMD_PACKAGED_SIZE) { - error_report("Unreasonably large packaged state: %u", length); + error_report("Unreasonably large packaged state: %zu", length); return -1; } - buffer = g_malloc0(length); - ret = qemu_get_buffer(mis->from_src_file, buffer, (int)length); + + bioc = qio_channel_buffer_new(length); + ret = qemu_get_buffer(mis->from_src_file, + bioc->data, + length); if (ret != length) { - g_free(buffer); - error_report("CMD_PACKAGED: Buffer receive fail ret=%d length=%d", + object_unref(OBJECT(bioc)); + error_report("CMD_PACKAGED: Buffer receive fail ret=%d length=%zu", ret, length); return (ret < 0) ? ret : -EAGAIN; } + bioc->usage += length; trace_loadvm_handle_cmd_packaged_received(ret); - /* Setup a dummy QEMUFile that actually reads from the buffer */ - qsb = qsb_create(buffer, length); - g_free(buffer); /* Because qsb_create copies */ - if (!qsb) { - error_report("Unable to create qsb"); - } - QEMUFile *packf = qemu_bufopen("r", qsb); + QEMUFile *packf = qemu_fopen_channel_input(QIO_CHANNEL(bioc)); ret = qemu_loadvm_state_main(packf, mis); trace_loadvm_handle_cmd_packaged_main(ret); qemu_fclose(packf); - qsb_free(qsb); + object_unref(OBJECT(bioc)); return ret; }