diff mbox

[17/50] block: Respect empty BB in bdrv_lookup_bs()

Message ID 1422288204-29271-18-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Jan. 26, 2015, 4:02 p.m. UTC
blk_by_name() may return a BlockBackend for which blk_bs() returns NULL.
In this case, an error should be returned (instead of just returning
NULL without modifying *errp).

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox

Patch

diff --git a/block.c b/block.c
index 9a0a510..b7e631c 100644
--- a/block.c
+++ b/block.c
@@ -3718,6 +3718,11 @@  BlockDriverState *bdrv_lookup_bs(const char *device,
         blk = blk_by_name(device);
 
         if (blk) {
+            if (!blk_bs(blk)) {
+                error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
+                return NULL;
+            }
+
             return blk_bs(blk);
         }
     }