Patchwork [2/7] block: fail live snapshot if disk has no medium

login
register
mail settings
Submitter Paolo Bonzini
Date April 5, 2012, 3:42 p.m.
Message ID <1333640581-25649-3-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/151025/
State New
Headers show

Comments

Paolo Bonzini - April 5, 2012, 3:42 p.m.
This would cause a segfault accessing states->old_bs->drv.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 blockdev.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Patch

diff --git a/blockdev.c b/blockdev.c
index 4d17486..be9cdc5 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -752,14 +752,17 @@  void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
             goto delete_and_fail;
         }
 
+        if (!bdrv_is_inserted(states->old_bs)) {
+            error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
+            goto delete_and_fail;
+        }
+
         if (bdrv_in_use(states->old_bs)) {
             error_set(errp, QERR_DEVICE_IN_USE, device);
             goto delete_and_fail;
         }
 
-        if (!bdrv_is_read_only(states->old_bs) &&
-             bdrv_is_inserted(states->old_bs)) {
-
+        if (!bdrv_is_read_only(states->old_bs)) {
             if (bdrv_flush(states->old_bs)) {
                 error_set(errp, QERR_IO_ERROR);
                 goto delete_and_fail;