[PATCH v11 10/13] stream: skip filters when writing backing file name to QCOW2 header

Andrey Shinkevich via posted 13 patches 5 years, 1 month ago
Maintainers: Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, John Snow <jsnow@redhat.com>, Fam Zheng <fam@euphon.net>, Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>
There is a newer version of this series
[PATCH v11 10/13] stream: skip filters when writing backing file name to QCOW2 header
Posted by Andrey Shinkevich via 5 years, 1 month ago
Avoid writing a filter JSON-name to QCOW2 image when the backing file
is changed after the block stream job.

Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
---
 block/stream.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/block/stream.c b/block/stream.c
index e0540ee..51462bd 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -65,6 +65,7 @@ static int stream_prepare(Job *job)
     BlockDriverState *bs = blk_bs(bjob->blk);
     BlockDriverState *unfiltered_bs = bdrv_skip_filters(bs);
     BlockDriverState *base = bdrv_filter_or_cow_bs(s->above_base);
+    BlockDriverState *base_unfiltered = bdrv_skip_filters(base);
     Error *local_err = NULL;
     int ret = 0;
 
@@ -73,10 +74,10 @@ static int stream_prepare(Job *job)
 
     if (bdrv_cow_child(unfiltered_bs)) {
         const char *base_id = NULL, *base_fmt = NULL;
-        if (base) {
-            base_id = s->backing_file_str;
-            if (base->drv) {
-                base_fmt = base->drv->format_name;
+        if (base_unfiltered) {
+            base_id = base_unfiltered->filename;
+            if (base_unfiltered->drv) {
+                base_fmt = base_unfiltered->drv->format_name;
             }
         }
         bdrv_set_backing_hd(unfiltered_bs, base, &local_err);
-- 
1.8.3.1


Re: [PATCH v11 10/13] stream: skip filters when writing backing file name to QCOW2 header
Posted by Max Reitz 5 years, 1 month ago
On 12.10.20 19:43, Andrey Shinkevich wrote:
> Avoid writing a filter JSON-name to QCOW2 image when the backing file
> is changed after the block stream job.
> 
> Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
> ---
>  block/stream.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/block/stream.c b/block/stream.c
> index e0540ee..51462bd 100644
> --- a/block/stream.c
> +++ b/block/stream.c
> @@ -65,6 +65,7 @@ static int stream_prepare(Job *job)
>      BlockDriverState *bs = blk_bs(bjob->blk);
>      BlockDriverState *unfiltered_bs = bdrv_skip_filters(bs);
>      BlockDriverState *base = bdrv_filter_or_cow_bs(s->above_base);
> +    BlockDriverState *base_unfiltered = bdrv_skip_filters(base);
>      Error *local_err = NULL;
>      int ret = 0;
>  
> @@ -73,10 +74,10 @@ static int stream_prepare(Job *job)
>  
>      if (bdrv_cow_child(unfiltered_bs)) {
>          const char *base_id = NULL, *base_fmt = NULL;
> -        if (base) {
> -            base_id = s->backing_file_str;
> -            if (base->drv) {
> -                base_fmt = base->drv->format_name;
> +        if (base_unfiltered) {
> +            base_id = base_unfiltered->filename;

I think you have to leave this querying s->backing_file_str, and instead
change how qmp_block_stream() gets @base_name.  block-stream has a
backing-file parameter that can override the string that should be used
here.

(Or perhaps you can let qmp_block_stream() just set it to NULL if no
backing-file parameter is passed and then fall back to
base_unfiltered->filename only here.  Probably better, actually, in case
base_unfiltered is changed during the job run.)

Max

> +            if (base_unfiltered->drv) {
> +                base_fmt = base_unfiltered->drv->format_name;
>              }
>          }
>          bdrv_set_backing_hd(unfiltered_bs, base, &local_err);
> 


Re: [PATCH v11 10/13] stream: skip filters when writing backing file name to QCOW2 header
Posted by Vladimir Sementsov-Ogievskiy 5 years, 1 month ago
14.10.2020 18:02, Max Reitz wrote:
> On 12.10.20 19:43, Andrey Shinkevich wrote:
>> Avoid writing a filter JSON-name to QCOW2 image when the backing file
>> is changed after the block stream job.
>>
>> Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
>> ---
>>   block/stream.c | 9 +++++----
>>   1 file changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/block/stream.c b/block/stream.c
>> index e0540ee..51462bd 100644
>> --- a/block/stream.c
>> +++ b/block/stream.c
>> @@ -65,6 +65,7 @@ static int stream_prepare(Job *job)
>>       BlockDriverState *bs = blk_bs(bjob->blk);
>>       BlockDriverState *unfiltered_bs = bdrv_skip_filters(bs);
>>       BlockDriverState *base = bdrv_filter_or_cow_bs(s->above_base);
>> +    BlockDriverState *base_unfiltered = bdrv_skip_filters(base);
>>       Error *local_err = NULL;
>>       int ret = 0;
>>   
>> @@ -73,10 +74,10 @@ static int stream_prepare(Job *job)
>>   
>>       if (bdrv_cow_child(unfiltered_bs)) {
>>           const char *base_id = NULL, *base_fmt = NULL;
>> -        if (base) {
>> -            base_id = s->backing_file_str;
>> -            if (base->drv) {
>> -                base_fmt = base->drv->format_name;
>> +        if (base_unfiltered) {
>> +            base_id = base_unfiltered->filename;
> 
> I think you have to leave this querying s->backing_file_str, and instead
> change how qmp_block_stream() gets @base_name.  block-stream has a
> backing-file parameter that can override the string that should be used
> here.
> 
> (Or perhaps you can let qmp_block_stream() just set it to NULL if no
> backing-file parameter is passed and then fall back to
> base_unfiltered->filename only here.  Probably better, actually, in case
> base_unfiltered is changed during the job run.)
> 

Agree with the way in brackets.

If user set backing-file parameter we should handle it here.

If backing-file is not set, we should use dynamically calculated unfiltered base in stream_prepare().

-- 
Best regards,
Vladimir