[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 16/33] block: Accept device model name for x-blockdev
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 16/33] block: Accept device model name for x-blockdev-insert-medium |
Date: |
Thu, 22 Sep 2016 18:29:17 +0200 |
In order to remove the need for BlockBackend names in the external API,
we want to allow qdev device names in all device related commands.
This converts x-blockdev-insert-medium to accept a qdev device name.
As the command is experimental, we can still remove the 'device' option
that uses the BlockBackend name. This requires some test case changes
and is left for another series.
Signed-off-by: Kevin Wolf <address@hidden>
---
blockdev.c | 33 +++++++++++++++++----------------
docs/qmp-commands.txt | 6 ++++--
qapi/block-core.json | 7 +++++--
3 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 046f9c6..0eb173d 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2468,34 +2468,26 @@ out:
aio_context_release(aio_context);
}
-static void qmp_blockdev_insert_anon_medium(const char *device,
+static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
BlockDriverState *bs, Error **errp)
{
- BlockBackend *blk;
bool has_device;
- blk = blk_by_name(device);
- 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);
if (has_device && !blk_dev_has_removable_media(blk)) {
- error_setg(errp, "Device '%s' is not removable", device);
+ error_setg(errp, "Device is not removable");
return;
}
if (has_device && blk_dev_has_tray(blk) && !blk_dev_is_tray_open(blk)) {
- error_setg(errp, "Tray of device '%s' is not open", device);
+ error_setg(errp, "Tray of the device is not open");
return;
}
if (blk_bs(blk)) {
- error_setg(errp, "There already is a medium in device '%s'", device);
+ error_setg(errp, "There already is a medium in the device");
return;
}
@@ -2511,11 +2503,20 @@ static void qmp_blockdev_insert_anon_medium(const char
*device,
}
}
-void qmp_x_blockdev_insert_medium(const char *device, const char *node_name,
- Error **errp)
+void qmp_x_blockdev_insert_medium(bool has_device, const char *device,
+ bool has_id, const char *id,
+ const char *node_name, Error **errp)
{
+ BlockBackend *blk;
BlockDriverState *bs;
+ blk = qmp_get_blk(has_device ? device : NULL,
+ has_id ? id : NULL,
+ errp);
+ if (!blk) {
+ return;
+ }
+
bs = bdrv_find_node(node_name);
if (!bs) {
error_setg(errp, "Node '%s' not found", node_name);
@@ -2528,7 +2529,7 @@ void qmp_x_blockdev_insert_medium(const char *device,
const char *node_name,
return;
}
- qmp_blockdev_insert_anon_medium(device, bs, errp);
+ qmp_blockdev_insert_anon_medium(blk, bs, errp);
}
void qmp_blockdev_change_medium(const char *device, const char *filename,
@@ -2609,7 +2610,7 @@ void qmp_blockdev_change_medium(const char *device, const
char *filename,
goto fail;
}
- qmp_blockdev_insert_anon_medium(device, medium_bs, &err);
+ qmp_blockdev_insert_anon_medium(blk, medium_bs, &err);
if (err) {
error_propagate(errp, err);
goto fail;
diff --git a/docs/qmp-commands.txt b/docs/qmp-commands.txt
index 9e230f5..ebb65e0 100644
--- a/docs/qmp-commands.txt
+++ b/docs/qmp-commands.txt
@@ -3328,7 +3328,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)
- "node-name": root node of the BDS tree to insert into the block device
Example:
@@ -3342,7 +3344,7 @@ Example:
<- { "return": {} }
-> { "execute": "x-blockdev-insert-medium",
- "arguments": { "device": "ide1-cd0",
+ "arguments": { "id": "ide0-1-0",
"node-name": "node0" } }
<- { "return": {} }
diff --git a/qapi/block-core.json b/qapi/block-core.json
index cd7b38a..6ac6809 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -2427,14 +2427,17 @@
# 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: #optional Block device name (deprecated, use @id instead)
+#
+# @id: #optional The name or QOM path of the guest device (since: 2.8)
#
# @node-name: name of a node in the block driver state graph
#
# Since: 2.5
##
{ 'command': 'x-blockdev-insert-medium',
- 'data': { 'device': 'str',
+ 'data': { '*device': 'str',
+ '*id': 'str',
'node-name': 'str'} }
--
1.8.3.1
- [Qemu-block] [PULL 03/33] tests: allow to specify list of formats to test for check-block.sh, (continued)
- [Qemu-block] [PULL 03/33] tests: allow to specify list of formats to test for check-block.sh, Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 04/33] block: Remove bdrv_is_snapshot, Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 07/33] block: Add "read-only" to the options QDict, Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 08/33] block: Don't queue the same BDS twice in bdrv_reopen_queue_child(), Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 09/33] commit: Add 'base' to the reopen queue before 'overlay_bs', Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 10/33] block: rename "read-only" to BDRV_OPT_READ_ONLY, Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 11/33] block: Fix 'since' for compressed Drive/BlockdevBackup, Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 12/33] block: Add blk_by_dev(), Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 13/33] qdev-monitor: Factor out find_device_state(), Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 14/33] qdev-monitor: Add blk_by_qdev_id(), Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 16/33] block: Accept device model name for x-blockdev-insert-medium,
Kevin Wolf <=
- [Qemu-block] [PULL 15/33] block: Accept device model name for blockdev-open/close-tray, Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 17/33] block: Accept device model name for x-blockdev-remove-medium, Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 18/33] block: Accept device model name for eject, Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 19/33] block: Accept device model name for blockdev-change-medium, Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 21/33] qemu-iotests/118: Test media change with qdev name, Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 22/33] qemu-iotests/041: Avoid blockdev-add with id, Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 23/33] qemu-iotests/067: Avoid blockdev-add with id, Kevin Wolf, 2016/09/22
- [Qemu-block] [PULL 25/33] qemu-iotests/081: Avoid blockdev-add with id, Kevin Wolf, 2016/09/22