From patchwork Fri Jan 5 06:55:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 10146051 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 401B7601A1 for ; Fri, 5 Jan 2018 06:59:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6EF02823E for ; Fri, 5 Jan 2018 06:59:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB2B727F81; Fri, 5 Jan 2018 06:59:00 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 40F5527F81 for ; Fri, 5 Jan 2018 06:59:00 +0000 (UTC) Received: from localhost ([::1]:50910 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXLxz-0007Ok-Gq for patchwork-qemu-devel@patchwork.kernel.org; Fri, 05 Jan 2018 01:58:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXLv3-0003iM-Ox for qemu-devel@nongnu.org; Fri, 05 Jan 2018 01:55:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eXLv2-0002NO-Dd for qemu-devel@nongnu.org; Fri, 05 Jan 2018 01:55:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34723) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eXLuz-0002ID-2E; Fri, 05 Jan 2018 01:55:53 -0500 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 CBC844D221; Fri, 5 Jan 2018 06:55:51 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-115.pek2.redhat.com [10.72.12.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20AE55C881; Fri, 5 Jan 2018 06:55:49 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 5 Jan 2018 14:55:38 +0800 Message-Id: <20180105065538.13375-3-famz@redhat.com> In-Reply-To: <20180105065538.13375-1-famz@redhat.com> References: <20180105065538.13375-1-famz@redhat.com> 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.25]); Fri, 05 Jan 2018 06:55:51 +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] [PATCH 2/2] qemu-img: info: try -U automatically 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 , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The error message we had didn't have a hint about "-U" when locking the image failed, which is not friendly. Also it is imaginable that the reaction to that error by the user would be a retry with '-U'. So the reason we require "-U" for "qemu-img info" if the image is used is to raise the awareness about what could be wrong. A warning would do just fine, especially since it is a little more informative. The test case reference output is updated accordingly. Signed-off-by: Fam Zheng Reviewed-by: Eric Blake --- qemu-img.c | 14 ++++++++++++++ tests/qemu-iotests/153.out | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 7d3171c20c..9684937425 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2605,6 +2605,20 @@ static int img_info(int argc, char **argv) list = collect_image_info_list(image_opts, filename, fmt, chain, force_share, &local_err); + if (!list && !force_share) { + Error *local_err2 = NULL; + list = collect_image_info_list(image_opts, filename, fmt, chain, + true, &local_err2); + if (list) { + error_report("WARNING: --force-share (-U) is not used but it " + "seems the image is attached to a running guest; " + "the information may be inaccurate if it is being " + "updated."); + error_free(local_err); + } else { + error_free(local_err2); + } + } if (!list) { error_reportf_err(local_err, "Could not open '%s': ", filename); return 1; diff --git a/tests/qemu-iotests/153.out b/tests/qemu-iotests/153.out index 5b917b177c..4de35184ba 100644 --- a/tests/qemu-iotests/153.out +++ b/tests/qemu-iotests/153.out @@ -41,8 +41,7 @@ Is another process using the image? no file open, try 'help open' _qemu_img_wrapper info TEST_DIR/t.qcow2 -qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock -Is another process using the image? +qemu-img: WARNING: --force-share (-U) is not used but it seems the image is attached to a running guest; the information may be inaccurate if it is being updated. _qemu_img_wrapper check TEST_DIR/t.qcow2 qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock