9ae3a8
From e1547d9eea752dde38bee613afb5cfb7bb26f0f8 Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Tue, 25 Mar 2014 14:23:37 +0100
9ae3a8
Subject: [PATCH 30/49] qcow2: Fix types in qcow2_alloc_clusters and alloc_clusters_noref
9ae3a8
9ae3a8
RH-Author: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Message-id: <1395753835-7591-31-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: n/a
9ae3a8
O-Subject: [virt-devel] [EMBARGOED RHEL-7.0 qemu-kvm PATCH 30/48] qcow2: Fix types in qcow2_alloc_clusters and alloc_clusters_noref
9ae3a8
Bugzilla: 1066691
9ae3a8
RH-Acked-by: Jeff Cody <jcody@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
9ae3a8
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1066691
9ae3a8
Upstream status: Series embargoed
9ae3a8
9ae3a8
In order to avoid integer overflows.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
 block/qcow2-refcount.c |   11 ++++++-----
9ae3a8
 block/qcow2.h          |    6 +++---
9ae3a8
 2 files changed, 9 insertions(+), 8 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
9ae3a8
index 7b00dda..fb57c10 100644
9ae3a8
--- a/block/qcow2-refcount.c
9ae3a8
+++ b/block/qcow2-refcount.c
9ae3a8
@@ -28,7 +28,7 @@
9ae3a8
 #include "qemu/range.h"
9ae3a8
 #include "qapi/qmp/types.h"
9ae3a8
 
9ae3a8
-static int64_t alloc_clusters_noref(BlockDriverState *bs, int64_t size);
9ae3a8
+static int64_t alloc_clusters_noref(BlockDriverState *bs, uint64_t size);
9ae3a8
 static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
9ae3a8
                             int64_t offset, int64_t length,
9ae3a8
                             int addend, enum qcow2_discard_type type);
9ae3a8
@@ -634,15 +634,16 @@ int qcow2_update_cluster_refcount(BlockDriverState *bs,
9ae3a8
 
9ae3a8
 
9ae3a8
 /* return < 0 if error */
9ae3a8
-static int64_t alloc_clusters_noref(BlockDriverState *bs, int64_t size)
9ae3a8
+static int64_t alloc_clusters_noref(BlockDriverState *bs, uint64_t size)
9ae3a8
 {
9ae3a8
     BDRVQcowState *s = bs->opaque;
9ae3a8
-    int i, nb_clusters, refcount;
9ae3a8
+    uint64_t i, nb_clusters;
9ae3a8
+    int refcount;
9ae3a8
 
9ae3a8
     nb_clusters = size_to_clusters(s, size);
9ae3a8
 retry:
9ae3a8
     for(i = 0; i < nb_clusters; i++) {
9ae3a8
-        int64_t next_cluster_index = s->free_cluster_index++;
9ae3a8
+        uint64_t next_cluster_index = s->free_cluster_index++;
9ae3a8
         refcount = get_refcount(bs, next_cluster_index);
9ae3a8
 
9ae3a8
         if (refcount < 0) {
9ae3a8
@@ -659,7 +660,7 @@ retry:
9ae3a8
     return (s->free_cluster_index - nb_clusters) << s->cluster_bits;
9ae3a8
 }
9ae3a8
 
9ae3a8
-int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size)
9ae3a8
+int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size)
9ae3a8
 {
9ae3a8
     int64_t offset;
9ae3a8
     int ret;
9ae3a8
diff --git a/block/qcow2.h b/block/qcow2.h
9ae3a8
index 0173d95..9f9f5ae 100644
9ae3a8
--- a/block/qcow2.h
9ae3a8
+++ b/block/qcow2.h
9ae3a8
@@ -222,8 +222,8 @@ typedef struct BDRVQcowState {
9ae3a8
     uint64_t *refcount_table;
9ae3a8
     uint64_t refcount_table_offset;
9ae3a8
     uint32_t refcount_table_size;
9ae3a8
-    int64_t free_cluster_index;
9ae3a8
-    int64_t free_byte_offset;
9ae3a8
+    uint64_t free_cluster_index;
9ae3a8
+    uint64_t free_byte_offset;
9ae3a8
 
9ae3a8
     CoMutex lock;
9ae3a8
 
9ae3a8
@@ -462,7 +462,7 @@ void qcow2_refcount_close(BlockDriverState *bs);
9ae3a8
 int qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index,
9ae3a8
                                   int addend, enum qcow2_discard_type type);
9ae3a8
 
9ae3a8
-int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size);
9ae3a8
+int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size);
9ae3a8
 int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
9ae3a8
     int nb_clusters);
9ae3a8
 int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size);
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8