From: Joelle van Dyne <j@getutm.app>
To: qemu-devel@nongnu.org
Cc: "Joelle van Dyne" <j@getutm.app>, "Kevin Wolf" <kwolf@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>,
"Eric Blake" <eblake@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Akihiko Odaki" <akihiko.odaki@daynix.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
qemu-block@nongnu.org (open list:Block layer core)
Subject: [PATCH] block: support locking on change medium
Date: Sun, 8 Sep 2024 18:58:47 -0700 [thread overview]
Message-ID: <20240909015847.40377-1-j@getutm.app> (raw)
New optional argument for 'blockdev-change-medium' QAPI command to allow
the caller to specify if they wish to enable file locking.
Signed-off-by: Joelle van Dyne <j@getutm.app>
---
qapi/block.json | 23 ++++++++++++++++++++++-
block/monitor/block-hmp-cmds.c | 2 +-
block/qapi-sysemu.c | 22 ++++++++++++++++++++++
ui/cocoa.m | 1 +
4 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/qapi/block.json b/qapi/block.json
index e66666f5c6..35e8e2e191 100644
--- a/qapi/block.json
+++ b/qapi/block.json
@@ -309,6 +309,23 @@
{ 'enum': 'BlockdevChangeReadOnlyMode',
'data': ['retain', 'read-only', 'read-write'] }
+##
+# @BlockdevChangeFileLockingMode:
+#
+# Specifies the new locking mode of a file image passed to the
+# @blockdev-change-medium command.
+#
+# @auto: Use locking if API is available
+#
+# @off: Disable file image locking
+#
+# @on: Enable file image locking
+#
+# Since: 9.2
+##
+{ 'enum': 'BlockdevChangeFileLockingMode',
+ 'data': ['auto', 'off', 'on'] }
+
##
# @blockdev-change-medium:
#
@@ -330,6 +347,9 @@
# @read-only-mode: change the read-only mode of the device; defaults
# to 'retain'
#
+# @file-locking-mode: change the locking mode of the file image; defaults
+# to 'auto' (since: 9.2)
+#
# @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,
@@ -378,7 +398,8 @@
'filename': 'str',
'*format': 'str',
'*force': 'bool',
- '*read-only-mode': 'BlockdevChangeReadOnlyMode' } }
+ '*read-only-mode': 'BlockdevChangeReadOnlyMode',
+ '*file-locking-mode': 'BlockdevChangeFileLockingMode' } }
##
# @DEVICE_TRAY_MOVED:
diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
index bdf2eb50b6..ff64020a80 100644
--- a/block/monitor/block-hmp-cmds.c
+++ b/block/monitor/block-hmp-cmds.c
@@ -1007,5 +1007,5 @@ void hmp_change_medium(Monitor *mon, const char *device, const char *target,
}
qmp_blockdev_change_medium(device, NULL, target, arg, true, force,
- !!read_only, read_only_mode, errp);
+ !!read_only, read_only_mode, false, 0, errp);
}
diff --git a/block/qapi-sysemu.c b/block/qapi-sysemu.c
index e4282631d2..8064bdfb3a 100644
--- a/block/qapi-sysemu.c
+++ b/block/qapi-sysemu.c
@@ -311,6 +311,8 @@ void qmp_blockdev_change_medium(const char *device,
bool has_force, bool force,
bool has_read_only,
BlockdevChangeReadOnlyMode read_only,
+ bool has_file_locking_mode,
+ BlockdevChangeFileLockingMode file_locking_mode,
Error **errp)
{
BlockBackend *blk;
@@ -362,6 +364,26 @@ void qmp_blockdev_change_medium(const char *device,
qdict_put_str(options, "driver", format);
}
+ if (!has_file_locking_mode) {
+ file_locking_mode = BLOCKDEV_CHANGE_FILE_LOCKING_MODE_AUTO;
+ }
+
+ switch (file_locking_mode) {
+ case BLOCKDEV_CHANGE_FILE_LOCKING_MODE_AUTO:
+ break;
+
+ case BLOCKDEV_CHANGE_FILE_LOCKING_MODE_OFF:
+ qdict_put_str(options, "file.locking", "off");
+ break;
+
+ case BLOCKDEV_CHANGE_FILE_LOCKING_MODE_ON:
+ qdict_put_str(options, "file.locking", "on");
+ break;
+
+ default:
+ abort();
+ }
+
medium_bs = bdrv_open(filename, NULL, options, bdrv_flags, errp);
if (!medium_bs) {
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 4c2dd33532..6e73c6e13e 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -1611,6 +1611,7 @@ - (void)changeDeviceMedia:(id)sender
"raw",
true, false,
false, 0,
+ false, 0,
&err);
});
handleAnyDeviceErrors(err);
--
2.41.0
next reply other threads:[~2024-09-09 1:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-09 1:58 Joelle van Dyne [this message]
2024-09-09 7:36 ` [PATCH] block: support locking on change medium Akihiko Odaki
2024-09-09 14:18 ` Joelle van Dyne
2024-09-10 4:24 ` Akihiko Odaki
2024-09-09 9:56 ` Kevin Wolf
2024-09-09 14:25 ` Joelle van Dyne
2024-09-09 15:42 ` 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=20240909015847.40377-1-j@getutm.app \
--to=j@getutm.app \
--cc=akihiko.odaki@daynix.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=hreitz@redhat.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--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).