From nobody Mon Feb 9 23:02:11 2026 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)