From nobody Thu May 2 14:16:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490630161345772.0502783034335; Mon, 27 Mar 2017 08:56:01 -0700 (PDT) Received: from localhost ([::1]:47734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWzw-0003fx-1c for importer@patchew.org; Mon, 27 Mar 2017 11:56:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWwp-0001S2-3R for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:52:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csWwo-0006CZ-HX for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:52:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55470) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csWwm-0006Aw-Gs; Mon, 27 Mar 2017 11:52:44 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7795764473; Mon, 27 Mar 2017 15:52:43 +0000 (UTC) Received: from localhost (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 28E6681C0A; Mon, 27 Mar 2017 15:52:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7795764473 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mreitz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7795764473 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 27 Mar 2017 17:52:29 +0200 Message-Id: <20170327155234.10980-2-mreitz@redhat.com> In-Reply-To: <20170327155234.10980-1-mreitz@redhat.com> References: <20170327155234.10980-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 27 Mar 2017 15:52:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/6] qemu-img: show help for invalid global options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi The qemu-img sub-command executes regardless of invalid global options: $ qemu-img --foo info test.img qemu-img: unrecognized option '--foo' image: test.img ... The unrecognized option warning may be missed by the user. This can hide incorrect command-lines in scripts and confuse users. This patch prints the help information and terminates instead of executing the sub-command. Signed-off-by: Stefan Hajnoczi Message-id: 20170317104541.28979-2-stefanha@redhat.com Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- qemu-img.c | 1 + 1 file changed, 1 insertion(+) diff --git a/qemu-img.c b/qemu-img.c index 98b836b030..ce293a4710 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4339,6 +4339,7 @@ int main(int argc, char **argv) while ((c =3D getopt_long(argc, argv, "+hVT:", long_options, NULL)) != =3D -1) { switch (c) { case 'h': + case '?': help(); return 0; case 'V': --=20 2.12.1 From nobody Thu May 2 14:16:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490630368079426.1977227048768; Mon, 27 Mar 2017 08:59:28 -0700 (PDT) Received: from localhost ([::1]:47746 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csX3G-0006Kz-B0 for importer@patchew.org; Mon, 27 Mar 2017 11:59:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWx0-0001Zj-DT for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:52:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csWwz-0006JN-6R for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:52:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34030) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csWwq-0006DS-Jb; Mon, 27 Mar 2017 11:52:48 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 894748123E; Mon, 27 Mar 2017 15:52:47 +0000 (UTC) Received: from localhost (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6B60182FBC; Mon, 27 Mar 2017 15:52:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 894748123E Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mreitz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 894748123E From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 27 Mar 2017 17:52:30 +0200 Message-Id: <20170327155234.10980-3-mreitz@redhat.com> In-Reply-To: <20170327155234.10980-1-mreitz@redhat.com> References: <20170327155234.10980-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 27 Mar 2017 15:52:47 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/6] qemu-img: fix switch indentation in img_amend() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi QEMU coding style indents 'case' to the same level as the 'switch' statement: switch (foo) { case 1: Fix this coding style violation so checkpatch.pl doesn't complain about the next patch. Signed-off-by: Stefan Hajnoczi Message-id: 20170317104541.28979-3-stefanha@redhat.com Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Max Reitz --- qemu-img.c | 82 +++++++++++++++++++++++++++++++---------------------------= ---- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index ce293a4710..c7ffabb268 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3500,47 +3500,47 @@ static int img_amend(int argc, char **argv) } =20 switch (c) { - case 'h': - case '?': - help(); - break; - case 'o': - if (!is_valid_option_list(optarg)) { - error_report("Invalid option list: %s", optarg); - ret =3D -1; - goto out_no_progress; - } - if (!options) { - options =3D g_strdup(optarg); - } else { - char *old_options =3D options; - options =3D g_strdup_printf("%s,%s", options, optarg); - g_free(old_options); - } - break; - case 'f': - fmt =3D optarg; - break; - case 't': - cache =3D optarg; - break; - case 'p': - progress =3D true; - break; - case 'q': - quiet =3D true; - break; - case OPTION_OBJECT: - opts =3D qemu_opts_parse_noisily(&qemu_object_opts, - optarg, true); - if (!opts) { - ret =3D -1; - goto out_no_progress; - } - break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; - break; + case 'h': + case '?': + help(); + break; + case 'o': + if (!is_valid_option_list(optarg)) { + error_report("Invalid option list: %s", optarg); + ret =3D -1; + goto out_no_progress; + } + if (!options) { + options =3D g_strdup(optarg); + } else { + char *old_options =3D options; + options =3D g_strdup_printf("%s,%s", options, optarg); + g_free(old_options); + } + break; + case 'f': + fmt =3D optarg; + break; + case 't': + cache =3D optarg; + break; + case 'p': + progress =3D true; + break; + case 'q': + quiet =3D true; + break; + case OPTION_OBJECT: + opts =3D qemu_opts_parse_noisily(&qemu_object_opts, + optarg, true); + if (!opts) { + ret =3D -1; + goto out_no_progress; + } + break; + case OPTION_IMAGE_OPTS: + image_opts =3D true; + break; } } =20 --=20 2.12.1 From nobody Thu May 2 14:16:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490630467926491.24992999059214; Mon, 27 Mar 2017 09:01:07 -0700 (PDT) Received: from localhost ([::1]:47795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csX4s-0007MY-EN for importer@patchew.org; Mon, 27 Mar 2017 12:01:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWx0-0001a8-Sr for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:53:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csWwz-0006JS-6n for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:52:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38132) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csWwt-0006Eo-9X; Mon, 27 Mar 2017 11:52:51 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 285FE8046F; Mon, 27 Mar 2017 15:52:50 +0000 (UTC) Received: from localhost (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 79900827A9; Mon, 27 Mar 2017 15:52:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 285FE8046F Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mreitz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 285FE8046F From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 27 Mar 2017 17:52:31 +0200 Message-Id: <20170327155234.10980-4-mreitz@redhat.com> In-Reply-To: <20170327155234.10980-1-mreitz@redhat.com> References: <20170327155234.10980-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 27 Mar 2017 15:52:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/6] qemu-img: print short help on getopt failure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Printing the full help output obscures the error message for an invalid command-line option or missing argument. Before this patch: $ ./qemu-img --foo ...pages of output... After this patch: $ ./qemu-img --foo qemu-img: unrecognized option '--foo' Try 'qemu-img --help' for more information This patch adds the getopt ':' character so that it can distinguish between missing arguments and unrecognized options. This helps provide more detailed error messages. Suggested-by: Max Reitz Signed-off-by: Stefan Hajnoczi Message-id: 20170317104541.28979-4-stefanha@redhat.com Reviewed-by: Max Reitz Signed-off-by: Max Reitz --- qemu-img.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++-------= ---- 1 file changed, 97 insertions(+), 20 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index c7ffabb268..b220cf71d7 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -88,6 +88,16 @@ static void QEMU_NORETURN GCC_FMT_ATTR(1, 2) error_exit(= const char *fmt, ...) exit(EXIT_FAILURE); } =20 +static void QEMU_NORETURN missing_argument(const char *option) +{ + error_exit("missing argument for option '%s'", option); +} + +static void QEMU_NORETURN unrecognized_option(const char *option) +{ + error_exit("unrecognized option '%s'", option); +} + /* Please keep in synch with qemu-img.texi */ static void QEMU_NORETURN help(void) { @@ -406,13 +416,18 @@ static int img_create(int argc, char **argv) {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "F:b:f:he6o:q", + c =3D getopt_long(argc, argv, ":F:b:f:he6o:q", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -651,13 +666,18 @@ static int img_check(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hf:r:T:q", + c =3D getopt_long(argc, argv, ":hf:r:T:q", long_options, &option_index); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -855,13 +875,18 @@ static int img_commit(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "f:ht:b:dpq", + c =3D getopt_long(argc, argv, ":f:ht:b:dpq", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -1190,13 +1215,18 @@ static int img_compare(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hf:F:T:pqs", + c =3D getopt_long(argc, argv, ":hf:F:T:pqs", long_options, NULL); if (c =3D=3D -1) { break; } switch (c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -1926,13 +1956,18 @@ static int img_convert(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hf:O:B:ce6o:s:l:S:pt:T:qnm:W", + c =3D getopt_long(argc, argv, ":hf:O:B:ce6o:s:l:S:pt:T:qnm:W", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -2502,13 +2537,18 @@ static int img_info(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "f:h", + c =3D getopt_long(argc, argv, ":f:h", long_options, &option_index); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -2713,13 +2753,18 @@ static int img_map(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "f:h", + c =3D getopt_long(argc, argv, ":f:h", long_options, &option_index); if (c =3D=3D -1) { break; } switch (c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -2835,13 +2880,18 @@ static int img_snapshot(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "la:c:d:hq", + c =3D getopt_long(argc, argv, ":la:c:d:hq", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); return 0; @@ -2988,13 +3038,18 @@ static int img_rebase(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hf:F:b:upt:T:q", + c =3D getopt_long(argc, argv, ":hf:F:b:upt:T:q", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); return 0; @@ -3355,13 +3410,18 @@ static int img_resize(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "f:hq", + c =3D getopt_long(argc, argv, ":f:hq", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -3493,15 +3553,20 @@ static int img_amend(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "ho:f:t:pq", + c =3D getopt_long(argc, argv, ":ho:f:t:pq", long_options, NULL); if (c =3D=3D -1) { break; } =20 switch (c) { - case 'h': + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; + case 'h': help(); break; case 'o': @@ -3759,14 +3824,19 @@ static int img_bench(int argc, char **argv) {"no-drain", no_argument, 0, OPTION_NO_DRAIN}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hc:d:f:no:qs:S:t:w", long_options, = NULL); + c =3D getopt_long(argc, argv, ":hc:d:f:no:qs:S:t:w", long_options,= NULL); if (c =3D=3D -1) { break; } =20 switch (c) { - case 'h': + case ':': + missing_argument(argv[optind - 1]); + break; case '?': + unrecognized_option(argv[optind - 1]); + break; + case 'h': help(); break; case 'c': @@ -4093,7 +4163,7 @@ static int img_dd(int argc, char **argv) { 0, 0, 0, 0 } }; =20 - while ((c =3D getopt_long(argc, argv, "hf:O:", long_options, NULL))) { + while ((c =3D getopt_long(argc, argv, ":hf:O:", long_options, NULL))) { if (c =3D=3D EOF) { break; } @@ -4104,10 +4174,12 @@ static int img_dd(int argc, char **argv) case 'f': fmt =3D optarg; break; + case ':': + missing_argument(argv[optind - 1]); + break; case '?': - error_report("Try 'qemu-img --help' for more information."); - ret =3D -1; - goto out; + unrecognized_option(argv[optind - 1]); + break; case 'h': help(); break; @@ -4336,10 +4408,15 @@ int main(int argc, char **argv) qemu_add_opts(&qemu_source_opts); qemu_add_opts(&qemu_trace_opts); =20 - while ((c =3D getopt_long(argc, argv, "+hVT:", long_options, NULL)) != =3D -1) { + while ((c =3D getopt_long(argc, argv, "+:hVT:", long_options, NULL)) != =3D -1) { switch (c) { - case 'h': + case ':': + missing_argument(argv[optind - 1]); + return 0; case '?': + unrecognized_option(argv[optind - 1]); + return 0; + case 'h': help(); return 0; case 'V': --=20 2.12.1 From nobody Thu May 2 14:16:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490630287457418.81067824860156; Mon, 27 Mar 2017 08:58:07 -0700 (PDT) Received: from localhost ([::1]:47743 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csX1y-0005LS-9P for importer@patchew.org; Mon, 27 Mar 2017 11:58:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWx0-0001ZQ-1L for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:52:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csWwz-0006JI-5e for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:52:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56634) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csWwv-0006G5-K6; Mon, 27 Mar 2017 11:52:53 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 862E96AADE; Mon, 27 Mar 2017 15:52:52 +0000 (UTC) Received: from localhost (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1949981C00; Mon, 27 Mar 2017 15:52:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 862E96AADE Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mreitz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 862E96AADE From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 27 Mar 2017 17:52:32 +0200 Message-Id: <20170327155234.10980-5-mreitz@redhat.com> In-Reply-To: <20170327155234.10980-1-mreitz@redhat.com> References: <20170327155234.10980-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 27 Mar 2017 15:52:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/6] nbd-client: fix handling of hungup connections X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Paolo Bonzini , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini After the switch to reading replies in a coroutine, nothing is reentering pending receive coroutines if the connection hangs. Move nbd_recv_coroutines_enter_all to the reply read coroutine, which is the place where hangups are detected. nbd_teardown_connection can simply wait for the reply read coroutine to detect the hangup and clean up after itself. This wouldn't be enough though because nbd_receive_reply returns 0 (rather than -EPIPE or similar) when reading from a hung connection. Fix the return value check in nbd_read_reply_entry. This fixes qemu-iotests 083. Reported-by: Max Reitz Signed-off-by: Paolo Bonzini Message-id: 20170314111157.14464-1-pbonzini@redhat.com Reviewed-by: Max Reitz Signed-off-by: Max Reitz --- block/nbd-client.c | 12 ++++++------ nbd/client.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 0dc12c2d67..1e2952fdae 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -33,17 +33,15 @@ #define HANDLE_TO_INDEX(bs, handle) ((handle) ^ ((uint64_t)(intptr_t)bs)) #define INDEX_TO_HANDLE(bs, index) ((index) ^ ((uint64_t)(intptr_t)bs)) =20 -static void nbd_recv_coroutines_enter_all(BlockDriverState *bs) +static void nbd_recv_coroutines_enter_all(NBDClientSession *s) { - NBDClientSession *s =3D nbd_get_client_session(bs); int i; =20 for (i =3D 0; i < MAX_NBD_REQUESTS; i++) { if (s->recv_coroutine[i]) { - qemu_coroutine_enter(s->recv_coroutine[i]); + aio_co_wake(s->recv_coroutine[i]); } } - BDRV_POLL_WHILE(bs, s->read_reply_co); } =20 static void nbd_teardown_connection(BlockDriverState *bs) @@ -58,7 +56,7 @@ static void nbd_teardown_connection(BlockDriverState *bs) qio_channel_shutdown(client->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); - nbd_recv_coroutines_enter_all(bs); + BDRV_POLL_WHILE(bs, client->read_reply_co); =20 nbd_client_detach_aio_context(bs); object_unref(OBJECT(client->sioc)); @@ -76,7 +74,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaqu= e) for (;;) { assert(s->reply.handle =3D=3D 0); ret =3D nbd_receive_reply(s->ioc, &s->reply); - if (ret < 0) { + if (ret <=3D 0) { break; } =20 @@ -103,6 +101,8 @@ static coroutine_fn void nbd_read_reply_entry(void *opa= que) aio_co_wake(s->recv_coroutine[i]); qemu_coroutine_yield(); } + + nbd_recv_coroutines_enter_all(s); s->read_reply_co =3D NULL; } =20 diff --git a/nbd/client.c b/nbd/client.c index 3dc2564cd0..a58fb02cb4 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -812,6 +812,6 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *re= ply) LOG("invalid magic (got 0x%" PRIx32 ")", magic); return -EINVAL; } - return 0; + return sizeof(buf); } =20 --=20 2.12.1 From nobody Thu May 2 14:16:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490630062611337.875248260215; Mon, 27 Mar 2017 08:54:22 -0700 (PDT) Received: from localhost ([::1]:47724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWyL-0002RW-8k for importer@patchew.org; Mon, 27 Mar 2017 11:54:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWx2-0001d7-QE for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:53:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csWx1-0006Kx-SR for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:53:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59236) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csWwz-0006Hl-07; Mon, 27 Mar 2017 11:52:57 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED5BCC06510E; Mon, 27 Mar 2017 15:52:54 +0000 (UTC) Received: from localhost (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7DAF381C0F; Mon, 27 Mar 2017 15:52:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ED5BCC06510E Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mreitz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com ED5BCC06510E From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 27 Mar 2017 17:52:33 +0200 Message-Id: <20170327155234.10980-6-mreitz@redhat.com> In-Reply-To: <20170327155234.10980-1-mreitz@redhat.com> References: <20170327155234.10980-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 27 Mar 2017 15:52:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/6] file-posix: Make bdrv_flush() failure permanent without O_DIRECT X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Kevin Wolf Success for bdrv_flush() means that all previously written data is safe on disk. For fdatasync(), the best semantics we can hope for on Linux (without O_DIRECT) is that all data that was written since the last call was successfully written back. Therefore, and because we can't redo all writes after a flush failure, we have to give up after a single fdatasync() failure. After this failure, we would never be able to make the promise that a successful bdrv_flush() makes. Signed-off-by: Kevin Wolf Message-id: 20170322210005.16533-1-kwolf@redhat.com Reviewed-by: Fam Zheng Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Signed-off-by: Max Reitz --- block/file-posix.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 53febd3767..beb7a4f728 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -144,6 +144,7 @@ typedef struct BDRVRawState { bool has_write_zeroes:1; bool discard_zeroes:1; bool use_linux_aio:1; + bool page_cache_inconsistent:1; bool has_fallocate; bool needs_alignment; } BDRVRawState; @@ -824,10 +825,31 @@ static ssize_t handle_aiocb_ioctl(RawPosixAIOData *ai= ocb) =20 static ssize_t handle_aiocb_flush(RawPosixAIOData *aiocb) { + BDRVRawState *s =3D aiocb->bs->opaque; int ret; =20 + if (s->page_cache_inconsistent) { + return -EIO; + } + ret =3D qemu_fdatasync(aiocb->aio_fildes); if (ret =3D=3D -1) { + /* There is no clear definition of the semantics of a failing fsyn= c(), + * so we may have to assume the worst. The sad truth is that this + * assumption is correct for Linux. Some pages are now probably ma= rked + * clean in the page cache even though they are inconsistent with = the + * on-disk contents. The next fdatasync() call would succeed, but = no + * further writeback attempt will be made. We can't get back to a = state + * in which we know what is on disk (we would have to rewrite + * everything that was touched since the last fdatasync() at least= ), so + * make bdrv_flush() fail permanently. Given that the behaviour is= n't + * really defined, I have little hope that other OSes are doing be= tter. + * + * Obviously, this doesn't affect O_DIRECT, which bypasses the page + * cache. */ + if ((s->open_flags & O_DIRECT) =3D=3D 0) { + s->page_cache_inconsistent =3D true; + } return -errno; } return 0; --=20 2.12.1 From nobody Thu May 2 14:16:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490630182076316.8303146435403; Mon, 27 Mar 2017 08:56:22 -0700 (PDT) Received: from localhost ([::1]:47736 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csX0G-0003wn-P7 for importer@patchew.org; Mon, 27 Mar 2017 11:56:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWx3-0001eD-Jq for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:53:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csWx2-0006LQ-P8 for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:53:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56788) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csWx0-0006Jk-Bd; Mon, 27 Mar 2017 11:52:58 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 53D98C7848; Mon, 27 Mar 2017 15:52:57 +0000 (UTC) Received: from localhost (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE84671C82; Mon, 27 Mar 2017 15:52:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 53D98C7848 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mreitz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 53D98C7848 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 27 Mar 2017 17:52:34 +0200 Message-Id: <20170327155234.10980-7-mreitz@redhat.com> In-Reply-To: <20170327155234.10980-1-mreitz@redhat.com> References: <20170327155234.10980-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 27 Mar 2017 15:52:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 6/6] block/file-posix.c: Fix unused variable warning on OpenBSD X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell On OpenBSD none of the ioctls probe_logical_blocksize() tries exist, so the variable sector_size is unused. Refactor the code to avoid this (and reduce the duplicated code). Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Jeff Cody Message-id: 1490279788-12995-1-git-send-email-peter.maydell@linaro.org Signed-off-by: Max Reitz --- block/file-posix.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index beb7a4f728..0841a08785 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -220,28 +220,28 @@ static int probe_logical_blocksize(int fd, unsigned i= nt *sector_size_p) { unsigned int sector_size; bool success =3D false; + int i; =20 errno =3D ENOTSUP; - - /* Try a few ioctls to get the right size */ + static const unsigned long ioctl_list[] =3D { #ifdef BLKSSZGET - if (ioctl(fd, BLKSSZGET, §or_size) >=3D 0) { - *sector_size_p =3D sector_size; - success =3D true; - } + BLKSSZGET, #endif #ifdef DKIOCGETBLOCKSIZE - if (ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) >=3D 0) { - *sector_size_p =3D sector_size; - success =3D true; - } + DKIOCGETBLOCKSIZE, #endif #ifdef DIOCGSECTORSIZE - if (ioctl(fd, DIOCGSECTORSIZE, §or_size) >=3D 0) { - *sector_size_p =3D sector_size; - success =3D true; - } + DIOCGSECTORSIZE, #endif + }; + + /* Try a few ioctls to get the right size */ + for (i =3D 0; i < (int)ARRAY_SIZE(ioctl_list); i++) { + if (ioctl(fd, ioctl_list[i], §or_size) >=3D 0) { + *sector_size_p =3D sector_size; + success =3D true; + } + } =20 return success ? 0 : -errno; } --=20 2.12.1