Skip to content

Commit 786c22d

Browse files
Vladimir Sementsov-OgievskiyXanClic
authored andcommitted
qcow2-refcount: improve style of check_refcounts_l2()
- don't use same name for size in bytes and in entries - use g_autofree for l2_table - add whitespace - fix block comment style Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]> Reviewed-by: Eric Blake <[email protected]> Reviewed-by: Hanna Reitz <[email protected]> Message-Id: <[email protected]> Signed-off-by: Hanna Reitz <[email protected]>
1 parent a1c6243 commit 786c22d

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

block/qcow2-refcount.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,23 +1601,22 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
16011601
int flags, BdrvCheckMode fix, bool active)
16021602
{
16031603
BDRVQcow2State *s = bs->opaque;
1604-
uint64_t *l2_table, l2_entry;
1604+
uint64_t l2_entry;
16051605
uint64_t next_contiguous_offset = 0;
1606-
int i, l2_size, nb_csectors, ret;
1606+
int i, nb_csectors, ret;
1607+
size_t l2_size_bytes = s->l2_size * l2_entry_size(s);
1608+
g_autofree uint64_t *l2_table = g_malloc(l2_size_bytes);
16071609

16081610
/* Read L2 table from disk */
1609-
l2_size = s->l2_size * l2_entry_size(s);
1610-
l2_table = g_malloc(l2_size);
1611-
1612-
ret = bdrv_pread(bs->file, l2_offset, l2_table, l2_size);
1611+
ret = bdrv_pread(bs->file, l2_offset, l2_table, l2_size_bytes);
16131612
if (ret < 0) {
16141613
fprintf(stderr, "ERROR: I/O error in check_refcounts_l2\n");
16151614
res->check_errors++;
1616-
goto fail;
1615+
return ret;
16171616
}
16181617

16191618
/* Do the actual checks */
1620-
for(i = 0; i < s->l2_size; i++) {
1619+
for (i = 0; i < s->l2_size; i++) {
16211620
l2_entry = get_l2_entry(s, l2_table, i);
16221621

16231622
switch (qcow2_get_cluster_type(bs, l2_entry)) {
@@ -1647,14 +1646,15 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
16471646
l2_entry & QCOW2_COMPRESSED_SECTOR_MASK,
16481647
nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE);
16491648
if (ret < 0) {
1650-
goto fail;
1649+
return ret;
16511650
}
16521651

16531652
if (flags & CHECK_FRAG_INFO) {
16541653
res->bfi.allocated_clusters++;
16551654
res->bfi.compressed_clusters++;
16561655

1657-
/* Compressed clusters are fragmented by nature. Since they
1656+
/*
1657+
* Compressed clusters are fragmented by nature. Since they
16581658
* take up sub-sector space but we only have sector granularity
16591659
* I/O we need to re-read the same sectors even for adjacent
16601660
* compressed clusters.
@@ -1700,9 +1700,11 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
17001700
if (ret < 0) {
17011701
fprintf(stderr, "ERROR: Overlap check failed\n");
17021702
res->check_errors++;
1703-
/* Something is seriously wrong, so abort checking
1704-
* this L2 table */
1705-
goto fail;
1703+
/*
1704+
* Something is seriously wrong, so abort checking
1705+
* this L2 table.
1706+
*/
1707+
return ret;
17061708
}
17071709

17081710
ret = bdrv_pwrite_sync(bs->file, l2e_offset,
@@ -1712,13 +1714,17 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
17121714
fprintf(stderr, "ERROR: Failed to overwrite L2 "
17131715
"table entry: %s\n", strerror(-ret));
17141716
res->check_errors++;
1715-
/* Do not abort, continue checking the rest of this
1716-
* L2 table's entries */
1717+
/*
1718+
* Do not abort, continue checking the rest of this
1719+
* L2 table's entries.
1720+
*/
17171721
} else {
17181722
res->corruptions--;
17191723
res->corruptions_fixed++;
1720-
/* Skip marking the cluster as used
1721-
* (it is unused now) */
1724+
/*
1725+
* Skip marking the cluster as used
1726+
* (it is unused now).
1727+
*/
17221728
continue;
17231729
}
17241730
}
@@ -1743,7 +1749,7 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
17431749
refcount_table_size,
17441750
offset, s->cluster_size);
17451751
if (ret < 0) {
1746-
goto fail;
1752+
return ret;
17471753
}
17481754
}
17491755
break;
@@ -1758,12 +1764,7 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
17581764
}
17591765
}
17601766

1761-
g_free(l2_table);
17621767
return 0;
1763-
1764-
fail:
1765-
g_free(l2_table);
1766-
return ret;
17671768
}
17681769

17691770
/*

0 commit comments

Comments
 (0)