From patchwork Tue Feb 12 09:37:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 219752 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B43AB2C031E for ; Tue, 12 Feb 2013 20:37:47 +1100 (EST) Received: from localhost ([::1]:38378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5CJ7-0005h0-Pf for incoming@patchwork.ozlabs.org; Tue, 12 Feb 2013 04:37:45 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59590) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5CIp-0005a3-1O for qemu-devel@nongnu.org; Tue, 12 Feb 2013 04:37:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U5CIl-0003a5-JG for qemu-devel@nongnu.org; Tue, 12 Feb 2013 04:37:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50560) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5CIl-0003Zt-D0 for qemu-devel@nongnu.org; Tue, 12 Feb 2013 04:37:23 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1C9bMbp010545 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 12 Feb 2013 04:37:22 -0500 Received: from localhost (ovpn-112-27.ams2.redhat.com [10.36.112.27]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r1C9bL6f030273; Tue, 12 Feb 2013 04:37:22 -0500 From: Stefan Hajnoczi To: Date: Tue, 12 Feb 2013 10:37:14 +0100 Message-Id: <1360661835-28663-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1360661835-28663-1-git-send-email-stefanha@redhat.com> References: <1360661835-28663-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Stefan Hajnoczi , Juan Quintela Subject: [Qemu-devel] [PATCH for-1.4 1/2] migration: make qemu_ftell() public and support writable files 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 Migration .save_live_iterate() functions return the number of bytes transferred. The easiest way of doing this is by calling qemu_ftell(f) at the beginning and end of the function to calculate the difference. Make qemu_ftell() public so that block-migration will be able to use it. Also adjust the ftell calculation for writable files where buf_offset does not include buf_size. Signed-off-by: Stefan Hajnoczi --- include/migration/qemu-file.h | 1 + savevm.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h index 68deefb..46fc11d 100644 --- a/include/migration/qemu-file.h +++ b/include/migration/qemu-file.h @@ -81,6 +81,7 @@ QEMUFile *qemu_popen(FILE *popen_file, const char *mode); QEMUFile *qemu_popen_cmd(const char *command, const char *mode); int qemu_get_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); +int64_t qemu_ftell(QEMUFile *f); void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); void qemu_put_byte(QEMUFile *f, int v); diff --git a/savevm.c b/savevm.c index 0b6724d..a8a53ef 100644 --- a/savevm.c +++ b/savevm.c @@ -673,9 +673,14 @@ int qemu_get_byte(QEMUFile *f) return result; } -static int64_t qemu_ftell(QEMUFile *f) +int64_t qemu_ftell(QEMUFile *f) { - return f->buf_offset - f->buf_size + f->buf_index; + /* buf_offset excludes buffer for writing but includes it for reading */ + if (f->is_write) { + return f->buf_offset + f->buf_index; + } else { + return f->buf_offset - f->buf_size + f->buf_index; + } } int qemu_file_rate_limit(QEMUFile *f)