[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 06/10] block: Accept device model name for x-blockde
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH 06/10] block: Accept device model name for x-blockdev-remove-medium |
Date: |
Fri, 19 Aug 2016 18:50:31 +0200 |
In order to remove the necessity to use BlockBackend names in the
external API, we want to allow qdev device names in all device related
commands.
This converts x-blockdev-remove-medium to accept a qdev device name.
Signed-off-by: Kevin Wolf <address@hidden>
---
blockdev.c | 23 +++++++++++++----------
qapi/block-core.json | 7 +++++--
qmp-commands.hx | 6 ++++--
3 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 645c639..77cf8db 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2279,7 +2279,7 @@ void qmp_eject(const char *device, bool has_force, bool
force, Error **errp)
}
error_free(local_err);
- qmp_x_blockdev_remove_medium(device, errp);
+ qmp_x_blockdev_remove_medium(true, device, false, NULL, errp);
}
void qmp_block_passwd(bool has_device, const char *device,
@@ -2412,29 +2412,32 @@ void qmp_blockdev_close_tray(bool has_device, const
char *device,
blk_dev_change_media_cb(blk, true);
}
-void qmp_x_blockdev_remove_medium(const char *device, Error **errp)
+void qmp_x_blockdev_remove_medium(bool has_device, const char *device,
+ bool has_id, const char *id, Error **errp)
{
BlockBackend *blk;
BlockDriverState *bs;
AioContext *aio_context;
- bool has_device;
+ bool has_attached_device;
- blk = blk_by_name(device);
+ blk = qmp_get_blk(has_device ? device : NULL,
+ has_id ? id : NULL,
+ errp);
if (!blk) {
- error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
- "Device '%s' not found", device);
return;
}
/* For BBs without a device, we can exchange the BDS tree at will */
- has_device = blk_get_attached_dev(blk);
+ has_attached_device = blk_get_attached_dev(blk);
- if (has_device && !blk_dev_has_removable_media(blk)) {
+ if (has_attached_device && !blk_dev_has_removable_media(blk)) {
error_setg(errp, "Device '%s' is not removable", device);
return;
}
- if (has_device && blk_dev_has_tray(blk) && !blk_dev_is_tray_open(blk)) {
+ if (has_attached_device && blk_dev_has_tray(blk) &&
+ !blk_dev_is_tray_open(blk))
+ {
error_setg(errp, "Tray of device '%s' is not open", device);
return;
}
@@ -2601,7 +2604,7 @@ void qmp_blockdev_change_medium(const char *device, const
char *filename,
error_free(err);
err = NULL;
- qmp_x_blockdev_remove_medium(device, &err);
+ qmp_x_blockdev_remove_medium(true, device, false, NULL, errp);
if (err) {
error_propagate(errp, err);
goto fail;
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 2625bf8..c3177f4 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -2363,12 +2363,15 @@
# This command is still a work in progress and is considered experimental.
# Stay away from it unless you want to help with its development.
#
-# @device: block device name
+# @device: block device name (deprecated, use @id instead)
+#
+# @id: the name or QOM path of the guest device (since: 2.8)
#
# Since: 2.5
##
{ 'command': 'x-blockdev-remove-medium',
- 'data': { 'device': 'str' } }
+ 'data': { '*device': 'str',
+ '*id': 'str' } }
##
# @x-blockdev-insert-medium:
diff --git a/qmp-commands.hx b/qmp-commands.hx
index b3aed7f..6f10cdf 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -4364,7 +4364,7 @@ EQMP
{
.name = "x-blockdev-remove-medium",
- .args_type = "device:s",
+ .args_type = "device:s?,id:s?",
.mhandler.cmd_new = qmp_marshal_x_blockdev_remove_medium,
},
@@ -4382,7 +4382,9 @@ Stay away from it unless you want to help with its
development.
Arguments:
-- "device": block device name (json-string)
+- "device": block device name (deprecated, use @id instead)
+ (json-string, optional)
+- "id": the name or QOM path of the guest device (json-string, optional)
Example:
--
1.8.3.1
- [Qemu-block] [PATCH 00/10] block: Accept qdev IDs in device level QMP commands, Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 01/10] block: Add blk_by_dev(), Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 05/10] block: Accept device model name for x-blockdev-insert-medium, Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 02/10] qdev-monitor: Factor out find_device_state(), Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 06/10] block: Accept device model name for x-blockdev-remove-medium,
Kevin Wolf <=
- [Qemu-block] [PATCH 04/10] block: Accept device model name for blockdev-open/close-tray, Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 03/10] qdev-monitor: Add blk_by_qdev_id(), Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 07/10] block: Accept device model name for eject, Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 10/10] qemu-iotests/118: Test media change with qdev name, Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 08/10] block: Accept device model name for blockdev-change-medium, Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 09/10] block: Accept device model name for block_set_io_throttle, Kevin Wolf, 2016/08/19