Blame 0050-raw-posix-Detect-CDROM-via-ioctl-on-linux.patch

Justin M. Forbes c98f18
From 361f29d46ce4a310818e88adaef0912573847295 Mon Sep 17 00:00:00 2001
Justin M. Forbes c98f18
From: Cole Robinson <crobinso@redhat.com>
Justin M. Forbes c98f18
Date: Thu, 14 Jan 2010 16:19:40 +0000
Justin M. Forbes c98f18
Subject: [PATCH] raw-posix: Detect CDROM via ioctl on linux
Justin M. Forbes c98f18
Justin M. Forbes c98f18
Current CDROM detection is hardcoded based on source file name.
Justin M. Forbes c98f18
Make this smarter on linux by attempting a CDROM specific ioctl.
Justin M. Forbes c98f18
Justin M. Forbes c98f18
This makes '-cdrom /dev/sr0' succeed with no media present.
Justin M. Forbes c98f18
Justin M. Forbes c98f18
v2:
Justin M. Forbes c98f18
    Give ioctl check higher priority than filename check.
Justin M. Forbes c98f18
Justin M. Forbes c98f18
v3:
Justin M. Forbes c98f18
    Actually initialize 'prio' variable.
Justin M. Forbes c98f18
    Check for ioctl success rather than absence of specific failure.
Justin M. Forbes c98f18
Justin M. Forbes c98f18
v4:
Justin M. Forbes c98f18
    Explicitly mention that change is linux specific.
Justin M. Forbes c98f18
Justin M. Forbes c98f18
Signed-off-by: Cole Robinson <crobinso@redhat.com>
Justin M. Forbes c98f18
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Justin M. Forbes c98f18
---
Justin M. Forbes c98f18
 block/raw-posix.c |   20 ++++++++++++++++++--
Justin M. Forbes c98f18
 1 files changed, 18 insertions(+), 2 deletions(-)
Justin M. Forbes c98f18
Justin M. Forbes c98f18
diff --git a/block/raw-posix.c b/block/raw-posix.c
Justin M. Forbes c98f18
index c204cf9..1c777a1 100644
Justin M. Forbes c98f18
--- a/block/raw-posix.c
Justin M. Forbes c98f18
+++ b/block/raw-posix.c
Justin M. Forbes c98f18
@@ -1142,9 +1142,25 @@ static int cdrom_open(BlockDriverState *bs, const char *filename, int flags)
Justin M. Forbes c98f18
Justin M. Forbes c98f18
 static int cdrom_probe_device(const char *filename)
Justin M. Forbes c98f18
 {
Justin M. Forbes c98f18
+    int fd, ret;
Justin M. Forbes c98f18
+    int prio = 0;
Justin M. Forbes c98f18
+
Justin M. Forbes c98f18
     if (strstart(filename, "/dev/cd", NULL))
Justin M. Forbes c98f18
-        return 100;
Justin M. Forbes c98f18
-    return 0;
Justin M. Forbes c98f18
+        prio = 50;
Justin M. Forbes c98f18
+
Justin M. Forbes c98f18
+    fd = open(filename, O_RDONLY | O_NONBLOCK);
Justin M. Forbes c98f18
+    if (fd < 0) {
Justin M. Forbes c98f18
+        goto out;
Justin M. Forbes c98f18
+    }
Justin M. Forbes c98f18
+
Justin M. Forbes c98f18
+    /* Attempt to detect via a CDROM specific ioctl */
Justin M. Forbes c98f18
+    ret = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
Justin M. Forbes c98f18
+    if (ret >= 0)
Justin M. Forbes c98f18
+        prio = 100;
Justin M. Forbes c98f18
+
Justin M. Forbes c98f18
+    close(fd);
Justin M. Forbes c98f18
+out:
Justin M. Forbes c98f18
+    return prio;
Justin M. Forbes c98f18
 }
Justin M. Forbes c98f18
Justin M. Forbes c98f18
 static int cdrom_is_inserted(BlockDriverState *bs)
Justin M. Forbes c98f18
-- 
Justin M. Forbes c98f18
1.6.6.1
Justin M. Forbes c98f18