Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 340e01248478ba8b78a6d4d1809b1eff > files > 736

kvm-83-270.el5_11.src.rpm

From 2dd9c40106a933088faed8442455fdb13925705c Mon Sep 17 00:00:00 2001
From: Kevin Wolf <kwolf@redhat.com>
Date: Fri, 3 Sep 2010 11:48:51 -0300
Subject: [PATCH 3/4] raw-posix: Detect CDROM via ioctl on linux

RH-Author: Kevin Wolf <kwolf@redhat.com>
Message-id: <1283514532-8401-3-git-send-email-kwolf@redhat.com>
Patchwork-id: 11754
O-Subject: [RHEL-5.6 KVM PATCH 2/3] raw-posix: Detect CDROM via ioctl on linux
Bugzilla: 609472
RH-Acked-by: Christoph Hellwig <chellwig@redhat.com>
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>

From: Cole Robinson <crobinso@redhat.com>

Bugzilla: 609472
Upstream commit: 3baf720e6b920d583ce2834d05e5a4e9603a1d56

Current CDROM detection is hardcoded based on source file name.
Make this smarter on linux by attempting a CDROM specific ioctl.

This makes '-cdrom /dev/sr0' succeed with no media present.

v2:
    Give ioctl check higher priority than filename check.

v3:
    Actually initialize 'prio' variable.
    Check for ioctl success rather than absence of specific failure.

v4:
    Explicitly mention that change is linux specific.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 qemu/block-raw-posix.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qemu/block-raw-posix.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/qemu/block-raw-posix.c b/qemu/block-raw-posix.c
index d8c883d..ed11e81 100644
--- a/qemu/block-raw-posix.c
+++ b/qemu/block-raw-posix.c
@@ -897,9 +897,25 @@ kern_return_t GetBSDPath( io_iterator_t mediaIterator, char *bsdPath, CFIndex ma
 #if defined(__linux__)
 static int cdrom_probe_device(const char *filename)
 {
+    int fd, ret;
+    int prio = 0;
+
     if (strstart(filename, "/dev/cd", NULL))
-        return 100;
-    return 0;
+        prio = 50;
+
+    fd = open(filename, O_RDONLY | O_NONBLOCK);
+    if (fd < 0) {
+        goto out;
+    }
+
+    /* Attempt to detect via a CDROM specific ioctl */
+    ret = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
+    if (ret >= 0)
+        prio = 100;
+
+    close(fd);
+out:
+    return prio;
 }
 #endif
 
-- 
1.6.5.5