@ -6822,6 +6822,7 @@ void bdrv_refresh_filename(BlockDriverState *bs)
{
{
BlockDriver * drv = bs - > drv ;
BlockDriver * drv = bs - > drv ;
BdrvChild * child ;
BdrvChild * child ;
BlockDriverState * primary_child_bs ;
QDict * opts ;
QDict * opts ;
bool backing_overridden ;
bool backing_overridden ;
bool generate_json_filename ; /* Whether our default implementation should
bool generate_json_filename ; /* Whether our default implementation should
@ -6891,20 +6892,30 @@ void bdrv_refresh_filename(BlockDriverState *bs)
qobject_unref ( bs - > full_open_options ) ;
qobject_unref ( bs - > full_open_options ) ;
bs - > full_open_options = opts ;
bs - > full_open_options = opts ;
primary_child_bs = bdrv_primary_bs ( bs ) ;
if ( drv - > bdrv_refresh_filename ) {
if ( drv - > bdrv_refresh_filename ) {
/* Obsolete information is of no use here, so drop the old file name
/* Obsolete information is of no use here, so drop the old file name
* information before refreshing it */
* information before refreshing it */
bs - > exact_filename [ 0 ] = ' \0 ' ;
bs - > exact_filename [ 0 ] = ' \0 ' ;
drv - > bdrv_refresh_filename ( bs ) ;
drv - > bdrv_refresh_filename ( bs ) ;
} else if ( bs - > file ) {
} else if ( primary_child_bs ) {
/* Try to reconstruct valid information from the underlying file */
/*
* Try to reconstruct valid information from the underlying
* file - - this only works for format nodes ( filter nodes
* cannot be probed and as such must be selected by the user
* either through an options dict , or through a special
* filename which the filter driver must construct in its
* . bdrv_refresh_filename ( ) implementation ) .
*/
bs - > exact_filename [ 0 ] = ' \0 ' ;
bs - > exact_filename [ 0 ] = ' \0 ' ;
/*
/*
* We can use the underlying file ' s filename if :
* We can use the underlying file ' s filename if :
* - it has a filename ,
* - it has a filename ,
* - the current BDS is not a filter ,
* - the file is a protocol BDS , and
* - the file is a protocol BDS , and
* - opening that file ( as this BDS ' s format ) will automatically create
* - opening that file ( as this BDS ' s format ) will automatically create
* the BDS tree we have right now , that is :
* the BDS tree we have right now , that is :
@ -6913,11 +6924,11 @@ void bdrv_refresh_filename(BlockDriverState *bs)
* - no non - file child of this BDS has been overridden by the user
* - no non - file child of this BDS has been overridden by the user
* Both of these conditions are represented by generate_json_filename .
* Both of these conditions are represented by generate_json_filename .
*/
*/
if ( bs - > file - > bs - > exact_filename [ 0 ] & &
if ( primary_child_ bs- > exact_filename [ 0 ] & &
bs - > file - > bs - > drv - > bdrv_file_open & &
primary_child_ bs- > drv - > bdrv_file_open & &
! generate_json_filename )
! drv - > is_filter & & ! generate_json_filename )
{
{
strcpy ( bs - > exact_filename , bs - > file - > bs - > exact_filename ) ;
strcpy ( bs - > exact_filename , primary_child_ bs- > exact_filename ) ;
}
}
}
}
@ -6937,6 +6948,7 @@ void bdrv_refresh_filename(BlockDriverState *bs)
char * bdrv_dirname ( BlockDriverState * bs , Error * * errp )
char * bdrv_dirname ( BlockDriverState * bs , Error * * errp )
{
{
BlockDriver * drv = bs - > drv ;
BlockDriver * drv = bs - > drv ;
BlockDriverState * child_bs ;
if ( ! drv ) {
if ( ! drv ) {
error_setg ( errp , " Node '%s' is ejected " , bs - > node_name ) ;
error_setg ( errp , " Node '%s' is ejected " , bs - > node_name ) ;
@ -6947,8 +6959,9 @@ char *bdrv_dirname(BlockDriverState *bs, Error **errp)
return drv - > bdrv_dirname ( bs , errp ) ;
return drv - > bdrv_dirname ( bs , errp ) ;
}
}
if ( bs - > file ) {
child_bs = bdrv_primary_bs ( bs ) ;
return bdrv_dirname ( bs - > file - > bs , errp ) ;
if ( child_bs ) {
return bdrv_dirname ( child_bs , errp ) ;
}
}
bdrv_refresh_filename ( bs ) ;
bdrv_refresh_filename ( bs ) ;