From patchwork Fri Nov 18 18:28:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 126463 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 411E7B7238 for ; Sat, 19 Nov 2011 05:26:24 +1100 (EST) Received: from localhost ([::1]:48888 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RRT8l-0006KO-G9 for incoming@patchwork.ozlabs.org; Fri, 18 Nov 2011 13:26:19 -0500 Received: from eggs.gnu.org ([140.186.70.92]:38248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RRT8Y-00068C-9n for qemu-devel@nongnu.org; Fri, 18 Nov 2011 13:26:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RRT8W-0006cE-Vb for qemu-devel@nongnu.org; Fri, 18 Nov 2011 13:26:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:6083) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RRT8W-0006c1-Ix for qemu-devel@nongnu.org; Fri, 18 Nov 2011 13:26:04 -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.14.4/8.14.4) with ESMTP id pAIIQ39k020478 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 18 Nov 2011 13:26:03 -0500 Received: from dhcp-5-188.str.redhat.com (vpn1-6-61.ams2.redhat.com [10.36.6.61]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id pAIIPuJZ031078; Fri, 18 Nov 2011 13:26:01 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 18 Nov 2011 19:28:59 +0100 Message-Id: <1321640945-9827-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1321640945-9827-1-git-send-email-kwolf@redhat.com> References: <1321640945-9827-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, stefanha@gmail.com Subject: [Qemu-devel] [PATCH v2 3/9] qcow2: Update snapshot table information at once 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 Failing in the middle wouldn't help with the integrity of the image, so doing everything in a single request seems better. Signed-off-by: Kevin Wolf --- block/qcow2-snapshot.c | 22 ++++++++++------------ 1 files changed, 10 insertions(+), 12 deletions(-) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index e91a286..1976df7 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -137,8 +137,10 @@ static int qcow2_write_snapshots(BlockDriverState *bs) QCowSnapshot *sn; QCowSnapshotHeader h; int i, name_size, id_str_size, snapshots_size; - uint64_t data64; - uint32_t data32; + struct { + uint32_t nb_snapshots; + uint64_t snapshots_offset; + } QEMU_PACKED header_data; int64_t offset, snapshots_offset; int ret; @@ -200,24 +202,20 @@ static int qcow2_write_snapshots(BlockDriverState *bs) /* * Update the header to point to the new snapshot table. This requires the * new table and its refcounts to be stable on disk. - * - * FIXME This should be done with a single write */ ret = bdrv_flush(bs); if (ret < 0) { goto fail; } - data64 = cpu_to_be64(snapshots_offset); - ret = bdrv_pwrite(bs->file, offsetof(QCowHeader, snapshots_offset), - &data64, sizeof(data64)); - if (ret < 0) { - goto fail; - } + QEMU_BUILD_BUG_ON(offsetof(QCowHeader, snapshots_offset) != + offsetof(QCowHeader, nb_snapshots) + sizeof(header_data.nb_snapshots)); + + header_data.nb_snapshots = cpu_to_be32(s->nb_snapshots); + header_data.snapshots_offset = cpu_to_be64(snapshots_offset); - data32 = cpu_to_be32(s->nb_snapshots); ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots), - &data32, sizeof(data32)); + &header_data, sizeof(header_data)); if (ret < 0) { goto fail; }