Re: [Qemu-devel] [PATCH v2 03/14] qapi: add some enum tests

2014-08-05 Thread Wenchao Xia

Reviewed-by: Wenchao Xia 



Re: [Qemu-devel] [PATCH v2 02/14] qapi: ignore files created during make check

2014-08-05 Thread Wenchao Xia

Reviewed-by: Wenchao Xia 

在 2014-8-6 6:38, Eric Blake 写道:

After an in-tree build and run of 'make check-{qapi-schema,unit}',
I noticed some leftover files.

* tests/.gitignore: Ignore more testsuite droppings.

Signed-off-by: Eric Blake 
---
  tests/.gitignore | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/tests/.gitignore b/tests/.gitignore
index c71c110..e2e4957 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -14,11 +14,14 @@ test-int128
  test-iov
  test-mul64
  test-opts-visitor
+test-qapi-event.[ch]
  test-qapi-types.[ch]
  test-qapi-visit.[ch]
  test-qdev-global-props
+test-qemu-opts
  test-qmp-commands
  test-qmp-commands.h
+test-qmp-event
  test-qmp-input-strict
  test-qmp-input-visitor
  test-qmp-marshal.c





Re: [Qemu-devel] [PATCH] scripts: qapi-event.py: support vendor extension

2014-07-23 Thread Wenchao Xia

Reviewed-by: Wenchao Xia 

I didn't expect dot in schema before.



Re: [Qemu-devel] [PATCH v2 for-2.1 0/5] docs: document remaining QMP events

2014-07-23 Thread Wenchao Xia
Reviewed-by: Wenchao Xia 



Re: [Qemu-devel] [PATCH v2 for-2.1 4/5] docs: document missing POWERDOWN event

2014-07-23 Thread Wenchao Xia
于 2014/7/23 20:26, Eric Blake 写道:
> The POWERDOWN event was first documented in 0aab9ec3.  But since
> dfab4892 later restored this file to the state prior to qmp events,
> and we never documented it in the past, anyone using this file
> instead of qapi will miss out on this event.  Tweak the existing
> wording of SHUTDOWN to match 84321831, and make the difference
> between the two events apparent.
> 
> * docs/qmp/qmp-events.txt (POWERDOWN): Add.
> (SHUTDOWN): Tweak.
> 
> Signed-off-by: Eric Blake 
> ---
>   docs/qmp/qmp-events.txt | 16 +++-
>   1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
> index 22d552f..9d7439e 100644
> --- a/docs/qmp/qmp-events.txt
> +++ b/docs/qmp/qmp-events.txt
> @@ -243,6 +243,19 @@ Data:
> "timestamp": { "seconds": 1368697518, "microseconds": 326866 } }
>   }
> 
> +POWERDOWN
> +-
> +
> +Emitted when the Virtual Machine is powered down through the power
> +control system, such as via ACPI.
> +
> +Data: None.
> +
> +Example:
> +
> +{ "event": "POWERDOWN",
> +"timestamp": { "seconds": 1267040730, "microseconds": 682951 } }
> +
>   QUORUM_FAILURE
>   --
> 
> @@ -325,7 +338,8 @@ Example:
>   SHUTDOWN
>   
> 
> -Emitted when the Virtual Machine is powered down.
> +Emitted when the Virtual Machine has shut down, indicating that qemu
> +is about to exit.
> 
>   Data: None.
> 
  Nice to have explantion about the difference.



Re: [Qemu-devel] [PATCH v2 2.1 2/3] blockjob: Fix recent BLOCK_JOB_ERROR regression

2014-07-01 Thread Wenchao Xia
于 2014/6/28 1:24, Markus Armbruster 写道:
> Commit 5a2d2cb screwed up the the value of members device and action,
> breaking tests/qemu-iotests/041.
> 
> Signed-off-by: Markus Armbruster 
> Tested-By: Benoit Canet 
> Reviewed-by: Kevin Wolf 
> Reviewed-by: Luiz Capitulino 
> ---
>   blockjob.c   | 2 +-
>   qapi/block-core.json | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/blockjob.c b/blockjob.c
> index 37a8f1f..4d8ff45 100644
> --- a/blockjob.c
> +++ b/blockjob.c
> @@ -286,7 +286,7 @@ BlockErrorAction block_job_error_action(BlockJob *job, 
> BlockDriverState *bs,
>   default:
>   abort();
>   }
> -qapi_event_send_block_job_error(bdrv_get_device_name(bs),
> +qapi_event_send_block_job_error(bdrv_get_device_name(job->bs),
>   is_read ? IO_OPERATION_TYPE_READ :
>   IO_OPERATION_TYPE_WRITE,
>   action, &error_abort);
> diff --git a/qapi/block-core.json b/qapi/block-core.json
> index 822fe16..fd5b579 100644
> --- a/qapi/block-core.json
> +++ b/qapi/block-core.json
> @@ -1544,7 +1544,7 @@
>   { 'event': 'BLOCK_JOB_ERROR',
> 'data': { 'device'   : 'str',
>   'operation': 'IoOperationType',
> -'action'   : 'BlockdevOnError' } }
> +'action'   : 'BlockErrorAction' } }
>   
  It is my mistake to use BlockdevOnError in code incorrectly.
The define as 'BlockdevOnError' before is on purpose, since the
doc for 'BlockErrorAction' says: stop means a VM is stoped, but
for block-job it is not true, so I chosed a different type, and
'BlockdevOnError' seems the right one(see the doc for it). We can
fix it in C caller or add doc in .json file later.
  I am occupied by other things these days, thanks for fixing
the bugs introduced by me!


>   ##
>   # @BLOCK_JOB_READY
> 




Re: [Qemu-devel] [PATCH FOR 2.1 1/5] tests/test-qmp-event: fix for GLib < 2.31

2014-07-01 Thread Wenchao Xia

于 2014/6/30 18:53, Paolo Bonzini 写道:

Il 29/06/2014 22:31, Peter Maydell ha scritto:

On 27 June 2014 19:28, Luiz Capitulino  wrote:

On Wed, 25 Jun 2014 15:15:35 +0200
Paolo Bonzini  wrote:


Il 25/06/2014 15:13, Luiz Capitulino ha scritto:

On Tue, 24 Jun 2014 16:33:56 -0700
Wenchao Xia  wrote:


From: Paolo Bonzini 

On old GLib, the test needs a g_thread_init call.

Reported-by: Wenchao Xia 
Signed-off-by: Paolo Bonzini 
Tested-by: Wenchao Xia 
Signed-off-by: Wenchao Xia 
---
 tests/test-qmp-event.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c
