QEMU Dbus support - a proposal management API
RFC 1/1 QEMU Dbus support - a proposal management API
Hello All,
Attached is a proposed patch which adds DBus support to QEMU. DBus is a standard message bus for linux (
http://www.freedesktop.org/wiki/Software/dbus )
The idea behind this is to allow for external programs such as controlling GUI or HyperVisors to communicate and control QEMU, in a standard manner. Although it is possible to connect to the monitor, an API is more standard, theres no need to parse texts and error messages, no internationalization problems and in general is a much better idea.
Implementation:
This is done by creating a DBus server from QEMU which raise signals and act upon methods.
Methods mainly implement same logic as the current command line options and monitor does.
How to use:
To enable DBus support you'll have to add --enable-dbus when you execure configure script.
Then when you execute QEMU, you'll have to add -dbus-service <service_name> where service_name follows the DBus naming convention ( xxx.xxx.xxx....) To support QEMU configuration through DBus, you'll also have to add -dbus_configuration which will cause QEMU to wait until ConfigDone is called through the DBus interface. this allows external programs time to call DBus methods starting with Config_ which changes configuration (just as the CLI does) thus enabling invocation of QEMU without parameters (beside the DBus ones).
With that, we have implemented a nice python script that reads VM's configuration from INI file.
To compile this you will also have to compile the attached freedesktop.orgdsrv library (it is also attach for those who can't handle GIT) from:git://people.freedesktop.org/~shaharf/dsrv
Features:
Currently support was added to all important CLI configuration and some online monitor functions (such as connecting and disconnecting usb devices).
configuration methods begins with Config_ prefix and monitor ones with Monitor_.
For a complete list you can just execute qemu and connect with dbus-viewer to see what is supported.
All the dbus handling routines can be found in dbus-monitor.c. I have two different implementations of this:
1) A single threaded version. which comply to the qemu standard of not opening additional threads.
2) A multi threaded version which open an additional, single, thread which handles all the DBus load. I actually believe this version is better as it allows QEMU to continue execution of guest operations even when there are DBus methods/signals to handle, whereas in the first option, DBus is integrated into QEMU mainloop. Also this makes it possible to monitor even during long operations (like monitoring the progress of savevm)
Please comment both on the idea of management API and the proposed implementation.
Attached are:
RFC-QEMU-Dbus.patch - patch file including all necessary changes to qemu. was made against QEMU HEAD as of 23/9 morning. RFC-QEMU-Dbus-Interface.xml - the xml description of the DBus interface that I suggest.
dsrv.tar.gz.txt - the dbus server library.
BR,
Yuval Kashtan,
Qumranet Development Team.
yuval/Dev/qemu-dbus/qemu/configure renamed from yuval/Dev/qemu-cvs/qemu/configure +17 -0
@@ -102,6 +102,8 @@ darwin_user="no" build_docs="no" uname_release="" +dbus="yes" +dbus_service="org.qemu" # OS specific targetos=`uname -s`
@@ -291,6 +293,12 @@ ;; --enable-uname-release=*) uname_release="$optarg" ;; + --disable-dbus) dbus="no" + ;; + --enable-dbus) dbus="yes" + ;; + --dbus-service=*) dbus_service="$optarg" + ;; --sparc_cpu=*) sparc_cpu="$optarg" case $sparc_cpu in
@@ -391,6 +399,9 @@ echo " --fmod-lib path to FMOD library" echo " --fmod-inc path to FMOD includes" echo " --enable-uname-release=R Return R for uname -r in usermode emulation" +echo " --enable-dbus enable DBus monitor service" +echo " --disable-dbus disable DBus monitor service" +echo " --dbus-service=service set the dbus service name" echo " --sparc_cpu=V Build qemu for Sparc architecture v7, v8, v8plus, v8plusa, v9" echo "" echo "NOTE: The object files are built at the place where configure is launched"
@@ -714,6 +725,7 @@ echo "Target Sparc Arch $sparc_cpu" fi echo "kqemu support $kqemu" +echo "DBUS support $dbus" echo "Documentation $build_docs" [ ! -z "$uname_release" ] && \ echo "uname -r $uname_release"
@@ -888,6 +900,11 @@ echo "CONFIG_VNC_TLS_LIBS=$vnc_tls_libs" >> $config_mak echo "#define CONFIG_VNC_TLS 1" >> $config_h fi +if test "$dbus" = "yes" ; then + echo "CONFIG_DBUS=yes" >> $config_mak + echo "#define CONFIG_DBUS 1" >> $config_h + echo "#define DBUS_SERVICE \"$dbus_service\"" >> $config_h +fi qemu_version=`head $source_path/VERSION` echo "VERSION=$qemu_version" >>$config_mak echo "#define QEMU_VERSION \"$qemu_version\"" >> $config_h
yuval/Dev/qemu-dbus/qemu/dbus/monitor-dbus.c renamed from yuval/Dev/qemu-cvs/qemu/dbus/monitor-dbus.c +1506 -0
1,506 lines not on this page · raw message
yuval/Dev/qemu-dbus/qemu/dbus/monitor-dbus.h renamed from yuval/Dev/qemu-cvs/qemu/dbus/monitor-dbus.h +60 -0
60 lines not on this page · raw message
yuval/Dev/qemu-dbus/qemu/error.c renamed from yuval/Dev/qemu-cvs/qemu/error.c +27 -0
@@ -0,0 +1,27 @@ +#include "error.h" +#include "vl.h" + +char g_szLastError[1024 ]; + +void SetLastError (char *szErrorMsg) { +strcpy (g_szLastError,szErrorMsg); +} + +void SetLastError_vprintf (const char *fmt,va_list ap) +{ +char buf[4096 ]; +vsnprintf (buf,sizeof (buf), fmt, ap); +SetLastError (buf); +} + +void SetLastError_printf (const char *fmt, ...) +{ +va_list ap; +va_start (ap, fmt); +SetLastError_vprintf (fmt, ap); +va_end (ap); +} + +const char *GetLastError () { +return g_szLastError; +}
yuval/Dev/qemu-dbus/qemu/error.h renamed from yuval/Dev/qemu-cvs/qemu/error.h +27 -0
@@ -0,0 +1,27 @@ +#include "error.h" +#include "vl.h" + +char g_szLastError[1024 ]; + +void SetLastError (char *szErrorMsg) { +strcpy (g_szLastError,szErrorMsg); +} + +void SetLastError_vprintf (const char *fmt,va_list ap) +{ +char buf[4096 ]; +vsnprintf (buf,sizeof (buf), fmt, ap); +SetLastError (buf); +} + +void SetLastError_printf (const char *fmt, ...) +{ +va_list ap; +va_start (ap, fmt); +SetLastError_vprintf (fmt, ap); +va_end (ap); +} + +const char *GetLastError () { +return g_szLastError; +}
yuval/Dev/qemu-dbus/qemu/Makefile.target renamed from yuval/Dev/qemu-cvs/qemu/Makefile.target +34 -0
@@ -368,6 +368,19 @@ # must use static linking to avoid leaving stuff in virtual address space VL_OBJS=vl.o osdep.o readline.o monitor.o pci.o console.o loader.o isa_mmio.o +ifdef CONFIG_DBUS +CPPFLAGS+=-I$(SRC_PATH)/dbus +VL_OBJS+=/usr/local/lib/dsrv.o + +DBUS_SERVER := monitor-dbus +DBUS_SERVOBJ :=$(DBUS_SERVER).o +VL_OBJS+=$(DBUS_SERVOBJ) + +error.o: error.c + $(CC) $(OP_CFLAGS) $(CPPFLAGS) -c -o $@ $< + +VL_OBJS+=error.o +endif VL_OBJS+=cutils.o VL_OBJS+=host-utils.o VL_OBJS+=block.o block-raw.o
@@ -659,6 +672,27 @@ %.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $< +ifdef CONFIG_DBUS + +PKGCONF ?= pkg-config +BINDTOOL ?= dbus-binding-tool + +DBUS_CFLAGS +=-I$(SRC_PATH)/dbus/ +DBUS_CFLAGS += $(shell $(PKGCONF) --cflags dbus-1) +DBUS_LDFLAGS += $(shell $(PKGCONF) --libs dbus-1) +LIBS += $(DBUS_LDFLAGS) + +DBUS_SERVOBJECT := qemu_mon +VL_OBJS+=$(DBUS_SERVOBJ) + +$(DBUS_SERVOBJ): dbus/monitor-dbus.c $(DBUS_SERVHDR) + $(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $(DBUS_CFLAGS) -c -o $@ $< + +#$(DBUS_SERVHDR): dbus/$(DBUS_SERVER).xml +# $(BINDTOOL) --prefix=$(DBUS_SERVOBJECT) --mode=glib-server --output=$@ $< + +endif + %.o: %.S $(CC) $(CPPFLAGS) -c -o $@ $<
yuval/Dev/qemu-dbus/qemu/monitor.c renamed from yuval/Dev/qemu-cvs/qemu/monitor.c +4 -4
@@ -199,7 +199,7 @@help_cmd (name); } -static void do_commit (const char *device) +void do_commit (const char *device) {int i, all_devices;
@@ -378,7 +378,7 @@return 0 ; } -static void do_eject (int force,const char *filename) +void do_eject (int force,const char *filename) {BlockDriverState *bs;
@@ -420,7 +420,7 @@ } } -static void do_change (const char *device,const char *target) +void do_change (const char *device,const char *target) {if (strcmp (device,"vnc" ) ==0 ) {do_change_vnc (target);
@@ -873,7 +873,7 @@return -1 ; } -static void do_send_key (const char *string) +void do_send_key (const char *string) {char keybuf[16 ], *q;uint8_t keycodes[16 ];
yuval/Dev/qemu-dbus/qemu/monitor.h renamed from yuval/Dev/qemu-cvs/qemu/monitor.h +10 -0
@@ -0,0 +1,10 @@ +#ifndef __monitor_h +#define __monitor_h + +void do_commit (const char *device); +void do_eject (int force,const char *filename); +void do_change (const char *device,const char *filename); +void do_send_key (const char *string); + +#endif // __monitor_h +
yuval/Dev/qemu-dbus/qemu/vl.c renamed from yuval/Dev/qemu-cvs/qemu/vl.c +233 -53
536 lines not on this page · raw message
yuval/Dev/qemu-dbus/qemu/vl.h renamed from yuval/Dev/qemu-cvs/qemu/vl.h +22 -0
@@ -38,6 +38,19 @@#include <fcntl.h> #include <sys/stat.h> +#define PHYS_RAM_MAX_SIZE (2047 * 1024 * 1024) + +#define MAX_NET_CLIENTS 32 + +#if defined(TARGET_SPARC ) +#define MAX_CPUS 16 +#elif defined(TARGET_I386 ) +#define MAX_CPUS 255 +#else +#define MAX_CPUS 1 +#endif + +#ifndef O_LARGEFILE #define O_LARGEFILE 0#endif
@@ -329,6 +342,7 @@QEMUBH *bh; } CharDriverState; +void qemu_chr_close (CharDriverState *chr);CharDriverState *qemu_chr_open (const char *filename);void qemu_chr_printf (CharDriverState *s,const char *fmt, ...);int qemu_chr_write (CharDriverState *s,const uint8_t *buf,int len);
@@ -412,6 +426,7 @@void qemu_send_packet (VLANClientState *vc,const uint8_t *buf,int size);void qemu_handler_true (void *opaque); +VLANState *get_first_vlan (void );void do_info_network (void );/* TAP win32 */
@@ -549,6 +564,9 @@void cpu_save (QEMUFile *f,void *opaque);int cpu_load (QEMUFile *f,void *opaque,int version_id); +int mgmt_savevm (const char *name); +int mgmt_loadvm (const char *name); +int mgmt_delvm (const char *name);void do_savevm (const char *name);void do_loadvm (const char *name);void do_delvm (const char *name);
@@ -1158,6 +1176,8 @@#include "hw/smbus.h" +void acpi_lid_status (uint8_t status); +/* acpi.c */ extern int acpi_enabled;i2c_bus *piix4_pm_init (PCIBus *bus,int devfn,uint32_t smb_io_base);
@@ -1384,6 +1404,8 @@#define VM_USB_HUB_SIZE 8 +int usb_device_add (const char *devname); +int usb_device_del (const char *devname);void do_usb_add (const char *devname);void do_usb_del (const char *devname);void usb_info (void );
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="xml" type="s" direction="out"/>
</method>
</interface>
<interface name = "org.qemu.Configuration">
<method name = "Monitor_system_powerdown">
</method>
<method name = "Monitor_system_reset">
</method>
<method name = "Monitor_send_key">
<arg name = "Keys" type = "s" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Monitor_delvm">
<arg name = "DeviceName" type = "s" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Monitor_loadvm">
<arg name = "DeviceName" type = "s" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Monitor_savevm">
<arg name = "DeviceName" type = "s" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Monitor_change">
<arg name = "DeviceName" type = "s" direction = "in" /> <arg name = "Filename" type = "s" direction = "in" />
</method>
<method name = "Monitor_eject">
<arg name = "Filename" type = "s" direction = "in" /> <arg name = "Force" type = "i" direction = "out" />
</method>
<method name = "Monitor_quit">
</method>
<method name = "Monitor_commit">
<arg name = "DeviceName" type = "s" direction = "in" />
</method>
<method name = "Config_vnc">
<arg name = "Display" type = "s" direction = "in" />
</method>
<method name = "Monitor_LoadVM">
<arg name = "Filename" type = "s" direction = "in" />
</method>
<method name = "Monitor_RemoveParallel">
<arg name = "DeviceID" type = "i" direction = "in" />
</method>
<method name = "Monitor_AddParallel">
<arg name = "DeviceName" type = "s" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Monitor_RemoveSerial">
<arg name = "DeviceID" type = "i" direction = "in" />
</method>
<method name = "Monitor_AddSerial">
<arg name = "DeviceName" type = "s" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Config_monitor">
<arg name = "DeviceName" type = "s" direction = "in" />
</method>
<method name = "Config_BIOSDir">
<arg name = "Directory" type = "s" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Config_AddNet">
<arg name = "Parameters" type = "s" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Config_SetCdrom">
<arg name = "ImageName" type = "s" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Monitor_SetBlockDevice">
<arg name = "Index" type = "u" direction = "in" /> <arg name = "ImageName" type = "s" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Monitor_SetFloppy">
<arg name = "Index" type = "u" direction = "in" /> <arg name = "ImageName" type = "s" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Config_SoundHWState">
<arg name = "Name" type = "s" direction = "in" /> <arg name = "State" type = "i" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Config_smp">
<arg name = "CPUs" type = "u" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Config_ramsize">
<arg name = "MegaBytes" type = "u" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Config_snapshot">
<arg name = "State" type = "u" direction = "in" />
</method>
<method name = "Config_boot">
<arg name = "DeviceLetter" type = "y" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "usb_del">
<arg name = "DeviceName" type = "s" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "usb_add">
<arg name = "DeviceName" type = "s" direction = "in" /> <arg name = "ReturnCode" type = "i" direction = "out" />
</method>
<method name = "Config_daemonize">
<arg name = "IsDaemnoize" type = "s" direction = "in" />
</method>
<method name = "Config_SetNoReboot">
<arg name = "IsNoReboot" type = "b" direction = "in" />
</method>
<method name = "Config_SetNoGraphic">
<arg name = "IsNoGraphic" type = "b" direction = "in" />
</method>
<method name = "Config_SetNoFDBootCheck">
<arg name = "IsNoFDBootCheck" type = "b" direction = "in" />
</method>
<method name = "Config_SetNoQuit">
<arg name = "IsNoQuit" type = "b" direction = "in" />
</method>
<method name = "Config_SetNoACPI">
<arg name = "Is_NoACPI" type = "b" direction = "in" />
</method>
<method name = "Config_Set_std_vga">
<arg name = "Is_std_vga" type = "b" direction = "in" />
</method>
<method name = "Config_SetFullScreen">
<arg name = "IsFullScreen" type = "b" direction = "in" />
</method>
<method name = "Config_SetLocaltime">
<arg name = "IsUTC" type = "b" direction = "in" />
</method>
<method name = "Config_UsbState">
<arg name = "State" type = "b" direction = "in" />
</method>
<method name = "ConfigDone">
</method>
</interface>
<interface name = "org.qemu.Debug">
<method name = "SetLogLevel">
<arg name = "LogLevel" type = "i" direction = "in" />
</method>
</interface>
</node>
BZh91AY&SY�O�M ������! ����������� �}� *��wh�Ͼ�R�������Iw{ww��ƻ��7�v^�ݕ^��{�g3���=m��aEr�vF��:��=�}>�.�ti�c�W'G$%MU��h/������������oo�;:_]{����׀��y��4;�Z�������+v���=����=���Ϟo�s�����_3n�wm���י}����>�}��t�sw�����������{�[����R��N���]�����C�zԧu����.��c�����U ��[�x��[�)�֟Z����R{�k�%{ޭ�����s�y��ݷ�wV^��uJ5�-ʗ] )w]����l���C3�K�r>�;+,7w ��
|�(������T��Om�h��;�����q{�( 2��1nI]�)�4}>�����[��6}��]��@�Ԍw�מ��}��K���3��RC{n�ny+�!)� �!��� )�S�O�O�
6P0�����JhB��i�mS�6����h�mF��4 H$DS�dM���6Sѥ7�F� @� ) ���1O MOM5O�T��i�{D�~��M�yG�hD� �S����h�y)�����M��(x�!�4b4� aBh!24 ���7�4�
�S�H�j =5 4��������u����W?�N�U�LΖD�� ��E�v �
?5|m���z
+!4A4�t#5���DW�1 *��Y2Es�1]D��@�b
@ LP�A��1�UTW�E�$@?�Ѩ�so��&"I"�� H����IQCDEr�.#�l��H�\���rV� j�)%`�(B��� 8������# 22j����ry��H�����#X�@
!,�ң�,S
"�&