Message ID | 1408725104-17176-5-git-send-email-mreitz@redhat.com |
---|---|
State | New |
Headers | show |
On Fri, Aug 22, 2014 at 06:31:38PM +0200, Max Reitz wrote: > We will later call calculate_refcounts multiple times, so reuse the > refcount table if possible. > > Signed-off-by: Max Reitz <mreitz@redhat.com> > --- > block/qcow2-refcount.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c > index 2b728ef..babe6cb 100644 > --- a/block/qcow2-refcount.c > +++ b/block/qcow2-refcount.c > @@ -1584,10 +1584,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 */ > @@ -1694,7 +1696,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); > -- > 2.0.4 > Reviewed-by: Benoît Canet <benoit.canet@nodalink.com>
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 2b728ef..babe6cb 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1584,10 +1584,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 */ @@ -1694,7 +1696,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);
We will later call calculate_refcounts multiple times, so reuse the refcount table if possible. Signed-off-by: Max Reitz <mreitz@redhat.com> --- block/qcow2-refcount.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)