index cb1e441..17c6444 100644
--- a/tests/test-qmp-event.c
+++ b/tests/test-qmp-event.c
@@ -251,6 +251,7 @@ static void test_event_d(TestEventData *data,

 int main(int argc, char **argv)
 {
+g_thread_init(NULL);
 qmp_event_set_func_emit(event_test_emit);

 g_test_init(&argc, &argv, NULL);


This breaks make check on F20:

"""
/home/lcapitulino/work/src/upstream/qmp-unstable/tests/test-qmp-event.c:
In function ‘main’:
/home/lcapitulino/work/src/upstream/qmp-unstable/tests/test-qmp-event.c:254:5:
error: ‘g_thread_init’ is deprecated (declared at
/usr/include/glib-2.0/glib/deprecated/gthread.h:260)
[-Werror=deprecated-declarations]
 g_thread_init(NULL);
 ^
cc1: all warnings being treated as errors
make: *** [tests/test-qmp-event.o] Error 1
"""

I think the best way to fix this is to make util/osdep.c:thread_init()
public (maybe by moving it to include/glib-compat.h) and use that
instead.
Also, note that thread_init()'s body is duplicated in a few other
places,
so maybe those places should call it too.

You may want to do this in a different series, then I can skip this
patch
and apply the rest of the series.



Thanks Luiz, it's a good suggestion.


Paolo, Wenchao, are one of one going to work on this?


Ping! Can we have at least a local fix using glib version #ifdefs before
Tuesday please? Otherwise we need to do something like this
to avoid shipping an rc0 which doesn't pass make check on some
systems.


I'll send the patch today.  thread_init() is a bit tricky because it is
a __constructor__ but it is not included in the binary because no other
function is included from the same file.

BTW, the make check limitation is currently mentioned in the changelog.

Paolo


  I am not free these days for the issue, thanks for fixing it instead
of me!



diff --git a/tests/Makefile b/tests/Makefile
index 7e53d0d..a1a0dae 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -27,8 +27,6 @@ check-unit-y +=
tests/test-string-input-visitor$(EXESUF)
 gcov-files-test-string-input-visitor-y = qapi/string-input-visitor.c
 check-unit-y += tests/test-string-output-visitor$(EXESUF)
 gcov-files-test-string-output-visitor-y = qapi/string-output-visitor.c
-check-unit-y += tests/test-qmp-event$(EXESUF)
-gcov-files-test-qmp-event-y += qapi/qmp-event.c
 check-unit-y += tests/test-opts-visitor$(EXESUF)
 gcov-files-test-opts-visitor-y = qapi/opts-visitor.c
 check-unit-y += tests/test-coroutine$(EXESUF)
@@ -213,7 +211,7 @@ test-obj-y = tests/check-qint.o
tests/check-qstring.o tests/check-qdict.o \
tests/test-qmp-input-visitor.o tests/test-qmp-input-strict.o \
tests/test-qmp-commands.o tests/test-visitor-serialization.o \
tests/test-x86-cpuid.o tests/test-mul64.o tests/test-int128.o \
-   tests/test-opts-visitor.o tests/test-qmp-event.o
+   tests/test-opts-visitor.o

 test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
   tests/test-qapi-event.o

thanks
-- PMM









[Qemu-devel] [PATCH FOR 2.1 3/5] qapi: ignore generated event files

2014-06-24 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 .gitignore |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore
index c658613..2286d0a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,6 +26,7 @@
 /qapi-generated
 /qapi-types.[ch]
 /qapi-visit.[ch]
+/qapi-event.[ch]
 /qmp-commands.h
 /qmp-marshal.c
 /qemu-doc.html
-- 
1.7.1




[Qemu-devel] [PATCH FOR 2.1 5/5] qapi event: clean up in callers

2014-06-24 Thread Wenchao Xia
This patch improves docs and address small issues in event
callers.

Signed-off-by: Wenchao Xia 
---
 hw/watchdog/watchdog.c   |2 +-
 include/block/blockjob.h |2 +-
 monitor.c|2 +-
 qapi-schema.json |7 ---
 qapi/block-core.json |3 ++-
 qapi/event.json  |4 ++--
 6 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/hw/watchdog/watchdog.c b/hw/watchdog/watchdog.c
index 4aebd34..9f607d4 100644
--- a/hw/watchdog/watchdog.c
+++ b/hw/watchdog/watchdog.c
@@ -106,7 +106,7 @@ int select_watchdog_action(const char *p)
  */
 void watchdog_perform_action(void)
 {
-switch(watchdog_action) {
+switch (watchdog_action) {
 case WDT_RESET: /* same as 'system_reset' in monitor */
 qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_RESET, 
&error_abort);
 qemu_system_reset_request();
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index e443987..cc765b5 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -217,7 +217,7 @@ void block_job_pause(BlockJob *job);
 void block_job_resume(BlockJob *job);
 
 /**
- * block_job_event_cancle:
+ * block_job_event_cancelled:
  * @job: The job whose information is requested.
  *
  * Send a BLOCK_JOB_CANCELLED event for the specified job.
diff --git a/monitor.c b/monitor.c
index a8ab600..fd34ab7 100644
--- a/monitor.c
+++ b/monitor.c
@@ -570,6 +570,7 @@ monitor_qapi_event_throttle(QAPIEvent event, int64_t rate)
 
 trace_monitor_protocol_event_throttle(event, rate);
 evstate->event = event;
+assert(rate * SCALE_MS <= INT64_MAX);
 evstate->rate = rate * SCALE_MS;
 evstate->last = 0;
 evstate->data = NULL;
@@ -585,7 +586,6 @@ static void monitor_qapi_event_init(void)
 monitor_qapi_event_throttle(QAPI_EVENT_RTC_CHANGE, 1000);
 monitor_qapi_event_throttle(QAPI_EVENT_WATCHDOG, 1000);
 monitor_qapi_event_throttle(QAPI_EVENT_BALLOON_CHANGE, 1000);
-/* limit the rate of quorum events to avoid hammering the management */
 monitor_qapi_event_throttle(QAPI_EVENT_QUORUM_REPORT_BAD, 1000);
 monitor_qapi_event_throttle(QAPI_EVENT_QUORUM_FAILURE, 1000);
 
diff --git a/qapi-schema.json b/qapi-schema.json
index 37c2189..c68a17f 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -657,8 +657,9 @@
 #
 # @host: IP address
 #
-# @service: The service name of vnc port. This may depend on the host system's
-#   service database so symbolic names should not be relied on.
+# @service: The service name of the vnc port. This may depend on the host
+#   system's service database so symbolic names should not be relied
+#   on.
 #
 # @family: address family
 #
@@ -697,7 +698,7 @@
 ##
 { 'type': 'VncClientInfo',
   'base': 'VncBasicInfo',
-  'data': { '*x509_dname'   : 'str', '*sasl_username': 'str' } }
+  'data': { '*x509_dname': 'str', '*sasl_username': 'str' } }
 
 ##
 # @VncInfo:
diff --git a/qapi/block-core.json b/qapi/block-core.json
index af6b436..925e53e 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1436,7 +1436,8 @@
 # @device: device name
 #
 # @msg: informative message for human consumption, such as the kind of
-#   corruption being detected
+#   corruption being detected. It should not be parsed by machine as it is
+#   not guaranteed to be stable
 #
 # @offset: #optional, if the corruption resulted from an image access, this is
 #  the access offset into the image
diff --git a/qapi/event.json b/qapi/event.json
index e7a47f9..8f817b1 100644
--- a/qapi/event.json
+++ b/qapi/event.json
@@ -1,8 +1,8 @@
 ##
 # @SHUTDOWN
 #
-# Emitted when the virtual machine has shutdown, possibly indicating that QEMU
-# is about about to exit.
+# Emitted when the virtual machine has shut down, indicating that qemu is
+# about to exit.
 #
 # Note: If the command-line option "-no-shutdown" has been specified, qemu will
 # not exit, and a STOP event will eventually follow the SHUTDOWN event
-- 
1.7.1




[Qemu-devel] [PATCH FOR 2.1 0/5] clean up for qapi event

2014-06-24 Thread Wenchao Xia

Paolo Bonzini (1):
  tests/test-qmp-event: fix for GLib < 2.31

Wenchao Xia (4):
  qapi: move event defines
  qapi: ignore generated event files
  qapi script: clean up in scripts
  qapi event: clean up in callers

 .gitignore  |1 +
 Makefile|2 +-
 docs/qapi-code-gen.txt  |8 +-
 hw/watchdog/watchdog.c  |2 +-
 include/block/blockjob.h|2 +-
 monitor.c   |2 +-
 qapi-event.json |  318 ---
 qapi-schema.json|   12 +-
 qapi/block-core.json|3 +-
 qapi/event.json |  318 +++
 scripts/qapi-event.py   |5 +-
 scripts/qapi.py |2 +-
 tests/qapi-schema/event-nest-struct.err |2 +-
 tests/test-qmp-event.c  |1 +
 14 files changed, 341 insertions(+), 337 deletions(-)
 delete mode 100644 qapi-event.json
 create mode 100644 qapi/event.json




[Qemu-devel] [PATCH FOR 2.1 1/5] tests/test-qmp-event: fix for GLib < 2.31

2014-06-24 Thread Wenchao Xia
From: Paolo Bonzini 

On old GLib, the test needs a g_thread_init call.

Reported-by: Wenchao Xia 
Signed-off-by: Paolo Bonzini 
Tested-by: Wenchao Xia 
Signed-off-by: Wenchao Xia 
---
 tests/test-qmp-event.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c
index cb1e441..17c6444 100644
--- a/tests/test-qmp-event.c
+++ b/tests/test-qmp-event.c
@@ -251,6 +251,7 @@ static void test_event_d(TestEventData *data,
 
 int main(int argc, char **argv)
 {
+g_thread_init(NULL);
 qmp_event_set_func_emit(event_test_emit);
 
 g_test_init(&argc, &argv, NULL);
-- 
1.7.1




[Qemu-devel] [PATCH FOR 2.1 2/5] qapi: move event defines

2014-06-24 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 Makefile |2 +-
 qapi-event.json  |  318 --
 qapi-schema.json |5 +-
 qapi/event.json  |  318 ++
 4 files changed, 322 insertions(+), 321 deletions(-)
 delete mode 100644 qapi-event.json
 create mode 100644 qapi/event.json

diff --git a/Makefile b/Makefile
index 145adb6..1eea0c4 100644
--- a/Makefile
+++ b/Makefile
@@ -248,7 +248,7 @@ $(SRC_PATH)/qga/qapi-schema.json 
$(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
 
 qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
$(SRC_PATH)/qapi/block.json $(SRC_PATH)/qapi/block-core.json \
-   $(SRC_PATH)/qapi-event.json
+   $(SRC_PATH)/qapi/event.json
 
 qapi-types.c qapi-types.h :\
 $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
diff --git a/qapi-event.json b/qapi-event.json
deleted file mode 100644
index e7a47f9..000
--- a/qapi-event.json
+++ /dev/null
@@ -1,318 +0,0 @@
-##
-# @SHUTDOWN
-#
-# Emitted when the virtual machine has shutdown, possibly indicating that QEMU
-# is about about to exit.
-#
-# Note: If the command-line option "-no-shutdown" has been specified, qemu will
-# not exit, and a STOP event will eventually follow the SHUTDOWN event
-#
-# Since: 0.12.0
-##
-{ 'event': 'SHUTDOWN' }
-
-##
-# @POWERDOWN
-#
-# Emitted when the virtual machine is powered down through the power control
-# system, such as via ACPI.
-#
-# Since: 0.12.0
-##
-{ 'event': 'POWERDOWN' }
-
-##
-# @RESET
-#
-# Emitted when the virtual machine is reset
-#
-# Since: 0.12.0
-##
-{ 'event': 'RESET' }
-
-##
-# @STOP
-#
-# Emitted when the virtual machine is stopped
-#
-# Since: 0.12.0
-##
-{ 'event': 'STOP' }
-
-##
-# @RESUME
-#
-# Emitted when the virtual machine resumes execution
-#
-# Since: 0.12.0
-##
-{ 'event': 'RESUME' }
-
-##
-# @SUSPEND
-#
-# Emitted when guest enters a hardware suspension state, for example, S3 state,
-# which is sometimes called standby state
-#
-# Since: 1.1
-##
-{ 'event': 'SUSPEND' }
-
-##
-# @SUSPEND_DISK
-#
-# Emitted when guest enters a hardware suspension state with data saved on
-# disk, for example, S4 state, which is sometimes called hibernate state
-#
-# Note: QEMU shuts down (similar to event @SHUTDOWN) when entering this state
-#
-# Since: 1.2
-##
-{ 'event': 'SUSPEND_DISK' }
-
-##
-# @WAKEUP
-#
-# Emitted when the guest has woken up from suspend state and is running
-#
-# Since: 1.1
-##
-{ 'event': 'WAKEUP' }
-
-##
-# @RTC_CHANGE
-#
-# Emitted when the guest changes the RTC time.
-#
-# @offset: offset between base RTC clock (as specified by -rtc base), and
-#  new RTC clock value
-#
-# Since: 0.13.0
-##
-{ 'event': 'RTC_CHANGE',
-  'data': { 'offset': 'int' } }
-
-##
-# @WATCHDOG
-#
-# Emitted when the watchdog device's timer is expired
-#
-# @action: action that has been taken
-#
-# Note: If action is "reset", "shutdown", or "pause" the WATCHDOG event is
-# followed respectively by the RESET, SHUTDOWN, or STOP events
-#
-# Since: 0.13.0
-##
-{ 'event': 'WATCHDOG',
-  'data': { 'action': 'WatchdogExpirationAction' } }
-
-##
-# @DEVICE_DELETED
-#
-# Emitted whenever the device removal completion is acknowledged by the guest.
-# At this point, it's safe to reuse the specified device ID. Device removal can
-# be initiated by the guest or by HMP/QMP commands.
-#
-# @device: #optional, device name
-#
-# @path: device path
-#
-# Since: 1.5
-##
-{ 'event': 'DEVICE_DELETED',
-  'data': { '*device': 'str', 'path': 'str' } }
-
-##
-# @NIC_RX_FILTER_CHANGED
-#
-# Emitted once until the 'query-rx-filter' command is executed, the first event
-# will always be emitted
-#
-# @name: #optional, net client name
-#
-# @path: device path
-#
-# Since: 1.6
-##
-{ 'event': 'NIC_RX_FILTER_CHANGED',
-  'data': { '*name': 'str', 'path': 'str' } }
-
-##
-# @VNC_CONNECTED
-#
-# Emitted when a VNC client establishes a connection
-#
-# @server: server information
-#
-# @client: client information
-#
-# Note: This event is emitted before any authentication takes place, thus
-# the authentication ID is not provided
-#
-# Since: 0.13.0
-##
-{ 'event': 'VNC_CONNECTED',
-  'data': { 'server': 'VncServerInfo',
-'client': 'VncBasicInfo' } }
-
-##
-# @VNC_INITIALIZED
-#
-# Emitted after authentication takes place (if any) and the VNC session is
-# made active
-#
-# @server: server information
-#
-# @client: cli

[Qemu-devel] [PATCH FOR 2.1 4/5] qapi script: clean up in scripts

2014-06-24 Thread Wenchao Xia
This patch improve docs and uses c_type(argentry, is_param=True)
in script.

Signed-off-by: Wenchao Xia 
---
 docs/qapi-code-gen.txt  |8 
 scripts/qapi-event.py   |5 ++---
 scripts/qapi.py |2 +-
 tests/qapi-schema/event-nest-struct.err |2 +-
 4 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt
index 3a0c99e..a6197a9 100644
--- a/docs/qapi-code-gen.txt
+++ b/docs/qapi-code-gen.txt
@@ -218,10 +218,10 @@ An example command is:
 === Events ===
 
 Events are defined with the keyword 'event'.  When 'data' is also specified,
-additional info will be carried on.  Finally there will be C API generated
-in qapi-event.h; when called by QEMU code, a message with timestamp will
-be emitted on the wire.  If timestamp is -1, it means failure to retrieve host
-time.
+additional info will be included in the event.  Finally there will be C API
+generated in qapi-event.h; when called by QEMU code, a message with timestamp
+will be emitted on the wire.  If timestamp is -1, it means failure to retrieve
+host time.
 
 An example event is:
 
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index 3a1cd61..601e307 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -26,9 +26,8 @@ def _generate_event_api_name(event_name, params):
 api_name += "bool has_%s,\n" % c_var(argname)
 api_name += "".ljust(l)
 
-if argentry == "str":
-api_name += "const "
-api_name += "%s %s,\n" % (c_type(argentry), c_var(argname))
+api_name += "%s %s,\n" % (c_type(argentry, is_param=True),
+  c_var(argname))
 api_name += "".ljust(l)
 
 api_name += "Error **errp)"
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 54b97cb..f2c6d1f 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -255,7 +255,7 @@ def check_event(expr, expr_info):
 if structured:
 raise QAPIExprError(expr_info,
 "Nested structure define in event is not "
-"supported now, event '%s', argname '%s'"
+"supported, event '%s', argname '%s'"
 % (expr['event'], argname))
 
 def check_union(expr, expr_info):
diff --git a/tests/qapi-schema/event-nest-struct.err 
b/tests/qapi-schema/event-nest-struct.err
index e4a0faa..91bde1c 100644
--- a/tests/qapi-schema/event-nest-struct.err
+++ b/tests/qapi-schema/event-nest-struct.err
@@ -1 +1 @@
-tests/qapi-schema/event-nest-struct.json:1: Nested structure define in event 
is not supported now, event 'EVENT_A', argname 'a'
+tests/qapi-schema/event-nest-struct.json:1: Nested structure define in event 
is not supported, event 'EVENT_A', argname 'a'
-- 
1.7.1




Re: [Qemu-devel] [PATCH build-fix] tests/test-qmp-event: fix for GLib < 2.31

2014-06-24 Thread Wenchao Xia
Tested-by: Wenchao Xia 




Re: [Qemu-devel] [PULL for-2.1 00/40] QMP queue

2014-06-24 Thread Wenchao Xia

于 2014/6/24 21:24, Peter Maydell 写道:

On 24 June 2014 14:20, Eric Blake  wrote:

Rebase your cleanups on to of this PULL request:
https://lists.gnu.org/archive/html/qemu-devel/2014-06/msg05424.html


I just applied that, so "rebase on top of master"...



There is a test broken due to CompatGMutex in test_qmp_event.c, and
using CompatGMutest instead of simple GStaticMutex is caused by patch:

commit 86946a2d835614050b90bc8e5c82982fe45deff2:
Author: Michael Tokarev 
glib-compat.h: add new thread API emulation on top of pre-2.31 API

It seems cond->once.retval never get a chance to be allocated before
g_mutex_lock(), a bug?




thanks
-- PMM






Re: [Qemu-devel] [PULL for-2.1 00/40] QMP queue

2014-06-24 Thread Wenchao Xia

于 2014/6/21 4:02, Eric Blake 写道:

On 06/20/2014 01:49 PM, Paolo Bonzini wrote:



As I explained on IRC, many patches when rebased would have conflicts
with Igor's new event.  I think this is much more complex than having
an "extraordinary" merge commit.

I include the conflict resolution:

- hw/acpi/memory-hotplug.c is only present in mst's branch, so I'm
including the diff from there (changing to the QAPI event style)

- qapi-event.json is only present in luiz's branch, so I'm
including the diff from there (adding the ACPI_DEVICE_OST event)


One other alternative would have been to pull out the new
ACPI_DEVICE_OST patches out of mst's branch, and upgrade them to Igor's
v3 which applies on top of Wenchao's work:
https://lists.gnu.org/archive/html/qemu-devel/2014-06/msg04927.html



  So which way to go now?



-
Paolo

a76d72f692ed5f4f30f116cc9c3ac5fefe221cb7
Merge: 0a99aae b98ff90
Author: Paolo Bonzini 
Date:   Fri Jun 20 21:18:08 2014 +0200

 Merge commit b98ff90e9459e0113da8502c03670a9539f90aa1 of 
git://repo.or.cz/qemu/qmp-unstable into HEAD

 Conflicts:
docs/qmp/qmp-events.txt [removed with QAPI event conversion]
hw/core/qdev.c [trivial header file conflict]
include/monitor/monitor.h [QMP event enum removed by QAPI conversion]
monitor.c [QMP event enum removed by QAPI conversion]
qapi-schema.json [trivial, code added by both sides in the same place]
qemu-char.c [trivial, code added by both sides in the same place]
vl.c [trivial header file conflict]

 Other files changed:
 qapi-event.json [include ACPI_DEVICE_OST event]
 hw/acpi/memory-hotplug.c [use QAPI event]

 Signed-off-by: Paolo Bonzini 


If you are okay taking this complex merge patch, you can add:

Reviewed-by: Eric Blake 






Re: [Qemu-devel] [PATCH v3] qmp: add ACPI_DEVICE_OST event handling

2014-06-20 Thread Wenchao Xia

于 2014/6/20 23:46, Eric Blake 写道:

On 06/20/2014 02:33 AM, Igor Mammedov wrote:

emits event when ACPI OSPM evaluates _OST method
of ACPI device.

Signed-off-by: Igor Mammedov 
---
v2:
  - use new QAPI event infrastructure
   from rebased PCI tree on top of today's QMP pull request
---
  hw/acpi/memory_hotplug.c |7 ++-
  qapi-event.json  |   10 ++
  2 files changed, 16 insertions(+), 1 deletions(-)




+++ b/qapi-event.json
@@ -304,3 +304,13 @@
  { 'event': 'QUORUM_REPORT_BAD',
'data': { '*error': 'str', 'node-name': 'str',
  'sector-num': 'int', 'sector-count': 'int' } }
+
+##
+# @ACPI_DEVICE_OST
+#
+# Emitted when guest executes ACPI _OST method.
+#
+# @info: ACPIOSTInfo type as described in qapi-schema.json


Needs 'Since: 2.1'.


  With above added,
Reviewed-by: Wenchao Xia 


+##
+{ 'event': 'ACPI_DEVICE_OST',
+ 'data': { 'info': 'ACPIOSTInfo' } }



Not your fault, as the problem already exists, but it's a bit awkward
that qapi-event.json is not self-contained, and your patch is only
making it worse.  qapi-event.json only makes sense when included by
qapi-schema.json, when ideally it would be nice if it made sense if
compiled in isolation. I already pointed this fact out on Wenchao's
series that made events part of QAPI, but fixing it first requires
teaching the code generators to flag places where a type is used without





a pre-definition, so that we know which types have to be moved into a
common include.  So don't let this comment hold up your patch.


  I think two issues should be addressed:
1 don't let generator guess the type if define is not found.
2 Support duplicated include, that is:

 qapi/types.json
 |
  ---
  |  |
qapi/qapi-event.json  qapi/block.json
 ||
  qapi-schema-json

  Making sure above include doesn't generate two copy of types from
qapi/types.json.
  We can improve it later.


If you add the Since line,
Reviewed-by: Eric Blake 






Re: [Qemu-devel] [PATCH 2.1 00/36] Pending monitor patches for 2.1

2014-06-20 Thread Wenchao Xia

于 2014/6/20 23:44, Eric Blake 写道:

On 06/18/2014 12:43 AM, Paolo Bonzini wrote:

This includes:

- Max's dependency fixes for QAPI scripts

- Wenchao's QAPI event series

- my thread-safety fixes, rebased onto QAPI events

Paolo




  monitor.c| 226 ++---
  qapi-event.json  | 306 +
  qapi-schema.json | 162 +++--
  qapi/Makefile.objs   |   1 +
  qapi/block-core.json | 150 +
  qapi/block.json  |  14 +
  qapi/qmp-event.c |  74 +


Wenchao, as part of your followups to this series, I'd really like to
move qapi-event.json into qapi/event.json, so that all of our subset
.json files live in the same directory.


  I'll send the clean up patch onece the Paolo's series get merged.



Re: [Qemu-devel] [PATCH 2.1 03/36] qapi: add event helper functions

2014-06-18 Thread Wenchao Xia
于 2014/6/18 14:43, Paolo Bonzini 写道:
> From: Wenchao Xia 
> 
> This file holds some functions that do not need to be generated.
> 
> Signed-off-by: Wenchao Xia 
> Reviewed-by: Eric Blake 
> Signed-off-by: Paolo Bonzini 
> ---
>   include/qapi/qmp-event.h | 27 ++
>   qapi/Makefile.objs   |  1 +
>   qapi/qmp-event.c | 74 
> 
>   3 files changed, 102 insertions(+)
>   create mode 100644 include/qapi/qmp-event.h
>   create mode 100644 qapi/qmp-event.c
> 
> diff --git a/include/qapi/qmp-event.h b/include/qapi/qmp-event.h
> new file mode 100644
> index 000..8a8ffb5
> --- /dev/null
> +++ b/include/qapi/qmp-event.h
> @@ -0,0 +1,27 @@
> +/*
> + * QMP Event related
> + *
> + * Copyright (c) 2014 Wenchao Xia
> + *
> + * Authors:
> + *  Wenchao Xia   
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or 
> later.
> + * See the COPYING.LIB file in the top-level directory.
> + *
> + */
> +
> +#ifndef QMP_EVENT_H
> +#define QMP_EVENT_H
> +
> +#include "qapi/error.h"
> +#include "qapi/qmp/qdict.h"
> +
> +typedef void (*QMPEventFuncEmit)(unsigned event, QDict *dict, Error **errp);
> +

  Using unsigned instead of QAPIEvent works around the include issue,
and also fix the type cast issue in implemention function that Eric
mentioned. It is nice to me, +1.

> +void qmp_event_set_func_emit(QMPEventFuncEmit emit);
> +
> +QMPEventFuncEmit qmp_event_get_func_emit(void);
> +
> +QDict *qmp_event_build_dict(const char *event_name);
> +#endif
> diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs
> index 1f9c973..d14b769 100644
> --- a/qapi/Makefile.objs
> +++ b/qapi/Makefile.objs
> @@ -3,3 +3,4 @@ util-obj-y += qmp-output-visitor.o qmp-registry.o 
> qmp-dispatch.o
>   util-obj-y += string-input-visitor.o string-output-visitor.o
>   
>   util-obj-y += opts-visitor.o
> +util-obj-y += qmp-event.o
> diff --git a/qapi/qmp-event.c b/qapi/qmp-event.c
> new file mode 100644
> index 000..0d1ce0b
> --- /dev/null
> +++ b/qapi/qmp-event.c
> @@ -0,0 +1,74 @@
> +/*
> + * QMP Event related
> + *
> + * Copyright (c) 2014 Wenchao Xia
> + *
> + * Authors:
> + *  Wenchao Xia   
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or 
> later.
> + * See the COPYING.LIB file in the top-level directory.
> + *
> + */
> +
> +#include 
> +
> +#include "qemu-common.h"
> +#include "qapi/qmp-event.h"
> +#include "qapi/qmp/qstring.h"
> +#include "qapi/qmp/qjson.h"
> +
> +#ifdef _WIN32
> +#include "sysemu/os-win32.h"
> +#endif
> +
> +#ifdef CONFIG_POSIX
> +#include "sysemu/os-posix.h"
> +#endif
> +
> +static QMPEventFuncEmit qmp_emit;
> +
> +void qmp_event_set_func_emit(QMPEventFuncEmit emit)
> +{
> +qmp_emit = emit;
> +}
> +
> +QMPEventFuncEmit qmp_event_get_func_emit(void)
> +{
> +return qmp_emit;
> +}
> +
> +static void timestamp_put(QDict *qdict)
> +{
> +int err;
> +QObject *obj;
> +qemu_timeval tv;
> +int64_t sec, usec;
> +
> +err = qemu_gettimeofday(&tv);
> +if (err < 0) {
> +/* Put -1 to indicate failure of getting host time */
> +sec = -1;
> +usec = -1;
> +} else {
> +sec = tv.tv_sec;
> +usec = tv.tv_usec;
> +}
> +
> +obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", "
> + "'microseconds': %" PRId64 " }",
> + sec, usec);
> +qdict_put_obj(qdict, "timestamp", obj);
> +}
> +
> +/*
> + * Build a QDict, then fill event name and time stamp, caller should free the
> + * QDict after usage.
> + */
> +QDict *qmp_event_build_dict(const char *event_name)
> +{
> +QDict *dict = qdict_new();
> +qdict_put(dict, "event", qstring_from_str(event_name));
> +timestamp_put(dict);
> +return dict;
> +}
> 




Re: [Qemu-devel] [PATCH V6 03/29] qapi script: add event support

2014-06-18 Thread Wenchao Xia

于 2014/6/18 14:06, Paolo Bonzini 写道:

Il 18/06/2014 05:33, Eric Blake ha scritto:

> +# This work is licensed under the terms of the GNU GPL, version 2.
> +# See the COPYING file in the top-level directory.

Any reason this can't be GPLv2+ instead of GPLv2-only?


I suppose because it copies parts of other qapi-* scripts. :(

Paolo


  Yes, feel free to change the license.



Re: [Qemu-devel] [PATCH V6 00/29] add direct support of event in qapi schema

2014-06-17 Thread Wenchao Xia

于 2014/6/18 0:30, Paolo Bonzini 写道:

Il 17/06/2014 18:05, Eric Blake ha scritto:

diff --git a/Makefile b/Makefile
index 3e65525..f473cf5 100644
--- a/Makefile
+++ b/Makefile
@@ -246,8 +246,7 @@ $(SRC_PATH)/qga/qapi-schema.json
$(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
 $(gen-out-type) -o "." -b -i $<, \
 "  GEN   $@")
 qapi-event.c qapi-event.h :\
-$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi-event.json \
-$(SRC_PATH)/scripts/qapi-event.py $(qapi-py)
+$(qapi-modules) $(SRC_PATH)/scripts/qapi-event.py $(qapi-py)


Where's the change that adds qapi/event.json to $(qapi-modules)?  (Maybe
the interdiff doesn't show it?)


Oops, it's not there.


+++ b/include/sysemu/os-posix.h
@@ -26,8 +26,6 @@
 #ifndef QEMU_OS_POSIX_H
 #define QEMU_OS_POSIX_H

-#include 
-
 void os_set_line_buffering(void);


Why this hunk? Did you accidentally forget to include Wenchao's 1/29 in
your series?


Yes, fixing now.


@@ -535,14 +533,15 @@ static void monitor_qapi_event_handler(void
*opaque)
  * more than 1 event will be emitted within @rate
  * milliseconds
  */
-static void monitor_qapi_event_throttle(QAPIEvent event, int64_t rate)
+static void
+monitor_qapi_event_throttle(QAPIEvent event, int64_t rate)
 {


Not the usual qemu formatting style.


Yeah, this happened because of __attribute__((__unused__)) and matches
other monitor_qapi_ functions.  I kind of like the
return-type-then-newline too. :)


Overall the interdiff looks like it resolves most of my concerns on v6.
 Now for me to read the actual commits in your git repo...


Will fix in a moment.

Paolo

  If you and Eric think v6 is OK to catch up 2.1, I can send a clean up
patch fixing the typo/doc issues after merge.



Re: [Qemu-devel] [PATCH V6 00/29] add direct support of event in qapi schema

2014-06-14 Thread Wenchao Xia

于 2014/6/10 13:48, Paolo Bonzini 写道:

Il 05/06/2014 14:21, Wenchao Xia ha scritto:

This series add support for tag/keyword 'event' in qapi-schema.
A new file was created to store some helper functions in patch 2,
patch 4 is
the test case, patch 5 is a convert example.

The implemention is done by generate API and a batch of parameters for
each
event define, it doesn't generate a struture and visit function in the
background for every event, so it doesn't support nested structure in the
define to avoid trouble. A callback layer is added to control the
behavior.
More detail can be found in patch 3's message and incode comments.

v2:
  Address Luiz's comments:
  patch 3: rename *err to *local_err, do not initialize *qmp = NULL,
create
a new function qmp_build_evet_dict().
  Other change:
  reorgnized script in patch 3, it have a clear three steps, see patch
3's
incode comments.

v3:
  Address Luiz's comments:
  2/5: use -1 when fail to get host timestamp.
  3/5: typo fix and better incode comments. all unchanged functions
are moved
into qmp-event.c, from generated file. To do so without include issue,
'int'
was used intead of 'enum' in function prototype declaration, since the
'enum'
define is a generated type.
  Address Eric's comments:
  2/5: use -1 when fail to get host timestamp.
  3/5: typo fix, add docs/qapi-code-gen.txt.
  4/5: typo fix, verify no other fields in member 'timestamp'.
  5/5: add doc in qapi-schema.json.
  fix license, all script using GPL2, all C code use LGPL, just as other
similar files in upstream.

v4:
  Address Eric's comments:
  2/5: typo fix, add copyright declaration, use a static function pointer
instead of a struct in C file, assign -1 in two line of codes to avoid
issue
when tv_sec and tv_usec are not in same data width, fix indention.
  3/5: typo fix, add copyright declaration.
  4/5: add copyright declaration, simplify string compare with
 "d->result = g_strcmp0(...) == 0;", add check for tv_usec's range and
value.
  Other:
  3/5: all error check code was moved from qapi-event.py to qapi.py,
and it
reports better message with line number info. Added related test case.
  Note:
  Benoit's series which track input file better seems not the final
version,
so I didn't rebase this series ontop for now, will do it once Benoit's
ones
get ACKed.

v5:
  Address Eric and Markus's comments:
  2/28: use uint64_t for both sec and usec, to avoid type cast issue
in printf.
  Other:
  Remove RFC, add full coversion by patch 5-28.
  3/28: add prefix for event enum type name, to avoid double define of
QAPIEvent in test code.

v6:
  Address Eric's comments:
  3/29: employ modularization mechnism of schema file of Lluís
series, remove
error_is_set() usage.
  4/29: Makefile change for Lluís series.
  5/29: separate patch for refactoring the existing schema defines,
improve doc
for @service in VncBasicInfo.
  7/29-28/29: define and convert event caller one by one.
  Other change:
  6/29: new way to add event emit implemention. In v5 it breaks old event
mechnism, in v6 it touch nothing of old event mechnism but add a new
set of
functions for new event mechnism.
  7/29: Add new file qapi-event.json to store event defines, and all type
defines goes into qapi-schema.json.
  29/29: related clean up change.
  Note:
  I have no way to verify target-s390x/kvm.c touched by patch 27/29, and
block/quorum.c touched by patch 28/29, need a confirm from whom has
the test
env.

Wenchao Xia (29):
  1 os-posix: include sys/time.h
  2 qapi: add event helper functions
  3 qapi script: add event support
  4 test: add test cases for qapi event
  5 qapi: adjust existing defines
  6 monitor: add an implemention as qapi event emit method
  7 qapi: add new schema file qapi-event.json
  8 qapi event: convert SHUTDOWN
  9 qapi event: convert POWERDOWN
  10 qapi event: convert RESET
  11 qapi event: convert STOP
  12 qapi event: convert RESUME
  13 qapi event: convert SUSPEND
  14 qapi event: convert SUSPEND_DISK
  15 qapi event: convert WAKEUP
  16 qapi event: convert RTC_CHANGE
  17 qapi event: convert WATCHDOG
  18 qapi event: convert DEVICE_DELETED
  19 qapi event: convert DEVICE_TRAY_MOVED
  20 qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR
  21 qapi event: convert BLOCK_IMAGE_CORRUPTED
  22 qapi event: convert other BLOCK_JOB events
  23 qapi event: convert NIC_RX_FILTER_CHANGED
  24 qapi event: convert VNC events
  25 qapi event: convert SPICE events
  26 qapi event: convert BALLOON_CHANGE
  27 qapi event: convert GUEST_PANICKED
  28 qapi event: convert QUORUM events
  29 qapi event: clean up

 Makefile |   21 +-
 Makefile.objs|2 +-
 balloon.c|   13 -
 block.c  |   68 +---
 block/backup.c   |2 +-
 block/mirror.c

Re: [Qemu-devel] [PATCH V6 17/29] qapi event: convert WATCHDOG

2014-06-14 Thread Wenchao Xia

于 2014/6/14 6:05, Eric Blake 写道:

On 06/13/2014 03:47 PM, Eric Blake wrote:

On 06/05/2014 06:22 AM, Wenchao Xia wrote:

Signed-off-by: Wenchao Xia 
---
  docs/qmp/qmp-events.txt |   19 ---
  hw/watchdog/watchdog.c  |   23 +++
  monitor.c   |2 +-
  qapi-event.json |   15 +++
  qapi-schema.json|   24 
  5 files changed, 47 insertions(+), 36 deletions(-)






+  'data': { 'action': 'WatchdogExpirationAction' } }


Hmm.  You've managed to create error.json in such a manner that it is
not self-sufficient.  If some other file includes error.json, it must
also define WatchdogExpirationAction or it will fail the generators.


s/error.json/qapi-event.json/




+++ b/qapi-schema.json



+##
+# @WatchdogExpirationAction


I think you will be better off to ensure that error.json is


and again qapi-event.json (not sure why I typed error.json).


self-sufficient, perhaps by sticking any data type it references
directly into common.json rather than qapi-schema.json, and having
error.json include common.json.  (This is the first instance of
referencing an external type, but other events later in the series have
the same issue).


Oh weird! I've managed to run all four of
scripts/qapi-{visit,types,commands,event}.py directly on
qapi-event.json, and didn't get any complaints from the generator.  BUT,
the generated code is definitely different:

-void qapi_event_send_watchdog(WatchdogExpirationAction action,
+void qapi_event_send_watchdog(WatchdogExpirationAction * action,
Error **errp)

That is, when the enum type is known (because the parse was done on
qapi-schema.json), the WatchdogExpirationAction argument is treated as
an integer enum value; but when the enum type is unknown (because the
parse was done directly on an incomplete qapi-event.json), the generator
tries to treat it as a pointer to an otherwise unknown structure.
(Never mind the odd formatting of the space after the '*' - I believe
this pending patch fixes it:
https://lists.gnu.org/archive/html/qemu-devel/2014-06/msg02385.html).

This little exercise raises red flags for me - we probably ought to
enhance the code generators to error out instead of blindly act as if
unknown types are pointers.  But save it for another day - no need to
stall this series just to wait for a robustness improvement to the
generators.





Meanwhile, my suggestion of making qapi-event.json to be self-sufficient
is going to be a bit harder to test, but is still probably worth trying
(just moving common types into a common shared include).



  I think it is a issue about how to orgnize the .json files. There are
some common type defines needed for different .json files, in my series
they are needed both in qapi-schema.json and qapi-event.json. So to
make qapi-event.json self-sufficient, qapi-schema.json will be
insufficient. I considered this before, and thought it is better
to reorgnize .json files as:

  qapi-types.json
  | |
qapi-cmd.jsonqapi-event.json

  It is an adjusting work for existing code, So I didn't do that in my
series.



Re: [Qemu-devel] [PATCH V6 16/29] qapi event: convert RTC_CHANGE

2014-06-14 Thread Wenchao Xia

于 2014/6/14 5:27, Eric Blake 写道:

On 06/05/2014 06:22 AM, Wenchao Xia wrote:

This patch also eliminates build time warning caused by no caller
of monitor_qapi_event_throttle().


Again, my suggestion on 6/29 could avoid that warning; if you use that
workaround, don't clean it until 29/29, but you can drop this paragraph
of this commit.



Signed-off-by: Wenchao Xia 
---
  docs/qmp/qmp-events.txt |   16 
  hw/ppc/spapr_rtas.c |3 ++-
  hw/timer/mc146818rtc.c  |3 ++-
  include/sysemu/sysemu.h |2 --
  monitor.c   |4 +++-
  qapi-event.json |   13 +
  vl.c|9 -
  7 files changed, 20 insertions(+), 30 deletions(-)



Yay - the first event with data, so I get to see what the generator does.

The .h file shows this signature:


void qapi_event_send_rtc_change(int64_t offset,
 Error **errp);


and the .c has this code:


void qapi_event_send_rtc_change(int64_t offset,
 Error **errp)
{
 QDict *qmp;
 Error *local_err = NULL;
 QMPEventFuncEmit emit;
 QmpOutputVisitor *qov;
 Visitor *v;
 QObject *obj;

 emit = qmp_event_get_func_emit();
 if (!emit) {
 return;
 }

 qmp = qmp_event_build_dict("RTC_CHANGE");

 qov = qmp_output_visitor_new();
 g_assert(qov);

 v = qmp_output_get_visitor(qov);
 g_assert(v);

 /* Fake visit, as if all member are under a structure */


Grammar error; guess I have more comments on 3/29.


 visit_start_struct(v, NULL, "", "RTC_CHANGE", 0, &local_err);
 if (local_err) {
 goto clean;
 }


Hmm, qmp_output_start_struct() never sets errp.



 visit_type_int(v, &offset, "offset", &local_err);
 if (local_err) {
 goto clean;
 }


Likewise, qmp_output_type_int never sets errp.



 visit_end_struct(v, &local_err);
 if (local_err) {
 goto clean;
 }


And neither does qmp_end_struct.



 obj = qmp_output_get_qobject(qov);
 g_assert(obj != NULL);

 qdict_put_obj(qmp, "data", obj);
 emit(QAPI_EVENT_RTC_CHANGE, qmp, &local_err);


And I already mentioned earlier that the only implementation of the
emit() callback never sets local_err (and probably doesn't even need it
as a parameter).



  clean:
 qmp_output_visitor_cleanup(qov);
 error_propagate(errp, local_err);
 QDECREF(qmp);
}


If you change the earlier 3 instances to just use visit_...(,
&error_abort), you can completely ditch the local_err variable, drop the
clean: label, and overall have a much shorter generated function.



@@ -93,7 +94,7 @@ static void rtas_set_time_of_day(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
  tm.tm_sec = rtas_ld(args, 5);

  /* Just generate a monitor event for the change */
-rtc_change_mon_event(&tm);
+qapi_event_send_rtc_change(qemu_timedate_diff(&tm), NULL);
  spapr->rtc_offset = qemu_timedate_diff(&tm);


Eww. This makes me worry whether grabbing qemu_timedate_diff() two times
in a row may cause a different value to be reported than what is stored
locally.  Please grab it only once into a local variable, then copy that
value into both locations.

Once again, all callers of qapi_event_send_rtc_change() are passing a
NULL errp to silently ignore errors; and I just audited that no errors
happen anyways.



  Fixing it.


+++ b/monitor.c
@@ -612,6 +612,9 @@ static void monitor_qapi_event_throttle(QAPIEvent event, 
int64_t rate)

  static void monitor_qapi_event_init(void)
  {
+/* Limit RTC & BALLOON events to 1 per second */


Comment is a bit misleading until a later patch converts balloon events,...



  Oops, good catch, will fix it.


+monitor_qapi_event_throttle(QAPI_EVENT_RTC_CHANGE, 1000);
+
  qmp_event_set_func_emit(monitor_qapi_event_queue);
  }

@@ -737,7 +740,6 @@ monitor_protocol_event_throttle(MonitorEvent event,
  static void monitor_protocol_event_init(void)
  {
  /* Limit RTC & BALLOON events to 1 per second */
-monitor_protocol_event_throttle(QEVENT_RTC_CHANGE, 1000);
  monitor_protocol_event_throttle(QEVENT_BALLOON_CHANGE, 1000);
  monitor_protocol_event_throttle(QEVENT_WATCHDOG, 1000);


...furthermore, the OLD comment was wrong (it forgot about the watchdog
event).  You could get around that by rewording the comment to just say
'limit guest-triggerable events to 1 per second' without calling out
what those events are.


+# @RTC_CHANGE
+#
+# Emitted when the guest changes the RTC time.
+#
+# @offset: offset between base RTC clock (as specified by -rtc base), and
+#  new RTC clock value
+#
+# Since: 2.1


0.14.0






Re: [Qemu-devel] [PATCH V6 08/29] qapi event: convert SHUTDOWN

2014-06-14 Thread Wenchao Xia

于 2014/6/14 3:57, Eric Blake 写道:

On 06/05/2014 06:22 AM, Wenchao Xia wrote:

This patch also eliminates build time warning caused by
QAPI_EVENT_MAX = 0.


I still don't know why I wasn't seeing a warning for that, but agree
this cleans it up (or whichever event gets converted first, as there
aren't really any dependency restrictions in the order in which you do
conversions).  If you do follow my suggestion of adding a workaround in
6/29 to avoid build warnings, then don't undo it here, but save it until
29/29; that way, no one individual conversion is doing more work than
any other.



Signed-off-by: Wenchao Xia 
---
  docs/qmp/qmp-events.txt |   15 ---
  qapi-event.json |   12 
  vl.c|3 ++-
  3 files changed, 14 insertions(+), 16 deletions(-)


Yay - I finally have enough to see what code gets generated in 3/29.
The qapi-event.h header now has:

void qapi_event_send_shutdown(Error **errp);

extern const char *QAPIEvent_lookup[];
typedef enum QAPIEvent
{
 QAPI_EVENT_SHUTDOWN = 0,
 QAPI_EVENT_MAX = 1,
} QAPIEvent;


and the .c file has:

void qapi_event_send_shutdown(Error **errp)
{
 QDict *qmp;
 Error *local_err = NULL;
 QMPEventFuncEmit emit;
 emit = qmp_event_get_func_emit();
 if (!emit) {
 return;
 }

 qmp = qmp_event_build_dict("SHUTDOWN");

 emit(QAPI_EVENT_SHUTDOWN, qmp, &local_err);

 error_propagate(errp, local_err);
 QDECREF(qmp);
}


Looks good, for a data-free event (I guess I'll have to wait till later
in the series to see what gets generated for an event with data).  Hmm,
I wonder if patch 3/29 should have also modified docs/qapi-code-gen.txt
to show a sample generated function.


  Will add doc part.




-
-Emitted when the Virtual Machine is powered down.



+++ b/qapi-event.json
@@ -0,0 +1,12 @@
+##
+# @SHUTDOWN
+#
+# Emitted when the virtual machine shutdown, qemu terminated the emulation and
+# is about to exit.


Different wording than the text it replaces, and the grammar is a bit
unusual.  Maybe:

Emitted when the virtual machine has shut down, indicating that qemu is
about to exit.


  if (qemu_shutdown_requested()) {
  qemu_kill_report();
-monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
+qapi_event_send_shutdown(NULL);


Note that the two NULLs serve different purposes.  In the old code, NULL
meant there was no additional data.  In the new code, NULL indicates
that we are ignoring the possibility for error.  I wonder if it would be
better to pass &error_abort instead of NULL?  For that matter, I just
re-read 6/29 - the one implementation we have of an emit function
(monitor_qapi_event_queue) never sets errp.  Is it better to just
consider events as best-effort, and completely ditch the errp parameter
from the emit callback typedef in 2/29, since it looks like you intend
to pass NULL for all clients of the callback?


  It make things simple, I will remove &errp in next version.



Re: [Qemu-devel] [PATCH V6 06/29] monitor: add an implemention as qapi event emit method

2014-06-14 Thread Wenchao Xia

于 2014/6/14 3:04, Eric Blake 写道:

On 06/05/2014 06:22 AM, Wenchao Xia wrote:

In the subject: s/as/of/


Now monitor has been hooked on the new event mechanism, so the patches


s/Now/The/


later can convert event callers one by one. Most code are copied from


s/the patches later/that later patches/

s/are/is/


old monitor_protocol_* functions with some modification.

Note that two build time warnings will be raised after this patch. One is
caused by no caller of monitor_qapi_event_throttle(), the other one is
caused by QAPI_EVENT_MAX = 0. They will be fixed automatically after
full event conversion later.


I only got one of those two warnings, about the unused function.  What
compiler and options are you using to get a warning about
QAPI_EVENT_MAX?.  Furthermore, since the default 'configure' turns
warnings into errors, this would be a build-breaker that hurts 'git
bisect'.  I think it's easy enough to avoid, if you would please squash
this in:



  The QAPI_EVENT_MAX = 0 cause a warning for code:

monitor_qapi_event_throttle(QAPIEvent event, int64_t rate)
{

assert(event < QAPI_EVENT_MAX);
}

which is always false now. Perhaps change it as

assert((int)event < QAPI_EVENT_MAX);

?



diff --git i/monitor.c w/monitor.c
index 952e1cb..a593d17 100644
--- i/monitor.c
+++ w/monitor.c
@@ -594,6 +594,7 @@ static void monitor_qapi_event_handler(void *opaque)
   * more than 1 event will be emitted within @rate
   * milliseconds
   */
+__attribute__((unused)) /* FIXME remove once in use */
  static void monitor_qapi_event_throttle(QAPIEvent event, int64_t rate)
  {
  MonitorQAPIEventState *evstate;


You can then remove that attribute later in 29/29 when you delete
everything else about the older implementation.

At this point, I think we're racking up enough fixes to be worth a v7
respin (particularly since avoiding 'git bisect' breakage cannot be done
as a followup patch, but has to be done in-place in the series).



  Thanks for tipping, it is a good way to go.




Signed-off-by: Wenchao Xia 
---
  monitor.c|  128 +-
  trace-events |4 ++
  2 files changed, 131 insertions(+), 1 deletions(-)





+typedef struct MonitorQAPIEventState {
+QAPIEvent event;/* Event being tracked */
+int64_t rate;   /* Period over which to throttle. 0 to disable */
+int64_t last;   /* Time at which event was last emitted */


in what unit? [1]...


+QEMUTimer *timer;   /* Timer for handling delayed events */
+QObject *data;/* Event pending delayed dispatch */


Any reason the comments aren't aligned?


  Will fix.




+} MonitorQAPIEventState;
+
  struct Monitor {
  CharDriverState *chr;
  int mux_out;
@@ -489,6 +499,122 @@ static const char *monitor_event_names[] = {
  QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != QEVENT_MAX)

  static MonitorEventState monitor_event_state[QEVENT_MAX];
+static MonitorQAPIEventState monitor_qapi_event_state[QAPI_EVENT_MAX];


If you are still seeing a compiler warning about allocating an array of
size 0, you could likewise try this hack:

/* FIXME Hack a minimum array size until we have events */
static MonitorQAPIEventState monitor_qapi_event_state[QAPI_EVENT_MAX +
!QAPI_EVENT_MAX];

and likewise clean that up in 29/29


+static void
+monitor_qapi_event_queue(int event_kind, QDict *data, Error **errp)


This is not the usual formatting in qemu.


  Fixing it.




+{
+MonitorQAPIEventState *evstate;
+assert(event_kind < QAPI_EVENT_MAX);


This doesn't filter out negative values for event_kind.  Is it worth the
extra paranoia to either make event_kind unsigned, or to assert that
event_kind >= 0?



  Build waring will be raised for QAPI_EVENT_MAX = 0, same as above,
any better way to solve?


+QAPIEvent event = (QAPIEvent)event_kind;


Why are we casting here?  Would it not make more sense to change the
signature in patch 2/29 to use the enum type from the get-go?

typedef void (*QMPEventFuncEmit)(QAPIEvent event_kind, QDict *dict,
Error **errp);

and adjust the signature of this function to match



  Since QAPIEvent is generated by qapi-event.py, and they are
different in qemu code and test code, so there will be conflict
in test code which include qmp-event.h:
in qemu:
qmp-event.h include qapi-event.h
in test:
qmp-event.h include test-qapi-event.h
For simple I just used int type instead of QAPIEvent type.

  To use QAPIEvent in declaration, I think there would be some
tricks in test, and doc that using qapi-event.h define in
qmp-event.c may break test code, the encapsulation is not very goood.



+int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);


...[1] okay, it looks like 'rate' and 'last' are specified in
nanoseconds.  Worth documenting in their declaration above.
Particularly since [1]...


+static void monitor_qapi_event_handler(void *opaque)
+{

[Qemu-devel] [PATCH V6 10/29] qapi event: convert RESET

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 docs/qmp/qmp-events.txt |   12 
 qapi-event.json |9 +
 vl.c|2 +-
 3 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index ff2f30d..20e3151 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -264,18 +264,6 @@ Example:
  "data": { "node-name": "1.raw", "sector-num": 345435, "sector-count": 5 },
  "timestamp": { "seconds": 1344522075, "microseconds": 745528 } }
 
-RESET
--
-
-Emitted when the Virtual Machine is reseted.
-
-Data: None.
-
-Example:
-
-{ "event": "RESET",
-"timestamp": { "seconds": 1267041653, "microseconds": 9518 } }
-
 RESUME
 --
 
diff --git a/qapi-event.json b/qapi-event.json
index fbdbc7c..6f27555 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -20,3 +20,12 @@
 # Since: 2.1
 ##
 { 'event': 'POWERDOWN' }
+
+##
+# @RESET
+#
+# Emitted when the virtual machine is reset
+#
+# Since: 2.1
+##
+{ 'event': 'RESET' }
diff --git a/vl.c b/vl.c
index 69ad0e9..b95fc5e 100644
--- a/vl.c
+++ b/vl.c
@@ -1907,7 +1907,7 @@ void qemu_system_reset(bool report)
 qemu_devices_reset();
 }
 if (report) {
-monitor_protocol_event(QEVENT_RESET, NULL);
+qapi_event_send_reset(NULL);
 }
 cpu_synchronize_all_post_reset();
 }
-- 
1.7.1




[Qemu-devel] [PATCH V6 24/29] qapi event: convert VNC events

2014-06-05 Thread Wenchao Xia
Since VNC_CONNECTED, VNC_DISCONNECTED, VNC_INITIALIZED share some
common functions, converts them in one patch.

Signed-off-by: Wenchao Xia 
---
 docs/qmp/qmp-events.txt |   90 --
 qapi-event.json |   49 +
 ui/vnc.c|  111 ---
 ui/vnc.h|4 +-
 4 files changed, 108 insertions(+), 146 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index 101f207..37bc891 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -132,93 +132,3 @@ Example:
   "connection-id": 1804289383, "host": "127.0.0.1",
   "channel-id": 0, "tls": true}
 }}
-
-VNC_CONNECTED
--
-
-Emitted when a VNC client establishes a connection.
-
-Data:
-
-- "server": Server information (json-object)
-  - "host": IP address (json-string)
-  - "service": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-  - "auth": authentication method (json-string, optional)
-- "client": Client information (json-object)
-  - "host": IP address (json-string)
-  - "service": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-
-Example:
-
-{ "event": "VNC_CONNECTED",
-"data": {
-"server": { "auth": "sasl", "family": "ipv4",
-"service": "5901", "host": "0.0.0.0" },
-"client": { "family": "ipv4", "service": "58425",
-"host": "127.0.0.1" } },
-"timestamp": { "seconds": 1262976601, "microseconds": 975795 } }
-
-
-Note: This event is emitted before any authentication takes place, thus
-the authentication ID is not provided.
-
-VNC_DISCONNECTED
-
-
-Emitted when the connection is closed.
-
-Data:
-
-- "server": Server information (json-object)
-  - "host": IP address (json-string)
-  - "service": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-  - "auth": authentication method (json-string, optional)
-- "client": Client information (json-object)
-  - "host": IP address (json-string)
-  - "service": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-  - "x509_dname": TLS dname (json-string, optional)
-  - "sasl_username": SASL username (json-string, optional)
-
-Example:
-
-{ "event": "VNC_DISCONNECTED",
-"data": {
-"server": { "auth": "sasl", "family": "ipv4",
-"service": "5901", "host": "0.0.0.0" },
-"client": { "family": "ipv4", "service": "58425",
-"host": "127.0.0.1", "sasl_username": "luiz" } },
-"timestamp": { "seconds": 1262976601, "microseconds": 975795 } }
-
-VNC_INITIALIZED

-
-Emitted after authentication takes place (if any) and the VNC session is
-made active.
-
-Data:
-
-- "server": Server information (json-object)
-  - "host": IP address (json-string)
-  - "service": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-  - "auth": authentication method (json-string, optional)
-- "client": Client information (json-object)
-  - "host": IP address (json-string)
-  - "service": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-  - "x509_dname": TLS dname (json-string, optional)
-  - "sasl_username": SASL username (json-string, optional)
-
-Example:
-
-{ "event": "VNC_INITIALIZED",
-"data": {
-"server": { "auth": "sasl", "family": "ipv4",
-"service": "5901", "host": "0.0.0.0"},
-"client": { "family": "ipv4", "service": "46089",
-"host": "127.0.0.1", "sasl_username": "luiz" } },
-"timestamp": { "seconds": 1263475302, "microseconds&quo

[Qemu-devel] [PATCH V6 23/29] qapi event: convert NIC_RX_FILTER_CHANGED

2014-06-05 Thread Wenchao Xia
Param name is declared as optional, since in code it is an optional
one.

Signed-off-by: Wenchao Xia 
---
 docs/qmp/qmp-events.txt |   17 -
 hw/net/virtio-net.c |   13 +++--
 qapi-event.json |   15 +++
 3 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index c57d5df..101f207 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -32,23 +32,6 @@ Example:
 { "event": "GUEST_PANICKED",
  "data": { "action": "pause" } }
 
-NIC_RX_FILTER_CHANGED
--
-
-The event is emitted once until the query command is executed,
-the first event will always be emitted.
-
-Data:
-
-- "name": net client name (json-string)
-- "path": device path (json-string)
-
-{ "event": "NIC_RX_FILTER_CHANGED",
-  "data": { "name": "vnet0",
-"path": "/machine/peripheral/vnet0/virtio-backend" },
-  "timestamp": { "seconds": 1368697518, "microseconds": 326866 } }
-}
-
 QUORUM_FAILURE
 --
 
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 940a7cf..f6d3447 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -22,7 +22,7 @@
 #include "net/vhost_net.h"
 #include "hw/virtio/virtio-bus.h"
 #include "qapi/qmp/qjson.h"
-#include "monitor/monitor.h"
+#include "qapi-event.h"
 
 #define VIRTIO_NET_VM_VERSION11
 
@@ -196,19 +196,12 @@ static void virtio_net_set_link_status(NetClientState *nc)
 
 static void rxfilter_notify(NetClientState *nc)
 {
-QObject *event_data;
 VirtIONet *n = qemu_get_nic_opaque(nc);
 
 if (nc->rxfilter_notify_enabled) {
 gchar *path = object_get_canonical_path(OBJECT(n->qdev));
-if (n->netclient_name) {
-event_data = qobject_from_jsonf("{ 'name': %s, 'path': %s }",
-n->netclient_name, path);
-} else {
-event_data = qobject_from_jsonf("{ 'path': %s }", path);
-}
-monitor_protocol_event(QEVENT_NIC_RX_FILTER_CHANGED, event_data);
-qobject_decref(event_data);
+qapi_event_send_nic_rx_filter_changed(!!n->netclient_name,
+  n->netclient_name, path, NULL);
 g_free(path);
 
 /* disable event notification to avoid events flooding */
diff --git a/qapi-event.json b/qapi-event.json
index bc47104..0f840e4 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -268,3 +268,18 @@
 ##
 { 'event': 'BLOCK_JOB_READY',
   'data': { 'device': 'str' } }
+
+##
+# @NIC_RX_FILTER_CHANGED
+#
+# Emitted once until the 'query-rx-filter' command is executed, the first event
+# will always be emitted
+#
+# @name: #optional, net client name
+#
+# @path: device path
+#
+# Since: 2.1
+##
+{ 'event': 'NIC_RX_FILTER_CHANGED',
+  'data': { '*name': 'str', 'path': 'str' } }
-- 
1.7.1




[Qemu-devel] [PATCH V6 27/29] qapi event: convert GUEST_PANICKED

2014-06-05 Thread Wenchao Xia
'monitor.h' is still included in target-s390x/kvm.c, since I have
no good way to verify whether other code need it on my x86 host.

Signed-off-by: Wenchao Xia 
---
 docs/qmp/qmp-events.txt |   14 --
 hw/misc/pvpanic.c   |   13 ++---
 qapi-event.json |   12 
 qapi-schema.json|   12 
 target-s390x/kvm.c  |8 +++-
 5 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index 1b0e25f..adf45d3 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -1,20 +1,6 @@
QEMU Machine Protocol Events

 
-GUEST_PANICKED
---
-
-Emitted when guest OS panic is detected.
-
-Data:
-
-- "action": Action that has been taken (json-string, currently always "pause").
-
-Example:
-
-{ "event": "GUEST_PANICKED",
- "data": { "action": "pause" } }
-
 QUORUM_FAILURE
 --
 
diff --git a/hw/misc/pvpanic.c b/hw/misc/pvpanic.c
index 5377fee..d396b74 100644
--- a/hw/misc/pvpanic.c
+++ b/hw/misc/pvpanic.c
@@ -14,12 +14,12 @@
 
 #include "qapi/qmp/qobject.h"
 #include "qapi/qmp/qjson.h"
-#include "monitor/monitor.h"
 #include "sysemu/sysemu.h"
 #include "qemu/log.h"
 
 #include "hw/nvram/fw_cfg.h"
 #include "hw/i386/pc.h"
+#include "qapi-event.h"
 
 /* The bit of supported pv event */
 #define PVPANIC_F_PANICKED  0
@@ -31,15 +31,6 @@
 #define ISA_PVPANIC_DEVICE(obj)\
 OBJECT_CHECK(PVPanicState, (obj), TYPE_ISA_PVPANIC_DEVICE)
 
-static void panicked_mon_event(const char *action)
-{
-QObject *data;
-
-data = qobject_from_jsonf("{ 'action': %s }", action);
-monitor_protocol_event(QEVENT_GUEST_PANICKED, data);
-qobject_decref(data);
-}
-
 static void handle_event(int event)
 {
 static bool logged;
@@ -50,7 +41,7 @@ static void handle_event(int event)
 }
 
 if (event & PVPANIC_PANICKED) {
-panicked_mon_event("pause");
+qapi_event_send_guest_panicked(GUEST_PANICK_ACTION_PAUSE, NULL);
 vm_stop(RUN_STATE_GUEST_PANICKED);
 return;
 }
diff --git a/qapi-event.json b/qapi-event.json
index 93f9eeb..6bfc2a7 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -400,3 +400,15 @@
 ##
 { 'event': 'BALLOON_CHANGE',
   'data': { 'actual': 'int' } }
+
+##
+# @GUEST_PANICKED
+#
+# Emitted when guest OS panic is detected
+#
+# @action: action that has been taken, currently always "pause"
+#
+# Since: 2.1
+##
+{ 'event': 'GUEST_PANICKED',
+  'data': { 'action': 'GuestPanickAction' } }
diff --git a/qapi-schema.json b/qapi-schema.json
index 23be2bf..badc1bf 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4837,4 +4837,16 @@
 { 'enum': 'IoOperationType',
   'data': [ 'read', 'write' ] }
 
+##
+# @GuestPanickAction
+#
+# An enumeration of the actions taken when guest OS panic is detected
+#
+# @pause: system pauses
+#
+# Since: 2.1
+##
+{ 'enum': 'GuestPanickAction',
+  'data': [ 'pause' ] }
+
 { 'include': 'qapi-event.json' }
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 7a07f9d..2212583 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -38,6 +38,7 @@
 #include "monitor/monitor.h"
 #include "exec/gdbstub.h"
 #include "trace.h"
+#include "qapi-event.h"
 
 /* #define DEBUG_KVM */
 
@@ -891,11 +892,8 @@ static int handle_intercept(S390CPU *cpu)
 if (is_special_wait_psw(cs)) {
 qemu_system_shutdown_request();
 } else {
-QObject *data;
-
-data = qobject_from_jsonf("{ 'action': %s }", "pause");
-monitor_protocol_event(QEVENT_GUEST_PANICKED, data);
-qobject_decref(data);
+qapi_event_send_guest_panicked(GUEST_PANICK_ACTION_PAUSE,
+   NULL);
 vm_stop(RUN_STATE_GUEST_PANICKED);
 }
 }
-- 
1.7.1




[Qemu-devel] [PATCH V6 16/29] qapi event: convert RTC_CHANGE

2014-06-05 Thread Wenchao Xia
This patch also eliminates build time warning caused by no caller
of monitor_qapi_event_throttle().

Signed-off-by: Wenchao Xia 
---
 docs/qmp/qmp-events.txt |   16 
 hw/ppc/spapr_rtas.c |3 ++-
 hw/timer/mc146818rtc.c  |3 ++-
 include/sysemu/sysemu.h |2 --
 monitor.c   |4 +++-
 qapi-event.json |   13 +
 vl.c|9 -
 7 files changed, 20 insertions(+), 30 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index 3d82db4..8cad3e7 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -264,22 +264,6 @@ Example:
  "data": { "node-name": "1.raw", "sector-num": 345435, "sector-count": 5 },
  "timestamp": { "seconds": 1344522075, "microseconds": 745528 } }
 
-RTC_CHANGE
---
-
-Emitted when the guest changes the RTC time.
-
-Data:
-
-- "offset": Offset between base RTC clock (as specified by -rtc base), and
-new RTC clock value (json-number)
-
-Example:
-
-{ "event": "RTC_CHANGE",
-"data": { "offset": 78 },
-"timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
-
 SPICE_CONNECTED, SPICE_DISCONNECTED
 ---
 
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index ea4a2b2..7e4cffe 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -32,6 +32,7 @@
 
 #include "hw/ppc/spapr.h"
 #include "hw/ppc/spapr_vio.h"
+#include "qapi-event.h"
 
 #include 
 
@@ -93,7 +94,7 @@ static void rtas_set_time_of_day(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 tm.tm_sec = rtas_ld(args, 5);
 
 /* Just generate a monitor event for the change */
-rtc_change_mon_event(&tm);
+qapi_event_send_rtc_change(qemu_timedate_diff(&tm), NULL);
 spapr->rtc_offset = qemu_timedate_diff(&tm);
 
 rtas_st(rets, 0, RTAS_OUT_SUCCESS);
diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index df54546..9bb3708 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -26,6 +26,7 @@
 #include "sysemu/sysemu.h"
 #include "hw/timer/mc146818rtc.h"
 #include "qapi/visitor.h"
+#include "qapi-event.h"
 
 #ifdef TARGET_I386
 #include "hw/i386/apic.h"
@@ -530,7 +531,7 @@ static void rtc_set_time(RTCState *s)
 s->base_rtc = mktimegm(&tm);
 s->last_update = qemu_clock_get_ns(rtc_clock);
 
-rtc_change_mon_event(&tm);
+qapi_event_send_rtc_change(qemu_timedate_diff(&tm), NULL);
 }
 
 static void rtc_set_cmos(RTCState *s, const struct tm *tm)
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index ba5c7f8..0046b27 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -189,8 +189,6 @@ void do_usb_add(Monitor *mon, const QDict *qdict);
 void do_usb_del(Monitor *mon, const QDict *qdict);
 void usb_info(Monitor *mon, const QDict *qdict);
 
-void rtc_change_mon_event(struct tm *tm);
-
 void add_boot_device_path(int32_t bootindex, DeviceState *dev,
   const char *suffix);
 char *get_boot_devices_list(size_t *size, bool ignore_suffixes);
diff --git a/monitor.c b/monitor.c
index e122381..e6d32c2 100644
--- a/monitor.c
+++ b/monitor.c
@@ -612,6 +612,9 @@ static void monitor_qapi_event_throttle(QAPIEvent event, 
int64_t rate)
 
 static void monitor_qapi_event_init(void)
 {
+/* Limit RTC & BALLOON events to 1 per second */
+monitor_qapi_event_throttle(QAPI_EVENT_RTC_CHANGE, 1000);
+
 qmp_event_set_func_emit(monitor_qapi_event_queue);
 }
 
@@ -737,7 +740,6 @@ monitor_protocol_event_throttle(MonitorEvent event,
 static void monitor_protocol_event_init(void)
 {
 /* Limit RTC & BALLOON events to 1 per second */
-monitor_protocol_event_throttle(QEVENT_RTC_CHANGE, 1000);
 monitor_protocol_event_throttle(QEVENT_BALLOON_CHANGE, 1000);
 monitor_protocol_event_throttle(QEVENT_WATCHDOG, 1000);
 /* limit the rate of quorum events to avoid hammering the management */
diff --git a/qapi-event.json b/qapi-event.json
index 32ac571..dc20bb4 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -78,3 +78,16 @@
 # Since: 2.1
 ##
 { 'event': 'WAKEUP' }
+
+##
+# @RTC_CHANGE
+#
+# Emitted when the guest changes the RTC time.
+#
+# @offset: offset between base RTC clock (as specified by -rtc base), and
+#  new RTC clock value
+#
+# Since: 2.1
+##
+{ 'event': 'RTC_CHANGE',
+  'data': { 'offset': 'int' } }
diff --git a/vl.c b/vl.c
index b8ad1df..cb56714 100644
--- a/vl.c
+++ b/vl.c
@@ -727,15 +727,6 @@ int qemu_timedate_diff(struct tm *tm)
 return seconds - time(NULL);
 }
 
-void rtc_change_mon_event(struct tm *tm)
-{
-QObject *data;
-
-data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
-monitor_protocol_event(QEVENT_RTC_CHANGE, data);
-qobject_decref(data);
-}
-
 static void configure_rtc_date_offset(const char *startdate, int legacy)
 {
 time_t rtc_start_date;
-- 
1.7.1




[Qemu-devel] [PATCH V6 19/29] qapi event: convert DEVICE_TRAY_MOVED

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 block.c |   21 +++--
 docs/qmp/qmp-events.txt |   18 --
 qapi-event.json |   15 +++
 3 files changed, 22 insertions(+), 32 deletions(-)

diff --git a/block.c b/block.c
index 84ad945..52f4580 100644
--- a/block.c
+++ b/block.c
@@ -35,6 +35,7 @@
 #include "block/qapi.h"
 #include "qmp-commands.h"
 #include "qemu/timer.h"
+#include "qapi-event.h"
 
 #ifdef CONFIG_BSD
 #include 
@@ -2162,17 +2163,6 @@ void bdrv_emit_qmp_error_event(const BlockDriverState 
*bdrv,
 qobject_decref(data);
 }
 
-static void bdrv_emit_qmp_eject_event(BlockDriverState *bs, bool ejected)
-{
-QObject *data;
-
-data = qobject_from_jsonf("{ 'device': %s, 'tray-open': %i }",
-  bdrv_get_device_name(bs), ejected);
-monitor_protocol_event(QEVENT_DEVICE_TRAY_MOVED, data);
-
-qobject_decref(data);
-}
-
 static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
 {
 if (bs->dev_ops && bs->dev_ops->change_media_cb) {
@@ -2180,11 +2170,13 @@ static void bdrv_dev_change_media_cb(BlockDriverState 
*bs, bool load)
 bs->dev_ops->change_media_cb(bs->dev_opaque, load);
 if (tray_was_closed) {
 /* tray open */
-bdrv_emit_qmp_eject_event(bs, true);
+qapi_event_send_device_tray_moved(bdrv_get_device_name(bs),
+  true, NULL);
 }
 if (load) {
 /* tray close */
-bdrv_emit_qmp_eject_event(bs, false);
+qapi_event_send_device_tray_moved(bdrv_get_device_name(bs),
+  false, NULL);
 }
 }
 }
@@ -5173,7 +5165,8 @@ void bdrv_eject(BlockDriverState *bs, bool eject_flag)
 }
 
 if (bs->device_name[0] != '\0') {
-bdrv_emit_qmp_eject_event(bs, eject_flag);
+qapi_event_send_device_tray_moved(bdrv_get_device_name(bs),
+  eject_flag, NULL);
 }
 }
 
diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index fda68df..1ee6f53 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -158,24 +158,6 @@ Example:
 Note: The "ready to complete" status is always reset by a BLOCK_JOB_ERROR
 event.
 
-DEVICE_TRAY_MOVED
--
-
-It's emitted whenever the tray of a removable device is moved by the guest
-or by HMP/QMP commands.
-
-Data:
-
-- "device": device name (json-string)
-- "tray-open": true if the tray has been opened or false if it has been closed
-   (json-bool)
-
-{ "event": "DEVICE_TRAY_MOVED",
-  "data": { "device": "ide1-cd0",
-"tray-open": true
-  },
-  "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
-
 GUEST_PANICKED
 --
 
diff --git a/qapi-event.json b/qapi-event.json
index fc83fed..c2c65f9 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -122,3 +122,18 @@
 ##
 { 'event': 'DEVICE_DELETED',
   'data': { '*device': 'str', 'path': 'str' } }
+
+##
+# @DEVICE_TRAY_MOVED
+#
+# Emitted whenever the tray of a removable device is moved by the guest or by
+# HMP/QMP commands
+#
+# @device: device name
+#
+# @tray-open: true if the tray has been opened or false if it has been closed
+#
+# Since: 2.1
+##
+{ 'event': 'DEVICE_TRAY_MOVED',
+  'data': { 'device': 'str', 'tray-open': 'bool' } }
-- 
1.7.1




[Qemu-devel] [PATCH V6 01/29] os-posix: include sys/time.h

2014-06-05 Thread Wenchao Xia
Since gettimeofday() is used in this header file as a macro define,
include the function's define header file, to avoid compile warning
when other file include os-posix.h.

Signed-off-by: Wenchao Xia 
Reviewed-by: Eric Blake 
---
 include/sysemu/os-posix.h |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
index 25d0b2a..f131521 100644
--- a/include/sysemu/os-posix.h
+++ b/include/sysemu/os-posix.h
@@ -26,6 +26,8 @@
 #ifndef QEMU_OS_POSIX_H
 #define QEMU_OS_POSIX_H
 
+#include 
+
 void os_set_line_buffering(void);
 void os_set_proc_name(const char *s);
 void os_setup_signal_handling(void);
-- 
1.7.1




[Qemu-devel] [PATCH V6 21/29] qapi event: convert BLOCK_IMAGE_CORRUPTED

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 block/qcow2-refcount.c  |   14 --
 docs/qmp/qmp-events.txt |   22 --
 qapi-event.json |   22 ++
 3 files changed, 30 insertions(+), 28 deletions(-)

diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 9507aef..2fca5a1 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -27,6 +27,7 @@
 #include "block/qcow2.h"
 #include "qemu/range.h"
 #include "qapi/qmp/types.h"
+#include "qapi-event.h"
 
 static int64_t alloc_clusters_noref(BlockDriverState *bs, uint64_t size);
 static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
@@ -1807,7 +1808,6 @@ int qcow2_pre_write_overlap_check(BlockDriverState *bs, 
int ign, int64_t offset,
 } else if (ret > 0) {
 int metadata_ol_bitnr = ffs(ret) - 1;
 char *message;
-QObject *data;
 
 assert(metadata_ol_bitnr < QCOW2_OL_MAX_BITNR);
 
@@ -1816,12 +1816,14 @@ int qcow2_pre_write_overlap_check(BlockDriverState *bs, 
int ign, int64_t offset,
 metadata_ol_names[metadata_ol_bitnr]);
 message = g_strdup_printf("Prevented %s overwrite",
 metadata_ol_names[metadata_ol_bitnr]);
-data = qobject_from_jsonf("{ 'device': %s, 'msg': %s, 'offset': %"
-PRId64 ", 'size': %" PRId64 " }", bs->device_name, message,
-offset, size);
-monitor_protocol_event(QEVENT_BLOCK_IMAGE_CORRUPTED, data);
+qapi_event_send_block_image_corrupted(bdrv_get_device_name(bs),
+  message,
+  true,
+  offset,
+  true,
+  size,
+  NULL);
 g_free(message);
-qobject_decref(data);
 
 qcow2_mark_corrupt(bs);
 bs->drv = NULL; /* make BDS unusable */
diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index f67a9ec..eec3955 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -18,28 +18,6 @@ Example:
 "data": { "actual": 944766976 },
 "timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
 
-BLOCK_IMAGE_CORRUPTED
--
-
-Emitted when a disk image is being marked corrupt.
-
-Data:
-
-- "device": Device name (json-string)
-- "msg":Informative message (e.g., reason for the corruption) (json-string)
-- "offset": If the corruption resulted from an image access, this is the access
-offset into the image (json-int)
-- "size":   If the corruption resulted from an image access, this is the access
-size (json-int)
-
-Example:
-
-{ "event": "BLOCK_IMAGE_CORRUPTED",
-"data": { "device": "ide0-hd0",
-"msg": "Prevented active L1 table overwrite", "offset": 196608,
-"size": 65536 },
-"timestamp": { "seconds": 1378126126, "microseconds": 966463 } }
-
 BLOCK_JOB_CANCELLED
 ---
 
diff --git a/qapi-event.json b/qapi-event.json
index c889dbf..640eaa0 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -159,6 +159,28 @@
 'action': 'BlockErrorAction' } }
 
 ##
+# @BLOCK_IMAGE_CORRUPTED
+#
+# Emitted when a disk image is being marked corrupt
+#
+# @device: device name
+#
+# @msg: informative message, for example, reason for the corruption
+#
+# @offset: #optional, if the corruption resulted from an image access, this is
+#  the access offset into the image
+# @size: #optional, if the corruption resulted from an image access, this is
+#the access size
+#
+# Since: 2.1
+##
+{ 'event': 'BLOCK_IMAGE_CORRUPTED',
+  'data': { 'device' : 'str',
+'msg': 'str',
+'*offset': 'int',
+'*size'  : 'int' } }
+
+##
 # @BLOCK_JOB_ERROR
 #
 # Emitted when a block job encounters an error
-- 
1.7.1




[Qemu-devel] [PATCH V6 17/29] qapi event: convert WATCHDOG

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 docs/qmp/qmp-events.txt |   19 ---
 hw/watchdog/watchdog.c  |   23 +++
 monitor.c   |2 +-
 qapi-event.json |   15 +++
 qapi-schema.json|   24 
 5 files changed, 47 insertions(+), 36 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index 8cad3e7..df15dc8 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -415,22 +415,3 @@ Example:
 "client": { "family": "ipv4", "service": "46089",
 "host": "127.0.0.1", "sasl_username": "luiz" } },
 "timestamp": { "seconds": 1263475302, "microseconds": 150772 } }
-
-WATCHDOG
-
-
-Emitted when the watchdog device's timer is expired.
-
-Data:
-
-- "action": Action that has been taken, it's one of the following 
(json-string):
-"reset", "shutdown", "poweroff", "pause", "debug", or "none"
-
-Example:
-
-{ "event": "WATCHDOG",
- "data": { "action": "reset" },
- "timestamp": { "seconds": 1267061043, "microseconds": 959568 } }
-
-Note: If action is "reset", "shutdown", or "pause" the WATCHDOG event is
-followed respectively by the RESET, SHUTDOWN, or STOP events.
diff --git a/hw/watchdog/watchdog.c b/hw/watchdog/watchdog.c
index f28161b..9284d3f 100644
--- a/hw/watchdog/watchdog.c
+++ b/hw/watchdog/watchdog.c
@@ -24,9 +24,9 @@
 #include "qemu/config-file.h"
 #include "qemu/queue.h"
 #include "qapi/qmp/types.h"
-#include "monitor/monitor.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/watchdog.h"
+#include "qapi-event.h"
 
 /* Possible values for action parameter. */
 #define WDT_RESET1 /* Hard reset. */
@@ -101,15 +101,6 @@ int select_watchdog_action(const char *p)
 return 0;
 }
 
-static void watchdog_mon_event(const char *action)
-{
-QObject *data;
-
-data = qobject_from_jsonf("{ 'action': %s }", action);
-monitor_protocol_event(QEVENT_WATCHDOG, data);
-qobject_decref(data);
-}
-
 /* This actually performs the "action" once a watchdog has expired,
  * ie. reboot, shutdown, exit, etc.
  */
@@ -117,31 +108,31 @@ void watchdog_perform_action(void)
 {
 switch(watchdog_action) {
 case WDT_RESET: /* same as 'system_reset' in monitor */
-watchdog_mon_event("reset");
+qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_RESET, NULL);
 qemu_system_reset_request();
 break;
 
 case WDT_SHUTDOWN:  /* same as 'system_powerdown' in monitor */
-watchdog_mon_event("shutdown");
+qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_SHUTDOWN, NULL);
 qemu_system_powerdown_request();
 break;
 
 case WDT_POWEROFF:  /* same as 'quit' command in monitor */
-watchdog_mon_event("poweroff");
+qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_POWEROFF, NULL);
 exit(0);
 
 case WDT_PAUSE: /* same as 'stop' command in monitor */
-watchdog_mon_event("pause");
+qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_PAUSE, NULL);
 vm_stop(RUN_STATE_WATCHDOG);
 break;
 
 case WDT_DEBUG:
-watchdog_mon_event("debug");
+qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_DEBUG, NULL);
 fprintf(stderr, "watchdog: timer fired\n");
 break;
 
 case WDT_NONE:
-watchdog_mon_event("none");
+qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_NONE, NULL);
 break;
 }
 }
diff --git a/monitor.c b/monitor.c
index e6d32c2..cae60ab 100644
--- a/monitor.c
+++ b/monitor.c
@@ -614,6 +614,7 @@ static void monitor_qapi_event_init(void)
 {
 /* Limit RTC & BALLOON events to 1 per second */
 monitor_qapi_event_throttle(QAPI_EVENT_RTC_CHANGE, 1000);
+monitor_qapi_event_throttle(QAPI_EVENT_WATCHDOG, 1000);
 
 qmp_event_set_func_emit(monitor_qapi_event_queue);
 }
@@ -741,7 +742,6 @@ static void monitor_protocol_event_init(void)
 {
 /* Limit RTC & BALLOON events to 1 per second */
 monitor_protocol_event_throttle(QEVENT_BALLOON_CHANGE, 1000);
-monitor_protocol_event_throttle(QEVENT_WATCHDOG, 1000);
 /* limit the rate of quorum events to avoid hammering the management */
 monitor_protocol_event_throttle(QEVENT_QUORUM_REPORT_BAD, 1000);
 monitor_protocol_event_throttle(QEVENT_QUORUM_FAILURE, 1000);
diff --git a/qapi-event.json b/qapi-event.json
index dc20bb4..640f8

[Qemu-devel] [PATCH V6 25/29] qapi event: convert SPICE events

2014-06-05 Thread Wenchao Xia
SPICE_INITIALIZED, SPICE_CONNECTED, SPICE_DISCONNECTED and
SPICE_MIGRATE_COMPLETED are converted in one patch, since they
use some common functions. inet_strfamily() is removed since no
more caller exist now.

Note that there is no existing doc for SPICE_MIGRATE_COMPLETED
in docs/qmp/qmp-events.txt before this patch.

Signed-off-by: Wenchao Xia 
---
 docs/qmp/qmp-events.txt |   62 -
 include/qemu/sockets.h  |1 -
 qapi-event.json |   55 +
 ui/spice-core.c |   70 ---
 util/qemu-sockets.c |   10 ---
 5 files changed, 91 insertions(+), 107 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index 37bc891..4fbc3de 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -70,65 +70,3 @@ Example:
 { "event": "QUORUM_REPORT_BAD",
  "data": { "node-name": "1.raw", "sector-num": 345435, "sector-count": 5 },
  "timestamp": { "seconds": 1344522075, "microseconds": 745528 } }
-
-SPICE_CONNECTED, SPICE_DISCONNECTED

-
-Emitted when a SPICE client connects or disconnects.
-
-Data:
-
-- "server": Server information (json-object)
-  - "host": IP address (json-string)
-  - "port": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-- "client": Client information (json-object)
-  - "host": IP address (json-string)
-  - "port": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-
-Example:
-
-{ "timestamp": {"seconds": 1290688046, "microseconds": 388707},
-  "event": "SPICE_CONNECTED",
-  "data": {
-"server": { "port": "5920", "family": "ipv4", "host": "127.0.0.1"},
-"client": {"port": "52873", "family": "ipv4", "host": "127.0.0.1"}
-}}
-
-SPICE_INITIALIZED
--
-
-Emitted after initial handshake and authentication takes place (if any)
-and the SPICE channel is up'n'running
-
-Data:
-
-- "server": Server information (json-object)
-  - "host": IP address (json-string)
-  - "port": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-  - "auth": authentication method (json-string, optional)
-- "client": Client information (json-object)
-  - "host": IP address (json-string)
-  - "port": port number (json-string)
-  - "family": address family (json-string, "ipv4" or "ipv6")
-  - "connection-id": spice connection id.  All channels with the same id
- belong to the same spice session (json-int)
-  - "channel-type": channel type.  "1" is the main control channel, filter for
-this one if you want track spice sessions only (json-int)
-  - "channel-id": channel id.  Usually "0", might be different needed when
-  multiple channels of the same type exist, such as multiple
-  display channels in a multihead setup (json-int)
-  - "tls": whevener the channel is encrypted (json-bool)
-
-Example:
-
-{ "timestamp": {"seconds": 1290688046, "microseconds": 417172},
-  "event": "SPICE_INITIALIZED",
-  "data": {"server": {"auth": "spice", "port": "5921",
-  "family": "ipv4", "host": "127.0.0.1"},
-   "client": {"port": "49004", "family": "ipv4", "channel-type": 3,
-  "connection-id": 1804289383, "host": "127.0.0.1",
-  "channel-id": 0, "tls": true}
-}}
diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
index af24669..fdbb196 100644
--- a/include/qemu/sockets.h
+++ b/include/qemu/sockets.h
@@ -61,7 +61,6 @@ int inet_nonblocking_connect(const char *str,
  void *opaque, Error **errp);
 
 int inet_dgram_opts(QemuOpts *opts, Error **errp);
-const char *inet_strfamily(int family);
 NetworkAddressFamily inet_netfamily(int family);
 
 int unix_listen_opts(QemuOpts *opts, Error **errp);
diff --git a/qapi-event.json b/qapi-event.json
index e4cb2d0..0849584 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -332,3 +332,58 @@
 { 'event': 'VNC_DISCON

[Qemu-devel] [PATCH V6 28/29] qapi event: convert QUORUM events

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 block/quorum.c  |   25 -
 docs/qmp/qmp-events.txt |   41 -
 monitor.c   |6 +++---
 qapi-event.json |   38 ++
 4 files changed, 49 insertions(+), 61 deletions(-)
 delete mode 100644 docs/qmp/qmp-events.txt

diff --git a/block/quorum.c b/block/quorum.c
index ecec3a5..5d1c3dc 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -17,6 +17,7 @@
 #include 
 #include "block/block_int.h"
 #include "qapi/qmp/qjson.h"
+#include "qapi-event.h"
 
 #define HASH_LENGTH 32
 
@@ -198,32 +199,22 @@ static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s,
 
 static void quorum_report_bad(QuorumAIOCB *acb, char *node_name, int ret)
 {
-QObject *data;
-assert(node_name);
-data = qobject_from_jsonf("{ 'node-name': %s"
-  ", 'sector-num': %" PRId64
-  ", 'sectors-count': %d }",
-  node_name, acb->sector_num, acb->nb_sectors);
+const char *msg = NULL;
 if (ret < 0) {
-QDict *dict = qobject_to_qdict(data);
-qdict_put(dict, "error", qstring_from_str(strerror(-ret)));
+msg = strerror(-ret);
 }
-monitor_protocol_event(QEVENT_QUORUM_REPORT_BAD, data);
-qobject_decref(data);
+qapi_event_send_quorum_report_bad(!!msg, msg, node_name,
+  acb->sector_num, acb->nb_sectors, NULL);
 }
 
 static void quorum_report_failure(QuorumAIOCB *acb)
 {
-QObject *data;
 const char *reference = acb->common.bs->device_name[0] ?
 acb->common.bs->device_name :
 acb->common.bs->node_name;
-data = qobject_from_jsonf("{ 'reference': %s"
-  ", 'sector-num': %" PRId64
-  ", 'sectors-count': %d }",
-  reference, acb->sector_num, acb->nb_sectors);
-monitor_protocol_event(QEVENT_QUORUM_FAILURE, data);
-qobject_decref(data);
+
+qapi_event_send_quorum_failure(reference, acb->sector_num,
+   acb->nb_sectors, NULL);
 }
 
 static int quorum_vote_error(QuorumAIOCB *acb);
diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
deleted file mode 100644
index adf45d3..000
--- a/docs/qmp/qmp-events.txt
+++ /dev/null
@@ -1,41 +0,0 @@
-   QEMU Machine Protocol Events
-   
-
-QUORUM_FAILURE
---
-
-Emitted by the Quorum block driver if it fails to establish a quorum.
-
-Data:
-
-- "reference":device name if defined else node name.
-- "sector-num":   Number of the first sector of the failed read operation.
-- "sector-count": Failed read operation sector count.
-
-Example:
-
-{ "event": "QUORUM_FAILURE",
- "data": { "reference": "usr1", "sector-num": 345435, "sector-count": 5 },
- "timestamp": { "seconds": 1344522075, "microseconds": 745528 } }
-
-QUORUM_REPORT_BAD
--
-
-Emitted to report a corruption of a Quorum file.
-
-Data:
-
-- "error":Error message (json-string, optional)
-  Only present on failure.  This field contains a 
human-readable
-  error message.  There are no semantics other than that the
-  block layer reported an error and clients should not try to
-  interpret the error string.
-- "node-name":The graph node name of the block driver state.
-- "sector-num":   Number of the first sector of the failed read operation.
-- "sector-count": Failed read operation sector count.
-
-Example:
-
-{ "event": "QUORUM_REPORT_BAD",
- "data": { "node-name": "1.raw", "sector-num": 345435, "sector-count": 5 },
- "timestamp": { "seconds": 1344522075, "microseconds": 745528 } }
diff --git a/monitor.c b/monitor.c
index b0a54cf..aaf6f9d 100644
--- a/monitor.c
+++ b/monitor.c
@@ -616,6 +616,9 @@ static void monitor_qapi_event_init(void)
 monitor_qapi_event_throttle(QAPI_EVENT_RTC_CHANGE, 1000);
 monitor_qapi_event_throttle(QAPI_EVENT_WATCHDOG, 1000);
 monitor_qapi_event_throttle(QAPI_EVENT_BALLOON_CHANGE, 1000);
+/* limit the rate of quorum events to avoid hammering the management */
+monitor_qapi_event_throttle(QAPI_EVENT_QUORUM_REPORT_BAD, 1000);
+monitor_qapi_event_throttle(QAPI_EVENT_QUORUM_FAILURE, 1000);
 
 qmp_event_set_func_emit(monitor_qapi_event_queue);
 }
@@ -741,

[Qemu-devel] [PATCH V6 29/29] qapi event: clean up

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 include/monitor/monitor.h  |   40 
 monitor.c  |  216 +---
 stubs/Makefile.objs|1 -
 stubs/mon-protocol-event.c |6 --
 4 files changed, 3 insertions(+), 260 deletions(-)
 delete mode 100644 stubs/mon-protocol-event.c

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 1c1f56f..3d6929d 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -19,48 +19,8 @@ extern Monitor *default_mon;
 /* flags for monitor commands */
 #define MONITOR_CMD_ASYNC   0x0001
 
-/* QMP events */
-typedef enum MonitorEvent {
-QEVENT_SHUTDOWN,
-QEVENT_RESET,
-QEVENT_POWERDOWN,
-QEVENT_STOP,
-QEVENT_RESUME,
-QEVENT_VNC_CONNECTED,
-QEVENT_VNC_INITIALIZED,
-QEVENT_VNC_DISCONNECTED,
-QEVENT_BLOCK_IO_ERROR,
-QEVENT_RTC_CHANGE,
-QEVENT_WATCHDOG,
-QEVENT_SPICE_CONNECTED,
-QEVENT_SPICE_INITIALIZED,
-QEVENT_SPICE_DISCONNECTED,
-QEVENT_BLOCK_JOB_COMPLETED,
-QEVENT_BLOCK_JOB_CANCELLED,
-QEVENT_BLOCK_JOB_ERROR,
-QEVENT_BLOCK_JOB_READY,
-QEVENT_DEVICE_DELETED,
-QEVENT_DEVICE_TRAY_MOVED,
-QEVENT_NIC_RX_FILTER_CHANGED,
-QEVENT_SUSPEND,
-QEVENT_SUSPEND_DISK,
-QEVENT_WAKEUP,
-QEVENT_BALLOON_CHANGE,
-QEVENT_SPICE_MIGRATE_COMPLETED,
-QEVENT_GUEST_PANICKED,
-QEVENT_BLOCK_IMAGE_CORRUPTED,
-QEVENT_QUORUM_FAILURE,
-QEVENT_QUORUM_REPORT_BAD,
-
-/* Add to 'monitor_event_names' array in monitor.c when
- * defining new events here */
-
-QEVENT_MAX,
-} MonitorEvent;
-
 int monitor_cur_is_qmp(void);
 
-void monitor_protocol_event(MonitorEvent event, QObject *data);
 void monitor_init(CharDriverState *chr, int flags);
 
 int monitor_suspend(Monitor *mon);
diff --git a/monitor.c b/monitor.c
index aaf6f9d..9f920f3 100644
--- a/monitor.c
+++ b/monitor.c
@@ -179,14 +179,6 @@ typedef struct MonitorControl {
  * throttling is calculated globally, rather than per-Monitor
  * instance.
  */
-typedef struct MonitorEventState {
-MonitorEvent event; /* Event being tracked */
-int64_t rate;   /* Period over which to throttle. 0 to disable */
-int64_t last;   /* Time at which event was last emitted */
-QEMUTimer *timer;   /* Timer for handling delayed events */
-QObject *data;  /* Event pending delayed dispatch */
-} MonitorEventState;
-
 typedef struct MonitorQAPIEventState {
 QAPIEvent event;/* Event being tracked */
 int64_t rate;   /* Period over which to throttle. 0 to disable */
@@ -447,58 +439,7 @@ static void monitor_protocol_emitter(Monitor *mon, QObject 
*data)
 QDECREF(qmp);
 }
 
-static void timestamp_put(QDict *qdict)
-{
-int err;
-QObject *obj;
-qemu_timeval tv;
-
-err = qemu_gettimeofday(&tv);
-if (err < 0)
-return;
-
-obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", "
-"'microseconds': %" PRId64 " }",
-(int64_t) tv.tv_sec, (int64_t) tv.tv_usec);
-qdict_put_obj(qdict, "timestamp", obj);
-}
-
-
-static const char *monitor_event_names[] = {
-[QEVENT_SHUTDOWN] = "SHUTDOWN",
-[QEVENT_RESET] = "RESET",
-[QEVENT_POWERDOWN] = "POWERDOWN",
-[QEVENT_STOP] = "STOP",
-[QEVENT_RESUME] = "RESUME",
-[QEVENT_VNC_CONNECTED] = "VNC_CONNECTED",
-[QEVENT_VNC_INITIALIZED] = "VNC_INITIALIZED",
-[QEVENT_VNC_DISCONNECTED] = "VNC_DISCONNECTED",
-[QEVENT_BLOCK_IO_ERROR] = "BLOCK_IO_ERROR",
-[QEVENT_RTC_CHANGE] = "RTC_CHANGE",
-[QEVENT_WATCHDOG] = "WATCHDOG",
-[QEVENT_SPICE_CONNECTED] = "SPICE_CONNECTED",
-[QEVENT_SPICE_INITIALIZED] = "SPICE_INITIALIZED",
-[QEVENT_SPICE_DISCONNECTED] = "SPICE_DISCONNECTED",
-[QEVENT_BLOCK_JOB_COMPLETED] = "BLOCK_JOB_COMPLETED",
-[QEVENT_BLOCK_JOB_CANCELLED] = "BLOCK_JOB_CANCELLED",
-[QEVENT_BLOCK_JOB_ERROR] = "BLOCK_JOB_ERROR",
-[QEVENT_BLOCK_JOB_READY] = "BLOCK_JOB_READY",
-[QEVENT_DEVICE_DELETED] = "DEVICE_DELETED",
-[QEVENT_DEVICE_TRAY_MOVED] = "DEVICE_TRAY_MOVED",
-[QEVENT_NIC_RX_FILTER_CHANGED] = "NIC_RX_FILTER_CHANGED",
-[QEVENT_SUSPEND] = "SUSPEND",
-[QEVENT_SUSPEND_DISK] = "SUSPEND_DISK",
-[QEVENT_WAKEUP] = "WAKEUP",
-[QEVENT_BALLOON_CHANGE] = "BALLOON_CHANGE",
-[QEVENT_SPICE_MIGRATE_COMPLETED] = "SPICE_MIGRATE_COMPLETED",
-[QEVENT_GUEST_PANICKED] = "GUEST_PANICKED",
-[QEVENT_BLOCK_IMAGE_CORRUPTED] = "BLOCK_IMAGE_CORRUPTED",
-[QEVENT_QUORUM_FAILURE] = "QUORUM_FAILURE",
-[QEVENT_QUORUM_REPORT_BAD] = "QUORUM_REPORT_

[Qemu-devel] [PATCH V6 26/29] qapi event: convert BALLOON_CHANGE

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 balloon.c  |   13 -
 docs/qmp/qmp-events.txt|   17 -
 hw/virtio/virtio-balloon.c |6 --
 include/sysemu/balloon.h   |2 --
 monitor.c  |3 +--
 qapi-event.json|   13 +
 6 files changed, 18 insertions(+), 36 deletions(-)

diff --git a/balloon.c b/balloon.c
index e321f2c..b70da4f 100644
--- a/balloon.c
+++ b/balloon.c
@@ -81,19 +81,6 @@ static int qemu_balloon_status(BalloonInfo *info)
 return 1;
 }
 
-void qemu_balloon_changed(int64_t actual)
-{
-QObject *data;
-
-data = qobject_from_jsonf("{ 'actual': %" PRId64 " }",
-  actual);
-
-monitor_protocol_event(QEVENT_BALLOON_CHANGE, data);
-
-qobject_decref(data);
-}
-
-
 BalloonInfo *qmp_query_balloon(Error **errp)
 {
 BalloonInfo *info;
diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index 4fbc3de..1b0e25f 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -1,23 +1,6 @@
QEMU Machine Protocol Events

 
-BALLOON_CHANGE
---
-
-Emitted when the guest changes the actual BALLOON level. This
-value is equivalent to the 'actual' field return by the
-'query-balloon' command
-
-Data:
-
-- "actual": actual level of the guest memory balloon in bytes (json-number)
-
-Example:
-
-{ "event": "BALLOON_CHANGE",
-"data": { "actual": 944766976 },
-"timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
-
 GUEST_PANICKED
 --
 
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index bf2b588..75d24b2 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -24,6 +24,7 @@
 #include "sysemu/kvm.h"
 #include "exec/address-spaces.h"
 #include "qapi/visitor.h"
+#include "qapi-event.h"
 
 #if defined(__linux__)
 #include 
@@ -294,8 +295,9 @@ static void virtio_balloon_set_config(VirtIODevice *vdev,
 memcpy(&config, config_data, sizeof(struct virtio_balloon_config));
 dev->actual = le32_to_cpu(config.actual);
 if (dev->actual != oldactual) {
-qemu_balloon_changed(ram_size -
-   ((ram_addr_t) dev->actual << VIRTIO_BALLOON_PFN_SHIFT));
+qapi_event_send_balloon_change(ram_size -
+((ram_addr_t) dev->actual << VIRTIO_BALLOON_PFN_SHIFT),
+NULL);
 }
 }
 
diff --git a/include/sysemu/balloon.h b/include/sysemu/balloon.h
index bd9d395..0345e01 100644
--- a/include/sysemu/balloon.h
+++ b/include/sysemu/balloon.h
@@ -24,6 +24,4 @@ int qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
 QEMUBalloonStatus *stat_func, void *opaque);
 void qemu_remove_balloon_handler(void *opaque);
 
-void qemu_balloon_changed(int64_t actual);
-
 #endif
diff --git a/monitor.c b/monitor.c
index cae60ab..b0a54cf 100644
--- a/monitor.c
+++ b/monitor.c
@@ -615,6 +615,7 @@ static void monitor_qapi_event_init(void)
 /* Limit RTC & BALLOON events to 1 per second */
 monitor_qapi_event_throttle(QAPI_EVENT_RTC_CHANGE, 1000);
 monitor_qapi_event_throttle(QAPI_EVENT_WATCHDOG, 1000);
+monitor_qapi_event_throttle(QAPI_EVENT_BALLOON_CHANGE, 1000);
 
 qmp_event_set_func_emit(monitor_qapi_event_queue);
 }
@@ -740,8 +741,6 @@ monitor_protocol_event_throttle(MonitorEvent event,
  * and initialize state */
 static void monitor_protocol_event_init(void)
 {
-/* Limit RTC & BALLOON events to 1 per second */
-monitor_protocol_event_throttle(QEVENT_BALLOON_CHANGE, 1000);
 /* limit the rate of quorum events to avoid hammering the management */
 monitor_protocol_event_throttle(QEVENT_QUORUM_REPORT_BAD, 1000);
 monitor_protocol_event_throttle(QEVENT_QUORUM_FAILURE, 1000);
diff --git a/qapi-event.json b/qapi-event.json
index 0849584..93f9eeb 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -387,3 +387,16 @@
 # Since: 2.1
 ##
 { 'event': 'SPICE_MIGRATE_COMPLETED' }
+
+##
+# @BALLOON_CHANGE
+#
+# Emitted when the guest changes the actual BALLOON level. This value is
+# equivalent to the @actual field return by the 'query-balloon' command
+#
+# @actual: actual level of the guest memory balloon in bytes
+#
+# Since: 2.1
+##
+{ 'event': 'BALLOON_CHANGE',
+  'data': { 'actual': 'int' } }
-- 
1.7.1




[Qemu-devel] [PATCH V6 20/29] qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 block.c   |   36 +++--
 blockjob.c|6 -
 docs/qmp/qmp-events.txt   |   47 -
 include/block/block_int.h |3 --
 qapi-event.json   |   38 
 qapi-schema.json  |   14 +
 6 files changed, 61 insertions(+), 83 deletions(-)

diff --git a/block.c b/block.c
index 52f4580..1ebbce6 100644
--- a/block.c
+++ b/block.c
@@ -24,7 +24,6 @@
 #include "config-host.h"
 #include "qemu-common.h"
 #include "trace.h"
-#include "monitor/monitor.h"
 #include "block/block_int.h"
 #include "block/blockjob.h"
 #include "qemu/module.h"
@@ -2133,36 +2132,6 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const 
BlockDevOps *ops,
 bs->dev_opaque = opaque;
 }
 
-void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
-   enum MonitorEvent ev,
-   BlockErrorAction action, bool is_read)
-{
-QObject *data;
-const char *action_str;
-
-switch (action) {
-case BLOCK_ERROR_ACTION_REPORT:
-action_str = "report";
-break;
-case BLOCK_ERROR_ACTION_IGNORE:
-action_str = "ignore";
-break;
-case BLOCK_ERROR_ACTION_STOP:
-action_str = "stop";
-break;
-default:
-abort();
-}
-
-data = qobject_from_jsonf("{ 'device': %s, 'action': %s, 'operation': %s 
}",
-  bdrv->device_name,
-  action_str,
-  is_read ? "read" : "write");
-monitor_protocol_event(ev, data);
-
-qobject_decref(data);
-}
-
 static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
 {
 if (bs->dev_ops && bs->dev_ops->change_media_cb) {
@@ -3612,7 +3581,10 @@ void bdrv_error_action(BlockDriverState *bs, 
BlockErrorAction action,
bool is_read, int error)
 {
 assert(error >= 0);
-bdrv_emit_qmp_error_event(bs, QEVENT_BLOCK_IO_ERROR, action, is_read);
+qapi_event_send_block_io_error(bdrv_get_device_name(bs),
+   is_read ? IO_OPERATION_TYPE_READ :
+   IO_OPERATION_TYPE_WRITE,
+   action, NULL);
 if (action == BLOCK_ERROR_ACTION_STOP) {
 vm_stop(RUN_STATE_IO_ERROR);
 bdrv_iostatus_set_err(bs, error);
diff --git a/blockjob.c b/blockjob.c
index bc63d42..43f971d 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -34,6 +34,7 @@
 #include "block/coroutine.h"
 #include "qmp-commands.h"
 #include "qemu/timer.h"
+#include "qapi-event.h"
 
 void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
int64_t speed, BlockDriverCompletionFunc *cb,
@@ -277,7 +278,10 @@ BlockErrorAction block_job_error_action(BlockJob *job, 
BlockDriverState *bs,
 default:
 abort();
 }
-bdrv_emit_qmp_error_event(job->bs, QEVENT_BLOCK_JOB_ERROR, action, 
is_read);
+qapi_event_send_block_job_error(bdrv_get_device_name(bs),
+is_read ? IO_OPERATION_TYPE_READ :
+IO_OPERATION_TYPE_WRITE,
+action, NULL);
 if (action == BLOCK_ERROR_ACTION_STOP) {
 block_job_pause(job);
 block_job_iostatus_set_err(job, error);
diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index 1ee6f53..f67a9ec 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -40,31 +40,6 @@ Example:
 "size": 65536 },
 "timestamp": { "seconds": 1378126126, "microseconds": 966463 } }
 
-BLOCK_IO_ERROR
---
-
-Emitted when a disk I/O error occurs.
-
-Data:
-
-- "device": device name (json-string)
-- "operation": I/O operation (json-string, "read" or "write")
-- "action": action that has been taken, it's one of the following 
(json-string):
-"ignore": error has been ignored
-"report": error has been reported to the device
-"stop": error caused VM to be stopped
-
-Example:
-
-{ "event": "BLOCK_IO_ERROR",
-"data": { "device": "ide0-hd1",
-  "operation": "write",
-  "action": "stop" },
-"timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
-
-Note: If action is "stop", a STOP event will eventually follow the
-BLOCK_IO_ERROR event.
-
 BLOCK_JOB_CANCELLED
 ---
 
@@ -118,28 +93,6 @@ Example:
 

[Qemu-devel] [PATCH V6 22/29] qapi event: convert other BLOCK_JOB events

2014-06-05 Thread Wenchao Xia
Since BLOCK_JOB_COMPLETED, BLOCK_JOB_CANCELLED, BLOCK_JOB_READY are
related, converts them in one patch. The block_job_event_* functions
are used to keep encapsulation of BlockJob structure.

Signed-off-by: Wenchao Xia 
---
 block/mirror.c   |2 +-
 blockdev.c   |   12 +++
 blockjob.c   |   36 +--
 docs/qmp/qmp-events.txt  |   71 --
 include/block/blockjob.h |   17 --
 qapi-event.json  |   71 ++
 6 files changed, 110 insertions(+), 99 deletions(-)

diff --git a/block/mirror.c b/block/mirror.c
index df58aea..301a04d 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -427,7 +427,7 @@ static void coroutine_fn mirror_run(void *opaque)
  */
 s->common.offset = end * BDRV_SECTOR_SIZE;
 if (!s->synced) {
-block_job_ready(&s->common);
+block_job_event_ready(&s->common);
 s->synced = true;
 }
 
diff --git a/blockdev.c b/blockdev.c
index 9b5261b..9cc2c0c 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1851,23 +1851,21 @@ void qmp_block_resize(bool has_device, const char 
*device,
 static void block_job_cb(void *opaque, int ret)
 {
 BlockDriverState *bs = opaque;
-QObject *obj;
+const char *msg = NULL;
 
 trace_block_job_cb(bs, bs->job, ret);
 
 assert(bs->job);
-obj = qobject_from_block_job(bs->job);
+
 if (ret < 0) {
-QDict *dict = qobject_to_qdict(obj);
-qdict_put(dict, "error", qstring_from_str(strerror(-ret)));
+msg = strerror(-ret);
 }
 
 if (block_job_is_cancelled(bs->job)) {
-monitor_protocol_event(QEVENT_BLOCK_JOB_CANCELLED, obj);
+block_job_event_cancelled(bs->job);
 } else {
-monitor_protocol_event(QEVENT_BLOCK_JOB_COMPLETED, obj);
+block_job_event_completed(bs->job, msg);
 }
-qobject_decref(obj);
 
 bdrv_put_ref_bh_schedule(bs);
 }
diff --git a/blockjob.c b/blockjob.c
index 43f971d..d21f51e 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -26,7 +26,6 @@
 #include "config-host.h"
 #include "qemu-common.h"
 #include "trace.h"
-#include "monitor/monitor.h"
 #include "block/block.h"
 #include "block/blockjob.h"
 #include "block/block_int.h"
@@ -233,26 +232,31 @@ static void block_job_iostatus_set_err(BlockJob *job, int 
error)
 }
 }
 
+void block_job_event_cancelled(BlockJob *job)
+{
+qapi_event_send_block_job_cancelled(job->driver->job_type,
+bdrv_get_device_name(job->bs),
+job->len,
+job->offset,
+job->speed,
+NULL);
+}
 
-QObject *qobject_from_block_job(BlockJob *job)
+void block_job_event_completed(BlockJob *job, const char *msg)
 {
-return qobject_from_jsonf("{ 'type': %s,"
-  "'device': %s,"
-  "'len': %" PRId64 ","
-  "'offset': %" PRId64 ","
-  "'speed': %" PRId64 " }",
-  BlockJobType_lookup[job->driver->job_type],
-  bdrv_get_device_name(job->bs),
-  job->len,
-  job->offset,
-  job->speed);
+qapi_event_send_block_job_completed(job->driver->job_type,
+bdrv_get_device_name(job->bs),
+job->len,
+job->offset,
+job->speed,
+!!msg,
+msg,
+NULL);
 }
 
-void block_job_ready(BlockJob *job)
+void block_job_event_ready(BlockJob *job)
 {
-QObject *data = qobject_from_block_job(job);
-monitor_protocol_event(QEVENT_BLOCK_JOB_READY, data);
-qobject_decref(data);
+qapi_event_send_block_job_ready(bdrv_get_device_name(job->bs), NULL);
 }
 
 BlockErrorAction block_job_error_action(BlockJob *job, BlockDriverState *bs,
diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index eec3955..c57d5df 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -18,77 +18,6 @@ Example:
 "data": { "actual": 944766976 },
 "timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
 
-BLOCK_JOB_CANCELLED
---

[Qemu-devel] [PATCH V6 14/29] qapi event: convert SUSPEND_DISK

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 docs/qmp/qmp-events.txt |   14 --
 hw/acpi/core.c  |4 ++--
 qapi-event.json |   12 
 3 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index d86a077..c2f23ef 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -342,20 +342,6 @@ Example:
   "channel-id": 0, "tls": true}
 }}
 
-SUSPEND_DISK
-
-
-Emitted when the guest makes a request to enter S4 state.
-
-Data: None.
-
-Example:
-
-{ "event": "SUSPEND_DISK",
- "timestamp": { "seconds": 1344456160, "microseconds": 309119 } }
-
-Note: QEMU shuts down when entering S4 state.
-
 VNC_CONNECTED
 -
 
diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 79414b4..ace6438 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -22,11 +22,11 @@
 #include "hw/hw.h"
 #include "hw/i386/pc.h"
 #include "hw/acpi/acpi.h"
-#include "monitor/monitor.h"
 #include "qemu/config-file.h"
 #include "qapi/opts-visitor.h"
 #include "qapi/dealloc-visitor.h"
 #include "qapi-visit.h"
+#include "qapi-event.h"
 
 struct acpi_table_header {
 uint16_t _length; /* our length, not actual part of the hdr */
@@ -550,7 +550,7 @@ static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
 break;
 default:
 if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
-monitor_protocol_event(QEVENT_SUSPEND_DISK, NULL);
+qapi_event_send_suspend_disk(NULL);
 qemu_system_shutdown_request();
 }
 break;
diff --git a/qapi-event.json b/qapi-event.json
index 83c4ea2..c68edfd 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -57,3 +57,15 @@
 # Since: 2.1
 ##
 { 'event': 'SUSPEND' }
+
+##
+# @SUSPEND_DISK
+#
+# Emitted when guest enters a hardware suspension state with data saved on
+# disk, for example, S4 state, which is sometimes called hibernate state
+#
+# Note: QEMU shuts down (similar to event @SHUTDOWN) when entering this state
+#
+# Since: 2.1
+##
+{ 'event': 'SUSPEND_DISK' }
-- 
1.7.1




[Qemu-devel] [PATCH V6 15/29] qapi event: convert WAKEUP

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 docs/qmp/qmp-events.txt |   12 
 qapi-event.json |9 +
 vl.c|2 +-
 3 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index c2f23ef..3d82db4 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -432,18 +432,6 @@ Example:
 "host": "127.0.0.1", "sasl_username": "luiz" } },
 "timestamp": { "seconds": 1263475302, "microseconds": 150772 } }
 
