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>
This commit is contained in:
Max Reitz 2014-10-22 14:09:37 +02:00 committed by Kevin Wolf
parent 641bb63cd6
commit 9696df219a

View file

@ -1661,11 +1661,13 @@ static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
QCowSnapshot *sn;
int ret;
if (!*refcount_table) {
*refcount_table = g_try_new0(uint16_t, *nb_clusters);
if (*nb_clusters && *refcount_table == NULL) {
res->check_errors++;
return -ENOMEM;
}
}
/* header */
ret = inc_refcounts(bs, res, refcount_table, nb_clusters,
@ -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);