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 v2 04/10] block: Accept device model name for blockdev-open/close-tray
Date: Mon, 19 Sep 2016 18:54:51 +0200 [thread overview]
Message-ID: <1474304097-5790-5-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1474304097-5790-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 blockdev-open/close-tray to accept a qdev device name.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
blockdev.c | 61 +++++++++++++++++++++++++++++++++++++++-------------
qapi/block-core.json | 14 ++++++++----
qmp-commands.hx | 16 ++++++++------
3 files changed, 66 insertions(+), 25 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index fb207cd..046f9c6 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -56,7 +56,8 @@
static QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states =
QTAILQ_HEAD_INITIALIZER(monitor_bdrv_states);
-static int do_open_tray(const char *device, bool force, Error **errp);
+static int do_open_tray(const char *blk_name, const char *qdev_id,
+ bool force, Error **errp);
static const char *const if_name[IF_COUNT] = {
[IF_NONE] = "none",
@@ -1198,6 +1199,29 @@ static BlockDriverState *qmp_get_root_bs(const char *name, Error **errp)
return bs;
}
+static BlockBackend *qmp_get_blk(const char *blk_name, const char *qdev_id,
+ Error **errp)
+{
+ BlockBackend *blk;
+
+ if (!blk_name == !qdev_id) {
+ error_setg(errp, "Need exactly one of 'device' and 'id'");
+ return NULL;
+ }
+
+ if (qdev_id) {
+ blk = blk_by_qdev_id(qdev_id, errp);
+ } else {
+ blk = blk_by_name(blk_name);
+ if (blk == NULL) {
+ error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
+ "Device '%s' not found", blk_name);
+ }
+ }
+
+ return blk;
+}
+
void hmp_commit(Monitor *mon, const QDict *qdict)
{
const char *device = qdict_get_str(qdict, "device");
@@ -2250,7 +2274,7 @@ void qmp_eject(const char *device, bool has_force, bool force, Error **errp)
force = false;
}
- rc = do_open_tray(device, force, &local_err);
+ rc = do_open_tray(device, NULL, force, &local_err);
if (rc && rc != -ENOSYS) {
error_propagate(errp, local_err);
return;
@@ -2295,15 +2319,15 @@ void qmp_block_passwd(bool has_device, const char *device,
* If the guest was asked to open the tray, return -EINPROGRESS.
* Else, return 0.
*/
-static int do_open_tray(const char *device, bool force, Error **errp)
+static int do_open_tray(const char *blk_name, const char *qdev_id,
+ bool force, Error **errp)
{
BlockBackend *blk;
+ const char *device = qdev_id ?: blk_name;
bool locked;
- blk = blk_by_name(device);
+ blk = qmp_get_blk(blk_name, qdev_id, errp);
if (!blk) {
- error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
- "Device '%s' not found", device);
return -ENODEV;
}
@@ -2339,7 +2363,9 @@ static int do_open_tray(const char *device, bool force, Error **errp)
return 0;
}
-void qmp_blockdev_open_tray(const char *device, bool has_force, bool force,
+void qmp_blockdev_open_tray(bool has_device, const char *device,
+ bool has_id, const char *id,
+ bool has_force, bool force,
Error **errp)
{
Error *local_err = NULL;
@@ -2348,7 +2374,9 @@ void qmp_blockdev_open_tray(const char *device, bool has_force, bool force,
if (!has_force) {
force = false;
}
- rc = do_open_tray(device, force, &local_err);
+ rc = do_open_tray(has_device ? device : NULL,
+ has_id ? id : NULL,
+ force, &local_err);
if (rc && rc != -ENOSYS && rc != -EINPROGRESS) {
error_propagate(errp, local_err);
return;
@@ -2356,19 +2384,22 @@ void qmp_blockdev_open_tray(const char *device, bool has_force, bool force,
error_free(local_err);
}
-void qmp_blockdev_close_tray(const char *device, Error **errp)
+void qmp_blockdev_close_tray(bool has_device, const char *device,
+ bool has_id, const char *id,
+ Error **errp)
{
BlockBackend *blk;
- 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;
}
if (!blk_dev_has_removable_media(blk)) {
- error_setg(errp, "Device '%s' is not removable", device);
+ error_setg(errp, "Device '%s' is not removable", device ?: id);
return;
}
@@ -2564,7 +2595,7 @@ void qmp_blockdev_change_medium(const char *device, const char *filename,
goto fail;
}
- rc = do_open_tray(device, false, &err);
+ rc = do_open_tray(device, NULL, false, &err);
if (rc && rc != -ENOSYS) {
error_propagate(errp, err);
goto fail;
@@ -2586,7 +2617,7 @@ void qmp_blockdev_change_medium(const char *device, const char *filename,
blk_apply_root_state(blk, medium_bs);
- qmp_blockdev_close_tray(device, errp);
+ qmp_blockdev_close_tray(true, device, false, NULL, errp);
fail:
/* If the medium has been inserted, the device has its own reference, so
diff --git a/qapi/block-core.json b/qapi/block-core.json
index eb0a7d5a..cd7b38a 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -2363,7 +2363,9 @@
# to it
# - if the guest device does not have an actual tray
#
-# @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)
#
# @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
@@ -2373,7 +2375,8 @@
# Since: 2.5
##
{ 'command': 'blockdev-open-tray',
- 'data': { 'device': 'str',
+ 'data': { '*device': 'str',
+ '*id': 'str',
'*force': 'bool' } }
##
@@ -2385,12 +2388,15 @@
#
# If the tray was already closed before, this will be a no-op.
#
-# @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': 'blockdev-close-tray',
- 'data': { 'device': 'str' } }
+ 'data': { '*device': 'str',
+ '*id': 'str' } }
##
# @x-blockdev-remove-medium:
diff --git a/qmp-commands.hx b/qmp-commands.hx
index e6c9193..1643891 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -4295,7 +4295,7 @@ EQMP
{
.name = "blockdev-open-tray",
- .args_type = "device:s,force:b?",
+ .args_type = "device:s?,id:s?,force:b?",
.mhandler.cmd_new = qmp_marshal_blockdev_open_tray,
},
@@ -4320,7 +4320,9 @@ which no such event will be generated, these include:
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)
- "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
@@ -4329,7 +4331,7 @@ Arguments:
Example:
-> { "execute": "blockdev-open-tray",
- "arguments": { "device": "ide1-cd0" } }
+ "arguments": { "id": "ide0-1-0" } }
<- { "timestamp": { "seconds": 1418751016,
"microseconds": 716996 },
@@ -4343,7 +4345,7 @@ EQMP
{
.name = "blockdev-close-tray",
- .args_type = "device:s",
+ .args_type = "device:s?,id:s?",
.mhandler.cmd_new = qmp_marshal_blockdev_close_tray,
},
@@ -4359,12 +4361,14 @@ If the tray was already closed before, this will be a no-op.
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": "blockdev-close-tray",
- "arguments": { "device": "ide1-cd0" } }
+ "arguments": { "id": "ide0-1-0" } }
<- { "timestamp": { "seconds": 1418751345,
"microseconds": 272147 },
--
1.8.3.1
next prev parent reply other threads:[~2016-09-19 16:55 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-19 16:54 [Qemu-devel] [PATCH v2 00/10] block: Accept qdev IDs in device level QMP commands Kevin Wolf
2016-09-19 16:54 ` [Qemu-devel] [PATCH v2 01/10] block: Add blk_by_dev() Kevin Wolf
2016-09-19 16:54 ` [Qemu-devel] [PATCH v2 02/10] qdev-monitor: Factor out find_device_state() Kevin Wolf
2016-09-19 16:54 ` [Qemu-devel] [PATCH v2 03/10] qdev-monitor: Add blk_by_qdev_id() Kevin Wolf
2016-09-19 16:54 ` Kevin Wolf [this message]
2016-09-19 19:28 ` [Qemu-devel] [PATCH v2 04/10] block: Accept device model name for blockdev-open/close-tray Eric Blake
2016-09-20 11:05 ` Kevin Wolf
2016-09-19 16:54 ` [Qemu-devel] [PATCH v2 05/10] block: Accept device model name for x-blockdev-insert-medium Kevin Wolf
2016-09-19 16:54 ` [Qemu-devel] [PATCH v2 06/10] block: Accept device model name for x-blockdev-remove-medium Kevin Wolf
2016-09-19 19:32 ` Eric Blake
2016-09-19 16:54 ` [Qemu-devel] [PATCH v2 07/10] block: Accept device model name for eject Kevin Wolf
2016-09-19 19:33 ` Eric Blake
2016-09-19 16:54 ` [Qemu-devel] [PATCH v2 08/10] block: Accept device model name for blockdev-change-medium Kevin Wolf
2016-09-19 19:34 ` Eric Blake
2016-09-19 16:54 ` [Qemu-devel] [PATCH v2 09/10] block: Accept device model name for block_set_io_throttle Kevin Wolf
2016-09-19 19:35 ` Eric Blake
2016-09-19 16:54 ` [Qemu-devel] [PATCH v2 10/10] qemu-iotests/118: Test media change with qdev name Kevin Wolf
2016-09-19 19:38 ` Eric Blake
2016-09-19 19:15 ` [Qemu-devel] [PATCH v2 00/10] block: Accept qdev IDs in device level QMP commands no-reply
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=1474304097-5790-5-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).