From nobody Fri Nov 14 15:22:01 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1588801041; cv=none; d=zohomail.com; s=zohoarc; b=cNbkgcQeF0H/u+nXC0sKrzLkAfz3C8xx7OO72WJ7adfBg4iCYHhxs6KulRLovqt1TKw0TTqxsgKcUcSB9m/JPj57WDjN7hg6YGk6R26qEPuDnYIfHB1N++l+rFDtO6MIfQgmC5kE1fdVgmGBBcU3e08yIvv5GU/J9n0iQ1/BxWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588801041; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject; bh=sJ4m17NJK5cs8JtIQvb12r57i6kH9t2M3Mg55ZLfYHQ=; b=ZVR9OzzE2E0/mEEaD7NVGPFwXSeE4dAPz++jPulG6r5m4gDUg84YyXXkAVifN9lEehVxHjZOEgc9Ro/xiOgXuhR6N4GFdRlsvvYM97KSUcC0lqemsxKKpCdw66rynvVC++FiOQ1ninPTNHm6SHGfg4OLPDl3ZeqtlwPej+Xjh0I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588801041363685.3089224907189; Wed, 6 May 2020 14:37:21 -0700 (PDT) Received: from localhost ([::1]:60446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWRjD-0000VP-Ro for importer@patchew.org; Wed, 06 May 2020 17:37:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWRhN-0006o2-Jm; Wed, 06 May 2020 17:35:25 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:52636) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWRhM-0006wV-Cg; Wed, 06 May 2020 17:35:25 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 046LJ9Vn102767; Wed, 6 May 2020 21:35:22 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 30s1gncq0r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 May 2020 21:35:22 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 046LHn7H039657; Wed, 6 May 2020 21:35:22 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 30t1r8sryn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 May 2020 21:35:21 +0000 Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 046LZLQe012347; Wed, 6 May 2020 21:35:21 GMT Received: from localhost.localdomain (/10.74.121.228) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 May 2020 14:35:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=sJ4m17NJK5cs8JtIQvb12r57i6kH9t2M3Mg55ZLfYHQ=; b=RfqsuDaxFcilvOURMCXES5fTegBX0/MHyYXbEOIG67b3I0k+OupWVpOGzq8u3cPlv45f c2mX1vGBr+D0ojla19GkbL+hKvLSdyCCQmWAqHgefW3Rl3E70H3NI7TUjZPDTlLtQ204 JuTvWNxrB18eoQ++wsPSRQmovSVl5xsC3VpsT7bo1AqtNVmRtnrnwcwD4uK7JWk5LnPL 0zWPUMb2sl2YqpVhBZoZVOo3coVaD6N/KBEjylr8tHOl7T8hmrdh9N3Ejy5WVkNlgCUP MOY/OSdrbSJ2lJh56z7X26Sm39266lCoPq/60OfchjAUtxPDfVMjvhSIH+ZoG+065ppB qA== From: Eyal Moscovici To: Subject: [PATCH v2 1/5] qemu-img: remove check that cvtnum value > MAX_INT Date: Thu, 7 May 2020 00:34:55 +0300 Message-Id: <20200506213459.44743-2-eyal.moscovici@oracle.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20200506213459.44743-1-eyal.moscovici@oracle.com> References: <59b0896d-85ad-08b5-fcc1-36adad7501a4@redhat.com> <20200506213459.44743-1-eyal.moscovici@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9613 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005060172 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9613 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 mlxscore=0 spamscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 phishscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005060172 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.85; envelope-from=eyal.moscovici@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/06 17:35:22 X-ACL-Warn: Detected OS = Linux 3.x [generic] [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Eyal Moscovici , qemu-block@nongnu.org, qemu-devel@nongnu.org, Max Reitz , liran.alon@oracle.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Following commit f46bfdbfc8f95cf65d7818ef68a801e063c40332 (util/cutils: Cha= nge qemu_strtosz*() from int64_t to uint64_t) which added a similar check to cvtnum. As a result there is no need to check it separately outside of cvtn= um. Acked-by: Mark Kanda Signed-off-by: Eyal Moscovici --- qemu-img.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 6a4327aaba..116a9c6349 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4307,7 +4307,7 @@ static int img_bench(int argc, char **argv) int64_t sval; =20 sval =3D cvtnum(optarg); - if (sval < 0 || sval > INT_MAX) { + if (sval < 0) { error_report("Invalid buffer size specified"); return 1; } @@ -4320,7 +4320,7 @@ static int img_bench(int argc, char **argv) int64_t sval; =20 sval =3D cvtnum(optarg); - if (sval < 0 || sval > INT_MAX) { + if (sval < 0) { error_report("Invalid step size specified"); return 1; } @@ -4493,7 +4493,7 @@ static int img_dd_bs(const char *arg, =20 res =3D cvtnum(arg); =20 - if (res <=3D 0 || res > INT_MAX) { + if (res <=3D 0) { error_report("invalid number: '%s'", arg); return 1; } --=20 2.17.2 (Apple Git-113) From nobody Fri Nov 14 15:22:01 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1588801017; cv=none; d=zohomail.com; s=zohoarc; b=Nv6ROUg9tgq9ih/gCZDrQPvbupcyVxBuapOWsvjzCD05i0PS633bLW1wuVeh9LEVUB8i+8Aijr0sWoVOytBwTGNmbDeHf1W7i0MLstA5T359e+quOQj464A+3YR613kMmIGT6n3VeNEJfxaCi93LFvRNDi1Z5i8wteC++wgZfZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588801017; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject; bh=KfZMoZ7bnwZv2BOgcPIdtmUUQ0+cdV+ar33s6cn9D04=; b=T1Q2SyHl27X9NvNt0bKAATGkpMRv+4G0qP1r75rQxCJChfnsIF+lYUpmnHV/7zr5CIzNBKWhycDiG8UZHruykr8tHFA/8YW7YanGuemjSSEy3zsVspaJWsIz5q9Gr+NShXw3vRAvxWMyNx6OM+UVh2TQYWGGw0S1KmWs+PdzU1k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588801017428364.0294745323366; Wed, 6 May 2020 14:36:57 -0700 (PDT) Received: from localhost ([::1]:59112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWRiq-0008Ou-2g for importer@patchew.org; Wed, 06 May 2020 17:36:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWRhR-0006wz-V6; Wed, 06 May 2020 17:35:30 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:50436) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWRhQ-0007HT-J0; Wed, 06 May 2020 17:35:29 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 046LJG2N099741; Wed, 6 May 2020 21:35:26 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 30usgq3y8u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 May 2020 21:35:26 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 046LHnku039740; Wed, 6 May 2020 21:35:25 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 30t1r8ss1r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 May 2020 21:35:25 +0000 Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 046LZONI017970; Wed, 6 May 2020 21:35:24 GMT Received: from localhost.localdomain (/10.74.121.228) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 May 2020 14:35:24 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=KfZMoZ7bnwZv2BOgcPIdtmUUQ0+cdV+ar33s6cn9D04=; b=JPXYcFi3KIh2jVZ7A3U7Zf2ZiOQkbRX2AKnYqKDAQU2WUQmo90ZdgQ+N8P7+NMOeF4RW r+D0LN0G0XcgU3s4573RZ1WMzMDZ7D526gekj6ih6z9qBv36MV4hSSxqAYo2qzDiVk+t O628XT5+TldekmLPwTHWBkzSugvdWDRJXLPr7w8uv9/t2uWVAagTNOeoqt7Sfx9rozfY +iKgJCKB9XHsK9PlYTtBNRg/+TwM83haKAN/xGjGhnDQz5ypWiStIyTU2oAr8robbsUN 2YRaDLAVmSjr86M6DzfNKTNv0N8rOwCt4rb5rHbDT/wBB0xr1Lj5lYy+jKFF7+Pc8NK7 Ow== From: Eyal Moscovici To: Subject: [PATCH v2 2/5] qemu_img: add error report to cvtnum Date: Thu, 7 May 2020 00:34:56 +0300 Message-Id: <20200506213459.44743-3-eyal.moscovici@oracle.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20200506213459.44743-1-eyal.moscovici@oracle.com> References: <59b0896d-85ad-08b5-fcc1-36adad7501a4@redhat.com> <20200506213459.44743-1-eyal.moscovici@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9613 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005060172 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9613 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 spamscore=0 adultscore=0 bulkscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005060172 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.78; envelope-from=eyal.moscovici@oracle.com; helo=aserp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/06 17:35:26 X-ACL-Warn: Detected OS = Linux 3.x [generic] [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Eyal Moscovici , qemu-block@nongnu.org, qemu-devel@nongnu.org, Max Reitz , liran.alon@oracle.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" All calls to cvtnum check the return value and print the same error message= more or less. And so error reporting moved to cvtnum to reduce duplicate code and provide a single error message. Acked-by: Mark Kanda Signed-off-by: Eyal Moscovici --- qemu-img.c | 63 ++++++++++++++++---------------------- tests/qemu-iotests/049.out | 4 +-- 2 files changed, 28 insertions(+), 39 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 116a9c6349..4a06ab7fe8 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -470,16 +470,22 @@ static int add_old_style_options(const char *fmt, Qem= uOpts *opts, return 0; } =20 -static int64_t cvtnum(const char *s) +static int64_t cvtnum(const char *arg_name, const char *arg_value) { int err; uint64_t value; =20 - err =3D qemu_strtosz(s, NULL, &value); - if (err < 0) { + err =3D qemu_strtosz(arg_value, NULL, &value); + if (err < 0 && err !=3D -ERANGE) { + error_report("Invalid %s specified! You may use " + "k, M, G, T, P or E suffixes for ", arg_name); + error_report("kilobytes, megabytes, gigabytes, terabytes, " + "petabytes and exabytes."); return err; } - if (value > INT64_MAX) { + if (err =3D=3D -ERANGE || value > INT64_MAX) { + error_report("Invalid %s specified! Must be less than 8 EiB!", + arg_name); return -ERANGE; } return value; @@ -572,16 +578,8 @@ static int img_create(int argc, char **argv) if (optind < argc) { int64_t sval; =20 - sval =3D cvtnum(argv[optind++]); + sval =3D cvtnum("image size", argv[optind++]); if (sval < 0) { - if (sval =3D=3D -ERANGE) { - error_report("Image size must be less than 8 EiB!"); - } else { - error_report("Invalid image size specified! You may use k,= M, " - "G, T, P or E suffixes for "); - error_report("kilobytes, megabytes, gigabytes, terabytes, " - "petabytes and exabytes."); - } goto fail; } img_size =3D (uint64_t)sval; @@ -2187,8 +2185,10 @@ static int img_convert(int argc, char **argv) { int64_t sval; =20 - sval =3D cvtnum(optarg); - if (sval < 0 || !QEMU_IS_ALIGNED(sval, BDRV_SECTOR_SIZE) || + sval =3D cvtnum("buffer size for sparse output", optarg); + if (sval < 0) { + goto fail_getopt; + } else if (!QEMU_IS_ALIGNED(sval, BDRV_SECTOR_SIZE) || sval / BDRV_SECTOR_SIZE > MAX_BUF_SECTORS) { error_report("Invalid buffer size for sparse output specif= ied. " "Valid sizes are multiples of %llu up to %llu. Select " @@ -4291,9 +4291,8 @@ static int img_bench(int argc, char **argv) break; case 'o': { - offset =3D cvtnum(optarg); + offset =3D cvtnum("offset", optarg); if (offset < 0) { - error_report("Invalid offset specified"); return 1; } break; @@ -4306,9 +4305,8 @@ static int img_bench(int argc, char **argv) { int64_t sval; =20 - sval =3D cvtnum(optarg); + sval =3D cvtnum("buffer size", optarg); if (sval < 0) { - error_report("Invalid buffer size specified"); return 1; } =20 @@ -4319,9 +4317,8 @@ static int img_bench(int argc, char **argv) { int64_t sval; =20 - sval =3D cvtnum(optarg); + sval =3D cvtnum("step_size", optarg); if (sval < 0) { - error_report("Invalid step size specified"); return 1; } =20 @@ -4491,10 +4488,12 @@ static int img_dd_bs(const char *arg, { int64_t res; =20 - res =3D cvtnum(arg); + res =3D cvtnum("bs", arg); =20 - if (res <=3D 0) { - error_report("invalid number: '%s'", arg); + if (res < 0) { + return 1; + } else if (res =3D=3D 0) { + error_report("Invalid bs specified! It cannot be 0."); return 1; } in->bsz =3D out->bsz =3D res; @@ -4506,10 +4505,9 @@ static int img_dd_count(const char *arg, struct DdIo *in, struct DdIo *out, struct DdInfo *dd) { - dd->count =3D cvtnum(arg); + dd->count =3D cvtnum("count", arg); =20 if (dd->count < 0) { - error_report("invalid number: '%s'", arg); return 1; } =20 @@ -4538,10 +4536,9 @@ static int img_dd_skip(const char *arg, struct DdIo *in, struct DdIo *out, struct DdInfo *dd) { - in->offset =3D cvtnum(arg); + in->offset =3D cvtnum("skip", arg); =20 if (in->offset < 0) { - error_report("invalid number: '%s'", arg); return 1; } =20 @@ -4923,16 +4920,8 @@ static int img_measure(int argc, char **argv) { int64_t sval; =20 - sval =3D cvtnum(optarg); + sval =3D cvtnum("image size", optarg); if (sval < 0) { - if (sval =3D=3D -ERANGE) { - error_report("Image size must be less than 8 EiB!"); - } else { - error_report("Invalid image size specified! You may us= e " - "k, M, G, T, P or E suffixes for "); - error_report("kilobytes, megabytes, gigabytes, terabyt= es, " - "petabytes and exabytes."); - } goto out; } img_size =3D (uint64_t)sval; diff --git a/tests/qemu-iotests/049.out b/tests/qemu-iotests/049.out index affa55b341..0ec2e6b82e 100644 --- a/tests/qemu-iotests/049.out +++ b/tests/qemu-iotests/049.out @@ -92,13 +92,13 @@ Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D16492= 67441664 cluster_size=3D65536 l =3D=3D 3. Invalid sizes =3D=3D =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- -1024 -qemu-img: Image size must be less than 8 EiB! +qemu-img: Invalid image size specified! Must be less than 8 EiB! =20 qemu-img create -f qcow2 -o size=3D-1024 TEST_DIR/t.qcow2 qemu-img: TEST_DIR/t.qcow2: Value '-1024' is out of range for parameter 's= ize' =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- -1k -qemu-img: Image size must be less than 8 EiB! +qemu-img: Invalid image size specified! Must be less than 8 EiB! =20 qemu-img create -f qcow2 -o size=3D-1k TEST_DIR/t.qcow2 qemu-img: TEST_DIR/t.qcow2: Value '-1k' is out of range for parameter 'siz= e' --=20 2.17.2 (Apple Git-113) From nobody Fri Nov 14 15:22:01 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1588801124; cv=none; d=zohomail.com; s=zohoarc; b=l+unTcIx+EhrRlO6LQ6aTjiNwsEaUWl2Pq9ME5AdOouhaumtWrk2XrzdLcvb1EXaFfGxa4ADX9gjpk0s85QpGYXAGOIHVPjejQ9RqdS9KAMZukjMY1+GWTBmcVHATolwEVuuW97OsgOcKgSL60IgvHWDtsOD30oap9gqqsQyb80= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588801124; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject; bh=fJuh9yEQX+2FkhodxnzfqX7Jo2/iC7Lfk8tHnWZtPYg=; b=Mp0LwJ748Wgn2WDBq1TYssGe2KsNZUMv/V3dy/25ku3oU0ny2Mx/2wfuReFEs+FEe77r7R1VRu2tikW5LyVJ2Mw9QTSKuqEmXmZXMEvqlazul35VGTahGmTcGwpLy581B1BLG6X2gOZu6Q3o26K4fQpn702SbaOneMjtnRTRyEo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588801124038368.30217209927116; Wed, 6 May 2020 14:38:44 -0700 (PDT) Received: from localhost ([::1]:38624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWRkY-00036w-Lg for importer@patchew.org; Wed, 06 May 2020 17:38:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50754) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWRhV-00071Z-7O; Wed, 06 May 2020 17:35:33 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:52688) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWRhT-0007Qn-H2; Wed, 06 May 2020 17:35:32 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 046LHusM102069; Wed, 6 May 2020 21:35:29 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 30s1gncq0y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 May 2020 21:35:29 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 046LHnRw039807; Wed, 6 May 2020 21:35:29 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 30t1r8ss4k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 May 2020 21:35:29 +0000 Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 046LZSpm018020; Wed, 6 May 2020 21:35:28 GMT Received: from localhost.localdomain (/10.74.121.228) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 May 2020 14:35:27 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=fJuh9yEQX+2FkhodxnzfqX7Jo2/iC7Lfk8tHnWZtPYg=; b=oEmzsQGIxSMawk2fAx30Q0UgJU/d0D7TLCwVYlHJD//kpQcRh3z7aB26OdLYcrrXfH/l gfInq3UJdiUA4mXxjfEP8IuL5zwtLeLVIgUuEkNW4DKQD1lUnHD0yQ+hVixstBE1kMq8 VEGRxx9J+mCsisFRGieh0JJ911z6OwnlRqn9YR7zQ9z8U/UTmgGKWwcS2dzbfTitZJWI TwDUofuK6cXtP2BBIuSbZpt8QKRR9DgrV4P8P2eCi+Rq6PSkGdq62NobH5ISRd/PifXK U11TWJFiSBVtTWFgBKWpt7WFdtUUMkzyHyq3Krlk/vjWQBu5KqOWr7mkqTYsPSprtF6B cg== From: Eyal Moscovici To: Subject: [PATCH v2 3/5] qemu-img: validate image length in img_map Date: Thu, 7 May 2020 00:34:57 +0300 Message-Id: <20200506213459.44743-4-eyal.moscovici@oracle.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20200506213459.44743-1-eyal.moscovici@oracle.com> References: <59b0896d-85ad-08b5-fcc1-36adad7501a4@redhat.com> <20200506213459.44743-1-eyal.moscovici@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9613 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=870 malwarescore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005060172 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9613 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 mlxscore=0 spamscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 phishscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=910 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005060172 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.85; envelope-from=eyal.moscovici@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/06 17:35:22 X-ACL-Warn: Detected OS = Linux 3.x [generic] [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Eyal Moscovici , qemu-block@nongnu.org, qemu-devel@nongnu.org, Max Reitz , liran.alon@oracle.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The code handles this case correctly we merely skip the loop. However it is probably best to return an explicit error. Acked-by: Mark Kanda Signed-off-by: Eyal Moscovici Reviewed-by: Eric Blake --- qemu-img.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qemu-img.c b/qemu-img.c index 4a06ab7fe8..a1b507a0be 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3086,6 +3086,11 @@ static int img_map(int argc, char **argv) } =20 length =3D blk_getlength(blk); + if (length < 0) { + error_report("Failed to get size for '%s'", filename); + return 1; + } + while (curr.start + curr.length < length) { int64_t offset =3D curr.start + curr.length; int64_t n; --=20 2.17.2 (Apple Git-113) From nobody Fri Nov 14 15:22:01 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1588801140; cv=none; d=zohomail.com; s=zohoarc; b=JRmD+OsqcnpwOf7Bb0hc7mqEP4k7rbzZKo6ql0O0pC/5inBenTGF++DsK/f/peKO5h1NckpoWJGM78Baakrj/wKbDTmNacOMZ1YxoSEv/TbXTLm/+22z2eZ06kU4yP3w5UFsx8IMgbWasFlp4CWi4/WvCqDY8Jws4lcyKGNirC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588801140; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject; bh=wYBItL0O1HkGz9n/QNq2NII3wXKWScs2S1KCgSg+tyg=; b=lsk9i3hBlfeqB6gKqYC/Albc0SP30U5yUw/gxPjjohlKYD5y+zMaHCc+CFgfKRaEqhmulUVH3ZJAvxOOITEqqtZpoFT3bM27x0wfb3fSmFnhNY7FoWWQ2iOpDI0+SmzzllHjviCsBkSyp5uxzFa5+x7CUiW438mOKD0eXpxP8qo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158880114031325.429373862837565; Wed, 6 May 2020 14:39:00 -0700 (PDT) Received: from localhost ([::1]:39408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWRko-0003QK-Vd for importer@patchew.org; Wed, 06 May 2020 17:38:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWRhb-0007AA-L1; Wed, 06 May 2020 17:35:39 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:50490) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWRhZ-0007ob-5z; Wed, 06 May 2020 17:35:39 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 046LJSHo100003; Wed, 6 May 2020 21:35:34 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 30usgq3y98-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 May 2020 21:35:34 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 046LZ1pD118799; Wed, 6 May 2020 21:35:34 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 30sjdwduf8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 May 2020 21:35:33 +0000 Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 046LZWQs016525; Wed, 6 May 2020 21:35:32 GMT Received: from localhost.localdomain (/10.74.121.228) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 May 2020 14:35:31 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=wYBItL0O1HkGz9n/QNq2NII3wXKWScs2S1KCgSg+tyg=; b=Bzhan7eYLMAbpDdA91UuqJmOVkOCoTfPYlV6hIgtJWAFkvh8O+8UtRAz+ULpO1srq+fp vv+1gQ1mEp5RgkFJbi/NC5t9lUSZALS/37nMqC7DgLAnK+Ag0UrBrA4DqWxdxPD8XY6F 9QKdQ1frJSUEolfoeSslV0H25gBevIYl0uIK2h3+gEklK0Bl9xhCN394Xz4fHfc4R2Jd ytRaBk7jyq38+vK9eppZrqKfTBSl0DMHVyOvj6Faj+ZuAHjyXJO30IRL0DRLvOgt1lmM WPN0ZqJqvKC4mAM6HwjuU69y6qHRuZNaRWSr+5wpEMZca4mKPp4FEPvD/Yy31OPkaoq5 6g== From: Eyal Moscovici To: Subject: [PATCH v2 4/5] qemu-img: refactor dump_map_entry JSON format output Date: Thu, 7 May 2020 00:34:58 +0300 Message-Id: <20200506213459.44743-5-eyal.moscovici@oracle.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20200506213459.44743-1-eyal.moscovici@oracle.com> References: <59b0896d-85ad-08b5-fcc1-36adad7501a4@redhat.com> <20200506213459.44743-1-eyal.moscovici@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9613 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 mlxscore=0 bulkscore=0 adultscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005060172 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9613 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 spamscore=0 adultscore=0 bulkscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005060172 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.78; envelope-from=eyal.moscovici@oracle.com; helo=aserp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/06 17:35:26 X-ACL-Warn: Detected OS = Linux 3.x [generic] [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Eyal Moscovici , qemu-block@nongnu.org, qemu-devel@nongnu.org, Max Reitz , liran.alon@oracle.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Previously dump_map_entry identified whether we need to start a new JSON array based on whether start address =3D=3D 0. In this refactor we remove this assumption as in following patches we will allow map to start from an arbitrary position. Reviewed-by: Eric Blake Acked-by: Mark Kanda Signed-off-by: Eyal Moscovici --- qemu-img.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index a1b507a0be..0a140fe564 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2896,9 +2896,8 @@ static int dump_map_entry(OutputFormat output_format,= MapEntry *e, } break; case OFORMAT_JSON: - printf("%s{ \"start\": %"PRId64", \"length\": %"PRId64"," + printf("{ \"start\": %"PRId64", \"length\": %"PRId64"," " \"depth\": %"PRId64", \"zero\": %s, \"data\": %s", - (e->start =3D=3D 0 ? "[" : ",\n"), e->start, e->length, e->depth, e->zero ? "true" : "false", e->data ? "true" : "false"); @@ -2907,8 +2906,8 @@ static int dump_map_entry(OutputFormat output_format,= MapEntry *e, } putchar('}'); =20 - if (!next) { - printf("]\n"); + if (next) { + puts(","); } break; } @@ -3083,6 +3082,8 @@ static int img_map(int argc, char **argv) =20 if (output_format =3D=3D OFORMAT_HUMAN) { printf("%-16s%-16s%-16s%s\n", "Offset", "Length", "Mapped to", "Fi= le"); + } else if (output_format =3D=3D OFORMAT_JSON) { + putchar('['); } =20 length =3D blk_getlength(blk); @@ -3119,6 +3120,9 @@ static int img_map(int argc, char **argv) } =20 ret =3D dump_map_entry(output_format, &curr, NULL); + if (output_format =3D=3D OFORMAT_JSON) { + puts("]"); + } =20 out: blk_unref(blk); --=20 2.17.2 (Apple Git-113) From nobody Fri Nov 14 15:22:01 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1588801200; cv=none; d=zohomail.com; s=zohoarc; b=HfXjrSsRSRYEld1NQOTynHwdAWEcuI8VRAgtWeVaOi6d4CJv8klPUJ+73waMym2oGXt1EXDre6l+VCdDGqqwaNgfoLx6pBpIATZ/k4lsZQqEoTDELq57S2vmkFoCnHcx88OsGF/oZJcXeqGuro7+HuiNvkgpV6VcBWgw4H0pjTk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588801200; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject; bh=hbXlgDGqtdlxUDisBUtKc5JIY9Tow9V2NgxslTx1slM=; b=JEyibgXMJakC69lQbPq4Qtog1jHgOikpSwzzIAaeCj1TBUiknTbyF1c7or7KXWNYXWeCOoDQZfwOokdKHTzbRyz+lcQPtOfDr+e4HiJ44Qd7xhiU/AszGQxkBDU98z7OadBJ+/lBKzVNGl92TZ39wOi3thK8obRGeRZ3NdIBrL4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588801200695614.8921338404843; Wed, 6 May 2020 14:40:00 -0700 (PDT) Received: from localhost ([::1]:42612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWRln-0004iy-Fn for importer@patchew.org; Wed, 06 May 2020 17:39:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50828) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWRhd-0007Da-UE; Wed, 06 May 2020 17:35:41 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:50522) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWRhc-0008BP-HO; Wed, 06 May 2020 17:35:41 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 046LJIuR099860; Wed, 6 May 2020 21:35:39 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 30usgq3y99-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 May 2020 21:35:39 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 046LHmtX039635; Wed, 6 May 2020 21:35:38 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 30t1r8ssam-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 May 2020 21:35:38 +0000 Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 046LZbqm017882; Wed, 6 May 2020 21:35:37 GMT Received: from localhost.localdomain (/10.74.121.228) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 May 2020 14:35:36 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=hbXlgDGqtdlxUDisBUtKc5JIY9Tow9V2NgxslTx1slM=; b=q9LeDFHicNRLckjUd2VOgdEzeYqU0uKZhT0RZu8UpfAX45gA2S9XGrUIeTj22ay0w6Hd /LpECSoSX7W7GPv80OV92m3PcgYI/rh5tvaM70SIoQKp35T2BdBRqicAM8BhxVBB01Sz UOg1agluIVXkqDxh7Vy3Vs1wrDO3kNS5vGabvvW+CwHaS+5LfViZcj2007bZZpqfr307 M2NgSo49AlOYipfaTUkgpBOMqRe4Zhk51MdpWJ3zPKIHC6VZg52wjxW86pjtWuZWmbOB G+SETJDfbCmWf2TMnAAclIXE6/yFn6x7Ru/+NLbxnrjt9kQkD0s3cCInQfpnMSeGjCGA RQ== From: Eyal Moscovici To: Subject: [PATCH v2 5/5] qemu-img: Add --start-offset and --max-length to map Date: Thu, 7 May 2020 00:34:59 +0300 Message-Id: <20200506213459.44743-6-eyal.moscovici@oracle.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20200506213459.44743-1-eyal.moscovici@oracle.com> References: <59b0896d-85ad-08b5-fcc1-36adad7501a4@redhat.com> <20200506213459.44743-1-eyal.moscovici@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9613 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005060172 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9613 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 spamscore=0 adultscore=0 bulkscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005060172 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.78; envelope-from=eyal.moscovici@oracle.com; helo=aserp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/06 17:35:26 X-ACL-Warn: Detected OS = Linux 3.x [generic] [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Eyal Moscovici , qemu-block@nongnu.org, qemu-devel@nongnu.org, Max Reitz , liran.alon@oracle.com, Yoav Elnekave Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The mapping operation of large disks especially ones stored over a long chain of QCOW2 files can take a long time to finish. Additionally when mapping fails there was no way recover by restarting the mapping from the failed location. The new options, --start-offset and --max-length allows the user to divide these type of map operations into shorter independent tasks. Reviewed-by: Eric Blake Acked-by: Mark Kanda Co-developed-by: Yoav Elnekave Signed-off-by: Yoav Elnekave Signed-off-by: Eyal Moscovici --- docs/tools/qemu-img.rst | 2 +- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 22 +++++++++++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 0080f83a76..f4ffe528ea 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -519,7 +519,7 @@ Command description: ``ImageInfoSpecific*`` QAPI object (e.g. ``ImageInfoSpecificQCow2`` for qcow2 images). =20 -.. option:: map [--object OBJECTDEF] [--image-opts] [-f FMT] [--output=3DO= FMT] [-U] FILENAME +.. option:: map [--object OBJECTDEF] [--image-opts] [-f FMT] [--start-offs= et=3DOFFSET] [--max-length=3DLEN] [--output=3DOFMT] [-U] FILENAME =20 Dump the metadata of image *FILENAME* and its backing file chain. In particular, this commands dumps the allocation state of every sector diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index c9c54de1df..35f832816f 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -63,9 +63,9 @@ SRST ERST =20 DEF("map", img_map, - "map [--object objectdef] [--image-opts] [-f fmt] [--output=3Dofmt] [-= U] filename") + "map [--object objectdef] [--image-opts] [-f fmt] [--start-offset=3Dof= fset] [--max-length=3Dlen] [--output=3Dofmt] [-U] filename") SRST -.. option:: map [--object OBJECTDEF] [--image-opts] [-f FMT] [--output=3DO= FMT] [-U] FILENAME +.. option:: map [--object OBJECTDEF] [--image-opts] [-f FMT] [--start-offs= et=3DOFFSET] [--max-length=3DLEN] [--output=3DOFMT] [-U] FILENAME ERST =20 DEF("measure", img_measure, diff --git a/qemu-img.c b/qemu-img.c index 0a140fe564..f59b2c0a7c 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3003,6 +3003,8 @@ static int img_map(int argc, char **argv) int ret =3D 0; bool image_opts =3D false; bool force_share =3D false; + int64_t start_offset =3D 0; + int64_t max_length =3D -1; =20 fmt =3D NULL; output =3D NULL; @@ -3015,9 +3017,11 @@ static int img_map(int argc, char **argv) {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {"force-share", no_argument, 0, 'U'}, + {"start-offset", required_argument, 0, 's'}, + {"max-length", required_argument, 0, 'l'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":f:hU", + c =3D getopt_long(argc, argv, ":f:s:l:hU", long_options, &option_index); if (c =3D=3D -1) { break; @@ -3041,6 +3045,18 @@ static int img_map(int argc, char **argv) case OPTION_OUTPUT: output =3D optarg; break; + case 's': + start_offset =3D cvtnum("start offset", optarg); + if (start_offset < 0) { + return 1; + } + break; + case 'l': + max_length =3D cvtnum("max length", optarg); + if (max_length < 0) { + return 1; + } + break; case OPTION_OBJECT: { QemuOpts *opts; opts =3D qemu_opts_parse_noisily(&qemu_object_opts, @@ -3091,7 +3107,11 @@ static int img_map(int argc, char **argv) error_report("Failed to get size for '%s'", filename); return 1; } + if (max_length !=3D -1) { + length =3D MIN(start_offset + max_length, length); + } =20 + curr.start =3D start_offset; while (curr.start + curr.length < length) { int64_t offset =3D curr.start + curr.length; int64_t n; --=20 2.17.2 (Apple Git-113)