From patchwork Fri May 3 11:52:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 241296 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 6D2002C00D0 for ; Fri, 3 May 2013 22:19:53 +1000 (EST) Received: from localhost ([::1]:57720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYEdp-0003xz-TO for incoming@patchwork.ozlabs.org; Fri, 03 May 2013 07:59:09 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYEYH-0003W9-KN for qemu-devel@nongnu.org; Fri, 03 May 2013 07:53:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UYEYE-000136-TK for qemu-devel@nongnu.org; Fri, 03 May 2013 07:53:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34134) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYEYE-00012r-Ku for qemu-devel@nongnu.org; Fri, 03 May 2013 07:53:22 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r43BrM8E015377 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 May 2013 07:53:22 -0400 Received: from localhost (ovpn-112-30.ams2.redhat.com [10.36.112.30]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r43BrKlM022739; Fri, 3 May 2013 07:53:21 -0400 From: Stefan Hajnoczi To: Date: Fri, 3 May 2013 13:52:47 +0200 Message-Id: <1367581972-4208-11-git-send-email-stefanha@redhat.com> In-Reply-To: <1367581972-4208-1-git-send-email-stefanha@redhat.com> References: <1367581972-4208-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Fam Zheng , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 10/15] vmdk: store fields of VmdkMetaData in cpu endian 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 From: Fam Zheng Previously VmdkMetaData.offset is stored little endian while other fields are cpu endian. This changes offset to cpu endian and convert before writing to image. Signed-off-by: Fam Zheng Signed-off-by: Stefan Hajnoczi --- block/vmdk.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 0463d3b..d98f304 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -813,14 +813,15 @@ static int get_whole_cluster(BlockDriverState *bs, static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data) { + uint32_t offset; + QEMU_BUILD_BUG_ON(sizeof(offset) != sizeof(m_data->offset)); + offset = cpu_to_le32(m_data->offset); /* update L2 table */ if (bdrv_pwrite_sync( extent->file, ((int64_t)m_data->l2_offset * 512) + (m_data->l2_index * sizeof(m_data->offset)), - &(m_data->offset), - sizeof(m_data->offset) - ) < 0) { + &offset, sizeof(offset)) < 0) { return VMDK_ERROR; } /* update backup L2 table */ @@ -830,8 +831,7 @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data) extent->file, ((int64_t)m_data->l2_offset * 512) + (m_data->l2_index * sizeof(m_data->offset)), - &(m_data->offset), sizeof(m_data->offset) - ) < 0) { + &offset, sizeof(offset)) < 0) { return VMDK_ERROR; } } @@ -848,7 +848,7 @@ static int get_cluster_offset(BlockDriverState *bs, { unsigned int l1_index, l2_offset, l2_index; int min_index, i, j; - uint32_t min_count, *l2_table, tmp = 0; + uint32_t min_count, *l2_table; bool zeroed = false; if (m_data) { @@ -924,8 +924,7 @@ static int get_cluster_offset(BlockDriverState *bs, } *cluster_offset >>= 9; - tmp = cpu_to_le32(*cluster_offset); - l2_table[l2_index] = tmp; + l2_table[l2_index] = cpu_to_le32(*cluster_offset); /* First of all we write grain itself, to avoid race condition * that may to corrupt the image. @@ -938,7 +937,7 @@ static int get_cluster_offset(BlockDriverState *bs, } if (m_data) { - m_data->offset = tmp; + m_data->offset = *cluster_offset; m_data->l1_index = l1_index; m_data->l2_index = l2_index; m_data->l2_offset = l2_offset;