From nobody Tue Dec 16 08:32:44 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1754664991; cv=none; d=zohomail.com; s=zohoarc; b=Od7GurmB2krajIV/Ieokw9eCdqUXT0HKz+xo9NQ6+NPNcOVPNzKVZ9i5ITYwt4YVDIJlqYju/KVE/Q6a2ltcsuF5acgVByi6jgdgauZIFjYPNeEzGgvFYzJiz1G+Ndf6hDKcVqYuovEoUpKHjqGarh8mX4me3qyOTp1eusfkXCY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754664991; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=f3B1XR/rJqzESb9x9Ihv7VOZk7psRW9ng9FNM3jhUwY=; b=CpMI/UpOiZntYFxCoKc66R6W4SfhJJQ8kjAcE99HSuRLtTOccgSwq7JwYRv7pADrArUqygKmo2YEyjjViM6dc6XTJnZkqLaWbaY28iApuWga5G7vYCb5QODS2T8J8Hu86dEnifpt+PLCdD4hZb+5+ScUtVmsljhtvlQKWfv26ro= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1754664991346130.37672391490253; Fri, 8 Aug 2025 07:56:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1074671.1437225 (Exim 4.92) (envelope-from ) id 1ukOVz-0001jP-39; Fri, 08 Aug 2025 14:56:15 +0000 Received: by outflank-mailman (output) from mailman id 1074671.1437225; Fri, 08 Aug 2025 14:56:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ukOVy-0001ht-Sf; Fri, 08 Aug 2025 14:56:14 +0000 Received: by outflank-mailman (input) for mailman id 1074671; Fri, 08 Aug 2025 14:56:13 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ukOVx-0001QK-J2 for xen-devel@lists.xenproject.org; Fri, 08 Aug 2025 14:56:13 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1ukOVx-007zrz-1I; Fri, 08 Aug 2025 14:56:13 +0000 Received: from [2a01:e0a:1da:8420:b77:bd5:6e45:7633] (helo=l14..) by xenbits.xenproject.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ukOVx-009BYT-0R; Fri, 08 Aug 2025 14:56:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xenproject.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=f3B1XR/rJqzESb9x9Ihv7VOZk7psRW9ng9FNM3jhUwY=; b=BGYlQfWXBzDQz4BrtRW8Dn5nPG 2R5//+BgDe8stX3MZHkI252eE/IYblCZ82+rLY4026MIwGysx1pi/9GwXBVduF+sTJsZR8qcqVgZf +pAWRePIk6SKUGCSqn2zFEPuC7rsnVY/+adAIRfFi7oquHuSY7cgrWsM/lVlgu+Aun2c=; From: Anthony PERARD To: xen-devel@lists.xenproject.org Cc: Anthony PERARD , Juergen Gross Subject: [XEN PATCH 09/11] tools/libxenstat: Use json-c when available Date: Fri, 8 Aug 2025 16:56:00 +0200 Message-Id: <20250808145602.41716-10-anthony@xenproject.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250808145602.41716-1-anthony@xenproject.org> References: <20250808145602.41716-1-anthony@xenproject.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xenproject.org) X-ZM-MESSAGEID: 1754664993403124100 Content-Type: text/plain; charset="utf-8" From: Anthony PERARD This is mainly a copy of the existing code in yajl and use json-c instead. Signed-off-by: Anthony PERARD Reviewed-by: Jason Andryuk --- tools/libs/stat/Makefile | 3 +- tools/libs/stat/xenstat_qmp.c | 126 ++++++++++++++++++++++++++++++++-- 2 files changed, 121 insertions(+), 8 deletions(-) diff --git a/tools/libs/stat/Makefile b/tools/libs/stat/Makefile index a968eaff48..3f13cf07be 100644 --- a/tools/libs/stat/Makefile +++ b/tools/libs/stat/Makefile @@ -24,7 +24,8 @@ OBJS-$(CONFIG_SunOS) +=3D xenstat_solaris.o OBJS-$(CONFIG_NetBSD) +=3D xenstat_netbsd.o OBJS-$(CONFIG_FreeBSD) +=3D xenstat_freebsd.o =20 -LDLIBS-y +=3D -lyajl +LDLIBS-y +=3D $(YAJL_LIBS) +LDLIBS-y +=3D $(LIBJSONC_LIBS) LDLIBS-$(CONFIG_SunOS) +=3D -lkstat LDLIBS +=3D $(LDLIBS-y) =20 diff --git a/tools/libs/stat/xenstat_qmp.c b/tools/libs/stat/xenstat_qmp.c index 9909b9727e..21e321fffa 100644 --- a/tools/libs/stat/xenstat_qmp.c +++ b/tools/libs/stat/xenstat_qmp.c @@ -24,6 +24,10 @@ =20 #include "xenstat_priv.h" =20 +#ifdef HAVE_LIBJSONC +#include + +#elif defined(HAVE_LIBYAJL) #ifdef HAVE_YAJL_YAJL_VERSION_H # include #endif @@ -32,11 +36,13 @@ #if defined(YAJL_MAJOR) && (YAJL_MAJOR > 1) # define HAVE_YAJL_V2 1 #endif +#endif =20 #ifdef HAVE_YAJL_V2 - #include +#endif =20 +#if defined(HAVE_LIBJSONC) || defined(HAVE_YAJL_V2) static unsigned char *qmp_query(int, const char *); =20 enum query_blockstats { @@ -76,9 +82,10 @@ enum query_block { "type": 'str' }]} */ -static char *qmp_get_block_image(xenstat_node *node, char *qmp_devname, in= t qfd) +static char *qmp_get_block_image(xenstat_node *node, const char *qmp_devna= me, int qfd) { - char *tmp, *file =3D NULL; + const char *tmp; + char *file =3D NULL; const char *query_block_cmd =3D "{ \"execute\": \"query-block\" }"; static const char *const qblock[] =3D { [ QMP_BLOCK_RETURN ] =3D "return", @@ -88,13 +95,56 @@ static char *qmp_get_block_image(xenstat_node *node, ch= ar *qmp_devname, int qfd) }; const char *ptr[] =3D {0, 0}; unsigned char *qmp_stats; - yajl_val info, ret_obj, dev_obj, n; int i; =20 if ((qmp_stats =3D qmp_query(qfd, query_block_cmd)) =3D=3D NULL) return NULL; =20 +#ifdef HAVE_LIBJSONC + json_object *jso; + enum json_tokener_error error; + jso =3D json_tokener_parse_verbose((const char *)qmp_stats, &error); + free(qmp_stats); + if (jso =3D=3D NULL) + return NULL; + + ptr[0] =3D qblock[QMP_BLOCK_RETURN]; /* "return" */ + json_object *ret_jso =3D json_object_object_get(jso, ptr[0]); + if (ret_jso =3D=3D NULL) + goto done; + + for (i=3D0; i