diff mbox

[v5,15/22] blkdebug: Allow command-line file configuration

Message ID 1386954633-28905-16-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Dec. 13, 2013, 5:10 p.m. UTC
Introduce the "image" option as an alternative to specifying the image
through the filename.

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

Comments

Kevin Wolf Dec. 13, 2013, 8:36 p.m. UTC | #1
Am 13.12.2013 um 18:10 hat Max Reitz geschrieben:
> Introduce the "image" option as an alternative to specifying the image
> through the filename.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>

One thing I'd like to see, either in the next version or in a follow-up
series, is to generalise open_image() into a block.c function.

The main difference between blkdebug and blkverify seems to be that
blkverify does image format probing on its main image. This can be a
bool argument to open_image().

Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Max Reitz Dec. 13, 2013, 11:57 p.m. UTC | #2
On 13.12.2013 21:36, Kevin Wolf wrote:
> Am 13.12.2013 um 18:10 hat Max Reitz geschrieben:
>> Introduce the "image" option as an alternative to specifying the image
>> through the filename.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
> One thing I'd like to see, either in the next version or in a follow-up
> series, is to generalise open_image() into a block.c function.

Yes, I thought of something like that myself. I think, eventually we 
need to merge bdrv_open() and bdrv_file_open() (now that "file"s can be 
nested and there may be block devices without "file"s, there is no 
actual need to separate both).

> The main difference between blkdebug and blkverify seems to be that
> blkverify does image format probing on its main image. This can be a
> bool argument to open_image().

I think, blkdebug should just force the raw driver with a common 
open_image().

Max
diff mbox

Patch

diff --git a/block/blkdebug.c b/block/blkdebug.c
index c73a6cf..0c800ae 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -368,13 +368,35 @@  static QemuOptsList runtime_opts = {
     },
 };
 
+static int open_image(BlockDriverState **pbs, const char *fname, QDict *options,
+                      const char *bdref_key, int flags, Error **errp)
+{
+    QDict *image_options;
+    int ret;
+    char *bdref_key_dot;
+
+    bdref_key_dot = g_strdup_printf("%s.", bdref_key);
+    qdict_extract_subqdict(options, &image_options, bdref_key_dot);
+    g_free(bdref_key_dot);
+
+    /* Never use bdrv_open() here; if just a filename is given without further
+       options, bdrv_open() will try to open it with the block driver we are
+       about to test. bdrv_file_open() never does this. */
+    ret = bdrv_file_open(pbs, fname, qdict_get_try_str(options, bdref_key),
+                         image_options, flags, errp);
+
+    qdict_del(options, bdref_key);
+
+    return ret;
+}
+
 static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
                          Error **errp)
 {
     BDRVBlkdebugState *s = bs->opaque;
     QemuOpts *opts;
     Error *local_err = NULL;
-    const char *filename, *config;
+    const char *config;
     int ret;
 
     opts = qemu_opts_create_nofail(&runtime_opts);
@@ -396,14 +418,8 @@  static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
     s->state = 1;
 
     /* Open the backing file */
-    filename = qemu_opt_get(opts, "x-image");
-    if (filename == NULL) {
-        error_setg(errp, "Could not retrieve image file name");
-        ret = -EINVAL;
-        goto fail;
-    }
-
-    ret = bdrv_file_open(&bs->file, filename, NULL, NULL, flags, &local_err);
+    ret = open_image(&bs->file, qemu_opt_get(opts, "x-image"), options, "image",
+                     flags, &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         goto fail;