From c7a0f2be8f95b220cdadbba9a9236eaf115951dc Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Tue, 10 Mar 2020 12:38:25 +0100 Subject: block: Make bdrv_get_cumulative_perm() public Signed-off-by: Kevin Wolf Message-Id: <20200310113831.27293-2-kwolf@redhat.com> Reviewed-by: Peter Krempa Signed-off-by: Kevin Wolf --- block.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'block.c') diff --git a/block.c b/block.c index 957630b1c5..79a5a2770f 100644 --- a/block.c +++ b/block.c @@ -1872,8 +1872,6 @@ static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q, bool *tighten_restrictions, Error **errp); static void bdrv_child_abort_perm_update(BdrvChild *c); static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared); -static void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, - uint64_t *shared_perm); typedef struct BlockReopenQueueEntry { bool prepared; @@ -2097,8 +2095,8 @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms, } } -static void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, - uint64_t *shared_perm) +void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, + uint64_t *shared_perm) { BdrvChild *c; uint64_t cumulative_perms = 0; -- cgit v1.2.3 From 30dd65f307b647eef8156c4a33bd007823ef85cb Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Tue, 10 Mar 2020 12:38:29 +0100 Subject: block: Fix cross-AioContext blockdev-snapshot external_snapshot_prepare() tries to move the overlay to the AioContext of the backing file (the snapshotted node). However, it's possible that this doesn't work, but the backing file can instead be moved to the overlay's AioContext (e.g. opening the backing chain for a mirror target). bdrv_append() already indirectly uses bdrv_attach_node(), which takes care to move nodes to make sure they use the same AioContext and which tries both directions. So the problem has a simple fix: Just delete the unnecessary extra bdrv_try_set_aio_context() call in external_snapshot_prepare() and instead assert in bdrv_append() that both nodes were indeed moved to the same AioContext. Signed-off-by: Kevin Wolf Message-Id: <20200310113831.27293-6-kwolf@redhat.com> Tested-by: Peter Krempa Signed-off-by: Kevin Wolf --- block.c | 1 + 1 file changed, 1 insertion(+) (limited to 'block.c') diff --git a/block.c b/block.c index 79a5a2770f..8fc7b56937 100644 --- a/block.c +++ b/block.c @@ -4365,6 +4365,7 @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, bdrv_ref(from); assert(qemu_get_current_aio_context() == qemu_get_aio_context()); + assert(bdrv_get_aio_context(from) == bdrv_get_aio_context(to)); bdrv_drained_begin(from); /* Put all parents into @list and calculate their cumulative permissions */ -- cgit v1.2.3 From e1d7f8bb1ec0c6911dcea81641ce6139dbded02d Mon Sep 17 00:00:00 2001 From: Daniel Henrique Barboza Date: Thu, 30 Jan 2020 18:39:05 -0300 Subject: block.c: adding bdrv_co_delete_file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using the new 'bdrv_co_delete_file' interface, a pure co_routine function 'bdrv_co_delete_file' inside block.c can can be used in a way similar of the existing bdrv_create_file to to clean up a created file. We're creating a pure co_routine because the only caller of 'bdrv_co_delete_file' will be already in co_routine context, thus there is no need to add all the machinery to check for qemu_in_coroutine() and create a separated co_routine to do the job. Suggested-by: Daniel P. Berrangé Signed-off-by: Daniel Henrique Barboza Message-Id: <20200130213907.2830642-3-danielhb413@gmail.com> Signed-off-by: Kevin Wolf --- block.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'block.c') diff --git a/block.c b/block.c index 8fc7b56937..a2542c977b 100644 --- a/block.c +++ b/block.c @@ -668,6 +668,32 @@ int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp) } } +int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp) +{ + Error *local_err = NULL; + int ret; + + assert(bs != NULL); + + if (!bs->drv) { + error_setg(errp, "Block node '%s' is not opened", bs->filename); + return -ENOMEDIUM; + } + + if (!bs->drv->bdrv_co_delete_file) { + error_setg(errp, "Driver '%s' does not support image deletion", + bs->drv->format_name); + return -ENOTSUP; + } + + ret = bs->drv->bdrv_co_delete_file(bs, &local_err); + if (ret < 0) { + error_propagate(errp, local_err); + } + + return ret; +} + /** * Try to get @bs's logical and physical block size. * On success, store them in @bsz struct and return 0. -- cgit v1.2.3