summary refs log tree commit diff stats
path: root/blockdev.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2016-09-12 19:08:31 +0200
committerKevin Wolf <kwolf@redhat.com>2016-09-29 14:13:39 +0200
commitb85114f8cfbede8b153db68875973ef0790bf296 (patch)
treef145eb5c7d45e3e2ad8eefb5c06ac5bf72d20883 /blockdev.c
parent692e01a27ccde4120f1371227d4011f668d67a76 (diff)
downloadfocaccia-qemu-b85114f8cfbede8b153db68875973ef0790bf296.tar.gz
focaccia-qemu-b85114f8cfbede8b153db68875973ef0790bf296.zip
block: Use 'detect-zeroes' option for 'blockdev-change-medium'
Instead of modifying the new BDS after it has been opened, use the newly
supported 'detect-zeroes' option in bdrv_open_common() so that all
requirements are checked (detect-zeroes=unmap requires discard=unmap).

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'blockdev.c')
-rw-r--r--blockdev.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/blockdev.c b/blockdev.c
index 511260ce93..7b87bd8a71 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2546,6 +2546,7 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
     BlockBackend *blk;
     BlockDriverState *medium_bs = NULL;
     int bdrv_flags;
+    bool detect_zeroes;
     int rc;
     QDict *options = NULL;
     Error *err = NULL;
@@ -2585,8 +2586,12 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
         abort();
     }
 
+    options = qdict_new();
+    detect_zeroes = blk_get_detect_zeroes_from_root_state(blk);
+    qdict_put(options, "detect-zeroes",
+              qstring_from_str(detect_zeroes ? "on" : "off"));
+
     if (has_format) {
-        options = qdict_new();
         qdict_put(options, "driver", qstring_from_str(format));
     }
 
@@ -2623,8 +2628,6 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
         goto fail;
     }
 
-    blk_apply_root_state(blk, medium_bs);
-
     qmp_blockdev_close_tray(has_device, device, has_id, id, errp);
 
 fail: