From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, eblake@redhat.com,
armbru@redhat.com
Subject: [Qemu-devel] [PATCH 4/4] qmp: add BLOCK_MEDIUM_EJECT event
Date: Wed, 15 Feb 2012 16:42:27 -0200 [thread overview]
Message-ID: <1329331347-11232-5-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1329331347-11232-1-git-send-email-lcapitulino@redhat.com>
It's emitted whenever the tray is moved by the guest or by HMP/QMP
commands.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
QMP/qmp-events.txt | 17 +++++++++++++++++
block.c | 24 ++++++++++++++++++++++++
monitor.c | 3 +++
monitor.h | 1 +
4 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
index 06cb404..c52e7fe 100644
--- a/QMP/qmp-events.txt
+++ b/QMP/qmp-events.txt
@@ -26,6 +26,23 @@ Example:
Note: If action is "stop", a STOP event will eventually follow the
BLOCK_IO_ERROR event.
+BLOCK_MEDIUM_EJECT
+------------------
+
+It's emitted whenever the tray is moved by the guest or by HMP/QMP
+commands.
+
+Data:
+
+- "device": device name (json-string)
+- "ejected": true if the tray has been opened or false if it has been closed
+
+{ "event": "BLOCK_MEDIUM_EJECT",
+ "data": { "device": "ide1-cd0",
+ "ejected": true
+ },
+ "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
+
RESET
-----
diff --git a/block.c b/block.c
index 47f1823..e5e2a5f 100644
--- a/block.c
+++ b/block.c
@@ -970,10 +970,30 @@ void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
qobject_decref(data);
}
+static void bdrv_emit_qmp_eject_event(BlockDriverState *bs, bool ejected)
+{
+ QObject *data;
+
+ data = qobject_from_jsonf("{ 'device': %s, 'ejected': %i }",
+ bdrv_get_device_name(bs), ejected);
+ monitor_protocol_event(QEVENT_BLOCK_MEDIUM_EJECT, data);
+
+ qobject_decref(data);
+}
+
static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
{
if (bs->dev_ops && bs->dev_ops->change_media_cb) {
+ bool tray_was_closed = !bdrv_dev_is_tray_open(bs);
bs->dev_ops->change_media_cb(bs->dev_opaque, load);
+ if (tray_was_closed) {
+ /* tray open */
+ bdrv_emit_qmp_eject_event(bs, true);
+ }
+ if (load) {
+ /* tray close */
+ bdrv_emit_qmp_eject_event(bs, false);
+ }
}
}
@@ -3567,6 +3587,10 @@ void bdrv_eject(BlockDriverState *bs, bool eject_flag, bool tray_changed)
if (drv && drv->bdrv_eject) {
drv->bdrv_eject(bs, eject_flag);
}
+
+ if (tray_changed) {
+ bdrv_emit_qmp_eject_event(bs, eject_flag);
+ }
}
/**
diff --git a/monitor.c b/monitor.c
index aadbdcb..1758f03 100644
--- a/monitor.c
+++ b/monitor.c
@@ -485,6 +485,9 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)
case QEVENT_BLOCK_JOB_CANCELLED:
event_name = "BLOCK_JOB_CANCELLED";
break;
+ case QEVENT_BLOCK_MEDIUM_EJECT:
+ event_name = "BLOCK_MEDIUM_EJECT";
+ break;
default:
abort();
break;
diff --git a/monitor.h b/monitor.h
index b72ea07..a2555e5 100644
--- a/monitor.h
+++ b/monitor.h
@@ -38,6 +38,7 @@ typedef enum MonitorEvent {
QEVENT_SPICE_DISCONNECTED,
QEVENT_BLOCK_JOB_COMPLETED,
QEVENT_BLOCK_JOB_CANCELLED,
+ QEVENT_BLOCK_MEDIUM_EJECT,
QEVENT_MAX,
} MonitorEvent;
--
1.7.9.111.gf3fb0.dirty
next prev parent reply other threads:[~2012-02-15 18:42 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-15 18:42 [Qemu-devel] [PATCH v2 0/4]: QMP: add BLOCK_MEDIUM_EJECT event Luiz Capitulino
2012-02-15 18:42 ` [Qemu-devel] [PATCH 1/4] block: Rename bdrv_mon_event() & BlockMonEventAction Luiz Capitulino
2012-02-15 18:42 ` [Qemu-devel] [PATCH 2/4] block: bdrv_eject(): Make eject_flag a real bool Luiz Capitulino
2012-02-15 18:42 ` [Qemu-devel] [PATCH 3/4] block: bdrv_eject(): Add tray_changed parameter Luiz Capitulino
2012-02-15 18:42 ` Luiz Capitulino [this message]
2012-02-16 9:25 ` [Qemu-devel] [PATCH 4/4] qmp: add BLOCK_MEDIUM_EJECT event Markus Armbruster
2012-02-16 13:14 ` Luiz Capitulino
2012-02-16 13:19 ` Luiz Capitulino
2012-02-16 13:31 ` Kevin Wolf
2012-02-16 14:10 ` Luiz Capitulino
2012-02-17 10:32 ` Paolo Bonzini
2012-02-17 11:03 ` Kevin Wolf
2012-02-17 11:48 ` Markus Armbruster
2012-02-17 12:12 ` Kevin Wolf
2012-02-17 12:43 ` Markus Armbruster
2012-02-16 18:30 ` Markus Armbruster
2012-02-16 19:08 ` Luiz Capitulino
2012-02-17 9:53 ` Kevin Wolf
2012-02-17 10:48 ` Paolo Bonzini
2012-02-17 11:50 ` Markus Armbruster
2012-02-17 11:44 ` Markus Armbruster
2012-02-17 11:56 ` Luiz Capitulino
2012-02-17 10:45 ` Paolo Bonzini
2012-02-17 11:57 ` Markus Armbruster
2012-02-17 10:49 ` [Qemu-devel] [PATCH v2 0/4]: QMP: " Paolo Bonzini
2012-02-17 11:58 ` Luiz Capitulino
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=1329331347-11232-5-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).