-WAKEUP
---
-
-Emitted when the guest has woken up from S3 and is running.
-
-Data: None.
-
-Example:
-
-{ "event": "WAKEUP",
- "timestamp": { "seconds": 1344522075, "microseconds": 745528 } }
-
 WATCHDOG
 
 
diff --git a/qapi-event.json b/qapi-event.json
index c68edfd..32ac571 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -69,3 +69,12 @@
 # Since: 2.1
 ##
 { 'event': 'SUSPEND_DISK' }
+
+##
+# @WAKEUP
+#
+# Emitted when the guest has woken up from suspend state and is running
+#
+# Since: 2.1
+##
+{ 'event': 'WAKEUP' }
diff --git a/vl.c b/vl.c
index c6cb2c1..b8ad1df 100644
--- a/vl.c
+++ b/vl.c
@@ -2052,7 +2052,7 @@ static bool main_loop_should_exit(void)
 notifier_list_notify(&wakeup_notifiers, &wakeup_reason);
 wakeup_reason = QEMU_WAKEUP_REASON_NONE;
 resume_all_vcpus();
-monitor_protocol_event(QEVENT_WAKEUP, NULL);
+qapi_event_send_wakeup(NULL);
 }
 if (qemu_powerdown_requested()) {
 qemu_system_powerdown();
-- 
1.7.1




[Qemu-devel] [PATCH V6 09/29] qapi event: convert POWERDOWN

2014-06-05 Thread Wenchao Xia
There is no existing comments for POWERDOWN in doc/qmp/qmp-events.txt,
so no change on it like other conversion patch.

Signed-off-by: Wenchao Xia 
---
 qapi-event.json |   10 ++
 vl.c|2 +-
 2 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/qapi-event.json b/qapi-event.json
index b2a943f..fbdbc7c 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -10,3 +10,13 @@
 # Since: 2.1
 ##
 { 'event': 'SHUTDOWN' }
+
+##
+# @POWERDOWN
+#
+# Emitted when the virtual machine is powered down through the power control
+# system, such as via ACPI.
+#
+# Since: 2.1
+##
+{ 'event': 'POWERDOWN' }
diff --git a/vl.c b/vl.c
index 273d237..69ad0e9 100644
--- a/vl.c
+++ b/vl.c
@@ -1991,7 +1991,7 @@ void qemu_system_shutdown_request(void)
 
 static void qemu_system_powerdown(void)
 {
-monitor_protocol_event(QEVENT_POWERDOWN, NULL);
+qapi_event_send_powerdown(NULL);
 notifier_list_notify(&powerdown_notifiers, NULL);
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH V6 07/29] qapi: add new schema file qapi-event.json

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 Makefile |   12 
 qapi-schema.json |2 ++
 2 files changed, 10 insertions(+), 4 deletions(-)
 create mode 100644 qapi-event.json

diff --git a/Makefile b/Makefile
index 237657e..554fb2d 100644
--- a/Makefile
+++ b/Makefile
@@ -247,22 +247,26 @@ $(SRC_PATH)/qga/qapi-schema.json 
$(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
"  GEN   $@")
 
 qapi-types.c qapi-types.h :\
-$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
+$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi-event.json \
+$(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \
$(gen-out-type) -o "." -b -i $<, \
"  GEN   $@")
 qapi-visit.c qapi-visit.h :\
-$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
+$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi-event.json \
+$(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py \
$(gen-out-type) -o "." -b -i $<, \
"  GEN   $@")
 qapi-event.c qapi-event.h :\
-$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-event.py $(qapi-py)
+$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi-event.json \
+$(SRC_PATH)/scripts/qapi-event.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py \
$(gen-out-type) -o "." -b -i $<, \
"  GEN   $@")
 qmp-commands.h qmp-marshal.c :\
