block: Prepare for NULL BDS
blk_bs() will not necessarily return a non-NULL value any more (unless
blk_is_available() is true or it can be assumed to otherwise, e.g.
because it is called immediately after a successful blk_new_with_bs() or
blk_new_open()).
Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
diff --git a/block.c b/block.c
index e28a32a..e9f40dc 100644
--- a/block.c
+++ b/block.c
@@ -2683,6 +2683,11 @@
blk = blk_by_name(device);
if (blk) {
+ if (!blk_bs(blk)) {
+ error_setg(errp, "Device '%s' has no medium", device);
+ return NULL;
+ }
+
return blk_bs(blk);
}
}