qcow2: Add errp to rebuild_refcount_structure()
Instead of fprint()-ing error messages in rebuild_refcount_structure() and its rebuild_refcounts_write_refblocks() helper, pass them through an Error object to qcow2_check_refcounts() (which will then print it). Suggested-by: Eric Blake <eblake@redhat.com> Signed-off-by: Hanna Reitz <hreitz@redhat.com> Message-Id: <20220405134652.19278-4-hreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
9ffd6d646d
commit
0423f75351
@ -2465,7 +2465,8 @@ static int64_t alloc_clusters_imrt(BlockDriverState *bs,
|
|||||||
static int rebuild_refcounts_write_refblocks(
|
static int rebuild_refcounts_write_refblocks(
|
||||||
BlockDriverState *bs, void **refcount_table, int64_t *nb_clusters,
|
BlockDriverState *bs, void **refcount_table, int64_t *nb_clusters,
|
||||||
int64_t first_cluster, int64_t end_cluster,
|
int64_t first_cluster, int64_t end_cluster,
|
||||||
uint64_t **on_disk_reftable_ptr, uint32_t *on_disk_reftable_entries_ptr
|
uint64_t **on_disk_reftable_ptr, uint32_t *on_disk_reftable_entries_ptr,
|
||||||
|
Error **errp
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BDRVQcow2State *s = bs->opaque;
|
BDRVQcow2State *s = bs->opaque;
|
||||||
@ -2516,8 +2517,8 @@ static int rebuild_refcounts_write_refblocks(
|
|||||||
nb_clusters,
|
nb_clusters,
|
||||||
&first_free_cluster);
|
&first_free_cluster);
|
||||||
if (refblock_offset < 0) {
|
if (refblock_offset < 0) {
|
||||||
fprintf(stderr, "ERROR allocating refblock: %s\n",
|
error_setg_errno(errp, -refblock_offset,
|
||||||
strerror(-refblock_offset));
|
"ERROR allocating refblock");
|
||||||
return refblock_offset;
|
return refblock_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2539,6 +2540,7 @@ static int rebuild_refcounts_write_refblocks(
|
|||||||
on_disk_reftable_entries *
|
on_disk_reftable_entries *
|
||||||
REFTABLE_ENTRY_SIZE);
|
REFTABLE_ENTRY_SIZE);
|
||||||
if (!on_disk_reftable) {
|
if (!on_disk_reftable) {
|
||||||
|
error_setg(errp, "ERROR allocating reftable memory");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2562,7 +2564,7 @@ static int rebuild_refcounts_write_refblocks(
|
|||||||
ret = qcow2_pre_write_overlap_check(bs, 0, refblock_offset,
|
ret = qcow2_pre_write_overlap_check(bs, 0, refblock_offset,
|
||||||
s->cluster_size, false);
|
s->cluster_size, false);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "ERROR writing refblock: %s\n", strerror(-ret));
|
error_setg_errno(errp, -ret, "ERROR writing refblock");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2578,7 +2580,7 @@ static int rebuild_refcounts_write_refblocks(
|
|||||||
ret = bdrv_pwrite(bs->file, refblock_offset, on_disk_refblock,
|
ret = bdrv_pwrite(bs->file, refblock_offset, on_disk_refblock,
|
||||||
s->cluster_size);
|
s->cluster_size);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "ERROR writing refblock: %s\n", strerror(-ret));
|
error_setg_errno(errp, -ret, "ERROR writing refblock");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2601,7 +2603,8 @@ static int rebuild_refcounts_write_refblocks(
|
|||||||
static int rebuild_refcount_structure(BlockDriverState *bs,
|
static int rebuild_refcount_structure(BlockDriverState *bs,
|
||||||
BdrvCheckResult *res,
|
BdrvCheckResult *res,
|
||||||
void **refcount_table,
|
void **refcount_table,
|
||||||
int64_t *nb_clusters)
|
int64_t *nb_clusters,
|
||||||
|
Error **errp)
|
||||||
{
|
{
|
||||||
BDRVQcow2State *s = bs->opaque;
|
BDRVQcow2State *s = bs->opaque;
|
||||||
int64_t reftable_offset = -1;
|
int64_t reftable_offset = -1;
|
||||||
@ -2652,7 +2655,7 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
|
|||||||
rebuild_refcounts_write_refblocks(bs, refcount_table, nb_clusters,
|
rebuild_refcounts_write_refblocks(bs, refcount_table, nb_clusters,
|
||||||
0, *nb_clusters,
|
0, *nb_clusters,
|
||||||
&on_disk_reftable,
|
&on_disk_reftable,
|
||||||
&on_disk_reftable_entries);
|
&on_disk_reftable_entries, errp);
|
||||||
if (reftable_size_changed < 0) {
|
if (reftable_size_changed < 0) {
|
||||||
res->check_errors++;
|
res->check_errors++;
|
||||||
ret = reftable_size_changed;
|
ret = reftable_size_changed;
|
||||||
@ -2676,8 +2679,8 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
|
|||||||
refcount_table, nb_clusters,
|
refcount_table, nb_clusters,
|
||||||
&first_free_cluster);
|
&first_free_cluster);
|
||||||
if (reftable_offset < 0) {
|
if (reftable_offset < 0) {
|
||||||
fprintf(stderr, "ERROR allocating reftable: %s\n",
|
error_setg_errno(errp, -reftable_offset,
|
||||||
strerror(-reftable_offset));
|
"ERROR allocating reftable");
|
||||||
res->check_errors++;
|
res->check_errors++;
|
||||||
ret = reftable_offset;
|
ret = reftable_offset;
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -2695,7 +2698,7 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
|
|||||||
reftable_start_cluster,
|
reftable_start_cluster,
|
||||||
reftable_end_cluster,
|
reftable_end_cluster,
|
||||||
&on_disk_reftable,
|
&on_disk_reftable,
|
||||||
&on_disk_reftable_entries);
|
&on_disk_reftable_entries, errp);
|
||||||
if (reftable_size_changed < 0) {
|
if (reftable_size_changed < 0) {
|
||||||
res->check_errors++;
|
res->check_errors++;
|
||||||
ret = reftable_size_changed;
|
ret = reftable_size_changed;
|
||||||
@ -2725,7 +2728,7 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
|
|||||||
ret = qcow2_pre_write_overlap_check(bs, 0, reftable_offset, reftable_length,
|
ret = qcow2_pre_write_overlap_check(bs, 0, reftable_offset, reftable_length,
|
||||||
false);
|
false);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "ERROR writing reftable: %s\n", strerror(-ret));
|
error_setg_errno(errp, -ret, "ERROR writing reftable");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2733,7 +2736,7 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
|
|||||||
ret = bdrv_pwrite(bs->file, reftable_offset, on_disk_reftable,
|
ret = bdrv_pwrite(bs->file, reftable_offset, on_disk_reftable,
|
||||||
reftable_length);
|
reftable_length);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "ERROR writing reftable: %s\n", strerror(-ret));
|
error_setg_errno(errp, -ret, "ERROR writing reftable");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2746,7 +2749,7 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
|
|||||||
&reftable_offset_and_clusters,
|
&reftable_offset_and_clusters,
|
||||||
sizeof(reftable_offset_and_clusters));
|
sizeof(reftable_offset_and_clusters));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "ERROR setting reftable: %s\n", strerror(-ret));
|
error_setg_errno(errp, -ret, "ERROR setting reftable");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2814,11 +2817,13 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
|
|||||||
if (rebuild && (fix & BDRV_FIX_ERRORS)) {
|
if (rebuild && (fix & BDRV_FIX_ERRORS)) {
|
||||||
BdrvCheckResult old_res = *res;
|
BdrvCheckResult old_res = *res;
|
||||||
int fresh_leaks = 0;
|
int fresh_leaks = 0;
|
||||||
|
Error *local_err = NULL;
|
||||||
|
|
||||||
fprintf(stderr, "Rebuilding refcount structure\n");
|
fprintf(stderr, "Rebuilding refcount structure\n");
|
||||||
ret = rebuild_refcount_structure(bs, res, &refcount_table,
|
ret = rebuild_refcount_structure(bs, res, &refcount_table,
|
||||||
&nb_clusters);
|
&nb_clusters, &local_err);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
error_report_err(local_err);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user