qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, anthony@codemonkey.ws,
	stefanha@redhat.com, Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Subject: [Qemu-devel] [RFC PATCH 6/8] block: replace monitor_protocol_event() with callback
Date: Thu, 12 Sep 2013 17:15:10 +0800	[thread overview]
Message-ID: <1378977312-17696-7-git-send-email-xiawenc@linux.vnet.ibm.com> (raw)
In-Reply-To: <1378977312-17696-1-git-send-email-xiawenc@linux.vnet.ibm.com>

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 <xiawenc@linux.vnet.ibm.com>
---
 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

  parent reply	other threads:[~2013-09-12  9:15 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-12  9:15 [Qemu-devel] [RFC PATCH 0/8] Remove stub mon-protocol-event for block Wenchao Xia
2013-09-12  9:15 ` [Qemu-devel] [RFC PATCH 1/8] block: use type MonitorEvent directly Wenchao Xia
2013-09-23 15:53   ` Eric Blake
2013-09-12  9:15 ` [Qemu-devel] [RFC PATCH 2/8] block: do not include monitor.h in block.c Wenchao Xia
2013-09-23 15:53   ` Eric Blake
2013-09-12  9:15 ` [Qemu-devel] [RFC PATCH 3/8] qapi: move MonitorEvent define Wenchao Xia
2013-09-23 15:55   ` Eric Blake
2013-09-24 14:05     ` Wenchao Xia
2013-09-12  9:15 ` [Qemu-devel] [RFC PATCH 4/8] qapi: rename MonitorEvent to QEvent Wenchao Xia
2013-09-23 15:56   ` Eric Blake
2013-09-12  9:15 ` [Qemu-devel] [RFC PATCH 5/8] block: add a callback layer for common functions Wenchao Xia
2013-09-12  9:15 ` Wenchao Xia [this message]
2013-09-12  9:15 ` [Qemu-devel] [RFC PATCH 7/8] block: do not include monitor.h Wenchao Xia
2013-09-12  9:15 ` [Qemu-devel] [RFC PATCH 8/8] stubs: remove mon-protocol-event.o in stub obj Wenchao Xia
2013-09-12  9:31 ` [Qemu-devel] [RFC PATCH 0/8] Remove stub mon-protocol-event for block Paolo Bonzini
2013-09-12 12:08   ` Kevin Wolf
2013-09-12 14:43     ` Paolo Bonzini
2013-09-12 12:44   ` Markus Armbruster
2013-09-16  4:59   ` Wenchao Xia
2013-09-16 10:02     ` Paolo Bonzini
2013-09-17  2:27       ` Wenchao Xia
2013-09-23 19:06         ` Wenchao Xia
2013-09-23  7:52           ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1378977312-17696-7-git-send-email-xiawenc@linux.vnet.ibm.com \
    --to=xiawenc@linux.vnet.ibm.com \
    --cc=anthony@codemonkey.ws \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).