-$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
+$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi-event.json \
+$(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \
$(gen-out-type) -o "." -m -i $<, \
"  GEN   $@")
diff --git a/qapi-event.json b/qapi-event.json
new file mode 100644
index 000..e69de29
diff --git a/qapi-schema.json b/qapi-schema.json
index 115d8d0..d04514a 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4798,3 +4798,5 @@
 ##
 { 'enum': 'BlockErrorAction',
   'data': [ 'ignore', 'report', 'stop' ] }
+
+{ 'include': 'qapi-event.json' }
-- 
1.7.1




[Qemu-devel] [PATCH V6 13/29] qapi event: convert SUSPEND

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 docs/qmp/qmp-events.txt |   12 
 qapi-event.json |   10 ++
 vl.c|2 +-
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index cda67d4..d86a077 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -342,18 +342,6 @@ Example:
   "channel-id": 0, "tls": true}
 }}
 
-SUSPEND

-
-Emitted when guest enters S3 state.
-
-Data: None.
-
-Example:
-
-{ "event": "SUSPEND",
- "timestamp": { "seconds": 1344456160, "microseconds": 309119 } }
-
 SUSPEND_DISK
 
 
diff --git a/qapi-event.json b/qapi-event.json
index 3485985..83c4ea2 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -47,3 +47,13 @@
 # Since: 2.1
 ##
 { 'event': 'RESUME' }
+
+##
+# @SUSPEND
+#
+# Emitted when guest enters a hardware suspension state, for example, S3 state,
+# which is sometimes called standby state
+#
+# Since: 2.1
+##
+{ 'event': 'SUSPEND' }
diff --git a/vl.c b/vl.c
index d195e50..c6cb2c1 100644
--- a/vl.c
+++ b/vl.c
@@ -1928,7 +1928,7 @@ static void qemu_system_suspend(void)
 pause_all_vcpus();
 notifier_list_notify(&suspend_notifiers, NULL);
 runstate_set(RUN_STATE_SUSPENDED);
-monitor_protocol_event(QEVENT_SUSPEND, NULL);
+qapi_event_send_suspend(NULL);
 }
 
 void qemu_system_suspend_request(void)
-- 
1.7.1




[Qemu-devel] [PATCH V6 18/29] qapi event: convert DEVICE_DELETED

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 docs/qmp/qmp-events.txt |   18 --
 hw/core/qdev.c  |   12 ++--
 qapi-event.json |   16 
 3 files changed, 18 insertions(+), 28 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index df15dc8..fda68df 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -158,24 +158,6 @@ Example:
 Note: The "ready to complete" status is always reset by a BLOCK_JOB_ERROR
 event.
 
