[{"id":1776629,"web_url":"http://patchwork.ozlabs.org/comment/1776629/","msgid":"<37b21d60-acbd-c4ce-3d6f-3f852b8da2a3@redhat.com>","list_archive_url":null,"date":"2017-09-27T21:35:12","subject":"Re: [Qemu-devel] [PATCH v4 16/23] qemu-img: Drop redundant error\n\tmessage in compare","submitter":{"id":64343,"url":"http://patchwork.ozlabs.org/api/people/64343/","name":"John Snow","email":"jsnow@redhat.com"},"content":"On 09/13/2017 12:03 PM, Eric Blake wrote:\n> If a read error is encountered during 'qemu-img compare', we\n> were printing the \"Error while reading offset ...\" message twice.\n> Update the testsuite for the improved output.\n> \n> Further simplify the code by hoisting the error code conversion\n> into the helper function, rather than repeating it at the callers.\n> \n> Signed-off-by: Eric Blake <eblake@redhat.com>\n> \n> ---\n> v3: new patch\n> ---\n>  qemu-img.c                 | 19 +++++--------------\n>  tests/qemu-iotests/074.out |  2 --\n>  2 files changed, 5 insertions(+), 16 deletions(-)\n> \n> diff --git a/qemu-img.c b/qemu-img.c\n> index dfccebe6bc..3e1e373e8f 100644\n> --- a/qemu-img.c\n> +++ b/qemu-img.c\n> @@ -1196,8 +1196,10 @@ static int64_t sectors_to_bytes(int64_t sectors)\n>  /*\n>   * Check if passed sectors are empty (not allocated or contain only 0 bytes)\n>   *\n> - * Returns 0 in case sectors are filled with 0, 1 if sectors contain non-zero\n> - * data and negative value on error.\n> + * Intended for use by 'qemu-img compare': Returns 0 in case sectors are\n> + * filled with 0, 1 if sectors contain non-zero data (this is a comparison\n> + * failure), and 4 on error (the exit status for read errors), after emitting\n> + * an error message.\n>   *\n>   * @param blk:  BlockBackend for the image\n>   * @param sect_num: Number of first sector to check\n> @@ -1218,7 +1220,7 @@ static int check_empty_sectors(BlockBackend *blk, int64_t sect_num,\n>      if (ret < 0) {\n>          error_report(\"Error while reading offset %\" PRId64 \" of %s: %s\",\n>                       sectors_to_bytes(sect_num), filename, strerror(-ret));\n> -        return ret;\n> +        return 4;\n>      }\n>      idx = find_nonzero(buffer, sect_count * BDRV_SECTOR_SIZE);\n>      if (idx >= 0) {\n> @@ -1473,11 +1475,6 @@ static int img_compare(int argc, char **argv)\n>                                            filename2, buf1, quiet);\n>              }\n>              if (ret) {\n> -                if (ret < 0) {\n> -                    error_report(\"Error while reading offset %\" PRId64 \": %s\",\n> -                                 sectors_to_bytes(sector_num), strerror(-ret));\n> -                    ret = 4;\n> -                }\n>                  goto out;\n>              }\n>          }\n> @@ -1522,12 +1519,6 @@ static int img_compare(int argc, char **argv)\n>                  ret = check_empty_sectors(blk_over, sector_num, nb_sectors,\n>                                            filename_over, buf1, quiet);\n>                  if (ret) {\n> -                    if (ret < 0) {\n> -                        error_report(\"Error while reading offset %\" PRId64\n> -                                     \" of %s: %s\", sectors_to_bytes(sector_num),\n> -                                     filename_over, strerror(-ret));\n> -                        ret = 4;\n> -                    }\n>                      goto out;\n>                  }\n>              }\n> diff --git a/tests/qemu-iotests/074.out b/tests/qemu-iotests/074.out\n> index 8fba5aea9c..ede66c3f81 100644\n> --- a/tests/qemu-iotests/074.out\n> +++ b/tests/qemu-iotests/074.out\n> @@ -4,7 +4,6 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824\n>  wrote 512/512 bytes at offset 512\n>  512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)\n>  qemu-img: Error while reading offset 0 of blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error\n> -qemu-img: Error while reading offset 0: Input/output error\n>  4\n>  Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824\n>  Formatting 'TEST_DIR/t.IMGFMT.2', fmt=IMGFMT size=0\n> @@ -12,7 +11,6 @@ Formatting 'TEST_DIR/t.IMGFMT.2', fmt=IMGFMT size=0\n>  wrote 512/512 bytes at offset 512\n>  512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)\n>  qemu-img: Error while reading offset 0 of blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error\n> -qemu-img: Error while reading offset 0 of blkdebug:TEST_DIR/blkdebug.conf:TEST_DIR/t.IMGFMT: Input/output error\n>  Warning: Image size mismatch!\n>  4\n>  Cleanup\n> \n\nHm, naively I might assume it's best for the caller to report the error\nand to leave the function a nicely self-contained helper, but I won't\ninsist on it.\n\nReviewed-by: John Snow <jsnow@redhat.com>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx04.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx04.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=jsnow@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3y2WN45l81z9t5l\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 28 Sep 2017 07:36:04 +1000 (AEST)","from localhost ([::1]:56432 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dxJzu-0007bC-SD\n\tfor incoming@patchwork.ozlabs.org; Wed, 27 Sep 2017 17:36:02 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:44840)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <jsnow@redhat.com>) id 1dxJzI-0007W2-Sg\n\tfor qemu-devel@nongnu.org; Wed, 27 Sep 2017 17:35:26 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <jsnow@redhat.com>) id 1dxJzH-0001Wj-K8\n\tfor qemu-devel@nongnu.org; Wed, 27 Sep 2017 17:35:24 -0400","from mx1.redhat.com ([209.132.183.28]:9341)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <jsnow@redhat.com>)\n\tid 1dxJzC-0001U8-I6; Wed, 27 Sep 2017 17:35:18 -0400","from smtp.corp.redhat.com\n\t(int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 7A066103897;\n\tWed, 27 Sep 2017 21:35:17 +0000 (UTC)","from [10.10.121.69] (ovpn-121-69.rdu2.redhat.com [10.10.121.69])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id A0E7390814;\n\tWed, 27 Sep 2017 21:35:13 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 7A066103897","To":"Eric Blake <eblake@redhat.com>, qemu-devel@nongnu.org","References":"<20170913160333.23622-1-eblake@redhat.com>\n\t<20170913160333.23622-17-eblake@redhat.com>","From":"John Snow <jsnow@redhat.com>","Message-ID":"<37b21d60-acbd-c4ce-3d6f-3f852b8da2a3@redhat.com>","Date":"Wed, 27 Sep 2017 17:35:12 -0400","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<20170913160333.23622-17-eblake@redhat.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-US","Content-Transfer-Encoding":"7bit","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.13","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.28]);\n\tWed, 27 Sep 2017 21:35:17 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] [PATCH v4 16/23] qemu-img: Drop redundant error\n\tmessage in compare","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org,\n\tMax Reitz <mreitz@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]