From patchwork Wed Dec 2 11:36:35 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 39994 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1F1D9B7BEF for ; Wed, 2 Dec 2009 23:04:28 +1100 (EST) Received: from localhost ([127.0.0.1]:57556 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFnwX-0003CZ-5v for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2009 07:04:25 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NFnWZ-0005q2-2K for qemu-devel@nongnu.org; Wed, 02 Dec 2009 06:37:35 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NFnWU-0005oU-61 for qemu-devel@nongnu.org; Wed, 02 Dec 2009 06:37:34 -0500 Received: from [199.232.76.173] (port=50853 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFnWT-0005oB-Kp for qemu-devel@nongnu.org; Wed, 02 Dec 2009 06:37:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:28115) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NFnWT-0002B3-4s for qemu-devel@nongnu.org; Wed, 02 Dec 2009 06:37:29 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB2BbSbr029588 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 2 Dec 2009 06:37:28 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB2BbPrW004274; Wed, 2 Dec 2009 06:37:27 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 2 Dec 2009 12:36:35 +0100 Message-Id: <356d13f1e7112c6daa693a0d937b74adc7de8f93.1259753146.git.quintela@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Jan Kiszka Subject: [Qemu-devel] [PATCH 01/12] vmstate: Avoid seeking X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jan Kiszka Seeking on vmstate save/load does not work if the underlying file is a stream. We could try to make all QEMUFile* forward-seek-aware, but first attempts in this direction indicated that it's saner to convert the few qemu_fseek-on-vmstates users to plain reads/writes. This fixes various subtle vmstate corruptions where unused fields were involved. Signed-off-by: Jan Kiszka Signed-off-by: Juan Quintela --- savevm.c | 20 +++++++++++++++++--- 1 files changed, 17 insertions(+), 3 deletions(-) diff --git a/savevm.c b/savevm.c index 18c2e54..833bf3c 100644 --- a/savevm.c +++ b/savevm.c @@ -959,13 +959,27 @@ const VMStateInfo vmstate_info_buffer = { static int get_unused_buffer(QEMUFile *f, void *pv, size_t size) { - qemu_fseek(f, size, SEEK_CUR); - return 0; + uint8_t buf[1024]; + int block_len; + + while (size > 0) { + block_len = MIN(sizeof(buf), size); + size -= block_len; + qemu_get_buffer(f, buf, block_len); + } + return 0; } static void put_unused_buffer(QEMUFile *f, void *pv, size_t size) { - qemu_fseek(f, size, SEEK_CUR); + static const uint8_t buf[1024]; + int block_len; + + while (size > 0) { + block_len = MIN(sizeof(buf), size); + size -= block_len; + qemu_put_buffer(f, buf, block_len); + } } const VMStateInfo vmstate_info_unused_buffer = {