Introduce a QMP client
v8 cover Introduce a QMP client
New:
- Rename set_default_namespace() to namespace(), this is much easier to read in the .idl files.
- Make get_default_namespace and default_namespace "private" to libxltypes.py with a leading '_'.
- libxl__realloc should now behave like realloc.
- Use libxl__ prefix when required.
- Rename libxl__json_object_get to libxl__json_map_get.
- Introduce libxl__json_map_node_get and libxl__json_array_get.
- Put libxl__yajl_gen_asciiz in libxl_json
- Make qmp_next easier to read by handling errors right after calls of select and read.
Change v6-v7:
- New patch that add set_default_namespaces to libxltypes.py, so we can set a namespace to use for a specific .idl.
- New function: libxl__realloc and libxl__strndup.
- The data is now pulled until it's completed (with a CRLF). Now libxl__json_parse expect only a whole json object.
- Use of libxl__gc in sevreal place.
Anthony PERARD (7):
libxl: Rename libxl.idl to libxl_types.idl.
libxl: Add get/set_default_namespace in libxltypes.py.
libxl: Introduce libxl_internal_types.idl.
libxl: Introduce libxl__realloc.
libxl: Intruduce libxl__strndup.
libxl: Introduce JSON parsing stuff.
libxl: Introduce a QMP client
README | 1 +
tools/libxl/Makefile | 21 +-
tools/libxl/gentypes.py | 9 +-
tools/libxl/libxl.c | 2 +
tools/libxl/libxl_create.c | 4 +
tools/libxl/libxl_dm.c | 10 +
tools/libxl/libxl_internal.c | 34 ++
tools/libxl/libxl_internal.h | 122 ++++++
tools/libxl/libxl_json.c | 560 ++++++++++++++++++++++++++
tools/libxl/libxl_qmp.c | 587 ++++++++++++++++++++++++++++
tools/libxl/{libxl.idl => libxl_types.idl} | 2 +
tools/libxl/libxl_types_internal.idl | 9 +
tools/libxl/libxltypes.py | 18 +-
tools/ocaml/libs/xl/Makefile | 4 +-
tools/python/Makefile | 4 +-
15 files changed, 1369 insertions(+), 18 deletions(-)
create mode 100644 tools/libxl/libxl_json.c
create mode 100644 tools/libxl/libxl_qmp.c
rename tools/libxl/{libxl.idl => libxl_types.idl} (99%)
create mode 100644 tools/libxl/libxl_types_internal.idlSignature · 1 line
Anthony PERARD
PATCH v8 1/7 libxl: Rename libxl.idl to libxl_types.idl.
---
tools/libxl/Makefile | 12 ++++++------
tools/libxl/{libxl.idl => libxl_types.idl} | 0
tools/ocaml/libs/xl/Makefile | 4 ++--
tools/python/Makefile | 4 ++--
4 files changed, 10 insertions(+), 10 deletions(-)
rename tools/libxl/{libxl.idl => libxl_types.idl} (100%)tools/libxl/Makefile +6 -6
@@ -52,8 +52,8 @@ $(XL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h $(XL_OBJS): CFLAGS += $(CFLAGS_libxenlight) testidl.o: CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenlight) -testidl.c: libxl.idl gentest.py libxl.h - $(PYTHON) gentest.py libxl.idl testidl.c.new +testidl.c: libxl_types.idl gentest.py libxl.h + $(PYTHON) gentest.py libxl_types.idl testidl.c.new mv testidl.c.new testidl.c .PHONY: all
@@ -84,10 +84,10 @@ libxl.h: _libxl_types.h $(LIBXL_OBJS) $(LIBXLU_OBJS) $(XL_OBJS): libxl.h -_libxl_%.h _libxl_%.c: libxl.idl gen%.py libxl%.py - $(PYTHON) gen$*.py libxl.idl __libxl_$*.h __libxl_$*.c - $(call move-if-changed,__libxl_$*.h,_libxl_$*.h) - $(call move-if-changed,__libxl_$*.c,_libxl_$*.c) +_libxl_type%.h _libxl_type%.c: libxl_type%.idl gentypes.py libxltypes.py + $(PYTHON) gentypes.py libxl_type$*.idl __libxl_type$*.h __libxl_type$*.c + $(call move-if-changed,__libxl_type$*.h,_libxl_type$*.h) + $(call move-if-changed,__libxl_type$*.c,_libxl_type$*.c) libxenlight.so: libxenlight.so.$(MAJOR) ln -sf $< $@
tools/libxl/libxl_types.idl renamed from tools/libxl/libxl.idl +0 -0
tools/ocaml/libs/xl/Makefile +2 -2
@@ -45,10 +45,10 @@ xl.mli: xl.mli.in _libxl_types.mli.in < xl.mli.in > xl.mli.tmp $(Q)mv xl.mli.tmp xl.mli -_libxl_types.ml.in _libxl_types.mli.in _libxl_types.inc: genwrap.py $(XEN_ROOT)/tools/libxl/libxl.idl \ +_libxl_types.ml.in _libxl_types.mli.in _libxl_types.inc: genwrap.py $(XEN_ROOT)/tools/libxl/libxl_types.idl \ $(XEN_ROOT)/tools/libxl/libxltypes.py PYTHONPATH=$(XEN_ROOT)/tools/libxl $(PYTHON) genwrap.py \ - $(XEN_ROOT)/tools/libxl/libxl.idl \ + $(XEN_ROOT)/tools/libxl/libxl_types.idl \ _libxl_types.mli.in _libxl_types.ml.in _libxl_types.inc libs: $(LIBS)
tools/python/Makefile +2 -2
@@ -10,10 +10,10 @@ genpath-target = $(call buildmakevars2file,$(XENPATH)) $(eval $(genpath-target)) .PHONY: build -build: genpath genwrap.py $(XEN_ROOT)/tools/libxl/libxl.idl \ +build: genpath genwrap.py $(XEN_ROOT)/tools/libxl/libxl_types.idl \ $(XEN_ROOT)/tools/libxl/libxltypes.py PYTHONPATH=$(XEN_ROOT)/tools/libxl $(PYTHON) genwrap.py \ - $(XEN_ROOT)/tools/libxl/libxl.idl \ + $(XEN_ROOT)/tools/libxl/libxl_types.idl \ xen/lowlevel/xl/_pyxl_types.h \ xen/lowlevel/xl/_pyxl_types.c CC="$(CC)" CFLAGS="$(CFLAGS)" $(PYTHON) setup.py build
Signature · 1 line
Anthony PERARD
PATCH v8 2/7 libxl: Add get/set_default_namespace in libxltypes.py.
In reply to Anthony PERARD--- tools/libxl/libxl_types.idl | 2 ++ tools/libxl/libxltypes.py | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-)
tools/libxl/libxl_types.idl +2 -0
@@ -3,6 +3,8 @@ # Builtin libxl types # +namespace("libxl_") + libxl_domid = Builtin("domid") libxl_uuid = Builtin("uuid", passby=PASS_BY_REFERENCE) libxl_mac = Builtin("mac", passby=PASS_BY_REFERENCE)
tools/libxl/libxltypes.py +16 -2
@@ -8,10 +8,23 @@ DIR_IN = 1 DIR_OUT = 2 DIR_BOTH = 3 +_default_namespace = "" +def namespace(s): + if type(s) != str: + raise TypeError, "Require a string for the default namespace." + global _default_namespace + _default_namespace = s + +def _get_default_namespace(): + global _default_namespace + return _default_namespace + + class Type(object): def __init__(self, typename, **kwargs): self.comment = kwargs.setdefault('comment', None) - self.namespace = kwargs.setdefault('namespace', "libxl_") + self.namespace = kwargs.setdefault('namespace', + _get_default_namespace()) self.dir = kwargs.setdefault('dir', DIR_BOTH) if self.dir not in [DIR_NONE, DIR_IN, DIR_OUT, DIR_BOTH]: raise ValueError
@@ -256,7 +269,8 @@ def parse(f): elif isinstance(t,type(object)) and issubclass(t, Type): globs[n] = t elif n in ['PASS_BY_REFERENCE', 'PASS_BY_VALUE', - 'DIR_NONE', 'DIR_IN', 'DIR_OUT', 'DIR_BOTH']: + 'DIR_NONE', 'DIR_IN', 'DIR_OUT', 'DIR_BOTH', + 'namespace']: globs[n] = t try:
Signature · 1 line
Anthony PERARD
PATCH v8 3/7 libxl: Introduce libxl_internal_types.idl.
In reply to Anthony PERARD--- tools/libxl/Makefile | 4 +++- tools/libxl/gentypes.py | 9 +++++---- tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_types_internal.idl | 9 +++++++++ 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 tools/libxl/libxl_types_internal.idl
tools/libxl/Makefile +3 -1
@@ -35,7 +35,7 @@ LIBXL_OBJS-$(CONFIG_IA64) += libxl_nocpuid.o LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o \ libxl_internal.o libxl_utils.o libxl_uuid.o $(LIBXL_OBJS-y) -LIBXL_OBJS += _libxl_types.o libxl_flask.o +LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o $(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl)
@@ -81,8 +81,10 @@ _libxl_paths.h: genpath libxl_paths.c: _libxl_paths.h libxl.h: _libxl_types.h +libxl_internal.h: _libxl_types_internal.h $(LIBXL_OBJS) $(LIBXLU_OBJS) $(XL_OBJS): libxl.h +$(LIBXL_OBJS): libxl_internal.h _libxl_type%.h _libxl_type%.c: libxl_type%.idl gentypes.py libxltypes.py $(PYTHON) gentypes.py libxl_type$*.idl __libxl_type$*.h __libxl_type$*.c
tools/libxl/gentypes.py +5 -4
@@ -150,8 +150,9 @@ if __name__ == '__main__': f = open(header, "w") - f.write("""#ifndef __LIBXL_TYPES_H -#define __LIBXL_TYPES_H + header_define = header.upper().replace('.','_') + f.write("""#ifndef %s +#define %s /* * DO NOT EDIT.
@@ -160,7 +161,7 @@ if __name__ == '__main__': * "%s" */ -""" % " ".join(sys.argv)) +""" % (header_define, header_define, " ".join(sys.argv))) for ty in types: f.write(libxl_C_type_define(ty) + ";\n")
@@ -172,7 +173,7 @@ if __name__ == '__main__': f.write("extern libxl_enum_string_table %s_string_table[];\n" % (ty.typename)) f.write("\n") - f.write("""#endif /* __LIBXL_TYPES_H */\n""") + f.write("""#endif /* %s */\n""" % (header_define)) f.close() print "outputting libxl type implementations to %s" % impl
tools/libxl/libxl_internal.h +1 -0
@@ -35,6 +35,7 @@#include "flexarray.h" #include "libxl_utils.h" +#include "_libxl_types_internal.h" #define LIBXL_DESTROY_TIMEOUT 10#define LIBXL_DEVICE_MODEL_START_TIMEOUT 10
tools/libxl/libxl_types_internal.idl new file +9 -0
@@ -0,0 +1,9 @@ +namespace("libxl__") + +libxl__qmp_message_type = Enumeration("qmp_message_type", [ + (1, "QMP"), + (2, "return"), + (3, "error"), + (4, "event"), + (5, "invalid"), + ])
Signature · 1 line
Anthony PERARD
PATCH v8 4/7 libxl: Introduce libxl__realloc.
In reply to Anthony PERARD--- tools/libxl/libxl_internal.c | 24 ++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 1 + 2 files changed, 25 insertions(+), 0 deletions(-)
tools/libxl/libxl_internal.c +24 -0
@@ -102,6 +102,30 @@ void *libxl__calloc(libxl__gc *gc, size_t nmemb, size_t size)return ptr; } +void *libxl__realloc (libxl__gc *gc,void *ptr,size_t new_size) +{ +void *new_ptr =realloc (ptr, new_size); +int i =0 ; + +if (new_ptr ==NULL && new_size !=0 ) { +return NULL ; + } + +if (ptr ==NULL ) { +libxl__ptr_add (gc, new_ptr); + }else if (new_ptr != ptr) { +for (i =0 ; i < gc->alloc_maxsize; i++) { +if (gc->alloc_ptrs[i] == ptr) { + gc->alloc_ptrs[i] = new_ptr; +break ; + } + } + } + + +return new_ptr; +} +char *libxl__sprintf (libxl__gc *gc,const char *fmt, ...) {char *s;
tools/libxl/libxl_internal.h +1 -0
@@ -145,6 +145,7 @@ _hidden int libxl__ptr_add(libxl__gc *gc, void *ptr); _hidden void libxl__free_all(libxl__gc *gc); _hidden void *libxl__zalloc(libxl__gc *gc, int bytes); _hidden void *libxl__calloc(libxl__gc *gc, size_t nmemb, size_t size); +_hidden void *libxl__realloc(libxl__gc *gc, void *ptr, size_t new_size); _hidden char *libxl__sprintf(libxl__gc *gc, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3); _hidden char *libxl__strdup(libxl__gc *gc, const char *c); _hidden char *libxl__dirname(libxl__gc *gc, const char *s);
Signature · 1 line
Anthony PERARD
PATCH v8 5/7 libxl: Intruduce libxl__strndup.
In reply to Anthony PERARD--- tools/libxl/libxl_internal.c | 10 ++++++++++ tools/libxl/libxl_internal.h | 1 + 2 files changed, 11 insertions(+), 0 deletions(-)
tools/libxl/libxl_internal.c +10 -0
@@ -159,6 +159,16 @@ char *libxl__strdup(libxl__gc *gc, const char *c)return s; } +char *libxl__strndup (libxl__gc *gc,const char *c,size_t n) +{ +char *s =strndup (c, n); + +if (s) +libxl__ptr_add (gc, s); + +return s; +} +char *libxl__dirname (libxl__gc *gc,const char *s) {char *c;
tools/libxl/libxl_internal.h +1 -0
@@ -148,6 +148,7 @@ _hidden void *libxl__calloc(libxl__gc *gc, size_t nmemb, size_t size); _hidden void *libxl__realloc(libxl__gc *gc, void *ptr, size_t new_size); _hidden char *libxl__sprintf(libxl__gc *gc, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3); _hidden char *libxl__strdup(libxl__gc *gc, const char *c); +_hidden char *libxl__strndup(libxl__gc *gc, const char *c, size_t n); _hidden char *libxl__dirname(libxl__gc *gc, const char *s); _hidden char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int length);
Signature · 1 line
Anthony PERARD
PATCH v8 6/7 libxl: Introduce JSON parsing stuff.
In reply to Anthony PERARDWe use the yajl parser, but we need to make a tree from the parse result to use it outside the parser.
So this patch include json_object struct that is used to hold the JSON data.
--- README | 1 + tools/libxl/Makefile | 5 +- tools/libxl/libxl_internal.h | 100 ++++++++ tools/libxl/libxl_json.c | 560 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 665 insertions(+), 1 deletions(-) create mode 100644 tools/libxl/libxl_json.c
README +1 -0
@@ -47,6 +47,7 @@ provided by your OS distributor: * Development install of openssl (e.g., openssl-dev) * Development install of x11 (e.g. xorg-x11-dev) * Development install of uuid (e.g. uuid-dev) + * Development install of yajl (e.g. libyajl-dev) * bridge-utils package (/sbin/brctl) * iproute package (/sbin/ip) * hotplug or udev
tools/libxl/Makefile +4 -1
@@ -32,9 +32,12 @@ endif LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o LIBXL_OBJS-$(CONFIG_IA64) += libxl_nocpuid.o +LIBXL_LIBS += -lyajl + LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o \ - libxl_internal.o libxl_utils.o libxl_uuid.o $(LIBXL_OBJS-y) + libxl_internal.o libxl_utils.o libxl_uuid.o libxl_json.o \ + $(LIBXL_OBJS-y) LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o $(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl)
tools/libxl/libxl_internal.h +100 -0
104 lines not on this page · raw message
tools/libxl/libxl_json.c new file +560 -0
560 lines not on this page · raw message
Signature · 1 line
Anthony PERARD
PATCH v8 7/7 libxl: Introduce a QMP client
In reply to Anthony PERARDQMP stands for QEMU Monitor Protocol and it is used to query information from QEMU or to control QEMU.
This implementation will ask QEMU the list of chardevice and store the path to serial ports in xenstored. So we will be able to use xl console with QEMU upstream.
In order to connect to the QMP server, a socket file is created in /var/run/xen/qmp-libxl-$(domid).
--- tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 2 + tools/libxl/libxl_create.c | 4 + tools/libxl/libxl_dm.c | 10 + tools/libxl/libxl_internal.h | 19 ++ tools/libxl/libxl_qmp.c | 587 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 623 insertions(+), 1 deletions(-) create mode 100644 tools/libxl/libxl_qmp.c
tools/libxl/Makefile +1 -1
@@ -37,7 +37,7 @@ LIBXL_LIBS += -lyajl LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o \ libxl_internal.o libxl_utils.o libxl_uuid.o libxl_json.o \ - $(LIBXL_OBJS-y) + libxl_qmp.o $(LIBXL_OBJS-y) LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o $(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl)
tools/libxl/libxl.c +2 -0
@@ -762,6 +762,8 @@ int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid, int force)if (dm_present) {if (libxl__destroy_device_model (&gc, domid) <0 )LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"libxl__destroy_device_model failed for %d" , domid); + +libxl__qmp_cleanup (&gc, domid); }if (libxl__devices_destroy (&gc, domid, force) <0 )LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"libxl_destroy_devices failed for %d" , domid);
tools/libxl/libxl_create.c +4 -0
@@ -573,6 +573,10 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, }if (dm_starting) { +if (dm_info->device_model_version + ==LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN ) { +libxl__qmp_initializations (ctx, domid); + } ret =libxl__confirm_device_model_startup (gc, dm_starting);if (ret <0 ) { LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
tools/libxl/libxl_dm.c +10 -0
@@ -248,6 +248,16 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc,flexarray_vappend (dm_args, dm,"-xen-domid" ,libxl__sprintf (gc,"%d" , info->domid),NULL ); +flexarray_append (dm_args,"-chardev" ); +flexarray_append (dm_args, +libxl__sprintf (gc,"socket,id=libxl-cmd," +"path=%s/qmp-libxl-%d,server,nowait" , +libxl_run_dir_path (), + info->domid)); + +flexarray_append (dm_args,"-mon" ); +flexarray_append (dm_args,"chardev=libxl-cmd,mode=control" ); +if (info->type ==LIBXL_DOMAIN_TYPE_PV ) {flexarray_append (dm_args,"-xen-attach" ); }
tools/libxl/libxl_internal.h +19 -0
@@ -387,6 +387,25 @@ _hidden int libxl__e820_alloc(libxl_ctx *ctx, uint32_t domid, libxl_domain_confi#define STRINGIFY (x) #x#define TOSTRING (x) STRINGIFY(x) +/* from libxl_qmp */ +typedef struct libxl__qmp_handler libxl__qmp_handler ; + +/* Initialise and connect to the QMP socket. +* Return an handler or NULL if there is an error +*/ +_hidden libxl__qmp_handler *libxl__qmp_initialize(libxl_ctx *ctx, +uint32_t domid); +/* ask to QEMU the serial port information and store it in xenstore. */ +_hidden int libxl__qmp_query_serial(libxl__qmp_handler *qmp); +/* close and free the QMP handler */ +_hidden void libxl__qmp_close(libxl__qmp_handler *qmp); +/* remove the socket file, if the file has already been removed, +* nothing happen */ +_hidden void libxl__qmp_cleanup(libxl__gc *gc, uint32_t domid); + +/* this helper calls qmp_initialize, query_serial and qmp_close */ +_hidden int libxl__qmp_initializations(libxl_ctx *ctx, uint32_t domid); +/* from libxl_json */ #include <yajl/yajl_gen.h>
tools/libxl/libxl_qmp.c new file +587 -0
587 lines not on this page · raw message
Signature · 1 line
Anthony PERARD