Skip to contentSkip to conversation

blockdev: BlockBackend and media

PATCH Superseded Max Reitz 2 participants 3 messages Nov 6, 2015 – Nov 10, 2015

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

v9 cover blockdev: BlockBackend and media

Patch 11 of the last series broke the OS X build due to ui/cocoa.m directly referencing qmp_change_blockdev() (which was an internal function not directly mapped to any QMP command before, now it becomes an "external" function and is renamed qmp_blockdev_change_medium()). This v9 consists only of that patch, because the rest is completely unchanged from v8.

Unfortunately, neither am I rich enough nor do I have the immediate intention of buying Apple hardware any time soon anyway, so I have no way of verifying that this changed version builds on OS X. I would appreciate help with that.

Oh, and if anybody ever asks me again why it might be a bad idea to put management code into the GUI layer of one specific operating system...

git-backport-diff against v8:

Key:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively

001/15:[----] [--] 'block: Add blk_remove_bs()' 002/15:[----] [--] 'block: Make bdrv_states public' 003/15:[----] [--] 'block: Add functions for inheriting a BBRS' 004/15:[----] [--] 'blockdev: Add blockdev-open-tray' 005/15:[----] [--] 'blockdev: Add blockdev-close-tray' 006/15:[----] [--] 'blockdev: Add blockdev-remove-medium' 007/15:[----] [--] 'blockdev: Add blockdev-insert-medium' 008/15:[----] [--] 'blockdev: Implement eject with basic operations' 009/15:[----] [--] 'blockdev: Implement change with basic operations' 010/15:[----] [--] 'block: Inquire tray state before tray-moved events' 011/15:[0010] [FC] 'qmp: Introduce blockdev-change-medium' 012/15:[----] [--] 'hmp: Use blockdev-change-medium for change command' 013/15:[----] [--] 'blockdev: read-only-mode for blockdev-change-medium' 014/15:[----] [--] 'hmp: Add read-only-mode option to change command' 015/15:[----] [--] 'iotests: Add test for change-related QMP commands'

Max Reitz (15):
block: Add blk_remove_bs()
block: Make bdrv_states public
block: Add functions for inheriting a BBRS
blockdev: Add blockdev-open-tray
blockdev: Add blockdev-close-tray
blockdev: Add blockdev-remove-medium
blockdev: Add blockdev-insert-medium
blockdev: Implement eject with basic operations
blockdev: Implement change with basic operations
block: Inquire tray state before tray-moved events
qmp: Introduce blockdev-change-medium
hmp: Use blockdev-change-medium for change command
blockdev: read-only-mode for blockdev-change-medium
hmp: Add read-only-mode option to change command
iotests: Add test for change-related QMP commands

 block.c                        |   3 +-
 block/block-backend.c          |  56 +++-
 blockdev.c                     | 286 ++++++++++++----
 hmp-commands.hx                |  20 +-
 hmp.c                          |  47 ++-
 include/block/block_int.h      |   2 +
 include/sysemu/block-backend.h |   3 +
 include/sysemu/blockdev.h      |   2 -
 qapi-schema.json               |   6 +-
 qapi/block-core.json           | 126 ++++++++
 qmp-commands.hx                | 218 +++++++++++++
 qmp.c                          |   3 +-
 tests/qemu-iotests/118         | 720 +++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/118.out     |   5 +
 tests/qemu-iotests/group       |   1 +
 ui/cocoa.m                     |  10 +-
 16 files changed, 1402 insertions(+), 106 deletions(-)
 create mode 100755 tests/qemu-iotests/118
 create mode 100644 tests/qemu-iotests/118.out
Signature · 1 line
2.6.2
author
#1 lore raw

PATCH v9 11/15 qmp: Introduce blockdev-change-medium

Introduce a new QMP command 'blockdev-change-medium' which is intended to replace the 'change' command for block devices. The existing function qmp_change_blockdev() is accordingly renamed to qmp_blockdev_change_medium().

---
 blockdev.c                |  7 ++++---
 include/sysemu/blockdev.h |  2 --
 qapi-schema.json          |  6 ++++--
 qapi/block-core.json      | 23 +++++++++++++++++++++++
 qmp-commands.hx           | 31 +++++++++++++++++++++++++++++++
 qmp.c                     |  2 +-
 ui/cocoa.m                | 10 ++++++----
 7 files changed, 69 insertions(+), 12 deletions(-)
blockdev.c +4 -3
index df93173..dec6169 100644
@@ -2133,8 +2133,9 @@ void qmp_blockdev_insert_medium(const char *device, const char *node_name,
     qmp_blockdev_insert_anon_medium(device, bs, errp);
 }
 
