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>
This commit is contained in:
Kevin Wolf 2017-02-17 11:23:33 +01:00
parent 2c3b44da07
commit 7dad9ee646
1 changed files with 6 additions and 1 deletions

View File

@ -2858,6 +2858,7 @@ void qmp_block_resize(bool has_device, const char *device,
int64_t size, Error **errp) int64_t size, Error **errp)
{ {
Error *local_err = NULL; Error *local_err = NULL;
BlockBackend *blk = NULL;
BlockDriverState *bs; BlockDriverState *bs;
AioContext *aio_context; AioContext *aio_context;
int ret; int ret;
@ -2888,10 +2889,13 @@ void qmp_block_resize(bool has_device, const char *device,
goto out; goto out;
} }
blk = blk_new();
blk_insert_bs(blk, bs);
/* complete all in-flight operations before resizing the device */ /* complete all in-flight operations before resizing the device */
bdrv_drain_all(); bdrv_drain_all();
ret = bdrv_truncate(bs, size); ret = blk_truncate(blk, size);
switch (ret) { switch (ret) {
case 0: case 0:
break; break;
@ -2913,6 +2917,7 @@ void qmp_block_resize(bool has_device, const char *device,
} }
out: out:
blk_unref(blk);
aio_context_release(aio_context); aio_context_release(aio_context);
} }