Introduce a QMP client
v5 cover Introduce a QMP client
New:
- Add a separate patch for XEN_RUN_DIR path.
- Add a new patch to generate an some internal type with gentypes.py. It's
used only to have a ENUM <-> String convertion with the QMP client.
- libxl_qmp.h content have been moved to libxl_internal.h
- return value of every single alloc are now check
- introduce some DEBUG_GEN_* macro to avoid some #ifdefs
- remove unused exported function: libxL__qmp_next libxl__qmp_send_command
- introduce libxl__qmp_query_serial and store all serial port chardev in xenstore.
- introduce json_object_{get,is}_* inline functions.
- coding style fixed
Change v3->v4:
- In case of a timeout, there is no more infinit loop
- include select bit in the qmp_next function, to avoid have it twice in the code.
- introduce libxl__qmp_cleanup to remove the socket file. It's called from libxl_domain_destroy when a dm is present.
- libxl__qmp_get_fd is removed as is not yet used.
- qmp_connect renamed to qmp_open
- I'm not skip anymore the CRLF a the end of a command. So there will always be another turn in the loop to eat them.
- fix coding style issue related to struct definitions.
- the receive buffer is now include in the qmp_handler struct to avoid an extra alloc.
- in struct json_object, rename floating to fp.
- introduce yajl_gen_asciiz that take a string nul-terminated and give it to yajl_gen_string.
- use "-chardev ... -mon ..." qemu option instead of -qmp "..."
Change v2->v3:
- Use of a timeout when wait for a reply from the server.
- Use of a command list, a list of pair "command" + callback. It's associated with an enum.
- Introduce libxl__qmp_initializations that will ask of all informations need through QMP. (It's just a rename of libxl__qmp_get_serial_console_path from the previous patch.)
Change v1->v2:
- Introduction of libxl_run_dir_path(), should maybe be in another patch.
- Add a new static function qmp_synchronous_send that wait the answer from the server.
- QMP is know use only inside libxl, so only one command is send through the socket and after, the connection is closed.
Anthony PERARD (3):
Introduce XEN_RUN_DIR path.
libxl: Introduce libxl_internal_types.idl.
libxl, Introduce a QMP client
Config.mk | 1 + config/StdGNU.mk | 2 + tools/libxl/Makefile | 14 +- tools/libxl/gentypes.py | 15 +- tools/libxl/libxl.c | 2 + tools/libxl/libxl.h | 1 + tools/libxl/libxl_create.c | 3 + tools/libxl/libxl_dm.c | 9 + tools/libxl/libxl_internal.h | 19 + tools/libxl/libxl_internal_types.idl | 10 + tools/libxl/libxl_paths.c | 5 + tools/libxl/libxl_qmp.c | 1116 ++++++++++++++++++++++++++++++++++ 12 files changed, 1189 insertions(+), 8 deletions(-) create mode 100644 tools/libxl/libxl_internal_types.idl create mode 100644 tools/libxl/libxl_qmp.c
Signature · 1 line
1.7.2.5
PATCH v5 1/3 Introduce XEN_RUN_DIR path.
This patch also add libxl_run_dir_path() function in libxl.
--- Config.mk | 1 + config/StdGNU.mk | 2 ++ tools/libxl/Makefile | 1 + tools/libxl/libxl.h | 1 + tools/libxl/libxl_paths.c | 5 +++++ 5 files changed, 10 insertions(+), 0 deletions(-)
Config.mk +1 -0
@@ -133,6 +133,7 @@ define buildmakevars2file-closure echo "XEN_CONFIG_DIR=\"$(XEN_CONFIG_DIR)\"" >> $(1).tmp; \ echo "XEN_SCRIPT_DIR=\"$(XEN_SCRIPT_DIR)\"" >> $(1).tmp; \ echo "XEN_LOCK_DIR=\"$(XEN_LOCK_DIR)\"" >> $(1).tmp; \ + echo "XEN_RUN_DIR=\"$(XEN_RUN_DIR)\"" >> $(1).tmp; \ if ! cmp $(1).tmp $(1); then mv -f $(1).tmp $(1); fi endef
config/StdGNU.mk +2 -0
@@ -52,9 +52,11 @@ PRIVATE_BINDIR = $(PRIVATE_PREFIX)/bin ifeq ($(PREFIX),/usr) CONFIG_DIR = /etc XEN_LOCK_DIR = /var/lock +XEN_RUN_DIR = /var/run/xen else CONFIG_DIR = $(PREFIX)/etc XEN_LOCK_DIR = $(PREFIX)/var/lock +XEN_RUN_DIR = $(PREFIX)/var/run/xen endif SYSCONFIG_DIR = $(CONFIG_DIR)/$(CONFIG_LEAF_DIR)
tools/libxl/Makefile +1 -0
@@ -123,6 +123,7 @@ install: all $(INSTALL_DIR) $(DESTDIR)$(LIBDIR) $(INSTALL_DIR) $(DESTDIR)$(INCLUDEDIR) $(INSTALL_DIR) $(DESTDIR)$(BASH_COMPLETION_DIR) + $(INSTALL_DIR) $(DESTDIR)$(XEN_RUN_DIR) $(INSTALL_PROG) xl $(DESTDIR)$(SBINDIR) $(INSTALL_PROG) libxenlight.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR) ln -sf libxenlight.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libxenlight.so.$(MAJOR)
tools/libxl/libxl.h +1 -0
@@ -529,6 +529,7 @@ const char *libxl_xenfirmwaredir_path(void);const char *libxl_xen_config_dir_path (void );const char *libxl_xen_script_dir_path (void );const char *libxl_lock_dir_path (void ); +const char *libxl_run_dir_path (void );#endif /* LIBXL_H */
tools/libxl/libxl_paths.c +5 -0
@@ -64,3 +64,8 @@ const char *libxl_lock_dir_path(void) {return XEN_LOCK_DIR ; } + +const char *libxl_run_dir_path (void ) +{ +return XEN_RUN_DIR ; +}
Signature · 1 line
1.7.2.5
Re: [PATCH V5 1/3] Introduce XEN_RUN_DIR path.
Anthony PERARD writes ("[Xen-devel] [PATCH V5 1/3] Introduce XEN_RUN_DIR path."):
Quoted 1 line
This patch also add
libxl_run_dir_path()function in libxl.
PATCH v5 2/3 libxl: Introduce libxl_internal_types.idl.
In reply to Anthony PERARD--- tools/libxl/Makefile | 10 +++++++++- tools/libxl/gentypes.py | 15 ++++++++------- tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_internal_types.idl | 10 ++++++++++ 4 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 tools/libxl/libxl_internal_types.idl
tools/libxl/Makefile +9 -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_internal_types.o $(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl)
@@ -79,14 +79,22 @@ _libxl_paths.h: genpath libxl_paths.c: _libxl_paths.h libxl.h: _libxl_types.h +libxl_internal.h: _libxl_internal_types.h $(LIBXL_OBJS) $(LIBXLU_OBJS) $(XL_OBJS): libxl.h +$(LIBXL_OBJS): libxl_internal.h _libxl_%.h _libxl_%.c: libxl.idl gen%.py libxl%.py $(PYTHON) gen$*.py libxl.idl __libxl_$*.h __libxl_$*.c mv __libxl_$*.h _libxl_$*.h mv __libxl_$*.c _libxl_$*.c +.NOTPARALLEL: _libxl_internal_types.h _libxl_internal_types.c +_libxl_internal_types.h _libxl_internal_types.c: libxl_internal_types.idl gentypes.py libxltypes.py + $(PYTHON) gentypes.py $< __libxl_internal_types.h __libxl_internal_types.c + mv __libxl_internal_types.h _libxl_internal_types.h + mv __libxl_internal_types.c _libxl_internal_types.c + libxenlight.so: libxenlight.so.$(MAJOR) ln -sf $< $@
tools/libxl/gentypes.py +8 -7
@@ -162,9 +162,10 @@ if __name__ == '__main__': print "outputting libxl type definitions to %s" % header 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.
@@ -172,9 +173,9 @@ if __name__ == '__main__': * This file is autogenerated by * "%s" */ - -""" % " ".join(sys.argv)) - + +""" % (header_define, header_define, " ".join(sys.argv))) + for ty in types: f.write(libxl_C_type_define(ty) + ";\n") if ty.destructor_fn is not None:
@@ -185,7 +186,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() impl = sys.argv[3]
tools/libxl/libxl_internal.h +1 -0
@@ -35,6 +35,7 @@#include "flexarray.h" #include "libxl_utils.h" +#include "_libxl_internal_types.h" #define LIBXL_DESTROY_TIMEOUT 10#define LIBXL_DEVICE_MODEL_START_TIMEOUT 10
tools/libxl/libxl_internal_types.idl new file +10 -0
@@ -0,0 +1,10 @@ + +libxl__qmp_message_type = Enumeration("qmp_message_type", [ + (1, "QMP"), + (2, "return"), + (3, "error"), + (4, "event"), + (5, "invalid"), + ], + namespace = "libxl__") +
Signature · 1 line
1.7.2.5
Re: [PATCH V5 2/3] libxl: Introduce libxl_internal_types.idl.
Quoted 6 lines · Anthony PERARD
Signed-off-by Anthony PERARD <[email protected]>--- tools/libxl/Makefile | 10 +++++++++- tools/libxl/gentypes.py | 15 ++++++++------- tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_internal_types.idl | 10 ++++++++++
Do you not need to update .hgignore?
Quoted 17 lines
4 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 tools/libxl/libxl_internal_types.idltools/libxl/Makefile +1
-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_internal_types.o $(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl)
tools/libxl/Makefile _libxl_paths.h: genpath · line 88
Quoted 10 lines
tools/libxl/Makefile +2
-0@@ -79,14 +79,22 @@ _libxl_paths.h: genpath libxl_paths.c: _libxl_paths.h libxl.h: _libxl_types.h +libxl_internal.h: _libxl_internal_types.h $(LIBXL_OBJS) $(LIBXLU_OBJS) $(XL_OBJS): libxl.h +$(LIBXL_OBJS): libxl_internal.h _libxl_%.h _libxl_%.c: libxl.idl gen%.py libxl%.py $(PYTHON) gen$*.py libxl.idl __libxl_$*.h __libxl_$*.c
If you simply s/gen$*.py/gentypes.py/ and s/libxl.idl/libxl$*.idl/g and leave the other patterns does this rule work for both IDL files?
tools/libxl/Makefile _libxl_paths.h: genpath · line 92
Quoted 4 lines
tools/libxl/Makefile +1
-0mv __libxl_$*.h _libxl_$*.h mv __libxl_$*.c _libxl_$*.c +.NOTPARALLEL: _libxl_internal_types.h _libxl_internal_types.c
I'd been wondering how to do that!
Quoted 76 lines
tools/libxl/Makefile +5
-0+_libxl_internal_types.h _libxl_internal_types.c: libxl_internal_types.idl gentypes.py libxltypes.py + $(PYTHON) gentypes.py $< __libxl_internal_types.h __libxl_internal_types.c + mv __libxl_internal_types.h _libxl_internal_types.h + mv __libxl_internal_types.c _libxl_internal_types.c + libxenlight.so: libxenlight.so.$(MAJOR) ln -sf $< $@tools/libxl/gentypes.py +8
-7@@ -162,9 +162,10 @@ if __name__ == '__main__': print "outputting libxl type definitions to %s" % header 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.@@ -172,9 +173,9 @@ if __name__ == '__main__': * This file is autogenerated by * "%s" */ - -""" % " ".join(sys.argv)) - + +""" % (header_define, header_define, " ".join(sys.argv))) + for ty in types: f.write(libxl_C_type_define(ty) + ";\n") if ty.destructor_fn is not None:@@ -185,7 +186,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() impl = sys.argv[3]tools/libxl/libxl_internal.h +1
-0@@ -35,6 +35,7 @@#include "flexarray.h" #include "libxl_utils.h" +#include "_libxl_internal_types.h" #define LIBXL_DESTROY_TIMEOUT 10#define LIBXL_DEVICE_MODEL_START_TIMEOUT 10tools/libxl/libxl_internal_types.idl new file +10
-0@@ -0,0 +1,10 @@ + +libxl__qmp_message_type = Enumeration("qmp_message_type", [ + (1, "QMP"), + (2, "return"), + (3, "error"), + (4, "event"), + (5, "invalid"), + ], + namespace = "libxl__") +
Re: Re: [PATCH V5 2/3] libxl: Introduce libxl_internal_types.idl.
Quoted 9 lines · Ian Campbell
Quoted 6 lines · Anthony PERARD
Signed-off-by Anthony PERARD <[email protected]>---
tools/libxl/Makefile | 10 +++++++++-tools/libxl/gentypes.py| 15 ++++++++-------tools/libxl/libxl_internal.h| 1 +tools/libxl/libxl_internal_types.idl| 10 ++++++++++Do you not need to update .hgignore?
I don't use mercurial! :)
But no, the file generated will be catch by:
^tools/libxl/_.*\.h$
Quoted 22 lines
Quoted 22 lines
4 files changed, 28 insertions(+), 8 deletions(-)create mode 100644
tools/libxl/libxl_internal_types.idltools/libxl/Makefile +1
-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_internal_types.o $(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl)@@ -79,14 +79,22 @@ _libxl_paths.h: genpathlibxl_paths.c:
_libxl_paths.hlibxl.h:
_libxl_types.h+libxl_internal.h:_libxl_internal_types.h
Quoted 8 lines
Quoted 5 lines
$(LIBXL_OBJS) $(LIBXLU_OBJS) $(XL_OBJS):
libxl.h
+$(LIBXL_OBJS):libxl_internal.h_libxl_%.h _libxl_%.c: libxl.idl gen%.py libxl%.py $(PYTHON) gen$*.py libxl.idl __libxl_$*.h __libxl_$*.c
If you simply s/gen$*.py/gentypes.py/ and s/libxl.idl/libxl$*.idl/g and leave the other patterns does this rule work for both IDL files?
Yes, it's works, with a mv libxl.idl libxl_types.idl. I thought this rules was used by something else.
Quoted 6 lines
Quoted 4 lines
mv __libxl_$*.h _libxl_$*.h
mv __libxl_$*.c _libxl_$*.c+.NOTPARALLEL:
_libxl_internal_types.h_libxl_internal_types.cI'd been wondering how to do that!
Better than a -j1, first time I use it but seams to work fine.
Signature · 1 line
Anthony PERARD
Re: Re: [PATCH V5 2/3] libxl: Introduce libxl_internal_types.idl.
Quoted 40 lines · Anthony PERARD
Quoted 9 lines · Ian Campbell
Quoted 6 lines · Anthony PERARD
Signed-off-by Anthony PERARD <[email protected]>--- tools/libxl/Makefile | 10 +++++++++- tools/libxl/gentypes.py | 15 ++++++++------- tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_internal_types.idl | 10 ++++++++++Do you not need to update .hgignore?
I don't use mercurial! :)
But no, the file generated will be catch by:
^tools/libxl/_.*\.h$Quoted 25 lines
Quoted 25 lines
4 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 tools/libxl/libxl_internal_types.idltools/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_internal_types.o $(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl)@@ -79,14 +79,22 @@ _libxl_paths.h: genpath libxl_paths.c: _libxl_paths.h libxl.h: _libxl_types.h +libxl_internal.h: _libxl_internal_types.h $(LIBXL_OBJS) $(LIBXLU_OBJS) $(XL_OBJS): libxl.h +$(LIBXL_OBJS): libxl_internal.h
Quoted 7 lines
Quoted 5 lines
tools/libxl/Makefile _libxl_paths.h: genpath · line 88
Quoted 2 lines
tools/libxl/Makefile +0
-0_libxl_%.h _libxl_%.c: libxl.idl gen%.py libxl%.py $(PYTHON) gen$*.py libxl.idl __libxl_$*.h __libxl_$*.cIf you simply s/gen$*.py/gentypes.py/ and s/libxl.idl/libxl$*.idl/g and leave the other patterns does this rule work for both IDL files?
Yes, it's works, with a
mv libxl.idl libxl_types.idl.
Can you incorporate the _types into the rule itself or does make not allow for % to match zero-characters?
Quoted 1 line
I thought this rules was used by something else.
No it's just used once. The reason it is currently a pattern rule is to work around make which will run a rule with multiple targets multiple times _unless_ it is a pattern rule. e.g.
A B: C
DO SOMETHING
will "DO SOMETHING" twice, rather than once.
Using a pattern rule is something of a hack. Another option might be to artificially split the multi pattern rule, e.g. do something like
_libxl_xxx.c: _libxl_xxx.h _libxl_xxx.h: libxl.idl etc etc genwrap.py ... etc etc mv ...
At first I thought the better way was your use of .NOTPARALLEL but actually it is probably still running the rule multiple times for no reason and you have just worked around the problem with multiple parallel invocations of the mv's.
Quoted 10 lines
Quoted 7 lines
tools/libxl/Makefile _libxl_paths.h: genpath · line 92
Quoted 5 lines
tools/libxl/Makefile +1
-0mv __libxl_$*.h _libxl_$*.h mv __libxl_$*.c _libxl_$*.c +.NOTPARALLEL: _libxl_internal_types.h _libxl_internal_types.cI'd been wondering how to do that!
Better than a -j1, first time I use it but seams to work fine.
Re: Re: [PATCH V5 2/3] libxl: Introduce libxl_internal_types.idl.
Ian Campbell writes ("Re: [Xen-devel] Re: [PATCH V5 2/3] libxl: Introduce libxl_internal_types.idl."):
Quoted 7 lines
Using a pattern rule is something of a hack. Another option might be to artificially split the multi pattern rule, e.g. do something like
_libxl_xxx.c: _libxl_xxx.h _libxl_xxx.h: libxl.idl etc etc genwrap.py ... etc etc mv ...
This is the conventional way of solving this problem.
Quoted 4 lines
At first I thought the better way was your use of .NOTPARALLEL but actually it is probably still running the rule multiple times for no reason and you have just worked around the problem with multiple parallel invocations of the mv's.
Yes, very likely.
Ian.
Re: Re: [PATCH V5 2/3] libxl: Introduce libxl_internal_types.idl.
In reply to Ian CampbellQuoted 11 lines · Ian Campbell
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
_libxl_%.h _libxl_%.c: libxl.idl gen%.py libxl%.py $(PYTHON) gen$*.py libxl.idl __libxl_$*.h __libxl_$*.c
If you simply s/gen$*.py/gentypes.py/ and s/libxl.idl/libxl$*.idl/g and leave the other patterns does this rule work for both IDL files?
Yes, it's works, with a
mv libxl.idl libxl_types.idl.Can you incorporate the
_typesinto the rule itself or does make not allow for % to match zero-characters?
I tried, but make did not "see" the rules. So % need to be at least one characters. I could incorporate just '_type', so we will know that the rule is for types.
Signature · 1 line
Anthony PERARD
PATCH v5 3/3 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 serial0 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-$(domid).
--- tools/libxl/Makefile | 3 + tools/libxl/libxl.c | 2 + tools/libxl/libxl_create.c | 3 + tools/libxl/libxl_dm.c | 9 + tools/libxl/libxl_internal.h | 18 + tools/libxl/libxl_qmp.c | 1116 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 1151 insertions(+), 0 deletions(-) create mode 100644 tools/libxl/libxl_qmp.c
tools/libxl/Makefile +3 -0
@@ -32,6 +32,9 @@ endif LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o LIBXL_OBJS-$(CONFIG_IA64) += libxl_nocpuid.o +LIBXL_OBJS-y += libxl_qmp.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)
tools/libxl/libxl.c +2 -0
@@ -757,6 +757,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 +3 -0
@@ -522,6 +522,9 @@ 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 +9 -0
@@ -249,6 +249,15 @@ 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-%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 +18 -0
@@ -379,4 +379,22 @@ _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); +#endif
tools/libxl/libxl_qmp.c new file +1116 -0
1,116 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Re: [PATCH V5 3/3] libxl, Introduce a QMP client
Anthony PERARD writes ("[Xen-devel] [PATCH V5 3/3] libxl, Introduce a QMP client"):
Quoted 6 lines
QMP 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 serial0 in xenstored. So we will be able to use xl console with QEMU upstream.
Can I make a suggestion ? I think the formulaic json parser stuff could usefully live in a separate file.
Quoted 1 line
+static inline
yajl_gen_statusyajl_gen_asciiz(yajl_gen hand, const
char *str)
Isn't this a hostage to fortune ? yajl may grow an identically-named function in which case this will no longer build.
tools/libxl/libxl_qmp.c line 840
Quoted 4 lines
tools/libxl/libxl_qmp.c new file +4
-0+#ifdef DEBUG_ANSWER +if (qmp->g) +yajl_gen_free (qmp->g); +#endif
Can this #ifdef not be shuffled off somewhere ? Ie, make a debug function (or macro) which we call unconditionally.
The rest looks plausible.
Ian.
Re: [PATCH V5 3/3] libxl, Introduce a QMP client
Quoted 10 lines · Ian Jackson
Anthony PERARD writes ("[Xen-devel] [PATCH V5 3/3] libxl, Introduce a QMP client"):
Quoted 6 lines
QMP 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 serial0 in xenstored. So we will be able to use xl console with QEMU upstream.
Can I make a suggestion ? I think the formulaic json parser stuff could usefully live in a separate file.
Ok, I will cut the file.
Quoted 5 lines
Quoted 1 line
+static inline
yajl_gen_statusyajl_gen_asciiz(yajl_gen hand, constchar *str)
Isn't this a hostage to fortune ? yajl may grow an identically-named function in which case this will no longer build.
Maybe. I will rename to libxl__yajl_gen_asciiz.
Quoted 7 lines
tools/libxl/libxl_qmp.c line 840
Quoted 4 lines
tools/libxl/libxl_qmp.c new file +4
-0+#ifdef DEBUG_ANSWER + if (qmp->g) + yajl_gen_free(qmp->g); +#endif Can this #ifdef not be shuffled off somewhere ? Ie, make a debug function (or macro) which we call unconditionally.
Ok, I will remove all the #ifdef debug_answer.
Quoted 1 line
The rest looks plausible.
Thanks for the review,
Signature · 1 line
Anthony PERARD
Re: [PATCH V5 3/3] libxl, Introduce a QMP client
Quoted 5 lines · Anthony PERARD
Quoted 4 lines · Ian Jackson
Anthony PERARD writes ("[Xen-devel] [PATCH V5 3/3] libxl, Introduce a QMP client"):
Quoted 3 lines
QMP stands for QEMU Monitor Protocol and it is used to query information from QEMU or to control QEMU.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
This implementation will ask QEMU the list of chardevice and store the path to serial0 in xenstored. So we will be able to use xl console with QEMU upstream.
Can I make a suggestion ? I think the formulaic json parser stuff could usefully live in a separate file.
Ok, I will cut the file.
FWIW my "libxl: IDL: autogenerate functions to produce JSON from libxl data structures" patch added libxl_json.c. If you want to add that file with the bits you need I will rebase onto it (since I need to rework at least this last patch of my series anyway, see below).
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
+static inline
yajl_gen_statusyajl_gen_asciiz(yajl_gen hand, constchar *str)
Isn't this a hostage to fortune ? yajl may grow an identically-named function in which case this will no longer build.
Maybe. I will rename to
libxl__yajl_gen_asciiz.
Good idea. My patch also added yajl_gen_asciiz. I shall defer to the version which you will have added when I rebase.
Quoted 9 lines
Quoted 7 lines
tools/libxl/libxl_qmp.c line 840
Quoted 4 lines
tools/libxl/libxl_qmp.c new file +4
-0+#ifdef DEBUG_ANSWER +if (qmp->g) +yajl_gen_free (qmp->g); +#endif Can this #ifdef not be shuffled off somewhere ? Ie, make a debug function (or macro) which we call unconditionally.
Ok, I will remove all the #ifdef
debug_answer.
I think Ian was only suggesting to remove the ifdef's from the main flow of code and you've done that for most of the uses with your DEBUG_GEN* but here perhaps you could also define and call functions which are empty in the non-debug case. e.g. DEBUG_GEN_START, DEBUG_GEN_END, DEBUG_GEN_REPORT?
BTW I noticed:
+#ifdef DEBUG_RECEIVED
+ qmp->buffer[rd] = 0;
+ LIBXL__LOG(qmp->ctx, LIBXL__LOG_DEBUG, "received: '%s'", qmp->buffer);
+#endif
I wondered if the zero termination of the string should be there even in the non-debug case? Also is there a buffer overrun (when rd==QMP_RECEIVE_BUFFER_SIZE)?
If its the latter you could perhaps use
printf("%*s", rd, qmp->buf);?
Having done that then:
#define DEBUG_RECEIVED(qmp) LIBXL__LOG(qmp->ctx, LIBXL__LOG_DEBUG...)
Would remove this ifdef from the codeflow too...
Quoted 4 lines
Quoted 1 line
The rest looks plausible.
Thanks for the review,
Re: [PATCH V5 3/3] libxl, Introduce a QMP client
Ian Campbell writes ("Re: [Xen-devel] [PATCH V5 3/3] libxl, Introduce a QMP client"):
Quoted 5 lines
I think Ian was only suggesting to remove the ifdef's from the main flow of code and you've done that for most of the uses with your DEBUG_GEN* but here perhaps you could also define and call functions which are empty in the non-debug case. e.g.
DEBUG_GEN_START,DEBUG_GEN_END,DEBUG_GEN_REPORT?
Quite so.
Thanks,
Ian.
Re: [PATCH V5 3/3] libxl, Introduce a QMP client
In reply to Ian CampbellQuoted 13 lines · Ian Campbell
Quoted 12 lines · Anthony PERARD
Quoted 10 lines · Ian Jackson
Anthony PERARD writes ("[Xen-devel] [PATCH V5 3/3] libxl, Introduce a QMP client"):
Quoted 6 lines
QMP 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 serial0 in xenstored. So we will be able to use xl console with QEMU upstream.
Can I make a suggestion ? I think the formulaic json parser stuff could usefully live in a separate file.
Quoted 6 lines
Quoted 1 line
Ok, I will cut the file.
FWIW my "libxl: IDL: autogenerate functions to produce JSON from libxl data structures" patch added
libxl_json.c. If you want to add that file with the bits you need I will rebase onto it (since I need to rework at least this last patch of my series anyway, see below).
I will look at this patch.
Quoted 19 lines
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
+static inline
yajl_gen_statusyajl_gen_asciiz(yajl_gen hand, constchar *str)
Isn't this a hostage to fortune ? yajl may grow an identically-named function in which case this will no longer build.
Maybe. I will rename to
libxl__yajl_gen_asciiz.Good idea. My patch also added
yajl_gen_asciiz. I shall defer to the version which you will have added when I rebase.Quoted 8 lines
Quoted 7 lines
tools/libxl/libxl_qmp.c line 840
Quoted 4 lines
tools/libxl/libxl_qmp.c new file +4
-0+#ifdef DEBUG_ANSWER + if (qmp->g) + yajl_gen_free(qmp->g); +#endif Can this #ifdef not be shuffled off somewhere ? Ie, make a debug function (or macro) which we call unconditionally.
Quoted 7 lines
Quoted 1 line
Ok, I will remove all the #ifdef
debug_answer.I think Ian was only suggesting to remove the ifdef's from the main flow of code and you've done that for most of the uses with your DEBUG_GEN* but here perhaps you could also define and call functions which are empty in the non-debug case. e.g.
DEBUG_GEN_START,DEBUG_GEN_END,DEBUG_GEN_REPORT?
Sorry, I should say replace by macros, instead of "remove". Is it fine to keep the #ifdef inside the struct or should I remove the #ifdef and keep "yajl_gen g" field even if it will not be used (in case DEBUG_ANSWER in undef) ?
Quoted 8 lines
BTW I noticed:
tools/libxl/libxl_qmp.c new file +4
-0+#ifdef DEBUG_RECEIVED + qmp->buffer[rd] = 0; + LIBXL__LOG(qmp->ctx, LIBXL__LOG_DEBUG, "received: '%s'", qmp->buffer); +#endif I wondered if the zero termination of the string should be there even in the non-debug case?
This should not be necessary as the read size (rd) is always used.
Quoted 6 lines
Also is there a buffer overrun (when
rd==QMP_RECEIVE_BUFFER_SIZE)?If its the latter you could perhaps use
printf("%*s", rd,qmp->buf);
?
This printf seams to work better with "%.*s". I will use that, so no more zero-terminited buffer and no more buffer overrun.
Quoted 3 lines
Having done that then:
#defineDEBUG_RECEIVED(qmp)LIBXL__LOG(qmp->ctx, LIBXL__LOG_DEBUG...)Would remove this ifdef from the codeflow too...
Thanks,
Signature · 1 line
Anthony PERARD