yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
218e99
From 7762468560c9a2283836a4abdde58301ad7fb1cf Mon Sep 17 00:00:00 2001
218e99
From: Fam Zheng <famz@redhat.com>
218e99
Date: Tue, 6 Aug 2013 15:44:54 +0800
218e99
Subject: [PATCH 08/13] vmdk: use heap allocation for whole_grain
218e99
218e99
Message-id: <1377573001-27070-9-git-send-email-famz@redhat.com>
218e99
Patchwork-id: 53788
218e99
O-Subject: [RHEL-7 qemu-kvm PATCH 08/13] vmdk: use heap allocation for
218e99
        whole_grain
218e99
Bugzilla: 995866
218e99
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
218e99
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
218e99
218e99
We should never grow the stack beyond 1 MB, otherwise we'll fall off the
218e99
end.  Thread stacks and coroutine stacks (1 MB) do not grow.
218e99
get_cluster_offset() allocates a big stack offset, it will fail for big
218e99
cluster images, change to heap allocated buffer.
218e99
218e99
Signed-off-by: Fam Zheng <famz@redhat.com>
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
(cherry picked from commit bf81507de38fdfa4cb6e9b46fb38691a25cb1499)
218e99
Signed-off-by: Fam Zheng <famz@redhat.com>
218e99
---
218e99
 block/vmdk.c |   21 +++++++++++++--------
218e99
 1 files changed, 13 insertions(+), 8 deletions(-)
218e99
218e99
diff --git a/block/vmdk.c b/block/vmdk.c
218e99
index 58163ef..1af6122 100644
218e99
--- a/block/vmdk.c
218e99
+++ b/block/vmdk.c
218e99
@@ -842,16 +842,17 @@ static int get_whole_cluster(BlockDriverState *bs,
218e99
                 uint64_t offset,
218e99
                 bool allocate)
218e99
 {
218e99
-    /* 128 sectors * 512 bytes each = grain size 64KB */
218e99
-    uint8_t  whole_grain[extent->cluster_sectors * 512];
218e99
+    int ret = VMDK_OK;
218e99
+    uint8_t *whole_grain = NULL;
218e99
 
218e99
     /* we will be here if it's first write on non-exist grain(cluster).
218e99
      * try to read from parent image, if exist */
218e99
     if (bs->backing_hd) {
218e99
-        int ret;
218e99
-
218e99
+        whole_grain =
218e99
+            qemu_blockalign(bs, extent->cluster_sectors << BDRV_SECTOR_BITS);
218e99
         if (!vmdk_is_cid_valid(bs)) {
218e99
-            return VMDK_ERROR;
218e99
+            ret = VMDK_ERROR;
218e99
+            goto exit;
218e99
         }
218e99
 
218e99
         /* floor offset to cluster */
218e99
@@ -859,17 +860,21 @@ static int get_whole_cluster(BlockDriverState *bs,
218e99
         ret = bdrv_read(bs->backing_hd, offset >> 9, whole_grain,
218e99
                 extent->cluster_sectors);
218e99
         if (ret < 0) {
218e99
-            return VMDK_ERROR;
218e99
+            ret = VMDK_ERROR;
218e99
+            goto exit;
218e99
         }
218e99
 
218e99
         /* Write grain only into the active image */
218e99
         ret = bdrv_write(extent->file, cluster_offset, whole_grain,
218e99
                 extent->cluster_sectors);
218e99
         if (ret < 0) {
218e99
-            return VMDK_ERROR;
218e99
+            ret = VMDK_ERROR;
218e99
+            goto exit;
218e99
         }
218e99
     }
218e99
-    return VMDK_OK;
218e99
+exit:
218e99
+    qemu_vfree(whole_grain);
218e99
+    return ret;
218e99
 }
218e99
 
218e99
 static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data)
218e99
-- 
218e99
1.7.1
218e99