From 3ae9121557d79a0170c996dba7958d42e6be1686 Mon Sep 17 00:00:00 2001
From: Kevin Wolf <kwolf@redhat.com>
Date: Tue, 8 Jun 2010 10:46:10 -0300
Subject: [PATCH 5/5] block: Assume raw for drives without media

RH-Author: Kevin Wolf <kwolf@redhat.com>
Message-id: <1275993970-15531-6-git-send-email-kwolf@redhat.com>
Patchwork-id: 9763
O-Subject: [RHEL-6 qemu-kvm PATCH 5/5] block: Assume raw for drives without media
Bugzilla: 593758
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>
RH-Acked-by: Christoph Hellwig <chellwig@redhat.com>

Bugzilla: 593758
Upstream status: Submitted

qemu -cdrom /dev/cdrom with an empty CD-ROM drive doesn't work any more because
we try to guess the format and when this fails (because there is no medium) we
exit with an error message.

This patch should restore the old behaviour by assuming raw format for such
drives.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 block.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index 97f1ced..0aa3ce7 100644
--- a/block.c
+++ b/block.c
@@ -328,8 +328,8 @@ static BlockDriver *find_image_format(const char *filename)
     if (ret < 0)
         return NULL;
 
-    /* Return the raw BlockDriver * to scsi-generic devices */
-    if (bs->sg) {
+    /* Return the raw BlockDriver * to scsi-generic devices or empty drives */
+    if (bs->sg || !bdrv_is_inserted(bs)) {
         bdrv_delete(bs);
         return bdrv_find_format("raw");
     }
-- 
1.7.0.3

