@@ -2698,25 +2698,35 @@ out:
/* Get the block job for a given device name and acquire its AioContext */
static BlockJob *find_block_job(const char *device, AioContext **aio_context)
{
+ BlockBackend *blk;
BlockDriverState *bs;
- bs = bdrv_find(device);
- if (!bs) {
+ *aio_context = NULL;
+
+ blk = blk_by_name(device);
+ if (!blk) {
goto notfound;
}
- *aio_context = bdrv_get_aio_context(bs);
+ *aio_context = blk_get_aio_context(blk);
aio_context_acquire(*aio_context);
+ if (!blk_is_available(blk)) {
+ goto notfound;
+ }
+ bs = blk_bs(blk);
+
if (!bs->job) {
- aio_context_release(*aio_context);
goto notfound;
}
return bs->job;
notfound:
- *aio_context = NULL;
+ if (*aio_context) {
+ aio_context_release(*aio_context);
+ *aio_context = NULL;
+ }
return NULL;
}
Call blk_is_available() before using blk_bs() to obtain the root BlockDriverState behind the BlockBackend. Signed-off-by: Max Reitz <mreitz@redhat.com> --- blockdev.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)