thebeanogamer / rpms / qemu-kvm

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