From: Eduardo Habkost <ehabkost@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: qemu-devel@nongnu.org, Cole Robinson <crobinso@redhat.com>
Subject: [Qemu-devel] [PATCH 2/2] Guess host device type from requested guest device type
Date: Wed, 17 Jun 2009 17:28:28 -0300 [thread overview]
Message-ID: <1245270508-23315-3-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1245270508-23315-1-git-send-email-ehabkost@redhat.com>
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 <ehabkost@redhat.com>
---
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
next prev parent reply other threads:[~2009-06-17 20:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-17 20:28 [Qemu-devel] [PATCH 0/2] Guess host device type from guest device type for block devices Eduardo Habkost
2009-06-17 20:28 ` [Qemu-devel] [PATCH 1/2] Add a BlockDriverState parameter to bdrv_probe_device() Eduardo Habkost
2009-06-17 20:28 ` Eduardo Habkost [this message]
2009-06-17 22:17 ` [Qemu-devel] Re: [PATCH 0/2] Guess host device type from guest device type for block devices Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1245270508-23315-3-git-send-email-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=crobinso@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).