Received: from eggs.gnu.org ([2001:4830:134:3::10]:35897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhJ6l-0004Ea-BK for qemu-devel@nongnu.org; Thu, 23 Oct 2014 10:11:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XhJ6f-0005eI-6g for qemu-devel@nongnu.org; Thu, 23 Oct 2014 10:11:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31583) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhJ6e-0005eC-U7 for qemu-devel@nongnu.org; Thu, 23 Oct 2014 10:11:13 -0400 From: Markus Armbruster References: <1414070952-25865-1-git-send-email-mreitz@redhat.com> Date: Thu, 23 Oct 2014 16:11:02 +0200 In-Reply-To: <1414070952-25865-1-git-send-email-mreitz@redhat.com> (Max Reitz's message of "Thu, 23 Oct 2014 15:29:12 +0200") Message-ID: <87wq7qlvux.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH] qemu-img: Print error if check failed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: Kevin Wolf , Peter Lieven , qemu-devel@nongnu.org, Stefan Hajnoczi , =?utf-8?Q?Beno?= =?utf-8?Q?=C3=AEt?= Canet Max Reitz writes: > Currently, if bdrv_check() fails either by returning -errno or having > check_errors set, qemu-img check just exits with 1 after having told the > user that there were no errors on the image. This is bad. > > Instead of printing the check result if there were internal errors which > were so bad that bdrv_check() could not even complete with 0 as a return > value, qemu-img check should inform the user about the error. > > Signed-off-by: Max Reitz > --- > qemu-img.c | 21 ++++++++++++++------- > 1 file changed, 14 insertions(+), 7 deletions(-) > > diff --git a/qemu-img.c b/qemu-img.c > index 09e7e72..731502c 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -687,16 +687,23 @@ static int img_check(int argc, char **argv) > check->corruptions_fixed = corruptions_fixed; > } > > - switch (output_format) { > - case OFORMAT_HUMAN: > - dump_human_image_check(check, quiet); > - break; > - case OFORMAT_JSON: > - dump_json_image_check(check, quiet); > - break; > + if (!ret) { > + switch (output_format) { > + case OFORMAT_HUMAN: > + dump_human_image_check(check, quiet); > + break; > + case OFORMAT_JSON: > + dump_json_image_check(check, quiet); > + break; > + } > } > > if (ret || check->check_errors) { > + if (ret) { > + error_report("Check failed: %s", strerror(-ret)); > + } else { > + error_report("Check failed"); > + } > ret = 1; > goto fail; > } Non-zero ret can only come from bdrv_check() via collect_image_check(). bdrv_check() is specified to return zero or -errno. Okay. Aside: ret is used for error codes, 0/-1 and for the return value 0/1/2/3/63. Unclean, but not this patch's fault. Reviewed-by: Markus Armbruster