-void qmp_change_blockdev(const char *device, const char *filename,
-                         const char *format, Error **errp)
+void qmp_blockdev_change_medium(const char *device, const char *filename,
+                                bool has_format, const char *format,
+                                Error **errp)
 {
     BlockBackend *blk;
     BlockDriverState *medium_bs = NULL;
@@ -2155,7 +2156,7 @@ void qmp_change_blockdev(const char *device, const char *filename,
 
     bdrv_flags = blk_get_open_flags_from_root_state(blk);
 
-    if (format) {
+    if (has_format) {
         options = qdict_new();
         qdict_put(options, "driver", qstring_from_str(format));
     }
include/sysemu/blockdev.h +0 -2
index a00be94..b06a060 100644
@@ -63,8 +63,6 @@ DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type);
 
 /* device-hotplug */
 
-void qmp_change_blockdev(const char *device, const char *filename,
-                         const char *format, Error **errp);
 void hmp_commit(Monitor *mon, const QDict *qdict);
 void hmp_drive_del(Monitor *mon, const QDict *qdict);
 #endif
qapi-schema.json +4 -2
index 702b7b5..058b8ec 100644
@@ -1842,8 +1842,10 @@
 #          device's password.  The behavior of reads and writes to the block
 #          device between when these calls are executed is undefined.
 #
-# Notes:  It is strongly recommended that this interface is not used especially
-#         for changing block devices.
+# Notes:  This interface is deprecated, and it is strongly recommended that you
+#         avoid using it.  For changing block devices, use
+#         blockdev-change-medium; for changing VNC parameters, use
+#         change-vnc-password.
 #
 # Since: 0.14.0
 ##
qapi/block-core.json +23 -0
index 5c4fc72..e9fa649 100644
@@ -1959,6 +1959,29 @@
 
 
 ##
+# @blockdev-change-medium:
+#
+# Changes the medium inserted into a block device by ejecting the current medium
+# and loading a new image file which is inserted as the new medium (this command
+# combines blockdev-open-tray, blockdev-remove-medium, blockdev-insert-medium
+# and blockdev-close-tray).
+#
+# @device:          block device name
+#
+# @filename:        filename of the new image to be loaded
+#
+# @format:          #optional, format to open the new image with (defaults to
+#                   the probed format)
+#
+# Since: 2.5
+##
+{ 'command': 'blockdev-change-medium',
+  'data': { 'device': 'str',
+            'filename': 'str',
+            '*format': 'str' } }
+
+
+##
 # @BlockErrorAction
 #
 # An enumeration of action that has been taken when a DISK I/O occurs
qmp-commands.hx +31 -0
index 1dfa809..d6e4d7e 100644
@@ -4163,6 +4163,37 @@ Example:
 EQMP
 
     {
+        .name       = "blockdev-change-medium",
+        .args_type  = "device:B,filename:F,format:s?",
+        .mhandler.cmd_new = qmp_marshal_blockdev_change_medium,
+    },
+
+SQMP
+blockdev-change-medium
+----------------------
+
+Changes the medium inserted into a block device by ejecting the current medium
+and loading a new image file which is inserted as the new medium.
+
+Arguments:
+
+- "device": device name (json-string)
+- "filename": filename of the new image (json-string)
+- "format": format of the new image (json-string, optional)
+
+Examples:
+
+1. Change a removable medium
+
+-> { "execute": "blockdev-change-medium",
+             "arguments": { "device": "ide1-cd0",
+                            "filename": "/srv/images/Fedora-12-x86_64-DVD.iso",
+                            "format": "raw" } }
+<- { "return": {} }
+
+EQMP
+
+    {
         .name       = "query-memdev",
         .args_type  = "",
         .mhandler.cmd_new = qmp_marshal_query_memdev,
qmp.c +1 -1
index ff54e5a..4e44f98 100644
@@ -414,7 +414,7 @@ void qmp_change(const char *device, const char *target,
     if (strcmp(device, "vnc") == 0) {
         qmp_change_vnc(target, has_arg, arg, errp);
     } else {
-        qmp_change_blockdev(device, target, arg, errp);
+        qmp_blockdev_change_medium(device, target, has_arg, arg, errp);
     }
 }
 
ui/cocoa.m +6 -4
index c0d6bb2..2d8e4e2 100644
@@ -1113,10 +1113,12 @@ QemuCocoaView *cocoaView;
         }
 
         Error *err = NULL;
-        qmp_change_blockdev([drive cStringUsingEncoding: NSASCIIStringEncoding],
-                            [file cStringUsingEncoding: NSASCIIStringEncoding],
-                            "raw",
-                            &err);
+        qmp_blockdev_change_medium([drive cStringUsingEncoding:
+                                          NSASCIIStringEncoding],
+                                   [file cStringUsingEncoding:
+                                         NSASCIIStringEncoding],
+                                   true, "raw",
+                                   &err);
         handleAnyDeviceErrors(err);
     }
 }
Signature · 1 line
2.6.2
#2 lore raw

Re: [Qemu-devel] [PATCH v9 11/15] qmp: Introduce blockdev-change-medium

Am 06.11.2015 um 16:27 hat Max Reitz geschrieben:

Quoted 6 lines

Introduce a new QMP command 'blockdev-change-medium' which is intended to replace the 'change' command for block devices. The existing function qmp_change_blockdev() is accordingly renamed to qmp_blockdev_change_medium().

Thanks, updated the queued patch with this one.

Kevin