From patchwork Fri May 27 19:31:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 97743 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 5F3D4B6F75 for ; Sat, 28 May 2011 05:32:26 +1000 (EST) Received: from localhost ([::1]:50847 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQ2lj-00049S-QA for incoming@patchwork.ozlabs.org; Fri, 27 May 2011 15:32:23 -0400 Received: from eggs.gnu.org ([140.186.70.92]:39192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQ2lV-000448-PD for qemu-devel@nongnu.org; Fri, 27 May 2011 15:32:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QQ2lU-0002JY-SX for qemu-devel@nongnu.org; Fri, 27 May 2011 15:32:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14733) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQ2lU-0002JU-LZ for qemu-devel@nongnu.org; Fri, 27 May 2011 15:32:08 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4RJW7fZ022881 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 27 May 2011 15:32:08 -0400 Received: from localhost (ovpn-113-111.phx2.redhat.com [10.3.113.111]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p4RJW69Z008747; Fri, 27 May 2011 15:32:07 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 27 May 2011 16:31:52 -0300 Message-Id: <1306524712-13050-4-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1306524712-13050-1-git-send-email-lcapitulino@redhat.com> References: <1306524712-13050-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 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] [PATCH 3/3] QMP: Introduce the BLOCK_MEDIA_EJECT event 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 Conforms to the event specification defined in the QMP/qmp-events.txt file. Please, note the following details: o The event should be emitted only by devices which support the eject operation, which currently are: CDROMs (IDE and SCSI) and floppies o Human monitor commands "eject" and "change" also cause the event to be emitted o The event is only emitted when there's a tray transition from closed to opened. To implement this in the human monitor, we only emit the event if the device is removable and a media is present Signed-off-by: Luiz Capitulino --- block.c | 12 ++++++++++++ block.h | 1 + blockdev.c | 5 +++++ monitor.c | 3 +++ monitor.h | 1 + 5 files changed, 22 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index f5014cf..dbe813b 100644 --- a/block.c +++ b/block.c @@ -1656,6 +1656,15 @@ 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); } +void bdrv_eject_mon_event(const BlockDriverState *bdrv) +{ + QObject *data; + + data = qobject_from_jsonf("{ 'device': %s }", bdrv->device_name); + monitor_protocol_event(QEVENT_BLOCK_MEDIA_EJECT, data); + qobject_decref(data); +} + void bdrv_error_mon_event(const BlockDriverState *bdrv, BlockMonEventAction action, int is_read) { @@ -2770,6 +2779,9 @@ int bdrv_eject(BlockDriverState *bs, int eject_flag) ret = 0; } if (ret >= 0) { + if (eject_flag && !bs->tray_open) { + bdrv_eject_mon_event(bs); + } bs->tray_open = eject_flag; } diff --git a/block.h b/block.h index 1f58eab..e4053dd 100644 --- a/block.h +++ b/block.h @@ -50,6 +50,7 @@ typedef enum { BDRV_ACTION_REPORT, BDRV_ACTION_IGNORE, BDRV_ACTION_STOP } BlockMonEventAction; +void bdrv_eject_mon_event(const BlockDriverState *bdrv); void bdrv_error_mon_event(const BlockDriverState *bdrv, BlockMonEventAction action, int is_read); void bdrv_info_print(Monitor *mon, const QObject *data); diff --git a/blockdev.c b/blockdev.c index 6e0eb83..5fd0043 100644 --- a/blockdev.c +++ b/blockdev.c @@ -661,6 +661,11 @@ static int eject_device(Monitor *mon, BlockDriverState *bs, int force) return -1; } } + + if (bdrv_is_removable(bs) && bdrv_is_inserted(bs)) { + bdrv_eject_mon_event(bs); + } + bdrv_close(bs); return 0; } diff --git a/monitor.c b/monitor.c index f63cce0..4a81467 100644 --- a/monitor.c +++ b/monitor.c @@ -450,6 +450,9 @@ void monitor_protocol_event(MonitorEvent event, QObject *data) case QEVENT_VNC_DISCONNECTED: event_name = "VNC_DISCONNECTED"; break; + case QEVENT_BLOCK_MEDIA_EJECT: + event_name = "BLOCK_MEDIA_EJECT"; + break; case QEVENT_BLOCK_IO_ERROR: event_name = "BLOCK_IO_ERROR"; break; diff --git a/monitor.h b/monitor.h index 4f2d328..7a04137 100644 --- a/monitor.h +++ b/monitor.h @@ -29,6 +29,7 @@ typedef enum MonitorEvent { QEVENT_VNC_CONNECTED, QEVENT_VNC_INITIALIZED, QEVENT_VNC_DISCONNECTED, + QEVENT_BLOCK_MEDIA_EJECT, QEVENT_BLOCK_IO_ERROR, QEVENT_RTC_CHANGE, QEVENT_WATCHDOG,