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 02AA2CAC5B0 for ; Mon, 29 Sep 2025 12:08:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1132744.1471034 (Exim 4.92) (envelope-from ) id 1v3Cfm-0000C7-QI; Mon, 29 Sep 2025 12:08:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1132744.1471034; Mon, 29 Sep 2025 12:08:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3Cfm-0000Bm-IP; Mon, 29 Sep 2025 12:08:06 +0000 Received: by outflank-mailman (input) for mailman id 1132744; Mon, 29 Sep 2025 12:08:05 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3Cfk-0008MS-Uh for xen-devel@lists.xenproject.org; Mon, 29 Sep 2025 12:08:04 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1v3Cfk-00GXBl-20; Mon, 29 Sep 2025 12:08:04 +0000 Received: from [2a01:cb15:80df:da00:e2a9:ff82:7bde:38cd] (helo=l14.home) by xenbits.xenproject.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v3Cfk-004JHo-27; Mon, 29 Sep 2025 12:08:04 +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=fd7IuQgDa95R64KYB4tblr0/98vW3XrqIHcr4eD97H4=; b=X203g5Yaxw9Ll+3MS5VUb9EOPi w5Q0flPWQK2T15TGrMdaV33NAB4xY5urY6whyNrUQ2EvLO0pzsNQ18lYaAs2LlVUMiiewvGOZ0vpf iFpihfU64n9aPKFtXy2ADhSU4ioWSLgaVSOytyYFxtZRQHhehyp2gvzm0+MaHXwJZEvk=; From: Anthony PERARD To: xen-devel@lists.xenproject.org Cc: Anthony PERARD , Jason Andryuk , Juergen Gross Subject: [XEN PATCH v2 6/8] tools/libxenstat: Use json-c when available Date: Mon, 29 Sep 2025 14:07:54 +0200 Message-ID: <20250929120756.46075-7-anthony@xenproject.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250929120756.46075-1-anthony@xenproject.org> References: <20250929120756.46075-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 Reviewed-by: Jason Andryuk --- Notes: v2: - use new $(XEN_JSON_LIBS) tools/libs/stat/Makefile | 2 +- tools/libs/stat/xenstat_qmp.c | 126 ++++++++++++++++++++++++++++++++-- 2 files changed, 120 insertions(+), 8 deletions(-) diff --git a/tools/libs/stat/Makefile b/tools/libs/stat/Makefile index a968eaff48..3151ee9f12 100644 --- a/tools/libs/stat/Makefile +++ b/tools/libs/stat/Makefile @@ -24,7 +24,7 @@ OBJS-$(CONFIG_SunOS) += xenstat_solaris.o OBJS-$(CONFIG_NetBSD) += xenstat_netbsd.o OBJS-$(CONFIG_FreeBSD) += xenstat_freebsd.o -LDLIBS-y += -lyajl +LDLIBS-y += $(XEN_JSON_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