[Qemu-devel] [PATCH 04/13] block: Freeze the backing chain for the duration of the stream job

Alberto Garcia posted 13 patches 6 years, 9 months ago
Maintainers: Max Reitz <mreitz@redhat.com>, Liu Yuan <namei.unix@gmail.com>, Josh Durgin <jdurgin@redhat.com>, Wen Congyang <wencongyang2@huawei.com>, Jeff Cody <jcody@redhat.com>, Peter Lieven <pl@kamp.de>, Fam Zheng <fam@euphon.net>, Xie Changlong <xiechanglong.d@gmail.com>, Ronnie Sahlberg <ronniesahlberg@gmail.com>, Kevin Wolf <kwolf@redhat.com>, Markus Armbruster <armbru@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Eric Blake <eblake@redhat.com>
There is a newer version of this series
[Qemu-devel] [PATCH 04/13] block: Freeze the backing chain for the duration of the stream job
Posted by Alberto Garcia 6 years, 9 months ago
Signed-off-by: Alberto Garcia <berto@igalia.com>
---
 block/stream.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/block/stream.c b/block/stream.c
index 7a49ac0992..39a2e10892 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -54,6 +54,14 @@ static int coroutine_fn stream_populate(BlockBackend *blk,
     return blk_co_preadv(blk, offset, qiov.size, &qiov, BDRV_REQ_COPY_ON_READ);
 }
 
+static void stream_abort(Job *job)
+{
+    StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
+    BlockJob *bjob = &s->common;
+
+    bdrv_unfreeze_backing_chain(blk_bs(bjob->blk), s->base);
+}
+
 static int stream_prepare(Job *job)
 {
     StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
@@ -63,6 +71,8 @@ static int stream_prepare(Job *job)
     Error *local_err = NULL;
     int ret = 0;
 
+    bdrv_unfreeze_backing_chain(bs, base);
+
     if (bs->backing) {
         const char *base_id = NULL, *base_fmt = NULL;
         if (base) {
@@ -213,6 +223,7 @@ static const BlockJobDriver stream_job_driver = {
         .free          = block_job_free,
         .run           = stream_run,
         .prepare       = stream_prepare,
+        .abort         = stream_abort,
         .clean         = stream_clean,
         .user_resume   = block_job_user_resume,
         .drain         = block_job_drain,
@@ -259,6 +270,11 @@ void stream_start(const char *job_id, BlockDriverState *bs,
                            &error_abort);
     }
 
+    if (bdrv_freeze_backing_chain(bs, base, errp) < 0) {
+        job_early_fail(&s->common.job);
+        goto fail;
+    }
+
     s->base = base;
     s->backing_file_str = g_strdup(backing_file_str);
     s->bs_read_only = bs_read_only;
-- 
2.11.0


Re: [Qemu-devel] [PATCH 04/13] block: Freeze the backing chain for the duration of the stream job
Posted by Kevin Wolf 6 years, 8 months ago
Am 17.01.2019 um 16:33 hat Alberto Garcia geschrieben:
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> ---
>  block/stream.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/block/stream.c b/block/stream.c
> index 7a49ac0992..39a2e10892 100644
> --- a/block/stream.c
> +++ b/block/stream.c
> @@ -54,6 +54,14 @@ static int coroutine_fn stream_populate(BlockBackend *blk,
>      return blk_co_preadv(blk, offset, qiov.size, &qiov, BDRV_REQ_COPY_ON_READ);
>  }
>  
> +static void stream_abort(Job *job)
> +{
> +    StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
> +    BlockJob *bjob = &s->common;
> +
> +    bdrv_unfreeze_backing_chain(blk_bs(bjob->blk), s->base);
> +}

Like in commit, you can get a double unfreeze here if .abort is called
after .prepare returned an error.

Kevin

Re: [Qemu-devel] [PATCH 04/13] block: Freeze the backing chain for the duration of the stream job
Posted by Alberto Garcia 6 years, 8 months ago
On Tue 12 Feb 2019 04:15:58 PM CET, Kevin Wolf wrote:
> Am 17.01.2019 um 16:33 hat Alberto Garcia geschrieben:
>> Signed-off-by: Alberto Garcia <berto@igalia.com>
>> ---
>>  block/stream.c | 16 ++++++++++++++++
>>  1 file changed, 16 insertions(+)
>> 
>> diff --git a/block/stream.c b/block/stream.c
>> index 7a49ac0992..39a2e10892 100644
>> --- a/block/stream.c
>> +++ b/block/stream.c
>> @@ -54,6 +54,14 @@ static int coroutine_fn stream_populate(BlockBackend *blk,
>>      return blk_co_preadv(blk, offset, qiov.size, &qiov, BDRV_REQ_COPY_ON_READ);
>>  }
>>  
>> +static void stream_abort(Job *job)
>> +{
>> +    StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
>> +    BlockJob *bjob = &s->common;
>> +
>> +    bdrv_unfreeze_backing_chain(blk_bs(bjob->blk), s->base);
>> +}
>
> Like in commit, you can get a double unfreeze here if .abort is called
> after .prepare returned an error.

You're right, I'll fix it

Berto