From nobody Sat Oct 4 22:00:05 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=1759147709; cv=none; d=zohomail.com; s=zohoarc; b=WxOnsJzRnMLKpJ9LseY0eudCLkaAdSlHt4n8czrDck9zaqNcEGDp8Ute9+dGWFPdC9NHjcH0rVQzihMGK6hfrYuXTt2ZlB6Ac/YX7gtVhrPGKdAZXX3e2imnwJG37qkvXi40oLZjsFDt9oloF6ad1wuqgy7FATbHdi3j3Qnz1ko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759147709; 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=TkLeJKOy6W2+2/EbdbLvrKVsvOauvUqw0+FWVe+Qo5U=; b=djwxMoLGLz/FX4jCDCKnkqQBeY/gnY25sy+h5Nj/bG1GLfria1fsM3Q8p9ldJXoG7/eHyr7/1YOnoAGrtYayoR36Cu//KRBh9a8++cUpeEx3f1s5LonAIB9x+zv8vmu1s453u1Fjr63JYRwBWgXTBZMT2CxqSZy00z72HvRB2SU= 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 1759147709898100.23749909751712; Mon, 29 Sep 2025 05:08:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1132738.1470977 (Exim 4.92) (envelope-from ) id 1v3Cfh-0007QG-Pl; Mon, 29 Sep 2025 12:08:01 +0000 Received: by outflank-mailman (output) from mailman id 1132738.1470977; Mon, 29 Sep 2025 12:08:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3Cfh-0007Q9-Ml; Mon, 29 Sep 2025 12:08:01 +0000 Received: by outflank-mailman (input) for mailman id 1132738; Mon, 29 Sep 2025 12:08:00 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3Cfg-0007Pr-4u for xen-devel@lists.xenproject.org; Mon, 29 Sep 2025 12:08:00 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1v3Cff-00GXAu-2k; Mon, 29 Sep 2025 12:07:59 +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 1v3Cff-004JHo-2o; Mon, 29 Sep 2025 12:07:59 +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=TkLeJKOy6W2+2/EbdbLvrKVsvOauvUqw0+FWVe+Qo5U=; b=KOPHVlCU3Hqbv1GIBsL7wMjXTv EBRaUzQxZQgXdw61BgRWDOGSEIxKG3Ni7e1K4hs2/3tYGMc2TNr7puBHE5jNt9OjjpQNA81Lj18db lC+EbSUedTHcoJd4JBhZ2E/r4fk8lkZPJotnr0B/jkn7nix9ZM20Z2njqhgFJclyZL2U=; From: Anthony PERARD To: xen-devel@lists.xenproject.org Cc: Anthony PERARD , Juergen Gross Subject: [XEN PATCH v2 1/8] tools/configure: Introduce deps on json-c lib for libxl Date: Mon, 29 Sep 2025 14:07:49 +0200 Message-ID: <20250929120756.46075-2-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: quoted-printable X-ZohoMail-DKIM: pass (identity @xenproject.org) X-ZM-MESSAGEID: 1759147713285116600 Content-Type: text/plain; charset="utf-8" From: Anthony PERARD To replace yajl. Introduce XEN_JSON_LIBS variable, to be able to remove "-lyajl" later. As a first step, the variable will have both or only -lyajl. Then commit "configure: Use json-c by default, fallback to yajl" will make a change to only have one or the other once the code is ready to build with only json-c. Signed-off-by: Anthony PERARD Acked-by: Andrew Cooper Reviewed-by: Jason Andryuk --- Notes: v2: - Introduce $(XEN_JSON_LIBS) to contain either of -lyajl or -ljson-c or both. At first, the variable will have both or only -lyajl, then commit "configure: Use json-c by default, fallback to yajl" will make a change to only have one or the other. config/Tools.mk.in | 1 + tools/config.h.in | 3 ++ tools/configure | 107 +++++++++++++++++++++++++++++++++++++- tools/configure.ac | 6 ++- tools/libs/light/Makefile | 4 +- tools/xl/Makefile | 2 +- 6 files changed, 117 insertions(+), 6 deletions(-) diff --git a/config/Tools.mk.in b/config/Tools.mk.in index e47ac23d11..0037ad5a64 100644 --- a/config/Tools.mk.in +++ b/config/Tools.mk.in @@ -65,6 +65,7 @@ EXTFS_LIBS :=3D @EXTFS_LIBS@ CURSES_LIBS :=3D @CURSES_LIBS@ TINFO_LIBS :=3D @TINFO_LIBS@ ARGP_LDFLAGS :=3D @argp_ldflags@ +XEN_JSON_LIBS :=3D @YAJL_LIBS@ @libjsonc_LIBS@ =20 FILE_OFFSET_BITS :=3D @FILE_OFFSET_BITS@ =20 diff --git a/tools/config.h.in b/tools/config.h.in index fe2a94cfc4..ed0042018d 100644 --- a/tools/config.h.in +++ b/tools/config.h.in @@ -27,6 +27,9 @@ /* Define to 1 if you have the `fdt' library (-lfdt). */ #undef HAVE_LIBFDT =20 +/* Use library json-c */ +#undef HAVE_LIBJSONC + /* Define to 1 if you have the `lzma' library (-llzma). */ #undef HAVE_LIBLZMA =20 diff --git a/tools/configure b/tools/configure index 5abd44e21e..edd1701b2d 100755 --- a/tools/configure +++ b/tools/configure @@ -660,6 +660,9 @@ libnl LIBNL3_LIBS LIBNL3_CFLAGS argp_ldflags +YAJL_LIBS +libjsonc_LIBS +libjsonc_CFLAGS PTHREAD_LIBS PTHREAD_LDFLAGS PTHREAD_CFLAGS @@ -882,6 +885,8 @@ pixman_CFLAGS pixman_LIBS libzstd_CFLAGS libzstd_LIBS +libjsonc_CFLAGS +libjsonc_LIBS LIBNL3_CFLAGS LIBNL3_LIBS SYSTEMD_SLEEP_DIR' @@ -1633,6 +1638,10 @@ Some influential environment variables: C compiler flags for libzstd, overriding pkg-config libzstd_LIBS linker flags for libzstd, overriding pkg-config + libjsonc_CFLAGS + C compiler flags for libjsonc, overriding pkg-config + libjsonc_LIBS + linker flags for libjsonc, overriding pkg-config LIBNL3_CFLAGS C compiler flags for LIBNL3, overriding pkg-config LIBNL3_LIBS linker flags for LIBNL3, overriding pkg-config @@ -9624,6 +9633,99 @@ printf "%s\n" "$ax_cv_pthread_flags" >&6; } =20 =20 =20 + +pkg_failed=3Dno +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for libjsonc" >&5 +printf %s "checking for libjsonc... " >&6; } + +if test -n "$libjsonc_CFLAGS"; then + pkg_cv_libjsonc_CFLAGS=3D"$libjsonc_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists = --print-errors \"json-c\""; } >&5 + ($PKG_CONFIG --exists --print-errors "json-c") 2>&5 + ac_status=3D$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? =3D $ac_status" >&5 + test $ac_status =3D 0; }; then + pkg_cv_libjsonc_CFLAGS=3D`$PKG_CONFIG --cflags "json-c" 2>/dev/null` + test "x$?" !=3D "x0" && pkg_failed=3Dyes +else + pkg_failed=3Dyes +fi + else + pkg_failed=3Duntried +fi +if test -n "$libjsonc_LIBS"; then + pkg_cv_libjsonc_LIBS=3D"$libjsonc_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists = --print-errors \"json-c\""; } >&5 + ($PKG_CONFIG --exists --print-errors "json-c") 2>&5 + ac_status=3D$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? =3D $ac_status" >&5 + test $ac_status =3D 0; }; then + pkg_cv_libjsonc_LIBS=3D`$PKG_CONFIG --libs "json-c" 2>/dev/null` + test "x$?" !=3D "x0" && pkg_failed=3Dyes +else + pkg_failed=3Dyes +fi + else + pkg_failed=3Duntried +fi + + + +if test $pkg_failed =3D yes; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=3Dyes +else + _pkg_short_errors_supported=3Dno +fi + if test $_pkg_short_errors_supported =3D yes; then + libjsonc_PKG_ERRORS=3D`$PKG_CONFIG --short-errors --print-errors = --cflags --libs "json-c" 2>&1` + else + libjsonc_PKG_ERRORS=3D`$PKG_CONFIG --print-errors --cflags --libs= "json-c" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$libjsonc_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements (json-c) were not met: + +$libjsonc_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables libjsonc_CFLAGS +and libjsonc_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 +elif test $pkg_failed =3D untried; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. M= ake sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables libjsonc_CFLAGS +and libjsonc_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } +else + libjsonc_CFLAGS=3D$pkg_cv_libjsonc_CFLAGS + libjsonc_LIBS=3D$pkg_cv_libjsonc_LIBS + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + +printf "%s\n" "#define HAVE_LIBJSONC 1" >>confdefs.h + +fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for yajl_alloc in -= lyajl" >&5 printf %s "checking for yajl_alloc in -lyajl... " >&6; } if test ${ac_cv_lib_yajl_yajl_alloc+y} @@ -9661,9 +9763,10 @@ fi printf "%s\n" "$ac_cv_lib_yajl_yajl_alloc" >&6; } if test "x$ac_cv_lib_yajl_yajl_alloc" =3D xyes then : - printf "%s\n" "#define HAVE_LIBYAJL 1" >>confdefs.h + YAJL_LIBS=3D-lyajl =20 - LIBS=3D"-lyajl $LIBS" + +printf "%s\n" "#define HAVE_LIBYAJL 1" >>confdefs.h =20 else $as_nop as_fn_error $? "Could not find yajl" "$LINENO" 5 diff --git a/tools/configure.ac b/tools/configure.ac index dada1c3b15..bb40b5b3f0 100644 --- a/tools/configure.ac +++ b/tools/configure.ac @@ -424,7 +424,11 @@ AC_SUBST([ZLIB_CFLAGS]) AC_SUBST([ZLIB_LIBS]) AX_CHECK_EXTFS AX_CHECK_PTHREAD -AC_CHECK_LIB([yajl], [yajl_alloc], [], +PKG_CHECK_MODULES([libjsonc], [json-c], + [AC_DEFINE([HAVE_LIBJSONC], [1], [Use library json-c])]) +AC_CHECK_LIB([yajl], [yajl_alloc], + [AC_SUBST([YAJL_LIBS],[-lyajl]) + AC_DEFINE([HAVE_LIBYAJL],[1],[Define to 1 if you have the `yajl' libra= ry (-lyajl).])], [AC_MSG_ERROR([Could not find yajl])]) AC_CHECK_LIB([z], [deflateCopy], [], [AC_MSG_ERROR([Could not find zlib])]) AC_CHECK_HEADER([argp.h], [ diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile index b690d92159..c05d89db33 100644 --- a/tools/libs/light/Makefile +++ b/tools/libs/light/Makefile @@ -166,7 +166,7 @@ LDLIBS-$(CONFIG_Linux) +=3D -luuid LDLIBS-$(CONFIG_Linux) +=3D -lrt LDLIBS-$(CONFIG_ARM) +=3D -lfdt LDLIBS-y +=3D $(PTHREAD_LIBS) -LDLIBS-y +=3D -lyajl +LDLIBS-y +=3D $(XEN_JSON_LIBS) LDLIBS +=3D $(LDLIBS-y) =20 $(OBJS-y) $(PIC_OBJS) $(LIBXL_TEST_OBJS): CFLAGS +=3D $(CFLAGS_LIBXL) -inc= lude $(XEN_ROOT)/tools/config.h @@ -246,7 +246,7 @@ libxenlight_test.so: $(PIC_OBJS) $(LIBXL_TEST_OBJS) $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenlight.so.$(MAJOR) $(SHLIB= _LDFLAGS) -o $@ $^ $(LDLIBS) $(APPEND_LDFLAGS) =20 test_%: test_%.o test_common.o libxenlight_test.so - $(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenli= ght)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) -lyajl $(APPEND_LDFL= AGS) + $(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenli= ght)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(XEN_JSON_LIBS) $(A= PPEND_LDFLAGS) =20 libxl-save-helper: $(SAVE_HELPER_OBJS) libxenlight.so $(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) $(LDLI= BS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxentoolcore) $(APPEND_LDFL= AGS) diff --git a/tools/xl/Makefile b/tools/xl/Makefile index ad577cdd70..973ff0e1a2 100644 --- a/tools/xl/Makefile +++ b/tools/xl/Makefile @@ -33,7 +33,7 @@ $(XL_OBJS): CFLAGS +=3D -include $(XEN_ROOT)/tools/config= .h # libxl_json.h needs i all: xl =20 xl: $(XL_OBJS) - $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlig= ht) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) -lyajl $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlig= ht) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(XEN_JSON_LIBS) $(APPEND= _LDFLAGS) =20 .PHONY: install install: all --=20 Anthony PERARD From nobody Sat Oct 4 22:00:05 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=1759147701; cv=none; d=zohomail.com; s=zohoarc; b=EgaQiSX7IrjgrJXDUHGeUGCo2Get/cI4/xAOOihduLJekrEdfZKciqFCjJfMy+kdRKFXpnYF0FMUzH32JKSuWM3PuscGG60yP8CXeZ+VXZT37TD+cT9izzUno86tWF5Iue6ECWY3tS1WtzbEGSFectBi0xsqEUjFvoIRrqCL648= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759147701; 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=U48btwyJU9uvDQVplZTudvitSWkJbIw5OvKyUBUKozM=; b=YMQJwhS2GWgFsgNhNsMFRecEVdYuvsSe/BMRkL+8MB+aaqrCyUPSCWtJG//Fe4iaPRsDj4h/zdhx5v+t0TqJT+UYrYY9gsU7NTlyyDmwi+Plo2niEoT9qY4U90M4Te7S50lTssW5OncKmTIK3l/WiZdt+HQIqTY4x9cuBxOalTI= 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 1759147701137175.17349218034167; Mon, 29 Sep 2025 05:08:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1132740.1470987 (Exim 4.92) (envelope-from ) id 1v3Cfi-0007X9-A6; Mon, 29 Sep 2025 12:08:02 +0000 Received: by outflank-mailman (output) from mailman id 1132740.1470987; Mon, 29 Sep 2025 12:08:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3Cfi-0007WN-4y; Mon, 29 Sep 2025 12:08:02 +0000 Received: by outflank-mailman (input) for mailman id 1132740; Mon, 29 Sep 2025 12:08:01 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3Cfh-0007Q3-2M for xen-devel@lists.xenproject.org; Mon, 29 Sep 2025 12:08:01 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1v3Cfg-00GXB3-2U; Mon, 29 Sep 2025 12:08:00 +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 1v3Cfg-004JHo-2a; Mon, 29 Sep 2025 12:08:00 +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=U48btwyJU9uvDQVplZTudvitSWkJbIw5OvKyUBUKozM=; b=ztZtTQFGGsBFuEkgZBeghumveO irYazE1PvvQ+bhmwLWfpa+e+/Hi3ZV1smhGm5n7E+xKFAYMtKgep6MKcSTjigL7yN9lk0bk2F01zn p3J6edxwYiSrCQ2vZmPmbkCaTdjL7jAVK6IjcSLnfDnY/Ff9MRH0PiBKGLp5XFEjL7Z4=; From: Anthony PERARD To: xen-devel@lists.xenproject.org Cc: Anthony PERARD , Jason Andryuk , Juergen Gross Subject: [XEN PATCH v2 2/8] libxl: Convert libxl__json_parse() to use json-c Date: Mon, 29 Sep 2025 14:07:50 +0200 Message-ID: <20250929120756.46075-3-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: quoted-printable X-ZohoMail-DKIM: pass (identity @xenproject.org) X-ZM-MESSAGEID: 1759147702213116600 Content-Type: text/plain; charset="utf-8" From: Anthony PERARD This reuse the "json_callback_*" implemented for the yajl parser as they don't really need to be changed. It's just awkward to have to cast between `unsigned char` and `char.` Replace few strncpy() by memcpy() to let the compiler know we want to copy the string without the terminating nul, as we are adding it just after. Also, it should be possible to keep using YAJL parser when json-c library isn't available. Signed-off-by: Anthony PERARD Reviewed-by: Jason Andryuk --- tools/include/libxl_json.h | 4 ++ tools/libs/light/libxl_json.c | 120 ++++++++++++++++++++++++++++++++-- 2 files changed, 120 insertions(+), 4 deletions(-) diff --git a/tools/include/libxl_json.h b/tools/include/libxl_json.h index 3f97267eae..f0b4871e0e 100644 --- a/tools/include/libxl_json.h +++ b/tools/include/libxl_json.h @@ -42,6 +42,7 @@ yajl_gen_status libxl_ms_vm_genid_gen_json(yajl_gen hand,= libxl_ms_vm_genid *p); # define HAVE_YAJL_V2 1 #endif =20 +#ifdef HAVE_LIBYAJL #ifdef HAVE_YAJL_V2 =20 typedef size_t libxl_yajl_length; @@ -89,5 +90,8 @@ static inline yajl_gen libxl_yajl_gen_alloc(const yajl_al= loc_funcs *allocFuncs) } =20 #endif /* !HAVE_YAJL_V2 */ +#else +typedef size_t libxl_yajl_length; +#endif /* !HAVE_LIBYAJL */ =20 #endif /* LIBXL_JSON_H */ diff --git a/tools/libs/light/libxl_json.c b/tools/libs/light/libxl_json.c index 9b8ef2cab9..44ee6e213f 100644 --- a/tools/libs/light/libxl_json.c +++ b/tools/libs/light/libxl_json.c @@ -16,7 +16,25 @@ =20 #include =20 +#ifdef HAVE_LIBJSONC +#include +#define USE_LIBJSONC_PARSER +#endif + +#ifdef HAVE_LIBYAJL +# ifndef USE_LIBJSONC_PARSER +# define USE_LIBYAJL_PARSER +# endif +#endif + + +#ifdef USE_LIBJSONC_PARSER +#include +#endif + +#ifdef USE_LIBYAJL_PARSER #include +#endif #include =20 #include "libxl_internal.h" @@ -25,7 +43,9 @@ =20 typedef struct libxl__yajl_ctx { libxl__gc *gc; +#ifdef USE_LIBYAJL_PARSER yajl_handle hand; +#endif libxl__json_object *head; libxl__json_object *current; #ifdef DEBUG_ANSWER @@ -33,7 +53,7 @@ typedef struct libxl__yajl_ctx { #endif } libxl__yajl_ctx; =20 -#ifdef DEBUG_ANSWER +#if defined(DEBUG_ANSWER) && defined(USE_LIBYAJL_PARSER) #if YAJL_VERSION < 20000 # define DEBUG_GEN_ALLOC(ctx) \ if ((ctx)->g =3D=3D NULL) { \ @@ -759,7 +779,7 @@ static int json_callback_number(void *opaque, const cha= r *s, libxl_yajl_length l obj =3D libxl__json_object_alloc(ctx->gc, JSON_NUMBER); =20 t =3D libxl__zalloc(ctx->gc, len + 1); - strncpy(t, s, len); + memcpy(t, s, len); t[len] =3D 0; =20 obj->u.string =3D t; @@ -806,7 +826,7 @@ static int json_callback_map_key(void *opaque, const un= signed char *str, =20 DEBUG_GEN_STRING(ctx, str, len); =20 - strncpy(t, (const char *) str, len); + memcpy(t, (const char *) str, len); t[len] =3D 0; =20 if (libxl__json_object_is_map(obj)) { @@ -890,6 +910,7 @@ static int json_callback_end_array(void *opaque) return 1; } =20 +#ifdef USE_LIBYAJL_PARSER static yajl_callbacks callbacks =3D { json_callback_null, json_callback_boolean, @@ -903,28 +924,111 @@ static yajl_callbacks callbacks =3D { json_callback_start_array, json_callback_end_array }; +#endif =20 static void yajl_ctx_free(libxl__yajl_ctx *yajl_ctx) { +#ifdef USE_LIBYAJL_PARSER if (yajl_ctx->hand) { yajl_free(yajl_ctx->hand); yajl_ctx->hand =3D NULL; } +#endif DEBUG_GEN_FREE(yajl_ctx); } =20 +#ifdef USE_LIBJSONC_PARSER +static int jso_visiter(json_object *jso, + int flags, + json_object *parent_jso, + const char *jso_key, + size_t *jso_index, + void *userarg) +{ + enum json_type type; + int r; + + if (jso_key && flags !=3D JSON_C_VISIT_SECOND) { + json_callback_map_key(userarg, (const unsigned char*)jso_key, strl= en(jso_key)); + } + type =3D json_object_get_type(jso); + switch (type) { + case json_type_null: + r =3D json_callback_null(userarg); + break; + case json_type_boolean: + r =3D json_callback_boolean(userarg, json_object_get_boolean(jso)); + break; + case json_type_int: + case json_type_double: { + // it might be better to use on of + // json_object_get_{int,int64,uint64,double} instead. + // but would need to replace json_callback_number(). + const char *s =3D json_object_get_string(jso); + r =3D json_callback_number(userarg, s, strlen(s)); + break; + } + case json_type_object: + if (flags !=3D JSON_C_VISIT_SECOND) { + r =3D json_callback_start_map(userarg); + } else { + r =3D json_callback_end_map(userarg); + } + break; + case json_type_array: + if (flags !=3D JSON_C_VISIT_SECOND) { + r =3D json_callback_start_array(userarg); + } else { + r =3D json_callback_end_array(userarg); + } + break; + case json_type_string: { + const char *s =3D json_object_get_string(jso); + const int len =3D json_object_get_string_len(jso); + r =3D json_callback_string(userarg, (const unsigned char*)s, len); + break; + } + default: + /* error */ + r =3D 0; + } + if (r =3D=3D 0) + return JSON_C_VISIT_RETURN_ERROR; + return JSON_C_VISIT_RETURN_CONTINUE; +} +#endif + libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s) { +#ifdef USE_LIBYAJL_PARSER yajl_status status; + unsigned char *str =3D NULL; +#endif libxl__yajl_ctx yajl_ctx; libxl__json_object *o =3D NULL; - unsigned char *str =3D NULL; +#ifdef USE_LIBJSONC_PARSER + json_object *jso; + enum json_tokener_error error; + + jso =3D json_tokener_parse_verbose(s, &error); + if (!jso) { + LOG(ERROR, "json-c parse error: %s", json_tokener_error_desc(error= )); + goto out; + } +#endif =20 memset(&yajl_ctx, 0, sizeof (yajl_ctx)); yajl_ctx.gc =3D gc; =20 DEBUG_GEN_ALLOC(&yajl_ctx); =20 +#ifdef USE_LIBJSONC_PARSER + int r =3D json_c_visit(jso, 0, jso_visiter, &yajl_ctx); + if (r < 0) { + LOG(ERROR, "json_c_visit failed"); + goto out; + } +#elif defined(USE_LIBYAJL_PARSER) if (yajl_ctx.hand =3D=3D NULL) { yajl_ctx.hand =3D libxl__yajl_alloc(&callbacks, NULL, &yajl_ctx); } @@ -935,6 +1039,7 @@ libxl__json_object *libxl__json_parse(libxl__gc *gc, c= onst char *s) status =3D yajl_complete_parse(yajl_ctx.hand); if (status !=3D yajl_status_ok) goto out; +#endif =20 o =3D yajl_ctx.head; =20 @@ -943,13 +1048,20 @@ libxl__json_object *libxl__json_parse(libxl__gc *gc,= const char *s) yajl_ctx.head =3D NULL; =20 yajl_ctx_free(&yajl_ctx); +#ifdef USE_LIBJSONC_PARSER + json_object_put(jso); +#endif return o; =20 out: +#ifdef USE_LIBJSONC_PARSER + json_object_put(jso); +#elif defined(USE_LIBYAJL_PARSER) str =3D yajl_get_error(yajl_ctx.hand, 1, (const unsigned char*)s, strl= en(s)); =20 LIBXL__LOG(libxl__gc_owner(gc), LIBXL__LOG_ERROR, "yajl error: %s", st= r); yajl_free_error(yajl_ctx.hand, str); +#endif yajl_ctx_free(&yajl_ctx); return NULL; } --=20 Anthony PERARD From nobody Sat Oct 4 22:00:05 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=1759147717; cv=none; d=zohomail.com; s=zohoarc; b=XH18IDTsk1VnzcQNvwxh/eJqEutg6BuF1V3JjiLyjLo0zeSWEz8BYjIQUwUgJCjtys6CzP54/FGySn4biKKT7lZ0wwFzSJ7OgUii7RtXESpwltr6acm+8xrfeUItNiqhA78jiU4uxwbxJlDtKBPAKM69IoMO8PkLDa+UZKpqex4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759147717; 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=j0zZ2dT1fhfsBSW2ysbdrRB/kmY03la1y9qVx0g8+RM=; b=mP975UsV13TwiAsW6s78xgHqTBDyvhuMy3lmQ+jtJWqQ/u4sx3znUbD1krwCymMhQu0jKOxkxU12bfLBNgIzBl93oWsyV1GllVg9fNS2t/M8o4Sla+vEK9b3PKYreunv9zW0NT/FSFU6vadFUhaKp8CnZ9hepWK0jXmKmS6Foe8= 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 1759147717010107.56584005339585; Mon, 29 Sep 2025 05:08:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1132741.1471008 (Exim 4.92) (envelope-from ) id 1v3Cfj-00084w-Fb; Mon, 29 Sep 2025 12:08:03 +0000 Received: by outflank-mailman (output) from mailman id 1132741.1471008; Mon, 29 Sep 2025 12:08:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3Cfj-00084m-CB; Mon, 29 Sep 2025 12:08:03 +0000 Received: by outflank-mailman (input) for mailman id 1132741; Mon, 29 Sep 2025 12:08:02 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3Cfh-0007T0-W8 for xen-devel@lists.xenproject.org; Mon, 29 Sep 2025 12:08:01 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1v3Cfh-00GXBN-2I; Mon, 29 Sep 2025 12:08:01 +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 1v3Cfh-004JHo-2O; Mon, 29 Sep 2025 12:08:01 +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=j0zZ2dT1fhfsBSW2ysbdrRB/kmY03la1y9qVx0g8+RM=; b=SjVfFDflBZ610y32EMC0u0eAI6 mK2QfpMRNOXpBwQA3AdvIeCfnJXca8P/ioSjzurE3hO/XjNNSPXR+P415irJRrJ1UsYUb/Z7ej5/l zANGZzVHg7GzNSlM697DMa5o8S8IqWiEEMUEP3vs+xeRPkI1M/0tBIGb7cnzez1Ip3JA=; From: Anthony PERARD To: xen-devel@lists.xenproject.org Cc: Anthony PERARD , Jason Andryuk , Juergen Gross Subject: [XEN PATCH v2 3/8] libxl: convert libxl__json_object_to_yajl_gen to libxl__json_object_to_libjsonc_object Date: Mon, 29 Sep 2025 14:07:51 +0200 Message-ID: <20250929120756.46075-4-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: quoted-printable X-ZohoMail-DKIM: pass (identity @xenproject.org) X-ZM-MESSAGEID: 1759147718478116600 Content-Type: text/plain; charset="utf-8" From: Anthony PERARD Convert yajl_gen to json_object from lib json-c. And make use of it in qmp_prepare_cmd(), which can be compiled with either lib. Signed-off-by: Anthony PERARD Reviewed-by: Jason Andryuk --- Notes: v2: - In libxl__json_object_to_json_object(), when generating a `json_object` from JSON_NUMBER, use json_object_new_double_s() instead of json_object_new_string(). This way, the json-c implementation will behave like the yajl one when number are bigger than int64, which is very unlikely. tools/include/libxl_json.h | 6 ++ tools/libs/light/libxl_internal.h | 7 +++ tools/libs/light/libxl_json.c | 100 ++++++++++++++++++++++++++++++ tools/libs/light/libxl_qmp.c | 53 ++++++++++++++++ 4 files changed, 166 insertions(+) diff --git a/tools/include/libxl_json.h b/tools/include/libxl_json.h index f0b4871e0e..e2ef8151f0 100644 --- a/tools/include/libxl_json.h +++ b/tools/include/libxl_json.h @@ -15,12 +15,18 @@ #ifndef LIBXL_JSON_H #define LIBXL_JSON_H =20 +#ifdef HAVE_LIBJSONC +#include +#endif + +#ifdef HAVE_LIBYAJL #include #include =20 #ifdef HAVE_YAJL_YAJL_VERSION_H # include #endif +#endif =20 yajl_gen_status libxl__uint64_gen_json(yajl_gen hand, uint64_t val); yajl_gen_status libxl_defbool_gen_json(yajl_gen hand, libxl_defbool *p); diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index 062123eed4..5204cb8889 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -2234,9 +2234,16 @@ _hidden const libxl__json_object *libxl__json_map_ge= t(const char *key, */ _hidden libxl__json_object *libxl__json_object_alloc(libxl__gc *gc_opt, libxl__json_node_type= type); +#ifdef HAVE_LIBJSONC +_hidden int libxl__json_object_to_json_object(libxl__gc *gc, + json_object **jso_out, + const libxl__json_object *ob= j); +#endif +#ifdef HAVE_LIBYAJL _hidden yajl_status libxl__json_object_to_yajl_gen(libxl__gc *gc_opt, yajl_gen hand, const libxl__json_objec= t *param); +#endif _hidden void libxl__json_object_free(libxl__gc *gc_opt, libxl__json_object *obj); =20 diff --git a/tools/libs/light/libxl_json.c b/tools/libs/light/libxl_json.c index 44ee6e213f..75b383ee14 100644 --- a/tools/libs/light/libxl_json.c +++ b/tools/libs/light/libxl_json.c @@ -631,6 +631,105 @@ const libxl__json_object *libxl__json_map_get(const c= har *key, return NULL; } =20 +#ifdef HAVE_LIBJSONC +int libxl__json_object_to_json_object(libxl__gc *gc, + json_object **jso_out, + const libxl__json_object *obj) +{ + int idx =3D 0; + int rc, r; + + switch (obj->type) { + case JSON_NULL: + *jso_out =3D json_object_new_null(); + return 0; + case JSON_BOOL: + *jso_out =3D json_object_new_boolean(obj->u.b); + if (!*jso_out) + return ERROR_NOMEM; + return 0; + case JSON_INTEGER: + *jso_out =3D json_object_new_int64(obj->u.i); + if (!*jso_out) + return ERROR_NOMEM; + return 0; + case JSON_DOUBLE: + *jso_out =3D json_object_new_double(obj->u.d); + if (!*jso_out) + return ERROR_NOMEM; + return 0; + case JSON_NUMBER: + /* + * Use json_object_new_double_s() to rewrite the number exactly as + * we parsed it. When generating the JSON string the value `0` will + * be ignored and `obj->u.string` will be written instead. + */ + *jso_out =3D json_object_new_double_s(0, obj->u.string); + if (!*jso_out) + return ERROR_NOMEM; + return 0; + case JSON_STRING: + *jso_out =3D json_object_new_string(obj->u.string); + if (!*jso_out) + return ERROR_NOMEM; + return 0; + case JSON_MAP: { + libxl__json_map_node *node =3D NULL; + json_object *map_root =3D json_object_new_object(); + json_object *node_value; + + for (idx =3D 0; idx < obj->u.map->count; idx++) { + if (flexarray_get(obj->u.map, idx, (void**)&node) !=3D 0) + break; + + rc =3D libxl__json_object_to_json_object(gc, &node_value, node= ->obj); + if (rc) { + json_object_put(map_root); + return rc; + } + + r =3D json_object_object_add(map_root, node->map_key, node_val= ue); + if (r < 0) { + json_object_put(node_value); + json_object_put(map_root); + return ERROR_FAIL; + } + } + *jso_out =3D map_root; + return 0; + } + case JSON_ARRAY: { + libxl__json_object *node =3D NULL; + json_object *array_root =3D json_object_new_array_ext(obj->u.array= ->count); + json_object *node_value; + + for (idx =3D 0; idx < obj->u.array->count; idx++) { + if (flexarray_get(obj->u.array, idx, (void**)&node) !=3D 0) + break; + + rc =3D libxl__json_object_to_json_object(gc, &node_value, node= ); + if (rc) { + json_object_put(array_root); + return rc; + } + r =3D json_object_array_add(array_root, node_value); + if (r < 0) { + json_object_put(node_value); + json_object_put(array_root); + return ERROR_FAIL; + } + } + *jso_out =3D array_root; + return 0; + } + case JSON_ANY: + default: + /* JSON_ANY is not a valid value for obj->type. */ + return ERROR_FAIL; + } +} +#endif +#ifdef HAVE_LIBYAJL yajl_status libxl__json_object_to_yajl_gen(libxl__gc *gc, yajl_gen hand, const libxl__json_object *obj) @@ -698,6 +797,7 @@ yajl_status libxl__json_object_to_yajl_gen(libxl__gc *g= c, abort(); #undef CONVERT_YAJL_GEN_TO_STATUS } +#endif =20 =20 /* diff --git a/tools/libs/light/libxl_qmp.c b/tools/libs/light/libxl_qmp.c index 84740bd4b3..94b6fdb559 100644 --- a/tools/libs/light/libxl_qmp.c +++ b/tools/libs/light/libxl_qmp.c @@ -61,7 +61,11 @@ =20 #include =20 +#ifdef HAVE_LIBJSONC +#include +#elif defined(HAVE_LIBYAJL) #include +#endif =20 #include "xen_list.h" #include "libxl_internal.h" @@ -481,13 +485,56 @@ static char *qmp_prepare_cmd(libxl__gc *gc, const cha= r *cmd, const libxl__json_object *args, int id) { +#ifdef HAVE_LIBJSONC + json_object *jso =3D NULL; + json_object *jso_value =3D NULL; + /* memory for 'buf' is owned by 'jso' */ + const char *buf; + int rc, r; +#elif defined(HAVE_LIBYAJL) yajl_gen hand =3D NULL; /* memory for 'buf' is owned by 'hand' */ const unsigned char *buf; libxl_yajl_length len; yajl_gen_status s; +#else +# error Missing JSON library +#endif char *ret =3D NULL; =20 +#ifdef HAVE_LIBJSONC + jso =3D json_object_new_object(); + if (!jso) + goto out; + + jso_value =3D json_object_new_string(cmd); + if (!jso_value) + goto out; + r =3D json_object_object_add(jso, "execute", jso_value); + if (r < 0) + goto out; + jso_value =3D json_object_new_int(id); + if (!jso_value) + goto out; + r =3D json_object_object_add(jso, "id", jso_value); + if (r < 0) + goto out; + /* `jso_value` now part of `jso`, shouldn't free it anymore */ + jso_value =3D NULL; + if (args) { + rc =3D libxl__json_object_to_json_object(gc, &jso_value, args); + if (rc) + goto out; + r =3D json_object_object_add(jso, "arguments", jso_value); + if (r < 0) + goto out; + jso_value =3D NULL; + } + + buf =3D json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN); + ret =3D libxl__sprintf(gc, "%s\r\n", buf); + +#elif defined(HAVE_LIBYAJL) hand =3D libxl_yajl_gen_alloc(NULL); =20 if (!hand) { @@ -516,9 +563,15 @@ static char *qmp_prepare_cmd(libxl__gc *gc, const char= *cmd, goto out; =20 ret =3D libxl__sprintf(gc, "%*.*s\r\n", (int)len, (int)len, buf); +#endif =20 out: +#ifdef HAVE_LIBJSONC + json_object_put(jso_value); + json_object_put(jso); +#elif defined(HAVE_LIBYAJL) yajl_gen_free(hand); +#endif return ret; } =20 --=20 Anthony PERARD From nobody Sat Oct 4 22:00:05 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=1759147704; cv=none; d=zohomail.com; s=zohoarc; b=hapXK3QL3Ql52RVk6+aea+YNcyihclwe6c1ENz5cVrHqb+ZFPcQn7u2FbXGbgO4tNOHHuE8j0mZTwVy3CB27dLU4pzyOCtLd9kJ6L9CFElwryux/TYH9UQNi/WFNOY5Pr/0Z0GEvo68zeuii3Z37jzgSbItSkOU+6vbgA3BGEDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759147704; 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=QdP8PHqJmogVusHtiO1gc6B5Y6eGFL1T9BNVCi6iVhg=; b=fnDKQu4CWRIhBy0LKfnJuf878MnloQQzmMjl2uzPN2bUYkpyPwjEUcigAxzAkZEbD102PluF1rI1bxbZL30+L6nJOkql4xkIPcfDjWWiRZeATbCOeBz/brKaMK8m+EJ+z062D5vMHUQmvySbmzPKrAPeZbrP9zjurLbtY4Hxa18= 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 1759147704137972.8252212088032; Mon, 29 Sep 2025 05:08:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1132742.1471018 (Exim 4.92) (envelope-from ) id 1v3Cfk-0008JI-Qp; Mon, 29 Sep 2025 12:08:04 +0000 Received: by outflank-mailman (output) from mailman id 1132742.1471018; Mon, 29 Sep 2025 12:08:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3Cfk-0008J5-M4; Mon, 29 Sep 2025 12:08:04 +0000 Received: by outflank-mailman (input) for mailman id 1132742; Mon, 29 Sep 2025 12:08:03 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3Cfi-0007uC-UR for xen-devel@lists.xenproject.org; Mon, 29 Sep 2025 12:08:02 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1v3Cfi-00GXBV-2V; Mon, 29 Sep 2025 12:08:02 +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 1v3Cfi-004JHo-2F; Mon, 29 Sep 2025 12:08:02 +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=QdP8PHqJmogVusHtiO1gc6B5Y6eGFL1T9BNVCi6iVhg=; b=VnZ5rgxsoXfTniZ3rahVpMU6YW NA1zXU2iTUkveG8fhMV6Yr3+zxy4sIhQ3iZBPAv16FXLr+prJxVjxRmEh4XJqNyBtgCVSJj+tKulX jAn6PbzGPgVl3mJ2mGcvBlvCv7xKmKSBpVv44b5Cz7JaNmYZF/7pJ4FG4Nyx8yHLCOuM=; From: Anthony PERARD To: xen-devel@lists.xenproject.org Cc: Anthony PERARD , Jason Andryuk , Juergen Gross Subject: [XEN PATCH v2 4/8] libxl: libxl__object_to_json() to json-c Date: Mon, 29 Sep 2025 14:07:52 +0200 Message-ID: <20250929120756.46075-5-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: quoted-printable X-ZohoMail-DKIM: pass (identity @xenproject.org) X-ZM-MESSAGEID: 1759147706343116600 Content-Type: text/plain; charset="utf-8" From: Anthony PERARD - libxl changes: While doing so, we rename all "*_gen_json" function to "*_gen_jso" as they have different prototype. All the function pointer are been cast to (libxl__gen_json_callback) by "gentypes.py" when generating "*_to_json()" functions. We also introduce a few more "*_gen_jso" functions for "int" and "bool" because we can't use json_object_*() functions from json-c directly like it's done with yajl. To make the generation of _libxl_types*json.[ch] with both YAJL and json-c we add "--libjsonc" to gentypes.py so it can generate functions/types for both. Also introducing "jsonc_json_gen_fn" in the IDL, to be able to point to a different function when using json-c. Also, don't export any of the new *_gen_jso() function, at the cost of having "_hidden" macro in semi-public headers. - xl changes: Also, rework the implementation of printf_info() in `xl` to avoid using libxl_domain_config_gen_json() which isn't available without YAJL. The implementation using "json_object" call libxl_domain_config_to_json() which generate a plain string of JSON, which we parse to add it to our own json; this avoid a dependency on the json library used by libxl. Signed-off-by: Anthony PERARD Reviewed-by: Jason Andryuk --- Notes: v2: - Replace construct $(if $(LIBJSONC_LIBS),--libjsonc) by $(if $(filter -ljson-c,$(XEN_JSON_LIBS)) tools/include/libxl_json.h | 17 ++ tools/libs/light/Makefile | 2 +- tools/libs/light/gentypes.py | 160 ++++++++++- tools/libs/light/idl.py | 7 +- tools/libs/light/libxl_cpuid.c | 119 ++++++++ tools/libs/light/libxl_internal.h | 16 +- tools/libs/light/libxl_json.c | 316 ++++++++++++++++++++++ tools/libs/light/libxl_types.idl | 7 +- tools/libs/light/libxl_types_internal.idl | 3 +- tools/xl/xl_info.c | 102 ++++++- 10 files changed, 729 insertions(+), 20 deletions(-) diff --git a/tools/include/libxl_json.h b/tools/include/libxl_json.h index e2ef8151f0..c130e88a5e 100644 --- a/tools/include/libxl_json.h +++ b/tools/include/libxl_json.h @@ -28,6 +28,22 @@ #endif #endif =20 +#ifdef HAVE_LIBJSONC +#ifndef _hidden +#define _hidden +#endif +_hidden int libxl__uint64_gen_jso(json_object **jso_r, uint64_t val); +_hidden int libxl_defbool_gen_jso(json_object **jso_r, libxl_defbool *p); +_hidden int libxl_uuid_gen_jso(json_object **jso_r, libxl_uuid *p); +_hidden int libxl_mac_gen_jso(json_object **jso_r, libxl_mac *p); +_hidden int libxl_bitmap_gen_jso(json_object **jso_r, libxl_bitmap *p); +_hidden int libxl_cpuid_policy_list_gen_jso(json_object **jso_r,libxl_cpui= d_policy_list *p); +_hidden int libxl_string_list_gen_jso(json_object **jso_r,libxl_string_lis= t *p); +_hidden int libxl_key_value_list_gen_jso(json_object **jso_r, libxl_key_va= lue_list *p); +_hidden int libxl_hwcap_gen_jso(json_object **jso_r, libxl_hwcap *p); +_hidden int libxl_ms_vm_genid_gen_jso(json_object **jso_r, libxl_ms_vm_gen= id *p); +#endif +#if defined(HAVE_LIBYAJL) yajl_gen_status libxl__uint64_gen_json(yajl_gen hand, uint64_t val); yajl_gen_status libxl_defbool_gen_json(yajl_gen hand, libxl_defbool *p); yajl_gen_status libxl_uuid_gen_json(yajl_gen hand, libxl_uuid *p); @@ -40,6 +56,7 @@ yajl_gen_status libxl_key_value_list_gen_json(yajl_gen ha= nd, libxl_key_value_list *p); yajl_gen_status libxl_hwcap_gen_json(yajl_gen hand, libxl_hwcap *p); yajl_gen_status libxl_ms_vm_genid_gen_json(yajl_gen hand, libxl_ms_vm_geni= d *p); +#endif =20 #include <_libxl_types_json.h> =20 diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile index c05d89db33..bc60c46558 100644 --- a/tools/libs/light/Makefile +++ b/tools/libs/light/Makefile @@ -226,7 +226,7 @@ testidl.o: $(XEN_INCLUDE)/libxl.h # This exploits the 'multi-target pattern rule' trick. # gentypes.py should be executed only once to make all the targets. _libxl_type%.h _libxl_type%_json.h _libxl_type%_private.h _libxl_type%.c: = libxl_type%.idl gentypes.py idl.py - $(PYTHON) gentypes.py libxl_type$(*F).idl __libxl_type$(*F).h __libxl_typ= e$(*F)_private.h \ + $(PYTHON) gentypes.py $(if $(filter -ljson-c,$(XEN_JSON_LIBS)),--libjsonc= ) libxl_type$(*F).idl __libxl_type$(*F).h __libxl_type$(*F)_private.h \ __libxl_type$(*F)_json.h __libxl_type$(*F).c $(call move-if-changed,__libxl_type$(*F).h,_libxl_type$(*F).h) $(call move-if-changed,__libxl_type$(*F)_private.h,_libxl_type$(*F)_priva= te.h) diff --git a/tools/libs/light/gentypes.py b/tools/libs/light/gentypes.py index 3fe3873242..006bea170a 100644 --- a/tools/libs/light/gentypes.py +++ b/tools/libs/light/gentypes.py @@ -256,6 +256,30 @@ def libxl_C_type_member_init(ty, field): s +=3D "\n" return s =20 +# For json-c gen_jso functions +def libxl_C_type_gen_jso_map_key(f, parent, indent, scope_object, sub_scop= e_object): + s =3D "" + if isinstance(f.type, idl.KeyedUnion): + s +=3D "switch (%s) {\n" % (parent + f.type.keyvar.name) + for x in f.type.fields: + v =3D f.type.keyvar.name + "." + x.name + s +=3D "case %s:\n" % x.enumname + s +=3D " if (json_object_object_add(%s, \"%s\", %s)) {\n" %= (scope_object, v, sub_scope_object) + s +=3D " json_object_put(%s);\n" % (sub_scope_object) + s +=3D " goto out;\n" + s +=3D " }\n" + s +=3D " break;\n" + s +=3D "}\n" + else: + s +=3D "if (json_object_object_add(%s, \"%s\", %s)) {\n" % (scope_= object, f.name, sub_scope_object) + s +=3D " json_object_put(%s);\n" % (sub_scope_object) + s +=3D " goto out;\n" + s +=3D "}\n" + if s !=3D "": + s =3D indent + s + return s.replace("\n", "\n%s" % indent).rstrip(indent) + +# For YAJL gen_json functions def libxl_C_type_gen_map_key(f, parent, indent =3D ""): s =3D "" if isinstance(f.type, idl.KeyedUnion): @@ -352,6 +376,86 @@ def get_default_expr(f, nparent, fexpr): =20 return "%s" % fexpr =20 +# For json-c gen_json functions +def libxl_C_type_gen_jso(ty, v, indent =3D " ", parent =3D None, scope_= object =3D "jso"): + s =3D "" + if parent is None: + s +=3D "json_object *jso;\n" + s +=3D "int rc;\n" + sub_scope_object =3D "jso_sub_1" + else: + sub_scope_object =3D "jso_sub_%d" % (1+int(scope_object.removepref= ix("jso_sub_"))) + + if isinstance(ty, idl.Array): + if parent is None: + raise Exception("Array type must have a parent") + s +=3D "{\n" + s +=3D " int i;\n" + s +=3D " %s =3D json_object_new_array_ext(%s);\n" % (scope_obje= ct, parent + ty.lenvar.name) + s +=3D " if (!%s)\n" % (scope_object) + s +=3D " goto out;\n" + s +=3D " for (i=3D0; i<%s; i++) {\n" % (parent + ty.lenvar.name) + s +=3D " json_object *%s;\n" % (sub_scope_object) + # remove some indent, it's over indented at least in one case libx= l_vcpu_sched_params_gen_json + s +=3D libxl_C_type_gen_jso(ty.elem_type, v+"[i]", + indent + " ", parent, sub_scope_obje= ct) + s +=3D " if (json_object_array_add(%s, %s)) {\n" % (scope_o= bject, sub_scope_object) + s +=3D " json_object_put(%s);\n" % (sub_scope_object) + s +=3D " goto out;\n" + s +=3D " }\n" + s +=3D " }\n" + s +=3D "}\n" + elif isinstance(ty, idl.Enumeration): + s +=3D "rc =3D libxl__enum_gen_jso(&%s, %s_to_string(%s));\n" % (s= cope_object, ty.typename, ty.pass_arg(v, parent is None)) + s +=3D "if (rc)\n" + s +=3D " goto out;\n" + elif isinstance(ty, idl.KeyedUnion): + if parent is None: + raise Exception("KeyedUnion type must have a parent") + s +=3D "switch (%s) {\n" % (parent + ty.keyvar.name) + for f in ty.fields: + (nparent,fexpr) =3D ty.member(v, f, parent is None) + s +=3D "case %s:\n" % f.enumname + if f.type is not None: + s +=3D libxl_C_type_gen_jso(f.type, fexpr, indent + " "= , nparent, scope_object) + else: + s +=3D " %s =3D json_object_new_object();\n" % (scope_o= bject) + s +=3D " if (!%s)\n" % (scope_object) + s +=3D " goto out;\n" + s +=3D " break;\n" + s +=3D "}\n" + elif isinstance(ty, idl.Struct) and (parent is None or ty.json_gen_fn = is None): + s +=3D "%s =3D json_object_new_object();\n" % (scope_object) + s +=3D "if (!%s)\n" % (scope_object) + s +=3D " goto out;\n" + for f in [f for f in ty.fields if not f.const and not f.type.priva= te]: + (nparent,fexpr) =3D ty.member(v, f, parent is None) + default_expr =3D get_default_expr(f, nparent, fexpr) + s +=3D "if (%s) {\n" % default_expr + s +=3D " json_object *%s =3D NULL;\n" % (sub_scope_object) + s +=3D libxl_C_type_gen_jso(f.type, fexpr, " ", nparent, su= b_scope_object) + s +=3D libxl_C_type_gen_jso_map_key(f, nparent, " ", scope_= object, sub_scope_object) + + s +=3D "}\n" + + else: + if ty.json_gen_fn is not None: + s +=3D "rc =3D %s(&%s, %s);\n" % (ty.json_gen_fn, scope_object= , ty.pass_arg(v, parent is None)) + s +=3D "if (rc)\n" + s +=3D " goto out;\n" + + if parent is None: + s +=3D "*jso_r =3D jso;\n" + s +=3D "return 0;\n" + s +=3D "out:\n" + s +=3D "json_object_put(jso);\n" + s +=3D "return ERROR_FAIL;\n" + + if s !=3D "": + s =3D indent + s + return s.replace("\n", "\n%s" % indent).rstrip(indent) + +# For YAJL gen_json functions def libxl_C_type_gen_json(ty, v, indent =3D " ", parent =3D None): s =3D "" if parent is None: @@ -426,9 +530,9 @@ def libxl_C_type_gen_json(ty, v, indent =3D " ", par= ent =3D None): s =3D indent + s return s.replace("\n", "\n%s" % indent).rstrip(indent) =20 -def libxl_C_type_to_json(ty, v, indent =3D " "): +def libxl_C_type_to_json(ty, v, indent =3D " ", fn_ptr_type=3D"libxl__g= en_json_callback", fn_suffix=3D"_gen_json"): s =3D "" - gen =3D "(libxl__gen_json_callback)&%s_gen_json" % ty.typename + gen =3D "(%s)&%s%s" % (fn_ptr_type, ty.typename, fn_suffix) s +=3D "return libxl__object_to_json(ctx, \"%s\", %s, (void *)%s);\n" = % (ty.typename, gen, ty.pass_arg(v, passby=3Didl.PASS_BY_REFERENCE)) =20 if s !=3D "": @@ -589,14 +693,38 @@ def clean_header_define(header_path): =20 =20 if __name__ =3D=3D '__main__': + opt_libjsonc =3D False + if len(sys.argv) =3D=3D 7: + if sys.argv.pop(1) =3D=3D "--libjsonc": + opt_libjsonc =3D True if len(sys.argv) !=3D 6: print("Usage: gentypes.py
", file=3Dsys.stderr) sys.exit(1) =20 (_, idlname, header, header_private, header_json, impl) =3D sys.argv =20 + # Overwrite `json_gen_fn` for standard types + if opt_libjsonc: + idl.bool.json_gen_fn =3D "libxl__boolean_gen_jso" + idl.size_t.json_gen_fn =3D "libxl__int_gen_jso" + idl.integer .json_gen_fn =3D "libxl__int_gen_jso" + idl.uint8.json_gen_fn =3D "libxl__int_gen_jso" + idl.uint16.json_gen_fn =3D "libxl__int_gen_jso" + idl.uint32.json_gen_fn =3D "libxl__int_gen_jso" + idl.uint64.json_gen_fn =3D "libxl__uint64_gen_jso" + idl.string.json_gen_fn =3D "libxl__string_gen_jso" + (builtins,types) =3D idl.parse(idlname) =20 + # Overwrite `json_gen_fn` with `jsonc_json_gen_fn` for types from the = IDL + if opt_libjsonc: + for t in builtins: + if t.jsonc_json_gen_fn is not None: + t.json_gen_fn =3D t.jsonc_json_gen_fn + for t in types: + if t.jsonc_json_gen_fn is not None: + t.json_gen_fn =3D t.jsonc_json_gen_fn + print("outputting libxl type definitions to %s" % header) =20 f =3D open(header, "w") @@ -665,7 +793,11 @@ if __name__ =3D=3D '__main__': """ % (header_json_define, header_json_define, " ".join(sys.argv))) =20 for ty in [ty for ty in types if ty.json_gen_fn is not None]: - f.write("%syajl_gen_status %s_gen_json(yajl_gen hand, %s);\n" % (t= y.hidden(), ty.typename, ty.make_arg("p", passby=3Didl.PASS_BY_REFERENCE))) + if opt_libjsonc: + # Always hide JSON generators base on json-c + f.write("%sint %s_gen_jso(json_object **jso_r, %s);\n" % ("_hi= dden ", ty.typename, ty.make_arg("p", passby=3Didl.PASS_BY_REFERENCE))) + else: + f.write("%syajl_gen_status %s_gen_json(yajl_gen hand, %s);\n" = % (ty.hidden(), ty.typename, ty.make_arg("p", passby=3Didl.PASS_BY_REFERENC= E))) =20 f.write("\n") f.write("""#endif /* %s */\n""" % header_json_define) @@ -769,15 +901,25 @@ if __name__ =3D=3D '__main__': f.write("\n") =20 for ty in [t for t in types if t.json_gen_fn is not None]: - f.write("yajl_gen_status %s_gen_json(yajl_gen hand, %s)\n" % (ty.t= ypename, ty.make_arg("p", passby=3Didl.PASS_BY_REFERENCE))) - f.write("{\n") - f.write(libxl_C_type_gen_json(ty, "p")) - f.write("}\n") - f.write("\n") + if opt_libjsonc: + f.write("int %s_gen_jso(json_object **jso_r, %s)\n" % (ty.type= name, ty.make_arg("p", passby=3Didl.PASS_BY_REFERENCE))) + f.write("{\n") + f.write(libxl_C_type_gen_jso(ty, "p")) + f.write("}\n") + f.write("\n") + else: + f.write("yajl_gen_status %s_gen_json(yajl_gen hand, %s)\n" % (= ty.typename, ty.make_arg("p", passby=3Didl.PASS_BY_REFERENCE))) + f.write("{\n") + f.write(libxl_C_type_gen_json(ty, "p")) + f.write("}\n") + f.write("\n") =20 f.write("char *%s_to_json(libxl_ctx *ctx, %s)\n" % (ty.typename, t= y.make_arg("p"))) f.write("{\n") - f.write(libxl_C_type_to_json(ty, "p")) + if opt_libjsonc: + f.write(libxl_C_type_to_json(ty, "p", fn_ptr_type=3D"libxl__ge= n_json_callback", fn_suffix=3D"_gen_jso")) + else: + f.write(libxl_C_type_to_json(ty, "p", fn_ptr_type=3D"libxl__ge= n_json_callback", fn_suffix=3D"_gen_json")) f.write("}\n") f.write("\n") =20 diff --git a/tools/libs/light/idl.py b/tools/libs/light/idl.py index d7367503b4..61c8e14004 100644 --- a/tools/libs/light/idl.py +++ b/tools/libs/light/idl.py @@ -79,6 +79,7 @@ class Type(object): =20 if self.typename is not None and not self.private: self.json_gen_fn =3D kwargs.setdefault('json_gen_fn', self.typ= ename + "_gen_json") + self.jsonc_json_gen_fn =3D kwargs.setdefault('jsonc_json_gen_f= n', self.typename + "_gen_jso") self.json_parse_type =3D kwargs.setdefault('json_parse_type', = "JSON_ANY") if self.namespace is not None: self.json_parse_fn =3D kwargs.setdefault('json_parse_fn', @@ -88,6 +89,7 @@ class Type(object): self.typename + "_p= arse_json") else: self.json_gen_fn =3D kwargs.setdefault('json_gen_fn', None) + self.jsonc_json_gen_fn =3D kwargs.setdefault('jsonc_json_gen_f= n', None) self.json_parse_type =3D kwargs.setdefault('json_parse_type', = None) self.json_parse_fn =3D kwargs.setdefault('json_parse_fn', None) =20 @@ -142,6 +144,7 @@ class Number(Builtin): kwargs.setdefault('copy_fn', None) kwargs.setdefault('signed', False) kwargs.setdefault('json_gen_fn', "yajl_gen_integer") + kwargs.setdefault('jsonc_json_gen_fn', "libxl__int_gen_jso") kwargs.setdefault('json_parse_type', "JSON_INTEGER") # json_parse_fn might be overriden on specific type kwargs.setdefault('json_parse_fn', "libxl__int_parse_json") @@ -290,6 +293,7 @@ void =3D Builtin("void *", namespace =3D None) bool =3D Builtin("bool", namespace =3D None, copy_fn=3DNone, json_gen_fn =3D "yajl_gen_bool", + jsonc_json_gen_fn =3D "libxl__boolean_gen_jso", json_parse_type =3D "JSON_BOOL", json_parse_fn =3D "libxl__bool_parse_json", autogenerate_json =3D False) @@ -301,10 +305,11 @@ integer =3D Number("int", namespace =3D None, signed = =3D True) uint8 =3D UInt(8) uint16 =3D UInt(16) uint32 =3D UInt(32) -uint64 =3D UInt(64, json_gen_fn =3D "libxl__uint64_gen_json") +uint64 =3D UInt(64, json_gen_fn =3D "libxl__uint64_gen_json", jsonc_json_g= en_fn =3D "libxl__uint64_gen_jso") =20 string =3D Builtin("char *", namespace =3D None, copy_fn =3D "libxl_string= _copy", dispose_fn =3D "free", json_gen_fn =3D "libxl__string_gen_json", + jsonc_json_gen_fn =3D "libxl__string_gen_jso", json_parse_type =3D "JSON_STRING | JSON_NULL", json_parse_fn =3D "libxl__string_parse_json", autogenerate_json =3D False, diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index f738e17b19..8420b2465f 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -545,6 +545,124 @@ static const char *policy_names[4] =3D { "eax", "ebx"= , "ecx", "edx" }; * } */ =20 +#ifdef HAVE_LIBJSONC +int libxl_cpuid_policy_list_gen_jso(json_object **jso_r, libxl_cpuid_polic= y_list *pl) +{ + libxl_cpuid_policy_list policy =3D *pl; + struct xc_xend_cpuid *cpuid; + const struct xc_msr *msr; + json_object *jso_outer; + json_object *jso_array; + int i, j; + int r; + int rc =3D ERROR_FAIL; + + jso_outer =3D json_object_new_object(); + if (!jso_outer) goto out; + + jso_array =3D json_object_new_array(); + if (!jso_array) goto out; + + r =3D json_object_object_add(jso_outer, "cpuid", jso_array); + if (r < 0) { + json_object_put(jso_array); + goto out; + } + + if (policy =3D=3D NULL || policy->cpuid =3D=3D NULL) goto empty; + cpuid =3D policy->cpuid; + + for (i =3D 0; cpuid[i].input[0] !=3D XEN_CPUID_INPUT_UNUSED; i++) { + json_object *jso_inner; + jso_inner =3D json_object_new_object(); + if (!jso_inner) goto out; + + r =3D json_object_array_add(jso_array, jso_inner); + if (r < 0) { + json_object_put(jso_inner); + goto out; + } + + for (j =3D 0; j < 2; j++) { + if (cpuid[i].input[j] !=3D XEN_CPUID_INPUT_UNUSED) { + json_object *jso_value =3D json_object_new_int(cpuid[i].in= put[j]); + if (!jso_value) goto out; + r =3D json_object_object_add(jso_inner, input_names[j], js= o_value); + if (r < 0) { + json_object_put(jso_value); + goto out; + } + } + } + + for (j =3D 0; j < 4; j++) { + if (cpuid[i].policy[j] !=3D NULL) { + json_object *jso_value =3D json_object_new_string_len(cpui= d[i].policy[j], 32); + if (!jso_value) goto out; + r =3D json_object_object_add(jso_inner, policy_names[j], j= so_value); + if (r < 0) { + json_object_put(jso_value); + goto out; + } + } + } + } + +empty: + + jso_array =3D json_object_new_array(); + if (!jso_array) goto out; + + r =3D json_object_object_add(jso_outer, "msr", jso_array); + if (r < 0) { + json_object_put(jso_array); + goto out; + } + + if (!policy || !policy->msr) goto done; + msr =3D policy->msr; + + for (i =3D 0; msr[i].index !=3D XC_MSR_INPUT_UNUSED; i++) { + json_object *jso_inner; + json_object *jso_value; + + jso_inner =3D json_object_new_object(); + if (!jso_inner) goto out; + + r =3D json_object_array_add(jso_array, jso_inner); + if (r < 0) { + json_object_put(jso_inner); + goto out; + } + + jso_value =3D json_object_new_int(msr[i].index); + if (!jso_value) goto out; + r =3D json_object_object_add(jso_inner, "index", jso_value); + if (r < 0) { + json_object_put(jso_value); + goto out; + } + + jso_value =3D json_object_new_string_len(msr[i].policy, 64); + if (!jso_value) goto out; + r =3D json_object_object_add(jso_inner, "policy", jso_value); + if (r < 0) { + json_object_put(jso_value); + goto out; + } + } + +done: + *jso_r =3D jso_outer; + jso_outer =3D NULL; + rc =3D 0; +out: + json_object_put(jso_outer); + return rc; +} +#endif + +#ifdef HAVE_LIBYAJL yajl_gen_status libxl_cpuid_policy_list_gen_json(yajl_gen hand, libxl_cpuid_policy_list *pl) { @@ -630,6 +748,7 @@ yajl_gen_status libxl_cpuid_policy_list_gen_json(yajl_g= en hand, out: return s; } +#endif =20 int libxl__cpuid_policy_list_parse_json(libxl__gc *gc, const libxl__json_object *o, diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index 5204cb8889..b65e0064b9 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -1993,9 +1993,11 @@ _hidden char *libxl__cpupoolid_to_name(libxl__gc *gc= , uint32_t poolid); _hidden int libxl__enum_from_string(const libxl_enum_string_table *t, const char *s, int *e) NN(2); =20 -_hidden yajl_gen_status libxl__string_gen_json(yajl_gen hand, const char *= p); - +#ifdef HAVE_LIBJSONC +typedef int (*libxl__gen_json_callback)(json_object **jso_r, void *); +#elif defined(HAVE_LIBYAJL) typedef yajl_gen_status (*libxl__gen_json_callback)(yajl_gen hand, void *); +#endif _hidden char *libxl__object_to_json(libxl_ctx *ctx, const char *type, libxl__gen_json_callback gen, void *p); =20 @@ -2084,11 +2086,21 @@ int libxl__recvmsg_fds(libxl__gc *gc, int carrier, void *databuf, size_t datalen, int nfds, int fds[], const char *what); =20 +#ifdef HAVE_LIBJSONC +_hidden int libxl__enum_gen_jso(json_object **jso_r, const char *str); +_hidden int libxl__int_gen_jso(json_object **jso_r, int i); +_hidden int libxl__boolean_gen_jso(json_object **jso_r, bool b); +_hidden int libxl__string_gen_jso(json_object **jso_r, const char *p); +#endif + +#ifdef HAVE_LIBYAJL /* from libxl_json */ #include =20 _hidden yajl_gen_status libxl__yajl_gen_asciiz(yajl_gen hand, const char *= str); _hidden yajl_gen_status libxl__yajl_gen_enum(yajl_gen hand, const char *st= r); +_hidden yajl_gen_status libxl__string_gen_json(yajl_gen hand, const char *= p); +#endif =20 typedef enum { JSON_NULL =3D (1 << 0), diff --git a/tools/libs/light/libxl_json.c b/tools/libs/light/libxl_json.c index 75b383ee14..eeda9c301d 100644 --- a/tools/libs/light/libxl_json.c +++ b/tools/libs/light/libxl_json.c @@ -19,12 +19,16 @@ #ifdef HAVE_LIBJSONC #include #define USE_LIBJSONC_PARSER +#define USE_LIBJSONC_GEN #endif =20 #ifdef HAVE_LIBYAJL # ifndef USE_LIBJSONC_PARSER # define USE_LIBYAJL_PARSER # endif +# ifndef USE_LIBJSONC_GEN +# define USE_LIBYAJL_GEN +# endif #endif =20 =20 @@ -35,7 +39,9 @@ #ifdef USE_LIBYAJL_PARSER #include #endif +#ifdef USE_LIBYAJL_GEN #include +#endif =20 #include "libxl_internal.h" =20 @@ -103,6 +109,21 @@ yajl_gen_status libxl__yajl_gen_asciiz(yajl_gen hand, = const char *str) return yajl_gen_string(hand, (const unsigned char *)str, strlen(str)); } =20 +#ifdef HAVE_LIBJSONC +int libxl__enum_gen_jso(json_object **jso_r, const char *str) +{ + if (str) { + *jso_r =3D json_object_new_string(str); + if (!*jso_r) + return ERROR_FAIL; + } else { + *jso_r =3D json_object_new_null(); + } + return 0; +} +#endif + +#ifdef HAVE_LIBYAJL yajl_gen_status libxl__yajl_gen_enum(yajl_gen hand, const char *str) { if (str) @@ -110,15 +131,28 @@ yajl_gen_status libxl__yajl_gen_enum(yajl_gen hand, c= onst char *str) else return yajl_gen_null(hand); } +#endif =20 /* * YAJL generators for builtin libxl types. */ +#ifdef HAVE_LIBJSONC +int libxl_defbool_gen_jso(json_object **jso_r, libxl_defbool *db) +{ + *jso_r =3D json_object_new_string(libxl_defbool_to_string(*db)); + if (!*jso_r) + return ERROR_FAIL; + return 0; +} +#endif + +#ifdef HAVE_LIBYAJL yajl_gen_status libxl_defbool_gen_json(yajl_gen hand, libxl_defbool *db) { return libxl__yajl_gen_asciiz(hand, libxl_defbool_to_string(*db)); } +#endif =20 int libxl__defbool_parse_json(libxl__gc *gc, const libxl__json_object *o, libxl_defbool *p) @@ -145,6 +179,16 @@ int libxl__defbool_parse_json(libxl__gc *gc, const lib= xl__json_object *o, return 0; } =20 +#ifdef HAVE_LIBJSONC +int libxl__boolean_gen_jso(json_object **jso_r, bool b) +{ + *jso_r =3D json_object_new_boolean(b); + if (!*jso_r) + return ERROR_FAIL; + return 0; +} +#endif + int libxl__bool_parse_json(libxl__gc *gc, const libxl__json_object *o, bool *p) { @@ -156,6 +200,19 @@ int libxl__bool_parse_json(libxl__gc *gc, const libxl_= _json_object *o, return 0; } =20 +#ifdef HAVE_LIBJSONC +int libxl_uuid_gen_jso(json_object **jso_r, libxl_uuid *uuid) +{ + char buf[LIBXL_UUID_FMTLEN+1]; + snprintf(buf, sizeof(buf), LIBXL_UUID_FMT, LIBXL_UUID_BYTES((*uuid))); + *jso_r =3D json_object_new_string_len(buf, LIBXL_UUID_FMTLEN); + if (!*jso_r) + return ERROR_FAIL; + return 0; +} +#endif + +#ifdef HAVE_LIBYAJL yajl_gen_status libxl_uuid_gen_json(yajl_gen hand, libxl_uuid *uuid) { @@ -163,6 +220,7 @@ yajl_gen_status libxl_uuid_gen_json(yajl_gen hand, snprintf(buf, sizeof(buf), LIBXL_UUID_FMT, LIBXL_UUID_BYTES((*uuid))); return yajl_gen_string(hand, (const unsigned char *)buf, LIBXL_UUID_FM= TLEN); } +#endif =20 int libxl__uuid_parse_json(libxl__gc *gc, const libxl__json_object *o, libxl_uuid *p) @@ -173,6 +231,39 @@ int libxl__uuid_parse_json(libxl__gc *gc, const libxl_= _json_object *o, return libxl_uuid_from_string(p, o->u.string); } =20 +#ifdef HAVE_LIBJSONC +int libxl_bitmap_gen_jso(json_object **jso_r, libxl_bitmap *bitmap) +{ + json_object *jso; + int i; + int r; + int rc =3D ERROR_FAIL; + + jso =3D json_object_new_array(); + if (!jso) goto out; + + libxl_for_each_bit(i, *bitmap) { + if (libxl_bitmap_test(bitmap, i)) { + json_object *jso_value =3D json_object_new_int(i); + if (!jso_value) goto out; + r =3D json_object_array_add(jso, jso_value); + if (r) { + json_object_put(jso_value); + goto out; + } + } + } + + *jso_r =3D jso; + jso =3D NULL; + rc =3D 0; +out: + json_object_put(jso); + return rc; +} +#endif + +#ifdef HAVE_LIBYAJL yajl_gen_status libxl_bitmap_gen_json(yajl_gen hand, libxl_bitmap *bitmap) { @@ -192,6 +283,7 @@ yajl_gen_status libxl_bitmap_gen_json(yajl_gen hand, out: return s; } +#endif =20 int libxl__bitmap_parse_json(libxl__gc *gc, const libxl__json_object *o, libxl_bitmap *p) @@ -227,6 +319,42 @@ int libxl__bitmap_parse_json(libxl__gc *gc, const libx= l__json_object *o, return 0; } =20 +#ifdef HAVE_LIBJSONC +int libxl_key_value_list_gen_jso(json_object **jso_r, libxl_key_value_list= *pkvl) +{ + libxl_key_value_list kvl =3D *pkvl; + json_object *jso; + int i; + + jso =3D json_object_new_object(); + if (!jso) goto out; + + if (!kvl) goto empty; + + for (i =3D 0; kvl[i] !=3D NULL; i +=3D 2) { + json_object *jso_value; + if (kvl[i + 1]) { + jso_value =3D json_object_new_string(kvl[i+1]); + if (!jso_value) goto out; + } else { + jso_value =3D json_object_new_null(); + } + int r =3D json_object_object_add(jso, kvl[i], jso_value); + if (r) { + json_object_put(jso_value); + goto out; + } + } +empty: + *jso_r =3D jso; + return 0; +out: + json_object_put(jso); + return ERROR_FAIL; +} +#endif + +#ifdef HAVE_LIBYAJL yajl_gen_status libxl_key_value_list_gen_json(yajl_gen hand, libxl_key_value_list *pkvl) { @@ -253,6 +381,7 @@ yajl_gen_status libxl_key_value_list_gen_json(yajl_gen = hand, out: return s; } +#endif =20 int libxl__key_value_list_parse_json(libxl__gc *gc, const libxl__json_obje= ct *o, libxl_key_value_list *p) @@ -289,6 +418,39 @@ int libxl__key_value_list_parse_json(libxl__gc *gc, co= nst libxl__json_object *o, return 0; } =20 +#ifdef HAVE_LIBJSONC +int libxl_string_list_gen_jso(json_object **jso_r, libxl_string_list *pl) +{ + libxl_string_list l =3D *pl; + json_object *jso; + int i; + int rc =3D ERROR_FAIL; + + jso =3D json_object_new_array(); + if (!jso) goto out; + + if (!l) goto empty; + + for (i =3D 0; l[i] !=3D NULL; i++) { + json_object *jso_value =3D json_object_new_string(l[i]); + if (!jso_value) goto out; + int r =3D json_object_array_add(jso, jso_value); + if (r) { + json_object_put(jso_value); + goto out; + } + } +empty: + *jso_r =3D jso; + jso =3D NULL; + rc =3D 0; +out: + json_object_put(jso); + return rc; +} +#endif + +#ifdef HAVE_LIBYAJL yajl_gen_status libxl_string_list_gen_json(yajl_gen hand, libxl_string_lis= t *pl) { libxl_string_list l =3D *pl; @@ -309,6 +471,7 @@ yajl_gen_status libxl_string_list_gen_json(yajl_gen han= d, libxl_string_list *pl) out: return s; } +#endif =20 int libxl__string_list_parse_json(libxl__gc *gc, const libxl__json_object = *o, libxl_string_list *p) @@ -342,12 +505,26 @@ int libxl__string_list_parse_json(libxl__gc *gc, cons= t libxl__json_object *o, return 0; } =20 +#ifdef HAVE_LIBJSONC +int libxl_mac_gen_jso(json_object **jso_r, libxl_mac *mac) +{ + char buf[LIBXL_MAC_FMTLEN+1]; + snprintf(buf, sizeof(buf), LIBXL_MAC_FMT, LIBXL_MAC_BYTES((*mac))); + *jso_r =3D json_object_new_string_len(buf, LIBXL_MAC_FMTLEN); + if (!*jso_r) + return ERROR_FAIL; + return 0; +} +#endif + +#ifdef HAVE_LIBYAJL yajl_gen_status libxl_mac_gen_json(yajl_gen hand, libxl_mac *mac) { char buf[LIBXL_MAC_FMTLEN+1]; snprintf(buf, sizeof(buf), LIBXL_MAC_FMT, LIBXL_MAC_BYTES((*mac))); return yajl_gen_string(hand, (const unsigned char *)buf, LIBXL_MAC_FMT= LEN); } +#endif =20 int libxl__mac_parse_json(libxl__gc *gc, const libxl__json_object *o, libxl_mac *p) @@ -358,6 +535,36 @@ int libxl__mac_parse_json(libxl__gc *gc, const libxl__= json_object *o, return libxl__parse_mac(libxl__json_object_get_string(o), *p); } =20 +#ifdef HAVE_LIBJSONC +int libxl_hwcap_gen_jso(json_object **jso_r, libxl_hwcap *p) +{ + json_object *jso; + int i; + int rc =3D ERROR_FAIL; + + jso =3D json_object_new_array(); + if (!jso) goto out; + + for(i=3D0; i<4; i++) { + json_object *jso_value =3D json_object_new_int((*p)[i]); + if (!jso_value) + goto out; + int r =3D json_object_array_add(jso, jso_value); + if (r) { + json_object_put(jso_value); + goto out; + } + } + *jso_r =3D jso; + jso =3D NULL; + rc =3D 0; +out: + json_object_put(jso); + return rc; +} +#endif + +#ifdef HAVE_LIBYAJL yajl_gen_status libxl_hwcap_gen_json(yajl_gen hand, libxl_hwcap *p) { @@ -375,6 +582,7 @@ yajl_gen_status libxl_hwcap_gen_json(yajl_gen hand, out: return s; } +#endif =20 int libxl__hwcap_parse_json(libxl__gc *gc, const libxl__json_object *o, libxl_hwcap *p) @@ -397,6 +605,37 @@ int libxl__hwcap_parse_json(libxl__gc *gc, const libxl= __json_object *o, return 0; } =20 +#ifdef HAVE_LIBJSONC +int libxl_ms_vm_genid_gen_jso(json_object **jso_r, libxl_ms_vm_genid *p) +{ + json_object *jso; + int i; + int rc =3D ERROR_FAIL; + + jso =3D json_object_new_array_ext(LIBXL_MS_VM_GENID_LEN); + if (!jso) goto out; + + for (i =3D 0; i < LIBXL_MS_VM_GENID_LEN; i++) { + json_object *jso_value =3D json_object_new_int(p->bytes[i]); + if (!jso_value) + goto out; + int r =3D json_object_array_add(jso, jso_value); + if (r) { + json_object_put(jso_value); + goto out; + } + } + + *jso_r =3D jso; + jso =3D NULL; + rc =3D 0; +out: + json_object_put(jso); + return rc; +} +#endif + +#ifdef HAVE_LIBYAJL yajl_gen_status libxl_ms_vm_genid_gen_json(yajl_gen hand, libxl_ms_vm_geni= d *p) { yajl_gen_status s; @@ -414,6 +653,7 @@ yajl_gen_status libxl_ms_vm_genid_gen_json(yajl_gen han= d, libxl_ms_vm_genid *p) =20 return yajl_gen_array_close(hand); } +#endif =20 int libxl__ms_vm_genid_parse_json(libxl__gc *gc, const libxl__json_object = *o, libxl_ms_vm_genid *p) @@ -436,6 +676,21 @@ int libxl__ms_vm_genid_parse_json(libxl__gc *gc, const= libxl__json_object *o, return 0; } =20 +#ifdef HAVE_LIBJSONC +int libxl__string_gen_jso(json_object **jso_r, const char *p) +{ + if (p) { + *jso_r =3D json_object_new_string(p); + if (!*jso_r) + return ERROR_FAIL; + } else { + *jso_r =3D json_object_new_null(); + } + return 0; +} +#endif + +#ifdef HAVE_LIBYAJL yajl_gen_status libxl__string_gen_json(yajl_gen hand, const char *p) { @@ -444,6 +699,7 @@ yajl_gen_status libxl__string_gen_json(yajl_gen hand, else return yajl_gen_null(hand); } +#endif =20 int libxl__string_parse_json(libxl__gc *gc, const libxl__json_object *o, char **p) @@ -1166,6 +1422,7 @@ libxl__json_object *libxl__json_parse(libxl__gc *gc, = const char *s) return NULL; } =20 +#ifdef USE_LIBYAJL_GEN static const char *yajl_gen_status_to_string(yajl_gen_status s) { switch (s) { @@ -1190,7 +1447,43 @@ static const char *yajl_gen_status_to_string(yajl_ge= n_status s) return "unknown error"; } } +#endif =20 +#ifdef USE_LIBJSONC_GEN +char *libxl__object_to_json(libxl_ctx *ctx, const char *type, + libxl__gen_json_callback gen, void *p) +{ + const char *buf; + char *ret =3D NULL; + json_object *jso =3D NULL; + int rc; + + rc =3D gen(&jso, p); + if (rc) + goto out; + + buf =3D json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PRETTY); + if (!buf) + goto out; + ret =3D strdup((const char *)buf); + +out: + json_object_put(jso); + + if (rc) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, + "unable to convert %s to JSON representation. ", + type); + } else if (!ret) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, + "unable to allocate space for to JSON representation of= %s", + type); + } + + return ret; +} + +#elif defined(USE_LIBYAJL_GEN) char *libxl__object_to_json(libxl_ctx *ctx, const char *type, libxl__gen_json_callback gen, void *p) { @@ -1229,6 +1522,7 @@ char *libxl__object_to_json(libxl_ctx *ctx, const cha= r *type, =20 return ret; } +#endif =20 char *libxl__json_object_to_json(libxl__gc *gc, const libxl__json_object *args) @@ -1262,6 +1556,17 @@ char *libxl__json_object_to_json(libxl__gc *gc, return ret; } =20 +#ifdef HAVE_LIBJSONC +int libxl__uint64_gen_jso(json_object **jso_r, uint64_t val) +{ + *jso_r =3D json_object_new_uint64(val); + if (!*jso_r) + return ERROR_FAIL; + return 0; +} +#endif + +#ifdef HAVE_LIBYAJL yajl_gen_status libxl__uint64_gen_json(yajl_gen hand, uint64_t val) { char *num; @@ -1282,6 +1587,7 @@ yajl_gen_status libxl__uint64_gen_json(yajl_gen hand,= uint64_t val) out: return s; } +#endif =20 int libxl__object_from_json(libxl_ctx *ctx, const char *type, libxl__json_parse_callback parse, @@ -1313,6 +1619,16 @@ int libxl__object_from_json(libxl_ctx *ctx, const ch= ar *type, return rc; } =20 +#ifdef HAVE_LIBJSONC +int libxl__int_gen_jso(json_object **jso_r, int i) +{ + *jso_r =3D json_object_new_int(i); + if (!*jso_r) + return ERROR_FAIL; + return 0; +} +#endif + int libxl__int_parse_json(libxl__gc *gc, const libxl__json_object *o, void *p) { diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index b53e013a44..d64a573ff3 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -7,9 +7,9 @@ namespace("libxl_") =20 libxl_defbool =3D Builtin("defbool", json_parse_type=3D"JSON_STRING", pass= by=3DPASS_BY_REFERENCE, copy_fn=3DNone, check_default_fn=3D"libxl__defbool_is_default") -libxl_domid =3D Builtin("domid", json_gen_fn =3D "yajl_gen_integer", json_= parse_fn =3D "libxl__uint32_parse_json", +libxl_domid =3D Builtin("domid", json_gen_fn =3D "yajl_gen_integer", jsonc= _json_gen_fn =3D "libxl__uint64_gen_jso", json_parse_fn =3D "libxl__uint32_= parse_json", json_parse_type =3D "JSON_INTEGER", autogenerate_jso= n =3D False, copy_fn=3DNone) -libxl_devid =3D Builtin("devid", json_gen_fn =3D "yajl_gen_integer", json_= parse_fn =3D "libxl__int_parse_json", +libxl_devid =3D Builtin("devid", json_gen_fn =3D "yajl_gen_integer", jsonc= _json_gen_fn =3D "libxl__int_gen_jso", json_parse_fn =3D "libxl__int_parse_= json", json_parse_type =3D "JSON_INTEGER", autogenerate_jso= n =3D False, signed =3D True, init_val=3D"-1", copy_fn=3DNone) libxl_uuid =3D Builtin("uuid", json_parse_type=3D"JSON_STRING", passby=3DP= ASS_BY_REFERENCE, check_default_fn=3D"libxl_uuid_is_nil", @@ -37,7 +37,8 @@ libxl_ms_vm_genid =3D Builtin("ms_vm_genid", passby=3DPAS= S_BY_REFERENCE, check_defau # Specific integer types # =20 -MemKB =3D UInt(64, init_val =3D "LIBXL_MEMKB_DEFAULT", json_gen_fn =3D "li= bxl__uint64_gen_json") +MemKB =3D UInt(64, init_val =3D "LIBXL_MEMKB_DEFAULT", + json_gen_fn =3D "libxl__uint64_gen_json", jsonc_json_gen_fn = =3D "libxl__uint64_gen_jso") =20 # # Constants / Enumerations diff --git a/tools/libs/light/libxl_types_internal.idl b/tools/libs/light/l= ibxl_types_internal.idl index 0425e9b6b0..ab4ee92870 100644 --- a/tools/libs/light/libxl_types_internal.idl +++ b/tools/libs/light/libxl_types_internal.idl @@ -1,7 +1,8 @@ namespace("libxl__") hidden(True) =20 -libxl_domid =3D Builtin("domid", namespace=3D"libxl_", json_gen_fn =3D "ya= jl_gen_integer", +libxl_domid =3D Builtin("domid", namespace=3D"libxl_", + json_gen_fn =3D "yajl_gen_integer", jsonc_json_gen_f= n =3D "libxl__uint64_gen_jso", json_parse_fn =3D "libxl__uint32_parse_json", json_parse_type =3D = "JSON_INTEGER", autogenerate_json =3D False, copy_fn =3D None) =20 diff --git a/tools/xl/xl_info.c b/tools/xl/xl_info.c index 83a02f45fe..80a3b25aac 100644 --- a/tools/xl/xl_info.c +++ b/tools/xl/xl_info.c @@ -60,6 +60,48 @@ static int maybe_printf(const char *fmt, ...) return count; } =20 + +#ifdef HAVE_LIBJSONC +static int printf_info_one_json(json_object **jso_r, int domid, + libxl_domain_config *d_config) +{ + json_object *jso =3D NULL; + json_object *jso_config =3D NULL; + enum json_tokener_error error; + char *s =3D NULL; + int r =3D EXIT_FAILURE; + + s =3D libxl_domain_config_to_json(ctx, d_config); + jso_config =3D json_tokener_parse_verbose(s, &error); + if (!jso_config) { + fprintf(stderr, "fail to parse JSON from libxl_domain_config_to_js= on(): %s\n", + json_tokener_error_desc(error)); + goto out; + } + + jso =3D json_object_new_object(); + if (domid !=3D -1) + json_object_object_add(jso, "domid", json_object_new_int(domid)); + else + json_object_object_add(jso, "domid", json_object_new_null()); + + + json_object_object_add(jso, "config", jso_config); + jso_config =3D NULL; + + *jso_r =3D jso; + jso =3D NULL; + r =3D EXIT_SUCCESS; + +out: + free(s); + json_object_put(jso); + json_object_put(jso_config); + return r; +} + +#elif defined(HAVE_LIBYAJL) + static yajl_gen_status printf_info_one_json(yajl_gen hand, int domid, libxl_domain_config *d_config) { @@ -95,6 +137,7 @@ static yajl_gen_status printf_info_one_json(yajl_gen han= d, int domid, out: return s; } +#endif =20 void printf_info(enum output_format output_format, int domid, @@ -103,6 +146,27 @@ void printf_info(enum output_format output_format, if (output_format =3D=3D OUTPUT_FORMAT_SXP) return printf_info_sexp(domid, d_config, fh); =20 +#ifdef HAVE_LIBJSONC + int r; + const char *buf; + json_object *jso; + + r =3D printf_info_one_json(&jso, domid, d_config); + if (r) + goto out; + + buf =3D json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PRETTY); + if (!buf) + goto out; + + fputs(buf, fh); + +out: + json_object_put(jso); + flush_stream(fh); + return; + +#elif defined(HAVE_LIBYAJL) const char *buf; libxl_yajl_length len =3D 0; yajl_gen_status s; @@ -132,6 +196,7 @@ void printf_info(enum output_format output_format, "unable to format domain config as JSON (YAJL:%d)\n", s); =20 flush_stream(fh); +#endif } =20 static void output_xeninfo(void) @@ -476,11 +541,20 @@ static void list_domains_details(const libxl_dominfo = *info, int nb_domain) =20 int i, rc; =20 + const char *buf; +#ifdef HAVE_LIBJSONC + json_object *jso =3D NULL; +#elif defined(HAVE_LIBYAJL) yajl_gen hand =3D NULL; yajl_gen_status s; - const char *buf; libxl_yajl_length yajl_len =3D 0; +#endif =20 +#ifdef HAVE_LIBJSONC + if (default_output_format =3D=3D OUTPUT_FORMAT_JSON) { + jso =3D json_object_new_array(); + } +#elif defined(HAVE_LIBYAJL) if (default_output_format =3D=3D OUTPUT_FORMAT_JSON) { hand =3D libxl_yajl_gen_alloc(NULL); if (!hand) { @@ -493,6 +567,7 @@ static void list_domains_details(const libxl_dominfo *i= nfo, int nb_domain) goto out; } else s =3D yajl_gen_status_ok; +#endif =20 for (i =3D 0; i < nb_domain; i++) { libxl_domain_config_init(&d_config); @@ -500,16 +575,32 @@ static void list_domains_details(const libxl_dominfo = *info, int nb_domain) &d_config, NULL); if (rc) continue; - if (default_output_format =3D=3D OUTPUT_FORMAT_JSON) + if (default_output_format =3D=3D OUTPUT_FORMAT_JSON) { +#ifdef HAVE_LIBJSONC + json_object *jso_value; + rc =3D printf_info_one_json(&jso_value, info[i].domid, &d_conf= ig); + json_object_array_add(jso, jso_value); +#elif defined(HAVE_LIBYAJL) s =3D printf_info_one_json(hand, info[i].domid, &d_config); - else +#endif + } else printf_info_sexp(info[i].domid, &d_config, stdout); libxl_domain_config_dispose(&d_config); +#ifdef HAVE_LIBJSONC + if (rc) + goto out; +#elif defined(HAVE_LIBYAJL) if (s !=3D yajl_gen_status_ok) goto out; +#endif } =20 if (default_output_format =3D=3D OUTPUT_FORMAT_JSON) { +#ifdef HAVE_LIBJSONC + buf =3D json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PRETT= Y); + if (!buf) + goto out; +#elif defined(HAVE_LIBYAJL) s =3D yajl_gen_array_close(hand); if (s !=3D yajl_gen_status_ok) goto out; @@ -517,16 +608,21 @@ static void list_domains_details(const libxl_dominfo = *info, int nb_domain) s =3D yajl_gen_get_buf(hand, (const unsigned char **)&buf, &yajl_l= en); if (s !=3D yajl_gen_status_ok) goto out; +#endif =20 puts(buf); } =20 out: if (default_output_format =3D=3D OUTPUT_FORMAT_JSON) { +#ifdef HAVE_LIBJSONC + json_object_put(jso); +#elif defined(HAVE_LIBYAJL) yajl_gen_free(hand); if (s !=3D yajl_gen_status_ok) fprintf(stderr, "unable to format domain config as JSON (YAJL:%d)\n", = s); +#endif } } =20 --=20 Anthony PERARD From nobody Sat Oct 4 22:00:05 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=1759147703; cv=none; d=zohomail.com; s=zohoarc; b=NwXwzTf1wKGK2SanlF0B/5tuZ0pHc9dlXHL+y7P0JdMtgkKQRLiV9IS1PO8edFi+Q2YRcdg7wXyz/b/e2ykJXarrpRMBme5xyAv4VIKy7Cjbyq0nIAI+6ZpVBBLm4BwjdTp1WjjkoE+g8y4pfrDlJOXK8SZDVYN7oM7ve1qLW+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759147703; 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=7z8q2jx9Z85Tq8/zLDVB0fdB1L9QpzjX78jo8wa3bT0=; b=jPD99wHjsWHc4E2e/y6pgJ3bhnLv7JfXTQG0lXixBgtIWUPUCBMZamFWHZA+XwZ+BRNUISQstYjH5akVn6kvKyudha/pA8nDDrcOJARadM79HHp2Z3cDJ4Mol+XubJTr45eYlhOB4LWLEvrH1sV5J1oqDxkjcYgt2IzBQpq72Sk= 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 1759147703059826.8140830461826; Mon, 29 Sep 2025 05:08:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1132743.1471028 (Exim 4.92) (envelope-from ) id 1v3Cfm-00007n-BK; Mon, 29 Sep 2025 12:08:06 +0000 Received: by outflank-mailman (output) from mailman id 1132743.1471028; 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-00007Y-6y; Mon, 29 Sep 2025 12:08:06 +0000 Received: by outflank-mailman (input) for mailman id 1132743; Mon, 29 Sep 2025 12:08:04 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3Cfj-0008DS-V9 for xen-devel@lists.xenproject.org; Mon, 29 Sep 2025 12:08:03 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1v3Cfj-00GXBd-2J; Mon, 29 Sep 2025 12:08:03 +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 1v3Cfj-004JHo-2M; Mon, 29 Sep 2025 12:08:03 +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=7z8q2jx9Z85Tq8/zLDVB0fdB1L9QpzjX78jo8wa3bT0=; b=HLJzgLIkTM1mPA8GjhtyzC+/m4 0VNpQPeN7gQnNYhhNAzpn3Ws5GxjwgcrgWs7TXCSdFCCGXicnmq6TQkLj+Jr5e0eAE+e1qreco8r3 V/sz6dP7atBoaUyoaXNkMemnamn4zIIOffbkZBXvLeGuQ/6wnou2x5NlQaI6lBivewPg=; From: Anthony PERARD To: xen-devel@lists.xenproject.org Cc: Anthony PERARD , Jason Andryuk , Juergen Gross Subject: [XEN PATCH v2 5/8] libxl: convert libxl__json_object_to_json() to json_object Date: Mon, 29 Sep 2025 14:07:53 +0200 Message-ID: <20250929120756.46075-6-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: quoted-printable X-ZohoMail-DKIM: pass (identity @xenproject.org) X-ZM-MESSAGEID: 1759147704187116600 Content-Type: text/plain; charset="utf-8" From: Anthony PERARD But keep the implementation done for YAJL. Signed-off-by: Anthony PERARD Reviewed-by: Jason Andryuk --- tools/libs/light/libxl_json.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/libs/light/libxl_json.c b/tools/libs/light/libxl_json.c index eeda9c301d..c76ae9f64a 100644 --- a/tools/libs/light/libxl_json.c +++ b/tools/libs/light/libxl_json.c @@ -104,10 +104,12 @@ typedef struct libxl__yajl_ctx { * YAJL Helper */ =20 +#ifdef HAVE_LIBYAJL yajl_gen_status libxl__yajl_gen_asciiz(yajl_gen hand, const char *str) { return yajl_gen_string(hand, (const unsigned char *)str, strlen(str)); } +#endif =20 #ifdef HAVE_LIBJSONC int libxl__enum_gen_jso(json_object **jso_r, const char *str) @@ -1527,6 +1529,29 @@ char *libxl__object_to_json(libxl_ctx *ctx, const ch= ar *type, char *libxl__json_object_to_json(libxl__gc *gc, const libxl__json_object *args) { +#ifdef HAVE_LIBJSONC + const char *buf; + json_object *root; + char *ret =3D NULL; + int rc; + + if (!args) + return NULL; + + rc =3D libxl__json_object_to_json_object(gc, &root, args); + if (rc) + goto out; + + buf =3D json_object_to_json_string_ext(root, JSON_C_TO_STRING_PRETTY); + if (!buf) + goto out; + + ret =3D libxl__strdup(gc, buf); + +out: + json_object_put(root); + return ret; +#elif defined(HAVE_LIBYAJL) const unsigned char *buf; libxl_yajl_length len; yajl_gen_status s; @@ -1554,6 +1579,7 @@ char *libxl__json_object_to_json(libxl__gc *gc, out: yajl_gen_free(hand); return ret; +#endif } =20 #ifdef HAVE_LIBJSONC --=20 Anthony PERARD From nobody Sat Oct 4 22:00:05 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=1759147711; cv=none; d=zohomail.com; s=zohoarc; b=edp71IrcL6EXzaGrA8w+lHcBVxM7dAKH0dcE9SLAoC6ZyMy3KB27WwhUDeK5yxHqxsD81wTXYCfZkw9V9uex3sDtivWNLE2+j1NJYaHQJ4gu6uqQCXq32CLaaHmOuCB/pl7zYHaul5olf6sFCyw6eCS1J0LlHYovH7e6uXp4jjk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759147711; 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=fd7IuQgDa95R64KYB4tblr0/98vW3XrqIHcr4eD97H4=; b=IuktVrVmokW34sO7rS+x9jjuNu9GGE/rN2Sb/k3wa26MlyC2B0t1hX+Btp1yGGNIg9TYVmwtQnupHUQEn8dbEvzejpeQy+6Ks/WKqWxL0MsvOLy+c+gyTrpNNgaW06vHOI5j8Ky0GXHrn46DeErKdFlzoIVwSr+u24RAI6p7H9g= 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 17591477112511011.7094027034736; Mon, 29 Sep 2025 05:08:31 -0700 (PDT) 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 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-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=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: quoted-printable X-ZohoMail-DKIM: pass (identity @xenproject.org) X-ZM-MESSAGEID: 1759147713228116600 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 --- 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) +=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 $(XEN_JSON_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 (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 1759147712711310.4334598269844; Mon, 29 Sep 2025 05:08:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1132745.1471039 (Exim 4.92) (envelope-from ) id 1v3Cfn-0000Fe-4B; Mon, 29 Sep 2025 12:08:07 +0000 Received: by outflank-mailman (output) from mailman id 1132745.1471039; Mon, 29 Sep 2025 12:08:07 +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-0000Er-R9; Mon, 29 Sep 2025 12:08:06 +0000 Received: by outflank-mailman (input) for mailman id 1132745; 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 1v3Cfl-0008Sd-FG for xen-devel@lists.xenproject.org; Mon, 29 Sep 2025 12:08:05 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1v3Cfl-00GXBu-14; Mon, 29 Sep 2025 12:08:05 +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 1v3Cfl-004JHo-1B; Mon, 29 Sep 2025 12:08:05 +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=9LmUJ4zuB4olL3YoOObx5zrJYD33c+ZXbGLTgVb/atI=; b=etrR+Ma3DnJFtNc9fa0KgGf8Wy o3eW5hATHhPH20+szrlhm+XcQRrzjX/uvHt9dipP1yk3p86dxvckIhKZJg+MzVHGIitZBnKC4IBgq ttdIWQgdw6OqAfoemb5LyWKffJ04WxBeZKgjZV9E0z8ImVT6YpYZBWmqXz8TJLTOrF6g=; From: Anthony PERARD To: xen-devel@lists.xenproject.org Cc: Anthony PERARD Subject: [XEN PATCH v2 7/8] configure: Use json-c by default, fallback to yajl Date: Mon, 29 Sep 2025 14:07:55 +0200 Message-ID: <20250929120756.46075-8-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: quoted-printable X-ZohoMail-DKIM: pass (identity @xenproject.org) X-ZM-MESSAGEID: 1759147714237116600 Content-Type: text/plain; charset="utf-8" From: Anthony PERARD Signed-off-by: Anthony PERARD Acked-by: Andrew Cooper Reviewed-by: Jason Andryuk --- tools/configure | 97 +++++++++++++++++++++++++++++----------------- tools/configure.ac | 12 +++--- 2 files changed, 69 insertions(+), 40 deletions(-) diff --git a/tools/configure b/tools/configure index edd1701b2d..0eb7a0ab6a 100755 --- a/tools/configure +++ b/tools/configure @@ -9692,41 +9692,7 @@ fi # Put the nasty error message in config.log where it belongs echo "$libjsonc_PKG_ERRORS" >&5 =20 - as_fn_error $? "Package requirements (json-c) were not met: - -$libjsonc_PKG_ERRORS - -Consider adjusting the PKG_CONFIG_PATH environment variable if you -installed software in a non-standard prefix. - -Alternatively, you may set the environment variables libjsonc_CFLAGS -and libjsonc_LIBS to avoid the need to call pkg-config. -See the pkg-config man page for more details." "$LINENO" 5 -elif test $pkg_failed =3D untried; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } - { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error $? "The pkg-config script could not be found or is too old. M= ake sure it -is in your PATH or set the PKG_CONFIG environment variable to the full -path to pkg-config. - -Alternatively, you may set the environment variables libjsonc_CFLAGS -and libjsonc_LIBS to avoid the need to call pkg-config. -See the pkg-config man page for more details. - -To get pkg-config, see . -See \`config.log' for more details" "$LINENO" 5; } -else - libjsonc_CFLAGS=3D$pkg_cv_libjsonc_CFLAGS - libjsonc_LIBS=3D$pkg_cv_libjsonc_LIBS - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -printf "%s\n" "yes" >&6; } - -printf "%s\n" "#define HAVE_LIBJSONC 1" >>confdefs.h - -fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for yajl_alloc in -= lyajl" >&5 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for yajl_alloc in = -lyajl" >&5 printf %s "checking for yajl_alloc in -lyajl... " >&6; } if test ${ac_cv_lib_yajl_yajl_alloc+y} then : @@ -9772,6 +9738,67 @@ else $as_nop as_fn_error $? "Could not find yajl" "$LINENO" 5 fi =20 + +elif test $pkg_failed =3D untried; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for yajl_alloc in = -lyajl" >&5 +printf %s "checking for yajl_alloc in -lyajl... " >&6; } +if test ${ac_cv_lib_yajl_yajl_alloc+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_check_lib_save_LIBS=3D$LIBS +LIBS=3D"-lyajl $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +char yajl_alloc (); +int +main (void) +{ +return yajl_alloc (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + ac_cv_lib_yajl_yajl_alloc=3Dyes +else $as_nop + ac_cv_lib_yajl_yajl_alloc=3Dno +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext +LIBS=3D$ac_check_lib_save_LIBS +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_yajl_yajl= _alloc" >&5 +printf "%s\n" "$ac_cv_lib_yajl_yajl_alloc" >&6; } +if test "x$ac_cv_lib_yajl_yajl_alloc" =3D xyes +then : + YAJL_LIBS=3D-lyajl + + +printf "%s\n" "#define HAVE_LIBYAJL 1" >>confdefs.h + +else $as_nop + as_fn_error $? "Could not find yajl" "$LINENO" 5 +fi + + +else + libjsonc_CFLAGS=3D$pkg_cv_libjsonc_CFLAGS + libjsonc_LIBS=3D$pkg_cv_libjsonc_LIBS + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + +printf "%s\n" "#define HAVE_LIBJSONC 1" >>confdefs.h + +fi + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for deflateCopy in = -lz" >&5 printf %s "checking for deflateCopy in -lz... " >&6; } if test ${ac_cv_lib_z_deflateCopy+y} diff --git a/tools/configure.ac b/tools/configure.ac index bb40b5b3f0..7267d02a04 100644 --- a/tools/configure.ac +++ b/tools/configure.ac @@ -425,11 +425,13 @@ AC_SUBST([ZLIB_LIBS]) AX_CHECK_EXTFS AX_CHECK_PTHREAD PKG_CHECK_MODULES([libjsonc], [json-c], - [AC_DEFINE([HAVE_LIBJSONC], [1], [Use library json-c])]) -AC_CHECK_LIB([yajl], [yajl_alloc], - [AC_SUBST([YAJL_LIBS],[-lyajl]) - AC_DEFINE([HAVE_LIBYAJL],[1],[Define to 1 if you have the `yajl' libra= ry (-lyajl).])], - [AC_MSG_ERROR([Could not find yajl])]) + [AC_DEFINE([HAVE_LIBJSONC], [1], [Use library json-c])], + [AC_CHECK_LIB([yajl], [yajl_alloc], + [AC_SUBST([YAJL_LIBS],[-lyajl]) + AC_DEFINE([HAVE_LIBYAJL],[1],[Define to 1 if you have the `yajl' = library (-lyajl).])], + [AC_MSG_ERROR([Could not find yajl])]) +]) + AC_CHECK_LIB([z], [deflateCopy], [], [AC_MSG_ERROR([Could not find zlib])]) AC_CHECK_HEADER([argp.h], [ AC_CHECK_LIB([argp], [argp_usage], [argp_ldflags=3D"-largp"]) --=20 Anthony PERARD From nobody Sat Oct 4 22:00:05 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=1759147704; cv=none; d=zohomail.com; s=zohoarc; b=nvHw8O2oe5VaFdYn2XJyhdZlLh+34bqnPrRgDH7anhxBfDRcFjKeUDSowl8pXyknvvphW3Nj+NV1zjU8OZML10JIMd3VmwVj5T+Hd7q8N4ymX/25H8b73y3pSn2S1lK20W0/X06l4wBgcUW0r+YvW5v9DDYFCD8kNSM8A+itEJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759147704; 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=raGKb3UCqN0a1TTX8Sfmq9eUg57Dvzpt+gXKdGHPbJI=; b=T5gcFrUDbyMDagGNAi+9NgGigtR5+ywxPvec8yCOIjfADmmFKAe/zMh0zZeVw//CqmVd4kD8Yw6g95yo6yOtBpsVrfyek3A4grH11T/xXSYlt1QXGIXcYcX4n5bkxJNnSNQuWsxgn5nKAoUegTiF9h5HZYNoufEoQy3KDH12HeY= 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 1759147704901507.6322097198621; Mon, 29 Sep 2025 05:08:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1132746.1471059 (Exim 4.92) (envelope-from ) id 1v3Cfp-0000us-C4; Mon, 29 Sep 2025 12:08:09 +0000 Received: by outflank-mailman (output) from mailman id 1132746.1471059; Mon, 29 Sep 2025 12:08:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3Cfp-0000uK-4s; Mon, 29 Sep 2025 12:08:09 +0000 Received: by outflank-mailman (input) for mailman id 1132746; Mon, 29 Sep 2025 12:08:07 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v3Cfn-0000cd-QQ for xen-devel@lists.xenproject.org; Mon, 29 Sep 2025 12:08:07 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1v3Cfm-00GXC0-36; Mon, 29 Sep 2025 12:08:06 +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 1v3Cfm-004JHo-3A; Mon, 29 Sep 2025 12:08:06 +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=raGKb3UCqN0a1TTX8Sfmq9eUg57Dvzpt+gXKdGHPbJI=; b=5ZAMrUM+JRmBDkqjSdk5ESmgoh PXqmbfjXnUNkWcKjup4FABeCBm6CoDra1a31szq1/sV+GZeaN/hBmIVPVsaTXbIhqyyweuK7uAS60 KMh+ArsFUdU5DNZNBnKdkMApVGk4JjGTEjFKfJeSdF70IZlogZ30LaVXAvS4wr3CXs/8=; From: Anthony PERARD To: xen-devel@lists.xenproject.org Cc: Anthony PERARD , Oleksii Kurochko , Community Manager , Andrew Cooper , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [XEN PATCH v2 8/8] Update CHANGELOG and README with dependency on json-c Date: Mon, 29 Sep 2025 14:07:56 +0200 Message-ID: <20250929120756.46075-9-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: quoted-printable X-ZohoMail-DKIM: pass (identity @xenproject.org) X-ZM-MESSAGEID: 1759147706048116601 Content-Type: text/plain; charset="utf-8" From: Anthony PERARD Signed-off-by: Anthony PERARD Acked-by: Oleksii Kurochko --- CHANGELOG.md | 2 ++ README | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b9518ff08..5c70bc0250 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](https://keepach= angelog.com/en/1.0.0/) - Debian Trixie added to CI. Debian Bullseye retired from CI for RISC-V = due to the baseline change. - Linux based device model stubdomains are now fully supported. + - New dependency on library json-c, the toolstack will prefer it to `YAJL` + when available. =20 - On x86: - Restrict the cache flushing done as a result of guest physical memory= map diff --git a/README b/README index 6ee58f7b35..9329f30e13 100644 --- a/README +++ b/README @@ -53,7 +53,7 @@ provided by your OS distributor: * Development install of Python 2.7 or later (e.g., python-dev) * Development install of curses (e.g., libncurses-dev) * Development install of uuid (e.g. uuid-dev) - * Development install of yajl (e.g. libyajl-dev) + * Development install of json-c (e.g. libjson-c-dev) or yajl (e.g. lib= yajl-dev) * Development install of libaio (e.g. libaio-dev) version 0.3.107 or greater. * Development install of GLib v2.0 (e.g. libglib2.0-dev) --=20 Anthony PERARD