qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 27/50] blockdev: Check BB validity in blockdev-backu


From: Max Reitz
Subject: [Qemu-devel] [PATCH 27/50] blockdev: Check BB validity in blockdev-backup
Date: Mon, 26 Jan 2015 11:03:01 -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 | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 9476c72..e335d06 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2452,6 +2452,7 @@ void qmp_blockdev_backup(const char *device, const char 
*target,
                          BlockdevOnError on_target_error,
                          Error **errp)
 {
+    BlockBackend *blk;
     BlockDriverState *bs;
     BlockDriverState *target_bs;
     Error *local_err = NULL;
@@ -2467,15 +2468,21 @@ void qmp_blockdev_backup(const char *device, const char 
*target,
         on_target_error = BLOCKDEV_ON_ERROR_REPORT;
     }
 
-    bs = bdrv_find(device);
-    if (!bs) {
+    blk = blk_by_name(device);
+    if (!blk) {
         error_set(errp, QERR_DEVICE_NOT_FOUND, device);
         return;
     }
 
-    aio_context = bdrv_get_aio_context(bs);
+    aio_context = blk_get_aio_context(blk);
     aio_context_acquire(aio_context);
 
+    if (!blk_is_available(blk)) {
+        error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
+        goto out;
+    }
+    bs = blk_bs(blk);
+
     target_bs = bdrv_find(target);
     if (!target_bs) {
         error_set(errp, QERR_DEVICE_NOT_FOUND, target);
-- 
2.1.0




reply via email to

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