From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:46317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXZNH-0008Sh-Al for qemu-devel@nongnu.org; Mon, 05 Dec 2011 09:18:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RXZNA-0008Tl-G7 for qemu-devel@nongnu.org; Mon, 05 Dec 2011 09:18:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:63659) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXZNA-0008TN-8C for qemu-devel@nongnu.org; Mon, 05 Dec 2011 09:18:24 -0500 From: Kevin Wolf Date: Mon, 5 Dec 2011 15:20:50 +0100 Message-Id: <1323094878-7967-14-git-send-email-kwolf@redhat.com> In-Reply-To: <1323094878-7967-1-git-send-email-kwolf@redhat.com> References: <1323094878-7967-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 13/41] qcow2: Update snapshot table information at once List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@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 Reviewed-by: Stefan Hajnoczi --- 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; } -- 1.7.6.4