diff mbox

[v3,09/14] qemu-io: Use blk_new_open() in openfile()

Message ID 1422284444-12529-10-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Jan. 26, 2015, 3 p.m. UTC
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 qemu-io.c | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)

Comments

Eric Blake Jan. 27, 2015, 4:23 p.m. UTC | #1
On 01/26/2015 08:00 AM, Max Reitz wrote:
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  qemu-io.c | 31 ++++++++++++-------------------
>  1 file changed, 12 insertions(+), 19 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
Kevin Wolf Feb. 2, 2015, 7:34 p.m. UTC | #2
Am 26.01.2015 um 16:00 hat Max Reitz geschrieben:
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  qemu-io.c | 31 ++++++++++++-------------------
>  1 file changed, 12 insertions(+), 19 deletions(-)
> 
> diff --git a/qemu-io.c b/qemu-io.c
> index 91a445a..81f8f64 100644
> --- a/qemu-io.c
> +++ b/qemu-io.c
> @@ -39,7 +39,6 @@ static ReadLineState *readline_state;
>  static int close_f(BlockDriverState *bs, int argc, char **argv)
>  {
>      blk_unref(qemuio_blk);
> -    qemuio_bs = NULL;
>      qemuio_blk = NULL;
>      return 0;
>  }

This doesn't seem to be correct at this point in the series. qemuio_bs
is still passed to qemuio_command(), which checks whether non-global
commands are allowed to run using init_check_command().

At the end of the series, please remove qemuio_bs altogether. This
version of the series leaves it around without any reader.

Kevin
Max Reitz Feb. 2, 2015, 7:51 p.m. UTC | #3
On 2015-02-02 at 14:34, Kevin Wolf wrote:
> Am 26.01.2015 um 16:00 hat Max Reitz geschrieben:
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>   qemu-io.c | 31 ++++++++++++-------------------
>>   1 file changed, 12 insertions(+), 19 deletions(-)
>>
>> diff --git a/qemu-io.c b/qemu-io.c
>> index 91a445a..81f8f64 100644
>> --- a/qemu-io.c
>> +++ b/qemu-io.c
>> @@ -39,7 +39,6 @@ static ReadLineState *readline_state;
>>   static int close_f(BlockDriverState *bs, int argc, char **argv)
>>   {
>>       blk_unref(qemuio_blk);
>> -    qemuio_bs = NULL;
>>       qemuio_blk = NULL;
>>       return 0;
>>   }
> This doesn't seem to be correct at this point in the series. qemuio_bs
> is still passed to qemuio_command(), which checks whether non-global
> commands are allowed to run using init_check_command().

$ ./qemu-io -c close -c 'read 0 64k' test.qcow2
read failed: No medium found

Yep, will fix. Thanks for catching it!

> At the end of the series, please remove qemuio_bs altogether. This
> version of the series leaves it around without any reader.

Okay, will do.

Max
diff mbox

Patch

diff --git a/qemu-io.c b/qemu-io.c
index 91a445a..81f8f64 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -39,7 +39,6 @@  static ReadLineState *readline_state;
 static int close_f(BlockDriverState *bs, int argc, char **argv)
 {
     blk_unref(qemuio_blk);
-    qemuio_bs = NULL;
     qemuio_blk = NULL;
     return 0;
 }
@@ -51,34 +50,29 @@  static const cmdinfo_t close_cmd = {
     .oneline    = "close the current open file",
 };
 
-static int openfile(char *name, BlockDriver *drv, int flags, int growable,
-                    QDict *opts)
+static int openfile(char *name, int flags, int growable, QDict *opts)
 {
     Error *local_err = NULL;
 
-    if (qemuio_bs) {
+    if (qemuio_blk) {
         fprintf(stderr, "file open already, try 'help close'\n");
         QDECREF(opts);
         return 1;
     }
 
-    qemuio_blk = blk_new_with_bs("hda", &error_abort);
-    qemuio_bs = blk_bs(qemuio_blk);
-
     if (growable) {
         flags |= BDRV_O_PROTOCOL;
     }
 
-    if (bdrv_open(&qemuio_bs, name, NULL, opts, flags, drv, &local_err) < 0) {
+    qemuio_blk = blk_new_open("hda", name, NULL, opts, flags, &local_err);
+    if (!qemuio_blk) {
         fprintf(stderr, "%s: can't open%s%s: %s\n", progname,
                 name ? " device " : "", name ?: "",
                 error_get_pretty(local_err));
         error_free(local_err);
-        blk_unref(qemuio_blk);
-        qemuio_bs = NULL;
-        qemuio_blk = NULL;
         return 1;
     }
+    qemuio_bs = blk_bs(qemuio_blk);
 
     return 0;
 }
@@ -170,9 +164,9 @@  static int open_f(BlockDriverState *bs, int argc, char **argv)
     qemu_opts_reset(&empty_opts);
 
     if (optind == argc - 1) {
-        return openfile(argv[optind], NULL, flags, growable, opts);
+        return openfile(argv[optind], flags, growable, opts);
     } else if (optind == argc) {
-        return openfile(NULL, NULL, flags, growable, opts);
+        return openfile(NULL, flags, growable, opts);
     } else {
         QDECREF(opts);
         return qemuio_command_usage(&open_cmd);
@@ -387,8 +381,8 @@  int main(int argc, char **argv)
     int c;
     int opt_index = 0;
     int flags = BDRV_O_UNMAP;
-    BlockDriver *drv = NULL;
     Error *local_error = NULL;
+    QDict *opts = NULL;
 
 #ifdef CONFIG_POSIX
     signal(SIGPIPE, SIG_IGN);
@@ -414,11 +408,10 @@  int main(int argc, char **argv)
             }
             break;
         case 'f':
-            drv = bdrv_find_format(optarg);
-            if (!drv) {
-                error_report("Invalid format '%s'", optarg);
-                exit(EXIT_FAILURE);
+            if (!opts) {
+                opts = qdict_new();
             }
+            qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str(optarg)));
             break;
         case 'c':
             add_user_command(optarg);
@@ -489,7 +482,7 @@  int main(int argc, char **argv)
     }
 
     if ((argc - optind) == 1) {
-        openfile(argv[optind], drv, flags, growable, NULL);
+        openfile(argv[optind], flags, growable, opts);
     }
     command_loop();