From patchwork Fri Feb 15 17:47:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 220795 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 0A4582C008C for ; Sat, 16 Feb 2013 05:08:32 +1100 (EST) Received: from localhost ([::1]:44838 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6Phy-0001VM-Lo for incoming@patchwork.ozlabs.org; Fri, 15 Feb 2013 13:08:26 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6POz-0007Tu-MJ for qemu-devel@nongnu.org; Fri, 15 Feb 2013 12:48:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U6POv-0004Vk-GB for qemu-devel@nongnu.org; Fri, 15 Feb 2013 12:48:49 -0500 Received: from mail-ve0-f171.google.com ([209.85.128.171]:41197) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6POv-0004Vf-BY for qemu-devel@nongnu.org; Fri, 15 Feb 2013 12:48:45 -0500 Received: by mail-ve0-f171.google.com with SMTP id b10so3335350vea.30 for ; Fri, 15 Feb 2013 09:48:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=1WQlctIXZj0+l6KMEM1919DYi5SZCs/MWJFr/Bs0nEo=; b=UpYtczxn6My11jY3rwCdoISWWAHUxRHnSNnjduWjTjg2x2xYxRVDfmbw/Fl1VdXStz LFsVDRXwjW5Og2FedwkyodOx5n8d7jQuPKXwvQrLQbF17nGAbE4msOEkvPN0m8/4Bwdr L04H7v85adHHNHEU2xP4zOyRgk4JLxu48afBp7IWOF6jP08M1L8rDHXUagnYpZnoP3G6 Fk7c0sixLK+9IfAb6Y7cqQ2l0/ne9uZSh9XLZ/uoj3UP+5rnvSRkuVNqHHW9ehPwSGQI rSfnJqr5d4pcDHKORQrb/+yi+63S4O8BLvvVyAXxNpMTXcYkqPB1CSznPuflKht26YiB 4j/A== X-Received: by 10.58.19.232 with SMTP id i8mr4324085vee.53.1360950516685; Fri, 15 Feb 2013 09:48:36 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-179-137.ip50.fastwebnet.it. [93.34.179.137]) by mx.google.com with ESMTPS id yu12sm65402142vec.6.2013.02.15.09.48.34 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 15 Feb 2013 09:48:35 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 15 Feb 2013 18:47:05 +0100 Message-Id: <1360950433-17106-34-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1360950433-17106-1-git-send-email-pbonzini@redhat.com> References: <1360950433-17106-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.128.171 Cc: owasserm@redhat.com, chegu_vinod@hp.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH 33/41] qemu-file: simplify and export qemu_ftell 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 Force a flush when qemu_ftell is called. This simplifies the buffer magic (it also breaks qemu_ftell for input QEMUFiles, but we never use it). Signed-off-by: Paolo Bonzini Reviewed-by: Orit Wasserman Acked-by: Juan Quintela --- savevm.c | 20 ++++++++------------ 1 files changed, 8 insertions(+), 12 deletions(-) diff --git a/savevm.c b/savevm.c index b6cf415..e4dc01d 100644 --- a/savevm.c +++ b/savevm.c @@ -119,8 +119,8 @@ struct QEMUFile { void *opaque; int is_write; - int64_t buf_offset; /* start of buffer when writing, end of buffer - when reading */ + int64_t pos; /* start of buffer when writing, end of buffer + when reading */ int buf_index; int buf_size; /* 0 when writing */ uint8_t buf[IO_BUF_SIZE]; @@ -505,9 +505,9 @@ static void qemu_fflush(QEMUFile *f) return; } if (f->is_write && f->buf_index > 0) { - ret = f->ops->put_buffer(f->opaque, f->buf, f->buf_offset, f->buf_index); + ret = f->ops->put_buffer(f->opaque, f->buf, f->pos, f->buf_index); if (ret >= 0) { - f->buf_offset += f->buf_index; + f->pos += f->buf_index; } f->buf_index = 0; } @@ -534,11 +534,11 @@ static void qemu_fill_buffer(QEMUFile *f) f->buf_index = 0; f->buf_size = pending; - len = f->ops->get_buffer(f->opaque, f->buf + pending, f->buf_offset, + len = f->ops->get_buffer(f->opaque, f->buf + pending, f->pos, IO_BUF_SIZE - pending); if (len > 0) { f->buf_size += len; - f->buf_offset += len; + f->pos += len; } else if (len == 0) { qemu_file_set_error(f, -EIO); } else if (len != -EAGAIN) @@ -718,12 +718,8 @@ int qemu_get_byte(QEMUFile *f) int64_t qemu_ftell(QEMUFile *f) { - /* 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; - } + qemu_fflush(f); + return f->pos; } int qemu_file_rate_limit(QEMUFile *f)