qcow2-refcount: improve style of check_refcounts_l1()
- use g_autofree for l1_table - better name for size in bytes variable - reduce code blocks nesting - whitespaces, braces, newlines Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Message-Id: <20210914122454.141075-9-vsementsov@virtuozzo.com> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
This commit is contained in:
parent
289ef5f219
commit
cd6efd60e9
@ -1862,47 +1862,54 @@ static int check_refcounts_l1(BlockDriverState *bs,
|
|||||||
int flags, BdrvCheckMode fix, bool active)
|
int flags, BdrvCheckMode fix, bool active)
|
||||||
{
|
{
|
||||||
BDRVQcow2State *s = bs->opaque;
|
BDRVQcow2State *s = bs->opaque;
|
||||||
uint64_t *l1_table = NULL, l2_offset, l1_size2;
|
size_t l1_size_bytes = l1_size * L1E_SIZE;
|
||||||
|
g_autofree uint64_t *l1_table = NULL;
|
||||||
|
uint64_t l2_offset;
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
|
||||||
l1_size2 = l1_size * L1E_SIZE;
|
if (!l1_size) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Mark L1 table as used */
|
/* Mark L1 table as used */
|
||||||
ret = qcow2_inc_refcounts_imrt(bs, res, refcount_table, refcount_table_size,
|
ret = qcow2_inc_refcounts_imrt(bs, res, refcount_table, refcount_table_size,
|
||||||
l1_table_offset, l1_size2);
|
l1_table_offset, l1_size_bytes);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto fail;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
l1_table = g_try_malloc(l1_size_bytes);
|
||||||
|
if (l1_table == NULL) {
|
||||||
|
res->check_errors++;
|
||||||
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read L1 table entries from disk */
|
/* Read L1 table entries from disk */
|
||||||
if (l1_size2 > 0) {
|
ret = bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size_bytes);
|
||||||
l1_table = g_try_malloc(l1_size2);
|
|
||||||
if (l1_table == NULL) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
res->check_errors++;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
ret = bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size2);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "ERROR: I/O error in check_refcounts_l1\n");
|
fprintf(stderr, "ERROR: I/O error in check_refcounts_l1\n");
|
||||||
res->check_errors++;
|
res->check_errors++;
|
||||||
goto fail;
|
return ret;
|
||||||
}
|
}
|
||||||
for(i = 0;i < l1_size; i++)
|
|
||||||
|
for (i = 0; i < l1_size; i++) {
|
||||||
be64_to_cpus(&l1_table[i]);
|
be64_to_cpus(&l1_table[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do the actual checks */
|
/* Do the actual checks */
|
||||||
for (i = 0; i < l1_size; i++) {
|
for (i = 0; i < l1_size; i++) {
|
||||||
l2_offset = l1_table[i];
|
if (!l1_table[i]) {
|
||||||
if (l2_offset) {
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
l2_offset = l1_table[i] & L1E_OFFSET_MASK;
|
||||||
|
|
||||||
/* Mark L2 table as used */
|
/* Mark L2 table as used */
|
||||||
l2_offset &= L1E_OFFSET_MASK;
|
|
||||||
ret = qcow2_inc_refcounts_imrt(bs, res,
|
ret = qcow2_inc_refcounts_imrt(bs, res,
|
||||||
refcount_table, refcount_table_size,
|
refcount_table, refcount_table_size,
|
||||||
l2_offset, s->cluster_size);
|
l2_offset, s->cluster_size);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto fail;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* L2 tables are cluster aligned */
|
/* L2 tables are cluster aligned */
|
||||||
@ -1917,17 +1924,12 @@ static int check_refcounts_l1(BlockDriverState *bs,
|
|||||||
refcount_table_size, l2_offset, flags,
|
refcount_table_size, l2_offset, flags,
|
||||||
fix, active);
|
fix, active);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_free(l1_table);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
g_free(l1_table);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Checks the OFLAG_COPIED flag for all L1 and L2 entries.
|
* Checks the OFLAG_COPIED flag for all L1 and L2 entries.
|
||||||
|
Loading…
Reference in New Issue
Block a user