summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2017-02-17 11:23:33 +0100
committerKevin Wolf <kwolf@redhat.com>2017-02-24 16:09:23 +0100
commit7dad9ee6467e0e3024fbe09f8a363148558b8eef (patch)
tree4a8e6364b206fa01fc51c64c3ef344eaa9765ce8
parent2c3b44da07d341557a8203cc509ea07fe3605e11 (diff)
downloadfocaccia-qemu-7dad9ee6467e0e3024fbe09f8a363148558b8eef.tar.gz
focaccia-qemu-7dad9ee6467e0e3024fbe09f8a363148558b8eef.zip
blockdev: Use BlockBackend to resize in qmp_block_resize()
In order to be able to do permission checking and to keep working with
the BdrvChild based bdrv_truncate() that this involves, we need to
create a temporary BlockBackend to resize the image.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
-rw-r--r--blockdev.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/blockdev.c b/blockdev.c
index bbf9d4d8f1..2b2f6ceef0 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2858,6 +2858,7 @@ void qmp_block_resize(bool has_device, const char *device,
                       int64_t size, Error **errp)
 {
     Error *local_err = NULL;
+    BlockBackend *blk = NULL;
     BlockDriverState *bs;
     AioContext *aio_context;
     int ret;
@@ -2888,10 +2889,13 @@ void qmp_block_resize(bool has_device, const char *device,
         goto out;
     }
 
+    blk = blk_new();
+    blk_insert_bs(blk, bs);
+
     /* complete all in-flight operations before resizing the device */
     bdrv_drain_all();
 
-    ret = bdrv_truncate(bs, size);
+    ret = blk_truncate(blk, size);
     switch (ret) {
     case 0:
         break;
@@ -2913,6 +2917,7 @@ void qmp_block_resize(bool has_device, const char *device,
     }
 
 out:
+    blk_unref(blk);
     aio_context_release(aio_context);
 }