diff options
author | Max Reitz <mreitz@redhat.com> | 2014-10-22 14:09:37 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2014-10-23 15:34:01 +0200 |
commit | 9696df219a71c6608f058ade8873d6d0b4e352fe (patch) | |
tree | 38d3c0ca47e98015f145baaaf01e9ff16ca7d1f0 /block/qcow2-refcount.c | |
parent | 641bb63cd6b003ab0ca2e312a014449037d71647 (diff) |
qcow2: Reuse refcount table in calculate_refcounts()
We will later call calculate_refcounts multiple times, so reuse the
refcount table if possible.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: BenoƮt Canet <benoit.canet@nodalink.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/qcow2-refcount.c')
-rw-r--r-- | block/qcow2-refcount.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index d653124cf2..c92e1fc62c 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1661,10 +1661,12 @@ static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res, QCowSnapshot *sn; int ret; - *refcount_table = g_try_new0(uint16_t, *nb_clusters); - if (*nb_clusters && *refcount_table == NULL) { - res->check_errors++; - return -ENOMEM; + if (!*refcount_table) { + *refcount_table = g_try_new0(uint16_t, *nb_clusters); + if (*nb_clusters && *refcount_table == NULL) { + res->check_errors++; + return -ENOMEM; + } } /* header */ @@ -1780,7 +1782,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res, { BDRVQcowState *s = bs->opaque; int64_t size, highest_cluster, nb_clusters; - uint16_t *refcount_table; + uint16_t *refcount_table = NULL; int ret; size = bdrv_getlength(bs->file); |