-DEVICE_DELETED
---
-
-Emitted whenever the device removal completion is acknowledged
-by the guest.
-At this point, it's safe to reuse the specified device ID.
-Device removal can be initiated by the guest or by HMP/QMP commands.
-
-Data:
-
-- "device": device name (json-string, optional)
-- "path": device path (json-string)
-
-{ "event": "DEVICE_DELETED",
-  "data": { "device": "virtio-net-pci-0",
-"path": "/machine/peripheral/virtio-net-pci-0" },
-  "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
-
 DEVICE_TRAY_MOVED
 -
 
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index e65a5aa..a6c62b2 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -32,8 +32,8 @@
 #include "qapi/qmp/qerror.h"
 #include "qapi/visitor.h"
 #include "qapi/qmp/qjson.h"
-#include "monitor/monitor.h"
 #include "hw/hotplug.h"
+#include "qapi-event.h"
 
 int qdev_hotplug = 0;
 static bool qdev_hot_added = false;
@@ -939,7 +939,6 @@ static void device_unparent(Object *obj)
 {
 DeviceState *dev = DEVICE(obj);
 BusState *bus;
-QObject *event_data;
 bool have_realized = dev->realized;
 
 if (dev->realized) {
@@ -959,14 +958,7 @@ static void device_unparent(Object *obj)
 if (have_realized) {
 gchar *path = object_get_canonical_path(OBJECT(dev));
 
-if (dev->id) {
-event_data = qobject_from_jsonf("{ 'device': %s, 'path': %s }",
-dev->id, path);
-} else {
-event_data = qobject_from_jsonf("{ 'path': %s }", path);
-}
-monitor_protocol_event(QEVENT_DEVICE_DELETED, event_data);
-qobject_decref(event_data);
+qapi_event_send_device_deleted(!!dev->id, dev->id, path, NULL);
 g_free(path);
 }
 }
diff --git a/qapi-event.json b/qapi-event.json
index 640f841..fc83fed 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -106,3 +106,19 @@
 ##
 { 'event': 'WATCHDOG',
   'data': { 'action': 'WatchdogExpirationAction' } }
+
+##
+# @DEVICE_DELETED
+#
+# Emitted whenever the device removal completion is acknowledged by the guest.
+# At this point, it's safe to reuse the specified device ID. Device removal can
+# be initiated by the guest or by HMP/QMP commands.
+#
+# @device: #optional, device name
+#
+# @path: device path
+#
+# Since: 2.1
+##
+{ 'event': 'DEVICE_DELETED',
+  'data': { '*device': 'str', 'path': 'str' } }
-- 
1.7.1




[Qemu-devel] [PATCH V6 05/29] qapi: adjust existing defines

2014-06-05 Thread Wenchao Xia
In order to let event defines use existing types later, instead of
redefine new ones, some old type defines for spice and vnc are changed,
and BlockErrorAction is moved from block.h to qapi schema. Note that
BlockErrorAction is not merged with BlockdevOnError.

One thing not perfect is that, VncInfo should be foldered but may break
API stability.

Signed-off-by: Wenchao Xia 
---
 block.c|   17 ---
 block/backup.c |2 +-
 block/mirror.c |7 ++-
 block/stream.c |4 +-
 blockjob.c |   11 ++--
 hmp.c  |5 +-
 hw/block/virtio-blk.c  |6 +-
 hw/ide/core.c  |6 +-
 hw/scsi/scsi-disk.c|6 +-
 include/block/block.h  |4 --
 include/qemu/sockets.h |2 +
 qapi-schema.json   |  126 ++--
 ui/spice-core.c|7 ++-
 ui/vnc.c   |9 ++--
 util/qemu-sockets.c|   10 
 15 files changed, 156 insertions(+), 66 deletions(-)

diff --git a/block.c b/block.c
index 310ea89..84ad945 100644
--- a/block.c
+++ b/block.c
@@ -2140,13 +2140,13 @@ void bdrv_emit_qmp_error_event(const BlockDriverState 
*bdrv,
 const char *action_str;
 
 switch (action) {
-case BDRV_ACTION_REPORT:
+case BLOCK_ERROR_ACTION_REPORT:
 action_str = "report";
 break;
-case BDRV_ACTION_IGNORE:
+case BLOCK_ERROR_ACTION_IGNORE:
 action_str = "ignore";
 break;
-case BDRV_ACTION_STOP:
+case BLOCK_ERROR_ACTION_STOP:
 action_str = "stop";
 break;
 default:
@@ -3599,13 +3599,14 @@ BlockErrorAction bdrv_get_error_action(BlockDriverState 
*bs, bool is_read, int e
 
 switch (on_err) {
 case BLOCKDEV_ON_ERROR_ENOSPC:
-return (error == ENOSPC) ? BDRV_ACTION_STOP : BDRV_ACTION_REPORT;
+return (error == ENOSPC) ?
+   BLOCK_ERROR_ACTION_STOP : BLOCK_ERROR_ACTION_REPORT;
 case BLOCKDEV_ON_ERROR_STOP:
-return BDRV_ACTION_STOP;
+return BLOCK_ERROR_ACTION_STOP;
 case BLOCKDEV_ON_ERROR_REPORT:
-return BDRV_ACTION_REPORT;
+return BLOCK_ERROR_ACTION_REPORT;
 case BLOCKDEV_ON_ERROR_IGNORE:
-return BDRV_ACTION_IGNORE;
+return BLOCK_ERROR_ACTION_IGNORE;
 default:
 abort();
 }
@@ -3620,7 +3621,7 @@ void bdrv_error_action(BlockDriverState *bs, 
BlockErrorAction action,
 {
 assert(error >= 0);
 bdrv_emit_qmp_error_event(bs, QEVENT_BLOCK_IO_ERROR, action, is_read);
-if (action == BDRV_ACTION_STOP) {
+if (action == BLOCK_ERROR_ACTION_STOP) {
 vm_stop(RUN_STATE_IO_ERROR);
 bdrv_iostatus_set_err(bs, error);
 }
diff --git a/block/backup.c b/block/backup.c
index 15a2e55..7978ae2 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -325,7 +325,7 @@ static void coroutine_fn backup_run(void *opaque)
 /* Depending on error action, fail now or retry cluster */
 BlockErrorAction action =
 backup_error_action(job, error_is_read, -ret);
-if (action == BDRV_ACTION_REPORT) {
+if (action == BLOCK_ERROR_ACTION_REPORT) {
 break;
 } else {
 start--;
diff --git a/block/mirror.c b/block/mirror.c
index 94c8661..df58aea 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -118,7 +118,7 @@ static void mirror_write_complete(void *opaque, int ret)
 
 bdrv_set_dirty(source, op->sector_num, op->nb_sectors);
 action = mirror_error_action(s, false, -ret);
-if (action == BDRV_ACTION_REPORT && s->ret >= 0) {
+if (action == BLOCK_ERROR_ACTION_REPORT && s->ret >= 0) {
 s->ret = ret;
 }
 }
@@ -135,7 +135,7 @@ static void mirror_read_complete(void *opaque, int ret)
 
 bdrv_set_dirty(source, op->sector_num, op->nb_sectors);
 action = mirror_error_action(s, true, -ret);
-if (action == BDRV_ACTION_REPORT && s->ret >= 0) {
+if (action == BLOCK_ERROR_ACTION_REPORT && s->ret >= 0) {
 s->ret = ret;
 }
 
@@ -415,7 +415,8 @@ static void coroutine_fn mirror_run(void *opaque)
 trace_mirror_before_flush(s);
 ret = bdrv_flush(s->target);
 if (ret < 0) {
-if (mirror_error_action(s, false, -ret) == BDRV_ACTION_REPORT) 
{
+if (mirror_error_action(s, false, -ret) ==
+BLOCK_ERROR_ACTION_REPORT) {
 goto immediate_exit;
 }
 } else {
diff --git a/block/stream.c b/block/stream.c
index 91d18a2..0433409 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -159,14 +159,14 @@ wait:
 BlockErrorAction action =
 block_job_error_action(&s->common, s->common.bs, s->on_error,

[Qemu-devel] [PATCH V6 11/29] qapi event: convert STOP

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 cpus.c  |5 +++--
 docs/qmp/qmp-events.txt |   12 
 qapi-event.json |9 +
 3 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/cpus.c b/cpus.c
index dd7ac13..28abb11 100644
--- a/cpus.c
+++ b/cpus.c
@@ -25,7 +25,7 @@
 /* Needed early for CONFIG_BSD etc. */
 #include "config-host.h"
 
-#include "monitor/monitor.h"
+#include "qapi/qmp/qerror.h"
 #include "sysemu/sysemu.h"
 #include "exec/gdbstub.h"
 #include "sysemu/dma.h"
@@ -38,6 +38,7 @@
 #include "qemu/main-loop.h"
 #include "qemu/bitmap.h"
 #include "qemu/seqlock.h"
+#include "qapi-event.h"
 
 #ifndef _WIN32
 #include "qemu/compatfd.h"
@@ -530,7 +531,7 @@ static int do_vm_stop(RunState state)
 pause_all_vcpus();
 runstate_set(state);
 vm_state_notify(0, state);
-monitor_protocol_event(QEVENT_STOP, NULL);
+qapi_event_send_stop(NULL);
 }
 
 bdrv_drain_all();
diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index 20e3151..c241a07 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -354,18 +354,6 @@ Example:
   "channel-id": 0, "tls": true}
 }}
 
-STOP
-
-
-Emitted when the Virtual Machine is stopped.
-
-Data: None.
-
-Example:
-
-{ "event": "STOP",
-"timestamp": { "seconds": 1267041730, "microseconds": 281295 } }
-
 SUSPEND
 ---
 
diff --git a/qapi-event.json b/qapi-event.json
index 6f27555..af5a18c 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -29,3 +29,12 @@
 # Since: 2.1
 ##
 { 'event': 'RESET' }
+
+##
+# @STOP
+#
+# Emitted when the virtual machine is stopped
+#
+# Since: 2.1
+##
+{ 'event': 'STOP' }
-- 
1.7.1




[Qemu-devel] [PATCH V6 06/29] monitor: add an implemention as qapi event emit method

2014-06-05 Thread Wenchao Xia
Now monitor has been hooked on the new event mechanism, so the patches
later can convert event callers one by one. Most code are copied from
old monitor_protocol_* functions with some modification.

Note that two build time warnings will be raised after this patch. One is
caused by no caller of monitor_qapi_event_throttle(), the other one is
caused by QAPI_EVENT_MAX = 0. They will be fixed automatically after
full event conversion later.

Signed-off-by: Wenchao Xia 
---
 monitor.c|  128 +-
 trace-events |4 ++
 2 files changed, 131 insertions(+), 1 deletions(-)

diff --git a/monitor.c b/monitor.c
index 593679a..e122381 100644
--- a/monitor.c
+++ b/monitor.c
@@ -69,6 +69,8 @@
 #include "qmp-commands.h"
 #include "hmp.h"
 #include "qemu/thread.h"
+#include "qapi/qmp-event.h"
+#include "qapi-event.h"
 
 /* for pic/irq_info */
 #if defined(TARGET_SPARC)
@@ -185,6 +187,14 @@ typedef struct MonitorEventState {
 QObject *data;  /* Event pending delayed dispatch */
 } MonitorEventState;
 
+typedef struct MonitorQAPIEventState {
+QAPIEvent event;/* Event being tracked */
+int64_t rate;   /* Period over which to throttle. 0 to disable */
+int64_t last;   /* Time at which event was last emitted */
+QEMUTimer *timer;   /* Timer for handling delayed events */
+QObject *data;/* Event pending delayed dispatch */
+} MonitorQAPIEventState;
+
 struct Monitor {
 CharDriverState *chr;
 int mux_out;
@@ -489,6 +499,122 @@ static const char *monitor_event_names[] = {
 QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != QEVENT_MAX)
 
 static MonitorEventState monitor_event_state[QEVENT_MAX];
+static MonitorQAPIEventState monitor_qapi_event_state[QAPI_EVENT_MAX];
+
+/*
+ * Emits the event to every monitor instance, @event is only used for trace
+ */
+static void monitor_qapi_event_emit(QAPIEvent event, QObject *data)
+{
+Monitor *mon;
+
+trace_monitor_qapi_event_emit(event, data);
+QLIST_FOREACH(mon, &mon_list, entry) {
+if (monitor_ctrl_mode(mon) && qmp_cmd_mode(mon)) {
+monitor_json_emitter(mon, data);
+}
+}
+}
+
+/*
+ * Queue a new event for emission to Monitor instances,
+ * applying any rate limiting if required.
+ */
+static void
+monitor_qapi_event_queue(int event_kind, QDict *data, Error **errp)
+{
+MonitorQAPIEventState *evstate;
+assert(event_kind < QAPI_EVENT_MAX);
+QAPIEvent event = (QAPIEvent)event_kind;
+int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
+
+evstate = &(monitor_qapi_event_state[event]);
+trace_monitor_qapi_event_queue(event,
+   data,
+   evstate->rate,
+   evstate->last,
+   now);
+
+/* Rate limit of 0 indicates no throttling */
+if (!evstate->rate) {
+monitor_qapi_event_emit(event, QOBJECT(data));
+evstate->last = now;
+} else {
+int64_t delta = now - evstate->last;
+if (evstate->data ||
+delta < evstate->rate) {
+/* If there's an existing event pending, replace
+ * it with the new event, otherwise schedule a
+ * timer for delayed emission
+ */
+if (evstate->data) {
+qobject_decref(evstate->data);
+} else {
+int64_t then = evstate->last + evstate->rate;
+timer_mod_ns(evstate->timer, then);
+}
+evstate->data = QOBJECT(data);
+qobject_incref(evstate->data);
+} else {
+monitor_qapi_event_emit(event, QOBJECT(data));
+evstate->last = now;
+}
+}
+}
+
+/*
+ * The callback invoked by QemuTimer when a delayed
+ * event is ready to be emitted
+ */
+static void monitor_qapi_event_handler(void *opaque)
+{
+MonitorQAPIEventState *evstate = opaque;
+int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
+
+
+trace_monitor_qapi_event_handler(evstate->event,
+ evstate->data,
+ evstate->last,
+ now);
+if (evstate->data) {
+monitor_qapi_event_emit(evstate->event, evstate->data);
+qobject_decref(evstate->data);
+evstate->data = NULL;
+}
+evstate->last = now;
+}
+
+/*
+ * @event: the event ID to be limited
+ * @rate: the rate limit in milliseconds
+ *
+ * Sets a rate limit on a particular event, so no
+ * more than 1 event will be emitted within @rate
+ * milliseconds
+ */
+static void monitor_qapi_event_throttle(QAPIEvent event, int64_t rate)
+{
+MonitorQAPIEventState *evstate;
+assert(event < QAPI_EVENT_MAX);
+
+evstate = &

[Qemu-devel] [PATCH V6 12/29] qapi event: convert RESUME

2014-06-05 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 docs/qmp/qmp-events.txt |   12 
 qapi-event.json |9 +
 vl.c|2 +-
 3 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index c241a07..cda67d4 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -264,18 +264,6 @@ Example:
  "data": { "node-name": "1.raw", "sector-num": 345435, "sector-count": 5 },
  "timestamp": { "seconds": 1344522075, "microseconds": 745528 } }
 
-RESUME
---
-
-Emitted when the Virtual Machine resumes execution.
-
-Data: None.
-
-Example:
-
-{ "event": "RESUME",
-"timestamp": { "seconds": 1271770767, "microseconds": 582542 } }
-
 RTC_CHANGE
 --
 
diff --git a/qapi-event.json b/qapi-event.json
index af5a18c..3485985 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -38,3 +38,12 @@
 # Since: 2.1
 ##
 { 'event': 'STOP' }
+
+##
+# @RESUME
+#
+# Emitted when the virtual machine resumes execution
+#
+# Since: 2.1
+##
+{ 'event': 'RESUME' }
diff --git a/vl.c b/vl.c
index b95fc5e..d195e50 100644
--- a/vl.c
+++ b/vl.c
@@ -1755,7 +1755,7 @@ void vm_start(void)
 runstate_set(RUN_STATE_RUNNING);
 vm_state_notify(1, RUN_STATE_RUNNING);
 resume_all_vcpus();
-monitor_protocol_event(QEVENT_RESUME, NULL);
+qapi_event_send_resume(NULL);
 }
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH V6 04/29] test: add test cases for qapi event

2014-06-05 Thread Wenchao Xia
These cases will verify whether the expected qdict is built.

Signed-off-by: Wenchao Xia 
---
 tests/Makefile  |   16 ++-
 tests/qapi-schema/qapi-schema-test.json |   12 ++
 tests/qapi-schema/qapi-schema-test.out  |   10 +-
 tests/test-qmp-event.c  |  265 +++
 4 files changed, 298 insertions(+), 5 deletions(-)
 create mode 100644 tests/test-qmp-event.c

diff --git a/tests/Makefile b/tests/Makefile
index 287455f..f07a916 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -27,6 +27,8 @@ check-unit-y += tests/test-string-input-visitor$(EXESUF)
 gcov-files-test-string-input-visitor-y = qapi/string-input-visitor.c
 check-unit-y += tests/test-string-output-visitor$(EXESUF)
 gcov-files-test-string-output-visitor-y = qapi/string-output-visitor.c
+check-unit-y += tests/test-qmp-event$(EXESUF)
+gcov-files-test-qmp-event-y += qapi/qmp-event.c
 check-unit-y += tests/test-opts-visitor$(EXESUF)
 gcov-files-test-opts-visitor-y = qapi/opts-visitor.c
 check-unit-y += tests/test-coroutine$(EXESUF)
@@ -200,7 +202,8 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
 include-nested-err.json include-self-cycle.json include-cycle.json \
 include-repetition.json event-nest-struct.json)
 
-GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h 
tests/test-qmp-commands.h
+GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h \
+ tests/test-qmp-commands.h tests/test-qapi-event.h
 
 test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \
tests/check-qlist.o tests/check-qfloat.o tests/check-qjson.o \
@@ -209,9 +212,10 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o 
tests/check-qdict.o \
tests/test-qmp-input-visitor.o tests/test-qmp-input-strict.o \
tests/test-qmp-commands.o tests/test-visitor-serialization.o \
tests/test-x86-cpuid.o tests/test-mul64.o tests/test-int128.o \
-   tests/test-opts-visitor.o
+   tests/test-opts-visitor.o tests/test-qmp-event.o
 
-test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o
+test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
+  tests/test-qapi-event.o
 
 $(test-obj-y): QEMU_INCLUDES += -Itests
 QEMU_CFLAGS += -I$(SRC_PATH)/tests
@@ -263,9 +267,15 @@ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json 
$(SRC_PATH)/scripts/qapi-com
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \
$(gen-out-type) -o tests -p "test-" -i $<, \
"  GEN   $@")
+tests/test-qapi-event.c tests/test-qapi-event.h :\
+$(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json 
$(SRC_PATH)/scripts/qapi-event.py
+   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py \
+   $(gen-out-type) -o tests -p "test-" -i $<, \
+   "  GEN   $@")
 
 tests/test-string-output-visitor$(EXESUF): tests/test-string-output-visitor.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
 tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
+tests/test-qmp-event$(EXESUF): tests/test-qmp-event.o $(test-qapi-obj-y) 
libqemuutil.a libqemustub.a
 tests/test-qmp-output-visitor$(EXESUF): tests/test-qmp-output-visitor.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
 tests/test-qmp-input-visitor$(EXESUF): tests/test-qmp-input-visitor.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
 tests/test-qmp-input-strict$(EXESUF): tests/test-qmp-input-strict.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
diff --git a/tests/qapi-schema/qapi-schema-test.json 
b/tests/qapi-schema/qapi-schema-test.json
index 818c06d..ab4d3d9 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -89,3 +89,15 @@
 '*u16' : [ 'uint16' ],
 '*i64x':   'int' ,
 '*u64x':   'uint64'  } }
+
+# testing event
+{ 'type': 'EventStructOne',
+  'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' } }
+
+{ 'event': 'EVENT_A' }
+{ 'event': 'EVENT_B',
+  'data': { } }
+{ 'event': 'EVENT_C',
+  'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
+{ 'event': 'EVENT_D',
+  'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 
'EnumOne' } }
diff --git a/tests/qapi-schema/qapi-schema-test.out 
b/tests/qapi-schema/qapi-schema-test.out
index 6cd03f3..95e9899 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema

[Qemu-devel] [PATCH V6 00/29] add direct support of event in qapi schema

2014-06-05 Thread Wenchao Xia
This series add support for tag/keyword 'event' in qapi-schema.
A new file was created to store some helper functions in patch 2, patch 4 is
the test case, patch 5 is a convert example.

The implemention is done by generate API and a batch of parameters for each
event define, it doesn't generate a struture and visit function in the
background for every event, so it doesn't support nested structure in the
define to avoid trouble. A callback layer is added to control the behavior.
More detail can be found in patch 3's message and incode comments.

v2:
  Address Luiz's comments:
  patch 3: rename *err to *local_err, do not initialize *qmp = NULL, create
a new function qmp_build_evet_dict().
  Other change:
  reorgnized script in patch 3, it have a clear three steps, see patch 3's
incode comments.

v3:
  Address Luiz's comments:
  2/5: use -1 when fail to get host timestamp.
  3/5: typo fix and better incode comments. all unchanged functions are moved
into qmp-event.c, from generated file. To do so without include issue, 'int'
was used intead of 'enum' in function prototype declaration, since the 'enum'
define is a generated type.
  Address Eric's comments:
  2/5: use -1 when fail to get host timestamp.
  3/5: typo fix, add docs/qapi-code-gen.txt.
  4/5: typo fix, verify no other fields in member 'timestamp'.
  5/5: add doc in qapi-schema.json.
  fix license, all script using GPL2, all C code use LGPL, just as other
similar files in upstream.

v4:
  Address Eric's comments:
  2/5: typo fix, add copyright declaration, use a static function pointer
instead of a struct in C file, assign -1 in two line of codes to avoid issue
when tv_sec and tv_usec are not in same data width, fix indention.
  3/5: typo fix, add copyright declaration.
  4/5: add copyright declaration, simplify string compare with
 "d->result = g_strcmp0(...) == 0;", add check for tv_usec's range and value.
  Other:
  3/5: all error check code was moved from qapi-event.py to qapi.py, and it
reports better message with line number info. Added related test case.
  Note:
  Benoit's series which track input file better seems not the final version,
so I didn't rebase this series ontop for now, will do it once Benoit's ones
get ACKed.

v5:
  Address Eric and Markus's comments:
  2/28: use uint64_t for both sec and usec, to avoid type cast issue in printf.
  Other:
  Remove RFC, add full coversion by patch 5-28.
  3/28: add prefix for event enum type name, to avoid double define of
QAPIEvent in test code.

v6:
  Address Eric's comments:
  3/29: employ modularization mechnism of schema file of Lluís series, remove
error_is_set() usage.
  4/29: Makefile change for Lluís series.
  5/29: separate patch for refactoring the existing schema defines, improve doc
for @service in VncBasicInfo.
  7/29-28/29: define and convert event caller one by one.
  Other change:
  6/29: new way to add event emit implemention. In v5 it breaks old event
mechnism, in v6 it touch nothing of old event mechnism but add a new set of
functions for new event mechnism.
  7/29: Add new file qapi-event.json to store event defines, and all type
defines goes into qapi-schema.json.
  29/29: related clean up change.
  Note:
  I have no way to verify target-s390x/kvm.c touched by patch 27/29, and
block/quorum.c touched by patch 28/29, need a confirm from whom has the test
env.

Wenchao Xia (29):
  1 os-posix: include sys/time.h
  2 qapi: add event helper functions
  3 qapi script: add event support
  4 test: add test cases for qapi event
  5 qapi: adjust existing defines
  6 monitor: add an implemention as qapi event emit method
  7 qapi: add new schema file qapi-event.json
  8 qapi event: convert SHUTDOWN
  9 qapi event: convert POWERDOWN
  10 qapi event: convert RESET
  11 qapi event: convert STOP
  12 qapi event: convert RESUME
  13 qapi event: convert SUSPEND
  14 qapi event: convert SUSPEND_DISK
  15 qapi event: convert WAKEUP
  16 qapi event: convert RTC_CHANGE
  17 qapi event: convert WATCHDOG
  18 qapi event: convert DEVICE_DELETED
  19 qapi event: convert DEVICE_TRAY_MOVED
  20 qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR
  21 qapi event: convert BLOCK_IMAGE_CORRUPTED
  22 qapi event: convert other BLOCK_JOB events
  23 qapi event: convert NIC_RX_FILTER_CHANGED
  24 qapi event: convert VNC events
  25 qapi event: convert SPICE events
  26 qapi event: convert BALLOON_CHANGE
  27 qapi event: convert GUEST_PANICKED
  28 qapi event: convert QUORUM events
  29 qapi event: clean up

 Makefile |   21 +-
 Makefile.objs|2 +-
 balloon.c|   13 -
 block.c  |   68 +---
 block/backup.c   |2 +-
 block/mirror.c   |9 +-
 block/qcow2-refcount.c   

[Qemu-devel] [PATCH V6 08/29] qapi event: convert SHUTDOWN

2014-06-05 Thread Wenchao Xia
This patch also eliminates build time warning caused by
QAPI_EVENT_MAX = 0.

Signed-off-by: Wenchao Xia 
---
 docs/qmp/qmp-events.txt |   15 ---
 qapi-event.json |   12 
 vl.c|3 ++-
 3 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index 145402e..ff2f30d 100644
--- a/docs/qmp/qmp-events.txt
+++ b/docs/qmp/qmp-events.txt
@@ -304,21 +304,6 @@ Example:
 "data": { "offset": 78 },
 "timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
 
-SHUTDOWN
-
-
-Emitted when the Virtual Machine is powered down.
-
-Data: None.
-
-Example:
-
-{ "event": "SHUTDOWN",
-"timestamp": { "seconds": 1267040730, "microseconds": 682951 } }
-
-Note: If the command-line option "-no-shutdown" has been specified, a STOP
-event will eventually follow the SHUTDOWN event.
-
 SPICE_CONNECTED, SPICE_DISCONNECTED
 ---
 
diff --git a/qapi-event.json b/qapi-event.json
index e69de29..b2a943f 100644
--- a/qapi-event.json
+++ b/qapi-event.json
@@ -0,0 +1,12 @@
+##
+# @SHUTDOWN
+#
+# Emitted when the virtual machine shutdown, qemu terminated the emulation and
+# is about to exit.
+#
+# Note: If the command-line option "-no-shutdown" has been specified, qemu will
+# not exit, and a STOP event will eventually follow the SHUTDOWN event
+#
+# Since: 2.1
+##
+{ 'event': 'SHUTDOWN' }
diff --git a/vl.c b/vl.c
index 0c15608..273d237 100644
--- a/vl.c
+++ b/vl.c
@@ -117,6 +117,7 @@ int main(int argc, char **argv)
 #include "ui/qemu-spice.h"
 #include "qapi/string-input-visitor.h"
 #include "qom/object_interfaces.h"
+#include "qapi-event.h"
 
 #define DEFAULT_RAM_SIZE 128
 
@@ -2028,7 +2029,7 @@ static bool main_loop_should_exit(void)
 }
 if (qemu_shutdown_requested()) {
 qemu_kill_report();
-monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
+qapi_event_send_shutdown(NULL);
 if (no_shutdown) {
 vm_stop(RUN_STATE_SHUTDOWN);
 } else {
-- 
1.7.1




[Qemu-devel] [PATCH V6 03/29] qapi script: add event support

2014-06-05 Thread Wenchao Xia
qapi-event.py will parse the schema and generate qapi-event.c, then
the API in qapi-event.c can be used to handle event in qemu code.
All API have prefix "qapi_event".

The script mainly includes two parts: generate API for each event
define, generate an enum type for all defined events.

Since in some cases the real emit behavior may change, for example,
qemu-img would not send a event, a callback layer is used to
control the behavior. As a result, the stubs at compile time
can be saved, the binding of block layer code and monitor code
will become looser.

Signed-off-by: Wenchao Xia 
---
 Makefile |   11 +-
 Makefile.objs|2 +-
 docs/qapi-code-gen.txt   |   18 ++
 scripts/qapi-event.py|  369 ++
 scripts/qapi.py  |   12 +
 tests/Makefile   |2 +-
 tests/qapi-schema/event-nest-struct.err  |1 +
 tests/qapi-schema/event-nest-struct.exit |1 +
 tests/qapi-schema/event-nest-struct.json |2 +
 9 files changed, 413 insertions(+), 5 deletions(-)
 create mode 100644 scripts/qapi-event.py
 create mode 100644 tests/qapi-schema/event-nest-struct.err
 create mode 100644 tests/qapi-schema/event-nest-struct.exit
 create mode 100644 tests/qapi-schema/event-nest-struct.json
 create mode 100644 tests/qapi-schema/event-nest-struct.out

diff --git a/Makefile b/Makefile
index d830483..237657e 100644
--- a/Makefile
+++ b/Makefile
@@ -45,8 +45,8 @@ endif
 endif
 
 GENERATED_HEADERS = config-host.h qemu-options.def
-GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
-GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c
+GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h qapi-event.h
+GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c qapi-event.c
 
 GENERATED_HEADERS += trace/generated-events.h
 GENERATED_SOURCES += trace/generated-events.c
@@ -202,7 +202,7 @@ Makefile: $(version-obj-y) $(version-lobj-y)
 # Build libraries
 
 libqemustub.a: $(stub-obj-y)
-libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o
+libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o qapi-event.o
 
 block-modules = $(foreach o,$(block-obj-m),"$(basename $(subst /,-,$o))",) NULL
 util/module.o-cflags = -D'CONFIG_BLOCK_MODULES=$(block-modules)'
@@ -256,6 +256,11 @@ $(SRC_PATH)/qapi-schema.json 
$(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py \
$(gen-out-type) -o "." -b -i $<, \
"  GEN   $@")
+qapi-event.c qapi-event.h :\
+$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-event.py $(qapi-py)
+   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py \
+   $(gen-out-type) -o "." -b -i $<, \
+   "  GEN   $@")
 qmp-commands.h qmp-marshal.c :\
 $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \
diff --git a/Makefile.objs b/Makefile.objs
index b897e1d..1f76cea 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -12,7 +12,7 @@ block-obj-y += main-loop.o iohandler.o qemu-timer.o
 block-obj-$(CONFIG_POSIX) += aio-posix.o
 block-obj-$(CONFIG_WIN32) += aio-win32.o
 block-obj-y += block/
-block-obj-y += qapi-types.o qapi-visit.o
+block-obj-y += qapi-types.o qapi-visit.o qapi-event.o
 block-obj-y += qemu-io-cmds.o
 
 block-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o
diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt
index dea0d50..c3d315f 100644
--- a/docs/qapi-code-gen.txt
+++ b/docs/qapi-code-gen.txt
@@ -215,6 +215,24 @@ An example command is:
'data': { 'arg1': 'str', '*arg2': 'str' },
'returns': 'str' }
 
+=== Events ===
+
+Events are defined with key word 'event'.  When 'data' is also specified,
+additional info will be carried on.  Finally there will be C API generated
+in qapi-event.h, and when called by QEMU code, a message with timestamp will
+be emitted on the wire.  If timestamp is -1, it means failure to retrieve host
+time.
+
+An example event is:
+
+{ 'event': 'EVENT_C',
+  'data': { '*a': 'int', 'b': 'str' } }
+
+Resulting in this JSON object:
+
+{ "event": "EVENT_C",
+  "data": { "b": "test string" },
+  "timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
 
 == Code generation ==
 
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
new file mode 100644
index 000..e1dcc43
--- /dev/null
+++ b/scripts/qapi-event.py
@@ -0,0 +1,369 @@
+#
+# QAPI event generator
+#
+# Copyright (c) 2014 Wenchao Xia

[Qemu-devel] [PATCH V6 02/29] qapi: add event helper functions

2014-06-05 Thread Wenchao Xia
This file holds some functions that do not need to be generated.

Signed-off-by: Wenchao Xia 
Reviewed-by: Eric Blake 
---
 include/qapi/qmp-event.h |   27 +
 qapi/Makefile.objs   |1 +
 qapi/qmp-event.c |   74 ++
 3 files changed, 102 insertions(+), 0 deletions(-)
 create mode 100644 include/qapi/qmp-event.h
 create mode 100644 qapi/qmp-event.c

diff --git a/include/qapi/qmp-event.h b/include/qapi/qmp-event.h
new file mode 100644
index 000..02b6ce5
--- /dev/null
+++ b/include/qapi/qmp-event.h
@@ -0,0 +1,27 @@
+/*
+ * QMP Event related
+ *
+ * Copyright (c) 2014 Wenchao Xia
+ *
+ * Authors:
+ *  Wenchao Xia   
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef QMP_EVENT_H
+#define QMP_EVENT_H
+
+#include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
+
+typedef void (*QMPEventFuncEmit)(int event_kind, QDict *dict, Error **errp);
+
+void qmp_event_set_func_emit(QMPEventFuncEmit emit);
+
+QMPEventFuncEmit qmp_event_get_func_emit(void);
+
+QDict *qmp_event_build_dict(const char *event_name);
+#endif
diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs
index 1f9c973..d14b769 100644
--- a/qapi/Makefile.objs
+++ b/qapi/Makefile.objs
@@ -3,3 +3,4 @@ util-obj-y += qmp-output-visitor.o qmp-registry.o qmp-dispatch.o
 util-obj-y += string-input-visitor.o string-output-visitor.o
 
 util-obj-y += opts-visitor.o
+util-obj-y += qmp-event.o
diff --git a/qapi/qmp-event.c b/qapi/qmp-event.c
new file mode 100644
index 000..0d1ce0b
--- /dev/null
+++ b/qapi/qmp-event.c
@@ -0,0 +1,74 @@
+/*
+ * QMP Event related
+ *
+ * Copyright (c) 2014 Wenchao Xia
+ *
+ * Authors:
+ *  Wenchao Xia   
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include 
+
+#include "qemu-common.h"
+#include "qapi/qmp-event.h"
+#include "qapi/qmp/qstring.h"
+#include "qapi/qmp/qjson.h"
+
+#ifdef _WIN32
+#include "sysemu/os-win32.h"
+#endif
+
+#ifdef CONFIG_POSIX
+#include "sysemu/os-posix.h"
+#endif
+
+static QMPEventFuncEmit qmp_emit;
+
+void qmp_event_set_func_emit(QMPEventFuncEmit emit)
+{
+qmp_emit = emit;
+}
+
+QMPEventFuncEmit qmp_event_get_func_emit(void)
+{
+return qmp_emit;
+}
+
+static void timestamp_put(QDict *qdict)
+{
+int err;
+QObject *obj;
+qemu_timeval tv;
+int64_t sec, usec;
+
+err = qemu_gettimeofday(&tv);
+if (err < 0) {
+/* Put -1 to indicate failure of getting host time */
+sec = -1;
+usec = -1;
+} else {
+sec = tv.tv_sec;
+usec = tv.tv_usec;
+}
+
+obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", "
+ "'microseconds': %" PRId64 " }",
+ sec, usec);
+qdict_put_obj(qdict, "timestamp", obj);
+}
+
+/*
+ * Build a QDict, then fill event name and time stamp, caller should free the
+ * QDict after usage.
+ */
+QDict *qmp_event_build_dict(const char *event_name)
+{
+QDict *dict = qdict_new();
+qdict_put(dict, "event", qstring_from_str(event_name));
+timestamp_put(dict);
+return dict;
+}
-- 
1.7.1




Re: [Qemu-devel] qemu core dump when vnc client connect to VM, Is anyone has the similar problem, thanks!

2014-05-15 Thread Wenchao Xia

Yeah, I have experienced it before on some Fefora 18 installation with
the qemu and libvirt it packaged. Sadlly I didn't look deep into it at
that time. It appeared some time when I boot a linux guest changing its
size in startup sequence, or sometime vnc client resize. I guess it is
caused by vnc server side code, either in qemu or vnc library,
recommend try it with latest released qemu and report it later.




Re: [Qemu-devel] [PATCH V3 0/3] Create an include directive for QAPI JSON files

2014-05-15 Thread Wenchao Xia

has this series been upstream? I am waiting for it to rebase my event
series.



Re: [Qemu-devel] [PATCH V5 07/28] qapi event: convert SHUTDOWN

2014-05-07 Thread Wenchao Xia

于 2014/5/1 22:44, Eric Blake 写道:

On 04/30/2014 10:26 PM, Wenchao Xia wrote:

Signed-off-by: Wenchao Xia 
---
  vl.c |3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)


This, and many of the subsequent patches in the series, are a bit
misleading; I have to go back to 5/28 to make sure that both pieces of
the conversion are in sync.  Is there a technical reason why you can't
provide both the qapi definition and the conversion to the new
qapi_event_send_FOO function in the same patch, one patch per FOO,
rather than your current split?


  No, it is just easy to get conflict to modifiy one file in 20+
patches when rebase, so I modified it once in patch 5/28. I'll adjust
it in next version.



Re: [Qemu-devel] [PATCH V5 06/28] monitor: change event functions as an implemention of new emit method

2014-05-07 Thread Wenchao Xia

于 2014/5/2 6:09, Eric Blake 写道:

On 04/30/2014 10:26 PM, Wenchao Xia wrote:

Now monitor has been hooked on the new event mechanism, so the patches
later can convert event callers one by one. qmp_query_events() is also
switched to use new generated event defines. Note that old function
monitor_protocol_event() is kept for existing caller to avoid code break,
but rate limiting is bypassed to avoid too many duplicated code. After
convertion, the function would be removed.


s/convertion/conversion/
s/would/will/



Signed-off-by: Wenchao Xia 
---
  monitor.c |   47 ++-
  1 files changed, 26 insertions(+), 21 deletions(-)




@@ -644,7 +648,8 @@ void monitor_protocol_event(MonitorEvent event, QObject 
*data)
  }

  trace_monitor_protocol_event(event, event_name, qmp);
-monitor_protocol_event_queue(event, QOBJECT(qmp));
+/* Bypass rate limiting for now */
+monitor_protocol_event_emit(event, QOBJECT(qmp));
  QDECREF(qmp);


I'm not quite sure I follow - is this comment evidence of something
temporarily broken for the duration of conversions, that gets fixed
later in the series; or are you breaking event rate limiting?


  This change breaks rate limiting, but gets fixed after conversion.
Since I modified old rate limiting code to work in new event mechnism,
so old event mechnism can't work any more, unless I duplicate those
code, make things complicate.





Re: [Qemu-devel] [PATCH V5 05/28] qapi: define events in qapi schema

2014-05-07 Thread Wenchao Xia

于 2014/5/1 23:00, Eric Blake 写道:

On 04/30/2014 10:26 PM, Wenchao Xia wrote:

Some old type defines for spice and vnc are changed to let new
event defines use them instead of redefine. Note that define of
BlockErrorAction is moved from block.h to qapi schema, and it is
not merged with BlockdevOnError. In schema NIC_RX_FILTER_CHANGED's
param 'name' is changed as optional one, since in caller it is
optional.

Signed-off-by: Wenchao Xia 
---


This is a big patch.  See my comments on 7/28; do you have to do ALL of
the qapi conversion here, or can you split it so that you are adding
qapi one event at a time, in the same patch as that event also uses the
generated code?

Is the code motion of BlockErrorAction something that can be split into
its own patch, to make the review focus easier?  (Code motion and
renaming fallout being separated from new additions is always easier
than having both in one commit)


  OK, adjust it in next version.



+++ b/docs/qmp/qmp-events.txt
@@ -1,39 +1,14 @@
-   QEMU Machine Protocol Events
-   
+   QEMU Machine Protocol Events Examples
+   =

  BALLOON_CHANGE
  --
-
-Emitted when the guest changes the actual BALLOON level. This
-value is equivalent to the 'actual' field return by the
-'query-balloon' command
-
-Data:
-
-- "actual": actual level of the guest memory balloon in bytes (json-number)
-
-Example:
-
  { "event": "BALLOON_CHANGE",
  "data": { "actual": 944766976 },
  "timestamp": { "seconds": 1267020223, "microseconds": 435656 } }


I'm wondering if we still need this file, or if (by the end of the
conversion to qapi) we can just drop it.  Showing only an example usage,
when the qapi already documents everything, isn't adding much value from
my perspective.  On the other hand, if you are able to rebase this patch
to do one event at a time, then keep this file around until the end of
the series.  Then, for each event converted, you remove one chunk of
this file, add one chunk to the schema.json file, and update all places
to generate that new event, all in a single commit, where it becomes
much easier to track that the conversion for that event was correct
(here, there are so many events converted from .txt to .json at once
that it is harder to correlate that the conversion of each event was
correct).



+# @VncBasicInfo
+#
+# The basic information for vnc network connection
  #
-# @host: The host name of the client.  QEMU tries to resolve this to a DNS name
-#when possible.
+# @host: IP address
  #
-# @family: 'ipv6' if the client is connected via IPv6 and TCP
-#  'ipv4' if the client is connected via IPv4 and TCP
-#  'unix' if the client is connected via a unix domain socket
-#  'unknown' otherwise
+# @service: port number
  #
-# @service: The service name of the client's port.  This may depends on the
-#   host system's service database so symbolic names should not be
-#   relied on.


Why are you reducing the information about @service?  At least you got
rid of the typo (s/depends/depend/).


  It is VncBasicInfo so it may indicate the server's port. Maybe:
# @service: The service name of vnc port.  This may depends on the
#   host system's service database so symbolic names should not be
#   relied on.




+##
+# @VncClientInfo:
+#
+# Information about a connected VNC client.
  #
  # @x509_dname: #optional If x509 authentication is in use, the Distinguished
  #  Name of the client.
@@ -1180,8 +1217,8 @@
  # Since: 0.14.0
  ##
  { 'type': 'VncClientInfo',
-  'data': {'host': 'str', 'family': 'str', 'service': 'str',
-   '*x509_dname': 'str', '*sasl_username': 'str'} }
+  'base': 'VncBasicInfo',
+  'data': { '*x509_dname'   : 'str', '*sasl_username': 'str' } }


All this work on refactoring the existing vnc QMP types should be its
own patch, prior to any patch that introduces an event that also uses
the shared types created by your refactoring.


  refactor it later.


+
+##
+# Event defines
+##


If Lluís' series goes in first, it might make sense to have all of the
event descriptions in their own file which gets included from the main
qemu-schema.json.


  How about define them in qemu-events.json?



[Qemu-devel] [PATCH V5 05/28] qapi: define events in qapi schema

2014-04-30 Thread Wenchao Xia
Some old type defines for spice and vnc are changed to let new
event defines use them instead of redefine. Note that define of
BlockErrorAction is moved from block.h to qapi schema, and it is
not merged with BlockdevOnError. In schema NIC_RX_FILTER_CHANGED's
param 'name' is changed as optional one, since in caller it is
optional.

Signed-off-by: Wenchao Xia 
---
 block.c |   17 +-
 block/backup.c  |2 +-
 block/mirror.c  |7 +-
 block/stream.c  |4 +-
 blockjob.c  |   11 +-
 docs/qmp/qmp-events.txt |  354 +--
 hmp.c   |5 +-
 hw/block/virtio-blk.c   |6 +-
 hw/ide/core.c   |6 +-
 hw/scsi/scsi-disk.c |6 +-
 include/block/block.h   |4 -
 include/qemu/sockets.h  |2 +
 qapi-schema.json|  632 +--
 ui/spice-core.c |7 +-
 ui/vnc.c|9 +-
 util/qemu-sockets.c |   10 +
 16 files changed, 664 insertions(+), 418 deletions(-)

