From patchwork Fri Oct 7 15:36:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reda Sallahi X-Patchwork-Id: 9366413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D234B608A6 for ; Fri, 7 Oct 2016 15:37:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C375229716 for ; Fri, 7 Oct 2016 15:37:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B823329718; Fri, 7 Oct 2016 15:37:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CB2DE29717 for ; Fri, 7 Oct 2016 15:37:14 +0000 (UTC) Received: from localhost ([::1]:36763 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsXCz-000340-LI for patchwork-qemu-devel@patchwork.kernel.org; Fri, 07 Oct 2016 11:37:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsXCa-00032Q-SX for qemu-devel@nongnu.org; Fri, 07 Oct 2016 11:36:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsXCU-0007lj-R8 for qemu-devel@nongnu.org; Fri, 07 Oct 2016 11:36:47 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:34558) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsXCU-0007lc-HV; Fri, 07 Oct 2016 11:36:42 -0400 Received: by mail-wm0-x242.google.com with SMTP id b201so3513363wmb.1; Fri, 07 Oct 2016 08:36:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u2/xmHCV5Nw92+nPGtzoqP4az5WEJqf/2III3v3tu3Q=; b=BCOXoPpvuHooYmVxEI0anw9vHE+LYsfA+Q3Znfm0yc95Fh2rGSDc2/e4+eTuEAoMNr nCAJ1SIS6DVBPgMIxSvkGUgGMV4HZqZamM7kj9cgwrKUiq+SN+eElsYBGmiwTneVx9U1 E+0WzFnJlw5byT1qagSpzjo8D25Zawiia8vEvUM+X06P/TXOJuyoTW54NIR+i+Jb8XRG c+b3YNS8mAbzpVwdTsav5MFf4CAzhHqBYankum2CLfW7fgFddBj61X+INfkIjZjL1dhE X6BBzTShuz6iJGymyHXddzOiCDu2hQLTURQsAKEXnuyOeCk+uSIWhiZxPOtgiallvlMh Vn8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=u2/xmHCV5Nw92+nPGtzoqP4az5WEJqf/2III3v3tu3Q=; b=kvbR85YoC3iyW9D0QoTkTXZEVNKsgmLMmGSRuYvvKoJ7T9GYCYvryXmjhchuz+zR7i XFV94LUeqf/y4VrIaUJRYfxxqVOiKhloUzF8hmLE51XTzYBD11bFgPivF5pGyHpIdkHl 10S+Zp1wykPJGsBWIit5rqfRJjETSKusiPBo/eBYLO5Bn13NNPtlrWnyp358j4j4kVDc 35ta0Sl3QhT5LpFxU8ffVMX0+0gRjZo4d3tvTxjRbEKp2RRuFkdtfizJ741YCnexzFem eJZgRWJNGMYKPL/9zfG97J2D4vc+4SHPTzlID12Uvh4I/Q/wNXt4cfNTo0kMouSQ7iRk VpwA== X-Gm-Message-State: AA6/9Rm0Lv+NhqJTAe1aUcOzy0LcWqFScDyqNp67wrD6ekPzHGqYpFFNWlDhgGbiaKsuRA== X-Received: by 10.28.88.77 with SMTP id m74mr7976072wmb.94.1475854601796; Fri, 07 Oct 2016 08:36:41 -0700 (PDT) Received: from cinque_stelle.sm14.sm.cri.epita.net ([163.5.208.20]) by smtp.gmail.com with ESMTPSA id 137sm3537659wmi.16.2016.10.07.08.36.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Oct 2016 08:36:41 -0700 (PDT) From: Reda Sallahi To: qemu-devel@nongnu.org Date: Fri, 7 Oct 2016 17:36:16 +0200 Message-Id: <20161007153617.28704-2-fullmanet@gmail.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161007153617.28704-1-fullmanet@gmail.com> References: <20161007153617.28704-1-fullmanet@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PATCH 1/2] qemu-img: make img_open() able to surpress file opening errors 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 , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Reda Sallahi , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Previously img_open() always printed file opening errors even if the intended action is just to check the file existence as is sometimes the case in qemu-img dd. This adds an argument (openerror) to img_open() that specifies whether to print an opening error or not. Signed-off-by: Reda Sallahi --- qemu-img.c | 54 ++++++++++++++++++++++++++++++-------------------- tests/qemu-iotests/160 | 1 + 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 219fd86..6c088bd 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -269,7 +269,7 @@ static int img_open_password(BlockBackend *blk, const char *filename, static BlockBackend *img_open_opts(const char *optstr, QemuOpts *opts, int flags, bool writethrough, - bool quiet) + bool quiet, bool openerror) { QDict *options; Error *local_err = NULL; @@ -277,7 +277,9 @@ static BlockBackend *img_open_opts(const char *optstr, options = qemu_opts_to_qdict(opts, NULL); blk = blk_new_open(NULL, NULL, options, flags, &local_err); if (!blk) { - error_reportf_err(local_err, "Could not open '%s': ", optstr); + if (openerror) { + error_reportf_err(local_err, "Could not open '%s': ", optstr); + } return NULL; } blk_set_enable_write_cache(blk, !writethrough); @@ -291,7 +293,8 @@ static BlockBackend *img_open_opts(const char *optstr, static BlockBackend *img_open_file(const char *filename, const char *fmt, int flags, - bool writethrough, bool quiet) + bool writethrough, bool quiet, + bool openerror) { BlockBackend *blk; Error *local_err = NULL; @@ -304,7 +307,9 @@ static BlockBackend *img_open_file(const char *filename, blk = blk_new_open(filename, NULL, options, flags, &local_err); if (!blk) { - error_reportf_err(local_err, "Could not open '%s': ", filename); + if (openerror) { + error_reportf_err(local_err, "Could not open '%s': ", filename); + } return NULL; } blk_set_enable_write_cache(blk, !writethrough); @@ -320,7 +325,7 @@ static BlockBackend *img_open_file(const char *filename, static BlockBackend *img_open(bool image_opts, const char *filename, const char *fmt, int flags, bool writethrough, - bool quiet) + bool quiet, bool openerror) { BlockBackend *blk; if (image_opts) { @@ -334,9 +339,11 @@ static BlockBackend *img_open(bool image_opts, if (!opts) { return NULL; } - blk = img_open_opts(filename, opts, flags, writethrough, quiet); + blk = img_open_opts(filename, opts, flags, writethrough, quiet, + openerror); } else { - blk = img_open_file(filename, fmt, flags, writethrough, quiet); + blk = img_open_file(filename, fmt, flags, writethrough, quiet, + openerror); } return blk; } @@ -706,7 +713,7 @@ static int img_check(int argc, char **argv) return 1; } - blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet); + blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet, true); if (!blk) { return 1; } @@ -898,7 +905,7 @@ static int img_commit(int argc, char **argv) return 1; } - blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet); + blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet, true); if (!blk) { return 1; } @@ -1232,13 +1239,15 @@ static int img_compare(int argc, char **argv) goto out3; } - blk1 = img_open(image_opts, filename1, fmt1, flags, writethrough, quiet); + blk1 = img_open(image_opts, filename1, fmt1, flags, writethrough, quiet, + true); if (!blk1) { ret = 2; goto out3; } - blk2 = img_open(image_opts, filename2, fmt2, flags, writethrough, quiet); + blk2 = img_open(image_opts, filename2, fmt2, flags, writethrough, quiet, + true); if (!blk2) { ret = 2; goto out2; @@ -1943,7 +1952,7 @@ static int img_convert(int argc, char **argv) total_sectors = 0; for (bs_i = 0; bs_i < bs_n; bs_i++) { blk[bs_i] = img_open(image_opts, argv[optind + bs_i], - fmt, src_flags, src_writethrough, quiet); + fmt, src_flags, src_writethrough, quiet, true); if (!blk[bs_i]) { ret = -1; goto out; @@ -2088,7 +2097,8 @@ static int img_convert(int argc, char **argv) * the bdrv_create() call which takes different params. * Not critical right now, so fix can wait... */ - out_blk = img_open_file(out_filename, out_fmt, flags, writethrough, quiet); + out_blk = img_open_file(out_filename, out_fmt, flags, writethrough, quiet, + true); if (!out_blk) { ret = -1; goto out; @@ -2280,7 +2290,7 @@ static ImageInfoList *collect_image_info_list(bool image_opts, g_hash_table_insert(filenames, (gpointer)filename, NULL); blk = img_open(image_opts, filename, fmt, - BDRV_O_NO_BACKING | BDRV_O_NO_IO, false, false); + BDRV_O_NO_BACKING | BDRV_O_NO_IO, false, false, true); if (!blk) { goto err; } @@ -2606,7 +2616,7 @@ static int img_map(int argc, char **argv) return 1; } - blk = img_open(image_opts, filename, fmt, 0, false, false); + blk = img_open(image_opts, filename, fmt, 0, false, false, true); if (!blk) { return 1; } @@ -2750,7 +2760,7 @@ static int img_snapshot(int argc, char **argv) } /* Open the image */ - blk = img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet); + blk = img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet, true); if (!blk) { return 1; } @@ -2925,7 +2935,7 @@ static int img_rebase(int argc, char **argv) * Ignore the old backing file for unsafe rebase in case we want to correct * the reference to a renamed or moved backing file. */ - blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet); + blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet, true); if (!blk) { ret = -1; goto out; @@ -3265,7 +3275,7 @@ static int img_resize(int argc, char **argv) qemu_opts_del(param); blk = img_open(image_opts, filename, fmt, - BDRV_O_RDWR, false, quiet); + BDRV_O_RDWR, false, quiet, true); if (!blk) { ret = -1; goto out; @@ -3423,7 +3433,7 @@ static int img_amend(int argc, char **argv) goto out; } - blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet); + blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet, true); if (!blk) { ret = -1; goto out; @@ -3741,7 +3751,7 @@ static int img_bench(int argc, char **argv) goto out; } - blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet); + blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet, true); if (!blk) { ret = -1; goto out; @@ -4025,7 +4035,7 @@ static int img_dd(int argc, char **argv) ret = -1; goto out; } - blk1 = img_open(image_opts, in.filename, fmt, 0, false, false); + blk1 = img_open(image_opts, in.filename, fmt, 0, false, false, true); if (!blk1) { ret = -1; @@ -4093,7 +4103,7 @@ static int img_dd(int argc, char **argv) } blk2 = img_open(image_opts, out.filename, out_fmt, BDRV_O_RDWR, - false, false); + false, false, true); if (!blk2) { ret = -1; diff --git a/tests/qemu-iotests/160 b/tests/qemu-iotests/160 index 53b3c30..f44834f 100755 --- a/tests/qemu-iotests/160 +++ b/tests/qemu-iotests/160 @@ -65,6 +65,7 @@ for skip in $TEST_SKIP_BLOCKS; do echo "== Compare the images with qemu-img compare ==" $QEMU_IMG compare "$TEST_IMG.out.dd" "$TEST_IMG.out" + rm -f "$TEST_IMG.out.dd" done echo