diff mbox series

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

Message ID 1602524605-481160-11-git-send-email-andrey.shinkevich@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series Apply COR-filter to the block-stream permanently | expand

Commit Message

Denis V. Lunev" via Oct. 12, 2020, 5:43 p.m. UTC
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(-)

Comments

Max Reitz Oct. 14, 2020, 3:02 p.m. UTC | #1
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);
>
Vladimir Sementsov-Ogievskiy Oct. 14, 2020, 3:40 p.m. UTC | #2
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().
diff mbox series

Patch

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);