diff --git a/block.c b/block.c
index 4745712..e9a55bb 100644
--- a/block.c
+++ b/block.c
@@ -2046,13 +2046,13 @@ void bdrv_emit_qmp_error_event(const BlockDriverState 
*bdrv,
 const char *action_str;
 
 switch (action) {
-case BDRV_ACTION_REPORT:
+case BLOCK_ERROR_ACTION_REPORT:
 action_str = "report";
 break;
-case BDRV_ACTION_IGNORE:
+case BLOCK_ERROR_ACTION_IGNORE:
 action_str = "ignore";
 break;
-case BDRV_ACTION_STOP:
+case BLOCK_ERROR_ACTION_STOP:
 action_str = "stop";
 break;
 default:
@@ -3496,13 +3496,14 @@ BlockErrorAction bdrv_get_error_action(BlockDriverState 
*bs, bool is_read, int e
 
 switch (on_err) {
 case BLOCKDEV_ON_ERROR_ENOSPC:
-return (error == ENOSPC) ? BDRV_ACTION_STOP : BDRV_ACTION_REPORT;
+return (error == ENOSPC) ?
+   BLOCK_ERROR_ACTION_STOP : BLOCK_ERROR_ACTION_REPORT;
 case BLOCKDEV_ON_ERROR_STOP:
-return BDRV_ACTION_STOP;
+return BLOCK_ERROR_ACTION_STOP;
 case BLOCKDEV_ON_ERROR_REPORT:
-return BDRV_ACTION_REPORT;
+return BLOCK_ERROR_ACTION_REPORT;
 case BLOCKDEV_ON_ERROR_IGNORE:
-return BDRV_ACTION_IGNORE;
+return BLOCK_ERROR_ACTION_IGNORE;
 default:
 abort();
 }
@@ -3517,7 +3518,7 @@ void bdrv_error_action(BlockDriverState *bs, 
BlockErrorAction action,
 {
 assert(error >= 0);
 bdrv_emit_qmp_error_event(bs, QEVENT_BLOCK_IO_ERROR, action, is_read);
-if (action == BDRV_ACTION_STOP) {
+if (action == BLOCK_ERROR_ACTION_STOP) {
 vm_stop(RUN_STATE_IO_ERROR);
 bdrv_iostatus_set_err(bs, error);
 }
diff --git a/block/backup.c b/block/backup.c
index 15a2e55..7978ae2 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -325,7 +325,7 @@ static void coroutine_fn backup_run(void *opaque)
 /* Depending on error action, fail now or retry cluster */
 BlockErrorAction action =
 backup_error_action(job, error_is_read, -ret);
-if (action == BDRV_ACTION_REPORT) {
+if (action == BLOCK_ERROR_ACTION_REPORT) {
 break;
 } else {
 start--;
diff --git a/block/mirror.c b/block/mirror.c
index 36f4f8e..8a1a359 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -118,7 +118,7 @@ static void mirror_write_complete(void *opaque, int ret)
 
 bdrv_set_dirty(source, op->sector_num, op->nb_sectors);
 action = mirror_error_action(s, false, -ret);
-if (action == BDRV_ACTION_REPORT && s->ret >= 0) {
+if (action == BLOCK_ERROR_ACTION_REPORT && s->ret >= 0) {
 s->ret = ret;
 }
 }
@@ -135,7 +135,7 @@ static void mirror_read_complete(void *opaque, int ret)
 
 bdrv_set_dirty(source, op->sector_num, op->nb_sectors);
 action = mirror_error_action(s, true, -ret);
-if (action == BDRV_ACTION_REPORT && s->ret >= 0) {
+if (action == BLOCK_ERROR_ACTION_REPORT && s->ret >= 0) {
 s->ret = ret;
 }
 
@@ -412,7 +412,8 @@ static void coroutine_fn mirror_run(void *opaque)
 trace_mirror_before_flush(s);
 ret = bdrv_flush(s->target);
 if (ret < 0) {
-if (mirror_error_action(s, false, -ret) == BDRV_ACTION_REPORT) 
{
+if (mirror_error_action(s, false, -ret) ==
+BLOCK_ERROR_ACTION_REPORT) {
 goto immediate_exit;
 }
 } else {
diff --git a/block/stream.c b/block/stream.c
index dd0b4ac..b923bb3 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -159,14 +159,14 @@ wait:
 BlockErrorAction action =
 block_job_error_action(&s->common, s->common.bs

[Qemu-devel] [PATCH V5 12/28] qapi event: convert SUSPEND

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 vl.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/vl.c b/vl.c
index 3679588..3ee2494 100644
--- a/vl.c
+++ b/vl.c
@@ -1907,7 +1907,7 @@ static void qemu_system_suspend(void)
 pause_all_vcpus();
 notifier_list_notify(&suspend_notifiers, NULL);
 runstate_set(RUN_STATE_SUSPENDED);
-monitor_protocol_event(QEVENT_SUSPEND, NULL);
+qapi_event_send_suspend(NULL);
 }
 
 void qemu_system_suspend_request(void)
-- 
1.7.1




[Qemu-devel] [PATCH V5 11/28] qapi event: convert RESUME

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 vl.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/vl.c b/vl.c
index 717bfc1..3679588 100644
--- a/vl.c
+++ b/vl.c
@@ -1734,7 +1734,7 @@ void vm_start(void)
 runstate_set(RUN_STATE_RUNNING);
 vm_state_notify(1, RUN_STATE_RUNNING);
 resume_all_vcpus();
-monitor_protocol_event(QEVENT_RESUME, NULL);
+qapi_event_send_resume(NULL);
 }
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH V5 22/28] qapi event: convert NIC_RX_FILTER_CHANGED

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 hw/net/virtio-net.c |   13 +++--
 1 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 33bd233..216d4e1 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -22,7 +22,7 @@
 #include "net/vhost_net.h"
 #include "hw/virtio/virtio-bus.h"
 #include "qapi/qmp/qjson.h"
-#include "monitor/monitor.h"
+#include "qapi-event.h"
 
 #define VIRTIO_NET_VM_VERSION11
 
@@ -196,19 +196,12 @@ static void virtio_net_set_link_status(NetClientState *nc)
 
 static void rxfilter_notify(NetClientState *nc)
 {
-QObject *event_data;
 VirtIONet *n = qemu_get_nic_opaque(nc);
 
 if (nc->rxfilter_notify_enabled) {
 gchar *path = object_get_canonical_path(OBJECT(n->qdev));
-if (n->netclient_name) {
-event_data = qobject_from_jsonf("{ 'name': %s, 'path': %s }",
-n->netclient_name, path);
-} else {
-event_data = qobject_from_jsonf("{ 'path': %s }", path);
-}
-monitor_protocol_event(QEVENT_NIC_RX_FILTER_CHANGED, event_data);
-qobject_decref(event_data);
+qapi_event_send_nic_rx_filter_changed(!!n->netclient_name,
+  n->netclient_name, path, NULL);
 g_free(path);
 
 /* disable event notification to avoid events flooding */
-- 
1.7.1




[Qemu-devel] [PATCH V5 16/28] qapi event: convert WATCHDOG

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 hw/watchdog/watchdog.c |   23 +++
 1 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/hw/watchdog/watchdog.c b/hw/watchdog/watchdog.c
index f28161b..9284d3f 100644
--- a/hw/watchdog/watchdog.c
+++ b/hw/watchdog/watchdog.c
@@ -24,9 +24,9 @@
 #include "qemu/config-file.h"
 #include "qemu/queue.h"
 #include "qapi/qmp/types.h"
-#include "monitor/monitor.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/watchdog.h"
+#include "qapi-event.h"
 
 /* Possible values for action parameter. */
 #define WDT_RESET1 /* Hard reset. */
@@ -101,15 +101,6 @@ int select_watchdog_action(const char *p)
 return 0;
 }
 
-static void watchdog_mon_event(const char *action)
-{
-QObject *data;
-
-data = qobject_from_jsonf("{ 'action': %s }", action);
-monitor_protocol_event(QEVENT_WATCHDOG, data);
-qobject_decref(data);
-}
-
 /* This actually performs the "action" once a watchdog has expired,
  * ie. reboot, shutdown, exit, etc.
  */
@@ -117,31 +108,31 @@ void watchdog_perform_action(void)
 {
 switch(watchdog_action) {
 case WDT_RESET: /* same as 'system_reset' in monitor */
-watchdog_mon_event("reset");
+qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_RESET, NULL);
 qemu_system_reset_request();
 break;
 
 case WDT_SHUTDOWN:  /* same as 'system_powerdown' in monitor */
-watchdog_mon_event("shutdown");
+qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_SHUTDOWN, NULL);
 qemu_system_powerdown_request();
 break;
 
 case WDT_POWEROFF:  /* same as 'quit' command in monitor */
-watchdog_mon_event("poweroff");
+qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_POWEROFF, NULL);
 exit(0);
 
 case WDT_PAUSE: /* same as 'stop' command in monitor */
-watchdog_mon_event("pause");
+qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_PAUSE, NULL);
 vm_stop(RUN_STATE_WATCHDOG);
 break;
 
 case WDT_DEBUG:
-watchdog_mon_event("debug");
+qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_DEBUG, NULL);
 fprintf(stderr, "watchdog: timer fired\n");
 break;
 
 case WDT_NONE:
-watchdog_mon_event("none");
+qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_NONE, NULL);
 break;
 }
 }
-- 
1.7.1




[Qemu-devel] [PATCH V5 13/28] qapi event: convert SUSPEND_DISK

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 hw/acpi/core.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 79414b4..ace6438 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -22,11 +22,11 @@
 #include "hw/hw.h"
 #include "hw/i386/pc.h"
 #include "hw/acpi/acpi.h"
-#include "monitor/monitor.h"
 #include "qemu/config-file.h"
 #include "qapi/opts-visitor.h"
 #include "qapi/dealloc-visitor.h"
 #include "qapi-visit.h"
+#include "qapi-event.h"
 
 struct acpi_table_header {
 uint16_t _length; /* our length, not actual part of the hdr */
@@ -550,7 +550,7 @@ static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
 break;
 default:
 if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
-monitor_protocol_event(QEVENT_SUSPEND_DISK, NULL);
+qapi_event_send_suspend_disk(NULL);
 qemu_system_shutdown_request();
 }
 break;
-- 
1.7.1




[Qemu-devel] [PATCH V5 15/28] qapi event: convert RTC_CHANGE

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 hw/ppc/spapr_rtas.c |3 ++-
 hw/timer/mc146818rtc.c  |3 ++-
 include/sysemu/sysemu.h |2 --
 vl.c|9 -
 4 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index 73860d0..d639b20 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -32,6 +32,7 @@
 
 #include "hw/ppc/spapr.h"
 #include "hw/ppc/spapr_vio.h"
+#include "qapi-event.h"
 
 #include 
 
@@ -93,7 +94,7 @@ static void rtas_set_time_of_day(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 tm.tm_sec = rtas_ld(args, 5);
 
 /* Just generate a monitor event for the change */
-rtc_change_mon_event(&tm);
+qapi_event_send_rtc_change(qemu_timedate_diff(&tm), NULL);
 spapr->rtc_offset = qemu_timedate_diff(&tm);
 
 rtas_st(rets, 0, RTAS_OUT_SUCCESS);
diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index 8509309..eeeb91c 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -26,6 +26,7 @@
 #include "sysemu/sysemu.h"
 #include "hw/timer/mc146818rtc.h"
 #include "qapi/visitor.h"
+#include "qapi-event.h"
 
 #ifdef TARGET_I386
 #include "hw/i386/apic.h"
@@ -530,7 +531,7 @@ static void rtc_set_time(RTCState *s)
 s->base_rtc = mktimegm(&tm);
 s->last_update = qemu_clock_get_ns(rtc_clock);
 
-rtc_change_mon_event(&tm);
+qapi_event_send_rtc_change(qemu_timedate_diff(&tm), NULL);
 }
 
 static void rtc_set_cmos(RTCState *s, const struct tm *tm)
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index ba5c7f8..0046b27 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -189,8 +189,6 @@ void do_usb_add(Monitor *mon, const QDict *qdict);
 void do_usb_del(Monitor *mon, const QDict *qdict);
 void usb_info(Monitor *mon, const QDict *qdict);
 
-void rtc_change_mon_event(struct tm *tm);
-
 void add_boot_device_path(int32_t bootindex, DeviceState *dev,
   const char *suffix);
 char *get_boot_devices_list(size_t *size, bool ignore_suffixes);
diff --git a/vl.c b/vl.c
index 73b4725..ecea575 100644
--- a/vl.c
+++ b/vl.c
@@ -727,15 +727,6 @@ int qemu_timedate_diff(struct tm *tm)
 return seconds - time(NULL);
 }
 
-void rtc_change_mon_event(struct tm *tm)
-{
-QObject *data;
-
-data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
-monitor_protocol_event(QEVENT_RTC_CHANGE, data);
-qobject_decref(data);
-}
-
 static void configure_rtc_date_offset(const char *startdate, int legacy)
 {
 time_t rtc_start_date;
-- 
1.7.1




[Qemu-devel] [PATCH V5 17/28] qapi event: convert DEVICE_DELETED

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 hw/core/qdev.c |   12 ++--
 1 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 60f9df1..ac85eaf 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -32,8 +32,8 @@
 #include "qapi/qmp/qerror.h"
 #include "qapi/visitor.h"
 #include "qapi/qmp/qjson.h"
-#include "monitor/monitor.h"
 #include "hw/hotplug.h"
+#include "qapi-event.h"
 
 int qdev_hotplug = 0;
 static bool qdev_hot_added = false;
@@ -874,7 +874,6 @@ static void device_unparent(Object *obj)
 {
 DeviceState *dev = DEVICE(obj);
 BusState *bus;
-QObject *event_data;
 bool have_realized = dev->realized;
 
 if (dev->realized) {
@@ -894,14 +893,7 @@ static void device_unparent(Object *obj)
 if (have_realized) {
 gchar *path = object_get_canonical_path(OBJECT(dev));
 
-if (dev->id) {
-event_data = qobject_from_jsonf("{ 'device': %s, 'path': %s }",
-dev->id, path);
-} else {
-event_data = qobject_from_jsonf("{ 'path': %s }", path);
-}
-monitor_protocol_event(QEVENT_DEVICE_DELETED, event_data);
-qobject_decref(event_data);
+qapi_event_send_device_deleted(!!dev->id, dev->id, path, NULL);
 g_free(path);
 }
 }
-- 
1.7.1




[Qemu-devel] [PATCH V5 18/28] qapi event: convert DEVICE_TRAY_MOVED

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 block.c |   21 +++--
 1 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/block.c b/block.c
index e9a55bb..dae5d25 100644
--- a/block.c
+++ b/block.c
@@ -35,6 +35,7 @@
 #include "block/qapi.h"
 #include "qmp-commands.h"
 #include "qemu/timer.h"
+#include "qapi-event.h"
 
 #ifdef CONFIG_BSD
 #include 
@@ -2068,17 +2069,6 @@ void bdrv_emit_qmp_error_event(const BlockDriverState 
*bdrv,
 qobject_decref(data);
 }
 
-static void bdrv_emit_qmp_eject_event(BlockDriverState *bs, bool ejected)
-{
-QObject *data;
-
-data = qobject_from_jsonf("{ 'device': %s, 'tray-open': %i }",
-  bdrv_get_device_name(bs), ejected);
-monitor_protocol_event(QEVENT_DEVICE_TRAY_MOVED, data);
-
-qobject_decref(data);
-}
-
 static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
 {
 if (bs->dev_ops && bs->dev_ops->change_media_cb) {
@@ -2086,11 +2076,13 @@ static void bdrv_dev_change_media_cb(BlockDriverState 
*bs, bool load)
 bs->dev_ops->change_media_cb(bs->dev_opaque, load);
 if (tray_was_closed) {
 /* tray open */
-bdrv_emit_qmp_eject_event(bs, true);
+qapi_event_send_device_tray_moved(bdrv_get_device_name(bs),
+  true, NULL);
 }
 if (load) {
 /* tray close */
-bdrv_emit_qmp_eject_event(bs, false);
+qapi_event_send_device_tray_moved(bdrv_get_device_name(bs),
+  false, NULL);
 }
 }
 }
@@ -5053,7 +5045,8 @@ void bdrv_eject(BlockDriverState *bs, bool eject_flag)
 }
 
 if (bs->device_name[0] != '\0') {
-bdrv_emit_qmp_eject_event(bs, eject_flag);
+qapi_event_send_device_tray_moved(bdrv_get_device_name(bs),
+  eject_flag, NULL);
 }
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH V5 25/28] qapi event: convert BALLOON_CHANGE

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 balloon.c  |   13 -
 hw/virtio/virtio-balloon.c |6 --
 include/sysemu/balloon.h   |2 --
 3 files changed, 4 insertions(+), 17 deletions(-)

diff --git a/balloon.c b/balloon.c
index e321f2c..b70da4f 100644
--- a/balloon.c
+++ b/balloon.c
@@ -81,19 +81,6 @@ static int qemu_balloon_status(BalloonInfo *info)
 return 1;
 }
 
-void qemu_balloon_changed(int64_t actual)
-{
-QObject *data;
-
-data = qobject_from_jsonf("{ 'actual': %" PRId64 " }",
-  actual);
-
-monitor_protocol_event(QEVENT_BALLOON_CHANGE, data);
-
-qobject_decref(data);
-}
-
-
 BalloonInfo *qmp_query_balloon(Error **errp)
 {
 BalloonInfo *info;
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index a470a0b..6af21a7 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -24,6 +24,7 @@
 #include "sysemu/kvm.h"
 #include "exec/address-spaces.h"
 #include "qapi/visitor.h"
+#include "qapi-event.h"
 
 #if defined(__linux__)
 #include 
@@ -275,8 +276,9 @@ static void virtio_balloon_set_config(VirtIODevice *vdev,
 memcpy(&config, config_data, sizeof(struct virtio_balloon_config));
 dev->actual = le32_to_cpu(config.actual);
 if (dev->actual != oldactual) {
-qemu_balloon_changed(ram_size -
-   ((ram_addr_t) dev->actual << VIRTIO_BALLOON_PFN_SHIFT));
+qapi_event_send_balloon_change(ram_size -
+((ram_addr_t) dev->actual << VIRTIO_BALLOON_PFN_SHIFT),
+NULL);
 }
 }
 
diff --git a/include/sysemu/balloon.h b/include/sysemu/balloon.h
index bd9d395..0345e01 100644
--- a/include/sysemu/balloon.h
+++ b/include/sysemu/balloon.h
@@ -24,6 +24,4 @@ int qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
 QEMUBalloonStatus *stat_func, void *opaque);
 void qemu_remove_balloon_handler(void *opaque);
 
-void qemu_balloon_changed(int64_t actual);
-
 #endif
-- 
1.7.1




[Qemu-devel] [PATCH V5 21/28] qapi event: convert other BLOCK_JOB events

2014-04-30 Thread Wenchao Xia
BLOCK_JOB_COMPLETED, BLOCK_JOB_CANCELLED, BLOCK_JOB_READY are
converted.

Signed-off-by: Wenchao Xia 
---
 block/mirror.c   |2 +-
 blockdev.c   |   12 +---
 blockjob.c   |   36 
 include/block/blockjob.h |   17 +
 4 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/block/mirror.c b/block/mirror.c
index 8a1a359..9cacc15 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -424,7 +424,7 @@ static void coroutine_fn mirror_run(void *opaque)
  */
 s->common.offset = end * BDRV_SECTOR_SIZE;
 if (!s->synced) {
-block_job_ready(&s->common);
+block_job_event_ready(&s->common);
 s->synced = true;
 }
 
diff --git a/blockdev.c b/blockdev.c
index 7810e9f..bb2c0e0 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1809,23 +1809,21 @@ void qmp_block_resize(bool has_device, const char 
*device,
 static void block_job_cb(void *opaque, int ret)
 {
 BlockDriverState *bs = opaque;
-QObject *obj;
+const char *msg = NULL;
 
 trace_block_job_cb(bs, bs->job, ret);
 
 assert(bs->job);
-obj = qobject_from_block_job(bs->job);
+
 if (ret < 0) {
-QDict *dict = qobject_to_qdict(obj);
-qdict_put(dict, "error", qstring_from_str(strerror(-ret)));
+msg = strerror(-ret);
 }
 
 if (block_job_is_cancelled(bs->job)) {
-monitor_protocol_event(QEVENT_BLOCK_JOB_CANCELLED, obj);
+block_job_event_cancelled(bs->job);
 } else {
-monitor_protocol_event(QEVENT_BLOCK_JOB_COMPLETED, obj);
+block_job_event_completed(bs->job, msg);
 }
-qobject_decref(obj);
 
 bdrv_put_ref_bh_schedule(bs);
 }
diff --git a/blockjob.c b/blockjob.c
index 5c2ae1b..8c90fd3 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -26,7 +26,6 @@
 #include "config-host.h"
 #include "qemu-common.h"
 #include "trace.h"
-#include "monitor/monitor.h"
 #include "block/block.h"
 #include "block/blockjob.h"
 #include "block/block_int.h"
@@ -229,26 +228,31 @@ static void block_job_iostatus_set_err(BlockJob *job, int 
error)
 }
 }
 
+void block_job_event_cancelled(BlockJob *job)
+{
+qapi_event_send_block_job_cancelled(job->driver->job_type,
+bdrv_get_device_name(job->bs),
+job->len,
+job->offset,
+job->speed,
+NULL);
+}
 
-QObject *qobject_from_block_job(BlockJob *job)
+void block_job_event_completed(BlockJob *job, const char *msg)
 {
-return qobject_from_jsonf("{ 'type': %s,"
-  "'device': %s,"
-  "'len': %" PRId64 ","
-  "'offset': %" PRId64 ","
-  "'speed': %" PRId64 " }",
-  BlockJobType_lookup[job->driver->job_type],
-  bdrv_get_device_name(job->bs),
-  job->len,
-  job->offset,
-  job->speed);
+qapi_event_send_block_job_completed(job->driver->job_type,
+bdrv_get_device_name(job->bs),
+job->len,
+job->offset,
+job->speed,
+!!msg,
+msg,
+NULL);
 }
 
-void block_job_ready(BlockJob *job)
+void block_job_event_ready(BlockJob *job)
 {
-QObject *data = qobject_from_block_job(job);
-monitor_protocol_event(QEVENT_BLOCK_JOB_READY, data);
-qobject_decref(data);
+qapi_event_send_block_job_ready(bdrv_get_device_name(job->bs), NULL);
 }
 
 BlockErrorAction block_job_error_action(BlockJob *job, BlockDriverState *bs,
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index d76de62..0fc5c93 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -214,12 +214,21 @@ void block_job_pause(BlockJob *job);
 void block_job_resume(BlockJob *job);
 
 /**
- * qobject_from_block_job:
+ * block_job_event_cancle:
  * @job: The job whose information is requested.
  *
- * Return a QDict corresponding to @job's query-block-jobs entry.
+ * Send a BLOCK_JOB_CANCELLED event for the specified job.
  */
-QObject *qobject_from_block_job(BlockJob *job);
+void block_job_event_cancelled(BlockJob *job);
+

[Qemu-devel] [PATCH V5 28/28] qapi event: clean up

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 include/monitor/monitor.h  |   40 -
 monitor.c  |   81 
 stubs/Makefile.objs|1 -
 stubs/mon-protocol-event.c |6 ---
 4 files changed, 0 insertions(+), 128 deletions(-)
 delete mode 100644 stubs/mon-protocol-event.c

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 42d8671..d2b24f2 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -19,48 +19,8 @@ extern Monitor *default_mon;
 /* flags for monitor commands */
 #define MONITOR_CMD_ASYNC   0x0001
 
-/* QMP events */
-typedef enum MonitorEvent {
-QEVENT_SHUTDOWN,
-QEVENT_RESET,
-QEVENT_POWERDOWN,
-QEVENT_STOP,
-QEVENT_RESUME,
-QEVENT_VNC_CONNECTED,
-QEVENT_VNC_INITIALIZED,
-QEVENT_VNC_DISCONNECTED,
-QEVENT_BLOCK_IO_ERROR,
-QEVENT_RTC_CHANGE,
-QEVENT_WATCHDOG,
-QEVENT_SPICE_CONNECTED,
-QEVENT_SPICE_INITIALIZED,
-QEVENT_SPICE_DISCONNECTED,
-QEVENT_BLOCK_JOB_COMPLETED,
-QEVENT_BLOCK_JOB_CANCELLED,
-QEVENT_BLOCK_JOB_ERROR,
-QEVENT_BLOCK_JOB_READY,
-QEVENT_DEVICE_DELETED,
-QEVENT_DEVICE_TRAY_MOVED,
-QEVENT_NIC_RX_FILTER_CHANGED,
-QEVENT_SUSPEND,
-QEVENT_SUSPEND_DISK,
-QEVENT_WAKEUP,
-QEVENT_BALLOON_CHANGE,
-QEVENT_SPICE_MIGRATE_COMPLETED,
-QEVENT_GUEST_PANICKED,
-QEVENT_BLOCK_IMAGE_CORRUPTED,
-QEVENT_QUORUM_FAILURE,
-QEVENT_QUORUM_REPORT_BAD,
-
-/* Add to 'monitor_event_names' array in monitor.c when
- * defining new events here */
-
-QEVENT_MAX,
-} MonitorEvent;
-
 int monitor_cur_is_qmp(void);
 
-void monitor_protocol_event(MonitorEvent event, QObject *data);
 void monitor_init(CharDriverState *chr, int flags);
 
 int monitor_suspend(Monitor *mon);
diff --git a/monitor.c b/monitor.c
index 6482ebe..beb02fd 100644
--- a/monitor.c
+++ b/monitor.c
@@ -439,58 +439,6 @@ static void monitor_protocol_emitter(Monitor *mon, QObject 
*data)
 QDECREF(qmp);
 }
 
-static void timestamp_put(QDict *qdict)
-{
-int err;
-QObject *obj;
-qemu_timeval tv;
-
-err = qemu_gettimeofday(&tv);
-if (err < 0)
-return;
-
-obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", "
-"'microseconds': %" PRId64 " }",
-(int64_t) tv.tv_sec, (int64_t) tv.tv_usec);
-qdict_put_obj(qdict, "timestamp", obj);
-}
-
-
-/* Following is kept only for monitor_protocol_event() */
-static const char *monitor_event_names[] = {
-[QEVENT_SHUTDOWN] = "SHUTDOWN",
-[QEVENT_RESET] = "RESET",
-[QEVENT_POWERDOWN] = "POWERDOWN",
-[QEVENT_STOP] = "STOP",
-[QEVENT_RESUME] = "RESUME",
-[QEVENT_VNC_CONNECTED] = "VNC_CONNECTED",
-[QEVENT_VNC_INITIALIZED] = "VNC_INITIALIZED",
-[QEVENT_VNC_DISCONNECTED] = "VNC_DISCONNECTED",
-[QEVENT_BLOCK_IO_ERROR] = "BLOCK_IO_ERROR",
-[QEVENT_RTC_CHANGE] = "RTC_CHANGE",
-[QEVENT_WATCHDOG] = "WATCHDOG",
-[QEVENT_SPICE_CONNECTED] = "SPICE_CONNECTED",
-[QEVENT_SPICE_INITIALIZED] = "SPICE_INITIALIZED",
-[QEVENT_SPICE_DISCONNECTED] = "SPICE_DISCONNECTED",
-[QEVENT_BLOCK_JOB_COMPLETED] = "BLOCK_JOB_COMPLETED",
-[QEVENT_BLOCK_JOB_CANCELLED] = "BLOCK_JOB_CANCELLED",
-[QEVENT_BLOCK_JOB_ERROR] = "BLOCK_JOB_ERROR",
-[QEVENT_BLOCK_JOB_READY] = "BLOCK_JOB_READY",
-[QEVENT_DEVICE_DELETED] = "DEVICE_DELETED",
-[QEVENT_DEVICE_TRAY_MOVED] = "DEVICE_TRAY_MOVED",
-[QEVENT_NIC_RX_FILTER_CHANGED] = "NIC_RX_FILTER_CHANGED",
-[QEVENT_SUSPEND] = "SUSPEND",
-[QEVENT_SUSPEND_DISK] = "SUSPEND_DISK",
-[QEVENT_WAKEUP] = "WAKEUP",
-[QEVENT_BALLOON_CHANGE] = "BALLOON_CHANGE",
-[QEVENT_SPICE_MIGRATE_COMPLETED] = "SPICE_MIGRATE_COMPLETED",
-[QEVENT_GUEST_PANICKED] = "GUEST_PANICKED",
-[QEVENT_BLOCK_IMAGE_CORRUPTED] = "BLOCK_IMAGE_CORRUPTED",
-[QEVENT_QUORUM_FAILURE] = "QUORUM_FAILURE",
-[QEVENT_QUORUM_REPORT_BAD] = "QUORUM_REPORT_BAD",
-};
-QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != QEVENT_MAX)
-
 MonitorEventState monitor_event_state[QAPI_EVENT_MAX];
 
 /*
@@ -624,35 +572,6 @@ static void monitor_protocol_event_init(void)
 qmp_event_set_func_emit(monitor_protocol_event_queue);
 }
 
-/**
- * monitor_protocol_event(): Generate a Monitor event
- *
- * Event-specific data can be emitted through the (optional) 'data' parameter.
- */
-void monitor_protocol_event(MonitorEvent event, QObject *data)
-{
-QDict *qmp;
-const char *event_name;
-
-assert(event < QEVENT_MAX);
-
-event_name = mon

[Qemu-devel] [PATCH V5 20/28] qapi event: convert BLOCK_IMAGE_CORRUPTED

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 block/qcow2-refcount.c |   14 --
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index a37ee45..3ab6b4e 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -27,6 +27,7 @@
 #include "block/qcow2.h"
 #include "qemu/range.h"
 #include "qapi/qmp/types.h"
+#include "qapi-event.h"
 
 static int64_t alloc_clusters_noref(BlockDriverState *bs, uint64_t size);
 static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
@@ -1793,7 +1794,6 @@ int qcow2_pre_write_overlap_check(BlockDriverState *bs, 
int ign, int64_t offset,
 } else if (ret > 0) {
 int metadata_ol_bitnr = ffs(ret) - 1;
 char *message;
-QObject *data;
 
 assert(metadata_ol_bitnr < QCOW2_OL_MAX_BITNR);
 
@@ -1802,12 +1802,14 @@ int qcow2_pre_write_overlap_check(BlockDriverState *bs, 
int ign, int64_t offset,
 metadata_ol_names[metadata_ol_bitnr]);
 message = g_strdup_printf("Prevented %s overwrite",
 metadata_ol_names[metadata_ol_bitnr]);
-data = qobject_from_jsonf("{ 'device': %s, 'msg': %s, 'offset': %"
-PRId64 ", 'size': %" PRId64 " }", bs->device_name, message,
-offset, size);
-monitor_protocol_event(QEVENT_BLOCK_IMAGE_CORRUPTED, data);
+qapi_event_send_block_image_corrupted(bdrv_get_device_name(bs),
+  message,
+  true,
+  offset,
+  true,
+  size,
+  NULL);
 g_free(message);
-qobject_decref(data);
 
 qcow2_mark_corrupt(bs);
 bs->drv = NULL; /* make BDS unusable */
-- 
1.7.1




[Qemu-devel] [PATCH V5 26/28] qapi event: convert GUEST_PANICKED

2014-04-30 Thread Wenchao Xia
monitor.h is still included in target-s390x/kvm.c, since no good
way to verify whether other code need it on my x86 host.

Signed-off-by: Wenchao Xia 
---
 hw/misc/pvpanic.c  |   13 ++---
 target-s390x/kvm.c |8 +++-
 2 files changed, 5 insertions(+), 16 deletions(-)

diff --git a/hw/misc/pvpanic.c b/hw/misc/pvpanic.c
index 5377fee..d396b74 100644
--- a/hw/misc/pvpanic.c
+++ b/hw/misc/pvpanic.c
@@ -14,12 +14,12 @@
 
 #include "qapi/qmp/qobject.h"
 #include "qapi/qmp/qjson.h"
-#include "monitor/monitor.h"
 #include "sysemu/sysemu.h"
 #include "qemu/log.h"
 
 #include "hw/nvram/fw_cfg.h"
 #include "hw/i386/pc.h"
+#include "qapi-event.h"
 
 /* The bit of supported pv event */
 #define PVPANIC_F_PANICKED  0
@@ -31,15 +31,6 @@
 #define ISA_PVPANIC_DEVICE(obj)\
 OBJECT_CHECK(PVPanicState, (obj), TYPE_ISA_PVPANIC_DEVICE)
 
-static void panicked_mon_event(const char *action)
-{
-QObject *data;
-
-data = qobject_from_jsonf("{ 'action': %s }", action);
-monitor_protocol_event(QEVENT_GUEST_PANICKED, data);
-qobject_decref(data);
-}
-
 static void handle_event(int event)
 {
 static bool logged;
@@ -50,7 +41,7 @@ static void handle_event(int event)
 }
 
 if (event & PVPANIC_PANICKED) {
-panicked_mon_event("pause");
+qapi_event_send_guest_panicked(GUEST_PANICK_ACTION_PAUSE, NULL);
 vm_stop(RUN_STATE_GUEST_PANICKED);
 return;
 }
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index a30d1bc..f133b4e 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -37,6 +37,7 @@
 #include "qapi/qmp/qjson.h"
 #include "monitor/monitor.h"
 #include "trace.h"
+#include "qapi-event.h"
 
 /* #define DEBUG_KVM */
 
@@ -784,11 +785,8 @@ static int handle_intercept(S390CPU *cpu)
 if (is_special_wait_psw(cs)) {
 qemu_system_shutdown_request();
 } else {
-QObject *data;
-
-data = qobject_from_jsonf("{ 'action': %s }", "pause");
-monitor_protocol_event(QEVENT_GUEST_PANICKED, data);
-qobject_decref(data);
+qapi_event_send_guest_panicked(GUEST_PANICK_ACTION_PAUSE,
+   NULL);
 vm_stop(RUN_STATE_GUEST_PANICKED);
 }
 }
-- 
1.7.1




[Qemu-devel] [PATCH V5 19/28] qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 block.c   |   36 
 blockjob.c|6 +-
 include/block/block_int.h |3 ---
 3 files changed, 9 insertions(+), 36 deletions(-)

diff --git a/block.c b/block.c
index dae5d25..c6c4e4b 100644
--- a/block.c
+++ b/block.c
@@ -24,7 +24,6 @@
 #include "config-host.h"
 #include "qemu-common.h"
 #include "trace.h"
-#include "monitor/monitor.h"
 #include "block/block_int.h"
 #include "block/blockjob.h"
 #include "qemu/module.h"
@@ -2039,36 +2038,6 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const 
BlockDevOps *ops,
 bs->dev_opaque = opaque;
 }
 
