From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [PATCH 04/28] qemu-img: global option processing and error printing
Date: Mon, 26 Feb 2024 15:40:25 +0000 [thread overview]
Message-ID: <Zdyw6Z1a8r8atJqi@redhat.com> (raw)
In-Reply-To: <20240221211622.2335170-4-mjt@tls.msk.ru>
On Thu, Feb 22, 2024 at 12:15:45AM +0300, Michael Tokarev wrote:
> In order to correctly print executable name in various
> error messages, pass argv[0] to error_exit() function.
> This way, error messages will refer to actual executable
> name, which may be different from 'qemu-img'.
>
> For subcommands, pass whole argv[] array, so argv[0] is
> the executable name, not subcommand name. In order to
> do that, avoid resetting optind but continue with the
> next option. Also don't require at least 3 options on
> the command line: it makes no sense with options before
> subcommand.
>
> Before invoking a subcommand, replace argv[0] to include
> the subcommand name.
>
> Introduce tryhelp() function which just prints
>
> try 'command-name --help' for more info
>
> and exits. When tryhelp() is called from within a subcommand
> handler, the message will look like:
>
> try 'command-name subcommand --help' for more info
>
> qemu-img uses getopt_long() with ':' as the first char in
> optstring parameter, which means it doesn't print error
> messages but return ':' or '?' instead, and qemu-img uses
> unrecognized_option() or missing_argument() function to
> print error messages. But it doesn't quite work:
>
> $ ./qemu-img -xx
> qemu-img: unrecognized option './qemu-img'
>
> so the aim is to let getopt_long() to print regular error
> messages instead (removing ':' prefix from optstring) and
> remove handling of '?' and ':' "options" entirely. With
> concatenated argv[0] and the subcommand, it all finally
> does the right thing in all cases. This will be done in
> subsequent changes command by command, with main() done
> last.
>
> unrecognized_option() and missing_argument() functions
> prototypes aren't changed by this patch, since they're
> called from many places and will be removed a few patches
> later. Only artifical "qemu-img" argv0 is provided in
> there for now.
>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> qemu-img.c | 75 +++++++++++++++++++++++++++---------------------------
> 1 file changed, 38 insertions(+), 37 deletions(-)
I'm not sure how, but this change seems to have broken the iotests.
Just one example:
$ (cd tests/qemu-iotests/ && ./check -qcow2 249)
QEMU -- "/var/home/berrange/src/virt/qemu/build/qemu-system-x86_64" -nodefaults -display none -accel qtest
QEMU_IMG -- "/var/home/berrange/src/virt/qemu/build/qemu-img"
QEMU_IO -- "/var/home/berrange/src/virt/qemu/build/qemu-io" --cache writeback --aio threads -f qcow2
QEMU_NBD -- "/var/home/berrange/src/virt/qemu/build/qemu-nbd"
IMGFMT -- qcow2
IMGPROTO -- file
PLATFORM -- Linux/x86_64 toolbox 6.6.12-200.fc39.x86_64
TEST_DIR -- /var/home/berrange/src/virt/qemu/build/tests/qemu-iotests/scratch
SOCK_DIR -- /tmp/qemu-iotests-0t8h94bu
GDB_OPTIONS --
VALGRIND_QEMU --
PRINT_QEMU_OUTPUT --
249 fail [15:39:25] [15:39:25] 0.2s (last: 0.4s) failed, exit status 1
--- /var/home/berrange/src/virt/qemu/tests/qemu-iotests/249.out
+++ /var/home/berrange/src/virt/qemu/build/tests/qemu-iotests/scratch/qcow2-file-249/249.out.bad
@@ -1,47 +1,7 @@
QA output created by 249
Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=1048576
-Formatting 'TEST_DIR/t.IMGFMT.int', fmt=IMGFMT size=1048576 backing_file=TEST_DIR/t.IMGFMT.base backing_fmt=IMGFMT
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 backing_file=TEST_DIR/t.IMGFMT.int backing_fmt=IMGFMT
-{ 'execute': 'qmp_capabilities' }
-{"return": {}}
...snip....
-*** done
+qemu-img: Invalid image size specified. You may use k, M, G, T, P or E suffixes for
+qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabytes.
+qemu-img: Invalid image size specified. You may use k, M, G, T, P or E suffixes for
+qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabytes.
+Timeout waiting for capabilities on handle 0
Failures: 249
Failed 1 of 1 iotests
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2024-02-26 15:41 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-21 21:15 [PATCH v2 00/28] qemu-img: refersh options and --help handling, cleanups Michael Tokarev
2024-02-21 21:15 ` [PATCH 01/28] qemu-img: stop printing error twice in a few places Michael Tokarev
2024-02-26 14:14 ` Daniel P. Berrangé
2024-02-26 18:58 ` Michael Tokarev
2024-02-26 16:37 ` Michael Tokarev
2024-02-21 21:15 ` [PATCH 02/28] qemu-img: measure: convert img_size to signed, simplify handling Michael Tokarev
2024-02-26 14:19 ` Daniel P. Berrangé
2024-02-21 21:15 ` [PATCH 03/28] qemu-img: create: " Michael Tokarev
2024-02-26 14:19 ` Daniel P. Berrangé
2024-02-21 21:15 ` [PATCH 04/28] qemu-img: global option processing and error printing Michael Tokarev
2024-02-26 14:23 ` Daniel P. Berrangé
2024-02-26 15:40 ` Daniel P. Berrangé [this message]
2024-02-21 21:13 ` [PATCH v2.1 " Michael Tokarev
2024-02-26 15:43 ` [PATCH " Michael Tokarev
2024-02-26 16:25 ` Michael Tokarev
2024-02-21 21:15 ` [PATCH 05/28] qemu-img: pass current cmd info into command handlers Michael Tokarev
2024-02-26 14:24 ` Daniel P. Berrangé
2024-02-21 21:15 ` [PATCH 06/28] qemu-img: create: refresh options/--help Michael Tokarev
2024-02-26 14:34 ` Daniel P. Berrangé
2024-02-26 14:37 ` Michael Tokarev
2024-02-21 21:15 ` [PATCH 07/28] qemu-img: factor out parse_output_format() and use it in the code Michael Tokarev
2024-02-21 21:15 ` [PATCH 08/28] qemu-img: check: refresh options/--help Michael Tokarev
2024-02-21 21:15 ` [PATCH 09/28] qemu-img: simplify --repair error message Michael Tokarev
2024-02-21 21:15 ` [PATCH 10/28] qemu-img: commit: refresh options/--help Michael Tokarev
2024-02-21 21:15 ` [PATCH 11/28] qemu-img: compare: " Michael Tokarev
2024-02-21 21:15 ` [PATCH 12/28] qemu-img: convert: " Michael Tokarev
2024-02-21 21:15 ` [PATCH 13/28] qemu-img: info: " Michael Tokarev
2024-02-21 21:15 ` [PATCH 14/28] qemu-img: map: " Michael Tokarev
2024-02-21 21:15 ` [PATCH 15/28] qemu-img: snapshot: allow specifying -f fmt Michael Tokarev
2024-02-21 21:15 ` [PATCH 16/28] qemu-img: snapshot: make -l (list) the default, simplify option handling Michael Tokarev
2024-02-26 14:36 ` Daniel P. Berrangé
2024-02-21 21:15 ` [PATCH 17/28] qemu-img: snapshot: refresh options/--help Michael Tokarev
2024-02-21 21:15 ` [PATCH 18/28] qemu-img: rebase: " Michael Tokarev
2024-02-21 21:16 ` [PATCH 19/28] qemu-img: resize: do not always eat last argument Michael Tokarev
2024-02-26 14:52 ` Daniel P. Berrangé
2024-02-26 14:59 ` Michael Tokarev
2024-02-21 21:16 ` [PATCH 20/28] qemu-img: resize: refresh options/--help Michael Tokarev
2024-02-21 21:16 ` [PATCH 21/28] qemu-img: amend: " Michael Tokarev
2024-02-21 21:16 ` [PATCH 22/28] qemu-img: bench: " Michael Tokarev
2024-02-21 21:16 ` [PATCH 23/28] qemu-img: bitmap: " Michael Tokarev
2024-02-21 21:16 ` [PATCH 24/28] qemu-img: dd: " Michael Tokarev
2024-02-21 21:16 ` [PATCH 25/28] qemu-img: measure: " Michael Tokarev
2024-02-21 21:16 ` [PATCH 26/28] qemu-img: implement short --help, remove global help() function Michael Tokarev
2024-02-26 14:53 ` Daniel P. Berrangé
2024-02-21 21:16 ` [PATCH 27/28] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include Michael Tokarev
2024-02-26 14:54 ` Daniel P. Berrangé
2024-02-21 21:16 ` [PATCH 28/28] qemu-img: extend cvtnum() and use it in more places Michael Tokarev
2024-02-26 14:57 ` Daniel P. Berrangé
2024-02-26 19:16 ` Michael Tokarev
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=Zdyw6Z1a8r8atJqi@redhat.com \
--to=berrange@redhat.com \
--cc=mjt@tls.msk.ru \
--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).