thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
26ba25
From 1041ad03a2c47f5bbae0b4c8089bab98ef1ba12d Mon Sep 17 00:00:00 2001
26ba25
From: Kevin Wolf <kwolf@redhat.com>
26ba25
Date: Thu, 6 Dec 2018 17:12:36 +0000
26ba25
Subject: [PATCH 11/15] qcow2: Resize the cache upon image resizing
26ba25
26ba25
RH-Author: Kevin Wolf <kwolf@redhat.com>
26ba25
Message-id: <20181206171240.5674-12-kwolf@redhat.com>
26ba25
Patchwork-id: 83293
26ba25
O-Subject: [RHEL-8.0 qemu-kvm PATCH 11/15] qcow2: Resize the cache upon image resizing
26ba25
Bugzilla: 1656507
26ba25
RH-Acked-by: Max Reitz <mreitz@redhat.com>
26ba25
RH-Acked-by: John Snow <jsnow@redhat.com>
26ba25
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
26ba25
From: Leonid Bloch <lbloch@janustech.com>
26ba25
26ba25
The caches are now recalculated upon image resizing. This is done
26ba25
because the new default behavior of assigning L2 cache relatively to
26ba25
the image size, implies that the cache will be adapted accordingly
26ba25
after an image resize.
26ba25
26ba25
Signed-off-by: Leonid Bloch <lbloch@janustech.com>
26ba25
Reviewed-by: Alberto Garcia <berto@igalia.com>
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
(cherry picked from commit 45b4949c7bcdcd998cb42f5c517e80a2657cfd33)
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 block/qcow2.c | 11 +++++++++++
26ba25
 1 file changed, 11 insertions(+)
26ba25
26ba25
diff --git a/block/qcow2.c b/block/qcow2.c
26ba25
index fc6bddd..72f1ea8 100644
26ba25
--- a/block/qcow2.c
26ba25
+++ b/block/qcow2.c
26ba25
@@ -3462,6 +3462,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
26ba25
     uint64_t old_length;
26ba25
     int64_t new_l1_size;
26ba25
     int ret;
26ba25
+    QDict *options;
26ba25
 
26ba25
     if (prealloc != PREALLOC_MODE_OFF && prealloc != PREALLOC_MODE_METADATA &&
26ba25
         prealloc != PREALLOC_MODE_FALLOC && prealloc != PREALLOC_MODE_FULL)
26ba25
@@ -3686,6 +3687,8 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
26ba25
         }
26ba25
     }
26ba25
 
26ba25
+    bs->total_sectors = offset / BDRV_SECTOR_SIZE;
26ba25
+
26ba25
     /* write updated header.size */
26ba25
     offset = cpu_to_be64(offset);
26ba25
     ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, size),
26ba25
@@ -3696,6 +3699,14 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
26ba25
     }
26ba25
 
26ba25
     s->l1_vm_state_index = new_l1_size;
26ba25
+
26ba25
+    /* Update cache sizes */
26ba25
+    options = qdict_clone_shallow(bs->options);
26ba25
+    ret = qcow2_update_options(bs, options, s->flags, errp);
26ba25
+    qobject_unref(options);
26ba25
+    if (ret < 0) {
26ba25
+        goto fail;
26ba25
+    }
26ba25
     ret = 0;
26ba25
 fail:
26ba25
     qemu_co_mutex_unlock(&s->lock);
26ba25
-- 
26ba25
1.8.3.1
26ba25