All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema
@ 2014-05-01  4:26 Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 01/28] os-posix: include sys/time.h Wenchao Xia
                   ` (27 more replies)
  0 siblings, 28 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

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                   |    3 +-
 hw/virtio/virtio-balloon.c               |    6 +-
 hw/watchdog/watchdog.c                   |   23 +-
 include/block/block.h                    |    4 -
 include/block/block_int.h                |    3 -
 include/block/blockjob.h                 |   17 +-
 include/monitor/monitor.h                |   40 --
 include/qapi/qmp-event.h                 |   27 ++
 include/qemu/sockets.h                   |    3 +-
 include/sysemu/balloon.h                 |    2 -
 include/sysemu/os-posix.h                |    2 +
 include/sysemu/sysemu.h                  |    2 -
 monitor.c                                |  120 +-----
 qapi-schema.json                         |  632 ++++++++++++++++++++++++++++--
 qapi/Makefile.objs                       |    1 +
 qapi/qmp-event.c                         |   74 ++++
 scripts/qapi-event.py                    |  366 +++++++++++++++++
 scripts/qapi.py                          |   12 +
 stubs/Makefile.objs                      |    1 -
 stubs/mon-protocol-event.c               |    6 -
 target-s390x/kvm.c                       |    8 +-
 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 +++++++++++++
 ui/spice-core.c                          |   77 ++--
 ui/vnc.c                                 |  120 +++---
 ui/vnc.h                                 |    4 +-
 util/qemu-sockets.c                      |   10 +-
 vl.c                                     |   22 +-
 56 files changed, 1690 insertions(+), 859 deletions(-)
 create mode 100644 include/qapi/qmp-event.h
 create mode 100644 qapi/qmp-event.c
 create mode 100644 scripts/qapi-event.py
 delete mode 100644 stubs/mon-protocol-event.c
 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

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 01/28] os-posix: include sys/time.h
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 02/28] qapi: add event helper functions Wenchao Xia
                   ` (26 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

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 <wenchaoqemu@gmail.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 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 <sys/time.h>
+
 void os_set_line_buffering(void);
 void os_set_proc_name(const char *s);
 void os_setup_signal_handling(void);
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 02/28] qapi: add event helper functions
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 01/28] os-posix: include sys/time.h Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01 14:20   ` Eric Blake
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 03/28] qapi script: add event support Wenchao Xia
                   ` (25 subsequent siblings)
  27 siblings, 1 reply; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

