Patchwork [v3,5/6] vmdk: store fields of VmdkMetaData in cpu endian

login
register
mail settings
Submitter Fam Zheng
Date April 24, 2013, 12:44 p.m.
Message ID <1366807475-26350-6-git-send-email-famz@redhat.com>
Download mbox | patch
Permalink /patch/239196/
State New
Headers show

Comments

Fam Zheng - April 24, 2013, 12:44 p.m.
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 <famz@redhat.com>
---
 block/vmdk.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Stefan Hajnoczi - April 25, 2013, 1:20 p.m.
On Wed, Apr 24, 2013 at 08:44:34PM +0800, Fam Zheng wrote:
> @@ -938,7 +938,7 @@ static int get_cluster_offset(BlockDriverState *bs,
>          }
>  
>          if (m_data) {
> -            m_data->offset = tmp;
> +            m_data->offset = *cluster_offset;

tmp can be dropped now:

-tmp = cpu_to_le32(*cluster_offset);
-l2_table[l2_index] = tmp;
+l2_table[l2_index] = cpu_to_le32(*cluster_offset);

Patch

diff --git a/block/vmdk.c b/block/vmdk.c
index 0463d3b..16e1417 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;
         }
     }
@@ -938,7 +938,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;