qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH 6/8] block: replace monitor_protocol_event() wit


From: Wenchao Xia
Subject: [Qemu-devel] [RFC PATCH 6/8] block: replace monitor_protocol_event() with callback
Date: Thu, 12 Sep 2013 17:15:10 +0800

For code inside block layer, it is replaced with a call back
function. vl.c will tell block layer how to emit the event.

Signed-off-by: Wenchao Xia <address@hidden>
---
 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(-)

diff --git a/block.c b/block.c
index 576b86e..5695064 100644
--- a/block.c
+++ b/block.c
@@ -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);
 }
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index ba129de..829083f 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -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);
 
diff --git a/blockjob.c b/blockjob.c
index e7d49b7..7ff356c 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -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);
 }
 
diff --git a/include/block/block.h b/include/block/block.h
index 7913f48..fadbf5b 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -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;
diff --git a/vl.c b/vl.c
index 4e709d5..a277598 100644
--- a/vl.c
+++ b/vl.c
@@ -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;
 
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]