qemu/block.c
/* 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
 *                    other options; so reading and writing must return the same
 *                    results, but caching etc. may be different)
 *  - full_open_options: Options which, when given when opening a block device
 *                       (without a filename), result in a BDS (mostly)
 *                       equalling the given one
 *  - filename: If exact_filename is set, it is copied here. Otherwise,
 *              full_open_options is converted to a JSON object, prefixed with
 *              "json:" (for use through the JSON pseudo protocol) and put here.
 */
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
other options; so reading and writing must return the same
results, but caching etc. may be different)
- full_open_options: Options which, when given when opening a block device
(without a filename), result in a BDS (mostly)
equalling the given one
- filename: If exact_filename is set, it is copied here. Otherwise,
full_open_options is converted to a JSON object, prefixed with
"json:" (for use through the JSON pseudo protocol) and put here.
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 other options ; so reading and writing must return the same results but caching etc . may be different ) - full_open_options : Options which when given when opening a block device ( without a filename ) result in a BDS ( mostly ) equalling the given one - filename : If exact_filename is set it is copied here . Otherwise full_open_options is converted to a JSON object prefixed with " json : " ( for use through the JSON pseudo protocol ) and put here .
void bdrv_refresh_filename(BlockDriverState *bs)
{
    BlockDriver *drv = bs->drv;
    QDict *opts;
    if (!drv) {
        return;
    }
    if (bs->file) {
        bdrv_refresh_filename(bs->file->bs);
    }
    if (drv->bdrv_refresh_filename) {
        bs->exact_filename[0] = '\0';
        if (bs->full_open_options) {
            qobject_unref(bs->full_open_options);
            bs->full_open_options = NULL;
        }
        opts = qdict_new();
        append_open_options(opts, bs);
        drv->bdrv_refresh_filename(bs, opts);
        qobject_unref(opts);
    } else if (bs->file) {
        bool has_open_options;
        bs->exact_filename[0] = '\0';
        if (bs->full_open_options) {
            qobject_unref(bs->full_open_options);
            bs->full_open_options = NULL;
        }
        opts = qdict_new();
        has_open_options = append_open_options(opts, bs);
        if (bs->file->bs->exact_filename[0] && !has_open_options) {
            strcpy(bs->exact_filename, bs->file->bs->exact_filename);
        }
        if (bs->file->bs->full_open_options) {
            qdict_put_str(opts, "driver", drv->format_name);
            qdict_put(opts, "file",
                      qobject_ref(bs->file->bs->full_open_options));
            bs->full_open_options = opts;
        } else {
            qobject_unref(opts);
        }
    } else if (!bs->full_open_options && qdict_size(bs->options)) {
        opts = qdict_new();
        append_open_options(opts, bs);
        qdict_put_str(opts, "driver", drv->format_name);
        if (bs->exact_filename[0]) {
            qdict_put_str(opts, "filename", bs->exact_filename);
        }
        bs->full_open_options = opts;
    }
    if (bs->exact_filename[0]) {
        pstrcpy(bs->filename, sizeof(bs->filename), bs->exact_filename);
    } else if (bs->full_open_options) {
        QString *json = qobject_to_json(QOBJECT(bs->full_open_options));
        snprintf(bs->filename, sizeof(bs->filename), "json:%s",
                 qstring_get_str(json));
        qobject_unref(json);
    }
}
void bdrv_refresh_filename ( BlockDriverState * bs ) { BlockDriver * drv = bs -> drv ; QDict * opts ; if ( ! drv ) { return ; } if ( bs -> file ) { bdrv_refresh_filename ( bs -> file -> bs ) ; } if ( drv -> bdrv_refresh_filename ) { bs -> exact_filename [ 0 ] = ' \0 ' ; if ( bs -> full_open_options ) { qobject_unref ( bs -> full_open_options ) ; bs -> full_open_options = NULL ; } opts = qdict_new ( ) ; append_open_options ( opts , bs ) ; drv -> bdrv_refresh_filename ( bs , opts ) ; qobject_unref ( opts ) ; } else if ( bs -> file ) { bool has_open_options ; bs -> exact_filename [ 0 ] = ' \0 ' ; if ( bs -> full_open_options ) { qobject_unref ( bs -> full_open_options ) ; bs -> full_open_options = NULL ; } opts = qdict_new ( ) ; has_open_options = append_open_options ( opts , bs ) ; if ( bs -> file -> bs -> exact_filename [ 0 ] && ! has_open_options ) { strcpy ( bs -> exact_filename , bs -> file -> bs -> exact_filename ) ; } if ( bs -> file -> bs -> full_open_options ) { qdict_put_str ( opts , " " , drv -> format_name ) ; qdict_put ( opts , " " , qobject_ref ( bs -> file -> bs -> full_open_options ) ) ; bs -> full_open_options = opts ; } else { qobject_unref ( opts ) ; } } else if ( ! bs -> full_open_options && qdict_size ( bs -> options ) ) { opts = qdict_new ( ) ; append_open_options ( opts , bs ) ; qdict_put_str ( opts , " " , drv -> format_name ) ; if ( bs -> exact_filename [ 0 ] ) { qdict_put_str ( opts , " " , bs -> exact_filename ) ; } bs -> full_open_options = opts ; } if ( bs -> exact_filename [ 0 ] ) { pstrcpy ( bs -> filename , sizeof ( bs -> filename ) , bs -> exact_filename ) ; } else if ( bs -> full_open_options ) { QString * json = qobject_to_json ( QOBJECT ( bs -> full_open_options ) ) ; snprintf ( bs -> filename , sizeof ( bs -> filename ) , " " , qstring_get_str ( json ) ) ; qobject_unref ( json ) ; } }
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
                    other options; so reading and writing must return the same
                    results, but caching etc.
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 other options ; so reading and writing must return the same results but caching etc .
/* This BDS's file name will most probably depend on its file's name, so
     * refresh that first */ /* Obsolete information is of no use here, so drop the old file name
         * information before refreshing it */ /* Try to reconstruct valid information from the underlying file */ /* If no specific options have been given for this BDS, the filename of
         * the underlying file should suffice for this one as well */ /* 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. */ /* There is no underlying file BDS (at least referenced by BDS.file),
         * so the full options QDict should be equal to the options given
         * specifically for this block device when it was opened (plus the
         * driver specification).
         * Because those options don't change, there is no need to update
         * full_open_options when it's already set. */ /* This may not work for all block protocol drivers (some may
             * require this filename to be parsed), but we have to find some
             * default solution here, so just include it. If some block driver
             * does not support pure options without any filename at all or
             * needs some special format of the options QDict, it needs to
             * implement the driver-specific bdrv_refresh_filename() function.
             */