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