mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 17:53:56 -06:00
block: refactor error handling of commit_iteration
Signed-off-by: Vincent Vanlaer <libvirt-e6954efa@volkihar.be> Message-Id: <20241026163010.2865002-4-libvirt-e6954efa@volkihar.be> [vsementsov]: move action declaration to the top of the function Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
This commit is contained in:
parent
23743ab282
commit
0648c76ad1
1 changed files with 38 additions and 29 deletions
|
@ -129,51 +129,60 @@ static void commit_clean(Job *job)
|
|||
}
|
||||
|
||||
static int commit_iteration(CommitBlockJob *s, int64_t offset,
|
||||
int64_t *n, void *buf)
|
||||
int64_t *requested_bytes, void *buf)
|
||||
{
|
||||
BlockErrorAction action;
|
||||
int64_t bytes = *requested_bytes;
|
||||
int ret = 0;
|
||||
bool copy;
|
||||
bool error_in_source = true;
|
||||
|
||||
/* Copy if allocated above the base */
|
||||
WITH_GRAPH_RDLOCK_GUARD() {
|
||||
ret = bdrv_co_common_block_status_above(blk_bs(s->top),
|
||||
s->base_overlay, true, true, offset, COMMIT_BUFFER_SIZE,
|
||||
n, NULL, NULL, NULL);
|
||||
&bytes, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
copy = (ret >= 0 && ret & BDRV_BLOCK_ALLOCATED);
|
||||
trace_commit_one_iteration(s, offset, *n, ret);
|
||||
if (copy) {
|
||||
assert(*n < SIZE_MAX);
|
||||
trace_commit_one_iteration(s, offset, bytes, ret);
|
||||
|
||||
ret = blk_co_pread(s->top, offset, *n, buf, 0);
|
||||
if (ret >= 0) {
|
||||
ret = blk_co_pwrite(s->base, offset, *n, buf, 0);
|
||||
if (ret < 0) {
|
||||
error_in_source = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
BlockErrorAction action = block_job_error_action(&s->common,
|
||||
s->on_error,
|
||||
error_in_source,
|
||||
-ret);
|
||||
if (action == BLOCK_ERROR_ACTION_REPORT) {
|
||||
return ret;
|
||||
} else {
|
||||
*n = 0;
|
||||
return 0;
|
||||
}
|
||||
goto fail;
|
||||
}
|
||||
/* Publish progress */
|
||||
job_progress_update(&s->common.job, *n);
|
||||
|
||||
if (copy) {
|
||||
block_job_ratelimit_processed_bytes(&s->common, *n);
|
||||
if (ret & BDRV_BLOCK_ALLOCATED) {
|
||||
assert(bytes < SIZE_MAX);
|
||||
|
||||
ret = blk_co_pread(s->top, offset, bytes, buf, 0);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = blk_co_pwrite(s->base, offset, bytes, buf, 0);
|
||||
if (ret < 0) {
|
||||
error_in_source = false;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
block_job_ratelimit_processed_bytes(&s->common, bytes);
|
||||
}
|
||||
|
||||
/* Publish progress */
|
||||
|
||||
job_progress_update(&s->common.job, bytes);
|
||||
|
||||
*requested_bytes = bytes;
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
action = block_job_error_action(&s->common, s->on_error,
|
||||
error_in_source, -ret);
|
||||
if (action == BLOCK_ERROR_ACTION_REPORT) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
*requested_bytes = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue