[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/19] block: Add bdrv_default_refresh_format_filena
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH 04/19] block: Add bdrv_default_refresh_format_filename |
Date: |
Tue, 26 Apr 2016 23:32:03 +0200 |
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 <address@hidden>
---
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
- [Qemu-devel] [PATCH 00/19] block: Fix some filename generation issues, Max Reitz, 2016/04/26
- [Qemu-devel] [PATCH 02/19] block: Add BDS.backing_overridden, Max Reitz, 2016/04/26
- [Qemu-devel] [PATCH 01/19] block: Use children list in bdrv_refresh_filename, Max Reitz, 2016/04/26
- [Qemu-devel] [PATCH 04/19] block: Add bdrv_default_refresh_format_filename,
Max Reitz <=
- [Qemu-devel] [PATCH 03/19] block: Respect backing bs in bdrv_refresh_filename, Max Reitz, 2016/04/26
- [Qemu-devel] [PATCH 05/19] block: Add bdrv_default_refresh_protocol_filename, Max Reitz, 2016/04/26
- [Qemu-devel] [PATCH 09/19] block: bdrv_get_full_backing_filename_from_...'s ret. val., Max Reitz, 2016/04/26
- [Qemu-devel] [PATCH 06/19] block: Make bdrv_default_refresh_format_filename public, Max Reitz, 2016/04/26
- [Qemu-devel] [PATCH 07/19] qcow2: Implement bdrv_refresh_filename(), Max Reitz, 2016/04/26
- [Qemu-devel] [PATCH 10/19] block: bdrv_get_full_backing_filename's ret. val., Max Reitz, 2016/04/26
- [Qemu-devel] [PATCH 12/19] block: Fix bdrv_find_backing_image(), Max Reitz, 2016/04/26
- [Qemu-devel] [PATCH 08/19] block: Make path_combine() return the path, Max Reitz, 2016/04/26
- [Qemu-devel] [PATCH 15/19] quorum: Make bdrv_dirname() return NULL, Max Reitz, 2016/04/26
- [Qemu-devel] [PATCH 11/19] block: Add bdrv_make_absolute_filename(), Max Reitz, 2016/04/26