mirror of
https://github.com/qemu/qemu.git
synced 2024-12-14 06:53:43 +08:00
block/stream: add s->target_bs
Add a direct link to target bs for convenience and to simplify following commit which will insert COR filter above target bs. This is a part of original commit written by Andrey. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-Id: <20201216061703.70908-13-vsementsov@virtuozzo.com> Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
9126a2dc4b
commit
0f6c94988a
@ -33,6 +33,7 @@ typedef struct StreamBlockJob {
|
||||
BlockJob common;
|
||||
BlockDriverState *base_overlay; /* COW overlay (stream from this) */
|
||||
BlockDriverState *above_base; /* Node directly above the base */
|
||||
BlockDriverState *target_bs;
|
||||
BlockdevOnError on_error;
|
||||
char *backing_file_str;
|
||||
bool bs_read_only;
|
||||
@ -53,23 +54,20 @@ static void stream_abort(Job *job)
|
||||
StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
|
||||
|
||||
if (s->chain_frozen) {
|
||||
BlockJob *bjob = &s->common;
|
||||
bdrv_unfreeze_backing_chain(blk_bs(bjob->blk), s->above_base);
|
||||
bdrv_unfreeze_backing_chain(s->target_bs, s->above_base);
|
||||
}
|
||||
}
|
||||
|
||||
static int stream_prepare(Job *job)
|
||||
{
|
||||
StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
|
||||
BlockJob *bjob = &s->common;
|
||||
BlockDriverState *bs = blk_bs(bjob->blk);
|
||||
BlockDriverState *unfiltered_bs = bdrv_skip_filters(bs);
|
||||
BlockDriverState *unfiltered_bs = bdrv_skip_filters(s->target_bs);
|
||||
BlockDriverState *base = bdrv_filter_or_cow_bs(s->above_base);
|
||||
BlockDriverState *unfiltered_base = bdrv_skip_filters(base);
|
||||
Error *local_err = NULL;
|
||||
int ret = 0;
|
||||
|
||||
bdrv_unfreeze_backing_chain(bs, s->above_base);
|
||||
bdrv_unfreeze_backing_chain(s->target_bs, s->above_base);
|
||||
s->chain_frozen = false;
|
||||
|
||||
if (bdrv_cow_child(unfiltered_bs)) {
|
||||
@ -95,13 +93,12 @@ static void stream_clean(Job *job)
|
||||
{
|
||||
StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
|
||||
BlockJob *bjob = &s->common;
|
||||
BlockDriverState *bs = blk_bs(bjob->blk);
|
||||
|
||||
/* Reopen the image back in read-only mode if necessary */
|
||||
if (s->bs_read_only) {
|
||||
/* Give up write permissions before making it read-only */
|
||||
blk_set_perm(bjob->blk, 0, BLK_PERM_ALL, &error_abort);
|
||||
bdrv_reopen_set_read_only(bs, true, NULL);
|
||||
bdrv_reopen_set_read_only(s->target_bs, true, NULL);
|
||||
}
|
||||
|
||||
g_free(s->backing_file_str);
|
||||
@ -111,8 +108,7 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
|
||||
{
|
||||
StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
|
||||
BlockBackend *blk = s->common.blk;
|
||||
BlockDriverState *bs = blk_bs(blk);
|
||||
BlockDriverState *unfiltered_bs = bdrv_skip_filters(bs);
|
||||
BlockDriverState *unfiltered_bs = bdrv_skip_filters(s->target_bs);
|
||||
bool enable_cor = !bdrv_cow_child(s->base_overlay);
|
||||
int64_t len;
|
||||
int64_t offset = 0;
|
||||
@ -125,7 +121,7 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = bdrv_getlength(bs);
|
||||
len = bdrv_getlength(s->target_bs);
|
||||
if (len < 0) {
|
||||
return len;
|
||||
}
|
||||
@ -137,7 +133,7 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
|
||||
* account.
|
||||
*/
|
||||
if (enable_cor) {
|
||||
bdrv_enable_copy_on_read(bs);
|
||||
bdrv_enable_copy_on_read(s->target_bs);
|
||||
}
|
||||
|
||||
for ( ; offset < len; offset += n) {
|
||||
@ -199,7 +195,7 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
|
||||
}
|
||||
|
||||
if (enable_cor) {
|
||||
bdrv_disable_copy_on_read(bs);
|
||||
bdrv_disable_copy_on_read(s->target_bs);
|
||||
}
|
||||
|
||||
/* Do not remove the backing file if an error was there but ignored. */
|
||||
@ -314,6 +310,7 @@ void stream_start(const char *job_id, BlockDriverState *bs,
|
||||
s->base_overlay = base_overlay;
|
||||
s->above_base = above_base;
|
||||
s->backing_file_str = g_strdup(backing_file_str);
|
||||
s->target_bs = bs;
|
||||
s->bs_read_only = bs_read_only;
|
||||
s->chain_frozen = true;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user