From nobody Tue May 7 21:26:22 2024 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=1589377179; cv=none; d=zohomail.com; s=zohoarc; b=lmMXrGPPTMYozFg5+NwU+ly13iCBufHvOR5KnKMehDPr6sHNAKCVB2ekmdCW+3JNbR96GV1s2daZgDZa8OywffJvBb7dh2vfqwx0Pf24omC47AgVWpeBVjghJ2+hPuyyRmVUj0vMWnWBeqgt1V24Ra8Nd/qOLYzie/1Ozec1lFY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589377179; 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=rUPZHNuSUsVradKy4beIPtnoBx/+30g1NxkePgtibM0=; b=dl02NMwz6BL3pW9na8GbWY6IvEJR8NUuidKzLwkXEK1jnCuDU1F5MMbm5gvFOXVcxVOign6cD7f4xuJeDh3GogKPUFp+9ElJPpacRb20RoFI6eED+EkuXssa5et9rEj+m/8pZ04UKNTJjvvuXbEFP6z8jNaxhwUytgkB+Xp7bi8= 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 1589377176963560.8015264209296; Wed, 13 May 2020 06:39:36 -0700 (PDT) Received: from localhost ([::1]:50644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYrbf-0001a4-31 for importer@patchew.org; Wed, 13 May 2020 09:39:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYray-0000iV-JU; Wed, 13 May 2020 09:38:48 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:38694) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYrax-0005Bu-Cn; Wed, 13 May 2020 09:38:48 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04DDXE2a164512; Wed, 13 May 2020 13:38:45 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 3100yfv7f5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 13 May 2020 13:38:45 +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 04DDY393113679; Wed, 13 May 2020 13:36:45 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 3100yek9c6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 May 2020 13:36:44 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 04DDahtG021129; Wed, 13 May 2020 13:36:43 GMT Received: from localhost.localdomain (/10.74.123.68) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 13 May 2020 06:36:43 -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=rUPZHNuSUsVradKy4beIPtnoBx/+30g1NxkePgtibM0=; b=kOMXtRs7kV/z7mtrhq+yF+RVdLruWGz3hWqbVI2E2P+ZoktAmQVD+gf0HKr81kuhnKrE izKtPZP9JS9bSZ+clZUjdDRW+U78oI9LEQyfjF8XKYthK+7FFQSaQPfIDnV76PbMdM82 lkqAemEjsf1JfTbGBS/lqMeIt0sLi+FHoIqmg2YHcMKhT8NrRAos1SH2DlD4T/woQuRQ mGyC4NxwINa/aTWCV0uuJs0J97PqbTCn6UCq02ali6xT1Y9r0ASwtGmnM44V3xz4SVwa HCpyQtpUd5FVTodBBjl+IicWzgTL339/YjOa1Qo69XcplJedtZQcc+ZgAdBaAPjISmD8 2Q== From: Eyal Moscovici To: Subject: [PATCH v3 1/1] qemu_img: add cvtnum_full to print error reports Date: Wed, 13 May 2020 16:36:26 +0300 Message-Id: <20200513133629.18508-2-eyal.moscovici@oracle.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20200513133629.18508-1-eyal.moscovici@oracle.com> References: <20200513133629.18508-1-eyal.moscovici@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9619 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 bulkscore=0 phishscore=0 suspectscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005130121 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9619 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 adultscore=0 cotscore=-2147483648 mlxscore=0 suspectscore=0 spamscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 clxscore=1015 phishscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005130121 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.86; envelope-from=eyal.moscovici@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 09:36:43 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [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" All calls to cvtnum check the return value and print the same error message= more or less. And so error reporting moved to cvtnum_full to reduce code duplication and provide a single error message. Additionally, cvtnum now wr= aps cvtnum_full with the existing default range of 0 to MAX_INT64. Acked-by: Mark Kanda Signed-off-by: Eyal Moscovici Reviewed-by: Eric Blake --- qemu-img.c | 76 +++++++++++++++++--------------------- tests/qemu-iotests/049.out | 8 ++-- 2 files changed, 38 insertions(+), 46 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 6a4327aaba..a4ce35abc5 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -470,19 +470,31 @@ 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_full(const char *name, const char *value, int64_t mi= n, + int64_t max) { int err; - uint64_t value; - - err =3D qemu_strtosz(s, NULL, &value); - if (err < 0) { + uint64_t res; + + err =3D qemu_strtosz(value, NULL, &res); + if (err < 0 && err !=3D -ERANGE) { + error_report("Invalid %s specified. You may use " + "k, M, G, T, P or E suffixes for ", name); + error_report("kilobytes, megabytes, gigabytes, terabytes, " + "petabytes and exabytes."); return err; } - if (value > INT64_MAX) { + if (err =3D=3D -ERANGE || res > max || res < min) { + error_report("Invalid %s specified. Must be between %ld bytes " + "to %ld bytes.", name, min, max); return -ERANGE; } - return value; + return res; +} + +static int64_t cvtnum(const char *name, const char *value) +{ + return cvtnum_full(name, value, 0, INT64_MAX); } =20 static int img_create(int argc, char **argv) @@ -572,16 +584,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 +2191,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 +4297,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 +4311,8 @@ static int img_bench(int argc, char **argv) { int64_t sval; =20 - sval =3D cvtnum(optarg); - if (sval < 0 || sval > INT_MAX) { - error_report("Invalid buffer size specified"); + sval =3D cvtnum_full("buffer size", optarg, 0, INT_MAX); + if (sval < 0) { return 1; } =20 @@ -4319,9 +4323,8 @@ static int img_bench(int argc, char **argv) { int64_t sval; =20 - sval =3D cvtnum(optarg); - if (sval < 0 || sval > INT_MAX) { - error_report("Invalid step size specified"); + sval =3D cvtnum_full("step_size", optarg, 0, INT_MAX); + if (sval < 0) { return 1; } =20 @@ -4491,10 +4494,9 @@ static int img_dd_bs(const char *arg, { int64_t res; =20 - res =3D cvtnum(arg); + res =3D cvtnum_full("bs", arg, 1, INT_MAX); =20 - if (res <=3D 0 || res > INT_MAX) { - error_report("invalid number: '%s'", arg); + if (res < 0) { return 1; } in->bsz =3D out->bsz =3D res; @@ -4506,10 +4508,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 +4539,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 +4923,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..e00d311180 100644 --- a/tests/qemu-iotests/049.out +++ b/tests/qemu-iotests/049.out @@ -92,19 +92,19 @@ 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 between 0 bytes to 9223372= 036854775807 bytes. =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 between 0 bytes to 9223372= 036854775807 bytes. =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 qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- 1kilobyte -qemu-img: Invalid image size specified! You may use k, M, G, T, P or E suf= fixes for +qemu-img: Invalid image size specified. You may use k, M, G, T, P or E suf= fixes for qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabyt= es. =20 qemu-img create -f qcow2 -o size=3D1kilobyte TEST_DIR/t.qcow2 @@ -113,7 +113,7 @@ Optional suffix k, M, G, T, P or E means kilo-, mega-, = giga-, tera-, peta- and exabytes, respectively. =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- foobar -qemu-img: Invalid image size specified! You may use k, M, G, T, P or E suf= fixes for +qemu-img: Invalid image size specified. You may use k, M, G, T, P or E suf= fixes for qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabyt= es. =20 qemu-img create -f qcow2 -o size=3Dfoobar TEST_DIR/t.qcow2 --=20 2.17.2 (Apple Git-113) From nobody Tue May 7 21:26:22 2024 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=1589377225; cv=none; d=zohomail.com; s=zohoarc; b=iIyQbcSrZwCUaFdAIInMFaethaBXQXUICJjLA3q5MJ2QtLh+f6zbQXh9/jOp43619n1Pb7dGMJ1CJoaoC6twZMelPOz2N1SjAePi+Ee7ACPVdE2KOOadUhjEgdzs95y4GNH7upqNP4J6sBCgGfz14x3Woe73HFPEQiRHnhFKBWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589377225; 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=7uYVCNJ3IcRaqaueO/mQf4X8aaj6MOJoym/nvcg420A=; b=jcAP1uN7jvTY0+m+JPsO+8xVMn36Sqpj2EsF8+zztsB6o6odbszX5nMBR1KarHl2WgwoyvdfI2HBv/2B4DZYEwWc48MGoyxiPG1E4w7rjsrBBTnHAPETYqy03rMPRAMKB33ynY2ytUSOsFFHz4R05kNBnfv+9+8rWv0w+ygcKH4= 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 1589377225184511.34535973027585; Wed, 13 May 2020 06:40:25 -0700 (PDT) Received: from localhost ([::1]:52880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYrcV-0002kp-VC for importer@patchew.org; Wed, 13 May 2020 09:40:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYrb1-0000l2-Q3; Wed, 13 May 2020 09:38:51 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:38744) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYrb0-0005CL-TL; Wed, 13 May 2020 09:38:51 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04DDWVp3163828; Wed, 13 May 2020 13:38:49 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 3100yfv7fe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 13 May 2020 13:38:49 +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 04DDXuWb102343; Wed, 13 May 2020 13:36:48 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 3100yajc0w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 May 2020 13:36:48 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 04DDalVk015393; Wed, 13 May 2020 13:36:47 GMT Received: from localhost.localdomain (/10.74.123.68) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 13 May 2020 06:36:46 -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=7uYVCNJ3IcRaqaueO/mQf4X8aaj6MOJoym/nvcg420A=; b=rnyQSZtNTdIuoWoFpyNQ9gLfAckEWix+QazyRz2u02uhbnZcZ9E10N+x/4D5Ieg4+/SD AI3eawt0C4kkH7s/LAPi3Fo7gEeuuzH1eQNwgt1K6FryCfmLd6EdCYEsZF0hTxFmJWjg 3CjDRvDtv+Idye1bjALEpFvuvJ5fFd5S54Xtr6Dp2ONya/PUvQwWkz3De8eK3pPh7/W/ qLmYBCPkWdh6P89oDjQI6yJ6likwznhP4E4Z+VEJfR7Hpk7DQacD0gK7TB0TwuHJ6eMS 3YIgarAFnoEZpLZtDQSP5lky2dT2gzbkbm5a8vHtXtN2HF4seelvNwyGKTA6cQEIScTO Iw== From: Eyal Moscovici To: Subject: [PATCH v3 2/4] qemu-img: validate image length in img_map Date: Wed, 13 May 2020 16:36:27 +0300 Message-Id: <20200513133629.18508-3-eyal.moscovici@oracle.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20200513133629.18508-1-eyal.moscovici@oracle.com> References: <20200513133629.18508-1-eyal.moscovici@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9619 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 phishscore=0 adultscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005130121 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9619 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 adultscore=0 cotscore=-2147483648 mlxscore=0 suspectscore=0 spamscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 clxscore=1015 phishscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005130121 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.86; envelope-from=eyal.moscovici@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 09:36:43 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [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. Reviewed-by: Eric Blake Acked-by: Mark Kanda Signed-off-by: Eyal Moscovici --- qemu-img.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qemu-img.c b/qemu-img.c index cc2e4a3799..23e90a99e1 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3091,6 +3091,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 Tue May 7 21:26:22 2024 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=1589377279; cv=none; d=zohomail.com; s=zohoarc; b=EeKAu8uyyCkw/WX28RpAQzopqXVBCjdDLyV+gzfzmFk26I5DQNiMGVVK93//D12ucIdJIVHPJ7eZJ+grKfVI1++UiwHW/BYqPhE2wwP7wreUWAUj54Je9FKzrtRxlUqJbXG98Yb64Sd6SjJJMQE4ZpU6S8HyESKXB2TX4MlIbAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589377279; 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=77A/CYmGa98C84EcFMSMiHGqtvwGQtvTRfrn9v78drw=; b=JR0T+fWOB6vzK9LkX94/xDd4U8wuq7yNqG1tg/0Mez1OE2xZsGwiFiFmwOl0dMx48Xx99HTle0/5jeiuomUoZwOX5r+Dju94bKCYGMCmE//w06F4JBqWxw84kmpSN9aOPxYfX/dWyrmwic3z6nOsVez1X2zdtEvbdTN35f/xgso= 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 158937727969650.844668929873365; Wed, 13 May 2020 06:41:19 -0700 (PDT) Received: from localhost ([::1]:55168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYrdO-0003n6-De for importer@patchew.org; Wed, 13 May 2020 09:41:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYrb5-0000sK-SI; Wed, 13 May 2020 09:38:55 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:35126) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYrb4-0005Cs-Tj; Wed, 13 May 2020 09:38:55 -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 04DDXLNG023714; Wed, 13 May 2020 13:38:52 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 3100xwc80q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 13 May 2020 13:38:52 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04DDYYVX036375; Wed, 13 May 2020 13:36:52 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 3100ym3mxu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 May 2020 13:36:51 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 04DDapgI003418; Wed, 13 May 2020 13:36:51 GMT Received: from localhost.localdomain (/10.74.123.68) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 13 May 2020 06:36:50 -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=77A/CYmGa98C84EcFMSMiHGqtvwGQtvTRfrn9v78drw=; b=t3sDYKkl1x+cuwCUHsuIO+hLP/TrxiLZ7jfYMtbFxD7NIK2TalSpEzx0Bq1KHTmjvesA ZIS/79YRlT0yrOYfOU/ZwXyH+K+yI9rUvShQREYZHL+i4u3dkggHy31uERWdJOJUfit0 jmdpp6e2NzHnMsJds+9zbbf/jMYhNLQ1WDaGeJTgjeqxBCYtxAU3XlGfUJq7OxuaSKkT ylaPaXKZd67U/4/lc2As/IUWCWCSsTplTyoXad3OLZEPfnsObpAWF2O2Ph18xvZVhqNN 4HidKEijcqp0vyBUjXxu075EzJd2zl0qwtnfRYDFGm8RBosx7appl55O36lb6gxZqqC+ VA== From: Eyal Moscovici To: Subject: [PATCH v3 3/4] qemu-img: refactor dump_map_entry JSON format output Date: Wed, 13 May 2020 16:36:28 +0300 Message-Id: <20200513133629.18508-4-eyal.moscovici@oracle.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20200513133629.18508-1-eyal.moscovici@oracle.com> References: <20200513133629.18508-1-eyal.moscovici@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9619 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005130121 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9619 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 cotscore=-2147483648 mlxscore=0 phishscore=0 adultscore=0 impostorscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005130121 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/13 08:03:36 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [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" 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 23e90a99e1..80340cb218 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2901,9 +2901,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"); @@ -2912,8 +2911,8 @@ static int dump_map_entry(OutputFormat output_format,= MapEntry *e, } putchar('}'); =20 - if (!next) { - printf("]\n"); + if (next) { + puts(","); } break; } @@ -3088,6 +3087,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); @@ -3124,6 +3125,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 Tue May 7 21:26:22 2024 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=1589377356; cv=none; d=zohomail.com; s=zohoarc; b=Blfu+f3lUkWrFlkiqwV614eXYj0D6yoOc+DneIDU1w9gyUMuxNAbyl74Mr7lzTqPg42N6AkCl7vlv+MaaeeS3GKffeQrCTNJlEetthXSPmF0UzGZk/jf1unzp1FP8DPX0N9qzJ/9V0gywY//TNr7XZp70eMsvcuwwo9sYV1QvuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589377356; 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=2YvLZRapzNNUWA58DYlojtp/pTZjH7rlMhyMwFTHNVw=; b=IcFnVEZpU4pq/pYNBrZbNwetKtd1ipi86hVgmTleJOgpGqjBmCVlfkkD97Rw0jrt60EMwXUd02+OzDHlfCR7OKOM6bB7LEQiCE8/I+nzYqpelG1/eTwDKxAm3i75WcrQIBdhTuuUGD1/mt0PsPdsChoJb5OwIPxGLpffvQyFGX8= 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 1589377356504281.87278069607714; Wed, 13 May 2020 06:42:36 -0700 (PDT) Received: from localhost ([::1]:57524 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYred-000534-9F for importer@patchew.org; Wed, 13 May 2020 09:42:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYrb9-0000zP-4G; Wed, 13 May 2020 09:38:59 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:35194) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYrb8-0005DR-2m; Wed, 13 May 2020 09:38:58 -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 04DDX9Wq023635; Wed, 13 May 2020 13:38:56 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 3100xwc816-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 13 May 2020 13:38:56 +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 04DDY2W9113567; Wed, 13 May 2020 13:36:55 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 3100yek9nv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 May 2020 13:36:55 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 04DDaswg015458; Wed, 13 May 2020 13:36:54 GMT Received: from localhost.localdomain (/10.74.123.68) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 13 May 2020 06:36:53 -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=2YvLZRapzNNUWA58DYlojtp/pTZjH7rlMhyMwFTHNVw=; b=zNYO7tM/zwQWfWtL5iKkxKIidz4BDoCKByTwGSkKQdbC1IM2apYV6Su9CluZO5gEb4Ys DpiDVHeKvtK3R1vVY7haWYsGLdWn4sXNPtcIbMBm/mVynDeRAgJcaM7HXdbXwqFjC7wy CAcMLclr3BtQkqF2L+SN4n0jrxvGdGlbIZavptKSRhOXFW37h4ROyVJTdVy/s0lekSUl OcsISgg7homzyjOr+X1NIUIONvtcrzUO/UuRbK82Im/nsjY5PH/pGdBJHEFq4QPMgSRl lXerZ8H1XpD6uInPc7x5ke4BfHLla17DW+Wx+UpOvg9ImeHiGD68KRlPONAl+Ark7Jh2 nA== From: Eyal Moscovici To: Subject: [PATCH v3 4/4] qemu-img: Add --start-offset and --max-length to map Date: Wed, 13 May 2020 16:36:29 +0300 Message-Id: <20200513133629.18508-5-eyal.moscovici@oracle.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20200513133629.18508-1-eyal.moscovici@oracle.com> References: <20200513133629.18508-1-eyal.moscovici@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9619 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 bulkscore=0 phishscore=0 suspectscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005130121 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9619 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 cotscore=-2147483648 mlxscore=0 phishscore=0 adultscore=0 impostorscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005130121 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/13 08:03:36 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [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, 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 80340cb218..bce7b49799 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3008,6 +3008,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; @@ -3020,9 +3022,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; @@ -3046,6 +3050,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, @@ -3096,7 +3112,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) From nobody Tue May 7 21:26:22 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589394209; cv=none; d=zohomail.com; s=zohoarc; b=eyJNV1rqxdyWv6drxFK9cjJ2/ij2dc5dANb8HELYbQwFj5bnfcdLhJ/kKFrauPRJoBXaEXHis32/N9fIgi48t9aF6SlTGuAZx5DlEo6IU3ugq4LKM3AKsMKaBISlC4qkd2ACB46JsNrbeDRR86GDACUDY8tzVRIBWJ5DhjUYouw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589394209; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gApSd30ZMKg/jas2KCKE4mCNtRGqWOp2oITD/c0hT+4=; b=S8cMvGcx6Rz1y/IiMexiY090T4Q+TQOvBJ1ca2Lk3sO4zc8jSmgYsnyjLqtmzA1oSemQxLWy5xXA35iW7Jx/X04xlp2H8qDilPApnhtI+ETU1aDuWDWsMYxTBBoYvotWu/qZFpdG+w41hz1pC7ah811s+YTf5HwXPQxP3uUGW+8= 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 1589394209704577.896155563815; Wed, 13 May 2020 11:23:29 -0700 (PDT) Received: from localhost ([::1]:41740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYw2S-0000rQ-AA for importer@patchew.org; Wed, 13 May 2020 14:23:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37118) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYvuL-0003sU-KN for qemu-devel@nongnu.org; Wed, 13 May 2020 14:15:05 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:33042 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jYvuK-0001Ud-QT for qemu-devel@nongnu.org; Wed, 13 May 2020 14:15:05 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-113-HrFAXTf4Nd2hEC_EC7W4Og-1; Wed, 13 May 2020 14:14:59 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B91A11005512; Wed, 13 May 2020 18:14:58 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-145.phx2.redhat.com [10.3.116.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D0A760BF1; Wed, 13 May 2020 18:14:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589393703; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gApSd30ZMKg/jas2KCKE4mCNtRGqWOp2oITD/c0hT+4=; b=YwpfcKnaTncLAElnmG+M09AjzR2QFxLfw0WEmvyOYwjXRvWo0SAiJoC8C1JNg3sEYooi3/ H7w+R9LZSBxT8cSu1zP5r3FVQCtBn++JIO3MJ8hZRg1oJSEKsUNXTUcVnrjahOyKPpdbmT MpF3F3MnR1pApEopHhPXnd8AV/mIrYg= X-MC-Unique: HrFAXTf4Nd2hEC_EC7W4Og-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v3 5/4] iotests: Enhance 223 to cover qemu-img map improvements Date: Wed, 13 May 2020 13:14:54 -0500 Message-Id: <20200513181455.295267-1-eblake@redhat.com> In-Reply-To: <20200513133629.18508-1-eyal.moscovici@oracle.com> References: <20200513133629.18508-1-eyal.moscovici@oracle.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=207.211.31.81; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 04:17:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-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: kwolf@redhat.com, liran.alon@oracle.com, eyal.moscovici@oracle.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Since qemu-img map + x-dirty-bitmap remains the easiest way to read persistent bitmaps at the moment, it makes a reasonable place to add coverage to ensure we do not regress on the just-added parameters to qemu-img map. Signed-off-by: Eric Blake --- [Resend for proper threading, since --in=3Dreply-to=3D is not the same as --in-reply-to=3D] tests/qemu-iotests/223 | 6 ++++-- tests/qemu-iotests/223.out | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/223 b/tests/qemu-iotests/223 index 56fbc5fb09a0..d68bc3cb6f1a 100755 --- a/tests/qemu-iotests/223 +++ b/tests/qemu-iotests/223 @@ -2,7 +2,7 @@ # # Test reading dirty bitmap over NBD # -# Copyright (C) 2018-2019 Red Hat, Inc. +# Copyright (C) 2018-2020 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -206,7 +206,9 @@ $QEMU_IMG map --output=3Djson --image-opts \ nbd_server_start_unix_socket -f $IMGFMT -B b2 "$TEST_IMG" IMG=3D"driver=3Dnbd,server.type=3Dunix,server.path=3D$nbd_unix_socket" -$QEMU_IMG map --output=3Djson --image-opts \ +$QEMU_IMG map --output=3Djson --image-opts --max-length=3D12345 \ + "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b2" | _filter_qemu_img_map +$QEMU_IMG map --output=3Djson --image-opts --start-offset=3D12345 \ "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b2" | _filter_qemu_img_map # success, all done diff --git a/tests/qemu-iotests/223.out b/tests/qemu-iotests/223.out index 80c0cf65095b..e1eaaedb55b3 100644 --- a/tests/qemu-iotests/223.out +++ b/tests/qemu-iotests/223.out @@ -201,6 +201,7 @@ read 2097152/2097152 bytes at offset 2097152 { "start": 2097152, "length": 2097152, "depth": 0, "zero": false, "data": = false}] [{ "start": 0, "length": 512, "depth": 0, "zero": false, "data": true, "of= fset": OFFSET}, { "start": 512, "length": 512, "depth": 0, "zero": false, "data": false}, -{ "start": 1024, "length": 2096128, "depth": 0, "zero": false, "data": tru= e, "offset": OFFSET}, +{ "start": 1024, "length": 11321, "depth": 0, "zero": false, "data": true,= "offset": OFFSET}] +[{ "start": 12345, "length": 2084807, "depth": 0, "zero": false, "data": t= rue, "offset": OFFSET}, { "start": 2097152, "length": 2097152, "depth": 0, "zero": false, "data": = false}] *** done --=20 2.26.2