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