From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, eblake@redhat.com, armbru@redhat.com
Subject: [Qemu-devel] [PATCH 5/5] qmp: add the BLOCK_MEDIUM_CHANGED event
Date: Tue, 7 Feb 2012 16:09:49 -0200 [thread overview]
Message-ID: <1328638189-9534-6-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1328638189-9534-1-git-send-email-lcapitulino@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
QMP/qmp-events.txt | 17 +++++++++++++++++
block.c | 12 ++++++++++++
monitor.c | 3 +++
monitor.h | 1 +
4 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
index ab32e62..a1815b5 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_CHANGED
+--------------------
+
+Emitted when a medium is either inserted or removed from a drive. This should
+happen as a result of the 'eject' and 'change' commands.
+
+Data:
+
+- "device": device name (json-string)
+- "medium-inserted": true if a medium has been inserted, false if it has been
+ removed from the drive
+
+{ "event": "BLOCK_MEDIUM_CHANGED",
+ "data": { "device": "ide1-cd1",
+ "medium-inserted": true },
+ "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
+
GUEST_MEDIUM_EJECTED
--------------------
diff --git a/block.c b/block.c
index 7f5b56d..1d40f82 100644
--- a/block.c
+++ b/block.c
@@ -941,10 +941,22 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
}
}
+static void bdrv_emit_qmp_medium_changed_event(BlockDriverState *bs, bool load)
+{
+ QObject *data;
+
+ data = qobject_from_jsonf("{ 'device': %s, 'medium-inserted': %i }",
+ bdrv_get_device_name(bs), load);
+ monitor_protocol_event(QEVENT_BLOCK_MEDIUM_CHANGED, 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) {
bs->dev_ops->change_media_cb(bs->dev_opaque, load);
+ bdrv_emit_qmp_medium_changed_event(bs, load);
}
}
diff --git a/monitor.c b/monitor.c
index 48b1dea..8701ec1 100644
--- a/monitor.c
+++ b/monitor.c
@@ -488,6 +488,9 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)
case QEVENT_GUEST_MEDIUM_EJECTED:
event_name = "GUEST_MEDIUM_EJECTED";
break;
+ case QEVENT_BLOCK_MEDIUM_CHANGED:
+ event_name = "BLOCK_MEDIUM_CHANGED";
+ break;
default:
abort();
break;
diff --git a/monitor.h b/monitor.h
index 06be7bb..4f9e6f7 100644
--- a/monitor.h
+++ b/monitor.h
@@ -39,6 +39,7 @@ typedef enum MonitorEvent {
QEVENT_BLOCK_JOB_COMPLETED,
QEVENT_BLOCK_JOB_CANCELLED,
QEVENT_GUEST_MEDIUM_EJECTED,
+ QEVENT_BLOCK_MEDIUM_CHANGED,
QEVENT_MAX,
} MonitorEvent;
--
1.7.9.111.gf3fb0.dirty
next prev parent reply other threads:[~2012-02-07 18:10 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-07 18:09 [Qemu-devel] [RFC 0/5]: QMP: Introduce GUEST_MEDIUM_EJECT & BLOCK_MEDIUM_CHANGED Luiz Capitulino
2012-02-07 18:09 ` [Qemu-devel] [PATCH 1/5] block: Rename bdrv_mon_event() & BlockMonEventAction Luiz Capitulino
2012-02-07 18:09 ` [Qemu-devel] [PATCH 2/5] block: bdrv_eject(): Make eject_flag a real bool Luiz Capitulino
2012-02-07 18:09 ` [Qemu-devel] [PATCH 3/5] block: bdrv_eject(): Add tray_changed parameter Luiz Capitulino
2012-02-07 18:09 ` [Qemu-devel] [PATCH 4/5] qmp: add the GUEST_MEDIUM_EJECTED event Luiz Capitulino
2012-02-07 18:09 ` Luiz Capitulino [this message]
2012-02-09 15:01 ` [Qemu-devel] [RFC 0/5]: QMP: Introduce GUEST_MEDIUM_EJECT & BLOCK_MEDIUM_CHANGED Markus Armbruster
2012-02-09 16:07 ` Luiz Capitulino
2012-02-10 9:27 ` Markus Armbruster
2012-02-10 17:20 ` Luiz Capitulino
2012-02-10 7:58 ` Paolo Bonzini
2012-02-10 9:36 ` Markus Armbruster
2012-02-10 17:04 ` Luiz Capitulino
2012-02-10 17:55 ` Kevin Wolf
2012-02-10 19:39 ` Paolo Bonzini
2012-02-10 20:47 ` 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=1328638189-9534-6-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@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).