block: Accept device model name for x-blockdev-remove-medium
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-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>
This commit is contained in:
parent
716df21707
commit
00949babe9
28
blockdev.c
28
blockdev.c
@ -2281,7 +2281,7 @@ void qmp_eject(const char *device, bool has_force, bool force, Error **errp)
|
|||||||
}
|
}
|
||||||
error_free(local_err);
|
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,
|
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);
|
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;
|
BlockBackend *blk;
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs;
|
||||||
AioContext *aio_context;
|
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) {
|
if (!blk) {
|
||||||
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
|
||||||
"Device '%s' not found", device);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For BBs without a device, we can exchange the BDS tree at will */
|
/* 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);
|
error_setg(errp, "Device '%s' is not removable", device ?: id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_device && blk_dev_has_tray(blk) && !blk_dev_is_tray_open(blk)) {
|
if (has_attached_device && blk_dev_has_tray(blk) &&
|
||||||
error_setg(errp, "Tray of device '%s' is not open", device);
|
!blk_dev_is_tray_open(blk))
|
||||||
|
{
|
||||||
|
error_setg(errp, "Tray of device '%s' is not open", device ?: id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2604,7 +2608,7 @@ void qmp_blockdev_change_medium(const char *device, const char *filename,
|
|||||||
error_free(err);
|
error_free(err);
|
||||||
err = NULL;
|
err = NULL;
|
||||||
|
|
||||||
qmp_x_blockdev_remove_medium(device, &err);
|
qmp_x_blockdev_remove_medium(true, device, false, NULL, errp);
|
||||||
if (err) {
|
if (err) {
|
||||||
error_propagate(errp, err);
|
error_propagate(errp, err);
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -3290,18 +3290,20 @@ Stay away from it unless you want to help with its development.
|
|||||||
|
|
||||||
Arguments:
|
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:
|
Example:
|
||||||
|
|
||||||
-> { "execute": "x-blockdev-remove-medium",
|
-> { "execute": "x-blockdev-remove-medium",
|
||||||
"arguments": { "device": "ide1-cd0" } }
|
"arguments": { "id": "ide0-1-0" } }
|
||||||
|
|
||||||
<- { "error": { "class": "GenericError",
|
<- { "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",
|
-> { "execute": "blockdev-open-tray",
|
||||||
"arguments": { "device": "ide1-cd0" } }
|
"arguments": { "id": "ide0-1-0" } }
|
||||||
|
|
||||||
<- { "timestamp": { "seconds": 1418751627,
|
<- { "timestamp": { "seconds": 1418751627,
|
||||||
"microseconds": 549958 },
|
"microseconds": 549958 },
|
||||||
@ -3312,7 +3314,7 @@ Example:
|
|||||||
<- { "return": {} }
|
<- { "return": {} }
|
||||||
|
|
||||||
-> { "execute": "x-blockdev-remove-medium",
|
-> { "execute": "x-blockdev-remove-medium",
|
||||||
"arguments": { "device": "ide1-cd0" } }
|
"arguments": { "device": "ide0-1-0" } }
|
||||||
|
|
||||||
<- { "return": {} }
|
<- { "return": {} }
|
||||||
|
|
||||||
|
@ -2410,12 +2410,15 @@
|
|||||||
# This command is still a work in progress and is considered experimental.
|
# This command is still a work in progress and is considered experimental.
|
||||||
# Stay away from it unless you want to help with its development.
|
# 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
|
# Since: 2.5
|
||||||
##
|
##
|
||||||
{ 'command': 'x-blockdev-remove-medium',
|
{ 'command': 'x-blockdev-remove-medium',
|
||||||
'data': { 'device': 'str' } }
|
'data': { '*device': 'str',
|
||||||
|
'*id': 'str' } }
|
||||||
|
|
||||||
##
|
##
|
||||||
# @x-blockdev-insert-medium:
|
# @x-blockdev-insert-medium:
|
||||||
|
Loading…
Reference in New Issue
Block a user