qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
	jsnow@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 1/5] qemu-io: Don't die on second open
Date: Thu, 25 May 2017 08:50:37 +0800	[thread overview]
Message-ID: <20170525005037.GA27936@lemon.lan> (raw)
In-Reply-To: <20170524202842.26724-2-eblake@redhat.com>

On Wed, 05/24 15:28, Eric Blake wrote:
> Most callback commands in qemu-io return 0 to keep the interpreter
> loop running, or 1 to quit immediately.  However, open_f() just
> passed through the return value of openfile(), which has different
> semantics of returning 0 if a file was opened, or 1 on any failure.
> 
> As a result of mixing the return semantics, we are forcing the
> qemu-io interpreter to exit early on any failures, which is rather
> annoying when some of the failures are obviously trying to give
> the user a hint of how to proceed (if we didn't then kill qemu-io
> out from under the user's feet):
> 
> $ qemu-io
> qemu-io> open foo
> qemu-io> open foo
> file open already, try 'help close'
> $ echo $?
> 0
> 
> Meanwhile, we WANT openfile() to report failures, as it is the
> way that 'qemu-io -c "$something" no_such_file' knows to exit
> early rather than attempting $something.  So the solution is to
> fix open_f() to always return 0 (when we are in interactive mode,
> even failure to open should not end the session), and save the
> return value of openfile() for command line use in main().
> 
> This has been awkward since at least as far back as commit
> e3aff4f, in 2009.
> 
> Signed-off-by: Eric Blake <eblake@redhat.com>
> 
> ---
> v2: fix open_f(), not openfile()
> ---
>  qemu-io.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/qemu-io.c b/qemu-io.c
> index 34fa8a1..b3febc2 100644
> --- a/qemu-io.c
> +++ b/qemu-io.c
> @@ -230,13 +230,14 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
>      qemu_opts_reset(&empty_opts);
> 
>      if (optind == argc - 1) {
> -        return openfile(argv[optind], flags, writethrough, force_share, opts);
> +        openfile(argv[optind], flags, writethrough, force_share, opts);
>      } else if (optind == argc) {
> -        return openfile(NULL, flags, writethrough, force_share, opts);
> +        openfile(NULL, flags, writethrough, force_share, opts);
>      } else {
>          QDECREF(opts);
> -        return qemuio_command_usage(&open_cmd);
> +        qemuio_command_usage(&open_cmd);
>      }
> +    return 0;
>  }
> 
>  static int quit_f(BlockBackend *blk, int argc, char **argv)
> -- 
> 2.9.4
> 
> 

This is better, thanks!

Reviewed-by: Fam Zheng <famz@redhat.com>

  reply	other threads:[~2017-05-25  0:50 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24 20:28 [Qemu-devel] [PATCH v2 0/5] more blkdebug tweaks Eric Blake
2017-05-24 20:28 ` [Qemu-devel] [PATCH v2 1/5] qemu-io: Don't die on second open Eric Blake
2017-05-25  0:50   ` Fam Zheng [this message]
2017-05-31 14:18   ` Max Reitz
2017-05-31 15:12     ` Eric Blake
2017-05-31 15:56       ` Max Reitz
2017-05-24 20:28 ` [Qemu-devel] [PATCH v2 2/5] block: Guarantee that *file is set on bdrv_get_block_status() Eric Blake
2017-05-25  6:18   ` Fam Zheng
2017-05-31 14:42   ` Max Reitz
2017-05-24 20:28 ` [Qemu-devel] [PATCH v2 3/5] block: Allow NULL file for bdrv_get_block_status() Eric Blake
2017-05-25  6:34   ` Fam Zheng
2017-05-25 13:57     ` Eric Blake
2017-05-31 14:53     ` Max Reitz
2017-05-24 20:28 ` [Qemu-devel] [PATCH v2 4/5] block: Simplify use of BDRV_BLOCK_RAW Eric Blake
2017-05-25  6:35   ` Fam Zheng
2017-05-31 14:56   ` Max Reitz
2017-05-24 20:28 ` [Qemu-devel] [PATCH v2 5/5] blkdebug: Support .bdrv_co_get_block_status Eric Blake
2017-05-25  6:37   ` Fam Zheng
2017-05-31 15:00   ` Max Reitz
2017-05-25 14:36 ` [Qemu-devel] [PATCH v2 0/5] more blkdebug tweaks Fam Zheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170525005037.GA27936@lemon.lan \
    --to=famz@redhat.com \
    --cc=eblake@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).