diff mbox

[05/19] block: Add bdrv_default_refresh_protocol_filename

Message ID 1461706338-20219-6-git-send-email-mreitz@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Max Reitz April 26, 2016, 9:32 p.m. UTC
Split off the default code for protocol BDS from bdrv_refresh_filename()
into an own function, just as it has been done for format BDS.

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

Comments

Alberto Garcia June 20, 2016, 1:18 p.m. UTC | #1
On Tue 26 Apr 2016 11:32:04 PM CEST, Max Reitz wrote:
> Split off the default code for protocol BDS from bdrv_refresh_filename()
> into an own function, just as it has been done for format BDS.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>

Reviewed-by: Alberto Garcia <berto@igalia.com>

Berto
diff mbox

Patch

diff --git a/block.c b/block.c
index 447468c..511a0b1 100644
--- a/block.c
+++ b/block.c
@@ -3922,6 +3922,38 @@  static void bdrv_default_refresh_format_filename(BlockDriverState *bs)
     }
 }
 
+static void bdrv_default_refresh_protocol_filename(BlockDriverState *bs)
+{
+    BlockDriver *drv = bs->drv;
+    QDict *opts;
+
+    /* 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. */
+
+    opts = qdict_new();
+    append_open_options(opts, bs);
+    qdict_put_obj(opts, "driver",
+                  QOBJECT(qstring_from_str(drv->format_name)));
+
+    if (bs->exact_filename[0]) {
+        /* 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.
+         */
+        qdict_put_obj(opts, "filename",
+                      QOBJECT(qstring_from_str(bs->exact_filename)));
+    }
+
+    bs->full_open_options = 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
@@ -3967,31 +3999,7 @@  void bdrv_refresh_filename(BlockDriverState *bs)
         /* Try to reconstruct valid information from the underlying file */
         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
-         * 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. */
-
-        opts = qdict_new();
-        append_open_options(opts, bs);
-        qdict_put_obj(opts, "driver",
-                      QOBJECT(qstring_from_str(drv->format_name)));
-
-        if (bs->exact_filename[0]) {
-            /* 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.
-             */
-            qdict_put_obj(opts, "filename",
-                          QOBJECT(qstring_from_str(bs->exact_filename)));
-        }
-
-        bs->full_open_options = opts;
+        bdrv_default_refresh_protocol_filename(bs);
     }
 
     if (bs->exact_filename[0]) {