-void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
-   enum MonitorEvent ev,
-   BlockErrorAction action, bool is_read)
-{
-QObject *data;
-const char *action_str;
-
-switch (action) {
-case BLOCK_ERROR_ACTION_REPORT:
-action_str = "report";
-break;
-case BLOCK_ERROR_ACTION_IGNORE:
-action_str = "ignore";
-break;
-case BLOCK_ERROR_ACTION_STOP:
-action_str = "stop";
-break;
-default:
-abort();
-}
-
-data = qobject_from_jsonf("{ 'device': %s, 'action': %s, 'operation': %s 
}",
-  bdrv->device_name,
-  action_str,
-  is_read ? "read" : "write");
-monitor_protocol_event(ev, data);
-
-qobject_decref(data);
-}
-
 static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
 {
 if (bs->dev_ops && bs->dev_ops->change_media_cb) {
@@ -3509,7 +3478,10 @@ void bdrv_error_action(BlockDriverState *bs, 
BlockErrorAction action,
bool is_read, int error)
 {
 assert(error >= 0);
-bdrv_emit_qmp_error_event(bs, QEVENT_BLOCK_IO_ERROR, action, is_read);
+qapi_event_send_block_io_error(bdrv_get_device_name(bs),
+   is_read ? IO_OPERATION_TYPE_READ :
+   IO_OPERATION_TYPE_WRITE,
+   action, NULL);
 if (action == BLOCK_ERROR_ACTION_STOP) {
 vm_stop(RUN_STATE_IO_ERROR);
 bdrv_iostatus_set_err(bs, error);
diff --git a/blockjob.c b/blockjob.c
index b8f6662..5c2ae1b 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -34,6 +34,7 @@
 #include "block/coroutine.h"
 #include "qmp-commands.h"
 #include "qemu/timer.h"
+#include "qapi-event.h"
 
 void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
int64_t speed, BlockDriverCompletionFunc *cb,
@@ -273,7 +274,10 @@ BlockErrorAction block_job_error_action(BlockJob *job, 
BlockDriverState *bs,
 default:
 abort();
 }
-bdrv_emit_qmp_error_event(job->bs, QEVENT_BLOCK_JOB_ERROR, action, 
is_read);
+qapi_event_send_block_job_error(bdrv_get_device_name(bs),
+is_read ? IO_OPERATION_TYPE_READ :
+IO_OPERATION_TYPE_WRITE,
+action, NULL);
 if (action == BLOCK_ERROR_ACTION_STOP) {
 block_job_pause(job);
 block_job_iostatus_set_err(job, error);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index cd5bc73..0026825 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -392,9 +392,6 @@ AioContext *bdrv_get_aio_context(BlockDriverState *bs);
 #ifdef _WIN32
 int is_windows_drive(const char *filename);
 #endif
-void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
-   enum MonitorEvent ev,
-   BlockErrorAction action, bool is_read);
 
 /**
  * stream_start:
-- 
1.7.1




[Qemu-devel] [PATCH V5 23/28] qapi event: convert VNC events

2014-04-30 Thread Wenchao Xia
VNC_CONNECTED, VNC_DISCONNECTED, VNC_INITIALIZED are converted.

Signed-off-by: Wenchao Xia 
---
 ui/vnc.c |  111 --
 ui/vnc.h |4 +-
 2 files changed, 59 insertions(+), 56 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index b03b3b8..a8ae881 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -34,6 +34,7 @@
 #include "qmp-commands.h"
 #include "qemu/osdep.h"
 #include "ui/input.h"
+#include "qapi-event.h"
 
 #define VNC_REFRESH_INTERVAL_BASE GUI_REFRESH_INTERVAL_DEFAULT
 #define VNC_REFRESH_INTERVAL_INC  50
@@ -123,9 +124,10 @@ char *vnc_socket_remote_addr(const char *format, int fd) {
 return addr_to_string(format, &sa, salen);
 }
 
-static int put_addr_qdict(QDict *qdict, struct sockaddr_storage *sa,
-  socklen_t salen)
+static VncBasicInfo *vnc_basic_info_get(struct sockaddr_storage *sa,
+socklen_t salen)
 {
+VncBasicInfo *info;
 char host[NI_MAXHOST];
 char serv[NI_MAXSERV];
 int err;
@@ -136,40 +138,40 @@ static int put_addr_qdict(QDict *qdict, struct 
sockaddr_storage *sa,
NI_NUMERICHOST | NI_NUMERICSERV)) != 0) {
 VNC_DEBUG("Cannot resolve address %d: %s\n",
   err, gai_strerror(err));
-return -1;
+return NULL;
 }
 
-qdict_put(qdict, "host", qstring_from_str(host));
-qdict_put(qdict, "service", qstring_from_str(serv));
-qdict_put(qdict, "family",qstring_from_str(inet_strfamily(sa->ss_family)));
-
-return 0;
+info = g_malloc0(sizeof(VncBasicInfo));
+info->host = g_strdup(host);
+info->service = g_strdup(serv);
+info->family = inet_netfamily(sa->ss_family);
+return info;
 }
 
-static int vnc_server_addr_put(QDict *qdict, int fd)
+static VncBasicInfo *vnc_basic_info_get_from_server_addr(int fd)
 {
 struct sockaddr_storage sa;
 socklen_t salen;
 
 salen = sizeof(sa);
 if (getsockname(fd, (struct sockaddr*)&sa, &salen) < 0) {
-return -1;
+return NULL;
 }
 
-return put_addr_qdict(qdict, &sa, salen);
+return vnc_basic_info_get(&sa, salen);
 }
 
-static int vnc_qdict_remote_addr(QDict *qdict, int fd)
+static VncBasicInfo *vnc_basic_info_get_from_remote_addr(int fd)
 {
 struct sockaddr_storage sa;
 socklen_t salen;
 
 salen = sizeof(sa);
 if (getpeername(fd, (struct sockaddr*)&sa, &salen) < 0) {
-return -1;
+return NULL;
 }
 
-return put_addr_qdict(qdict, &sa, salen);
+return vnc_basic_info_get(&sa, salen);
 }
 
 static const char *vnc_auth_name(VncDisplay *vd) {
@@ -223,81 +225,82 @@ static const char *vnc_auth_name(VncDisplay *vd) {
 return "unknown";
 }
 
-static int vnc_server_info_put(QDict *qdict)
+static VncServerInfo *vnc_server_info_get(void)
 {
-if (vnc_server_addr_put(qdict, vnc_display->lsock) < 0) {
-return -1;
+VncServerInfo *info;
+VncBasicInfo *bi = vnc_basic_info_get_from_server_addr(vnc_display->lsock);
+if (!bi) {
+return NULL;
 }
 
-qdict_put(qdict, "auth", qstring_from_str(vnc_auth_name(vnc_display)));
-return 0;
+info = g_malloc(sizeof(*info));
+info->base = bi;
+info->has_auth = true;
+info->auth = g_strdup(vnc_auth_name(vnc_display));
+return info;
 }
 
 static void vnc_client_cache_auth(VncState *client)
 {
-#if defined(CONFIG_VNC_TLS) || defined(CONFIG_VNC_SASL)
-QDict *qdict;
-#endif
-
 if (!client->info) {
 return;
 }
 
-#if defined(CONFIG_VNC_TLS) || defined(CONFIG_VNC_SASL)
-qdict = qobject_to_qdict(client->info);
-#endif
-
 #ifdef CONFIG_VNC_TLS
 if (client->tls.session &&
 client->tls.dname) {
-qdict_put(qdict, "x509_dname", qstring_from_str(client->tls.dname));
+client->info->has_x509_dname = true;
+client->info->x509_dname = g_strdup(client->tls.dname);
 }
 #endif
 #ifdef CONFIG_VNC_SASL
 if (client->sasl.conn &&
 client->sasl.username) {
-qdict_put(qdict, "sasl_username",
-  qstring_from_str(client->sasl.username));
+client->info->has_sasl_username = true;
+client->info->sasl_username = g_strdup(client->sasl.username);
 }
 #endif
 }
 
 static void vnc_client_cache_addr(VncState *client)
 {
-QDict *qdict;
+VncBasicInfo *bi = vnc_basic_info_get_from_remote_addr(client->csock);
 
-qdict = qdict_new();
-if (vnc_qdict_remote_addr(qdict, client->csock) < 0) {
-QDECREF(qdict);
-/* XXX: how to report the error? */
-return;
+if (bi) {
+client->info = g_malloc0(sizeof(*client->info));
+client->info->base = bi;
 }
-
-client

[Qemu-devel] [PATCH V5 27/28] qapi event: convert QUORUM events

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 block/quorum.c |   25 -
 1 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/block/quorum.c b/block/quorum.c
index ecec3a5..5d1c3dc 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -17,6 +17,7 @@
 #include 
 #include "block/block_int.h"
 #include "qapi/qmp/qjson.h"
+#include "qapi-event.h"
 
 #define HASH_LENGTH 32
 
@@ -198,32 +199,22 @@ static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s,
 
 static void quorum_report_bad(QuorumAIOCB *acb, char *node_name, int ret)
 {
-QObject *data;
-assert(node_name);
-data = qobject_from_jsonf("{ 'node-name': %s"
-  ", 'sector-num': %" PRId64
-  ", 'sectors-count': %d }",
-  node_name, acb->sector_num, acb->nb_sectors);
+const char *msg = NULL;
 if (ret < 0) {
-QDict *dict = qobject_to_qdict(data);
-qdict_put(dict, "error", qstring_from_str(strerror(-ret)));
+msg = strerror(-ret);
 }
-monitor_protocol_event(QEVENT_QUORUM_REPORT_BAD, data);
-qobject_decref(data);
+qapi_event_send_quorum_report_bad(!!msg, msg, node_name,
+  acb->sector_num, acb->nb_sectors, NULL);
 }
 
 static void quorum_report_failure(QuorumAIOCB *acb)
 {
-QObject *data;
 const char *reference = acb->common.bs->device_name[0] ?
 acb->common.bs->device_name :
 acb->common.bs->node_name;
-data = qobject_from_jsonf("{ 'reference': %s"
-  ", 'sector-num': %" PRId64
-  ", 'sectors-count': %d }",
-  reference, acb->sector_num, acb->nb_sectors);
-monitor_protocol_event(QEVENT_QUORUM_FAILURE, data);
-qobject_decref(data);
+
+qapi_event_send_quorum_failure(reference, acb->sector_num,
+   acb->nb_sectors, NULL);
 }
 
 static int quorum_vote_error(QuorumAIOCB *acb);
-- 
1.7.1




[Qemu-devel] [PATCH V5 24/28] qapi event: convert SPICE events

2014-04-30 Thread Wenchao Xia
SPICE_INITIALIZED, SPICE_CONNECTED, SPICE_DISCONNECTED and
SPICE_MIGRATE_COMPLETED are converted. inet_strfamily is removed
since no more caller exist now.

Signed-off-by: Wenchao Xia 
---
 include/qemu/sockets.h |1 -
 ui/spice-core.c|   70 ---
 util/qemu-sockets.c|   10 ---
 3 files changed, 36 insertions(+), 45 deletions(-)

diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
index af24669..fdbb196 100644
--- a/include/qemu/sockets.h
+++ b/include/qemu/sockets.h
@@ -61,7 +61,6 @@ int inet_nonblocking_connect(const char *str,
  void *opaque, Error **errp);
 
 int inet_dgram_opts(QemuOpts *opts, Error **errp);
-const char *inet_strfamily(int family);
 NetworkAddressFamily inet_netfamily(int family);
 
 int unix_listen_opts(QemuOpts *opts, Error **errp);
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 387f0ab..f69cdc1 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -35,9 +35,9 @@
 #include "qapi/qmp/qjson.h"
 #include "qemu/notify.h"
 #include "migration/migration.h"
-#include "monitor/monitor.h"
 #include "hw/hw.h"
 #include "ui/spice-display.h"
+#include "qapi-event.h"
 
 /* core bits */
 
@@ -173,39 +173,34 @@ static void channel_list_del(SpiceChannelEventInfo *info)
 }
 }
 
-static void add_addr_info(QDict *dict, struct sockaddr *addr, int len)
+static void add_addr_info(SpiceBasicInfo *info, struct sockaddr *addr, int len)
 {
 char host[NI_MAXHOST], port[NI_MAXSERV];
-const char *family;
 
 getnameinfo(addr, len, host, sizeof(host), port, sizeof(port),
 NI_NUMERICHOST | NI_NUMERICSERV);
-family = inet_strfamily(addr->sa_family);
 
-qdict_put(dict, "host", qstring_from_str(host));
-qdict_put(dict, "port", qstring_from_str(port));
-qdict_put(dict, "family", qstring_from_str(family));
+info->host = g_strdup(host);
+info->port = g_strdup(port);
+info->family = inet_netfamily(addr->sa_family);
 }
 
-static void add_channel_info(QDict *dict, SpiceChannelEventInfo *info)
+static void add_channel_info(SpiceChannel *sc, SpiceChannelEventInfo *info)
 {
 int tls = info->flags & SPICE_CHANNEL_EVENT_FLAG_TLS;
 
-qdict_put(dict, "connection-id", qint_from_int(info->connection_id));
-qdict_put(dict, "channel-type", qint_from_int(info->type));
-qdict_put(dict, "channel-id", qint_from_int(info->id));
-qdict_put(dict, "tls", qbool_from_int(tls));
+sc->connection_id = info->connection_id;
+sc->channel_type = info->type;
+sc->channel_id = info->id;
+sc->tls = !!tls;
 }
 
 static void channel_event(int event, SpiceChannelEventInfo *info)
 {
-static const int qevent[] = {
-[ SPICE_CHANNEL_EVENT_CONNECTED] = QEVENT_SPICE_CONNECTED,
-[ SPICE_CHANNEL_EVENT_INITIALIZED  ] = QEVENT_SPICE_INITIALIZED,
-[ SPICE_CHANNEL_EVENT_DISCONNECTED ] = QEVENT_SPICE_DISCONNECTED,
-};
-QDict *server, *client;
-QObject *data;
+SpiceServerInfo *server = g_malloc0(sizeof(*server));
+SpiceChannel *client = g_malloc0(sizeof(*client));
+server->base = g_malloc0(sizeof(*server->base));
+client->base = g_malloc0(sizeof(*client->base));
 
 /*
  * Spice server might have called us from spice worker thread
@@ -221,36 +216,43 @@ static void channel_event(int event, 
SpiceChannelEventInfo *info)
 qemu_mutex_lock_iothread();
 }
 
-client = qdict_new();
-server = qdict_new();
-
 if (info->flags & SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT) {
-add_addr_info(client, (struct sockaddr *)&info->paddr_ext,
+add_addr_info(client->base, (struct sockaddr *)&info->paddr_ext,
   info->plen_ext);
-add_addr_info(server, (struct sockaddr *)&info->laddr_ext,
+add_addr_info(server->base, (struct sockaddr *)&info->laddr_ext,
   info->llen_ext);
 } else {
 error_report("spice: %s, extended address is expected",
  __func__);
 }
 
-if (event == SPICE_CHANNEL_EVENT_INITIALIZED) {
-qdict_put(server, "auth", qstring_from_str(auth));
+switch (event) {
+case SPICE_CHANNEL_EVENT_CONNECTED:
+qapi_event_send_spice_connected(server->base, client->base, NULL);
+break;
+case SPICE_CHANNEL_EVENT_INITIALIZED:
+if (auth) {
+server->has_auth = true;
+server->auth = g_strdup(auth);
+}
 add_channel_info(client, info);
 channel_list_add(info);
-}
-if (event == SPICE_CHANNEL_EVENT_DISCONNECTED) {
+qapi_event_send_spice_initialized(server, client, NULL);
+break;
+case SPICE_CHANNEL_EVENT_DISCONNECTED:

[Qemu-devel] [PATCH V5 08/28] qapi event: convert POWERDOWN

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 vl.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/vl.c b/vl.c
index 9f78bd7..5dd30c9 100644
--- a/vl.c
+++ b/vl.c
@@ -1970,7 +1970,7 @@ void qemu_system_shutdown_request(void)
 
 static void qemu_system_powerdown(void)
 {
-monitor_protocol_event(QEVENT_POWERDOWN, NULL);
+qapi_event_send_powerdown(NULL);
 notifier_list_notify(&powerdown_notifiers, NULL);
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH V5 14/28] qapi event: convert WAKEUP

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 vl.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/vl.c b/vl.c
index 3ee2494..73b4725 100644
--- a/vl.c
+++ b/vl.c
@@ -2031,7 +2031,7 @@ static bool main_loop_should_exit(void)
 notifier_list_notify(&wakeup_notifiers, &wakeup_reason);
 wakeup_reason = QEMU_WAKEUP_REASON_NONE;
 resume_all_vcpus();
-monitor_protocol_event(QEVENT_WAKEUP, NULL);
+qapi_event_send_wakeup(NULL);
 }
 if (qemu_powerdown_requested()) {
 qemu_system_powerdown();
-- 
1.7.1




[Qemu-devel] [PATCH V5 10/28] qapi event: convert STOP

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 cpus.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/cpus.c b/cpus.c
index 7bbe153..95a0228 100644
--- a/cpus.c
+++ b/cpus.c
@@ -25,7 +25,7 @@
 /* Needed early for CONFIG_BSD etc. */
 #include "config-host.h"
 
-#include "monitor/monitor.h"
+#include "qapi/qmp/qerror.h"
 #include "sysemu/sysemu.h"
 #include "exec/gdbstub.h"
 #include "sysemu/dma.h"
@@ -38,6 +38,7 @@
 #include "qemu/main-loop.h"
 #include "qemu/bitmap.h"
 #include "qemu/seqlock.h"
+#include "qapi-event.h"
 
 #ifndef _WIN32
 #include "qemu/compatfd.h"
@@ -531,7 +532,7 @@ static int do_vm_stop(RunState state)
 pause_all_vcpus();
 runstate_set(state);
 vm_state_notify(0, state);
-monitor_protocol_event(QEVENT_STOP, NULL);
+qapi_event_send_stop(NULL);
 }
 
 bdrv_drain_all();
-- 
1.7.1




[Qemu-devel] [PATCH V5 06/28] monitor: change event functions as an implemention of new emit method

2014-04-30 Thread Wenchao Xia
Now monitor has been hooked on the new event mechanism, so the patches
later can convert event callers one by one. qmp_query_events() is also
switched to use new generated event defines. Note that old function
monitor_protocol_event() is kept for existing caller to avoid code break,
but rate limiting is bypassed to avoid too many duplicated code. After
convertion, the function would be removed.

Signed-off-by: Wenchao Xia 
---
 monitor.c |   47 ++-
 1 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/monitor.c b/monitor.c
index 1266ba0..6482ebe 100644
--- a/monitor.c
+++ b/monitor.c
@@ -69,6 +69,8 @@
 #include "qmp-commands.h"
 #include "hmp.h"
 #include "qemu/thread.h"
+#include "qapi/qmp-event.h"
+#include "qapi-event.h"
 
 /* for pic/irq_info */
 #if defined(TARGET_SPARC)
@@ -178,7 +180,7 @@ typedef struct MonitorControl {
  * instance.
  */
 typedef struct MonitorEventState {
-MonitorEvent event; /* Event being tracked */
+QAPIEvent event;/* Event being tracked */
 int64_t rate;   /* Period over which to throttle. 0 to disable */
 int64_t last;   /* Time at which event was last emitted */
 QEMUTimer *timer;   /* Timer for handling delayed events */
@@ -454,6 +456,7 @@ static void timestamp_put(QDict *qdict)
 }
 
 
+/* Following is kept only for monitor_protocol_event() */
 static const char *monitor_event_names[] = {
 [QEVENT_SHUTDOWN] = "SHUTDOWN",
 [QEVENT_RESET] = "RESET",
@@ -488,13 +491,13 @@ static const char *monitor_event_names[] = {
 };
 QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != QEVENT_MAX)
 
-MonitorEventState monitor_event_state[QEVENT_MAX];
+MonitorEventState monitor_event_state[QAPI_EVENT_MAX];
 
 /*
  * Emits the event to every monitor instance
  */
 static void
-monitor_protocol_event_emit(MonitorEvent event,
+monitor_protocol_event_emit(QAPIEvent event,
 QObject *data)
 {
 Monitor *mon;
@@ -513,12 +516,12 @@ monitor_protocol_event_emit(MonitorEvent event,
  * applying any rate limiting if required.
  */
 static void
-monitor_protocol_event_queue(MonitorEvent event,
- QObject *data)
+monitor_protocol_event_queue(int event_kind, QDict *data, Error **errp)
 {
 MonitorEventState *evstate;
+QAPIEvent event = (QAPIEvent)event_kind;
 int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
-assert(event < QEVENT_MAX);
+assert(event < QAPI_EVENT_MAX);
 
 evstate = &(monitor_event_state[event]);
 trace_monitor_protocol_event_queue(event,
@@ -529,7 +532,7 @@ monitor_protocol_event_queue(MonitorEvent event,
 
 /* Rate limit of 0 indicates no throttling */
 if (!evstate->rate) {
-monitor_protocol_event_emit(event, data);
+monitor_protocol_event_emit(event, QOBJECT(data));
 evstate->last = now;
 } else {
 int64_t delta = now - evstate->last;
@@ -545,10 +548,10 @@ monitor_protocol_event_queue(MonitorEvent event,
 int64_t then = evstate->last + evstate->rate;
 timer_mod_ns(evstate->timer, then);
 }
-evstate->data = data;
+evstate->data = QOBJECT(data);
 qobject_incref(evstate->data);
 } else {
-monitor_protocol_event_emit(event, data);
+monitor_protocol_event_emit(event, QOBJECT(data));
 evstate->last = now;
 }
 }
@@ -587,11 +590,11 @@ static void monitor_protocol_event_handler(void *opaque)
  * milliseconds
  */
 static void
-monitor_protocol_event_throttle(MonitorEvent event,
+monitor_protocol_event_throttle(QAPIEvent event,
 int64_t rate)
 {
 MonitorEventState *evstate;
-assert(event < QEVENT_MAX);
+assert(event < QAPI_EVENT_MAX);
 
 evstate = &(monitor_event_state[event]);
 
@@ -606,18 +609,19 @@ monitor_protocol_event_throttle(MonitorEvent event,
 evstate->data = NULL;
 }
 
-
 /* Global, one-time initializer to configure the rate limiting
  * and initialize state */
 static void monitor_protocol_event_init(void)
 {
 /* Limit RTC & BALLOON events to 1 per second */
-monitor_protocol_event_throttle(QEVENT_RTC_CHANGE, 1000);
-monitor_protocol_event_throttle(QEVENT_BALLOON_CHANGE, 1000);
-monitor_protocol_event_throttle(QEVENT_WATCHDOG, 1000);
+monitor_protocol_event_throttle(QAPI_EVENT_RTC_CHANGE, 1000);
+monitor_protocol_event_throttle(QAPI_EVENT_BALLOON_CHANGE, 1000);
+monitor_protocol_event_throttle(QAPI_EVENT_WATCHDOG, 1000);
 /* limit the rate of quorum events to avoid hammering the management */
-monitor_protocol_event_throttle(QEVENT_QUORUM_REPORT_BAD, 1000);
-monitor_protocol_event_throttle(QEVENT_QUORUM_FAILURE, 1000);
+monitor_protocol_event_throttle(QAPI_EVENT_QUORUM_REPORT_BAD, 1000);
+  

[Qemu-devel] [PATCH V5 09/28] qapi event: convert RESET

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 vl.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/vl.c b/vl.c
index 5dd30c9..717bfc1 100644
--- a/vl.c
+++ b/vl.c
@@ -1886,7 +1886,7 @@ void qemu_system_reset(bool report)
 qemu_devices_reset();
 }
 if (report) {
-monitor_protocol_event(QEVENT_RESET, NULL);
+qapi_event_send_reset(NULL);
 }
 cpu_synchronize_all_post_reset();
 }
-- 
1.7.1




[Qemu-devel] [PATCH V5 02/28] qapi: add event helper functions

2014-04-30 Thread Wenchao Xia
This file holds some functions that do not need to be generated.

Signed-off-by: Wenchao Xia 
---
 include/qapi/qmp-event.h |   27 +
 qapi/Makefile.objs   |1 +
 qapi/qmp-event.c |   74 ++
 3 files changed, 102 insertions(+), 0 deletions(-)
 create mode 100644 include/qapi/qmp-event.h
 create mode 100644 qapi/qmp-event.c

diff --git a/include/qapi/qmp-event.h b/include/qapi/qmp-event.h
new file mode 100644
index 000..02b6ce5
--- /dev/null
+++ b/include/qapi/qmp-event.h
@@ -0,0 +1,27 @@
+/*
+ * QMP Event related
+ *
+ * Copyright (c) 2014 Wenchao Xia
+ *
+ * Authors:
+ *  Wenchao Xia   
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef QMP_EVENT_H
+#define QMP_EVENT_H
+
+#include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
+
+typedef void (*QMPEventFuncEmit)(int event_kind, QDict *dict, Error **errp);
+
+void qmp_event_set_func_emit(QMPEventFuncEmit emit);
+
+QMPEventFuncEmit qmp_event_get_func_emit(void);
+
+QDict *qmp_event_build_dict(const char *event_name);
+#endif
diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs
index 1f9c973..d14b769 100644
--- a/qapi/Makefile.objs
+++ b/qapi/Makefile.objs
@@ -3,3 +3,4 @@ util-obj-y += qmp-output-visitor.o qmp-registry.o qmp-dispatch.o
 util-obj-y += string-input-visitor.o string-output-visitor.o
 
 util-obj-y += opts-visitor.o
+util-obj-y += qmp-event.o
diff --git a/qapi/qmp-event.c b/qapi/qmp-event.c
new file mode 100644
index 000..0d1ce0b
--- /dev/null
+++ b/qapi/qmp-event.c
@@ -0,0 +1,74 @@
+/*
+ * QMP Event related
+ *
+ * Copyright (c) 2014 Wenchao Xia
+ *
+ * Authors:
+ *  Wenchao Xia   
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include 
+
+#include "qemu-common.h"
+#include "qapi/qmp-event.h"
+#include "qapi/qmp/qstring.h"
+#include "qapi/qmp/qjson.h"
+
+#ifdef _WIN32
+#include "sysemu/os-win32.h"
+#endif
+
+#ifdef CONFIG_POSIX
+#include "sysemu/os-posix.h"
+#endif
+
+static QMPEventFuncEmit qmp_emit;
+
+void qmp_event_set_func_emit(QMPEventFuncEmit emit)
+{
+qmp_emit = emit;
+}
+
+QMPEventFuncEmit qmp_event_get_func_emit(void)
+{
+return qmp_emit;
+}
+
+static void timestamp_put(QDict *qdict)
+{
+int err;
+QObject *obj;
+qemu_timeval tv;
+int64_t sec, usec;
+
+err = qemu_gettimeofday(&tv);
+if (err < 0) {
+/* Put -1 to indicate failure of getting host time */
+sec = -1;
+usec = -1;
+} else {
+sec = tv.tv_sec;
+usec = tv.tv_usec;
+}
+
+obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", "
+ "'microseconds': %" PRId64 " }",
+ sec, usec);
+qdict_put_obj(qdict, "timestamp", obj);
+}
+
+/*
+ * Build a QDict, then fill event name and time stamp, caller should free the
+ * QDict after usage.
+ */
+QDict *qmp_event_build_dict(const char *event_name)
+{
+QDict *dict = qdict_new();
+qdict_put(dict, "event", qstring_from_str(event_name));
+timestamp_put(dict);
+return dict;
+}
-- 
1.7.1




[Qemu-devel] [PATCH V5 04/28] test: add test cases for qapi event

2014-04-30 Thread Wenchao Xia
These cases will verify whether the expected qdict is built.

Signed-off-by: Wenchao Xia 
---
 tests/Makefile  |   14 ++-
 tests/qapi-schema/qapi-schema-test.json |   12 ++
 tests/qapi-schema/qapi-schema-test.out  |   10 +-
 tests/test-qmp-event.c  |  265 +++
 4 files changed, 296 insertions(+), 5 deletions(-)
 create mode 100644 tests/test-qmp-event.c

diff --git a/tests/Makefile b/tests/Makefile
index e477f14..6daa7e4 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -27,6 +27,8 @@ check-unit-y += tests/test-string-input-visitor$(EXESUF)
 gcov-files-test-string-input-visitor-y = qapi/string-input-visitor.c
 check-unit-y += tests/test-string-output-visitor$(EXESUF)
 gcov-files-test-string-output-visitor-y = qapi/string-output-visitor.c
+check-unit-y += tests/test-qmp-event$(EXESUF)
+gcov-files-test-qmp-event-y += qapi/qmp-event.c
 check-unit-y += tests/test-opts-visitor$(EXESUF)
 gcov-files-test-opts-visitor-y = qapi/opts-visitor.c
 check-unit-y += tests/test-coroutine$(EXESUF)
@@ -178,7 +180,8 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
 flat-union-string-discriminator.json \
 event-nest-struct.json)
 
-GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h 
tests/test-qmp-commands.h
+GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h \
+ tests/test-qapi-event.h tests/test-qmp-commands.h
 
 test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \
tests/check-qlist.o tests/check-qfloat.o tests/check-qjson.o \
@@ -187,9 +190,10 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o 
tests/check-qdict.o \
tests/test-qmp-input-visitor.o tests/test-qmp-input-strict.o \
tests/test-qmp-commands.o tests/test-visitor-serialization.o \
tests/test-x86-cpuid.o tests/test-mul64.o tests/test-int128.o \
-   tests/test-opts-visitor.o
+   tests/test-opts-visitor.o tests/test-qmp-event.o
 
-test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o
+test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
+  tests/test-qapi-event.o
 
 $(test-obj-y): QEMU_INCLUDES += -Itests
 QEMU_CFLAGS += -I$(SRC_PATH)/tests
@@ -232,12 +236,16 @@ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json 
$(SRC_PATH)/scripts/qapi-typ
 tests/test-qapi-visit.c tests/test-qapi-visit.h :\
 $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json 
$(SRC_PATH)/scripts/qapi-visit.py
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py 
$(gen-out-type) -o tests -p "test-" < $<, "  GEN   $@")
+tests/test-qapi-event.c tests/test-qapi-event.h :\
+$(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json 
$(SRC_PATH)/scripts/qapi-event.py
+   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py 
$(gen-out-type) -o tests -p "test-" < $<, "  GEN   $@")
 tests/test-qmp-commands.h tests/test-qmp-marshal.c :\
 $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json 
$(SRC_PATH)/scripts/qapi-commands.py
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py 
$(gen-out-type) -o tests -p "test-" < $<, "  GEN   $@")
 
 tests/test-string-output-visitor$(EXESUF): tests/test-string-output-visitor.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
 tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
+tests/test-qmp-event$(EXESUF): tests/test-qmp-event.o $(test-qapi-obj-y) 
libqemuutil.a libqemustub.a
 tests/test-qmp-output-visitor$(EXESUF): tests/test-qmp-output-visitor.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
 tests/test-qmp-input-visitor$(EXESUF): tests/test-qmp-input-visitor.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
 tests/test-qmp-input-strict$(EXESUF): tests/test-qmp-input-strict.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
diff --git a/tests/qapi-schema/qapi-schema-test.json 
b/tests/qapi-schema/qapi-schema-test.json
index 818c06d..ab4d3d9 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -89,3 +89,15 @@
 '*u16' : [ 'uint16' ],
 '*i64x':   'int' ,
 '*u64x':   'uint64'  } }
+
+# testing event
+{ 'type': 'EventStructOne',
+  'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' } }
+
+{ 'event': 'EVENT_A' }
+{ 'event': 'EVENT_B',
+  'data': { } }
+{ 'event': 'EVENT_C',
+  'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
+{ 'event': 'EVENT_D',
+  'data': { 'a' : 'EventStructOne', 

[Qemu-devel] [PATCH V5 07/28] qapi event: convert SHUTDOWN

2014-04-30 Thread Wenchao Xia
Signed-off-by: Wenchao Xia 
---
 vl.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/vl.c b/vl.c
index 236f95e..9f78bd7 100644
--- a/vl.c
+++ b/vl.c
@@ -117,6 +117,7 @@ int main(int argc, char **argv)
 #include "ui/qemu-spice.h"
 #include "qapi/string-input-visitor.h"
 #include "qom/object_interfaces.h"
+#include "qapi-event.h"
 
 #define DEFAULT_RAM_SIZE 128
 
@@ -2007,7 +2008,7 @@ static bool main_loop_should_exit(void)
 }
 if (qemu_shutdown_requested()) {
 qemu_kill_report();
-monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
+qapi_event_send_shutdown(NULL);
 if (no_shutdown) {
 vm_stop(RUN_STATE_SHUTDOWN);
 } else {
-- 
1.7.1




[Qemu-devel] [PATCH V5 03/28] qapi script: add event support

2014-04-30 Thread Wenchao Xia
qapi-event.py will parse the schema and generate qapi-event.c, then
the API in qapi-event.c can be used to handle event in qemu code.
All API have prefix "qapi_event".

The script mainly includes two parts: generate API for each event
define, generate an enum type for all defined events.

Since in some cases the real emit behavior may change, for example,
qemu-img would not send a event, a callback layer is used to
control the behavior. As a result, the stubs at compile time
can be saved, the binding of block layer code and monitor code
will become looser.

Signed-off-by: Wenchao Xia 
---
 Makefile |9 +-
 Makefile.objs|2 +-
 docs/qapi-code-gen.txt   |   18 ++
 scripts/qapi-event.py|  366 ++
 scripts/qapi.py  |   12 +
 tests/Makefile   |3 +-
 tests/qapi-schema/event-nest-struct.err  |1 +
 tests/qapi-schema/event-nest-struct.exit |1 +
 tests/qapi-schema/event-nest-struct.json |2 +
 9 files changed, 409 insertions(+), 5 deletions(-)
 create mode 100644 scripts/qapi-event.py
 create mode 100644 tests/qapi-schema/event-nest-struct.err
 create mode 100644 tests/qapi-schema/event-nest-struct.exit
 create mode 100644 tests/qapi-schema/event-nest-struct.json
 create mode 100644 tests/qapi-schema/event-nest-struct.out

diff --git a/Makefile b/Makefile
index 423e373..ed5b612 100644
--- a/Makefile
+++ b/Makefile
@@ -45,8 +45,8 @@ endif
 endif
 
 GENERATED_HEADERS = config-host.h qemu-options.def
-GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
-GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c
+GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h qapi-event.h
+GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c qapi-event.c
 
 GENERATED_HEADERS += trace/generated-events.h
 GENERATED_SOURCES += trace/generated-events.c
@@ -208,7 +208,7 @@ Makefile: $(version-obj-y) $(version-lobj-y)
 # Build libraries
 
 libqemustub.a: $(stub-obj-y)
-libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o
+libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o qapi-event.o
 
 block-modules = $(foreach o,$(block-obj-m),"$(basename $(subst /,-,$o))",) NULL
 util/module.o-cflags = -D'CONFIG_BLOCK_MODULES=$(block-modules)'
@@ -252,6 +252,9 @@ $(SRC_PATH)/qapi-schema.json 
$(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
 qapi-visit.c qapi-visit.h :\
 $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py 
$(gen-out-type) -o "." -b < $<, "  GEN   $@")
+qapi-event.c qapi-event.h :\
+$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-event.py $(qapi-py)
+   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py 
$(gen-out-type) -o "." -b < $<, "  GEN   $@")
 qmp-commands.h qmp-marshal.c :\
 $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py 
$(gen-out-type) -m -o "." < $<, "  GEN   $@")
diff --git a/Makefile.objs b/Makefile.objs
index a6e0e2a..93697a1 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -12,7 +12,7 @@ block-obj-y += main-loop.o iohandler.o qemu-timer.o
 block-obj-$(CONFIG_POSIX) += aio-posix.o
 block-obj-$(CONFIG_WIN32) += aio-win32.o
 block-obj-y += block/
-block-obj-y += qapi-types.o qapi-visit.o
+block-obj-y += qapi-types.o qapi-visit.o qapi-event.o
 block-obj-y += qemu-io-cmds.o
 
 block-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o
diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt
index d78921f..91e4e13 100644
--- a/docs/qapi-code-gen.txt
+++ b/docs/qapi-code-gen.txt
@@ -180,6 +180,24 @@ An example command is:
'data': { 'arg1': 'str', '*arg2': 'str' },
'returns': 'str' }
 
+=== Events ===
+
+Events are defined with key word 'event'.  When 'data' is also specified,
+additional info will be carried on.  Finally there will be C API generated
+in qapi-event.h, and when called by QEMU code, a message with timestamp will
+be emitted on the wire.  If timestamp is -1, it means failure to retrieve host
+time.
+
+An example event is:
+
+{ 'event': 'EVENT_C',
+  'data': { '*a': 'int', 'b': 'str' } }
+
+Resulting in this JSON object:
+
+{ "event": "EVENT_C",
+  "data": { "b": "test string" },
+  "timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
 
 == Code generation ==
 
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
new file mode 100644
index 000..501baff
--- /dev/null
+++ b/scripts

[Qemu-devel] [PATCH V5 01/28] os-posix: include sys/time.h

2014-04-30 Thread Wenchao Xia
Since gettimeofday() is used in this header file as a macro define,
include the function's define header file, to avoid compile warning
when other file include os-posix.h.

Signed-off-by: Wenchao Xia 
Reviewed-by: Eric Blake 
---
 include/sysemu/os-posix.h |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
index 25d0b2a..f131521 100644
--- a/include/sysemu/os-posix.h
+++ b/include/sysemu/os-posix.h
@@ -26,6 +26,8 @@
 #ifndef QEMU_OS_POSIX_H
 #define QEMU_OS_POSIX_H
 
+#include 
+
 void os_set_line_buffering(void);
 void os_set_proc_name(const char *s);
 void os_setup_signal_handling(void);
-- 
1.7.1




[Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema

2014-04-30 Thread Wenchao Xia
This series add support for tag/keyword 'event' in qapi-schema.
A new file was created to store some helper functions in patch 2, patch 4 is
the test case, patch 5 is a convert example.

The implemention is done by generate API and a batch of parameters for each
event define, it doesn't generate a struture and visit function in the
background for every event, so it doesn't support nested structure in the
define to avoid trouble. A callback layer is added to control the behavior.
More detail can be found in patch 3's message and incode comments.

v2:
  Address Luiz's comments:
  patch 3: rename *err to *local_err, do not initialize *qmp = NULL, create
a new function qmp_build_evet_dict().
  Other change:
  reorgnized script in patch 3, it have a clear three steps, see patch 3's
incode comments.

v3:
  Address Luiz's comments:
  2/5: use -1 when fail to get host timestamp.
  3/5: typo fix and better incode comments. all unchanged functions are moved
into qmp-event.c, from generated file. To do so without include issue, 'int'
was used intead of 'enum' in function prototype declaration, since the 'enum'
define is a generated type.
  Address Eric's comments:
  2/5: use -1 when fail to get host timestamp.
  3/5: typo fix, add docs/qapi-code-gen.txt.
  4/5: typo fix, verify no other fields in member 'timestamp'.
  5/5: add doc in qapi-schema.json.
  fix license, all script using GPL2, all C code use LGPL, just as other
similar files in upstream.

v4:
  Address Eric's comments:
  2/5: typo fix, add copyright declaration, use a static function pointer
instead of a struct in C file, assign -1 in two line of codes to avoid issue
when tv_sec and tv_usec are not in same data width, fix indention.
  3/5: typo fix, add copyright declaration.
  4/5: add copyright declaration, simplify string compare with
 "d->result = g_strcmp0(...) == 0;", add check for tv_usec's range and value.
  Other:
  3/5: all error check code was moved from qapi-event.py to qapi.py, and it
reports better message with line number info. Added related test case.
  Note:
  Benoit's series which track input file better seems not the final version,
so I didn't rebase this series ontop for now, will do it once Benoit's ones
get ACKed.

v5:
  Address Eric and Markus's comments:
  2/28: use uint64_t for both sec and usec, to avoid type cast issue in printf.
  Other:
  Remove RFC, add full coversion by patch 5-28.
  3/28: add prefix for event enum type name, to avoid double define of
QAPIEvent in test code. 

Wenchao Xia (28):
  1 os-posix: include sys/time.h
  2 qapi: add event helper functions
  3 qapi script: add event support
  4 test: add test cases for qapi event
  5 qapi: define events in qapi schema
  6 monitor: change event functions as an implemention of new emit method
  7 qapi event: convert SHUTDOWN
  8 qapi event: convert POWERDOWN
  9 qapi event: convert RESET
  10 qapi event: convert STOP
  11 qapi event: convert RESUME
  12 qapi event: convert SUSPEND
  13 qapi event: convert SUSPEND_DISK
  14 qapi event: convert WAKEUP
  15 qapi event: convert RTC_CHANGE
  16 qapi event: convert WATCHDOG
  17 qapi event: convert DEVICE_DELETED
  18 qapi event: convert DEVICE_TRAY_MOVED
  19 qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR
  20 qapi event: convert BLOCK_IMAGE_CORRUPTED
  21 qapi event: convert other BLOCK_JOB events
  22 qapi event: convert NIC_RX_FILTER_CHANGED
  23 qapi event: convert VNC events
  24 qapi event: convert SPICE events
  25 qapi event: convert BALLOON_CHANGE
  26 qapi event: convert GUEST_PANICKED
  27 qapi event: convert QUORUM events
  28 qapi event: clean up

 Makefile |9 +-
 Makefile.objs|2 +-
 balloon.c|   13 -
 block.c  |   68 +---
 block/backup.c   |2 +-
 block/mirror.c   |9 +-
 block/qcow2-refcount.c   |   14 +-
 block/quorum.c   |   25 +-
 block/stream.c   |4 +-
 blockdev.c   |   12 +-
 blockjob.c   |   53 ++-
 cpus.c   |5 +-
 docs/qapi-code-gen.txt   |   18 +
 docs/qmp/qmp-events.txt  |  354 +-
 hmp.c|5 +-
 hw/acpi/core.c   |4 +-
 hw/block/virtio-blk.c|6 +-
 hw/core/qdev.c   |   12 +-
 hw/ide/core.c|6 +-
 hw/misc/pvpanic.c|   13 +-
 hw/net/virtio-net.c  |   13 +-
 hw/ppc/spapr_rtas.c  |3 +-
 hw/scsi/scsi-disk.c  |6 +-
 hw/timer/mc146818rtc.c 

Re: [Qemu-devel] [RFC PATCH V4 2/5] qapi: add event helper functions

2014-04-02 Thread Wenchao Xia
于 2014/3/28 16:21, Markus Armbruster 写道:
> Eric Blake  writes:
> 
>> On 03/27/2014 02:03 AM, Wenchao Xia wrote:
>>> This file holds some functions that do not need to be generated.
>>>
>>> Signed-off-by: Wenchao Xia 
>>> ---
>>>   include/qapi/qmp-event.h |   27 +
>>>   qapi/Makefile.objs   |1 +
>>>   qapi/qmp-event.c |   70 
>>> ++
>>>   3 files changed, 98 insertions(+), 0 deletions(-)
>>>   create mode 100644 include/qapi/qmp-event.h
>>>   create mode 100644 qapi/qmp-event.c
>>>
>>
>>> +err = qemu_gettimeofday(&tv);
>>> +if (err < 0) {
>>> +/* Put -1 to indicate failure of getting host time */
>>> +tv.tv_sec = -1;
>>> +tv.tv_usec = -1;
>>
>> You fixed the problem with C promotion here, but...
>>
>>> +}
>>> +
>>> +obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", "
>>> + "'microseconds': %" PRId64 " }",
>>> + (int64_t) tv.tv_sec, (int64_t) tv.tv_usec);
>>
>> ...here, C promotion rules bite once again :(  If tv_usec is uint32_t,
>> then it zero-extends rather than sign-extends into int64_t, and you may
>> end up with 0x instead of the intended -1.  When doing
>> potentially widening casts, it is only safe if you know the signedness
>> of the pre-cast value; but with struct timeval, POSIX doesn't make that
>> easy.
>>
>> Maybe it's easier to just rewrite things with known types:
>>
>> int64_t sec;
>> int usec;
>> qemu_timval tv;
>> err = qemu_gettimeofday(&tv);
>> if (err < 0) {
>>  sec = -1;
>>  usec = -1;
>> } else {
>>  sec = tv.tv_sec;
>>  usec = tv.tv_usec;
>> }
>> qobject_from_jsonf("... %"PRId64 ", ...%d", sec, usec)
>>
>> since 'int' is guaranteed to be large enough for all the usec values we
>> care about on all platforms we compile on (that is, we require 32-bit
>> int, even if C allows for a 16-bit int implementation).
> 
> If you go that route, then why not go all the way nad make both sec and
> usec int64_t?  Look ma, no type casts!
> 
  Yep, in this way code looks better... I will respin it later with a
full conversion.



[Qemu-devel] [RFC PATCH V4 4/5] test: add test cases for qapi event

2014-03-27 Thread Wenchao Xia
These cases will verify whether the expected qdict is built.

Signed-off-by: Wenchao Xia 
---
 tests/Makefile  |   14 ++-
 tests/qapi-schema/qapi-schema-test.json |   12 ++
 tests/qapi-schema/qapi-schema-test.out  |   10 +-
 tests/test-qmp-event.c  |  265 +++
 4 files changed, 296 insertions(+), 5 deletions(-)
 create mode 100644 tests/test-qmp-event.c

diff --git a/tests/Makefile b/tests/Makefile
index 7e7c37f..c3dad9b 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -27,6 +27,8 @@ check-unit-y += tests/test-string-input-visitor$(EXESUF)
 gcov-files-test-string-input-visitor-y = qapi/string-input-visitor.c
 check-unit-y += tests/test-string-output-visitor$(EXESUF)
 gcov-files-test-string-output-visitor-y = qapi/string-output-visitor.c
+check-unit-y += tests/test-qmp-event$(EXESUF)
+gcov-files-test-qmp-event-y += qapi/qmp-event.c
 check-unit-y += tests/test-opts-visitor$(EXESUF)
 gcov-files-test-opts-visitor-y = qapi/opts-visitor.c
 check-unit-y += tests/test-coroutine$(EXESUF)
@@ -167,7 +169,8 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
 flat-union-string-discriminator.json \
 event-nest-struct.json)
 
-GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h 
tests/test-qmp-commands.h
+GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h \
+ tests/test-qapi-event.h tests/test-qmp-commands.h
 
 test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \
tests/check-qlist.o tests/check-qfloat.o tests/check-qjson.o \
@@ -176,9 +179,10 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o 
tests/check-qdict.o \
tests/test-qmp-input-visitor.o tests/test-qmp-input-strict.o \
tests/test-qmp-commands.o tests/test-visitor-serialization.o \
tests/test-x86-cpuid.o tests/test-mul64.o tests/test-int128.o \
-   tests/test-opts-visitor.o
+   tests/test-opts-visitor.o tests/test-qmp-event.o
 
-test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o
+test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
+  tests/test-qapi-event.o
 
 $(test-obj-y): QEMU_INCLUDES += -Itests
 QEMU_CFLAGS += -I$(SRC_PATH)/tests
@@ -221,12 +225,16 @@ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json 
$(SRC_PATH)/scripts/qapi-typ
 tests/test-qapi-visit.c tests/test-qapi-visit.h :\
 $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json 
$(SRC_PATH)/scripts/qapi-visit.py
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py 
$(gen-out-type) -o tests -p "test-" < $<, "  GEN   $@")
+tests/test-qapi-event.c tests/test-qapi-event.h :\
+$(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json 
$(SRC_PATH)/scripts/qapi-event.py
+   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py 
$(gen-out-type) -o tests -p "test-" < $<, "  GEN   $@")
 tests/test-qmp-commands.h tests/test-qmp-marshal.c :\
 $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json 
$(SRC_PATH)/scripts/qapi-commands.py
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py 
$(gen-out-type) -o tests -p "test-" < $<, "  GEN   $@")
 
 tests/test-string-output-visitor$(EXESUF): tests/test-string-output-visitor.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
 tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
