diff mbox

[01/54] blockdev: Use BlockBackend to resize in qmp_block_resize()

Message ID 1487689130-30373-2-git-send-email-kwolf@redhat.com
State New, archived
Headers show

Commit Message

Kevin Wolf Feb. 21, 2017, 2:57 p.m. UTC
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>
---
 blockdev.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Max Reitz Feb. 22, 2017, 12:27 p.m. UTC | #1
On 21.02.2017 15:57, Kevin Wolf wrote:
> 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>
> ---
>  blockdev.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

Reviewed-by: Max Reitz <mreitz@redhat.com>
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index db82ac9..3596d87 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2855,6 +2855,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;
@@ -2885,10 +2886,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;
@@ -2910,6 +2914,7 @@  void qmp_block_resize(bool has_device, const char *device,
     }
 
 out:
+    blk_unref(blk);
     aio_context_release(aio_context);
 }