From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, eblake@redhat.com, mreitz@redhat.com,
jsnow@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v3 06/10] block: Accept device model name for x-blockdev-remove-medium
Date: Tue, 20 Sep 2016 13:38:45 +0200 [thread overview]
Message-ID: <1474371529-24466-7-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1474371529-24466-1-git-send-email-kwolf@redhat.com>
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.
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 <kwolf@redhat.com>
---
blockdev.c | 28 ++++++++++++++++------------
docs/qmp-commands.txt | 12 +++++++-----
qapi/block-core.json | 7 +++++--
3 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 0eb173d..a007b22 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2281,7 +2281,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,
@@ -2415,30 +2415,34 @@ 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);
+ device = has_device ? device : NULL;
+ id = has_id ? id : NULL;
+
+ blk = qmp_get_blk(device, id, 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)) {
- error_setg(errp, "Device '%s' is not removable", device);
+ if (has_attached_device && !blk_dev_has_removable_media(blk)) {
+ error_setg(errp, "Device '%s' is not removable", device ?: id);
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);
+ 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 ?: id);
return;
}
@@ -2604,7 +2608,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/docs/qmp-commands.txt b/docs/qmp-commands.txt
index ebb65e0..e77bf2f 100644
--- a/docs/qmp-commands.txt
+++ b/docs/qmp-commands.txt
@@ -3290,18 +3290,20 @@ 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:
-> { "execute": "x-blockdev-remove-medium",
- "arguments": { "device": "ide1-cd0" } }
+ "arguments": { "id": "ide0-1-0" } }
<- { "error": { "class": "GenericError",
- "desc": "Tray of device 'ide1-cd0' is not open" } }
+ "desc": "Tray of device 'ide0-1-0' is not open" } }
-> { "execute": "blockdev-open-tray",
- "arguments": { "device": "ide1-cd0" } }
+ "arguments": { "id": "ide0-1-0" } }
<- { "timestamp": { "seconds": 1418751627,
"microseconds": 549958 },
@@ -3312,7 +3314,7 @@ Example:
<- { "return": {} }
-> { "execute": "x-blockdev-remove-medium",
- "arguments": { "device": "ide1-cd0" } }
+ "arguments": { "device": "ide0-1-0" } }
<- { "return": {} }
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 6ac6809..e370366 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -2410,12 +2410,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: #optional Block device name (deprecated, use @id instead)
+#
+# @id: #optional 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:
--
1.8.3.1
next prev parent reply other threads:[~2016-09-20 11:39 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-20 11:38 [Qemu-devel] [PATCH v3 00/10] block: Accept qdev IDs in device level QMP commands Kevin Wolf
2016-09-20 11:38 ` [Qemu-devel] [PATCH v3 01/10] block: Add blk_by_dev() Kevin Wolf
2016-09-20 11:38 ` [Qemu-devel] [PATCH v3 02/10] qdev-monitor: Factor out find_device_state() Kevin Wolf
2016-09-20 11:38 ` [Qemu-devel] [PATCH v3 03/10] qdev-monitor: Add blk_by_qdev_id() Kevin Wolf
2016-09-20 11:38 ` [Qemu-devel] [PATCH v3 04/10] block: Accept device model name for blockdev-open/close-tray Kevin Wolf
2016-09-20 17:55 ` Eric Blake
2016-09-20 11:38 ` [Qemu-devel] [PATCH v3 05/10] block: Accept device model name for x-blockdev-insert-medium Kevin Wolf
2016-09-20 11:38 ` Kevin Wolf [this message]
2016-09-20 11:38 ` [Qemu-devel] [PATCH v3 07/10] block: Accept device model name for eject Kevin Wolf
2016-09-20 11:38 ` [Qemu-devel] [PATCH v3 08/10] block: Accept device model name for blockdev-change-medium Kevin Wolf
2016-09-20 11:38 ` [Qemu-devel] [PATCH v3 09/10] block: Accept device model name for block_set_io_throttle Kevin Wolf
2016-09-20 11:38 ` [Qemu-devel] [PATCH v3 10/10] qemu-iotests/118: Test media change with qdev name Kevin Wolf
2016-09-20 18:01 ` [Qemu-devel] [PATCH v3 00/10] block: Accept qdev IDs in device level QMP commands Eric Blake
2016-09-21 11:02 ` Kevin Wolf
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=1474371529-24466-7-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=eblake@redhat.com \
--cc=jsnow@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--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).