thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
05bba0
From 0b47923f65c2e457bb642b949f0e3dda722eba35 Mon Sep 17 00:00:00 2001
05bba0
From: Max Reitz <mreitz@redhat.com>
05bba0
Date: Sat, 13 Jun 2015 16:22:26 +0200
05bba0
Subject: [PATCH 32/42] qcow2: Drop REFCOUNT_SHIFT
05bba0
05bba0
Message-id: <1434212556-3927-33-git-send-email-mreitz@redhat.com>
05bba0
Patchwork-id: 66051
05bba0
O-Subject: [RHEL-7.2 qemu-kvm PATCH 32/42] qcow2: Drop REFCOUNT_SHIFT
05bba0
Bugzilla: 1129893
05bba0
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
05bba0
RH-Acked-by: Fam Zheng <famz@redhat.com>
05bba0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
05bba0
05bba0
BZ: 1129893
05bba0
05bba0
With BDRVQcowState.refcount_block_bits, we don't need REFCOUNT_SHIFT
05bba0
anymore.
05bba0
05bba0
Signed-off-by: Max Reitz <mreitz@redhat.com>
05bba0
Reviewed-by: Eric Blake <eblake@redhat.com>
05bba0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
05bba0
(cherry picked from commit 17bd5f472754acd2458b53dc02a30d5651e6dd79)
05bba0
05bba0
Signed-off-by: Max Reitz <mreitz@redhat.com>
05bba0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
---
05bba0
 block/qcow2-refcount.c | 32 ++++++++++++++------------------
05bba0
 block/qcow2.c          |  2 +-
05bba0
 block/qcow2.h          |  2 --
05bba0
 3 files changed, 15 insertions(+), 21 deletions(-)
05bba0
05bba0
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
05bba0
index fe36bbd..87b932c 100644
05bba0
--- a/block/qcow2-refcount.c
05bba0
+++ b/block/qcow2-refcount.c
05bba0
@@ -94,7 +94,7 @@ static int get_refcount(BlockDriverState *bs, int64_t cluster_index)
05bba0
     uint16_t *refcount_block;
05bba0
     uint16_t refcount;
05bba0
 
05bba0
-    refcount_table_index = cluster_index >> (s->cluster_bits - REFCOUNT_SHIFT);
05bba0
+    refcount_table_index = cluster_index >> s->refcount_block_bits;
05bba0
     if (refcount_table_index >= s->refcount_table_size)
05bba0
         return 0;
05bba0
     refcount_block_offset = s->refcount_table[refcount_table_index];
05bba0
@@ -114,8 +114,7 @@ static int get_refcount(BlockDriverState *bs, int64_t cluster_index)
05bba0
         return ret;
05bba0
     }
05bba0
 
