From 0749b0306e560c04a854ed19cc4d49d636c42fd4 Mon Sep 17 00:00:00 2001 From: Cole Robinson <crobinso@redhat.com> Date: Tue, 16 Jun 2009 17:46:45 -0300 Subject: [PATCH 1/2] bz#505090: Guess host device type from requested guest device type RHEL bug: https://bugzilla.redhat.com/show_bug.cgi?id=505090 Clone of the following Fedora bug: https://bugzilla.redhat.com/show_bug.cgi?id=473154 [ehabkost: comments from Cole Robinson on bugzilla are pasted below] > I just went digging through the qemu code, and I think the fix should really be > at that level. > > The code is already capable of being launched with an empty cdrom device > attached to it. Unfortunately qemu only enables this mode for cdrom devices if > the passed path starts with '/dev/cd': in the above case, we are using /dev/sr0 > :( Yay robustness. > > Patch basically says "If the user requests a cdrom/floppy device, and the > passed path is a block or char device, assume the path is a host cdrom/floppy > device." This would change some existing behavior: for example, a host block > device that is passed to a qemu guest as a cdrom is now assumed to be a host > cdrom, even when it isn't. My guess is this won't yield any real functional > change, since the only differences between floppy/cdrom and everything else (in > this case) is in the ejectable media commands. > > I haven't done much testing besides verifying that qemu no longer complains > about accessing the empty /dev/sr0. [ehabkost: patch was sent to qemu-devel at: http://marc.info/?l=qemu-devel&m=124458617900905 However, the code on the upstream qemu tree is different now, and the patch will need to be ported when submitted again.] Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Bugzilla: 505090 RH-Upstream-status: equivalent-patch-submitted(qemu-devel) Message-Id: <1245185205-9600-1-git-send-email-ehabkost@redhat.com> Acked-by: Dor Laor <dlaor@redhat.com> Acked-by: Juan Quintela <quintela@redhat.com> Acked-by: john cooper <john.cooper@redhat.com> --- qemu/block-raw-posix.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-) diff --git a/qemu/block-raw-posix.c b/qemu/block-raw-posix.c index 85c57b8..ac2dab9 100644 --- a/qemu/block-raw-posix.c +++ b/qemu/block-raw-posix.c @@ -944,16 +944,21 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags) s->type = FTYPE_FILE; #if defined(__linux__) - if (strstart(filename, "/dev/cd", NULL)) { + if (strstart(filename, "/dev/cd", NULL) || + bs->type == BDRV_TYPE_CDROM) { /* open will not fail even if no CD is inserted */ open_flags |= O_NONBLOCK; s->type = FTYPE_CD; - } else if (strstart(filename, "/dev/fd", NULL)) { + } + if (strstart(filename, "/dev/fd", NULL) || + bs->type == BDRV_TYPE_FLOPPY) { s->type = FTYPE_FD; s->fd_open_flags = open_flags; /* open will not fail even if no floppy is inserted */ open_flags |= O_NONBLOCK; - } else if (strstart(filename, "/dev/sg", NULL)) { + } + if (s->type = FTYPE_FILE && + strstart(filename, "/dev/sg", NULL)) { bs->sg = 1; } #endif -- 1.6.3.rc4.29.g8146