+tests/test-qmp-event$(EXESUF): tests/test-qmp-event.o $(test-qapi-obj-y) 
libqemuutil.a libqemustub.a
 tests/test-qmp-output-visitor$(EXESUF): tests/test-qmp-output-visitor.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
 tests/test-qmp-input-visitor$(EXESUF): tests/test-qmp-input-visitor.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
 tests/test-qmp-input-strict$(EXESUF): tests/test-qmp-input-strict.o 
$(test-qapi-obj-y) libqemuutil.a libqemustub.a
diff --git a/tests/qapi-schema/qapi-schema-test.json 
b/tests/qapi-schema/qapi-schema-test.json
index 818c06d..ab4d3d9 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -89,3 +89,15 @@
 '*u16' : [ 'uint16' ],
 '*i64x':   'int' ,
 '*u64x':   'uint64'  } }
+
+# testing event
+{ 'type': 'EventStructOne',
+  'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' } }
+
+{ 'event': 'EVENT_A' }
+{ 'event': 'EVENT_B',
+  'data': { } }
+{ 'event': 'EVENT_C',
+  'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
+{ 'event': 'EVENT_D',
+  'data': { 'a' : 'EventStructOne', 

[Qemu-devel] [RFC PATCH V4 5/5] qapi event: convert RTC_CHANGE

2014-03-27 Thread Wenchao Xia
This is just an example of how to use qapi event API, and it
bypassed the event throttle queue. A complete convert should
be first define all events in qapi-schema.json, use qapi
event types in monitor functions, then change caller one
by one.

Signed-off-by: Wenchao Xia 
---
 monitor.c|   15 +++
 qapi-schema.json |   13 +
 vl.c |7 ++-
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/monitor.c b/monitor.c
index 342e83b..163f654 100644
--- a/monitor.c
+++ b/monitor.c
@@ -57,6 +57,7 @@
 #include "qapi/qmp/qjson.h"
 #include "qapi/qmp/json-streamer.h"
 #include "qapi/qmp/json-parser.h"
+#include "qapi/qmp-event.h"
 #include 
 #include "qemu/osdep.h"
 #include "cpu.h"
@@ -76,6 +77,8 @@
 #endif
 #include "hw/lm32/lm32_pic.h"
 
+#include "qapi-event.h"
+
 //#define DEBUG
 //#define DEBUG_COMPLETION
 
@@ -632,6 +635,16 @@ monitor_protocol_event_throttle(MonitorEvent event,
 evstate->data = NULL;
 }
 
+static void monitor_event_emit(int event_kind, QDict *d, Error **errp)
+{
+Monitor *mon;
+
+QLIST_FOREACH(mon, &mon_list, entry) {
+if (monitor_ctrl_mode(mon) && qmp_cmd_mode(mon)) {
+monitor_json_emitter(mon, QOBJECT(d));
+}
+}
+}
 
 /* Global, one-time initializer to configure the rate limiting
  * and initialize state */
@@ -644,6 +657,8 @@ static void monitor_protocol_event_init(void)
 /* limit the rate of quorum events to avoid hammering the management */
 monitor_protocol_event_throttle(QEVENT_QUORUM_REPORT_BAD, 1000);
 monitor_protocol_event_throttle(QEVENT_QUORUM_FAILURE, 1000);
+
+qmp_event_set_func_emit(monitor_event_emit);
 }
 
 /**
diff --git a/qapi-schema.json b/qapi-schema.json
index 391356f..6c63814 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4689,3 +4689,16 @@
   'btn' : 'InputBtnEvent',
   'rel' : 'InputMoveEvent',
   'abs' : 'InputMoveEvent' } }
+
+##
+# @RTC_CHANGE
+#
+# Emitted when the guest changes the RTC time.
+#
+# @offset: Offset between base RTC clock (as specified by -rtc base), and
+#  new RTC clock value
+#
+# Since: 2.1
+##
+{ 'event': 'RTC_CHANGE',
+  'data': { 'offset' : 'int' } }
diff --git a/vl.c b/vl.c
index 2355227..a8f1a66 100644
--- a/vl.c
+++ b/vl.c
@@ -117,6 +117,7 @@ int main(int argc, char **argv)
 #include "ui/qemu-spice.h"
 #include "qapi/string-input-visitor.h"
 #include "qom/object_interfaces.h"
+#include "qapi-event.h"
 
 #define DEFAULT_RAM_SIZE 128
 
@@ -723,11 +724,7 @@ int qemu_timedate_diff(struct tm *tm)
 
 void rtc_change_mon_event(struct tm *tm)
 {
-QObject *data;
-
-data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
-monitor_protocol_event(QEVENT_RTC_CHANGE, data);
-qobject_decref(data);
+qapi_event_send_rtc_change(qemu_timedate_diff(tm), NULL);
 }
 
 static void configure_rtc_date_offset(const char *startdate, int legacy)
-- 
1.7.1




[Qemu-devel] [RFC PATCH V4 2/5] qapi: add event helper functions

2014-03-27 Thread Wenchao Xia
This file holds some functions that do not need to be generated.

Signed-off-by: Wenchao Xia 
---
 include/qapi/qmp-event.h |   27 +
 qapi/Makefile.objs   |1 +
 qapi/qmp-event.c |   70 ++
 3 files changed, 98 insertions(+), 0 deletions(-)
 create mode 100644 include/qapi/qmp-event.h
 create mode 100644 qapi/qmp-event.c

diff --git a/include/qapi/qmp-event.h b/include/qapi/qmp-event.h
new file mode 100644
index 000..02b6ce5
--- /dev/null
+++ b/include/qapi/qmp-event.h
@@ -0,0 +1,27 @@
+/*
+ * QMP Event related
+ *
+ * Copyright (c) 2014 Wenchao Xia
+ *
+ * Authors:
+ *  Wenchao Xia   
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef QMP_EVENT_H
+#define QMP_EVENT_H
+
+#include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
+
+typedef void (*QMPEventFuncEmit)(int event_kind, QDict *dict, Error **errp);
+
+void qmp_event_set_func_emit(QMPEventFuncEmit emit);
+
+QMPEventFuncEmit qmp_event_get_func_emit(void);
+
+QDict *qmp_event_build_dict(const char *event_name);
+#endif
diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs
index 1f9c973..d14b769 100644
--- a/qapi/Makefile.objs
+++ b/qapi/Makefile.objs
@@ -3,3 +3,4 @@ util-obj-y += qmp-output-visitor.o qmp-registry.o qmp-dispatch.o
 util-obj-y += string-input-visitor.o string-output-visitor.o
 
 util-obj-y += opts-visitor.o
+util-obj-y += qmp-event.o
diff --git a/qapi/qmp-event.c b/qapi/qmp-event.c
new file mode 100644
index 000..371099d
--- /dev/null
+++ b/qapi/qmp-event.c
@@ -0,0 +1,70 @@
+/*
+ * QMP Event related
+ *
+ * Copyright (c) 2014 Wenchao Xia
+ *
+ * Authors:
+ *  Wenchao Xia   
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include 
+
+#include "qemu-common.h"
+#include "qapi/qmp-event.h"
+#include "qapi/qmp/qstring.h"
+#include "qapi/qmp/qjson.h"
+
+#ifdef _WIN32
+#include "sysemu/os-win32.h"
+#endif
+
+#ifdef CONFIG_POSIX
+#include "sysemu/os-posix.h"
+#endif
+
+static QMPEventFuncEmit qmp_emit;
+
+void qmp_event_set_func_emit(QMPEventFuncEmit emit)
+{
+qmp_emit = emit;
+}
+
+QMPEventFuncEmit qmp_event_get_func_emit(void)
+{
+return qmp_emit;
+}
+
+static void timestamp_put(QDict *qdict)
+{
+int err;
+QObject *obj;
+qemu_timeval tv;
+
+err = qemu_gettimeofday(&tv);
+if (err < 0) {
+/* Put -1 to indicate failure of getting host time */
+tv.tv_sec = -1;
+tv.tv_usec = -1;
+}
+
+obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", "
+ "'microseconds': %" PRId64 " }",
+ (int64_t) tv.tv_sec, (int64_t) tv.tv_usec);
+qdict_put_obj(qdict, "timestamp", obj);
+}
+
+/*
+ * Build a QDict, then fill event name and time stamp, caller should free the
+ * QDict after usage.
+ */
+QDict *qmp_event_build_dict(const char *event_name)
+{
+QDict *dict = qdict_new();
+qdict_put(dict, "event", qstring_from_str(event_name));
+timestamp_put(dict);
+return dict;
+}
-- 
1.7.1




[Qemu-devel] [RFC PATCH V4 3/5] qapi script: add event support

2014-03-27 Thread Wenchao Xia
qapi-event.py will parse the schema and generate qapi-event.c, then
the API in qapi-event.c can be used to handle event in qemu code.
All API have prefix "qapi_event".

The script mainly includes two parts: generate API for each event
define, generate an enum type for all defined events.

Since in some cases the real emit behavior may change, for example,
qemu-img would not send a event, a callback layer is used to
control the behavior. As a result, the stubs at compile time
can be saved, the binding of block layer code and monitor code
will become looser.

Signed-off-by: Wenchao Xia 
---
 Makefile |9 +-
 Makefile.objs|2 +-
 docs/qapi-code-gen.txt   |   18 ++
 scripts/qapi-event.py|  366 ++
 scripts/qapi.py  |   12 +
 tests/Makefile   |3 +-
 tests/qapi-schema/event-nest-struct.err  |1 +
 tests/qapi-schema/event-nest-struct.exit |1 +
 tests/qapi-schema/event-nest-struct.json |2 +
 9 files changed, 409 insertions(+), 5 deletions(-)
 create mode 100644 scripts/qapi-event.py
 create mode 100644 tests/qapi-schema/event-nest-struct.err
 create mode 100644 tests/qapi-schema/event-nest-struct.exit
 create mode 100644 tests/qapi-schema/event-nest-struct.json
 create mode 100644 tests/qapi-schema/event-nest-struct.out

diff --git a/Makefile b/Makefile
index ec74039..47cb661 100644
--- a/Makefile
+++ b/Makefile
@@ -45,8 +45,8 @@ endif
 endif
 
 GENERATED_HEADERS = config-host.h qemu-options.def
-GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
-GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c
+GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h qapi-event.h
+GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c qapi-event.c
 
 GENERATED_HEADERS += trace/generated-events.h
 GENERATED_SOURCES += trace/generated-events.c
@@ -207,7 +207,7 @@ Makefile: $(version-obj-y) $(version-lobj-y)
 # Build libraries
 
 libqemustub.a: $(stub-obj-y)
-libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o
+libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o qapi-event.o
 
 block-modules = $(foreach o,$(block-obj-m),"$(basename $(subst /,-,$o))",) NULL
 util/module.o-cflags = -D'CONFIG_BLOCK_MODULES=$(block-modules)'
@@ -251,6 +251,9 @@ $(SRC_PATH)/qapi-schema.json 
$(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
 qapi-visit.c qapi-visit.h :\
 $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py 
$(gen-out-type) -o "." -b < $<, "  GEN   $@")
+qapi-event.c qapi-event.h :\
+$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-event.py $(qapi-py)
+   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py 
$(gen-out-type) -o "." -b < $<, "  GEN   $@")
 qmp-commands.h qmp-marshal.c :\
 $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py 
$(gen-out-type) -m -o "." < $<, "  GEN   $@")
diff --git a/Makefile.objs b/Makefile.objs
index a6e0e2a..93697a1 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -12,7 +12,7 @@ block-obj-y += main-loop.o iohandler.o qemu-timer.o
 block-obj-$(CONFIG_POSIX) += aio-posix.o
 block-obj-$(CONFIG_WIN32) += aio-win32.o
 block-obj-y += block/
-block-obj-y += qapi-types.o qapi-visit.o
+block-obj-y += qapi-types.o qapi-visit.o qapi-event.o
 block-obj-y += qemu-io-cmds.o
 
 block-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o
diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt
index d78921f..91e4e13 100644
--- a/docs/qapi-code-gen.txt
+++ b/docs/qapi-code-gen.txt
@@ -180,6 +180,24 @@ An example command is:
'data': { 'arg1': 'str', '*arg2': 'str' },
'returns': 'str' }
 
+=== Events ===
+
+Events are defined with key word 'event'.  When 'data' is also specified,
+additional info will be carried on.  Finally there will be C API generated
+in qapi-event.h, and when called by QEMU code, a message with timestamp will
+be emitted on the wire.  If timestamp is -1, it means failure to retrieve host
+time.
+
+An example event is:
+
+{ 'event': 'EVENT_C',
+  'data': { '*a': 'int', 'b': 'str' } }
+
+Resulting in this JSON object:
+
+{ "event": "EVENT_C",
+  "data": { "b": "test string" },
+  "timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
 
 == Code generation ==
 
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
new file mode 100644
index 000..cdb24fa
--- /dev/null
+++ b/scripts

[Qemu-devel] [RFC PATCH V4 1/5] os-posix: include sys/time.h

2014-03-27 Thread Wenchao Xia
Since gettimeofday() is used in this header file as a macro define,
include the function's define header file, to avoid compile warning
when other file include os-posix.h.

Signed-off-by: Wenchao Xia 
Reviewed-by: Eric Blake 
---
 include/sysemu/os-posix.h |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
index 25d0b2a..f131521 100644
--- a/include/sysemu/os-posix.h
+++ b/include/sysemu/os-posix.h
@@ -26,6 +26,8 @@
 #ifndef QEMU_OS_POSIX_H
 #define QEMU_OS_POSIX_H
 
+#include 
+
 void os_set_line_buffering(void);
 void os_set_proc_name(const char *s);
 void os_setup_signal_handling(void);
-- 
1.7.1




[Qemu-devel] [RFC PATCH V4 0/5] add direct support of event in qapi schema

2014-03-27 Thread Wenchao Xia
This series add support for tag/keyword 'event' in qapi-schema.
A new file was created to store some helper functions in patch 2, patch 4 is
the test case, patch 5 is a convert example.

The implemention is done by generate API and a batch of parameters for each
event define, it doesn't generate a struture and visit function in the
background for every event, so it doesn't support nested structure in the
define to avoid trouble. A callback layer is added to control the behavior.
More detail can be found in patch 3's message and incode comments.

v2:
  Address Luiz's comments:
  patch 3: rename *err to *local_err, do not initialize *qmp = NULL, create
a new function qmp_build_evet_dict().
  Other change:
  reorgnized script in patch 3, it have a clear three steps, see patch 3's
incode comments.

v3:
  Address Luiz's comments:
  2/5: use -1 when fail to get host timestamp.
  3/5: typo fix and better incode comments. all unchanged functions are moved
into qmp-event.c, from generated file. To do so without include issue, 'int'
was used intead of 'enum' in function prototype declaration, since the 'enum'
define is a generated type.
  Address Eric's comments:
  2/5: use -1 when fail to get host timestamp.
  3/5: typo fix, add docs/qapi-code-gen.txt.
  4/5: typo fix, verify no other fields in member 'timestamp'.
  5/5: add doc in qapi-schema.json.
  fix license, all script using GPL2, all C code use LGPL, just as other
similar files in upstream.

v4:
  Address Eric's comments:
  2/5: typo fix, add copyright declaration, use a static function pointer
instead of a struct in C file, assign -1 in two line of codes to avoid issue
when tv_sec and tv_usec are not in same data width, fix indention.
  3/5: typo fix, add copyright declaration.
  4/5: add copyright declaration, simplify string compare with
 "d->result = g_strcmp0(...) == 0;", add check for tv_usec's range and value.
  Other:
  3/5: all error check code was moved from qapi-event.py to qapi.py, and it
reports better message with line number info. Added related test case.
  Note:
  Benoit's series which track input file better seems not the final version,
so I didn't rebase this series ontop for now, will do it once Benoit's ones
get ACKed.

Wenchao Xia (5):
  1 os-posix: include sys/time.h
  2 qapi: add event helper functions
  3 qapi script: add event support
  4 test: add test cases for qapi event
  5 qapi event: convert RTC_CHANGE

 Makefile |9 +-
 Makefile.objs|2 +-
 docs/qapi-code-gen.txt   |   18 ++
 include/qapi/qmp-event.h |   27 +++
 include/sysemu/os-posix.h|2 +
 monitor.c|   15 ++
 qapi-schema.json |   13 +
 qapi/Makefile.objs   |1 +
 qapi/qmp-event.c |   70 ++
 scripts/qapi-event.py|  366 ++
 scripts/qapi.py  |   12 +
 tests/Makefile   |   17 +-
 tests/qapi-schema/event-nest-struct.err  |1 +
 tests/qapi-schema/event-nest-struct.exit |1 +
 tests/qapi-schema/event-nest-struct.json |2 +
 tests/qapi-schema/qapi-schema-test.json  |   12 +
 tests/qapi-schema/qapi-schema-test.out   |   10 +-
 tests/test-qmp-event.c   |  265 +
 vl.c |7 +-
 19 files changed, 835 insertions(+), 15 deletions(-)
 create mode 100644 include/qapi/qmp-event.h
 create mode 100644 qapi/qmp-event.c
 create mode 100644 scripts/qapi-event.py
 create mode 100644 tests/qapi-schema/event-nest-struct.err
 create mode 100644 tests/qapi-schema/event-nest-struct.exit
 create mode 100644 tests/qapi-schema/event-nest-struct.json
 create mode 100644 tests/qapi-schema/event-nest-struct.out
 create mode 100644 tests/test-qmp-event.c




Re: [Qemu-devel] [RFC PATCH V2 3/5] qapi script: add event support by qapi-event.py

2014-03-27 Thread Wenchao Xia



You may need to rebase this on top of other patches that refactor the
qapi generators to track the input file, for improved error messages.

It seems qapi-visit.py and qapi-types.py remains the same as above in
upstream, which kind of change are your referring to?

Lluís' patch to use an explicit input file via a new -i option:
https://lists.gnu.org/archive/html/qemu-devel/2014-02/msg05220.html


I see, will adjust it.


Part of "[PATCH v4 0/3] qapi: Allow modularization of QAPI schema
files".  There's also Benoît's "[PATCH 0/2] Create and include directive
for QAPI JSON files"[*].  Benoît, care to explain how the two are
related?


I don't see the relation excepted that my patch changes the various 
qapi-generators
to accept their input files as argv[1].

The purpose of my patch is to implement a directive to modularise the pseudo 
JSON
files we use. Lluis told me that he would not have the time to work on his 
series
until the end of the month so I picked up the ball.

Best regards

Benoît


  Thanks for the explain, I'll rebase on top once your series merged
into Luiz's tree.




Wenchao, please note "you *may* need to rebase".  First patch in wins :)

[*] https://lists.nongnu.org/archive/html/qemu-devel/2014-03/msg04412.html





Re: [Qemu-devel] [PATCH 2/2] qapi: Create an include directive for use in the JSON description files.

2014-03-26 Thread Wenchao Xia

Just saw the discuss of Lluís's patch, either
{ 'include': './include/include.json' }
or
include("include-cycle-b.json")
is OK to me, but hope only one way is kepted in the end.




Re: [Qemu-devel] [RFC PATCH V3 4/5] test: add test cases for qapi event

2014-03-23 Thread Wenchao Xia

于 2014/3/21 8:23, Eric Blake 写道:

On 03/18/2014 11:16 PM, Wenchao Xia wrote:

These cases will verify whether the expected qdict is built.

Signed-off-by: Wenchao Xia
---
  tests/Makefile  |   14 ++-
  tests/qapi-schema/qapi-schema-test.json |   12 ++
  tests/qapi-schema/qapi-schema-test.out  |   10 +-
  tests/test-qmp-event.c  |  258 +++
  4 files changed, 289 insertions(+), 5 deletions(-)
  create mode 100644 tests/test-qmp-event.c




+++ b/tests/test-qmp-event.c
@@ -0,0 +1,258 @@
+/*
+ * qapi event unit-tests.
+ *
+ * Authors:
+ *  Wenchao Xia
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *

Missing "Copyright"


+case QTYPE_QINT:
+d->result = (qint_get_int(qobject_to_qint(obj1)) ==
+ qint_get_int(qobject_to_qint(obj2)));
+return;
+case QTYPE_QSTRING:
+if (!g_strcmp0(qstring_get_str(qobject_to_qstring(obj1)),
+   qstring_get_str(qobject_to_qstring(obj2 {
+d->result = true;
+} else {
+d->result = false;
+}

Could also be written without 'if':
   d->result = g_strcmp0(...) == 0;


+obj = qdict_get(t, "seconds");
+g_assert(obj&&  qobject_type(obj) == QTYPE_QINT);
+obj = qdict_get(t, "microseconds");
+g_assert(obj&&  qobject_type(obj) == QTYPE_QINT);

Might be worth asserting that microseconds is within the range
[0,99] (or -1 if seconds is -1)


  will add those test.



  1   2   3   4   5   6   7   8   9   10   >