]> Git Repo - qemu.git/commitdiff
qcow2: Add two new fields to BDRVQcowState
authorMax Reitz <[email protected]>
Tue, 10 Feb 2015 20:28:43 +0000 (15:28 -0500)
committerKevin Wolf <[email protected]>
Tue, 10 Mar 2015 13:02:20 +0000 (14:02 +0100)
Add two new fields regarding refcount information (the bit width of
every entry and the maximum refcount value) to the BDRVQcowState.

Signed-off-by: Max Reitz <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
block/qcow2-refcount.c
block/qcow2.c
block/qcow2.h

index 9b80ca79ea68a4dbf0a3ab2ae84159b5c73dab91..e124a5418e981bc25866e8b4e122a3c176531efc 100644 (file)
@@ -584,7 +584,7 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
 
         refcount = be16_to_cpu(refcount_block[block_index]);
         refcount += addend;
-        if (refcount < 0 || refcount > 0xffff) {
+        if (refcount < 0 || refcount > s->refcount_max) {
             ret = -EINVAL;
             goto fail;
         }
@@ -775,7 +775,7 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size)
             return refcount;
         }
 
-        if (refcount == 0xffff) {
+        if (refcount == s->refcount_max) {
             offset = 0;
         }
     }
index 50e0a947dfa6843da9080043520773b936389a6e..e04ba6d56e01471afdf7f3a5297335c2a2fd2d5f 100644 (file)
@@ -684,6 +684,9 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
         goto fail;
     }
     s->refcount_order = header.refcount_order;
+    s->refcount_bits = 1 << s->refcount_order;
+    s->refcount_max = UINT64_C(1) << (s->refcount_bits - 1);
+    s->refcount_max += s->refcount_max - 1;
 
     if (header.crypt_method > QCOW_CRYPT_AES) {
         error_setg(errp, "Unsupported encryption method: %" PRIu32,
index 0fee29bb5e7fa9e64d59913ce46aa16f098620df..55138c9d92036af7ab05619685cd36106ae74950 100644 (file)
@@ -258,6 +258,8 @@ typedef struct BDRVQcowState {
     int qcow_version;
     bool use_lazy_refcounts;
     int refcount_order;
+    int refcount_bits;
+    uint64_t refcount_max;
 
     bool discard_passthrough[QCOW2_DISCARD_MAX];
 
This page took 0.036486 seconds and 4 git commands to generate.