qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH RESEND 29/50] blockdev: Check BB validity in find_bl


From: Max Reitz
Subject: [Qemu-devel] [PATCH RESEND 29/50] blockdev: Check BB validity in find_block_job()
Date: Tue, 27 Jan 2015 14:46:02 -0500

Call blk_is_available() before using blk_bs() to obtain the root
BlockDriverState behind the BlockBackend.

Signed-off-by: Max Reitz <address@hidden>
---
 blockdev.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 4e12061..4bd52b8 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -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;
 }
 
-- 
2.1.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]