[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 05/40] blockdev: Add blockdev-open-tray
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL v2 05/40] blockdev: Add blockdev-open-tray |
Date: |
Tue, 10 Nov 2015 15:09:05 +0100 |
From: Max Reitz <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
blockdev.c | 36 ++++++++++++++++++++++++++++++++++++
qapi/block-core.json | 32 ++++++++++++++++++++++++++++++++
qmp-commands.hx | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 116 insertions(+)
diff --git a/blockdev.c b/blockdev.c
index 97be42f..d01a99e 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2088,6 +2088,42 @@ out:
aio_context_release(aio_context);
}
+void qmp_blockdev_open_tray(const char *device, bool has_force, bool force,
+ Error **errp)
+{
+ BlockBackend *blk;
+ bool locked;
+
+ if (!has_force) {
+ force = false;
+ }
+
+ blk = blk_by_name(device);
+ if (!blk) {
+ error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
+ "Device '%s' not found", device);
+ return;
+ }
+
+ if (!blk_dev_has_removable_media(blk)) {
+ error_setg(errp, "Device '%s' is not removable", device);
+ return;
+ }
+
+ if (blk_dev_is_tray_open(blk)) {
+ return;
+ }
+
+ locked = blk_dev_is_medium_locked(blk);
+ if (locked) {
+ blk_dev_eject_request(blk, force);
+ }
+
+ if (!locked || force) {
+ blk_dev_change_media_cb(blk, false);
+ }
+}
+
/* throttling disk I/O limits */
void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,
int64_t bps_wr,
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 425fdab..b65ab81 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1876,6 +1876,38 @@
##
{ 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } }
+##
+# @blockdev-open-tray:
+#
+# Opens a block device's tray. If there is a block driver state tree inserted
as
+# a medium, it will become inaccessible to the guest (but it will remain
+# associated to the block device, so closing the tray will make it accessible
+# again).
+#
+# If the tray was already open before, this will be a no-op.
+#
+# Once the tray opens, a DEVICE_TRAY_MOVED event is emitted. There are cases in
+# which no such event will be generated, these include:
+# - if the guest has locked the tray, @force is false and the guest does not
+# respond to the eject request
+# - if the BlockBackend denoted by @device does not have a guest device
attached
+# to it
+# - if the guest device does not have an actual tray and is empty, for instance
+# for floppy disk drives
+#
+# @device: block device name
+#
+# @force: #optional if false (the default), an eject request will be sent to
+# the guest if it has locked the tray (and the tray will not be opened
+# immediately); if true, the tray will be opened regardless of whether
+# it is locked
+#
+# Since: 2.5
+##
+{ 'command': 'blockdev-open-tray',
+ 'data': { 'device': 'str',
+ '*force': 'bool' } }
+
##
# @BlockErrorAction
diff --git a/qmp-commands.hx b/qmp-commands.hx
index d7cf0ff..0b796f9 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3936,6 +3936,54 @@ Example (2):
EQMP
{
+ .name = "blockdev-open-tray",
+ .args_type = "device:s,force:b?",
+ .mhandler.cmd_new = qmp_marshal_blockdev_open_tray,
+ },
+
+SQMP
+blockdev-open-tray
+------------------
+
+Opens a block device's tray. If there is a block driver state tree inserted as
a
+medium, it will become inaccessible to the guest (but it will remain associated
+to the block device, so closing the tray will make it accessible again).
+
+If the tray was already open before, this will be a no-op.
+
+Once the tray opens, a DEVICE_TRAY_MOVED event is emitted. There are cases in
+which no such event will be generated, these include:
+- if the guest has locked the tray, @force is false and the guest does not
+ respond to the eject request
+- if the BlockBackend denoted by @device does not have a guest device attached
+ to it
+- if the guest device does not have an actual tray and is empty, for instance
+ for floppy disk drives
+
+Arguments:
+
+- "device": block device name (json-string)
+- "force": if false (the default), an eject request will be sent to the guest
if
+ it has locked the tray (and the tray will not be opened
immediately);
+ if true, the tray will be opened regardless of whether it is locked
+ (json-bool, optional)
+
+Example:
+
+-> { "execute": "blockdev-open-tray",
+ "arguments": { "device": "ide1-cd0" } }
+
+<- { "timestamp": { "seconds": 1418751016,
+ "microseconds": 716996 },
+ "event": "DEVICE_TRAY_MOVED",
+ "data": { "device": "ide1-cd0",
+ "tray-open": true } }
+
+<- { "return": {} }
+
+EQMP
+
+ {
.name = "query-named-block-nodes",
.args_type = "",
.mhandler.cmd_new = qmp_marshal_query_named_block_nodes,
--
1.8.3.1
- [Qemu-devel] [PULL v2 00/40] Block layer patches, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 03/40] block: Make bdrv_states public, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 02/40] block: Add blk_remove_bs(), Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 04/40] block: Add functions for inheriting a BBRS, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 01/40] block: Don't call blk_bs() twice in bdrv_lookup_bs(), Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 05/40] blockdev: Add blockdev-open-tray,
Kevin Wolf <=
- [Qemu-devel] [PULL v2 06/40] blockdev: Add blockdev-close-tray, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 09/40] blockdev: Implement eject with basic operations, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 08/40] blockdev: Add blockdev-insert-medium, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 07/40] blockdev: Add blockdev-remove-medium, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 11/40] block: Inquire tray state before tray-moved events, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 12/40] qmp: Introduce blockdev-change-medium, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 10/40] blockdev: Implement change with basic operations, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 13/40] hmp: Use blockdev-change-medium for change command, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 15/40] hmp: Add read-only-mode option to change command, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 14/40] blockdev: read-only-mode for blockdev-change-medium, Kevin Wolf, 2015/11/10