summaryrefslogtreecommitdiff
path: root/block/qcow2.h
diff options
context:
space:
mode:
authorMax Reitz <mreitz@redhat.com>2015-02-10 15:28:47 -0500
committerKevin Wolf <kwolf@redhat.com>2015-03-10 14:02:21 +0100
commit2aabe7c7a16cee6b1b54592fa05b5f9c23c89bc0 (patch)
treeda45f57f7fcd1a09b6e2835c04cd93ff95737a37 /block/qcow2.h
parent7324c10f96c821b00d691e2c8ced67d8536bf1d6 (diff)
downloadqemu-2aabe7c7a16cee6b1b54592fa05b5f9c23c89bc0.tar.gz
qcow2: Use unsigned addend for update_refcount()
update_refcount() and qcow2_update_cluster_refcount() currently take a signed addend. At least one caller passes a value directly derived from an absolute refcount that should be reached ("l2_refcount - 1" in expand_zero_clusters_in_l1()). Therefore, the addend should be unsigned as well; this will be especially important for 64 bit refcounts. Because update_refcount() then no longer knows whether the refcount should be increased or decreased, it now requires an additional flag which specified exactly that. The same applies to qcow2_update_cluster_refcount(). Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/qcow2.h')
-rw-r--r--block/qcow2.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/block/qcow2.h b/block/qcow2.h
index a33431f05a..40910d817d 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -459,6 +459,11 @@ static inline uint64_t l2meta_cow_end(QCowL2Meta *m)
+ (m->cow_end.nb_sectors << BDRV_SECTOR_BITS);
}
+static inline uint16_t refcount_diff(uint16_t r1, uint16_t r2)
+{
+ return r1 > r2 ? r1 - r2 : r2 - r1;
+}
+
// FIXME Need qcow2_ prefix to global functions
/* qcow2.c functions */
@@ -482,7 +487,8 @@ int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index,
uint16_t *refcount);
int qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index,
- int addend, enum qcow2_discard_type type);
+ uint16_t addend, bool decrease,
+ enum qcow2_discard_type type);
int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size);
int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,