diff mbox

[v6,4/9] block: Do not blindly copy filename from file

Message ID 20170113205237.30386-5-mreitz@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Max Reitz Jan. 13, 2017, 8:52 p.m. UTC
bdrv_refresh_filename() can do the same and it has some checks whether
the filename can actually be inherited or not, so we can let it do its
job in bdrv_open_inherit() after bdrv_open_common() has been called.

The only thing we need to set in bdrv_open_common() is the
exact_filename of a BDS without an underlying file, for two reasons:
(1) It cannot be inherited from an underlying file BDS, so it has to be
    set somewhere.
(2) The driver may need the filename in its bdrv_file_open()
    implementation (format drivers do not need their own filename,
    though they may need their file BDS's name).

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

Comments

Eric Blake Jan. 16, 2017, 8:48 p.m. UTC | #1
On 01/13/2017 02:52 PM, Max Reitz wrote:
> bdrv_refresh_filename() can do the same and it has some checks whether
> the filename can actually be inherited or not, so we can let it do its
> job in bdrv_open_inherit() after bdrv_open_common() has been called.
> 
> The only thing we need to set in bdrv_open_common() is the
> exact_filename of a BDS without an underlying file, for two reasons:
> (1) It cannot be inherited from an underlying file BDS, so it has to be
>     set somewhere.
> (2) The driver may need the filename in its bdrv_file_open()
>     implementation (format drivers do not need their own filename,
>     though they may need their file BDS's name).
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox

Patch

diff --git a/block.c b/block.c
index 9943d8eff6..19f8a84d03 100644
--- a/block.c
+++ b/block.c
@@ -1116,12 +1116,11 @@  static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,
         bs->detect_zeroes = value;
     }
 
-    if (filename != NULL) {
-        pstrcpy(bs->filename, sizeof(bs->filename), filename);
+    if (!file && filename) {
+        pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), filename);
     } else {
-        bs->filename[0] = '\0';
+        assert(!drv->bdrv_needs_filename);
     }
-    pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), bs->filename);
 
     bs->drv = drv;
     bs->opaque = g_malloc0(drv->instance_size);