Split off the default code for format BDS from bdrv_refresh_filename() into an own function, first because it is nicer this way, and second because this will allow block drivers to reuse this function in their own specific implementation of bdrv_refresh_filename().
Signed-off-by: Max Reitz <mre...@redhat.com> --- block.c | 95 +++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/block.c b/block.c index aff9ea3..447468c 100644 --- a/block.c +++ b/block.c @@ -3872,6 +3872,56 @@ static bool append_open_options(QDict *d, BlockDriverState *bs) return found_any; } +static void bdrv_default_refresh_format_filename(BlockDriverState *bs) +{ + BlockDriver *drv = bs->drv; + QDict *opts; + bool has_open_options; + + bs->exact_filename[0] = '\0'; + if (bs->full_open_options) { + QDECREF(bs->full_open_options); + bs->full_open_options = NULL; + } + + opts = qdict_new(); + has_open_options = append_open_options(opts, bs); + has_open_options |= bs->backing_overridden; + + /* 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] && !has_open_options) { + strcpy(bs->exact_filename, bs->file->bs->exact_filename); + } + /* Reconstructing the full options QDict is simple for most format block + * drivers, as long as the full options are known for the underlying + * file BDS. The full options QDict of that file BDS should somehow + * contain a representation of the filename, therefore the following + * suffices without querying the (exact_)filename of this BDS. */ + if (bs->file->bs->full_open_options && + (!bs->backing || bs->backing->bs->full_open_options)) + { + qdict_put_obj(opts, "driver", + QOBJECT(qstring_from_str(drv->format_name))); + + QINCREF(bs->file->bs->full_open_options); + qdict_put_obj(opts, "file", + QOBJECT(bs->file->bs->full_open_options)); + + if (bs->backing) { + QINCREF(bs->backing->bs->full_open_options); + qdict_put_obj(opts, "backing", + QOBJECT(bs->backing->bs->full_open_options)); + } else if (bs->backing_overridden && !bs->backing) { + qdict_put_obj(opts, "backing", QOBJECT(qstring_new())); + } + + bs->full_open_options = opts; + } else { + QDECREF(opts); + } +} + /* Updates the following BDS fields: * - exact_filename: A filename which may be used for opening a block device * which (mostly) equals the given BDS (even without any @@ -3915,50 +3965,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) QDECREF(opts); } else if (bs->file) { /* Try to reconstruct valid information from the underlying file */ - bool has_open_options; - - bs->exact_filename[0] = '\0'; - if (bs->full_open_options) { - QDECREF(bs->full_open_options); - bs->full_open_options = NULL; - } - - opts = qdict_new(); - has_open_options = append_open_options(opts, bs); - has_open_options |= bs->backing_overridden; - - /* 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] && !has_open_options) { - strcpy(bs->exact_filename, bs->file->bs->exact_filename); - } - /* Reconstructing the full options QDict is simple for most format block - * drivers, as long as the full options are known for the underlying - * file BDS. The full options QDict of that file BDS should somehow - * contain a representation of the filename, therefore the following - * suffices without querying the (exact_)filename of this BDS. */ - if (bs->file->bs->full_open_options && - (!bs->backing || bs->backing->bs->full_open_options)) - { - qdict_put_obj(opts, "driver", - QOBJECT(qstring_from_str(drv->format_name))); - - QINCREF(bs->file->bs->full_open_options); - qdict_put_obj(opts, "file", - QOBJECT(bs->file->bs->full_open_options)); - - if (bs->backing) { - QINCREF(bs->backing->bs->full_open_options); - qdict_put_obj(opts, "backing", - QOBJECT(bs->backing->bs->full_open_options)); - } else if (bs->backing_overridden && !bs->backing) { - qdict_put_obj(opts, "backing", QOBJECT(qstring_new())); - } - - bs->full_open_options = opts; - } else { - QDECREF(opts); - } + bdrv_default_refresh_format_filename(bs); } else if (!bs->full_open_options && qdict_size(bs->options)) { /* There is no underlying file BDS (at least referenced by BDS.file), * so the full options QDict should be equal to the options given -- 2.8.0