]> Git Repo - qemu.git/commitdiff
qcow2: Don't round the L1 table allocation up to the sector size
authorAlberto Garcia <[email protected]>
Sat, 18 Jan 2020 19:09:26 +0000 (20:09 +0100)
committerMax Reitz <[email protected]>
Thu, 6 Feb 2020 12:47:45 +0000 (13:47 +0100)
The L1 table is read from disk using the byte-based bdrv_pread() and
is never accessed beyond its last element, so there's no need to
allocate more memory than that.

Signed-off-by: Alberto Garcia <[email protected]>
Reviewed-by: Max Reitz <[email protected]>
Message-id: b2e27214ec7b03a585931bcf383ee1ac3a641a10.1579374329[email protected]
Signed-off-by: Max Reitz <[email protected]>
block/qcow2-cluster.c
block/qcow2-refcount.c
block/qcow2-snapshot.c
block/qcow2.c

index e9431f678509a84f94c099df870d265c8ede3db1..0384fb233981375d4f6e4dc0499c99df6026af35 100644 (file)
@@ -124,12 +124,11 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
 #endif
 
     new_l1_size2 = sizeof(uint64_t) * new_l1_size;
-    new_l1_table = qemu_try_blockalign(bs->file->bs,
-                                       ROUND_UP(new_l1_size2, 512));
+    new_l1_table = qemu_try_blockalign(bs->file->bs, new_l1_size2);
     if (new_l1_table == NULL) {
         return -ENOMEM;
     }
-    memset(new_l1_table, 0, ROUND_UP(new_l1_size2, 512));
+    memset(new_l1_table, 0, new_l1_size2);
 
     if (s->l1_size) {
         memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t));
index f67ac6b2d8930f9354ffa41ab00b4c06e8cc6281..c963bc8de1869487e4c5dc90843d92efea4ba14c 100644 (file)
@@ -1262,7 +1262,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
      * l1_table_offset when it is the current s->l1_table_offset! Be careful
      * when changing this! */
     if (l1_table_offset != s->l1_table_offset) {
-        l1_table = g_try_malloc0(ROUND_UP(l1_size2, 512));
+        l1_table = g_try_malloc0(l1_size2);
         if (l1_size2 && l1_table == NULL) {
             ret = -ENOMEM;
             goto fail;
index 5ab64da1ec36163ddfdca182bed17a40904f1aad..82c32d4c9b08606185415f4fcda8ffd09e47b7b3 100644 (file)
@@ -1024,8 +1024,7 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs,
         return ret;
     }
     new_l1_bytes = sn->l1_size * sizeof(uint64_t);
-    new_l1_table = qemu_try_blockalign(bs->file->bs,
-                                       ROUND_UP(new_l1_bytes, 512));
+    new_l1_table = qemu_try_blockalign(bs->file->bs, new_l1_bytes);
     if (new_l1_table == NULL) {
         return -ENOMEM;
     }
index e29fc0706815fbcc2754f8b62a9de8e59c13888e..83db01381484220d83b6be194d294d5e4836a8f5 100644 (file)
@@ -1491,7 +1491,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
 
     if (s->l1_size > 0) {
         s->l1_table = qemu_try_blockalign(bs->file->bs,
-            ROUND_UP(s->l1_size * sizeof(uint64_t), 512));
+                                          s->l1_size * sizeof(uint64_t));
         if (s->l1_table == NULL) {
             error_setg(errp, "Could not allocate L1 table");
             ret = -ENOMEM;
This page took 0.042511 seconds and 4 git commands to generate.