qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 2/2] Guess host device type from requested guest dev


From: Eduardo Habkost
Subject: [Qemu-devel] [PATCH 2/2] Guess host device type from requested guest device type
Date: Wed, 17 Jun 2009 17:28:28 -0300

This fixes the following issue:
https://bugzilla.redhat.com/show_bug.cgi?id=473154

Sometimes a CD-ROM drive path doesn't start with /dev/cdrom, causing problems
if a disk isn't inserted on the drive. With this patch, the floppy and cdrom
drivers are used if using a host block device as backend and the
virtual device type is floppy or CD-ROM.

Example:

 $ ls -l /dev/cdrom /dev/hda
 lrwxrwxrwx 1 root root    3 Jun 17 10:20 /dev/cdrom -> hda
 brw-rw---- 1 root disk 3, 0 Jun 17 10:20 /dev/hda

Before this patch (CD-ROM drive with no disk):

 $ sudo qemu-system-x86_64 -cdrom /dev/cdrom
 [works]
 $ sudo qemu-system-x86_64 -cdrom /dev/hda
 qemu: could not open disk image /dev/hda

After this patch (with no disk on the CD-ROM drive, too):

 $ sudo qemu-system-x86_64 -cdrom /dev/hda
 [works]

This is based on a fix from Cole Robinson, submitted here:
http://marc.info/?l=qemu-devel&m=124458617900905

The FreeBSD side of the cdrom driver changes is untested.

Signed-off-by: Eduardo Habkost <address@hidden>
---
 block/raw-posix.c |   30 +++++++++++++++++++++++++-----
 1 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index bbcb6bc..795d465 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -959,13 +959,12 @@ static int hdev_probe_device(BlockDriverState *bs, const 
char *filename)
 {
     struct stat st;
 
-    /* allow a dedicated CD-ROM driver to match with a higher priority */
-    if (strstart(filename, "/dev/cdrom", NULL))
-        return 50;
-
     if (stat(filename, &st) >= 0 &&
             (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) {
-        return 100;
+        /* allow a dedicated driver (e.g. cdrom, floppy) to match with a higher
+         * priority
+         */
+        return 90;
     }
 
     return 0;
@@ -1203,8 +1202,15 @@ static int floppy_open(BlockDriverState *bs, const char 
*filename, int flags)
 
 static int floppy_probe_device(BlockDriverState *bs, const char *filename)
 {
+    struct stat st;
+
     if (strstart(filename, "/dev/fd", NULL))
         return 100;
+
+    if (bs->type == BDRV_TYPE_FLOPPY &&
+        stat(filename, &st) >= 0 && S_ISBLK(st.st_mode))
+        return 100;
+
     return 0;
 }
 
@@ -1287,8 +1293,15 @@ static int cdrom_open(BlockDriverState *bs, const char 
*filename, int flags)
 
 static int cdrom_probe_device(BlockDriverState *bs, const char *filename)
 {
+    struct stat st;
+
     if (strstart(filename, "/dev/cd", NULL))
         return 100;
+
+    if (bs->type == BDRV_TYPE_CDROM &&
+        stat(filename, &st) >= 0 && S_ISBLK(st.st_mode))
+        return 100;
+
     return 0;
 }
 
@@ -1383,9 +1396,16 @@ static int cdrom_open(BlockDriverState *bs, const char 
*filename, int flags)
 
 static int cdrom_probe_device(BlockDriverState *bs, const char *filename)
 {
+    struct stat st;
+
     if (strstart(filename, "/dev/cd", NULL) ||
             strstart(filename, "/dev/acd", NULL))
         return 100;
+
+    if (bs->type == BDRV_TYPE_CDROM &&
+        stat(filename, &st) >= 0 && S_ISBLK(st.st_mode))
+        return 100;
+
     return 0;
 }
 
-- 
1.6.3.rc4.29.g8146





reply via email to

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