From nobody Sun May 5 13:12:08 2024 Delivered-To: importer@patchew.org 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; 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=1584888499; cv=none; d=zohomail.com; s=zohoarc; b=DSFOS3BJdhF7b/T3e4DFdrh1eT8Wk4eo6yqZvv7gkhGxDIsrJFftEwc75giF7wgg+yhVbIb7qpiCNRLOsut+rBaZViRgZf0sHB4qYinI0bzNQbPP7b6FNT0lyCrqxtQLJeHPYGAG7X5SvCwnLWUwqFLrGjcQEThnnT9NIza3XoU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584888499; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=JPEMsm1Gf3umvspm/9mkoTaF1cxu2wRXZXQlNMDFP4M=; b=bvZk52ccYo6hCvMpF6ABGRmqS6WlmeC0Dc/LoQ8EtaW9QQagc2mEv4uqcLub+g7QO4UHgQ1Chk9De4hiMftHji1XnIGg0a4sqatbj0olqE0dZiJ0VO8DMqd3lUCJGlbl6D5DCc7symW3D2ag8p+A0aqpxm0Wck40V6ZboE0i5Yk= 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 1584888499337844.8250401734094; Sun, 22 Mar 2020 07:48:19 -0700 (PDT) Received: from localhost ([::1]:46912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jG1ti-0007Rq-4E for importer@patchew.org; Sun, 22 Mar 2020 10:48:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54463) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFwdt-0005oN-Fp for qemu-devel@nongnu.org; Sun, 22 Mar 2020 05:11:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jFwds-00014O-Fj for qemu-devel@nongnu.org; Sun, 22 Mar 2020 05:11:37 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:33570) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jFwdq-00012v-3i; Sun, 22 Mar 2020 05:11:34 -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 02M9Avbj096079; Sun, 22 Mar 2020 09:11:32 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2ywabqtq59-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 22 Mar 2020 09:11:32 +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 02M92vbX158679; Sun, 22 Mar 2020 09:11:32 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2ywvd9xncw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 22 Mar 2020 09:11:32 +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 02M9BVDK003693; Sun, 22 Mar 2020 09:11:31 GMT Received: from localhost.localdomain (/10.74.126.182) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 22 Mar 2020 02:11:30 -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=JPEMsm1Gf3umvspm/9mkoTaF1cxu2wRXZXQlNMDFP4M=; b=t/wXeCGTmNigR/VJftwMe4fF9KSK9rVy/Mo2UzY6sSd8ns97+JUIE73rvN293DI7Htxr Esybd4+wiqm8yb4DKdinc4FX8bkfLrCKDB4nt4xOLittRYIQ3bqEN/jkyrt2nedHQD9z iyBq0YxOoEA1lIY8kidBE76OnvF9eTdMJUpKU3uGHm0v0uSWC7qluDho3whn0uDfiVWP z7D/O+Nq96M1e+OvqwwOZkFFQ96nlntFFcpzo4fC7cORQp/yI97zrTQ2FQd82i9d+OYK R286AqJ7XOrGd3NbrSzrt6G7Qg/fwa5vLL/06segYLlBVNuF/aj9E6U70F3GhvKKatcw kw== From: Eyal Moscovici To: qemu-devel@nongnu.org Subject: [PATCH 1/2] qemu-img: refactor dump_map_entry JSON format output Date: Sun, 22 Mar 2020 11:11:16 +0200 Message-Id: <20200322091117.79443-2-eyal.moscovici@oracle.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20200322091117.79443-1-eyal.moscovici@oracle.com> References: <20200322091117.79443-1-eyal.moscovici@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9567 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 spamscore=0 suspectscore=1 mlxscore=0 phishscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003220053 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9567 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=1 lowpriorityscore=0 malwarescore=0 phishscore=0 priorityscore=1501 clxscore=1015 adultscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003220053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-Mailman-Approved-At: Sun, 22 Mar 2020 10:44:45 -0400 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 , liran.alon@oracle.com, Eyal Moscovici , qemu-block@nongnu.org, Max Reitz 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. Acked-by: Mark Kanda Signed-off-by: Eyal Moscovici Reviewed-by: Eric Blake --- qemu-img.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index afddf33f08..9cf8576217 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2860,9 +2860,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"); @@ -2871,8 +2870,8 @@ static int dump_map_entry(OutputFormat output_format,= MapEntry *e, } putchar('}'); =20 - if (!next) { - printf("]\n"); + if (next) { + printf(",\n"); } break; } @@ -3047,6 +3046,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) { + printf("["); } =20 length =3D blk_getlength(blk); @@ -3078,6 +3079,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) { + printf("]\n"); + } =20 out: blk_unref(blk); --=20 2.17.2 (Apple Git-113) From nobody Sun May 5 13:12:08 2024 Delivered-To: importer@patchew.org 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; 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=1584888491; cv=none; d=zohomail.com; s=zohoarc; b=DaWsOJh9AluChxf1BCZYFPu17zFpau3vvq2voLNa4gh9rXpxVBFkfkOilPV4Uwl5Pd7BtRIDRBvK9NHubJVgjz/aB2iK/9s7oaBq3YrhGQZMJYZAGZy+GqdMAoUpYULVIcKCsDUegyadpJrF/EPsSBMNHamQ9ZMHmPu2vbzvccI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584888491; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=4TKHpg48FG+WYR853DyAmnpjVBnplNSfECTD8ZLEO7A=; b=Qg7EIf1nZ+cDyZgLpMu68rRwDcNApOLqoKlihe+/iwK3d8cDOL7Cg6BsoDyOmdMswvwmluGTFK4ArQV3pYBBEobc7ZrZW3bVY07mR5CG0MhGKkUBYHfOzt9NY8OKeDXG4ivbWtue/9DFFZpDmFDlessdAXTzHBfV6vkeHzvNxSQ= 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 1584888491639126.46301969841; Sun, 22 Mar 2020 07:48:11 -0700 (PDT) Received: from localhost ([::1]:46909 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jG1ta-0007Gy-9I for importer@patchew.org; Sun, 22 Mar 2020 10:48:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54498) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFwdy-0005pc-F8 for qemu-devel@nongnu.org; Sun, 22 Mar 2020 05:11:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jFwdv-00015o-PL for qemu-devel@nongnu.org; Sun, 22 Mar 2020 05:11:41 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:56660) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jFwds-000149-H7; Sun, 22 Mar 2020 05:11:36 -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 02M9AEI1121158; Sun, 22 Mar 2020 09:11:35 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2ywbjmtm0c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 22 Mar 2020 09:11:35 +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 02M92gNC068686; Sun, 22 Mar 2020 09:11:35 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 2ywvmtye8g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 22 Mar 2020 09:11:35 +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 02M9BY3n003697; Sun, 22 Mar 2020 09:11:34 GMT Received: from localhost.localdomain (/10.74.126.182) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 22 Mar 2020 02:11:33 -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=4TKHpg48FG+WYR853DyAmnpjVBnplNSfECTD8ZLEO7A=; b=lEHlu2uB8/uxEUErYkUkN+z+5aLsWugZPcIEjbZwTAvaN5PchXoT6nYxwIyI1Tnuod7X hYSYW3b0FkObTXVmYY3ejByDFK6NG7CjPYa0bduJ3MUa5yzKV84iBIPSE4VbgDppJytH bdRI24QSBkcfgD37kxPqKkSI3dM/nnZgM1GCaXelq+S9cvmOW+uSOu5thLkk2c5AbFNe fikgfshhxT1r0nSjiChhuKduy1L8XGGBS/0xSpMc7mtYIRipn9+KXuTq8FT7mMnp3/eL tBQjfQhODw2mdoSt2iFZfc0UX9GOKcZ4Nio2cC+C5IeCs29kWF7lJABTYqWBipefBGkc fw== From: Eyal Moscovici To: qemu-devel@nongnu.org Subject: [PATCH 2/2] qemu-img: Add --start-offset and --max-length to map Date: Sun, 22 Mar 2020 11:11:17 +0200 Message-Id: <20200322091117.79443-3-eyal.moscovici@oracle.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20200322091117.79443-1-eyal.moscovici@oracle.com> References: <20200322091117.79443-1-eyal.moscovici@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9567 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 suspectscore=1 bulkscore=0 spamscore=0 mlxscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003220053 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9567 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 bulkscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 suspectscore=1 impostorscore=0 clxscore=1015 phishscore=0 mlxscore=0 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003220053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-Mailman-Approved-At: Sun, 22 Mar 2020 10:44:45 -0400 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, 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. Acked-by: Mark Kanda Co-developed-by: Yoav Elnekave Signed-off-by: Yoav Elnekave Signed-off-by: Eyal Moscovici Reviewed-by: Eric Blake --- docs/tools/qemu-img.rst | 2 +- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 30 +++++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 0080f83a76..924e89f679 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 9cf8576217..cd365b275e 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2967,6 +2967,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; @@ -2979,9 +2981,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; @@ -3005,6 +3009,26 @@ static int img_map(int argc, char **argv) case OPTION_OUTPUT: output =3D optarg; break; + case 's': + start_offset =3D cvtnum(optarg); + if (start_offset < 0) { + error_report("Invalid start offset specified! You may use " + "k, M, G, T, P or E suffixes for "); + error_report("kilobytes, megabytes, gigabytes, terabytes, " + "petabytes and exabytes."); + return 1; + } + break; + case 'l': + max_length =3D cvtnum(optarg); + if (max_length < 0) { + error_report("Invalid max length specified! You may use " + "k, M, G, T, P or E suffixes for "); + error_report("kilobytes, megabytes, gigabytes, terabytes, " + "petabytes and exabytes."); + return 1; + } + break; case OPTION_OBJECT: { QemuOpts *opts; opts =3D qemu_opts_parse_noisily(&qemu_object_opts, @@ -3050,7 +3074,11 @@ static int img_map(int argc, char **argv) printf("["); } =20 + curr.start =3D start_offset; length =3D blk_getlength(blk); + if (max_length !=3D -1) { + length =3D MIN(start_offset + max_length, length); + } while (curr.start + curr.length < length) { int64_t offset =3D curr.start + curr.length; int64_t n; --=20 2.17.2 (Apple Git-113)