From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MH1kS-0007W0-Rt for qemu-devel@nongnu.org; Wed, 17 Jun 2009 16:28:44 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MH1kO-0007VU-9M for qemu-devel@nongnu.org; Wed, 17 Jun 2009 16:28:44 -0400 Received: from [199.232.76.173] (port=36780 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MH1kN-0007VP-Ub for qemu-devel@nongnu.org; Wed, 17 Jun 2009 16:28:39 -0400 Received: from mx2.redhat.com ([66.187.237.31]:52743) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MH1kN-0008Ip-8P for qemu-devel@nongnu.org; Wed, 17 Jun 2009 16:28:39 -0400 From: Eduardo Habkost Date: Wed, 17 Jun 2009 17:28:28 -0300 Message-Id: <1245270508-23315-3-git-send-email-ehabkost@redhat.com> In-Reply-To: <1245270508-23315-1-git-send-email-ehabkost@redhat.com> References: <1245270508-23315-1-git-send-email-ehabkost@redhat.com> Subject: [Qemu-devel] [PATCH 2/2] Guess host device type from requested guest device type List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org, Cole Robinson 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 --- 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