Remove stub mon-protocol-event for block
cover Remove stub mon-protocol-event for block
This series will remove the usage of symbols of mon-protocol-event in qemu-img, qemu-nbd and qemu-io, in short remove the connetion for block layer.
Background:
I am tring to decouple block layer code with other unnnessary components,
and in ./stub there many symbols that qemu-img linked as fake implemtion. As a first step, I am decouple monitor with block layer code, this is the first part of it.
There are still other stub symbols for monitor, which will be solved later.
It seems error handlering is also link with those symbols, and will adjust that.
Wenchao Xia (8):
1 block: use type MonitorEvent directly
2 block: do not include monitor.h in block.c
3 qapi: move MonitorEvent define
4 qapi: rename MonitorEvent to QEvent
5 block: add a callback layer for common functions 6 block: replace monitor_protocol_event() with callback 7 block: do not include monitor.h
7 stubs: remove mon-protocol-event.o in stub obj
block.c | 22 ++++++++++++++++++---- block/qcow2-refcount.c | 4 +++- blockjob.c | 10 ++++++++-- include/block/block.h | 12 ++++++++++++ include/block/block_int.h | 3 +-- include/monitor/monitor.h | 40 ++-------------------------------------- include/qapi/qmp/qevent.h | 41 +++++++++++++++++++++++++++++++++++++++++ include/qapi/qmp/types.h | 1 + monitor.c | 12 ++++++------ stubs/Makefile.objs | 1 - stubs/mon-protocol-event.c | 2 +- tests/Makefile | 3 ++- ui/vnc.c | 2 +- vl.c | 4 ++++ 14 files changed, 100 insertions(+), 57 deletions(-) create mode 100644 include/qapi/qmp/qevent.h
RFC PATCH 1/8 block: use type MonitorEvent directly
block_int.h included monitor.h, so it knows the typedef.
--- block.c | 2 +- include/block/block_int.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
block.c +1 -1
@@ -1711,7 +1711,7 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, }void bdrv_emit_qmp_error_event (const BlockDriverState *bdrv, -enum MonitorEvent ev, +MonitorEvent ev,BlockErrorAction action,bool is_read) {QObject *data;
include/block/block_int.h +1 -1
@@ -315,7 +315,7 @@ AioContext *bdrv_get_aio_context(BlockDriverState *bs);int is_windows_drive (const char *filename);#endif void bdrv_emit_qmp_error_event (const BlockDriverState *bdrv, -enum MonitorEvent ev, +MonitorEvent ev,BlockErrorAction action,bool is_read);/**
Signature · 1 line
1.7.1
RFC PATCH 2/8 block: do not include monitor.h in block.c
In reply to Wenchao Xiablock_int.h already included it.
--- block.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
block.c +0 -1
@@ -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"
Signature · 1 line
1.7.1
RFC PATCH 4/8 qapi: rename MonitorEvent to QEvent
In reply to Wenchao Xia--- block.c | 2 +- include/block/block_int.h | 2 +- include/monitor/monitor.h | 2 +- include/qapi/qmp/qevent.h | 4 ++-- monitor.c | 12 ++++++------ stubs/mon-protocol-event.c | 2 +- ui/vnc.c | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-)
block.c +1 -1
@@ -1710,7 +1710,7 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, }void bdrv_emit_qmp_error_event (const BlockDriverState *bdrv, -MonitorEvent ev, +QEvent ev,BlockErrorAction action,bool is_read) {QObject *data;
include/block/block_int.h +1 -1
@@ -315,7 +315,7 @@ AioContext *bdrv_get_aio_context(BlockDriverState *bs);int is_windows_drive (const char *filename);#endif void bdrv_emit_qmp_error_event (const BlockDriverState *bdrv, -MonitorEvent ev, +QEvent ev,BlockErrorAction action,bool is_read);/**
include/monitor/monitor.h +1 -1
@@ -22,7 +22,7 @@ extern Monitor *default_mon;int monitor_cur_is_qmp (void ); -void monitor_protocol_event (MonitorEvent event,QObject *data); +void monitor_protocol_event (QEvent event,QObject *data);void monitor_init (CharDriverState *chr,int flags);int monitor_suspend (Monitor *mon);
include/qapi/qmp/qevent.h +2 -2
@@ -2,7 +2,7 @@#define QEVENT_H /* QMP events */ -typedef enum MonitorEvent { +typedef enum QEvent { QEVENT_SHUTDOWN, QEVENT_RESET, QEVENT_POWERDOWN,
@@ -36,6 +36,6 @@ typedef enum MonitorEvent {* defining new events here */ QEVENT_MAX , -} MonitorEvent; +} QEvent;#endif
monitor.c +6 -6
@@ -175,7 +175,7 @@ typedef struct MonitorControl {* instance. */ typedef struct MonitorEventState { - MonitorEvent event; /* Event being tracked */ + QEvent 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 */
@@ -517,7 +517,7 @@ QemuMutex monitor_event_state_lock;* Emits the event to every monitor instance */ static void -monitor_protocol_event_emit (MonitorEvent event, +monitor_protocol_event_emit (QEvent event,QObject *data) {Monitor *mon;
@@ -536,7 +536,7 @@ monitor_protocol_event_emit(MonitorEvent event,* applying any rate limiting if required. */ static void -monitor_protocol_event_queue (MonitorEvent event, +monitor_protocol_event_queue (QEvent event,QObject *data) {MonitorEventState *evstate;
@@ -614,7 +614,7 @@ static void monitor_protocol_event_handler(void *opaque)* milliseconds */ static void -monitor_protocol_event_throttle (MonitorEvent event, +monitor_protocol_event_throttle (QEvent event,int64_t rate) {MonitorEventState *evstate;
@@ -650,7 +650,7 @@ static void monitor_protocol_event_init(void)* * Event-specific data can be emitted through the (optional) 'data' parameter. */ -void monitor_protocol_event (MonitorEvent event,QObject *data) +void monitor_protocol_event (QEvent event,QObject *data) {QDict *qmp;const char *event_name;
@@ -1067,7 +1067,7 @@ CommandInfoList *qmp_query_commands(Error **errp)EventInfoList *qmp_query_events (Error **errp) {EventInfoList *info, *ev_list =NULL ; -MonitorEvent e; +QEvent e;for (e =0 ; e <QEVENT_MAX ; e++) {const char *event_name = monitor_event_names[e];
stubs/mon-protocol-event.c +1 -1
@@ -1,6 +1,6 @@#include "qemu-common.h" #include "monitor/monitor.h" -void monitor_protocol_event (MonitorEvent event,QObject *data) +void monitor_protocol_event (QEvent event,QObject *data) { }
ui/vnc.c +1 -1
@@ -275,7 +275,7 @@ static void vnc_client_cache_addr(VncState *client) client->info =QOBJECT (qdict); } -static void vnc_qmp_event (VncState *vs,MonitorEvent event) +static void vnc_qmp_event (VncState *vs,QEvent event) {QDict *server;QObject *data;
Signature · 1 line
1.7.1
RFC PATCH 3/8 qapi: move MonitorEvent define
In reply to Wenchao Xia--- include/monitor/monitor.h | 38 +------------------------------------- include/qapi/qmp/qevent.h | 41 +++++++++++++++++++++++++++++++++++++++++ include/qapi/qmp/types.h | 1 + 3 files changed, 43 insertions(+), 37 deletions(-) create mode 100644 include/qapi/qmp/qevent.h
include/monitor/monitor.h +1 -37
@@ -4,6 +4,7 @@#include "qemu-common.h" #include "qapi/qmp/qerror.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qevent.h" #include "block/block.h" #include "monitor/readline.h"
@@ -19,43 +20,6 @@ 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 , - -/* 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);
include/qapi/qmp/qevent.h new file +41 -0
41 lines not on this page · raw message
include/qapi/qmp/types.h +1 -0
@@ -21,5 +21,6 @@#include "qapi/qmp/qdict.h" #include "qapi/qmp/qlist.h" #include "qapi/qmp/qjson.h" +#include "qapi/qmp/qevent.h" #endif /* QEMU_OBJECTS_H */
Signature · 1 line
1.7.1
RFC PATCH 8/8 stubs: remove mon-protocol-event.o in stub obj
In reply to Wenchao XiaNow block layer do not use this symbol now, so qemg-img, qemu-io and qemu-nbd do not link with this file any more. The test program tests/test-qdev-global-props still need it, so add this obj in rule of test/Makefile, and keeps the c file now.
--- stubs/Makefile.objs | 1 - tests/Makefile | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-)
stubs/Makefile.objs +0 -1
@@ -15,7 +15,6 @@ stub-obj-y += migr-blocker.o stub-obj-y += mon-is-qmp.o stub-obj-y += mon-printf.o stub-obj-y += mon-print-filename.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 += reset.o
tests/Makefile +2 -1
@@ -134,7 +134,8 @@ tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ hw/core/irq.o \ qom/object.o qom/container.o qom/qom-qobject.o \ $(test-qapi-obj-y) \ - libqemuutil.a libqemustub.a + libqemuutil.a libqemustub.a \ + stubs/mon-protocol-event.o tests/test-qapi-types.c tests/test-qapi-types.h :\ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-types.py
Signature · 1 line
1.7.1
RFC PATCH 6/8 block: replace monitor_protocol_event() with callback
In reply to Wenchao XiaFor code inside block layer, it is replaced with a call back function. vl.c will tell block layer how to emit the event.
--- block.c | 12 ++++++++++-- block/qcow2-refcount.c | 4 +++- blockjob.c | 10 ++++++++-- include/block/block.h | 3 ++- vl.c | 4 ++++ 5 files changed, 27 insertions(+), 6 deletions(-)
block.c +10 -2
@@ -1723,6 +1723,10 @@ void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,QObject *data;const char *action_str; +if (!bdrv_common_hooks.event_emit) { +return ; + } +switch (action) {case BDRV_ACTION_REPORT : action_str ="report" ;
@@ -1741,7 +1745,7 @@ void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv, bdrv->device_name, action_str, is_read ? "read" : "write"); -monitor_protocol_event (ev, data); + bdrv_common_hooks.event_emit (ev, data);qobject_decref (data); }
@@ -1750,9 +1754,13 @@ static void bdrv_emit_qmp_eject_event(BlockDriverState *bs, bool ejected) {QObject *data; +if (!bdrv_common_hooks.event_emit) { +return ; + } + data =qobject_from_jsonf ("{ 'device': %s, 'tray-open': %i }" ,bdrv_get_device_name (bs), ejected); -monitor_protocol_event (QEVENT_DEVICE_TRAY_MOVED , data); + bdrv_common_hooks.event_emit (QEVENT_DEVICE_TRAY_MOVED , data);qobject_decref (data); }
block/qcow2-refcount.c +3 -1
@@ -1790,7 +1790,9 @@ int qcow2_pre_write_overlap_check(BlockDriverState *bs, int chk, int64_t offset, 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); +if (bdrv_common_hooks.event_emit) { + bdrv_common_hooks.event_emit (QEVENT_BLOCK_IMAGE_CORRUPTED , data); + }g_free (message);qobject_decref (data);
blockjob.c +8 -2
@@ -245,8 +245,14 @@ QObject *qobject_from_block_job(BlockJob *job)void block_job_ready (BlockJob *job) { -QObject *data =qobject_from_block_job (job); -monitor_protocol_event (QEVENT_BLOCK_JOB_READY , data); +QObject *data; + +if (!bdrv_common_hooks.event_emit) { +return ; + } + + data =qobject_from_block_job (job); + bdrv_common_hooks.event_emit (QEVENT_BLOCK_JOB_READY , data);qobject_decref (data); }
include/block/block.h +2 -1
@@ -7,6 +7,7 @@#include "block/coroutine.h" #include "qapi/qmp/qobject.h" #include "qapi-types.h" +#include "qapi/qmp/qevent.h" /* block.c */ typedef struct BlockDriver BlockDriver ;
@@ -124,7 +125,7 @@ typedef struct BDRVReopenState {* bds. */ typedef struct BDRVCommonHooks { -void (*hooks)(void *); +void (*event_emit)(QEvent event,QObject *data); }BDRVCommonHooks ;extern BDRVCommonHooks bdrv_common_hooks;
vl.c +4 -0
@@ -2852,6 +2852,7 @@ int main(int argc, char **argv, char **envp) };const char *trace_events =NULL ;const char *trace_file =NULL ; +BDRVCommonHooks bdrv_hooks;atexit (qemu_run_exit_notifiers);error_set_progname (argv[0 ]);
@@ -2915,6 +2916,9 @@ int main(int argc, char **argv, char **envp) nb_nics =0 ;bdrv_init_with_whitelist (); +memset (&bdrv_hooks,0 ,sizeof (bdrv_hooks)); + bdrv_hooks.event_emit = monitor_protocol_event; +bdrv_set_common_hooks (&bdrv_hooks); autostart=1 ;
Signature · 1 line
1.7.1
RFC PATCH 7/8 block: do not include monitor.h
In reply to Wenchao XiaBlock layer do not need it any more.
--- include/block/block_int.h | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
include/block/block_int.h +0 -1
@@ -31,7 +31,6 @@#include "qemu/timer.h" #include "qapi-types.h" #include "qapi/qmp/qerror.h" -#include "monitor/monitor.h" #include "qemu/hbitmap.h" #include "block/snapshot.h" #include "qemu/main-loop.h"
Signature · 1 line
1.7.1
RFC PATCH 5/8 block: add a callback layer for common functions
In reply to Wenchao XiaThis structure can hold some call back functions, such as event emit, error printf. By using call back, block layer can be decoupled with other components.
--- block.c | 7 +++++++ include/block/block.h | 11 +++++++++++ 2 files changed, 18 insertions(+), 0 deletions(-)
block.c +7 -0
@@ -55,6 +55,13 @@ typedef enum {BDRV_REQ_ZERO_WRITE =0x2 , } BdrvRequestFlags; +BDRVCommonHooks bdrv_common_hooks; + +void bdrv_set_common_hooks (BDRVCommonHooks *hooks) +{ + bdrv_common_hooks = *hooks; +} +static void bdrv_dev_change_media_cb (BlockDriverState *bs,bool load); static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
include/block/block.h +11 -0
@@ -119,6 +119,17 @@ typedef struct BDRVReopenState {void *opaque; } BDRVReopenState; +/* +* Now all block layer use same hooks, If needed it can be changed as per +* bds. +*/ +typedef struct BDRVCommonHooks { +void (*hooks)(void *); +}BDRVCommonHooks ; + +extern BDRVCommonHooks bdrv_common_hooks; + +void bdrv_set_common_hooks (BDRVCommonHooks *hooks);void bdrv_iostatus_enable (BlockDriverState *bs);void bdrv_iostatus_reset (BlockDriverState *bs);
Signature · 1 line
1.7.1
Il 12/09/2013 11:15, Wenchao Xia ha scritto:
Quoted 23 lines
This series will remove the usage of symbols of mon-protocol-event in qemu-img, qemu-nbd and qemu-io, in short remove the connetion for block layer.
Background:
I am tring to decouple block layer code with other unnnessary components,
and in ./stub there many symbols that qemu-img linked as fake implemtion. As a first step, I am decouple monitor with block layer code, this is the first part of it.
There are still other stub symbols for monitor, which will be solved later.
It seems error handlering is also link with those symbols, and will adjust that.Wenchao Xia (8):
1 block: use type MonitorEvent directly
2 block: do not includemonitor.hinblock.c
3 qapi: move MonitorEvent define
4 qapi: rename MonitorEvent to QEvent
5 block: add a callback layer for common functions 6 block: replacemonitor_protocol_event()with callback 7 block: do not includemonitor.h
7 stubs: remove mon-protocol-event.o in stub obj
Quoted 17 lines
block.c | 22 ++++++++++++++++++---- block/qcow2-refcount.c | 4 +++- blockjob.c | 10 ++++++++-- include/block/block.h | 12 ++++++++++++ include/block/block_int.h | 3 +-- include/monitor/monitor.h | 40 ++-------------------------------------- include/qapi/qmp/qevent.h | 41 +++++++++++++++++++++++++++++++++++++++++ include/qapi/qmp/types.h | 1 + monitor.c | 12 ++++++------ stubs/Makefile.objs | 1 - stubs/mon-protocol-event.c | 2 +- tests/Makefile | 3 ++- ui/vnc.c | 2 +- vl.c | 4 ++++ 14 files changed, 100 insertions(+), 57 deletions(-) create mode 100644 include/qapi/qmp/qevent.h
Patches 1-4 look good. I'm not sure of the advantage of the last four, however. The ugly part of monitor_protocol_event is not really the stub, but the dependency on QObject.
So, in my opinion a more interesting approach would be to describe events using QAPI types. Generating the events would require a small amount of code to build QObjects manually, because the event syntax doesn't match exactly a QAPI union, but that is only a technical detail.
Paolo
Am 12.09.2013 um 11:31 hat Paolo Bonzini geschrieben:
Quoted 14 lines
Il 12/09/2013 11:15, Wenchao Xia ha scritto:
Quoted 4 lines
This series will remove the usage of symbols of mon-protocol-event in qemu-img, qemu-nbd and qemu-io, in short remove the connetion for block layer.
Quoted 8 lines
Background:
I am tring to decouple block layer code with other unnnessary components,
and in ./stub there many symbols that qemu-img linked as fake implemtion. As a first step, I am decouple monitor with block layer code, this is the first part of it.
There are still other stub symbols for monitor, which will be solved later.
It seems error handlering is also link with those symbols, and will adjust that.
Quoted 8 lines
Patches 1-4 look good. I'm not sure of the advantage of the last four, however. The ugly part of
monitor_protocol_eventis not really the stub, but the dependency on QObject.So, in my opinion a more interesting approach would be to describe events using QAPI types. Generating the events would require a small amount of code to build QObjects manually, because the event syntax doesn't match exactly a QAPI union, but that is only a technical detail.
You mean the QAPI schema cannot describe events? Why do you think so, and wouldn't this be a reason to extend the schema language?
The QMP spec describes events like this:
{ "event": json-string, "data": json-object,
"timestamp": { "seconds": json-number, "microseconds": json-number } }
Looks like it could be described as:
{ 'type': 'EventTypeA',
'data': {
'data': {
# event-specific data
} } }
{ 'type': 'EventBase',
'data': { 'event': 'str'. 'timestamp': {
'seconds': 'int', 'microseconds': 'int' } }{ 'union': 'Event',
'base:' EventBase',
'discriminator': 'event',
'data': {
'EVENT_NAME_A': 'EventTypeA'
} }
Kevin
[Note cc: Luiz]
Quoted 46 lines · Paolo Bonzini
Il 12/09/2013 11:15, Wenchao Xia ha scritto:
Quoted 23 lines
This series will remove the usage of symbols of mon-protocol-event in qemu-img, qemu-nbd and qemu-io, in short remove the connetion for block layer.
Background:
I am tring to decouple block layer code with other unnnessary components,
and in ./stub there many symbols that qemu-img linked as fake implemtion. As a first step, I am decouple monitor with block layer code, this is the first part of it.
There are still other stub symbols for monitor, which will be solved later.
It seems error handlering is also link with those symbols, and will adjust that.Wenchao Xia (8):
1 block: use type MonitorEvent directly
2 block: do not includemonitor.hinblock.c
3 qapi: move MonitorEvent define
4 qapi: rename MonitorEvent to QEvent
5 block: add a callback layer for common functions 6 block: replacemonitor_protocol_event()with callback 7 block: do not includemonitor.h
7 stubs: remove mon-protocol-event.o in stub objQuoted 17 lines
block.c | 22 ++++++++++++++++++---- block/qcow2-refcount.c | 4 +++- blockjob.c | 10 ++++++++-- include/block/block.h | 12 ++++++++++++ include/block/block_int.h | 3 +-- include/monitor/monitor.h | 40 ++-------------------------------------- include/qapi/qmp/qevent.h | 41 +++++++++++++++++++++++++++++++++++++++++ include/qapi/qmp/types.h | 1 + monitor.c | 12 ++++++------ stubs/Makefile.objs | 1 - stubs/mon-protocol-event.c | 2 +- tests/Makefile | 3 ++- ui/vnc.c | 2 +- vl.c | 4 ++++ 14 files changed, 100 insertions(+), 57 deletions(-) create mode 100644 include/qapi/qmp/qevent.hPatches 1-4 look good. I'm not sure of the advantage of the last four, however. The ugly part of
monitor_protocol_eventis not really the stub, but the dependency on QObject.
Quoted 6 lines
So, in my opinion a more interesting approach would be to describe events using QAPI types. Generating the events would require a small amount of code to build QObjects manually, because the event syntax doesn't match exactly a QAPI union, but that is only a technical detail.
Paolo
See QMP TODO list, item "Add events support to the QAPI"
http://wiki.qemu.org/QMP#TODO
https://lists.nongnu.org/archive/html/qemu-devel/2013-09/msg01816.html
Il 12/09/2013 14:08, Kevin Wolf ha scritto:
Quoted 42 lines
Am 12.09.2013 um 11:31 hat Paolo Bonzini geschrieben:
Quoted 14 lines
Il 12/09/2013 11:15, Wenchao Xia ha scritto:
Quoted 4 lines
This series will remove the usage of symbols of mon-protocol-event in qemu-img, qemu-nbd and qemu-io, in short remove the connetion for block layer.
Quoted 8 lines
Background:
I am tring to decouple block layer code with other unnnessary components,
and in ./stub there many symbols that qemu-img linked as fake implemtion. As a first step, I am decouple monitor with block layer code, this is the first part of it.
There are still other stub symbols for monitor, which will be solved later.
It seems error handlering is also link with those symbols, and will adjust that.Quoted 8 lines
Patches 1-4 look good. I'm not sure of the advantage of the last four, however. The ugly part of
monitor_protocol_eventis not really the stub, but the dependency on QObject.So, in my opinion a more interesting approach would be to describe events using QAPI types. Generating the events would require a small amount of code to build QObjects manually, because the event syntax doesn't match exactly a QAPI union, but that is only a technical detail.
You mean the QAPI schema cannot describe events? Why do you think so, and wouldn't this be a reason to extend the schema language?
The QMP spec describes events like this:
{ "event": json-string, "data": json-object,
"timestamp": { "seconds": json-number, "microseconds": json-number } }Looks like it could be described as:
{ 'type': 'EventTypeA',
'data': { 'data': { # event-specific data } } } { 'type': 'EventBase', 'data': { 'event': 'str'. 'timestamp': { 'seconds': 'int', 'microseconds': 'int' } }
Quoted 6 lines
{ 'union': 'Event',
'base:' EventBase',
'discriminator': 'event',
'data': {
'EVENT_NAME_A': 'EventTypeA'
} }
I didn't know about all this cool stuff you added. :)
Paolo
Quoted 41 lines · Paolo Bonzini
Il 12/09/2013 11:15, Wenchao Xia ha scritto:
Quoted 38 lines
This series will remove the usage of symbols of mon-protocol-event in qemu-img, qemu-nbd and qemu-io, in short remove the connetion for block layer.
Background:
I am tring to decouple block layer code with other unnnessary components,
and in ./stub there many symbols that qemu-img linked as fake implemtion. As a first step, I am decouple monitor with block layer code, this is the first part of it.
There are still other stub symbols for monitor, which will be solved later.
It seems error handlering is also link with those symbols, and will adjust that.Wenchao Xia (8):
1 block: use type MonitorEvent directly
2 block: do not includemonitor.hinblock.c
3 qapi: move MonitorEvent define
4 qapi: rename MonitorEvent to QEvent
5 block: add a callback layer for common functions 6 block: replacemonitor_protocol_event()with callback 7 block: do not includemonitor.h
7 stubs: remove mon-protocol-event.o in stub objblock.c | 22 ++++++++++++++++++---- block/qcow2-refcount.c | 4 +++- blockjob.c | 10 ++++++++-- include/block/block.h | 12 ++++++++++++ include/block/block_int.h | 3 +-- include/monitor/monitor.h | 40 ++-------------------------------------- include/qapi/qmp/qevent.h | 41 +++++++++++++++++++++++++++++++++++++++++ include/qapi/qmp/types.h | 1 + monitor.c | 12 ++++++------ stubs/Makefile.objs | 1 - stubs/mon-protocol-event.c | 2 +- tests/Makefile | 3 ++- ui/vnc.c | 2 +- vl.c | 4 ++++ 14 files changed, 100 insertions(+), 57 deletions(-)Quoted 2 lines
create mode 100644
include/qapi/qmp/qevent.h
Quoted 3 lines
Patches 1-4 look good. I'm not sure of the advantage of the last four, however. The ugly part of
monitor_protocol_eventis not really the stub, but the dependency on QObject.
I think replacing QObject with QAPI types is another issue we could improve. The last foure patches tries decouple monitor code with block layer code from build time. The files in ./stubs is needed since some symbols are needed in some program which don't need it really, and I think, that tips the code are not organized very well in .c file level. After removing ./stubs, the code will be more clear. And as a by- prodcut, the components in qemu will have a clear boundary, and I can select several components to form library, and qemu can naturlly link with it.
Quoted 7 lines
So, in my opinion a more interesting approach would be to describe events using QAPI types. Generating the events would require a small amount of code to build QObjects manually, because the event syntax doesn't match exactly a QAPI union, but that is only a technical detail.
Paolo
Il 16/09/2013 06:59, Wenchao Xia ha scritto:
Quoted 52 lines
Quoted 48 lines · Paolo Bonzini
Il 12/09/2013 11:15, Wenchao Xia ha scritto:
Quoted 45 lines
This series will remove the usage of symbols of mon-protocol-event in qemu-img, qemu-nbd and qemu-io, in short remove the connetion for block layer.
Background:
I am tring to decouple block layer code with other unnnessary
components,
and in ./stub there many symbols that qemu-img linked as fake implemtion.
As a first step, I am decouple monitor with block layer code, this is the
first part of it.
There are still other stub symbols for monitor, which will be
solved later.
It seems error handlering is also link with those symbols, and will adjust
that.Wenchao Xia (8):
1 block: use type MonitorEvent directly
2 block: do not includemonitor.hinblock.c
3 qapi: move MonitorEvent define
4 qapi: rename MonitorEvent to QEvent
5 block: add a callback layer for common functions 6 block: replacemonitor_protocol_event()with callback 7 block: do not includemonitor.h
7 stubs: remove mon-protocol-event.o in stub objblock.c | 22 ++++++++++++++++++---- block/qcow2-refcount.c | 4 +++- blockjob.c | 10 ++++++++-- include/block/block.h | 12 ++++++++++++ include/block/block_int.h | 3 +-- include/monitor/monitor.h | 40 ++-------------------------------------- include/qapi/qmp/qevent.h | 41 +++++++++++++++++++++++++++++++++++++++++ include/qapi/qmp/types.h | 1 + monitor.c | 12 ++++++------ stubs/Makefile.objs | 1 - stubs/mon-protocol-event.c | 2 +- tests/Makefile | 3 ++- ui/vnc.c | 2 +- vl.c | 4 ++++ 14 files changed, 100 insertions(+), 57 deletions(-)Quoted 2 lines
create mode 100644
include/qapi/qmp/qevent.hQuoted 3 lines
Patches 1-4 look good. I'm not sure of the advantage of the last four, however. The ugly part of
monitor_protocol_eventis not really the stub, but the dependency on QObject.
Quoted 8 lines
I think replacing QObject with QAPI types is another issue we could improve. The last
foure patches tries decouple monitor code with block layer code from build time.
The files in ./stubs is needed since some symbols are needed in some program which don't
need it really, and I think, that tips the code are not organized very well in .c file level.
That may very well be the case. However, picking a function, replacing it with a function pointer, and throwing it into a struct, will not improve the structure at the .c file level very much.
It does not abstract anything. In order to provide a useful abstractions, the questions to answer are:
1) If a library wanted to provide a callback for events, would the current design (using QObject) be the right thing to do? (If you change the design, it might happen that the stub goes away naturally and that the work in these patches does nothing except obscure the history).
2) Are there other services that the block layer could desire from the monitor?
3) Could any tool (e.g. qemu-io) desire to implement monitor_protocol_event? If so, what other services could it provide that the QEMU monitor provides?
Quoted 1 line
After removing ./stubs, the code will be more clear
If done in the right way, yes. If done in the wrong way, the code will be less clear.
Paolo
Quoted 65 lines · Paolo Bonzini
Il 16/09/2013 06:59, Wenchao Xia ha scritto:
Quoted 52 lines
Quoted 48 lines · Paolo Bonzini
Il 12/09/2013 11:15, Wenchao Xia ha scritto:
Quoted 45 lines
This series will remove the usage of symbols of mon-protocol-event in qemu-img, qemu-nbd and qemu-io, in short remove the connetion for block layer.
Background:
I am tring to decouple block layer code with other unnnessary
components,
and in ./stub there many symbols that qemu-img linked as fake implemtion.
As a first step, I am decouple monitor with block layer code, this is the
first part of it.
There are still other stub symbols for monitor, which will be
solved later.
It seems error handlering is also link with those symbols, and will adjust
that.Wenchao Xia (8):
1 block: use type MonitorEvent directly
2 block: do not includemonitor.hinblock.c
3 qapi: move MonitorEvent define
4 qapi: rename MonitorEvent to QEvent
5 block: add a callback layer for common functions 6 block: replacemonitor_protocol_event()with callback 7 block: do not includemonitor.h
7 stubs: remove mon-protocol-event.o in stub objblock.c | 22 ++++++++++++++++++---- block/qcow2-refcount.c | 4 +++- blockjob.c | 10 ++++++++-- include/block/block.h | 12 ++++++++++++ include/block/block_int.h | 3 +-- include/monitor/monitor.h | 40 ++-------------------------------------- include/qapi/qmp/qevent.h | 41 +++++++++++++++++++++++++++++++++++++++++ include/qapi/qmp/types.h | 1 + monitor.c | 12 ++++++------ stubs/Makefile.objs | 1 - stubs/mon-protocol-event.c | 2 +- tests/Makefile | 3 ++- ui/vnc.c | 2 +- vl.c | 4 ++++ 14 files changed, 100 insertions(+), 57 deletions(-)Quoted 2 lines
create mode 100644
include/qapi/qmp/qevent.hQuoted 3 lines
Patches 1-4 look good. I'm not sure of the advantage of the last four, however. The ugly part of
monitor_protocol_eventis not really the stub, but the dependency on QObject.Quoted 8 lines
I think replacing QObject with QAPI types is another issue we could improve. The last
foure patches tries decouple monitor code with block layer code from build time.
The files in ./stubs is needed since some symbols are needed in some program which don't
need it really, and I think, that tips the code are not organized very well in .c file level.That may very well be the case. However, picking a function, replacing it with a function pointer, and throwing it into a struct, will not improve the structure at the .c file level very much.
Quoted 6 lines
It does not abstract anything. In order to provide a useful abstractions, the questions to answer are:
1) If a library wanted to provide a callback for events, would the current design (using QObject) be the right thing to do? (If you change the design, it might happen that the stub goes away naturally and that
I think it would not goes away even QAPI is used. The ./stubs is a symbol
issue at link time, so whenever block layer use a symbol belong to monitor component, the stubs would be needed.
In my opinion, there could be two steps: remove this symbol in block
code,
replace it with QAPI in monitor code.
Quoted 5 lines
the work in these patches does nothing except obscure the history).
2) Are there other services that the block layer could desire from the monitor?
I have a draft makefile which link the core block code, it
shows that only event and error printf(include mon_is_qmp) service are used by block code now. Those symbols basically are listed in ./stubs.
Quoted 4 lines
3) Could any tool (e.g. qemu-io) desire to implement
monitor_protocol_event? If so, what other services could it provide that the QEMU monitor provides?
It seems tools do not need event service now, they link with stubs.
Quoted 6 lines
Quoted 1 line
After removing ./stubs, the code will be more clear
If done in the right way, yes. If done in the wrong way, the code will be less clear.
Paolo
Quoted 89 lines · Wenchao Xia
Quoted 65 lines · Paolo Bonzini
Il 16/09/2013 06:59, Wenchao Xia ha scritto:
Quoted 52 lines
Quoted 48 lines · Paolo Bonzini
Il 12/09/2013 11:15, Wenchao Xia ha scritto:
Quoted 45 lines
This series will remove the usage of symbols of mon-protocol-event in qemu-img, qemu-nbd and qemu-io, in short remove the connetion for block layer.
Background:
I am tring to decouple block layer code with other unnnessary
components,
and in ./stub there many symbols that qemu-img linked as fake implemtion.
As a first step, I am decouple monitor with block layer code, this is the
first part of it.
There are still other stub symbols for monitor, which will be
solved later.
It seems error handlering is also link with those symbols, and will adjust
that.Wenchao Xia (8):
1 block: use type MonitorEvent directly
2 block: do not includemonitor.hinblock.c
3 qapi: move MonitorEvent define
4 qapi: rename MonitorEvent to QEvent
5 block: add a callback layer for common functions 6 block: replacemonitor_protocol_event()with callback 7 block: do not includemonitor.h
7 stubs: remove mon-protocol-event.o in stub objblock.c | 22 ++++++++++++++++++---- block/qcow2-refcount.c | 4 +++- blockjob.c | 10 ++++++++-- include/block/block.h | 12 ++++++++++++ include/block/block_int.h | 3 +-- include/monitor/monitor.h | 40 ++-------------------------------------- include/qapi/qmp/qevent.h | 41 +++++++++++++++++++++++++++++++++++++++++ include/qapi/qmp/types.h | 1 + monitor.c | 12 ++++++------ stubs/Makefile.objs | 1 - stubs/mon-protocol-event.c | 2 +- tests/Makefile | 3 ++- ui/vnc.c | 2 +- vl.c | 4 ++++ 14 files changed, 100 insertions(+), 57 deletions(-)Quoted 2 lines
create mode 100644
include/qapi/qmp/qevent.hQuoted 3 lines
Patches 1-4 look good. I'm not sure of the advantage of the last four, however. The ugly part of
monitor_protocol_eventis not really the stub, but the dependency on QObject.Quoted 8 lines
I think replacing QObject with QAPI types is another issue we could improve. The last
foure patches tries decouple monitor code with block layer code from build time.
The files in ./stubs is needed since some symbols are needed in some program which don't
need it really, and I think, that tips the code are not organized very well in .c file level.That may very well be the case. However, picking a function, replacing it with a function pointer, and throwing it into a struct, will not improve the structure at the .c file level very much.
Quoted 6 lines
It does not abstract anything. In order to provide a useful abstractions, the questions to answer are:
1) If a library wanted to provide a callback for events, would the current design (using QObject) be the right thing to do? (If you change the design, it might happen that the stub goes away naturally and that
I think it would not goes away even QAPI is used. The ./stubs is a
symbol
issue at link time, so whenever block layer use a symbol belong to monitor component, the stubs would be needed.
In my opinion, there could be two steps: remove this symbol in block
code,
replace it with QAPI in monitor code.Quoted 5 lines
the work in these patches does nothing except obscure the history).
2) Are there other services that the block layer could desire from the monitor?
I have a draft makefile which link the core block code, it
shows that only event and errorprintf(include mon_is_qmp)service are used by block code now. Those symbols basically are listed in ./stubs.
Quoted 14 lines
Quoted 4 lines
3) Could any tool (e.g. qemu-io) desire to implement
monitor_protocol_event? If so, what other services could it provide that the QEMU monitor provides?It seems tools do not need event service now, they link with stubs.
Quoted 6 lines
Quoted 1 line
After removing ./stubs, the code will be more clear
If done in the right way, yes. If done in the wrong way, the code will be less clear.
Paolo
Hi Paolo,
This series tries to find a mechanism, which can avoid link with unused
symbols. Assume QObject was replaced with other design, such as QAPI, it will still call monitor funcions to emit the event, so it will still require resolving that function in linking of qemu-img.
Do you have some suggestion for it?
Il 23/09/2013 21:06, Wenchao Xia ha scritto:
Quoted 9 lines
Quoted 1 line
Hi Paolo,
This series tries to find a mechanism, which can avoid link with unused
symbols. Assume QObject was replaced with other design, such as QAPI, it will still call monitor funcions to emit the event, so it will still require
resolving that function in linking of qemu-img.
Do you have some suggestion for it?
No, I don't. Still, it seems to me that (for now) this series does not solve any real problem.
Paolo
Re: [Qemu-devel] [RFC PATCH 2/8] block: do not include monitor.h in block.c
In reply to Wenchao XiaQuoted 6 lines · Wenchao Xia
block_int.halready included it.Signed-off-by Wenchao Xia <[email protected]>--- block.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
Quoted 14 lines
block.c +0
-1@@ -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"
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [RFC PATCH 3/8] qapi: move MonitorEvent define
In reply to Wenchao Xiainclude/qapi/qmp/qevent.h line 1
Quoted 9 lines · Wenchao Xia
Signed-off-by Wenchao Xia <[email protected]>---
new file mode 100644
index 0000000..aef71d9include/qapi/qmp/qevent.h new file +1
-0@@ -0,0 +1,41 @@ +#ifndef QEVENT_H
No copyright notice? Fix that.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [RFC PATCH 4/8] qapi: rename MonitorEvent to QEvent
In reply to Wenchao XiaQuoted 10 lines · Wenchao Xia
Signed-off-by Wenchao Xia <[email protected]>--- block.c | 2 +- include/block/block_int.h | 2 +- include/monitor/monitor.h | 2 +- include/qapi/qmp/qevent.h | 4 ++-- monitor.c | 12 ++++++------ stubs/mon-protocol-event.c | 2 +- ui/vnc.c | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [RFC PATCH 1/8] block: use type MonitorEvent directly
In reply to Wenchao XiaQuoted 7 lines · Wenchao Xia
block_int.hincludedmonitor.h, so it knows the typedef.Signed-off-by Wenchao Xia <[email protected]>--- block.c | 2 +- include/block/block_int.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [RFC PATCH 3/8] qapi: move MonitorEvent define
In reply to Eric BlakeQuoted 11 lines · Eric Blake
include/qapi/qmp/qevent.h line 1
Quoted 8 lines · Wenchao Xia
Signed-off-by Wenchao Xia<[email protected]>---
new file mode 100644
index 0000000..aef71d9include/qapi/qmp/qevent.h new file +1
-0@@ -0,0 +1,41 @@ +#ifndef QEVENT_H No copyright notice? Fix that.
Will add one in next version.