From: Hanna Reitz <hreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Hanna Reitz <hreitz@redhat.com>,
Richard Henderson <richard.henderson@linaro.org>,
qemu-devel@nongnu.org
Subject: [PULL 01/14] block: add 'force' parameter to 'blockdev-change-medium' command
Date: Mon, 25 Apr 2022 16:08:08 +0200 [thread overview]
Message-ID: <20220425140821.957511-2-hreitz@redhat.com> (raw)
In-Reply-To: <20220425140821.957511-1-hreitz@redhat.com>
From: "Denis V. Lunev" <den@openvz.org>
'blockdev-change-medium' is a convinient wrapper for the following
sequence of commands:
* blockdev-open-tray
* blockdev-remove-medium
* blockdev-insert-medium
* blockdev-close-tray
and should be used f.e. to change ISO image inside the CD-ROM tray.
Though the guest could lock the tray and some linux guests like
CentOS 8.5 actually does that. In this case the execution if this
command results in the error like the following:
Device 'scsi0-0-1-0' is locked and force was not specified,
wait for tray to open and try again.
This situation is could be resolved 'blockdev-open-tray' by passing
flag 'force' inside. Thus is seems reasonable to add the same
capability for 'blockdev-change-medium' too.
Signed-off-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
Acked-by: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
CC: Hanna Reitz <hreitz@redhat.com>
CC: Eric Blake <eblake@redhat.com>
CC: Markus Armbruster <armbru@redhat.com>
Message-Id: <20220412221846.280723-1-den@openvz.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
---
qapi/block.json | 6 ++++++
block/qapi-sysemu.c | 3 ++-
monitor/hmp-cmds.c | 4 +++-
hmp-commands.hx | 11 +++++++----
ui/cocoa.m | 1 +
5 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/qapi/block.json b/qapi/block.json
index 82fcf2c914..3f100d4887 100644
--- a/qapi/block.json
+++ b/qapi/block.json
@@ -326,6 +326,11 @@
# @read-only-mode: change the read-only mode of the device; defaults
# to 'retain'
#
+# @force: if false (the default), an eject request through blockdev-open-tray
+# 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. (since 7.1)
+#
# Features:
# @deprecated: Member @device is deprecated. Use @id instead.
#
@@ -367,6 +372,7 @@
'*id': 'str',
'filename': 'str',
'*format': 'str',
+ '*force': 'bool',
'*read-only-mode': 'BlockdevChangeReadOnlyMode' } }
diff --git a/block/qapi-sysemu.c b/block/qapi-sysemu.c
index 8498402ad4..680c7ee342 100644
--- a/block/qapi-sysemu.c
+++ b/block/qapi-sysemu.c
@@ -318,6 +318,7 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
bool has_id, const char *id,
const char *filename,
bool has_format, const char *format,
+ bool has_force, bool force,
bool has_read_only,
BlockdevChangeReadOnlyMode read_only,
Error **errp)
@@ -380,7 +381,7 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
rc = do_open_tray(has_device ? device : NULL,
has_id ? id : NULL,
- false, &err);
+ force, &err);
if (rc && rc != -ENOSYS) {
error_propagate(errp, err);
goto fail;
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 634968498b..d8b98bed6c 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -1472,6 +1472,7 @@ void hmp_change(Monitor *mon, const QDict *qdict)
const char *target = qdict_get_str(qdict, "target");
const char *arg = qdict_get_try_str(qdict, "arg");
const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
+ bool force = qdict_get_try_bool(qdict, "force", false);
BlockdevChangeReadOnlyMode read_only_mode = 0;
Error *err = NULL;
@@ -1508,7 +1509,8 @@ void hmp_change(Monitor *mon, const QDict *qdict)
}
qmp_blockdev_change_medium(true, device, false, NULL, target,
- !!arg, arg, !!read_only, read_only_mode,
+ !!arg, arg, true, force,
+ !!read_only, read_only_mode,
&err);
}
diff --git a/hmp-commands.hx b/hmp-commands.hx
index dd4006d355..34947d6d20 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -202,9 +202,9 @@ ERST
{
.name = "change",
- .args_type = "device:B,target:F,arg:s?,read-only-mode:s?",
- .params = "device filename [format [read-only-mode]]",
- .help = "change a removable medium, optional format",
+ .args_type = "device:B,force:-f,target:F,arg:s?,read-only-mode:s?",
+ .params = "device [-f] filename [format [read-only-mode]]",
+ .help = "change a removable medium, optional format, use -f to force the operation",
.cmd = hmp_change,
},
@@ -212,11 +212,14 @@ SRST
``change`` *device* *setting*
Change the configuration of a device.
- ``change`` *diskdevice* *filename* [*format* [*read-only-mode*]]
+ ``change`` *diskdevice* [-f] *filename* [*format* [*read-only-mode*]]
Change the medium for a removable disk device to point to *filename*. eg::
(qemu) change ide1-cd0 /path/to/some.iso
+ ``-f``
+ forces the operation even if the guest has locked the tray.
+
*format* is optional.
*read-only-mode* may be used to change the read-only status of the device.
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 68bff4ff37..09a62817f2 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -1531,6 +1531,7 @@ - (void)changeDeviceMedia:(id)sender
[file cStringUsingEncoding:
NSASCIIStringEncoding],
true, "raw",
+ true, false,
false, 0,
&err);
});
--
2.35.1
next prev parent reply other threads:[~2022-04-25 14:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-25 14:08 [PULL 00/14] Block patches Hanna Reitz
2022-04-25 14:08 ` Hanna Reitz [this message]
2022-04-25 14:08 ` [PULL 02/14] iotests: replace calls to log(qemu_io(...)) with qemu_io_log() Hanna Reitz
2022-04-25 14:08 ` [PULL 03/14] iotests/163: Fix broken qemu-io invocation Hanna Reitz
2022-04-25 14:08 ` [PULL 04/14] iotests: Don't check qemu_io() output for specific error strings Hanna Reitz
2022-04-25 14:08 ` [PULL 05/14] iotests/040: Don't check image pattern on zero-length image Hanna Reitz
2022-04-25 14:08 ` [PULL 06/14] iotests/040: Fix TestCommitWithFilters test Hanna Reitz
2022-04-25 14:08 ` [PULL 07/14] iotests: create generic qemu_tool() function Hanna Reitz
2022-04-25 14:08 ` [PULL 08/14] iotests: rebase qemu_io() on top of qemu_tool() Hanna Reitz
2022-04-25 14:08 ` [PULL 09/14] iotests/migration-permissions: use assertRaises() for qemu_io() negative test Hanna Reitz
2022-04-25 14:08 ` [PULL 10/14] iotests/image-fleecing: switch to qemu_io() Hanna Reitz
2022-04-25 14:08 ` [PULL 11/14] iotests: remove qemu_io_pipe_and_status() Hanna Reitz
2022-04-25 14:08 ` [PULL 12/14] iotests: remove qemu_io_silent() and qemu_io_silent_check() Hanna Reitz
2022-04-25 14:08 ` [PULL 13/14] iotests: make qemu_io_log() check return codes by default Hanna Reitz
2022-04-25 14:08 ` [PULL 14/14] iotests/108: Fix when missing user_allow_other Hanna Reitz
2022-04-25 23:32 ` [PULL 00/14] Block patches Richard Henderson
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=20220425140821.957511-2-hreitz@redhat.com \
--to=hreitz@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).