05bba0
-    block_index = cluster_index &
05bba0
-        ((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1);
05bba0
+    block_index = cluster_index & (s->refcount_block_size - 1);
05bba0
     refcount = be16_to_cpu(refcount_block[block_index]);
05bba0
 
05bba0
     ret = qcow2_cache_put(bs, s->refcount_block_cache,
05bba0
@@ -150,8 +149,8 @@ static unsigned int next_refcount_table_size(BDRVQcowState *s,
05bba0
 static int in_same_refcount_block(BDRVQcowState *s, uint64_t offset_a,
05bba0
     uint64_t offset_b)
05bba0
 {
05bba0
-    uint64_t block_a = offset_a >> (2 * s->cluster_bits - REFCOUNT_SHIFT);
05bba0
-    uint64_t block_b = offset_b >> (2 * s->cluster_bits - REFCOUNT_SHIFT);
05bba0
+    uint64_t block_a = offset_a >> (s->cluster_bits + s->refcount_block_bits);
05bba0
+    uint64_t block_b = offset_b >> (s->cluster_bits + s->refcount_block_bits);
05bba0
 
05bba0
     return (block_a == block_b);
05bba0
 }
05bba0
@@ -172,7 +171,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
05bba0
     BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC);
05bba0
 
05bba0
     /* Find the refcount block for the given cluster */
05bba0
-    refcount_table_index = cluster_index >> (s->cluster_bits - REFCOUNT_SHIFT);
05bba0
+    refcount_table_index = cluster_index >> s->refcount_block_bits;
05bba0
 
05bba0
     if (refcount_table_index < s->refcount_table_size) {
05bba0
 
05bba0
@@ -249,7 +248,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
05bba0
 
05bba0
         /* The block describes itself, need to update the cache */
05bba0
         int block_index = (new_block >> s->cluster_bits) &
05bba0
-            ((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1);
05bba0
+            (s->refcount_block_size - 1);
05bba0
         (*refcount_block)[block_index] = cpu_to_be16(1);
05bba0
     } else {
05bba0
         /* Described somewhere else. This can recurse at most twice before we
05bba0
@@ -321,8 +320,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
05bba0
     BLKDBG_EVENT(bs->file, BLKDBG_REFTABLE_GROW);
05bba0
 
05bba0
     /* Calculate the number of refcount blocks needed so far */
05bba0
-    uint64_t refcount_block_clusters = 1 << (s->cluster_bits - REFCOUNT_SHIFT);
05bba0
-    uint64_t blocks_used = DIV_ROUND_UP(cluster_index, refcount_block_clusters);
05bba0
+    uint64_t blocks_used = DIV_ROUND_UP(cluster_index, s->refcount_block_size);
05bba0
 
05bba0
     if (blocks_used > QCOW_MAX_REFTABLE_SIZE / sizeof(uint64_t)) {
05bba0
         return -EFBIG;
05bba0
@@ -336,14 +334,14 @@ static int alloc_refcount_block(BlockDriverState *bs,
05bba0
         uint64_t table_clusters =
05bba0
             size_to_clusters(s, table_size * sizeof(uint64_t));
05bba0
         blocks_clusters = 1 +
05bba0
-            ((table_clusters + refcount_block_clusters - 1)
05bba0
-            / refcount_block_clusters);
05bba0
+            ((table_clusters + s->refcount_block_size - 1)
05bba0
+            / s->refcount_block_size);
05bba0
         uint64_t meta_clusters = table_clusters + blocks_clusters;
05bba0
 
05bba0
         last_table_size = table_size;
05bba0
         table_size = next_refcount_table_size(s, blocks_used +
05bba0
-            ((meta_clusters + refcount_block_clusters - 1)
05bba0
-            / refcount_block_clusters));
05bba0
+            ((meta_clusters + s->refcount_block_size - 1)
05bba0
+            / s->refcount_block_size));
05bba0
 
05bba0
     } while (last_table_size != table_size);
05bba0
 
05bba0
@@ -353,7 +351,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
05bba0
 #endif
05bba0
 
05bba0
     /* Create the new refcount table and blocks */
05bba0
-    uint64_t meta_offset = (blocks_used * refcount_block_clusters) *
05bba0
+    uint64_t meta_offset = (blocks_used * s->refcount_block_size) *
05bba0
         s->cluster_size;
05bba0
     uint64_t table_offset = meta_offset + blocks_clusters * s->cluster_size;
05bba0
     uint16_t *new_blocks = g_malloc0(blocks_clusters * s->cluster_size);
05bba0
@@ -545,8 +543,7 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
05bba0
     {
05bba0
         int block_index, refcount;
05bba0
         int64_t cluster_index = cluster_offset >> s->cluster_bits;
05bba0
-        int64_t table_index =
05bba0
-            cluster_index >> (s->cluster_bits - REFCOUNT_SHIFT);
05bba0
+        int64_t table_index = cluster_index >> s->refcount_block_bits;
05bba0
 
05bba0
         /* Load the refcount block and allocate it if needed */
05bba0
         if (table_index != old_table_index) {
05bba0
@@ -568,8 +565,7 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
05bba0
         qcow2_cache_entry_mark_dirty(s->refcount_block_cache, refcount_block);
05bba0
 
05bba0
         /* we can update the count and save it */
05bba0
-        block_index = cluster_index &
05bba0
-            ((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1);
05bba0
+        block_index = cluster_index & (s->refcount_block_size - 1);
05bba0
 
05bba0
         refcount = be16_to_cpu(refcount_block[block_index]);
05bba0
         refcount += addend;
05bba0
diff --git a/block/qcow2.c b/block/qcow2.c
05bba0
index 6c3c6bc..4e60077 100644
05bba0
--- a/block/qcow2.c
05bba0
+++ b/block/qcow2.c
05bba0
@@ -1678,7 +1678,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
05bba0
         .l1_size                    = cpu_to_be32(0),
05bba0
         .refcount_table_offset      = cpu_to_be64(cluster_size),
05bba0
         .refcount_table_clusters    = cpu_to_be32(1),
05bba0
-        .refcount_order             = cpu_to_be32(3 + REFCOUNT_SHIFT),
05bba0
+        .refcount_order             = cpu_to_be32(4),
05bba0
         .header_length              = cpu_to_be32(sizeof(*header)),
05bba0
     };
05bba0
 
05bba0
diff --git a/block/qcow2.h b/block/qcow2.h
05bba0
index b65f629..b210a7f 100644
05bba0
--- a/block/qcow2.h
05bba0
+++ b/block/qcow2.h
05bba0
@@ -59,8 +59,6 @@
05bba0
 /* The cluster reads as all zeros */
05bba0
 #define QCOW_OFLAG_ZERO (1LL << 0)
05bba0
 
05bba0
-#define REFCOUNT_SHIFT 1 /* refcount size is 2 bytes */
05bba0
-
05bba0
 #define MIN_CLUSTER_BITS 9
05bba0
 #define MAX_CLUSTER_BITS 21
05bba0
 
05bba0
-- 
05bba0
1.8.3.1
05bba0