From patchwork Fri Jun 3 19:04:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 98625 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6554AB6FAF for ; Sat, 4 Jun 2011 05:08:13 +1000 (EST) Received: from localhost ([::1]:48326 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSZj7-0005h1-HK for incoming@patchwork.ozlabs.org; Fri, 03 Jun 2011 15:08:09 -0400 Received: from eggs.gnu.org ([140.186.70.92]:59355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSZfZ-0005gH-9i for qemu-devel@nongnu.org; Fri, 03 Jun 2011 15:04:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QSZfW-0002Wq-Ew for qemu-devel@nongnu.org; Fri, 03 Jun 2011 15:04:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20295) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSZfV-0002Wb-L6 for qemu-devel@nongnu.org; Fri, 03 Jun 2011 15:04:26 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p53J4OJx027371 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Jun 2011 15:04:24 -0400 Received: from localhost (ovpn-113-26.phx2.redhat.com [10.3.113.26]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p53J4MCw021181; Fri, 3 Jun 2011 15:04:23 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 3 Jun 2011 16:04:00 -0300 Message-Id: <1307127842-12102-9-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1307127842-12102-1-git-send-email-lcapitulino@redhat.com> References: <1307127842-12102-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, amit.shah@redhat.com, aliguori@us.ibm.com, armbru@redhat.com Subject: [Qemu-devel] [RFC 08/10] QMP: Introduce the BLOCK_TRAY_OPEN and BLOCK_TRAY_CLOSE events 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 They are emitted when the tray is opened or closed, either by the guest or by monitor commands. Signed-off-by: Luiz Capitulino --- QMP/qmp-events.txt | 30 ++++++++++++++++++++++++++++++ block.c | 22 ++++++++++++++++++++++ monitor.c | 6 ++++++ monitor.h | 2 ++ 4 files changed, 60 insertions(+), 0 deletions(-) diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt index 0ce5d4e..51a93d0 100644 --- a/QMP/qmp-events.txt +++ b/QMP/qmp-events.txt @@ -26,6 +26,36 @@ Example: Note: If action is "stop", a STOP event will eventually follow the BLOCK_IO_ERROR event. +BLOCK_TRAY_CLOSE +---------------- + +Emitted when a removable disk media tray is closed. + +Data: + +- "device": device name (json-string) + +Example: + +{ "event": "BLOCK_TRAY_CLOSE", + "data": { "device": "ide1-cd0" }, + "timestamp": { "seconds": 1265044280, "microseconds": 450456 } } + +BLOCK_TRAY_OPEN +--------------- + +Emitted when a removable disk media tray is opened. + +Data: + +- "device": device name (json-string) + +Example: + +{ "event": "BLOCK_TRAY_OPEN", + "data": { "device": "ide1-cd0" }, + "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } + RESET ----- diff --git a/block.c b/block.c index 3df5a4f..9224f22 100644 --- a/block.c +++ b/block.c @@ -1656,6 +1656,17 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum); } +static void bdrv_eject_mon_event(const BlockDriverState *bdrv, int tray_open) +{ + QObject *data; + int event; + + data = qobject_from_jsonf("{ 'device': %s }", bdrv->device_name); + event = tray_open ? QEVENT_BLOCK_TRAY_OPEN : QEVENT_BLOCK_TRAY_CLOSE; + monitor_protocol_event(event, data); + qobject_decref(data); +} + void bdrv_error_mon_event(const BlockDriverState *bdrv, BlockMonEventAction action, int is_read) { @@ -2776,6 +2787,17 @@ int bdrv_eject(BlockDriverState *bs, int eject_flag, int force) ret = 0; } if (ret >= 0) { + if (bs->tray_open != eject_flag) { + if (bs->device_name[0] != '\0') { + /* + * FIXME: raw_eject() calls bdrv_eject(), which makes the + * event be emitted twice. The check above will prevent that + * from happening, * but we need a better way to deal with + * this... + */ + bdrv_eject_mon_event(bs, eject_flag); + } + } bs->tray_open = eject_flag; } diff --git a/monitor.c b/monitor.c index f63cce0..22353b5 100644 --- a/monitor.c +++ b/monitor.c @@ -453,6 +453,12 @@ void monitor_protocol_event(MonitorEvent event, QObject *data) case QEVENT_BLOCK_IO_ERROR: event_name = "BLOCK_IO_ERROR"; break; + case QEVENT_BLOCK_TRAY_OPEN: + event_name = "BLOCK_TRAY_OPEN"; + break; + case QEVENT_BLOCK_TRAY_CLOSE: + event_name = "BLOCK_TRAY_CLOSE"; + break; case QEVENT_RTC_CHANGE: event_name = "RTC_CHANGE"; break; diff --git a/monitor.h b/monitor.h index 4f2d328..fca1e18 100644 --- a/monitor.h +++ b/monitor.h @@ -30,6 +30,8 @@ typedef enum MonitorEvent { QEVENT_VNC_INITIALIZED, QEVENT_VNC_DISCONNECTED, QEVENT_BLOCK_IO_ERROR, + QEVENT_BLOCK_TRAY_OPEN, + QEVENT_BLOCK_TRAY_CLOSE, QEVENT_RTC_CHANGE, QEVENT_WATCHDOG, QEVENT_SPICE_CONNECTED,