Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 489C6C87FDA for ; Fri, 8 Aug 2025 14:56:27 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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: 8bit From: Anthony PERARD This is mainly a copy of the existing code in yajl and use json-c instead. Signed-off-by: Anthony PERARD --- 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) += xenstat_solaris.o OBJS-$(CONFIG_NetBSD) += xenstat_netbsd.o OBJS-$(CONFIG_FreeBSD) += xenstat_freebsd.o -LDLIBS-y += -lyajl +LDLIBS-y += $(YAJL_LIBS) +LDLIBS-y += $(LIBJSONC_LIBS) LDLIBS-$(CONFIG_SunOS) += -lkstat LDLIBS += $(LDLIBS-y) 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 @@ #include "xenstat_priv.h" +#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 #ifdef HAVE_YAJL_V2 - #include +#endif +#if defined(HAVE_LIBJSONC) || defined(HAVE_YAJL_V2) static unsigned char *qmp_query(int, const char *); enum query_blockstats { @@ -76,9 +82,10 @@ enum query_block { "type": 'str' }]} */ -static char *qmp_get_block_image(xenstat_node *node, char *qmp_devname, int qfd) +static char *qmp_get_block_image(xenstat_node *node, const char *qmp_devname, int qfd) { - char *tmp, *file = NULL; + const char *tmp; + char *file = NULL; const char *query_block_cmd = "{ \"execute\": \"query-block\" }"; static const char *const qblock[] = { [ QMP_BLOCK_RETURN ] = "return", @@ -88,13 +95,56 @@ static char *qmp_get_block_image(xenstat_node *node, char *qmp_devname, int qfd) }; const char *ptr[] = {0, 0}; unsigned char *qmp_stats; - yajl_val info, ret_obj, dev_obj, n; int i; if ((qmp_stats = qmp_query(qfd, query_block_cmd)) == NULL) return NULL; +#ifdef HAVE_LIBJSONC + json_object *jso; + enum json_tokener_error error; + jso = json_tokener_parse_verbose((const char *)qmp_stats, &error); + free(qmp_stats); + if (jso == NULL) + return NULL; + + ptr[0] = qblock[QMP_BLOCK_RETURN]; /* "return" */ + json_object *ret_jso = json_object_object_get(jso, ptr[0]); + if (ret_jso == NULL) + goto done; + + for (i=0; i