Allow to build libxl and other tools with json-c instead of yajl
v2 cover Allow to build libxl and other tools with json-c instead of yajl
From: Anthony PERARD <[email protected]>
Patch series available in this git branch:
https://xenbits.xenproject.org/git-http/people/aperard/xen-unstable.git br.libxl-libjsonc-v2
changes in v2:
- introduce $(XEN_JSON_LIBS) to have either -lyajl or -ljson-c or both (for a short while).
- few more changes detail in each patches.
Hi,
The library YAJL has been unmaintained for several years, without an obvious fork to pick.
On the other and the library json-c is been maintained and use by several other project, it's probably already installed on your machine. So this patch series intend to allow to build the Xen toolstack again json-c, and forgo yajl.
Just in case, YAJL is can still be used.
There's bit of libxl API that exposes YAJL, mainly so it can be used by xl to call libxl_domain_config_gen_json(). It was exposed via the "libxl_json.h" headers. This functions and others won't be available when libxl is build against json-c.
Cheers,
Anthony PERARD (8):
tools/configure: Introduce deps on json-c lib for libxl
libxl: Convert libxl__json_parse() to use json-c
libxl: convert libxl__json_object_to_yajl_gen to
libxl__json_object_to_libjsonc_object
libxl: libxl__object_to_json() to json-c
libxl: convert libxl__json_object_to_json() to json_object tools/libxenstat: Use json-c when available
configure: Use json-c by default, fallback to yajl Update CHANGELOG and README with dependency on json-c
CHANGELOG.md | 2 + README | 2 +- config/Tools.mk.in | 1 + tools/config.h.in | 3 + tools/configure | 136 +++++- tools/configure.ac | 10 +- tools/include/libxl_json.h | 27 ++ tools/libs/light/Makefile | 6 +- 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 | 23 +- tools/libs/light/libxl_json.c | 562 +++++++++++++++++++++- tools/libs/light/libxl_qmp.c | 53 ++ tools/libs/light/libxl_types.idl | 7 +- tools/libs/light/libxl_types_internal.idl | 3 +- tools/libs/stat/Makefile | 2 +- tools/libs/stat/xenstat_qmp.c | 126 ++++- tools/xl/Makefile | 2 +- tools/xl/xl_info.c | 102 +++- 20 files changed, 1312 insertions(+), 41 deletions(-)
Signature · 1 line
Anthony PERARD
PATCH v2 1/8 tools/configure: Introduce deps on json-c lib for libxl
From: Anthony PERARD <[email protected]>
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.
---
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(-)
config/Tools.mk.in +1 -0
@@ -65,6 +65,7 @@ EXTFS_LIBS := @EXTFS_LIBS@ CURSES_LIBS := @CURSES_LIBS@ TINFO_LIBS := @TINFO_LIBS@ ARGP_LDFLAGS := @argp_ldflags@ +XEN_JSON_LIBS := @YAJL_LIBS@ @libjsonc_LIBS@ FILE_OFFSET_BITS := @FILE_OFFSET_BITS@
tools/config.h.in +3 -0
@@ -27,6 +27,9 @@ /* Define to 1 if you have the `fdt' library (-lfdt). */ #undef HAVE_LIBFDT +/* Use library json-c */ +#undef HAVE_LIBJSONC + /* Define to 1 if you have the `lzma' library (-llzma). */ #undef HAVE_LIBLZMA
tools/configure +105 -2
138 lines not on this page · raw message
tools/configure.ac +5 -1
@@ -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' 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], [
tools/libs/light/Makefile +2 -2
@@ -166,7 +166,7 @@ LDLIBS-$(CONFIG_Linux) += -luuid LDLIBS-$(CONFIG_Linux) += -lrt LDLIBS-$(CONFIG_ARM) += -lfdt LDLIBS-y += $(PTHREAD_LIBS) -LDLIBS-y += -lyajl +LDLIBS-y += $(XEN_JSON_LIBS) LDLIBS += $(LDLIBS-y) $(OBJS-y) $(PIC_OBJS) $(LIBXL_TEST_OBJS): CFLAGS += $(CFLAGS_LIBXL) -include $(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) test_%: test_%.o test_common.o libxenlight_test.so - $(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) -lyajl $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(XEN_JSON_LIBS) $(APPEND_LDFLAGS) libxl-save-helper: $(SAVE_HELPER_OBJS) libxenlight.so $(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
tools/xl/Makefile +1 -1
@@ -33,7 +33,7 @@ $(XL_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h # libxl_json.h needs i all: xl xl: $(XL_OBJS) - $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) -lyajl $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(XEN_JSON_LIBS) $(APPEND_LDFLAGS) .PHONY: install install: all
Signature · 1 line
Anthony PERARD
Re: [XEN PATCH v2 1/8] tools/configure: Introduce deps on json-c lib for libxl
Quoted 4 lines · Anthony PERARD
From: Anthony PERARD <[email protected]>
To replace yajl.
Quoted 8 lines
Introduce
XEN_JSON_LIBSvariable, 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 <[email protected]>
Re: [XEN PATCH v2 1/8] tools/configure: Introduce deps on json-c lib for libxl
In reply to Anthony PERARDQuoted 4 lines · Anthony PERARD
From: Anthony PERARD <[email protected]>
To replace yajl.
Quoted 8 lines
Introduce
XEN_JSON_LIBSvariable, 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 <[email protected]>
Thanks,
Jason
PATCH v2 2/8 libxl: Convert libxl__json_parse() to use json-c
In reply to Anthony PERARDFrom: Anthony PERARD <[email protected]>
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.
--- tools/include/libxl_json.h | 4 ++ tools/libs/light/libxl_json.c | 120 ++++++++++++++++++++++++++++++++-- 2 files changed, 120 insertions(+), 4 deletions(-)
tools/include/libxl_json.h +4 -0
@@ -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 +#ifdef HAVE_LIBYAJL #ifdef HAVE_YAJL_V2 typedef size_t libxl_yajl_length ;
@@ -89,5 +90,8 @@ static inline yajl_gen libxl_yajl_gen_alloc(const yajl_alloc_funcs *allocFuncs) }#endif /* !HAVE_YAJL_V2 */ +#else +typedef size_t libxl_yajl_length ; +#endif /* !HAVE_LIBYAJL */ #endif /* LIBXL_JSON_H */
tools/libs/light/libxl_json.c +116 -4
204 lines not on this page · raw message
Signature · 1 line
Anthony PERARD
Re: [XEN PATCH v2 2/8] libxl: Convert libxl__json_parse() to use json-c
Quoted 11 lines · Anthony PERARD
tools/libs/light/libxl_json.c +5
-0@@ -16,7 +16,25 @@#include <math.h> +#ifdef HAVE_LIBJSONC +#include <json-c/json.h> +#define USE_LIBJSONC_PARSER +#endif +
tools/libs/light/libxl_json.c line 33
Quoted 10 lines
tools/libs/light/libxl_json.c +10
-0+#ifdef HAVE_LIBYAJL +# ifndef USE_LIBJSONC_PARSER +# define USE_LIBYAJL_PARSER +# endif +#endif + + +#ifdef USE_LIBJSONC_PARSER +#include <json-c/json_visit.h> +#endif
The version of json-c one of my systems is using also doesn't have this header.
Plus (uses originating from other patches in this series) json_object_object_add() returns void there. Plus of course any number of further issues I'm going to see. The checking configure.ac is doing right now looks to be insufficient overall.
Jan
Re: [XEN PATCH v2 2/8] libxl: Convert libxl__json_parse() to use json-c
Quoted 16 lines · Jan Beulich
Quoted 15 lines · Anthony PERARD
tools/libs/light/libxl_json.c +9
-0@@ -16,7 +16,25 @@#include <math.h> +#ifdef HAVE_LIBJSONC +#include <json-c/json.h> +#define USE_LIBJSONC_PARSER +#endif + +#ifdef HAVE_LIBYAJL +# ifndef USE_LIBJSONC_PARSER +# define USE_LIBYAJL_PARSER +# endif
Quoted 8 lines
tools/libs/light/libxl_json.c line 33
Quoted 6 lines
tools/libs/light/libxl_json.c +6
-0+#endif + + +#ifdef USE_LIBJSONC_PARSER +#include <json-c/json_visit.h> +#endif The version of json-c one of my systems is using also doesn't have this header.
Looks like this was introduced in 0.13, with json_c_visit().
Quoted 4 lines
Plus (uses originating from other patches in this series)
json_object_object_add()returns void there. Plus of course any number of further issues I'm going to see. The checking configure.ac is doing right now looks to be insufficient overall.
json_object_object_add() prototype was change in 0.13 it seems, according to
https://github.com/json-c/json-c/blob/master/ChangeLog
Also, another patch (xenstat) was using a deprecated function json_object_object_get(), but the deprecation seems to have been removed in 0.13.
I've tried to build with our Ubuntu 20.04 docker image, on which we can install json-c 0.13 and found other missing functions.
Both json_object_new_null() and json_object_new_uint64() are missing, the first one isn't needed, but I think we need the second one. Both were introduced in json-c 0.14.
And last one, json_object_new_array_ext() which was introduced in 0.15. We could replace it by json_object_new_array() if needed.
Overall, is seems the current code needs json-c 0.15, so
-PKG_CHECK_MODULES([libjsonc], [json-c],
+PKG_CHECK_MODULES([libjsonc], [json-c >= 0.15],I'll prepare a patch.
Cheers,
Signature · 1 line
Anthony PERARD
PATCH v2 3/8 libxl: convert libxl__json_object_to_yajl_gen to libxl__json_object_to_libjsonc_object
In reply to Anthony PERARDFrom: Anthony PERARD <[email protected]>
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.
---
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(+)
tools/include/libxl_json.h +6 -0
@@ -15,12 +15,18 @@#ifndef LIBXL_JSON_H #define LIBXL_JSON_H +#ifdef HAVE_LIBJSONC +#include <json-c/json.h> +#endif + +#ifdef HAVE_LIBYAJL #include <yajl/yajl_gen.h> #include <yajl/yajl_parse.h> #ifdef HAVE_YAJL_YAJL_VERSION_H # include <yajl/yajl_version.h> #endif +#endif 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);
tools/libs/light/libxl_internal.h +7 -0
@@ -2234,9 +2234,16 @@ _hidden const libxl__json_object *libxl__json_map_get(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 *obj); +#endif +#ifdef HAVE_LIBYAJL _hidden yajl_status libxl__json_object_to_yajl_gen(libxl__gc *gc_opt,yajl_gen hand,const libxl__json_object *param); +#endif _hidden void libxl__json_object_free(libxl__gc *gc_opt,libxl__json_object *obj);
tools/libs/light/libxl_json.c +100 -0
112 lines not on this page · raw message
tools/libs/light/libxl_qmp.c +53 -0
82 lines not on this page · raw message
Signature · 1 line
Anthony PERARD
PATCH v2 4/8 libxl: libxl__object_to_json() to json-c
In reply to Anthony PERARDFrom: Anthony PERARD <[email protected]>
- 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.
---
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(-)
tools/include/libxl_json.h +17 -0
@@ -28,6 +28,22 @@#endif #endif +#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_cpuid_policy_list *p); +_hidden int libxl_string_list_gen_jso(json_object **jso_r,libxl_string_list *p); +_hidden int libxl_key_value_list_gen_jso(json_object **jso_r, libxl_key_value_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_genid *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 hand, 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_genid *p); +#endif #include <_libxl_types_json.h>
tools/libs/light/Makefile +1 -1
@@ -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_type$(*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)_private.h)
tools/libs/light/gentypes.py +151 -9
208 lines not on this page · raw message
tools/libs/light/idl.py +6 -1
@@ -79,6 +79,7 @@ class Type(object): if self.typename is not None and not self.private: self.json_gen_fn = kwargs.setdefault('json_gen_fn', self.typename + "_gen_json") + self.jsonc_json_gen_fn = kwargs.setdefault('jsonc_json_gen_fn', self.typename + "_gen_jso") self.json_parse_type = kwargs.setdefault('json_parse_type', "JSON_ANY") if self.namespace is not None: self.json_parse_fn = kwargs.setdefault('json_parse_fn',
@@ -88,6 +89,7 @@ class Type(object): self.typename + "_parse_json") else: self.json_gen_fn = kwargs.setdefault('json_gen_fn', None) + self.jsonc_json_gen_fn = kwargs.setdefault('jsonc_json_gen_fn', None) self.json_parse_type = kwargs.setdefault('json_parse_type', None) self.json_parse_fn = kwargs.setdefault('json_parse_fn', None)
@@ -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 = Builtin("void *", namespace = None) bool = Builtin("bool", namespace = None, copy_fn=None, json_gen_fn = "yajl_gen_bool", + jsonc_json_gen_fn = "libxl__boolean_gen_jso", json_parse_type = "JSON_BOOL", json_parse_fn = "libxl__bool_parse_json", autogenerate_json = False)
@@ -301,10 +305,11 @@ integer = Number("int", namespace = None, signed = True) uint8 = UInt(8) uint16 = UInt(16) uint32 = UInt(32) -uint64 = UInt(64, json_gen_fn = "libxl__uint64_gen_json") +uint64 = UInt(64, json_gen_fn = "libxl__uint64_gen_json", jsonc_json_gen_fn = "libxl__uint64_gen_jso") string = Builtin("char *", namespace = None, copy_fn = "libxl_string_copy", dispose_fn = "free", json_gen_fn = "libxl__string_gen_json", + jsonc_json_gen_fn = "libxl__string_gen_jso", json_parse_type = "JSON_STRING | JSON_NULL", json_parse_fn = "libxl__string_parse_json", autogenerate_json = False,
tools/libs/light/libxl_cpuid.c +119 -0
131 lines not on this page · raw message
tools/libs/light/libxl_internal.h +14 -2
@@ -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); -_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);
@@ -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); +#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 <yajl/yajl_gen.h> _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 *str); +_hidden yajl_gen_status libxl__string_gen_json(yajl_gen hand, const char *p); +#endif typedef enum { JSON_NULL = (1 << 0),
tools/libs/light/libxl_json.c +316 -0
495 lines not on this page · raw message
tools/libs/light/libxl_types.idl +4 -3
@@ -7,9 +7,9 @@ namespace("libxl_") libxl_defbool = Builtin("defbool", json_parse_type="JSON_STRING", passby=PASS_BY_REFERENCE, copy_fn=None, check_default_fn="libxl__defbool_is_default") -libxl_domid = Builtin("domid", json_gen_fn = "yajl_gen_integer", json_parse_fn = "libxl__uint32_parse_json", +libxl_domid = Builtin("domid", json_gen_fn = "yajl_gen_integer", jsonc_json_gen_fn = "libxl__uint64_gen_jso", json_parse_fn = "libxl__uint32_parse_json", json_parse_type = "JSON_INTEGER", autogenerate_json = False, copy_fn=None) -libxl_devid = Builtin("devid", json_gen_fn = "yajl_gen_integer", json_parse_fn = "libxl__int_parse_json", +libxl_devid = Builtin("devid", json_gen_fn = "yajl_gen_integer", jsonc_json_gen_fn = "libxl__int_gen_jso", json_parse_fn = "libxl__int_parse_json", json_parse_type = "JSON_INTEGER", autogenerate_json = False, signed = True, init_val="-1", copy_fn=None) libxl_uuid = Builtin("uuid", json_parse_type="JSON_STRING", passby=PASS_BY_REFERENCE, check_default_fn="libxl_uuid_is_nil",
@@ -37,7 +37,8 @@ libxl_ms_vm_genid = Builtin("ms_vm_genid", passby=PASS_BY_REFERENCE, check_defau # Specific integer types # -MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT", json_gen_fn = "libxl__uint64_gen_json") +MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT", + json_gen_fn = "libxl__uint64_gen_json", jsonc_json_gen_fn = "libxl__uint64_gen_jso") # # Constants / Enumerations
tools/libs/light/libxl_types_internal.idl +2 -1
@@ -1,7 +1,8 @@ namespace("libxl__") hidden(True) -libxl_domid = Builtin("domid", namespace="libxl_", json_gen_fn = "yajl_gen_integer", +libxl_domid = Builtin("domid", namespace="libxl_", + json_gen_fn = "yajl_gen_integer", jsonc_json_gen_fn = "libxl__uint64_gen_jso", json_parse_fn = "libxl__uint32_parse_json", json_parse_type = "JSON_INTEGER", autogenerate_json = False, copy_fn = None)
tools/xl/xl_info.c +99 -3
172 lines not on this page · raw message
Signature · 1 line
Anthony PERARD
Re: [XEN PATCH v2 4/8] libxl: libxl__object_to_json() to json-c
tools/libs/light/gentypes.py def get_default_expr(f, nparent, fexpr): · line 387
Quoted 13 lines · Anthony PERARD
tools/libs/light/gentypes.py +9
-0@@ -352,6 +376,86 @@ def get_default_expr(f, nparent, fexpr): return "%s" % fexpr +# For json-c gen_json functions +def libxl_C_type_gen_jso(ty, v, indent = " ", parent = None, scope_object = "jso"): + s = "" + if parent is None: + s += "json_object *jso;\n" + s += "int rc;\n" + sub_scope_object = "jso_sub_1" + else: + sub_scope_object = "jso_sub_%d" % (1+int(scope_object.removeprefix("jso_sub_")))
removeprefix() was added only in 3.9. I'm now trying to figure out what to replace its use with to be compatible with older versions.
Jan
PATCH v2 5/8 libxl: convert libxl__json_object_to_json() to json_object
In reply to Anthony PERARDFrom: Anthony PERARD <[email protected]>
But keep the implementation done for YAJL.
--- tools/libs/light/libxl_json.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
tools/libs/light/libxl_json.c +26 -0
@@ -104,10 +104,12 @@ typedef struct libxl__yajl_ctx {* YAJL Helper */ +#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 #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 char *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 =NULL ; +int rc; + +if (!args) +return NULL ; + + rc =libxl__json_object_to_json_object (gc, &root, args); +if (rc) + goto out; + + buf =json_object_to_json_string_ext (root,JSON_C_TO_STRING_PRETTY ); +if (!buf) + goto out; + + ret =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 }#ifdef HAVE_LIBJSONC
Signature · 1 line
Anthony PERARD
PATCH v2 6/8 tools/libxenstat: Use json-c when available
In reply to Anthony PERARDFrom: Anthony PERARD <[email protected]>
This is mainly a copy of the existing code in yajl and use json-c instead.
---
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(-)
tools/libs/stat/Makefile +1 -1
@@ -24,7 +24,7 @@ OBJS-$(CONFIG_SunOS) += xenstat_solaris.o OBJS-$(CONFIG_NetBSD) += xenstat_netbsd.o OBJS-$(CONFIG_FreeBSD) += xenstat_freebsd.o -LDLIBS-y += -lyajl +LDLIBS-y += $(XEN_JSON_LIBS) LDLIBS-$(CONFIG_SunOS) += -lkstat LDLIBS += $(LDLIBS-y)
tools/libs/stat/xenstat_qmp.c +119 -7
195 lines not on this page · raw message
Signature · 1 line
Anthony PERARD
Re: [XEN PATCH v2 6/8] tools/libxenstat: Use json-c when available
Quoted 18 lines · Anthony PERARD
tools/libs/stat/xenstat_qmp.c +8
-1@@ -88,13 +95,56 @@ static char *qmp_get_block_image(xenstat_node *node, char *qmp_devname, int qfd) };const char *ptr[] = {0 ,0 };unsigned char *qmp_stats; -yajl_val info, ret_obj, dev_obj, n;int i;if ((qmp_stats =qmp_query (qfd, query_block_cmd)) ==NULL )return NULL ; +#ifdef HAVE_LIBJSONC +json_object *jso; +enum json_tokener_error error; + jso =json_tokener_parse_verbose ((const char *)qmp_stats, &error); +free (qmp_stats); +if (jso ==NULL ) +return NULL ; +
tools/libs/stat/xenstat_qmp.c static char *qmp_get_block_image(xenstat_node *node, char *qmp_devname, int qfd) · line 120
Quoted 10 lines
tools/libs/stat/xenstat_qmp.c +10
-0+ ptr[0 ] = qblock[QMP_BLOCK_RETURN ];/* "return" */ +json_object *ret_jso =json_object_object_get (jso, ptr[0 ]); +if (ret_jso ==NULL ) + goto done; + +for (i=0 ; i<json_object_array_length (ret_jso); i++) { +json_object *n =json_object_array_get_idx (ret_jso, i); + + ptr[0 ] = qblock[QMP_BLOCK_DEVICE ];/* "device" */ +json_object *dev_jso =json_object_object_get (n, ptr[0 ]);
This causes the build to fail for me when building with version 0.12.1 of the library. The function is marked deprecated there, suggesting to use json_object_object_get_ex() instead. The deprecation was undone in May 2016, so we may need to cope with the deprecation (or avoid using the library in that case).
Jan
PATCH v2 7/8 configure: Use json-c by default, fallback to yajl
In reply to Anthony PERARDFrom: Anthony PERARD <[email protected]>
--- tools/configure | 97 +++++++++++++++++++++++++++++----------------- tools/configure.ac | 12 +++--- 2 files changed, 69 insertions(+), 40 deletions(-)
tools/configure +62 -35
@@ -9692,41 +9692,7 @@ 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 = 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. Make 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 <http://pkg-config.freedesktop.org/>. -See \`config.log' for more details" "$LINENO" 5; } -else - libjsonc_CFLAGS=$pkg_cv_libjsonc_CFLAGS - libjsonc_LIBS=$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 + +elif test $pkg_failed = 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=$LIBS +LIBS="-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=yes +else $as_nop + ac_cv_lib_yajl_yajl_alloc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$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" = xyes +then : + YAJL_LIBS=-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=$pkg_cv_libjsonc_CFLAGS + libjsonc_LIBS=$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}
tools/configure.ac +7 -5
@@ -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' library (-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="-largp"])
Signature · 1 line
Anthony PERARD
Re: [XEN PATCH v2 7/8] configure: Use json-c by default, fallback to yajl
Quoted 3 lines · Anthony PERARD
From: Anthony PERARD <[email protected]>
Signed-off-by Anthony PERARD <[email protected]>
Re: [XEN PATCH v2 7/8] configure: Use json-c by default, fallback to yajl
In reply to Anthony PERARDQuoted 3 lines · Anthony PERARD
From: Anthony PERARD <[email protected]>
Signed-off-by Anthony PERARD <[email protected]>
Thanks,
Jason
PATCH v2 8/8 Update CHANGELOG and README with dependency on json-c
In reply to Anthony PERARDFrom: Anthony PERARD <[email protected]>
--- CHANGELOG.md | 2 ++ README | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
CHANGELOG.md +2 -0
@@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.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. - On x86: - Restrict the cache flushing done as a result of guest physical memory map
README +1 -1
@@ -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. libyajl-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)
Signature · 1 line
Anthony PERARD
Re: [XEN PATCH v2 8/8] Update CHANGELOG and README with dependency on json-c
Quoted 4 lines · Anthony PERARD
From: Anthony PERARD <[email protected]>
Signed-off-by Anthony PERARD <[email protected]>Acked-by Oleksii Kurochko <[email protected]>
Thankyou for doing this. v2 looks much cleaner.
Quoted 10 lines · Anthony PERARD
From: Anthony PERARD<[email protected]>
Patch series available in this git branch:
https://xenbits.xenproject.org/git-http/people/aperard/xen-unstable.git br.libxl-libjsonc-v2changes in v2:
- introduce $(XEN_JSON_LIBS) to have either -lyajl or -ljson-c or both (for a short while).
- few more changes detail in each patches.
Quoted 8 lines
Hi,
The library YAJL has been unmaintained for several years, without an obvious fork to pick.
On the other and the library json-c is been maintained and use by several other project, it's probably already installed on your machine. So this patch series intend to allow to build the Xen toolstack again json-c, and forgo yajl.
Do we have any plans to drop fallback to yajl in the next release? Or because of this ...
Quoted 7 lines
Just in case, YAJL is can still be used.
There's bit of libxl API that exposes YAJL, mainly so it can be used by
xlto calllibxl_domain_config_gen_json(). It was exposed via the "libxl_json.h" headers. This functions and others won't be available when libxl is build against json-c.
... that some API trying to use API exposed by YAJL we just can't drop support of yajl?
~ Oleksii
Quoted 36 lines
Cheers,
Anthony PERARD (8):
tools/configure: Introduce deps on json-c lib for libxl
libxl: Convertlibxl__json_parse()to use json-c
libxl: convertlibxl__json_object_to_yajl_gento
libxl__json_object_to_libjsonc_object
libxl:libxl__object_to_json()to json-c
libxl: convertlibxl__json_object_to_json()tojson_objecttools/libxenstat: Use json-c when available
configure: Use json-c by default, fallback to yajl Update CHANGELOG and README with dependency on json-cCHANGELOG.md | 2 + README | 2 +- config/Tools.mk.in | 1 + tools/config.h.in | 3 + tools/configure | 136 +++++- tools/configure.ac | 10 +- tools/include/libxl_json.h | 27 ++ tools/libs/light/Makefile | 6 +- 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 | 23 +- tools/libs/light/libxl_json.c | 562 +++++++++++++++++++++- tools/libs/light/libxl_qmp.c | 53 ++ tools/libs/light/libxl_types.idl | 7 +- tools/libs/light/libxl_types_internal.idl | 3 +- tools/libs/stat/Makefile | 2 +- tools/libs/stat/xenstat_qmp.c | 126 ++++- tools/xl/Makefile | 2 +- tools/xl/xl_info.c | 102 +++- 20 files changed, 1312 insertions(+), 41 deletions(-)
Quoted 11 lines · Oleksii Kurochko
Quoted 6 lines · Anthony PERARD
The library YAJL has been unmaintained for several years, without an obvious fork to pick.
On the other and the library json-c is been maintained and use by several other project, it's probably already installed on your machine. So this patch series intend to allow to build the Xen toolstack again json-c, and forgo yajl.
Do we have any plans to drop fallback to yajl in the next release? Or because of this ...
Do we need a plan? We still have to support ancient version of several dependencies, and json-c is a fairly recent project. In any case, usage of yajl is quite contained, so I don't think it's a problem to let it rot, and remove it when it get broken for long enough, but that's unlikely to happen.
Quoted 10 lines
Quoted 7 lines
Just in case, YAJL is can still be used.
There's bit of libxl API that exposes YAJL, mainly so it can be used by
xlto calllibxl_domain_config_gen_json(). It was exposed via the "libxl_json.h" headers. This functions and others won't be available when libxl is build against json-c.... that some API trying to use API exposed by YAJL we just can't drop support of yajl?
Well, I'm hopping those API are only used by xl and nothing else. And to be fair, I've seen few project dropping support for YAJL and use json-c instead (libvirt, to name one), so they can't use those API.
Cheers,
Signature · 1 line
Anthony PERARD