This file holds some functions that do not need to be generated.

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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 0000000..02b6ce5
--- /dev/null
+++ b/include/qapi/qmp-event.h
@@ -0,0 +1,27 @@
+/*
+ * QMP Event related
+ *
+ * Copyright (c) 2014 Wenchao Xia
+ *
+ * Authors:
+ *  Wenchao Xia   <wenchaoqemu@gmail.com>
+ *
+ * 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 0000000..0d1ce0b
--- /dev/null
+++ b/qapi/qmp-event.c
@@ -0,0 +1,74 @@
+/*
+ * QMP Event related
+ *
+ * Copyright (c) 2014 Wenchao Xia
+ *
+ * Authors:
+ *  Wenchao Xia   <wenchaoqemu@gmail.com>
+ *
+ * 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 <inttypes.h>
+
+#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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 03/28] qapi script: add event support
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 01/28] os-posix: include sys/time.h Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 02/28] qapi: add event helper functions Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01 22:05   ` Eric Blake
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 04/28] test: add test cases for qapi event Wenchao Xia
                   ` (24 subsequent siblings)
  27 siblings, 1 reply; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

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 <wenchaoqemu@gmail.com>
---
 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 0000000..501baff
--- /dev/null
+++ b/scripts/qapi-event.py
@@ -0,0 +1,366 @@
+#
+# QAPI event generator
+#
+# Copyright (c) 2014 Wenchao Xia
+#
+# Authors:
+#  Wenchao Xia <wenchaoqemu@gmail.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2.
+# See the COPYING file in the top-level directory.
+
+from ordereddict import OrderedDict
+from qapi import *
+import sys
+import os
+import getopt
+import errno
+
+def _generate_event_api_name(event_name, params):
+    api_name = "void qapi_event_send_%s(" % c_fun(event_name).lower();
+    l = len(api_name)
+
+    if params:
+        for argname, argentry, optional, structured in parse_args(params):
+            if optional:
+                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 += "".ljust(l)
+
+    api_name += "Error **errp)"
+    return api_name;
+
+
+# Following are the core functions that generate C APIs to emit event.
+
+def generate_event_declaration(api_name):
+    return mcgen('''
+
+%(api_name)s;
+''',
+                 api_name = api_name)
+
+def generate_event_implement(api_name, event_name, params):
+    # step 1: declare and variables
+    ret = mcgen("""
+
+%(api_name)s
+{
+    QDict *qmp;
+    Error *local_err = NULL;
+    QMPEventFuncEmit emit;
+""",
+                api_name = api_name)
+
+    if params:
+        ret += mcgen("""
+    QmpOutputVisitor *qov;
+    Visitor *v;
+    QObject *obj;
+
+""")
+
+    # step 2: check emit function, create a dict
+    ret += mcgen("""
+    emit = qmp_event_get_func_emit();
+    if (!emit) {
+        return;
+    }
+
+    qmp = qmp_event_build_dict("%(event_name)s");
+
+""",
+                 event_name = event_name)
+
+    # step 3: visit the params if params != None
+    if params:
+        ret += mcgen("""
+    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 */
+    visit_start_struct(v, NULL, "", "%(event_name)s", 0, &local_err);
+    if (error_is_set(&local_err)) {
+        goto clean;
+    }
+
+""",
+                event_name = event_name)
+
+        for argname, argentry, optional, structured in parse_args(params):
+            if optional:
+                ret += mcgen("""
+    if (has_%(var)s) {
+""",
+                             var = c_var(argname))
+                push_indent()
+
+            if argentry == "str":
+                var_type = "(char **)"
+            else:
+                var_type = ""
+
+            ret += mcgen("""
+    visit_type_%(type)s(v, %(var_type)s&%(var)s, "%(name)s", &local_err);
+    if (error_is_set(&local_err)) {
+        goto clean;
+    }
+""",
+                         var_type = var_type,
+                         var = c_var(argname),
+                         type = type_name(argentry),
+                         name = argname)
+
+            if optional:
+                pop_indent()
+                ret += mcgen("""
+    }
+""")
+
+        ret += mcgen("""
+
+    visit_end_struct(v, &local_err);
+    if (error_is_set(&local_err)) {
+        goto clean;
+    }
+
+    obj = qmp_output_get_qobject(qov);
+    g_assert(obj != NULL);
+
+    qdict_put_obj(qmp, "data", obj);
+""")
+
+    # step 4: call qmp event api
+    ret += mcgen("""
+    emit(%(event_enum_value)s, qmp, &local_err);
+
+""",
+                 event_enum_value = event_enum_value)
+
+    # step 5: clean up
+    if params:
+        ret += mcgen("""
+ clean:
+    qmp_output_visitor_cleanup(qov);
+""")
+    ret += mcgen("""
+    error_propagate(errp, local_err);
+    QDECREF(qmp);
+}
+""")
+
+    return ret
+
+
+# Following are the functions that generate an enum type for all defined
+# events, similar to qapi-types.py. Here we already have enum name and
+# values which were generated before and recorded in event_enum_*. It also
+# works around the issue that "import qapi-types" can't work.
+
+def generate_event_enum_decl(event_enum_name, event_enum_values):
+    lookup_decl = mcgen('''
+
+extern const char *%(event_enum_name)s_lookup[];
+''',
+                        event_enum_name = event_enum_name)
+
+    enum_decl = mcgen('''
+typedef enum %(event_enum_name)s
+{
+''',
+                      event_enum_name = event_enum_name)
+
+    # append automatically generated _MAX value
+    enum_max_value = generate_enum_full_value(event_enum_name, "MAX")
+    enum_values = event_enum_values + [ enum_max_value ]
+
+    i = 0
+    for value in enum_values:
+        enum_decl += mcgen('''
+    %(value)s = %(i)d,
+''',
+                     value = value,
+                     i = i)
+        i += 1
+
+    enum_decl += mcgen('''
+} %(event_enum_name)s;
+''',
+                       event_enum_name = event_enum_name)
+
+    return lookup_decl + enum_decl
+
+def generate_event_enum_lookup(event_enum_name, event_enum_strings):
+    ret = mcgen('''
+
+const char *%(event_enum_name)s_lookup[] = {
+''',
+                event_enum_name = event_enum_name)
+
+    i = 0
+    for string in event_enum_strings:
+        ret += mcgen('''
+    "%(string)s",
+''',
+                     string = string)
+
+    ret += mcgen('''
+    NULL,
+};
+''')
+    return ret
+
+
+# Start the real job
+
+try:
+    opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:o:",
+                                   ["source", "header", "builtins", "prefix=",
+                                    "output-dir="])
+except getopt.GetoptError, err:
+    print str(err)
+    sys.exit(1)
+
+output_dir = ""
+prefix = ""
+c_file = 'qapi-event.c'
+h_file = 'qapi-event.h'
+
+do_c = False
+do_h = False
+do_builtins = False
+
+for o, a in opts:
+    if o in ("-p", "--prefix"):
+        prefix = a
+    elif o in ("-o", "--output-dir"):
+        output_dir = a + "/"
+    elif o in ("-c", "--source"):
+        do_c = True
+    elif o in ("-h", "--header"):
+        do_h = True
+    elif o in ("-b", "--builtins"):
+        do_builtins = True
+
+if not do_c and not do_h:
+    do_c = True
+    do_h = True
+
+c_file = output_dir + prefix + c_file
+h_file = output_dir + prefix + h_file
+
+try:
+    os.makedirs(output_dir)
+except os.error, e:
+    if e.errno != errno.EEXIST:
+        raise
+
+def maybe_open(really, name, opt):
+    if really:
+        return open(name, opt)
+    else:
+        import StringIO
+        return StringIO.StringIO()
+
+fdef = maybe_open(do_c, c_file, 'w')
+fdecl = maybe_open(do_h, h_file, 'w')
+
+fdef.write(mcgen('''
+/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
+
+/*
+ * schema-defined QAPI event functions
+ *
+ * Copyright (c) 2014 Wenchao Xia
+ *
+ * Authors:
+ *  Wenchao Xia   <wenchaoqemu@gmail.com>
+ *
+ * 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 "qemu-common.h"
+#include "%(header)s"
+#include "%(prefix)sqapi-visit.h"
+#include "qapi/qmp-output-visitor.h"
+#include "qapi/qmp-event.h"
+
+''',
+                 prefix=prefix, header=basename(h_file)))
+
+fdecl.write(mcgen('''
+/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
+
+/*
+ * schema-defined QAPI event functions
+ *
+ * Copyright (c) 2014 Wenchao Xia
+ *
+ * Authors:
+ *  Wenchao Xia  <wenchaoqemu@gmail.com>
+ *
+ * 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 %(guard)s
+#define %(guard)s
+
+#include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
+#include "%(prefix)sqapi-types.h"
+
+''',
+                  prefix=prefix, guard=guardname(h_file)))
+
+exprs = parse_schema(sys.stdin)
+
+event_enum_name = prefix.upper().replace('-', '_') + "QAPIEvent"
+event_enum_values = []
+event_enum_strings = []
+
+for expr in exprs:
+    if expr.has_key('event'):
+        event_name = expr['event']
+        params = expr.get('data')
+        if params and len(params) == 0:
+            params = None
+
+        api_name = _generate_event_api_name(event_name, params)
+        ret = generate_event_declaration(api_name)
+        fdecl.write(ret)
+
+        # We need an enum value per event
+        event_enum_value = generate_enum_full_value(event_enum_name,
+                                                    event_name)
+        ret = generate_event_implement(api_name, event_name, params)
+        fdef.write(ret)
+
+        # Record it, and generate enum later
+        event_enum_values.append(event_enum_value)
+        event_enum_strings.append(event_name)
+
+ret = generate_event_enum_decl(event_enum_name, event_enum_values)
+fdecl.write(ret)
+ret = generate_event_enum_lookup(event_enum_name, event_enum_strings)
+fdef.write(ret)
+
+fdecl.write('''
+#endif
+''')
+
+fdecl.flush()
+fdecl.close()
+
+fdef.flush()
+fdef.close()
diff --git a/scripts/qapi.py b/scripts/qapi.py
index b474c39..b2941d1 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -199,6 +199,16 @@ def discriminator_find_enum_define(expr):
 
     return find_enum(discriminator_type)
 
+def check_event(expr, expr_info):
+    params = expr.get('data')
+    if params:
+        for argname, argentry, optional, structured in parse_args(params):
+            if structured:
+                raise QAPIExprError(expr_info,
+                                    "Nested structure define in event is not "
+                                    "supported now, event '%s', argname '%s'"
+                                    % (expr['event'], argname))
+
 def check_union(expr, expr_info):
     name = expr['union']
     base = expr.get('base')
@@ -262,6 +272,8 @@ def check_exprs(schema):
         expr = expr_elem['expr']
         if expr.has_key('union'):
             check_union(expr, expr_elem['info'])
+        if expr.has_key('event'):
+            check_event(expr, expr_elem['info'])
 
 def parse_schema(fp):
     try:
diff --git a/tests/Makefile b/tests/Makefile
index 88f7105..e477f14 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -175,7 +175,8 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
         duplicate-key.json union-invalid-base.json flat-union-no-base.json \
         flat-union-invalid-discriminator.json \
         flat-union-invalid-branch-key.json flat-union-reverse-define.json \
-        flat-union-string-discriminator.json)
+        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
 
diff --git a/tests/qapi-schema/event-nest-struct.err b/tests/qapi-schema/event-nest-struct.err
new file mode 100644
index 0000000..6c10a02
--- /dev/null
+++ b/tests/qapi-schema/event-nest-struct.err
@@ -0,0 +1 @@
+<stdin>:1: Nested structure define in event is not supported now, event 'EVENT_A', argname 'a'
diff --git a/tests/qapi-schema/event-nest-struct.exit b/tests/qapi-schema/event-nest-struct.exit
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/tests/qapi-schema/event-nest-struct.exit
@@ -0,0 +1 @@
+1
diff --git a/tests/qapi-schema/event-nest-struct.json b/tests/qapi-schema/event-nest-struct.json
new file mode 100644
index 0000000..ee6f3ec
--- /dev/null
+++ b/tests/qapi-schema/event-nest-struct.json
@@ -0,0 +1,2 @@
+{ 'event': 'EVENT_A',
+  'data': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' } }
diff --git a/tests/qapi-schema/event-nest-struct.out b/tests/qapi-schema/event-nest-struct.out
new file mode 100644
index 0000000..e69de29
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 04/28] test: add test cases for qapi event
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (2 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 03/28] qapi script: add event support Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01 14:38   ` Eric Blake
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 05/28] qapi: define events in qapi schema Wenchao Xia
                   ` (23 subsequent siblings)
  27 siblings, 1 reply; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

These cases will verify whether the expected qdict is built.

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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', '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-test.out
@@ -15,7 +15,12 @@
  OrderedDict([('command', 'user_def_cmd1'), ('data', OrderedDict([('ud1a', 'UserDefOne')]))]),
  OrderedDict([('command', 'user_def_cmd2'), ('data', OrderedDict([('ud1a', 'UserDefOne'), ('*ud1b', 'UserDefOne')])), ('returns', 'UserDefTwo')]),
  OrderedDict([('command', 'user_def_cmd3'), ('data', OrderedDict([('a', 'int'), ('*b', 'int')])), ('returns', 'int')]),
- OrderedDict([('type', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64')]))])]
+ OrderedDict([('type', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64')]))]),
+ OrderedDict([('type', 'EventStructOne'), ('data', OrderedDict([('struct1', 'UserDefOne'), ('string', 'str'), ('*enum2', 'EnumOne')]))]),
+ OrderedDict([('event', 'EVENT_A')]),
+ OrderedDict([('event', 'EVENT_B'), ('data', OrderedDict())]),
+ OrderedDict([('event', 'EVENT_C'), ('data', OrderedDict([('*a', 'int'), ('*b', 'UserDefOne'), ('c', 'str')]))]),
+ OrderedDict([('event', 'EVENT_D'), ('data', OrderedDict([('a', 'EventStructOne'), ('b', 'str'), ('*c', 'str'), ('*enum3', 'EnumOne')]))])]
 [{'enum_name': 'EnumOne', 'enum_values': ['value1', 'value2', 'value3']},
  {'enum_name': 'UserDefUnionKind', 'enum_values': None},
  {'enum_name': 'UserDefAnonUnionKind', 'enum_values': None},
@@ -28,4 +33,5 @@
  OrderedDict([('type', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]),
  OrderedDict([('type', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]),
  OrderedDict([('type', 'UserDefUnionBase'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]),
- OrderedDict([('type', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64')]))])]
+ OrderedDict([('type', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64')]))]),
+ OrderedDict([('type', 'EventStructOne'), ('data', OrderedDict([('struct1', 'UserDefOne'), ('string', 'str'), ('*enum2', 'EnumOne')]))])]
diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c
new file mode 100644
index 0000000..c967d35
--- /dev/null
+++ b/tests/test-qmp-event.c
@@ -0,0 +1,265 @@
+/*
+ * qapi event unit-tests.
+ *
+ * Copyright (c) 2014 Wenchao Xia
+ *
+ * Authors:
+ *  Wenchao Xia   <wenchaoqemu@gmail.com>
+ *
+ * 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 <glib.h>
+#include <stdarg.h>
+
+#include "qemu-common.h"
+#include "test-qapi-types.h"
+#include "test-qapi-visit.h"
+#include "test-qapi-event.h"
+#include "qapi/qmp/types.h"
+#include "qapi/qmp/qint.h"
+#include "qapi/qmp/qobject.h"
+#include "qapi/qmp-event.h"
+
+typedef struct TestEventData {
+    QDict *expect;
+} TestEventData;
+
+typedef struct QDictCmpData {
+    QDict *expect;
+    bool result;
+} QDictCmpData;
+
+TestEventData *test_event_data;
+static GStaticMutex test_event_lock = G_STATIC_MUTEX_INIT;
+
+/* Only compares bool, int, string */
+static
+void qdict_cmp_do_simple(const char *key, QObject *obj1, void *opaque)
+
+{
+    QObject *obj2;
+    QDictCmpData d_new, *d = opaque;
+
+    if (!d->result) {
+        return;
+    }
+
+    obj2 = qdict_get(d->expect, key);
+    if (!obj2) {
+        d->result = false;
+        return;
+    }
+
+    if (qobject_type(obj1) != qobject_type(obj2)) {
+        d->result = false;
+        return;
+    }
+
+    switch (qobject_type(obj1)) {
+    case QTYPE_QBOOL:
+        d->result = (qbool_get_int(qobject_to_qbool(obj1)) ==
+                     qbool_get_int(qobject_to_qbool(obj2)));
+        return;
+    case QTYPE_QINT:
+        d->result = (qint_get_int(qobject_to_qint(obj1)) ==
+                     qint_get_int(qobject_to_qint(obj2)));
+        return;
+    case QTYPE_QSTRING:
+        d->result = g_strcmp0(qstring_get_str(qobject_to_qstring(obj1)),
+                              qstring_get_str(qobject_to_qstring(obj2))) == 0;
+        return;
+    case QTYPE_QDICT:
+        d_new.expect = qobject_to_qdict(obj2);
+        d_new.result = true;
+        qdict_iter(qobject_to_qdict(obj1), qdict_cmp_do_simple, &d_new);
+        d->result = d_new.result;
+        return;
+    default:
+        abort();
+    }
+}
+
+static bool qdict_cmp_simple(QDict *a, QDict *b)
+{
+    QDictCmpData d;
+
+    d.expect = b;
+    d.result = true;
+    qdict_iter(a, qdict_cmp_do_simple, &d);
+    return d.result;
+}
+
+/* This function is hooked as final emit function, which can verify the
+   correctness. */
+static void event_test_emit(int event_kind, QDict *d, Error **errp)
+{
+    QObject *obj;
+    QDict *t;
+    int64_t s, ms;
+
+    /* Verify that we have timestamp, then remove it to compare other field */
+    obj = qdict_get(d, "timestamp");
+    g_assert(obj);
+    t = qobject_to_qdict(obj);
+    g_assert(t);
+    obj = qdict_get(t, "seconds");
+    g_assert(obj && qobject_type(obj) == QTYPE_QINT);
+    s = qint_get_int(qobject_to_qint(obj));
+    obj = qdict_get(t, "microseconds");
+    g_assert(obj && qobject_type(obj) == QTYPE_QINT);
+    ms = qint_get_int(qobject_to_qint(obj));
+    if (s == -1) {
+        g_assert(ms == -1);
+    } else {
+        g_assert(ms >= 0 && ms <= 999999);
+    }
+    g_assert(qdict_size(t) == 2);
+
+    qdict_del(d, "timestamp");
+
+    g_assert(qdict_cmp_simple(d, test_event_data->expect));
+
+}
+
+static void event_prepare(TestEventData *data,
+                          const void *unused)
+{
+    /* Global variable test_event_data was used to pass the expectation, so
+       test cases can't be executed at same time. */
+    g_static_mutex_lock(&test_event_lock);
+
+    data->expect = qdict_new();
+    test_event_data = data;
+}
+
+static void event_teardown(TestEventData *data,
+                           const void *unused)
+{
+    QDECREF(data->expect);
+    test_event_data = NULL;
+
+    g_static_mutex_unlock(&test_event_lock);
+}
+
+static void event_test_add(const char *testpath,
+                           void (*test_func)(TestEventData *data,
+                                             const void *user_data))
+{
+    g_test_add(testpath, TestEventData, NULL, event_prepare, test_func,
+               event_teardown);
+}
+
+
+/* Test cases */
+
+static void test_event_a(TestEventData *data,
+                         const void *unused)
+{
+    QDict *d;
+    d = data->expect;
+    qdict_put(d, "event", qstring_from_str("EVENT_A"));
+    qapi_event_send_event_a(NULL);
+}
+
+static void test_event_b(TestEventData *data,
+                         const void *unused)
+{
+    QDict *d;
+    d = data->expect;
+    qdict_put(d, "event", qstring_from_str("EVENT_B"));
+    qapi_event_send_event_b(NULL);
+}
+
+static void test_event_c(TestEventData *data,
+                         const void *unused)
+{
+    QDict *d, *d_data, *d_b;
+
+    UserDefOne b;
+    UserDefZero z;
+    z.integer = 2;
+    b.base = &z;
+    b.string = g_strdup("test1");
+    b.has_enum1 = false;
+
+    d_b = qdict_new();
+    qdict_put(d_b, "integer", qint_from_int(2));
+    qdict_put(d_b, "string", qstring_from_str("test1"));
+
+    d_data = qdict_new();
+    qdict_put(d_data, "a", qint_from_int(1));
+    qdict_put(d_data, "b", d_b);
+    qdict_put(d_data, "c", qstring_from_str("test2"));
+
+    d = data->expect;
+    qdict_put(d, "event", qstring_from_str("EVENT_C"));
+    qdict_put(d, "data", d_data);
+
+    qapi_event_send_event_c(true, 1, true, &b, "test2", NULL);
+
+    g_free(b.string);
+}
+
+/* Complex type */
+static void test_event_d(TestEventData *data,
+                         const void *unused)
+{
+    UserDefOne struct1;
+    EventStructOne a;
+    UserDefZero z;
+    QDict *d, *d_data, *d_a, *d_struct1;
+
+    z.integer = 2;
+    struct1.base = &z;
+    struct1.string = g_strdup("test1");
+    struct1.has_enum1 = true;
+    struct1.enum1 = ENUM_ONE_VALUE1;
+
+    a.struct1 = &struct1;
+    a.string = g_strdup("test2");
+    a.has_enum2 = true;
+    a.enum2 = ENUM_ONE_VALUE2;
+
+    d_struct1 = qdict_new();
+    qdict_put(d_struct1, "integer", qint_from_int(2));
+    qdict_put(d_struct1, "string", qstring_from_str("test1"));
+    qdict_put(d_struct1, "enum1", qstring_from_str("value1"));
+
+    d_a = qdict_new();
+    qdict_put(d_a, "struct1", d_struct1);
+    qdict_put(d_a, "string", qstring_from_str("test2"));
+    qdict_put(d_a, "enum2", qstring_from_str("value2"));
+
+    d_data = qdict_new();
+    qdict_put(d_data, "a", d_a);
+    qdict_put(d_data, "b", qstring_from_str("test3"));
+    qdict_put(d_data, "enum3", qstring_from_str("value3"));
+
+    d = data->expect;
+    qdict_put(d, "event", qstring_from_str("EVENT_D"));
+    qdict_put(d, "data", d_data);
+
+    qapi_event_send_event_d(&a, "test3", false, NULL, true, ENUM_ONE_VALUE3,
+                           NULL);
+
+    g_free(struct1.string);
+    g_free(a.string);
+}
+
+int main(int argc, char **argv)
+{
+    qmp_event_set_func_emit(event_test_emit);
+
+    g_test_init(&argc, &argv, NULL);
+
+    event_test_add("/event/event_a", test_event_a);
+    event_test_add("/event/event_b", test_event_b);
+    event_test_add("/event/event_c", test_event_c);
+    event_test_add("/event/event_d", test_event_d);
+    g_test_run();
+
+    return 0;
+}
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 05/28] qapi: define events in qapi schema
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (3 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 04/28] test: add test cases for qapi event Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01 15:00   ` Eric Blake
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 06/28] monitor: change event functions as an implemention of new emit method Wenchao Xia
                   ` (22 subsequent siblings)
  27 siblings, 1 reply; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

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 <wenchaoqemu@gmail.com>
---
 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, s->on_error,
                                        true, -ret);
-            if (action == BDRV_ACTION_STOP) {
+            if (action == BLOCK_ERROR_ACTION_STOP) {
                 n = 0;
                 continue;
             }
             if (error == 0) {
                 error = ret;
             }
-            if (action == BDRV_ACTION_REPORT) {
+            if (action == BLOCK_ERROR_ACTION_REPORT) {
                 break;
             }
         }
diff --git a/blockjob.c b/blockjob.c
index cd4784f..b8f6662 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -258,22 +258,23 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockDriverState *bs,
 
     switch (on_err) {
     case BLOCKDEV_ON_ERROR_ENOSPC:
-        action = (error == ENOSPC) ? BDRV_ACTION_STOP : BDRV_ACTION_REPORT;
+        action = (error == ENOSPC) ?
+                 BLOCK_ERROR_ACTION_STOP : BLOCK_ERROR_ACTION_REPORT;
         break;
     case BLOCKDEV_ON_ERROR_STOP:
-        action = BDRV_ACTION_STOP;
+        action = BLOCK_ERROR_ACTION_STOP;
         break;
     case BLOCKDEV_ON_ERROR_REPORT:
-        action = BDRV_ACTION_REPORT;
+        action = BLOCK_ERROR_ACTION_REPORT;
         break;
     case BLOCKDEV_ON_ERROR_IGNORE:
-        action = BDRV_ACTION_IGNORE;
+        action = BLOCK_ERROR_ACTION_IGNORE;
         break;
     default:
         abort();
     }
     bdrv_emit_qmp_error_event(job->bs, QEVENT_BLOCK_JOB_ERROR, action, is_read);
-    if (action == BDRV_ACTION_STOP) {
+    if (action == BLOCK_ERROR_ACTION_STOP) {
         block_job_pause(job);
         block_job_iostatus_set_err(job, error);
         if (bs != job->bs) {
diff --git a/docs/qmp/qmp-events.txt b/docs/qmp/qmp-events.txt
index 145402e..4a47645 100644
--- a/docs/qmp/qmp-events.txt
+++ 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 } }
 
 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,
@@ -42,47 +17,14 @@ Example:
 
 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
 -------------------
-
-Emitted when a block job has been cancelled.
-
-Data:
-
-- "type":     Job type (json-string; "stream" for image streaming
-                                     "commit" for block commit)
-- "device":   Device name (json-string)
-- "len":      Maximum progress value (json-int)
-- "offset":   Current progress value (json-int)
-              On success this is equal to len.
-              On failure this is less than len.
-- "speed":    Rate limit, bytes per second (json-int)
-
-Example:
-
 { "event": "BLOCK_JOB_CANCELLED",
      "data": { "type": "stream", "device": "virtio-disk0",
                "len": 10737418240, "offset": 134217728,
@@ -91,27 +33,6 @@ Example:
 
 BLOCK_JOB_COMPLETED
 -------------------
-
-Emitted when a block job has completed.
-
-Data:
-
-- "type":     Job type (json-string; "stream" for image streaming
-                                     "commit" for block commit)
-- "device":   Device name (json-string)
-- "len":      Maximum progress value (json-int)
-- "offset":   Current progress value (json-int)
-              On success this is equal to len.
-              On failure this is less than len.
-- "speed":    Rate limit, bytes per second (json-int)
-- "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 streaming
-              has failed and clients should not try to interpret the error
-              string.
-
-Example:
-
 { "event": "BLOCK_JOB_COMPLETED",
      "data": { "type": "stream", "device": "virtio-disk0",
                "len": 10737418240, "offset": 10737418240,
@@ -120,20 +41,6 @@ Example:
 
 BLOCK_JOB_ERROR
 ---------------
-
-Emitted when a block job encounters an error.
-
-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, the job may fail later
-    "report": error will be reported and the job canceled
-    "stop": error caused job to be paused
-
-Example:
-
 { "event": "BLOCK_JOB_ERROR",
     "data": { "device": "ide0-hd1",
               "operation": "write",
@@ -142,35 +49,12 @@ Example:
 
 BLOCK_JOB_READY
 ---------------
-
-Emitted when a block job is ready to complete.
-
-Data:
-
-- "device": device name (json-string)
-
-Example:
-
 { "event": "BLOCK_JOB_READY",
     "data": { "device": "ide0-hd1" },
     "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
 
-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" },
@@ -178,16 +62,6 @@ Data:
 
 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
@@ -196,29 +70,11 @@ Data:
 
 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" } }
 
 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" },
@@ -227,116 +83,39 @@ Data:
 
 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 } }
 
 RESET
 -----
-
-Emitted when the Virtual Machine is reseted.
-
-Data: None.
-
-Example:
-
 { "event": "RESET",
     "timestamp": { "seconds": 1267041653, "microseconds": 9518 } }
 
 RESUME
 ------
-
-Emitted when the Virtual Machine resumes execution.
-
-Data: None.
-
-Example:
-
 { "event": "RESUME",
     "timestamp": { "seconds": 1271770767, "microseconds": 582542 } }
 
 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 } }
 
 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
 -----------------------------------
-
-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": {
@@ -346,32 +125,6 @@ Example:
 
 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",
@@ -383,61 +136,21 @@ Example:
 
 STOP
 ----
-
-Emitted when the Virtual Machine is stopped.
-
-Data: None.
-
-Example:
-
 { "event": "STOP",
     "timestamp": { "seconds": 1267041730, "microseconds": 281295 } }
 
 SUSPEND
 -------
-
-Emitted when guest enters S3 state.
-
-Data: None.
-
-Example:
-
 { "event": "SUSPEND",
      "timestamp": { "seconds": 1344456160, "microseconds": 309119 } }
 
 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
 -------------
-
-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",
@@ -446,31 +159,8 @@ Example:
                     "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",
@@ -481,26 +171,6 @@ Example:
 
 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",
@@ -511,31 +181,11 @@ Example:
 
 WAKEUP
 ------
-
-Emitted when the guest has woken up from S3 and is running.
-
-Data: None.
-
-Example:
-
 { "event": "WAKEUP",
      "timestamp": { "seconds": 1344522075, "microseconds": 745528 } }
 
 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/hmp.c b/hmp.c
index ca869ba..10598d3 100644
--- a/hmp.c
+++ b/hmp.c
@@ -453,7 +453,8 @@ void hmp_info_vnc(Monitor *mon, const QDict *qdict)
         for (client = info->clients; client; client = client->next) {
             monitor_printf(mon, "Client:\n");
             monitor_printf(mon, "     address: %s:%s\n",
-                           client->value->host, client->value->service);
+                           client->value->base->host,
+                           client->value->base->service);
             monitor_printf(mon, "  x509_dname: %s\n",
                            client->value->x509_dname ?
                            client->value->x509_dname : "none");
@@ -501,7 +502,7 @@ void hmp_info_spice(Monitor *mon, const QDict *qdict)
         for (chan = info->channels; chan; chan = chan->next) {
             monitor_printf(mon, "Channel:\n");
             monitor_printf(mon, "     address: %s:%s%s\n",
-                           chan->value->host, chan->value->port,
+                           chan->value->base->host, chan->value->base->port,
                            chan->value->tls ? " [tls]" : "");
             monitor_printf(mon, "     session: %" PRId64 "\n",
                            chan->value->connection_id);
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 8a568e5..62ac610 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -57,17 +57,17 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
     BlockErrorAction action = bdrv_get_error_action(req->dev->bs, is_read, error);
     VirtIOBlock *s = req->dev;
 
-    if (action == BDRV_ACTION_STOP) {
+    if (action == BLOCK_ERROR_ACTION_STOP) {
         req->next = s->rq;
         s->rq = req;
-    } else if (action == BDRV_ACTION_REPORT) {
+    } else if (action == BLOCK_ERROR_ACTION_REPORT) {
         virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
         bdrv_acct_done(s->bs, &req->acct);
         g_free(req);
     }
 
     bdrv_error_action(s->bs, action, is_read, error);
-    return action != BDRV_ACTION_IGNORE;
+    return action != BLOCK_ERROR_ACTION_IGNORE;
 }
 
 static void virtio_blk_rw_complete(void *opaque, int ret)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index c943a4d..f6ea5c6 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -596,10 +596,10 @@ static int ide_handle_rw_error(IDEState *s, int error, int op)
     bool is_read = (op & BM_STATUS_RETRY_READ) != 0;
     BlockErrorAction action = bdrv_get_error_action(s->bs, is_read, error);
 
-    if (action == BDRV_ACTION_STOP) {
+    if (action == BLOCK_ERROR_ACTION_STOP) {
         s->bus->dma->ops->set_unit(s->bus->dma, s->unit);
         s->bus->error_status = op;
-    } else if (action == BDRV_ACTION_REPORT) {
+    } else if (action == BLOCK_ERROR_ACTION_REPORT) {
         if (op & BM_STATUS_DMA_RETRY) {
             dma_buf_commit(s);
             ide_dma_error(s);
@@ -608,7 +608,7 @@ static int ide_handle_rw_error(IDEState *s, int error, int op)
         }
     }
     bdrv_error_action(s->bs, action, is_read, error);
-    return action != BDRV_ACTION_IGNORE;
+    return action != BLOCK_ERROR_ACTION_IGNORE;
 }
 
 void ide_dma_cb(void *opaque, int ret)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 48a28ae..5c141c0 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -419,7 +419,7 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error)
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
     BlockErrorAction action = bdrv_get_error_action(s->qdev.conf.bs, is_read, error);
 
-    if (action == BDRV_ACTION_REPORT) {
+    if (action == BLOCK_ERROR_ACTION_REPORT) {
         switch (error) {
         case ENOMEDIUM:
             scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
@@ -439,10 +439,10 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error)
         }
     }
     bdrv_error_action(s->qdev.conf.bs, action, is_read, error);
-    if (action == BDRV_ACTION_STOP) {
+    if (action == BLOCK_ERROR_ACTION_STOP) {
         scsi_req_retry(&r->req);
     }
-    return action != BDRV_ACTION_IGNORE;
+    return action != BLOCK_ERROR_ACTION_IGNORE;
 }
 
 static void scsi_write_complete(void * opaque, int ret)
diff --git a/include/block/block.h b/include/block/block.h
index c12808a..d874465 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -142,10 +142,6 @@ typedef enum {
 #define BDRV_BLOCK_RAW          8
 #define BDRV_BLOCK_OFFSET_MASK  BDRV_SECTOR_MASK
 
-typedef enum {
-    BDRV_ACTION_REPORT, BDRV_ACTION_IGNORE, BDRV_ACTION_STOP
-} BlockErrorAction;
-
 typedef QSIMPLEQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQueue;
 
 typedef struct BDRVReopenState {
diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
index 45588d7..af24669 100644
--- a/include/qemu/sockets.h
+++ b/include/qemu/sockets.h
@@ -29,6 +29,7 @@ int inet_aton(const char *cp, struct in_addr *ia);
 #include "qemu/option.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qerror.h"
+#include "qapi-types.h"
 
 extern QemuOptsList socket_optslist;
 
@@ -61,6 +62,7 @@ int inet_nonblocking_connect(const char *str,
 
 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);
 int unix_listen(const char *path, char *ostr, int olen, Error **errp);
diff --git a/qapi-schema.json b/qapi-schema.json
index 0b00427..cb790e2 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1155,21 +1155,58 @@
 { 'command': 'query-blockstats', 'returns': ['BlockStats'] }
 
 ##
-# @VncClientInfo:
+# @NetworkAddressFamily
 #
-# Information about a connected VNC client.
+# The network address family
+#
+# @ipv4: IPV4 family
+#
+# @ipv6: IPV6 family
+#
+# @unix: unix socket
+#
+# @unknown: otherwise
+#
+# Since: 2.1
+##
+{ 'enum': 'NetworkAddressFamily',
+  'data': [ 'ipv4', 'ipv6', 'unix', 'unknown' ] }
+
+##
+# @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.
+# @family: address family
+#
+# Since: 2.1
+##
+{ 'type': 'VncBasicInfo',
+  'data': { 'host': 'str',
+            'service': 'str',
+            'family': 'NetworkAddressFamily' } }
+
+##
+# @VncServerInfo
+#
+# The network connection information for server
+#
+# @auth: #optional, authentication method
+#
+# Since: 2.1
+##
+{ 'type': 'VncServerInfo',
+  'base': 'VncBasicInfo',
+  'data': { '*auth': 'str' } }
+
+##
+# @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' } }
 
 ##
 # @VncInfo:
@@ -1220,7 +1257,8 @@
 # Since: 0.14.0
 ##
 { 'type': 'VncInfo',
-  'data': {'enabled': 'bool', '*host': 'str', '*family': 'str',
+  'data': {'enabled': 'bool', '*host': 'str',
+           '*family': 'NetworkAddressFamily',
            '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo']} }
 
 ##
@@ -1235,19 +1273,40 @@
 { 'command': 'query-vnc', 'returns': 'VncInfo' }
 
 ##
-# @SpiceChannel
+# @SpiceBasicInfo
 #
-# Information about a SPICE client channel.
+# The basic information for SPICE network connection
+#
+# @host: IP address
 #
-# @host: The host name of the client.  QEMU tries to resolve this to a DNS name
-#        when possible.
+# @port: port number
 #
-# @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
+# @family: address family
+#
+# Since: 2.1
+##
+{ 'type': 'SpiceBasicInfo',
+  'data': { 'host': 'str',
+            'port': 'str',
+            'family': 'NetworkAddressFamily' } }
+
+##
+# @SpiceServerInfo
+#
+# Information about a SPICE server
+#
+# @auth: #optional, authentication method
+#
+# Since: 2.1
+##
+{ 'type': 'SpiceServerInfo',
+  'base': 'SpiceBasicInfo',
+  'data': { '*auth': 'str' } }
+
+##
+# @SpiceChannel
 #
-# @port: The client's port number.
+# Information about a SPICE client channel.
 #
 # @connection-id: SPICE connection id number.  All channels with the same id
 #                 belong to the same SPICE session.
@@ -1265,8 +1324,8 @@
 # Since: 0.14.0
 ##
 { 'type': 'SpiceChannel',
-  'data': {'host': 'str', 'family': 'str', 'port': 'str',
-           'connection-id': 'int', 'channel-type': 'int', 'channel-id': 'int',
+  'base': 'SpiceBasicInfo',
+  'data': {'connection-id': 'int', 'channel-type': 'int', 'channel-id': 'int',
            'tls': 'bool'} }
 
 ##
@@ -4695,3 +4754,526 @@
               'btn'     : 'InputBtnEvent',
               'rel'     : 'InputMoveEvent',
               'abs'     : 'InputMoveEvent' } }
+
+##
+# Event defines
+##
+
+##
+# @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' }
+
+##
+# @POWERDOWN
+#
+# Emitted when the virtual machine is powered down through the power control
+# system, such as via ACPI.
+#
+# Since: 2.1
+##
+{ 'event': 'POWERDOWN' }
+
+##
+# @RESET
+#
+# Emitted when the virtual machine is reset
+#
+# Since: 2.1
+##
+{ 'event': 'RESET' }
+
+##
+# @STOP
+#
+# Emitted when the virtual machine is stopped
+#
+# Since: 2.1
+##
+{ 'event': 'STOP' }
+
+##
+# @RESUME
+#
+# Emitted when the virtual machine resumes execution
+#
+# 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' }
+
+##
+# @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' }
+
+##
+# @WAKEUP
+#
+# Emitted when the guest has woken up from suspend state and is running
+#
+# 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' } }
+
+##
+# @WatchdogExpirationAction
+#
+# An enumeration of the actions taken when the watchdog device's timer is
+# expired
+#
+# @reset: system resets
+#
+# @shutdown: system shutdown, note that it is similar to @powerdown, which
+#            tries to set to system status and notify guest
+#
+# @poweroff: system poweroff, the emulator program exits
+#
+# @pause: system pauses, similar to @stop
+#
+# @debug: system enters debug state
+#
+# @none: nothing is done
+#
+# Since: 2.1
+##
+{ 'enum': 'WatchdogExpirationAction',
+  'data': [ 'reset', 'shutdown', 'poweroff', 'pause', 'debug', 'none' ] }
+
+##
+# @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: 2.1
+##
+{ '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' } }
+
+##
+# @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' } }
+
+##
+# @IoOperationType
+#
+# An enumeration of the I/O operation types
+#
+# @read: read operation
+#
+# @write: write operation
+#
+# Since: 2.1
+##
+{ 'enum': 'IoOperationType',
+  'data': [ 'read', 'write' ] }
+
+##
+# @BlockErrorAction
+#
+# An enumeration of action that has been taken when a DISK I/O occurs
+#
+# @ignore: error has been ignored
+#
+# @report: error has been reported to the device
+#
+# @stop: error caused VM to be stopped
+#
+# Since: 2.1
+##
+{ 'enum': 'BlockErrorAction',
+  'data': [ 'ignore', 'report', 'stop' ] }
+
+##
+# @BLOCK_IO_ERROR
+#
+# Emitted when a disk I/O error occurs
+#
+# @device: device name
+#
+# @operation: I/O operation
+#
+# @action: action that has been taken
+#
+# Note: If action is "stop", a STOP event will eventually follow the
+# BLOCK_IO_ERROR event
+#
+# Since: 2.1
+##
+{ 'event': 'BLOCK_IO_ERROR',
+  'data': { 'device': 'str', 'operation': 'IoOperationType',
+            '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_COMPLETED
+#
+# Emitted when a block job has completed
+#
+# @type: job type
+#
+# @device: device name
+#
+# @len: maximum progress value
+#
+# @offset: current progress value. On success this is equal to len.
+#          On failure this is less than len
+#
+# @speed: rate limit, bytes per second
+#
+# @error: #optional, error message. Only present on failure. This field
+#         contains a human-readable error message. There are no semantics
+#         other than that streaming has failed and clients should not try to
+#         interpret the error string
+#
+# Since: 2.1
+##
+{ 'event': 'BLOCK_JOB_COMPLETED',
+  'data': { 'type'  : 'BlockJobType',
+            'device': 'str',
+            'len'   : 'int',
+            'offset': 'int',
+            'speed' : 'int',
+            '*error': 'str' } }
+
+##
+# @BLOCK_JOB_CANCELLED
+#
+# Emitted when a block job has been cancelled
+#
+# @type: job type
+#
+# @device: device name
+#
+# @len: maximum progress value
+#
+# @offset: current progress value. On success this is equal to len.
+#          On failure this is less than len
+#
+# @speed: rate limit, bytes per second
+#
+# Since: 2.1
+##
+{ 'event': 'BLOCK_JOB_CANCELLED',
+  'data': { 'type'  : 'BlockJobType',
+            'device': 'str',
+            'len'   : 'int',
+            'offset': 'int',
+            'speed' : 'int' } }
+
+##
+# @BLOCK_JOB_ERROR
+#
+# Emitted when a block job encounters an error
+#
+# @device: device name
+#
+# @operation: I/O operation
+#
+# @action: action that has been taken
+#
+# Since: 2.1
+##
+{ 'event': 'BLOCK_JOB_ERROR',
+  'data': { 'device'   : 'str',
+            'operation': 'IoOperationType',
+            'action'   : 'BlockdevOnError' } }
+
+##
+# @BLOCK_JOB_READY
+#
+# Emitted when a block job is ready to complete
+#
+# @device: device name
+#
+# Note: The "ready to complete" status is always reset by a @BLOCK_JOB_ERROR
+# event
+#
+# Since: 2.1
+##
+{ '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' } }
+
+##
+# @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: 2.1
+##
+{ '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: client information
+#
+# Since: 2.1
+##
+{ 'event': 'VNC_INITIALIZED',
+  'data': { 'server': 'VncServerInfo',
+            'client': 'VncClientInfo' } }
+
+##
+# @VNC_DISCONNECTED
+#
+# Emitted when the connection is closed
+#
+# @server: server information
+#
+# @client: client information
+#
+# Since: 2.1
+##
+{ 'event': 'VNC_DISCONNECTED',
+  'data': { 'server': 'VncServerInfo',
+            'client': 'VncClientInfo' } }
+
+##
+# @SPICE_CONNECTED
+#
+# Emitted when a SPICE client establishes a connection
+#
+# @server: server information
+#
+# @client: client information
+#
+# Since: 2.1
+##
+{ 'event': 'SPICE_CONNECTED',
+  'data': { 'server': 'SpiceBasicInfo',
+            'client': 'SpiceBasicInfo' } }
+
+##
+# @SPICE_INITIALIZED
+#
+# Emitted after initial handshake and authentication takes place (if any)
+# and the SPICE channel is up and running
+#
+# @server: server information
+#
+# @client: client information
+#
+# Since: 2.1
+##
+{ 'event': 'SPICE_INITIALIZED',
+  'data': { 'server': 'SpiceServerInfo',
+            'client': 'SpiceChannel' } }
+
+##
+# @SPICE_DISCONNECTED
+#
+# Emitted when the SPICE connection is closed
+#
+# @server: server information
+#
+# @client: client information
+#
+# Since: 2.1
+##
+{ 'event': 'SPICE_DISCONNECTED',
+  'data': { 'server': 'SpiceBasicInfo',
+            'client': 'SpiceBasicInfo' } }
+
+##
+# @SPICE_MIGRATE_COMPLETED
+#
+# Emitted when SPICE migration has completed
+#
+# 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' } }
+
+##
+# @GuestPanickAction
+#
+# An enumeration of the actions taken when guest OS panic is detected
+#
+# @pause: system pauses
+#
+# Since: 2.1
+##
+{ 'enum': 'GuestPanickAction',
+  'data': [ 'pause' ] }
+
+##
+# @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' } }
+
+##
+# @QUORUM_FAILURE
+#
+# Emitted by the Quorum block driver if it fails to establish a quorum
+#
+# @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
+#
+# Since: 2.1
+##
+{ 'event': 'QUORUM_FAILURE',
+  'data': { 'reference': 'str', 'sector-num': 'int', 'sector-count': 'int' } }
+
+##
+# @QUORUM_REPORT_BAD
+#
+# Emitted to report a corruption of a Quorum file
+#
+# @error: #optional, error message. 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
+#
+# Since: 2.1
+##
+{ 'event': 'QUORUM_REPORT_BAD',
+  'data': { '*error': 'str', 'node-name': 'str',
+            'sector-num': 'int', 'sector-count': 'int' } }
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 4cce3b3..387f0ab 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -390,15 +390,16 @@ static SpiceChannelList *qmp_query_spice_channels(void)
 
         chan = g_malloc0(sizeof(*chan));
         chan->value = g_malloc0(sizeof(*chan->value));
+        chan->value->base = g_malloc0(sizeof(*chan->value->base));
 
         paddr = (struct sockaddr *)&item->info->paddr_ext;
         plen = item->info->plen_ext;
         getnameinfo(paddr, plen,
                     host, sizeof(host), port, sizeof(port),
                     NI_NUMERICHOST | NI_NUMERICSERV);
-        chan->value->host = g_strdup(host);
-        chan->value->port = g_strdup(port);
-        chan->value->family = g_strdup(inet_strfamily(paddr->sa_family));
+        chan->value->base->host = g_strdup(host);
+        chan->value->base->port = g_strdup(port);
+        chan->value->base->family = inet_netfamily(paddr->sa_family);
 
         chan->value->connection_id = item->info->connection_id;
         chan->value->channel_type = item->info->type;
diff --git a/ui/vnc.c b/ui/vnc.c
index 2d7def9..b03b3b8 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -320,9 +320,10 @@ static VncClientInfo *qmp_query_vnc_client(const VncState *client)
     }
 
     info = g_malloc0(sizeof(*info));
-    info->host = g_strdup(host);
-    info->service = g_strdup(serv);
-    info->family = g_strdup(inet_strfamily(sa.ss_family));
+    info->base = g_malloc0(sizeof(*info->base));
+    info->base->host = g_strdup(host);
+    info->base->service = g_strdup(serv);
+    info->base->family = inet_netfamily(sa.ss_family);
 
 #ifdef CONFIG_VNC_TLS
     if (client->tls.session && client->tls.dname) {
@@ -397,7 +398,7 @@ VncInfo *qmp_query_vnc(Error **errp)
         info->service = g_strdup(serv);
 
         info->has_family = true;
-        info->family = g_strdup(inet_strfamily(sa.ss_family));
+        info->family = inet_netfamily(sa.ss_family);
 
         info->has_auth = true;
         info->auth = g_strdup(vnc_auth_name(vnc_display));
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 8818d7c..777aca2 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -104,6 +104,16 @@ const char *inet_strfamily(int family)
     return "unknown";
 }
 
+NetworkAddressFamily inet_netfamily(int family)
+{
+    switch (family) {
+    case PF_INET6: return NETWORK_ADDRESS_FAMILY_IPV6;
+    case PF_INET:  return NETWORK_ADDRESS_FAMILY_IPV4;
+    case PF_UNIX:  return NETWORK_ADDRESS_FAMILY_UNIX;
+    }
+    return NETWORK_ADDRESS_FAMILY_UNKNOWN;
+}
+
 int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
 {
     struct addrinfo ai,*res,*e;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 06/28] monitor: change event functions as an implemention of new emit method
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (4 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 05/28] qapi: define events in qapi schema Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01 22:09   ` Eric Blake
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 07/28] qapi event: convert SHUTDOWN Wenchao Xia
                   ` (21 subsequent siblings)
  27 siblings, 1 reply; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

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 <wenchaoqemu@gmail.com>
---
 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);
+    monitor_protocol_event_throttle(QAPI_EVENT_QUORUM_FAILURE, 1000);
+
+    qmp_event_set_func_emit(monitor_protocol_event_queue);
 }
 
 /**
@@ -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);
 }
 
@@ -1042,10 +1047,10 @@ CommandInfoList *qmp_query_commands(Error **errp)
 EventInfoList *qmp_query_events(Error **errp)
 {
     EventInfoList *info, *ev_list = NULL;
-    MonitorEvent e;
+    QAPIEvent e;
 
-    for (e = 0 ; e < QEVENT_MAX ; e++) {
-        const char *event_name = monitor_event_names[e];
+    for (e = 0 ; e < QAPI_EVENT_MAX ; e++) {
+        const char *event_name = QAPIEvent_lookup[e];
         assert(event_name != NULL);
         info = g_malloc0(sizeof(*info));
         info->value = g_malloc0(sizeof(*info->value));
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 07/28] qapi event: convert SHUTDOWN
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (5 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 06/28] monitor: change event functions as an implemention of new emit method Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01 14:44   ` Eric Blake
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 08/28] qapi event: convert POWERDOWN Wenchao Xia
                   ` (20 subsequent siblings)
  27 siblings, 1 reply; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 08/28] qapi event: convert POWERDOWN
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (6 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 07/28] qapi event: convert SHUTDOWN Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 09/28] qapi event: convert RESET Wenchao Xia
                   ` (19 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 09/28] qapi event: convert RESET
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (7 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 08/28] qapi event: convert POWERDOWN Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 10/28] qapi event: convert STOP Wenchao Xia
                   ` (18 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 10/28] qapi event: convert STOP
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (8 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 09/28] qapi event: convert RESET Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 11/28] qapi event: convert RESUME Wenchao Xia
                   ` (17 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 11/28] qapi event: convert RESUME
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (9 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 10/28] qapi event: convert STOP Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 12/28] qapi event: convert SUSPEND Wenchao Xia
                   ` (16 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 12/28] qapi event: convert SUSPEND
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (10 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 11/28] qapi event: convert RESUME Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 13/28] qapi event: convert SUSPEND_DISK Wenchao Xia
                   ` (15 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 13/28] qapi event: convert SUSPEND_DISK
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (11 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 12/28] qapi event: convert SUSPEND Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 14/28] qapi event: convert WAKEUP Wenchao Xia
                   ` (14 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 14/28] qapi event: convert WAKEUP
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (12 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 13/28] qapi event: convert SUSPEND_DISK Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 15/28] qapi event: convert RTC_CHANGE Wenchao Xia
                   ` (13 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 15/28] qapi event: convert RTC_CHANGE
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (13 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 14/28] qapi event: convert WAKEUP Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 16/28] qapi event: convert WATCHDOG Wenchao Xia
                   ` (12 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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 <libfdt.h>
 
@@ -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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 16/28] qapi event: convert WATCHDOG
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (14 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 15/28] qapi event: convert RTC_CHANGE Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 17/28] qapi event: convert DEVICE_DELETED Wenchao Xia
                   ` (11 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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_RESET        1	/* 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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 17/28] qapi event: convert DEVICE_DELETED
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (15 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 16/28] qapi event: convert WATCHDOG Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 18/28] qapi event: convert DEVICE_TRAY_MOVED Wenchao Xia
                   ` (10 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 18/28] qapi event: convert DEVICE_TRAY_MOVED
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (16 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 17/28] qapi event: convert DEVICE_DELETED Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 19/28] qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR Wenchao Xia
                   ` (9 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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 <sys/types.h>
@@ -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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 19/28] qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (17 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 18/28] qapi event: convert DEVICE_TRAY_MOVED Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 20/28] qapi event: convert BLOCK_IMAGE_CORRUPTED Wenchao Xia
                   ` (8 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 20/28] qapi event: convert BLOCK_IMAGE_CORRUPTED
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (18 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 19/28] qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 21/28] qapi event: convert other BLOCK_JOB events Wenchao Xia
                   ` (7 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 21/28] qapi event: convert other BLOCK_JOB events
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (19 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 20/28] qapi event: convert BLOCK_IMAGE_CORRUPTED Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 22/28] qapi event: convert NIC_RX_FILTER_CHANGED Wenchao Xia
                   ` (6 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

BLOCK_JOB_COMPLETED, BLOCK_JOB_CANCELLED, BLOCK_JOB_READY are
converted.

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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);
+
+/**
+ * block_job_ready:
+ * @job: The job which is now ready to complete.
+ * @msg: Error message. Only present on failure.
+ *
+ * Send a BLOCK_JOB_COMPLETED event for the specified job.
+ */
+void block_job_event_completed(BlockJob *job, const char *msg);
 
 /**
  * block_job_ready:
@@ -227,7 +236,7 @@ QObject *qobject_from_block_job(BlockJob *job);
  *
  * Send a BLOCK_JOB_READY event for the specified job.
  */
-void block_job_ready(BlockJob *job);
+void block_job_event_ready(BlockJob *job);
 
 /**
  * block_job_is_paused:
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 22/28] qapi event: convert NIC_RX_FILTER_CHANGED
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (20 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 21/28] qapi event: convert other BLOCK_JOB events Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 23/28] qapi event: convert VNC events Wenchao Xia
                   ` (5 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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_VERSION    11
 
@@ -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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 23/28] qapi event: convert VNC events
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (21 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 22/28] qapi event: convert NIC_RX_FILTER_CHANGED Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 24/28] qapi event: convert SPICE events Wenchao Xia
                   ` (4 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

VNC_CONNECTED, VNC_DISCONNECTED, VNC_INITIALIZED are converted.

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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->info = QOBJECT(qdict);
 }
 
-static void vnc_qmp_event(VncState *vs, MonitorEvent event)
+static void vnc_qmp_event(VncState *vs, QAPIEvent event)
 {
-    QDict *server;
-    QObject *data;
+    VncServerInfo *si;
 
     if (!vs->info) {
         return;
     }
+    g_assert(vs->info->base);
 
-    server = qdict_new();
-    if (vnc_server_info_put(server) < 0) {
-        QDECREF(server);
+    si = vnc_server_info_get();
+    if (!si) {
         return;
     }
 
-    data = qobject_from_jsonf("{ 'client': %p, 'server': %p }",
-                              vs->info, QOBJECT(server));
-
-    monitor_protocol_event(event, data);
+    switch (event) {
+    case QAPI_EVENT_VNC_CONNECTED:
+        qapi_event_send_vnc_connected(si, vs->info->base, NULL);
+        break;
+    case QAPI_EVENT_VNC_INITIALIZED:
+        qapi_event_send_vnc_initialized(si, vs->info, NULL);
+        break;
+    case QAPI_EVENT_VNC_DISCONNECTED:
+        qapi_event_send_vnc_disconnected(si, vs->info, NULL);
+        break;
+    default:
+        break;
+    }
 
-    qobject_incref(vs->info);
-    qobject_decref(data);
+    qapi_free_VncServerInfo(si);
 }
 
 static VncClientInfo *qmp_query_vnc_client(const VncState *client)
@@ -1036,7 +1039,7 @@ void vnc_disconnect_finish(VncState *vs)
     vnc_jobs_join(vs); /* Wait encoding jobs */
 
     vnc_lock_output(vs);
-    vnc_qmp_event(vs, QEVENT_VNC_DISCONNECTED);
+    vnc_qmp_event(vs, QAPI_EVENT_VNC_DISCONNECTED);
 
     buffer_free(&vs->input);
     buffer_free(&vs->output);
@@ -1045,7 +1048,7 @@ void vnc_disconnect_finish(VncState *vs)
     buffer_free(&vs->ws_output);
 #endif /* CONFIG_VNC_WS */
 
-    qobject_decref(vs->info);
+    qapi_free_VncClientInfo(vs->info);
 
     vnc_zlib_clear(vs);
     vnc_tight_clear(vs);
@@ -2302,7 +2305,7 @@ static int protocol_client_init(VncState *vs, uint8_t *data, size_t len)
     vnc_flush(vs);
 
     vnc_client_cache_auth(vs);
-    vnc_qmp_event(vs, QEVENT_VNC_INITIALIZED);
+    vnc_qmp_event(vs, QAPI_EVENT_VNC_INITIALIZED);
 
     vnc_read_when(vs, protocol_client_msg, 1);
 
@@ -2825,7 +2828,7 @@ static void vnc_connect(VncDisplay *vd, int csock,
     }
 
     vnc_client_cache_addr(vs);
-    vnc_qmp_event(vs, QEVENT_VNC_CONNECTED);
+    vnc_qmp_event(vs, QAPI_EVENT_VNC_CONNECTED);
     vnc_set_share_mode(vs, VNC_SHARE_MODE_CONNECTING);
 
     vs->vd = vd;
diff --git a/ui/vnc.h b/ui/vnc.h
index 8da81b8..07af9f7 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -31,7 +31,6 @@
 #include "qemu/queue.h"
 #include "qemu/thread.h"
 #include "ui/console.h"
-#include "monitor/monitor.h"
 #include "audio/audio.h"
 #include "qemu/bitmap.h"
 #include <zlib.h>
@@ -40,6 +39,7 @@
 #include "keymaps.h"
 #include "vnc-palette.h"
 #include "vnc-enc-zrle.h"
+#include "qapi-types.h"
 
 // #define _VNC_DEBUG 1
 
@@ -292,7 +292,7 @@ struct VncState
     bool websocket;
 #endif /* CONFIG_VNC_WS */
 
-    QObject *info;
+    VncClientInfo *info;
 
     Buffer output;
     Buffer input;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 24/28] qapi event: convert SPICE events
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (22 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 23/28] qapi event: convert VNC events Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 25/28] qapi event: convert BALLOON_CHANGE Wenchao Xia
                   ` (3 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

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 <wenchaoqemu@gmail.com>
---
 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:
         channel_list_del(info);
+        qapi_event_send_spice_disconnected(server->base, client->base, NULL);
+        break;
+    default:
+        break;
     }
 
-    data = qobject_from_jsonf("{ 'client': %p, 'server': %p }",
-                              QOBJECT(client), QOBJECT(server));
-    monitor_protocol_event(qevent[event], data);
-    qobject_decref(data);
-
     if (need_lock) {
         qemu_mutex_unlock_iothread();
     }
+
+    qapi_free_SpiceServerInfo(server);
+    qapi_free_SpiceChannel(client);
 }
 
 static SpiceCoreInterface core_interface = {
@@ -304,7 +306,7 @@ static void migrate_connect_complete_cb(SpiceMigrateInstance *sin)
 
 static void migrate_end_complete_cb(SpiceMigrateInstance *sin)
 {
-    monitor_protocol_event(QEVENT_SPICE_MIGRATE_COMPLETED, NULL);
+    qapi_event_send_spice_migrate_completed(NULL);
     spice_migration_completed = true;
 }
 
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 777aca2..9999c38 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -94,16 +94,6 @@ static void inet_setport(struct addrinfo *e, int port)
     }
 }
 
-const char *inet_strfamily(int family)
-{
-    switch (family) {
-    case PF_INET6: return "ipv6";
-    case PF_INET:  return "ipv4";
-    case PF_UNIX:  return "unix";
-    }
-    return "unknown";
-}
-
 NetworkAddressFamily inet_netfamily(int family)
 {
     switch (family) {
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 25/28] qapi event: convert BALLOON_CHANGE
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (23 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 24/28] qapi event: convert SPICE events Wenchao Xia
@ 2014-05-01  4:26 ` Wenchao Xia
  2014-05-01  4:27 ` [Qemu-devel] [PATCH V5 26/28] qapi event: convert GUEST_PANICKED Wenchao Xia
                   ` (2 subsequent siblings)
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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 <sys/mman.h>
@@ -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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 26/28] qapi event: convert GUEST_PANICKED
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (24 preceding siblings ...)
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 25/28] qapi event: convert BALLOON_CHANGE Wenchao Xia
@ 2014-05-01  4:27 ` Wenchao Xia
  2014-05-01  4:27 ` [Qemu-devel] [PATCH V5 27/28] qapi event: convert QUORUM events Wenchao Xia
  2014-05-01  4:27 ` [Qemu-devel] [PATCH V5 28/28] qapi event: clean up Wenchao Xia
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

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 <wenchaoqemu@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 27/28] qapi event: convert QUORUM events
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (25 preceding siblings ...)
  2014-05-01  4:27 ` [Qemu-devel] [PATCH V5 26/28] qapi event: convert GUEST_PANICKED Wenchao Xia
@ 2014-05-01  4:27 ` Wenchao Xia
  2014-05-01  4:27 ` [Qemu-devel] [PATCH V5 28/28] qapi event: clean up Wenchao Xia
  27 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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 <gnutls/crypto.h>
 #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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH V5 28/28] qapi event: clean up
  2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
                   ` (26 preceding siblings ...)
  2014-05-01  4:27 ` [Qemu-devel] [PATCH V5 27/28] qapi event: convert QUORUM events Wenchao Xia
@ 2014-05-01  4:27 ` Wenchao Xia
  2014-05-01 22:15   ` Eric Blake
  27 siblings, 1 reply; 40+ messages in thread
From: Wenchao Xia @ 2014-05-01  4:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, Wenchao Xia, lcapitulino

Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
---
 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 = monitor_event_names[event];
-    assert(event_name != NULL);
-
-    qmp = qdict_new();
-    timestamp_put(qmp);
-    qdict_put(qmp, "event", qstring_from_str(event_name));
-    if (data) {
-        qobject_incref(data);
-        qdict_put_obj(qmp, "data", data);
-    }
-
-    trace_monitor_protocol_event(event, event_name, qmp);
-    /* Bypass rate limiting for now */
-    monitor_protocol_event_emit(event, QOBJECT(qmp));
-    QDECREF(qmp);
-}
-
 static int do_qmp_capabilities(Monitor *mon, const QDict *params,
                                QObject **ret_data)
 {
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index d99e2b9..60de407 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -14,7 +14,6 @@ stub-obj-y += iothread-lock.o
 stub-obj-y += migr-blocker.o
 stub-obj-y += mon-is-qmp.o
 stub-obj-y += mon-printf.o
-stub-obj-y += mon-protocol-event.o
 stub-obj-y += mon-set-error.o
 stub-obj-y += pci-drive-hot-add.o
 stub-obj-y += qtest.o
diff --git a/stubs/mon-protocol-event.c b/stubs/mon-protocol-event.c
deleted file mode 100644
index 0946e94..0000000
--- a/stubs/mon-protocol-event.c
+++ /dev/null
@@ -1,6 +0,0 @@
-#include "qemu-common.h"
-#include "monitor/monitor.h"
-
-void monitor_protocol_event(MonitorEvent event, QObject *data)
-{
-}
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH V5 02/28] qapi: add event helper functions
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 02/28] qapi: add event helper functions Wenchao Xia
@ 2014-05-01 14:20   ` Eric Blake
  0 siblings, 0 replies; 40+ messages in thread
From: Eric Blake @ 2014-05-01 14:20 UTC (permalink / raw)
  To: Wenchao Xia, qemu-devel; +Cc: mdroth, armbru, lcapitulino

[-- Attachment #1: Type: text/plain, Size: 657 bytes --]

On 04/30/2014 10:26 PM, Wenchao Xia wrote:
> This file holds some functions that do not need to be generated.
> 
> Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
> ---
>  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
> 

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH V5 04/28] test: add test cases for qapi event
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 04/28] test: add test cases for qapi event Wenchao Xia
@ 2014-05-01 14:38   ` Eric Blake
  0 siblings, 0 replies; 40+ messages in thread
From: Eric Blake @ 2014-05-01 14:38 UTC (permalink / raw)
  To: Wenchao Xia, qemu-devel; +Cc: mdroth, armbru, lcapitulino

[-- Attachment #1: Type: text/plain, Size: 1614 bytes --]

On 04/30/2014 10:26 PM, Wenchao Xia wrote:
> These cases will verify whether the expected qdict is built.
> 
> Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
> ---
>  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
> 

> @@ -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   $@")

I'd like to see Lluís' modularization patches go in first, which means
this should be rebased to break into shorter lines and to pass the name
of the file as an input parameter rather than parsing it from stdin.

https://lists.gnu.org/archive/html/qemu-devel/2014-04/msg05069.html

But everything else here seems okay.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH V5 07/28] qapi event: convert SHUTDOWN
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 07/28] qapi event: convert SHUTDOWN Wenchao Xia
@ 2014-05-01 14:44   ` Eric Blake
  2014-05-07 12:55     ` Wenchao Xia
  0 siblings, 1 reply; 40+ messages in thread
From: Eric Blake @ 2014-05-01 14:44 UTC (permalink / raw)
  To: Wenchao Xia, qemu-devel; +Cc: mdroth, armbru, lcapitulino

[-- Attachment #1: Type: text/plain, Size: 667 bytes --]

On 04/30/2014 10:26 PM, Wenchao Xia wrote:
> Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
> ---
>  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?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH V5 05/28] qapi: define events in qapi schema
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 05/28] qapi: define events in qapi schema Wenchao Xia
@ 2014-05-01 15:00   ` Eric Blake
  2014-05-07 12:48     ` Wenchao Xia
  0 siblings, 1 reply; 40+ messages in thread
From: Eric Blake @ 2014-05-01 15:00 UTC (permalink / raw)
  To: Wenchao Xia, qemu-devel; +Cc: mdroth, armbru, lcapitulino

[-- Attachment #1: Type: text/plain, Size: 4329 bytes --]

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 <wenchaoqemu@gmail.com>
> ---

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)

> +++ 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/).


> +##
> +# @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.

> +
> +##
> +# 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.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH V5 03/28] qapi script: add event support
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 03/28] qapi script: add event support Wenchao Xia
@ 2014-05-01 22:05   ` Eric Blake
  2014-05-02  7:54     ` Markus Armbruster
  0 siblings, 1 reply; 40+ messages in thread
From: Eric Blake @ 2014-05-01 22:05 UTC (permalink / raw)
  To: Wenchao Xia, qemu-devel; +Cc: mdroth, armbru, lcapitulino

[-- Attachment #1: Type: text/plain, Size: 2129 bytes --]

On 04/30/2014 10:26 PM, Wenchao Xia wrote:
> 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 <wenchaoqemu@gmail.com>
> ---

> @@ -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   $@")

Long lines; I think you should rebase atop Lluís series.


> +
> +    /* Fake visit, as if all member are under a structure */
> +    visit_start_struct(v, NULL, "", "%(event_name)s", 0, &local_err);
> +    if (error_is_set(&local_err)) {
> +        goto clean;
> +    }

s/error_is_set(&local_err)/local_err/ here and elsewhere.  We are
getting rid of error_is_set.

> +
> +# Start the real job
> +
> +try:
> +    opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:o:",
> +                                   ["source", "header", "builtins", "prefix=",
> +                                    "output-dir="])

Another reason to rebase atop Lluís work: this should take the input
file name as a parameter rather than reading stdin.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH V5 06/28] monitor: change event functions as an implemention of new emit method
  2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 06/28] monitor: change event functions as an implemention of new emit method Wenchao Xia
@ 2014-05-01 22:09   ` Eric Blake
  2014-05-07 12:53     ` Wenchao Xia
  0 siblings, 1 reply; 40+ messages in thread
From: Eric Blake @ 2014-05-01 22:09 UTC (permalink / raw)
  To: Wenchao Xia, qemu-devel; +Cc: mdroth, armbru, lcapitulino

[-- Attachment #1: Type: text/plain, Size: 1359 bytes --]

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 <wenchaoqemu@gmail.com>
> ---
>  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?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH V5 28/28] qapi event: clean up
  2014-05-01  4:27 ` [Qemu-devel] [PATCH V5 28/28] qapi event: clean up Wenchao Xia
@ 2014-05-01 22:15   ` Eric Blake
  0 siblings, 0 replies; 40+ messages in thread
From: Eric Blake @ 2014-05-01 22:15 UTC (permalink / raw)
  To: Wenchao Xia, qemu-devel; +Cc: mdroth, armbru, lcapitulino

[-- Attachment #1: Type: text/plain, Size: 593 bytes --]

On 04/30/2014 10:27 PM, Wenchao Xia wrote:
> Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
> ---
>  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

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH V5 03/28] qapi script: add event support
  2014-05-01 22:05   ` Eric Blake
@ 2014-05-02  7:54     ` Markus Armbruster
  0 siblings, 0 replies; 40+ messages in thread
From: Markus Armbruster @ 2014-05-02  7:54 UTC (permalink / raw)
  To: Eric Blake; +Cc: mdroth, lcapitulino, Wenchao Xia, qemu-devel

Eric Blake <eblake@redhat.com> writes:

> On 04/30/2014 10:26 PM, Wenchao Xia wrote:
>> 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 <wenchaoqemu@gmail.com>
>> ---
>
>> @@ -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   $@")
>
> Long lines; I think you should rebase atop Lluís series.

This one: "qapi: Allow modularization of QAPI schema files".  v9 looked
committable to me, but Lluís decided to address minor review comments
right away.  I haven't reviewed his v10, yet, but I expect it to be the
final one.

>> +
>> +    /* Fake visit, as if all member are under a structure */
>> +    visit_start_struct(v, NULL, "", "%(event_name)s", 0, &local_err);
>> +    if (error_is_set(&local_err)) {
>> +        goto clean;
>> +    }
>
> s/error_is_set(&local_err)/local_err/ here and elsewhere.  We are
> getting rid of error_is_set.

Yes, please!

>> +
>> +# Start the real job
>> +
>> +try:
>> +    opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:o:",
>> + ["source", "header", "builtins", "prefix=",
>> +                                    "output-dir="])
>
> Another reason to rebase atop Lluís work: this should take the input
> file name as a parameter rather than reading stdin.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH V5 05/28] qapi: define events in qapi schema
  2014-05-01 15:00   ` Eric Blake
@ 2014-05-07 12:48     ` Wenchao Xia
  0 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-07 12:48 UTC (permalink / raw)
  To: Eric Blake, qemu-devel; +Cc: mdroth, armbru, lcapitulino

于 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 <wenchaoqemu@gmail.com>
>> ---
>
> 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?

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH V5 06/28] monitor: change event functions as an implemention of new emit method
  2014-05-01 22:09   ` Eric Blake
@ 2014-05-07 12:53     ` Wenchao Xia
  0 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-07 12:53 UTC (permalink / raw)
  To: Eric Blake, qemu-devel; +Cc: mdroth, armbru, lcapitulino

于 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 <wenchaoqemu@gmail.com>
>> ---
>>   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.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH V5 07/28] qapi event: convert SHUTDOWN
  2014-05-01 14:44   ` Eric Blake
@ 2014-05-07 12:55     ` Wenchao Xia
  0 siblings, 0 replies; 40+ messages in thread
From: Wenchao Xia @ 2014-05-07 12:55 UTC (permalink / raw)
  To: Eric Blake, qemu-devel; +Cc: mdroth, armbru, lcapitulino

于 2014/5/1 22:44, Eric Blake 写道:
> On 04/30/2014 10:26 PM, Wenchao Xia wrote:
>> Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
>> ---
>>   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.

^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2014-05-07 12:56 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-01  4:26 [Qemu-devel] [PATCH V5 00/28] add direct support of event in qapi schema Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 01/28] os-posix: include sys/time.h Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 02/28] qapi: add event helper functions Wenchao Xia
2014-05-01 14:20   ` Eric Blake
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 03/28] qapi script: add event support Wenchao Xia
2014-05-01 22:05   ` Eric Blake
2014-05-02  7:54     ` Markus Armbruster
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 04/28] test: add test cases for qapi event Wenchao Xia
2014-05-01 14:38   ` Eric Blake
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 05/28] qapi: define events in qapi schema Wenchao Xia
2014-05-01 15:00   ` Eric Blake
2014-05-07 12:48     ` Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 06/28] monitor: change event functions as an implemention of new emit method Wenchao Xia
2014-05-01 22:09   ` Eric Blake
2014-05-07 12:53     ` Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 07/28] qapi event: convert SHUTDOWN Wenchao Xia
2014-05-01 14:44   ` Eric Blake
2014-05-07 12:55     ` Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 08/28] qapi event: convert POWERDOWN Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 09/28] qapi event: convert RESET Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 10/28] qapi event: convert STOP Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 11/28] qapi event: convert RESUME Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 12/28] qapi event: convert SUSPEND Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 13/28] qapi event: convert SUSPEND_DISK Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 14/28] qapi event: convert WAKEUP Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 15/28] qapi event: convert RTC_CHANGE Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 16/28] qapi event: convert WATCHDOG Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 17/28] qapi event: convert DEVICE_DELETED Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 18/28] qapi event: convert DEVICE_TRAY_MOVED Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 19/28] qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 20/28] qapi event: convert BLOCK_IMAGE_CORRUPTED Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 21/28] qapi event: convert other BLOCK_JOB events Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 22/28] qapi event: convert NIC_RX_FILTER_CHANGED Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 23/28] qapi event: convert VNC events Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 24/28] qapi event: convert SPICE events Wenchao Xia
2014-05-01  4:26 ` [Qemu-devel] [PATCH V5 25/28] qapi event: convert BALLOON_CHANGE Wenchao Xia
2014-05-01  4:27 ` [Qemu-devel] [PATCH V5 26/28] qapi event: convert GUEST_PANICKED Wenchao Xia
2014-05-01  4:27 ` [Qemu-devel] [PATCH V5 27/28] qapi event: convert QUORUM events Wenchao Xia
2014-05-01  4:27 ` [Qemu-devel] [PATCH V5 28/28] qapi event: clean up Wenchao Xia
2014-05-01 22:15   ` Eric Blake

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.