From patchwork Thu Sep 12 09:15:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 274480 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DF0EE2C01F0 for ; Thu, 12 Sep 2013 19:19:45 +1000 (EST) Received: from localhost ([::1]:40476 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VK33w-0005Jv-0U for incoming@patchwork.ozlabs.org; Thu, 12 Sep 2013 05:19:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VK305-0007J7-3U for qemu-devel@nongnu.org; Thu, 12 Sep 2013 05:15:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VK2zv-0003lJ-RY for qemu-devel@nongnu.org; Thu, 12 Sep 2013 05:15:44 -0400 Received: from e28smtp07.in.ibm.com ([122.248.162.7]:46027) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VK2zv-0003kT-0R for qemu-devel@nongnu.org; Thu, 12 Sep 2013 05:15:35 -0400 Received: from /spool/local by e28smtp07.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 12 Sep 2013 14:35:46 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp07.in.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 12 Sep 2013 14:35:44 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id DEE0F3940066 for ; Thu, 12 Sep 2013 14:45:16 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r8C9HNUP27918382 for ; Thu, 12 Sep 2013 14:47:24 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r8C9FNfG008152 for ; Thu, 12 Sep 2013 14:45:23 +0530 Received: from RH64wenchao ([9.181.129.59]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id r8C9FDVk007408; Thu, 12 Sep 2013 14:45:22 +0530 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Thu, 12 Sep 2013 17:15:10 +0800 Message-Id: <1378977312-17696-7-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1378977312-17696-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1378977312-17696-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13091209-8878-0000-0000-000008CF0EC9 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.7 Cc: kwolf@redhat.com, pbonzini@redhat.com, anthony@codemonkey.ws, stefanha@redhat.com, Wenchao Xia Subject: [Qemu-devel] [RFC PATCH 6/8] block: replace monitor_protocol_event() with callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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;