|
|
1be5c7 |
From 552e7c8ae2c6e281a72791aefa1729be86f96642 Mon Sep 17 00:00:00 2001
|
|
|
1be5c7 |
From: Hanna Reitz <hreitz@redhat.com>
|
|
|
1be5c7 |
Date: Tue, 5 Apr 2022 15:46:52 +0200
|
|
|
1be5c7 |
Subject: [PATCH 5/6] qcow2: Add errp to rebuild_refcount_structure()
|
|
|
1be5c7 |
|
|
|
1be5c7 |
RH-Author: Hanna Reitz <hreitz@redhat.com>
|
|
|
1be5c7 |
RH-MergeRequest: 171: qcow2: Improve refcount structure rebuilding
|
|
|
1be5c7 |
RH-Commit: [3/4] 9dddd1d21383c4cbd528e5a0d42b0c2a7d87c8f6
|
|
|
1be5c7 |
RH-Bugzilla: 1519071
|
|
|
1be5c7 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
1be5c7 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
1be5c7 |
RH-Acked-by: Eric Blake <eblake@redhat.com>
|
|
|
1be5c7 |
|
|
|
1be5c7 |
Instead of fprint()-ing error messages in rebuild_refcount_structure()
|
|
|
1be5c7 |
and its rebuild_refcounts_write_refblocks() helper, pass them through an
|
|
|
1be5c7 |
Error object to qcow2_check_refcounts() (which will then print it).
|
|
|
1be5c7 |
|
|
|
1be5c7 |
Suggested-by: Eric Blake <eblake@redhat.com>
|
|
|
1be5c7 |
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
|
|
|
1be5c7 |
Message-Id: <20220405134652.19278-4-hreitz@redhat.com>
|
|
|
1be5c7 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
1be5c7 |
(cherry picked from commit 0423f75351ab83b844a31349218b0eadd830e07a)
|
|
|
1be5c7 |
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
|
|
|
1be5c7 |
---
|
|
|
1be5c7 |
block/qcow2-refcount.c | 33 +++++++++++++++++++--------------
|
|
|
1be5c7 |
1 file changed, 19 insertions(+), 14 deletions(-)
|
|
|
1be5c7 |
|
|
|
1be5c7 |
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
|
|
|
1be5c7 |
index 555d8ba5ac..09f8ef4927 100644
|
|
|
1be5c7 |
--- a/block/qcow2-refcount.c
|
|
|
1be5c7 |
+++ b/block/qcow2-refcount.c
|
|
|
1be5c7 |
@@ -2462,7 +2462,8 @@ static int64_t alloc_clusters_imrt(BlockDriverState *bs,
|
|
|
1be5c7 |
static int rebuild_refcounts_write_refblocks(
|
|
|
1be5c7 |
BlockDriverState *bs, void **refcount_table, int64_t *nb_clusters,
|
|
|
1be5c7 |
int64_t first_cluster, int64_t end_cluster,
|
|
|
1be5c7 |
- uint64_t **on_disk_reftable_ptr, uint32_t *on_disk_reftable_entries_ptr
|
|
|
1be5c7 |
+ uint64_t **on_disk_reftable_ptr, uint32_t *on_disk_reftable_entries_ptr,
|
|
|
1be5c7 |
+ Error **errp
|
|
|
1be5c7 |
)
|
|
|
1be5c7 |
{
|
|
|
1be5c7 |
BDRVQcow2State *s = bs->opaque;
|
|
|
1be5c7 |
@@ -2513,8 +2514,8 @@ static int rebuild_refcounts_write_refblocks(
|
|
|
1be5c7 |
nb_clusters,
|
|
|
1be5c7 |
&first_free_cluster);
|
|
|
1be5c7 |
if (refblock_offset < 0) {
|
|
|
1be5c7 |
- fprintf(stderr, "ERROR allocating refblock: %s\n",
|
|
|
1be5c7 |
- strerror(-refblock_offset));
|
|
|
1be5c7 |
+ error_setg_errno(errp, -refblock_offset,
|
|
|
1be5c7 |
+ "ERROR allocating refblock");
|
|
|
1be5c7 |
return refblock_offset;
|
|
|
1be5c7 |
}
|
|
|
1be5c7 |
|
|
|
1be5c7 |
@@ -2536,6 +2537,7 @@ static int rebuild_refcounts_write_refblocks(
|
|
|
1be5c7 |
on_disk_reftable_entries *
|
|
|
1be5c7 |
REFTABLE_ENTRY_SIZE);
|
|
|
1be5c7 |
if (!on_disk_reftable) {
|
|
|
1be5c7 |
+ error_setg(errp, "ERROR allocating reftable memory");
|
|
|
1be5c7 |
return -ENOMEM;
|
|
|
1be5c7 |
}
|
|
|
1be5c7 |
|
|
|
1be5c7 |
@@ -2559,7 +2561,7 @@ static int rebuild_refcounts_write_refblocks(
|
|
|
1be5c7 |
ret = qcow2_pre_write_overlap_check(bs, 0, refblock_offset,
|
|
|
1be5c7 |
s->cluster_size, false);
|
|
|
1be5c7 |
if (ret < 0) {
|
|
|
1be5c7 |
- fprintf(stderr, "ERROR writing refblock: %s\n", strerror(-ret));
|
|
|
1be5c7 |
+ error_setg_errno(errp, -ret, "ERROR writing refblock");
|
|
|
1be5c7 |
return ret;
|
|
|
1be5c7 |
}
|
|
|
1be5c7 |
|
|
|
1be5c7 |
@@ -2575,7 +2577,7 @@ static int rebuild_refcounts_write_refblocks(
|
|
|
1be5c7 |
ret = bdrv_pwrite(bs->file, refblock_offset, on_disk_refblock,
|
|
|
1be5c7 |
s->cluster_size);
|
|
|
1be5c7 |
if (ret < 0) {
|
|
|
1be5c7 |
- fprintf(stderr, "ERROR writing refblock: %s\n", strerror(-ret));
|
|
|
1be5c7 |
+ error_setg_errno(errp, -ret, "ERROR writing refblock");
|
|
|
1be5c7 |
return ret;
|
|
|
1be5c7 |
}
|
|
|
1be5c7 |
|
|
|
1be5c7 |
@@ -2598,7 +2600,8 @@ static int rebuild_refcounts_write_refblocks(
|
|
|
1be5c7 |
static int rebuild_refcount_structure(BlockDriverState *bs,
|
|
|
1be5c7 |
BdrvCheckResult *res,
|
|
|
1be5c7 |
void **refcount_table,
|
|
|
1be5c7 |
- int64_t *nb_clusters)
|
|
|
1be5c7 |
+ int64_t *nb_clusters,
|
|
|
1be5c7 |
+ Error **errp)
|
|
|
1be5c7 |
{
|
|
|
1be5c7 |
BDRVQcow2State *s = bs->opaque;
|
|
|
1be5c7 |
int64_t reftable_offset = -1;
|
|
|
1be5c7 |
@@ -2649,7 +2652,7 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
|
|
|
1be5c7 |
rebuild_refcounts_write_refblocks(bs, refcount_table, nb_clusters,
|
|
|
1be5c7 |
0, *nb_clusters,
|
|
|
1be5c7 |
&on_disk_reftable,
|
|
|
1be5c7 |
- &on_disk_reftable_entries);
|
|
|
1be5c7 |
+ &on_disk_reftable_entries, errp);
|
|
|
1be5c7 |
if (reftable_size_changed < 0) {
|
|
|
1be5c7 |
res->check_errors++;
|
|
|
1be5c7 |
ret = reftable_size_changed;
|
|
|
1be5c7 |
@@ -2673,8 +2676,8 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
|
|
|
1be5c7 |
refcount_table, nb_clusters,
|
|
|
1be5c7 |
&first_free_cluster);
|
|
|
1be5c7 |
if (reftable_offset < 0) {
|
|
|
1be5c7 |
- fprintf(stderr, "ERROR allocating reftable: %s\n",
|
|
|
1be5c7 |
- strerror(-reftable_offset));
|
|
|
1be5c7 |
+ error_setg_errno(errp, -reftable_offset,
|
|
|
1be5c7 |
+ "ERROR allocating reftable");
|
|
|
1be5c7 |
res->check_errors++;
|
|
|
1be5c7 |
ret = reftable_offset;
|
|
|
1be5c7 |
goto fail;
|
|
|
1be5c7 |
@@ -2692,7 +2695,7 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
|
|
|
1be5c7 |
reftable_start_cluster,
|
|
|
1be5c7 |
reftable_end_cluster,
|
|
|
1be5c7 |
&on_disk_reftable,
|
|
|
1be5c7 |
- &on_disk_reftable_entries);
|
|
|
1be5c7 |
+ &on_disk_reftable_entries, errp);
|
|
|
1be5c7 |
if (reftable_size_changed < 0) {
|
|
|
1be5c7 |
res->check_errors++;
|
|
|
1be5c7 |
ret = reftable_size_changed;
|
|
|
1be5c7 |
@@ -2722,7 +2725,7 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
|
|
|
1be5c7 |
ret = qcow2_pre_write_overlap_check(bs, 0, reftable_offset, reftable_length,
|
|
|
1be5c7 |
false);
|
|
|
1be5c7 |
if (ret < 0) {
|
|
|
1be5c7 |
- fprintf(stderr, "ERROR writing reftable: %s\n", strerror(-ret));
|
|
|
1be5c7 |
+ error_setg_errno(errp, -ret, "ERROR writing reftable");
|
|
|
1be5c7 |
goto fail;
|
|
|
1be5c7 |
}
|
|
|
1be5c7 |
|
|
|
1be5c7 |
@@ -2730,7 +2733,7 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
|
|
|
1be5c7 |
ret = bdrv_pwrite(bs->file, reftable_offset, on_disk_reftable,
|
|
|
1be5c7 |
reftable_length);
|
|
|
1be5c7 |
if (ret < 0) {
|
|
|
1be5c7 |
- fprintf(stderr, "ERROR writing reftable: %s\n", strerror(-ret));
|
|
|
1be5c7 |
+ error_setg_errno(errp, -ret, "ERROR writing reftable");
|
|
|
1be5c7 |
goto fail;
|
|
|
1be5c7 |
}
|
|
|
1be5c7 |
|
|
|
1be5c7 |
@@ -2743,7 +2746,7 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
|
|
|
1be5c7 |
&reftable_offset_and_clusters,
|
|
|
1be5c7 |
sizeof(reftable_offset_and_clusters));
|
|
|
1be5c7 |
if (ret < 0) {
|
|
|
1be5c7 |
- fprintf(stderr, "ERROR setting reftable: %s\n", strerror(-ret));
|
|
|
1be5c7 |
+ error_setg_errno(errp, -ret, "ERROR setting reftable");
|
|
|
1be5c7 |
goto fail;
|
|
|
1be5c7 |
}
|
|
|
1be5c7 |
|
|
|
1be5c7 |
@@ -2811,11 +2814,13 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
|
|
|
1be5c7 |
if (rebuild && (fix & BDRV_FIX_ERRORS)) {
|
|
|
1be5c7 |
BdrvCheckResult old_res = *res;
|
|
|
1be5c7 |
int fresh_leaks = 0;
|
|
|
1be5c7 |
+ Error *local_err = NULL;
|
|
|
1be5c7 |
|
|
|
1be5c7 |
fprintf(stderr, "Rebuilding refcount structure\n");
|
|
|
1be5c7 |
ret = rebuild_refcount_structure(bs, res, &refcount_table,
|
|
|
1be5c7 |
- &nb_clusters);
|
|
|
1be5c7 |
+ &nb_clusters, &local_err);
|
|
|
1be5c7 |
if (ret < 0) {
|
|
|
1be5c7 |
+ error_report_err(local_err);
|
|
|
1be5c7 |
goto fail;
|
|
|
1be5c7 |
}
|
|
|
1be5c7 |
|
|
|
1be5c7 |
--
|
|
|
1be5c7 |
2.27.0
|
|
|
1be5c7 |
|