diff mbox

[v3,22/25] block: Do not copy exact_filename from format file

Message ID 20161130011851.24696-23-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Nov. 30, 2016, 1:18 a.m. UTC
If the a format BDS's file BDS is in turn a format BDS, we cannot simply
use the same filename, because when opening a BDS tree based on a
filename alone, qemu will create only one format node on top of one
protocol node (disregarding a potential backing file).

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

Comments

Max Reitz Jan. 11, 2017, 4:29 p.m. UTC | #1
On 30.11.2016 02:18, Max Reitz wrote:
> If the a format BDS's file BDS is in turn a format BDS, we cannot simply
> use the same filename, because when opening a BDS tree based on a
> filename alone, qemu will create only one format node on top of one
> protocol node (disregarding a potential backing file).
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/block.c b/block.c
> index ec25cbf..71c14f4 100644
> --- a/block.c
> +++ b/block.c
> @@ -4095,9 +4095,20 @@ void bdrv_refresh_filename(BlockDriverState *bs)
>  
>          bs->exact_filename[0] = '\0';
>  
> -        /* If no specific options have been given for this BDS, the filename of
> -         * the underlying file should suffice for this one as well */
> -        if (bs->file->bs->exact_filename[0] && !generate_json_filename) {
> +        /* We can use the underlying file's filename if:
> +         * - it has a filename,
> +         * - the file is a protocol BDS, and
> +         * - opening that file (as this BDS's format) will automatically create
> +         *   the BDS tree we have right now, that is:
> +         *   - the user did not significantly change this BDS's behavior with
> +         *     some explicit options
> +         *   - no non-file child of this BDS has been overridden by the user
> +         *   Both of these conditions are represented by generate_json_filename.
> +         */
> +        if (bs->file->bs->exact_filename[0] &&
> +            (bs->file->bs->open_flags & BDRV_O_PROTOCOL) &&

This was a nice try, but as it turns out, this flag does not have to
always set for protocol BDSs. A more reliable test is:

!bs->file->bs->file

This test may also be a bit more intuitive: We can copy exact_filename
in one layer from bs->file, but not through two layers.

Max

> +            !generate_json_filename)
> +        {
>              strcpy(bs->exact_filename, bs->file->bs->exact_filename);
>          }
>      }
>
Max Reitz Jan. 11, 2017, 5:13 p.m. UTC | #2
On 11.01.2017 17:29, Max Reitz wrote:
> On 30.11.2016 02:18, Max Reitz wrote:
>> If the a format BDS's file BDS is in turn a format BDS, we cannot simply
>> use the same filename, because when opening a BDS tree based on a
>> filename alone, qemu will create only one format node on top of one
>> protocol node (disregarding a potential backing file).
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>  block.c | 17 ++++++++++++++---
>>  1 file changed, 14 insertions(+), 3 deletions(-)
>>
>> diff --git a/block.c b/block.c
>> index ec25cbf..71c14f4 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -4095,9 +4095,20 @@ void bdrv_refresh_filename(BlockDriverState *bs)
>>  
>>          bs->exact_filename[0] = '\0';
>>  
>> -        /* If no specific options have been given for this BDS, the filename of
>> -         * the underlying file should suffice for this one as well */
>> -        if (bs->file->bs->exact_filename[0] && !generate_json_filename) {
>> +        /* We can use the underlying file's filename if:
>> +         * - it has a filename,
>> +         * - the file is a protocol BDS, and
>> +         * - opening that file (as this BDS's format) will automatically create
>> +         *   the BDS tree we have right now, that is:
>> +         *   - the user did not significantly change this BDS's behavior with
>> +         *     some explicit options
>> +         *   - no non-file child of this BDS has been overridden by the user
>> +         *   Both of these conditions are represented by generate_json_filename.
>> +         */
>> +        if (bs->file->bs->exact_filename[0] &&
>> +            (bs->file->bs->open_flags & BDRV_O_PROTOCOL) &&
> 
> This was a nice try, but as it turns out, this flag does not have to
> always set for protocol BDSs. A more reliable test is:
> 
> !bs->file->bs->file
> 
> This test may also be a bit more intuitive: We can copy exact_filename
> in one layer from bs->file, but not through two layers.

And now it turns out that it's again more complicated...

blkdebug is a protocol block driver that has a bs->file. So when using
blkdebug, bs->file->bs->file is set on the format layer.

So I guess I'll have to resort to testing
bs->file->bs->drv->bdrv_file_open...

Max
diff mbox

Patch

diff --git a/block.c b/block.c
index ec25cbf..71c14f4 100644
--- a/block.c
+++ b/block.c
@@ -4095,9 +4095,20 @@  void bdrv_refresh_filename(BlockDriverState *bs)
 
         bs->exact_filename[0] = '\0';
 
-        /* If no specific options have been given for this BDS, the filename of
-         * the underlying file should suffice for this one as well */
-        if (bs->file->bs->exact_filename[0] && !generate_json_filename) {
+        /* We can use the underlying file's filename if:
+         * - it has a filename,
+         * - the file is a protocol BDS, and
+         * - opening that file (as this BDS's format) will automatically create
+         *   the BDS tree we have right now, that is:
+         *   - the user did not significantly change this BDS's behavior with
+         *     some explicit options
+         *   - no non-file child of this BDS has been overridden by the user
+         *   Both of these conditions are represented by generate_json_filename.
+         */
+        if (bs->file->bs->exact_filename[0] &&
+            (bs->file->bs->open_flags & BDRV_O_PROTOCOL) &&
+            !generate_json_filename)
+        {
             strcpy(bs->exact_filename, bs->file->bs->exact_filename);
         }
     }