All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glauber Costa <glommer@redhat.com>
To: qemu-devel@nongnu.org
Cc: Mark McLoughlin <markmc@redhat.com>, aliguori@us.ibm.com
Subject: [Qemu-devel] [PATCH 14/15] Prevent CD-ROM media eject while device is locked
Date: Wed, 17 Jun 2009 13:10:03 -0400	[thread overview]
Message-ID: <1245258604-2843-15-git-send-email-glommer@redhat.com> (raw)
In-Reply-To: <1245258604-2843-14-git-send-email-glommer@redhat.com>

From: Mark McLoughlin <markmc@redhat.com>

Section 10.8.25 ("START/STOP UNIT Command") of SFF-8020i states that
if the device is locked we should refuse to eject if the device is
locked.

ASC_MEDIA_REMOVAL_PREVENTED is the appropriate return in this case.

In order to stop itself from ejecting the media it is running from,
Fedora's installer (anaconda) requires the CDROMEJECT ioctl() to fail
if the drive has been previously locked.

See also https://bugzilla.redhat.com/501412

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
 block.c  |    9 ++++++++-
 block.h  |    2 +-
 hw/ide.c |   26 ++++++++++++++++++--------
 3 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/block.c b/block.c
index b68a8da..e5cd23d 100644
--- a/block.c
+++ b/block.c
@@ -1664,11 +1664,15 @@ int bdrv_media_changed(BlockDriverState *bs)
 /**
  * If eject_flag is TRUE, eject the media. Otherwise, close the tray
  */
-void bdrv_eject(BlockDriverState *bs, int eject_flag)
+int bdrv_eject(BlockDriverState *bs, int eject_flag)
 {
     BlockDriver *drv = bs->drv;
     int ret;
 
+    if (bs->locked) {
+        return -EBUSY;
+    }
+
     if (!drv || !drv->bdrv_eject) {
         ret = -ENOTSUP;
     } else {
@@ -1677,7 +1681,10 @@ void bdrv_eject(BlockDriverState *bs, int eject_flag)
     if (ret == -ENOTSUP) {
         if (eject_flag)
             bdrv_close(bs);
+        ret = 0;
     }
+
+    return ret;
 }
 
 int bdrv_is_locked(BlockDriverState *bs)
diff --git a/block.h b/block.h
index 979781a..e1070e9 100644
--- a/block.h
+++ b/block.h
@@ -132,7 +132,7 @@ int bdrv_is_inserted(BlockDriverState *bs);
 int bdrv_media_changed(BlockDriverState *bs);
 int bdrv_is_locked(BlockDriverState *bs);
 void bdrv_set_locked(BlockDriverState *bs, int locked);
-void bdrv_eject(BlockDriverState *bs, int eject_flag);
+int bdrv_eject(BlockDriverState *bs, int eject_flag);
 void bdrv_set_change_cb(BlockDriverState *bs,
                         void (*change_cb)(void *opaque), void *opaque);
 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
diff --git a/hw/ide.c b/hw/ide.c
index 6ad1d08..9b93e7f 100644
--- a/hw/ide.c
+++ b/hw/ide.c
@@ -359,6 +359,7 @@
 #define ASC_INCOMPATIBLE_FORMAT              0x30
 #define ASC_MEDIUM_NOT_PRESENT               0x3a
 #define ASC_SAVING_PARAMETERS_NOT_SUPPORTED  0x39
+#define ASC_MEDIA_REMOVAL_PREVENTED          0x53
 
 #define CFA_NO_ERROR            0x00
 #define CFA_MISC_ERROR          0x09
@@ -1818,18 +1819,27 @@ static void ide_atapi_cmd(IDEState *s)
         break;
     case GPCMD_START_STOP_UNIT:
         {
-            int start, eject;
+            int start, eject, err = 0;
             start = packet[4] & 1;
             eject = (packet[4] >> 1) & 1;
 
-            if (eject && !start) {
-                /* eject the disk */
-                bdrv_eject(s->bs, 1);
-            } else if (eject && start) {
-                /* close the tray */
-                bdrv_eject(s->bs, 0);
+            if (eject) {
+                err = bdrv_eject(s->bs, !start);
+            }
+
+            switch (err) {
+            case 0:
+                ide_atapi_cmd_ok(s);
+                break;
+            case -EBUSY:
+                ide_atapi_cmd_error(s, SENSE_NOT_READY,
+                                    ASC_MEDIA_REMOVAL_PREVENTED);
+                break;
+            default:
+                ide_atapi_cmd_error(s, SENSE_NOT_READY,
+                                    ASC_MEDIUM_NOT_PRESENT);
+                break;
             }
-            ide_atapi_cmd_ok(s);
         }
         break;
     case GPCMD_MECHANISM_STATUS:
-- 
1.6.2.2

  reply	other threads:[~2009-06-17 17:10 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-17 17:09 [Qemu-devel] [GIT PULL 00/15] Stable branch update 2009-06-17 Glauber Costa
2009-06-17 17:09 ` [Qemu-devel] [PATCH 01/15] net: Fix -net socket, listen (Jan Kiszka) Glauber Costa
2009-06-17 17:09   ` [Qemu-devel] [PATCH 02/15] Minimal ethernet frame length is 64 bytes Glauber Costa
2009-06-17 17:09     ` [Qemu-devel] [PATCH 03/15] Don't send all gratuitous packets at once Glauber Costa
2009-06-17 17:09       ` [Qemu-devel] [PATCH 04/15] serial: fix lost character after sysrq Glauber Costa
2009-06-17 17:09         ` [Qemu-devel] [PATCH 05/15] e1000: Ignore reset command Glauber Costa
2009-06-17 17:09           ` [Qemu-devel] [PATCH 06/15] VNC: Fix memory allocation (wrong structure size) Glauber Costa
2009-06-17 17:09             ` [Qemu-devel] [PATCH 07/15] fix raw_pread_aligned return value Glauber Costa
2009-06-17 17:09               ` [Qemu-devel] [PATCH 08/15] BACKPORT: Register reset functions for e1000 and rtl8139 Glauber Costa
2009-06-17 17:09                 ` [Qemu-devel] [PATCH 09/15] BACKPORT: Update irqs on reset and device load Glauber Costa
2009-06-17 17:09                   ` [Qemu-devel] [PATCH 10/15] BACKPORT: Add rtc reset function Glauber Costa
2009-06-17 17:10                     ` [Qemu-devel] [PATCH 11/15] fix qemu_aio_flush Glauber Costa
2009-06-17 17:10                       ` [Qemu-devel] [PATCH 12/15] QEMU KVM: i386: Fix the cpu reset state Glauber Costa
2009-06-17 17:10                         ` [Qemu-devel] [PATCH 13/15] kvm: Fix IRQ injection into full queue Glauber Costa
2009-06-17 17:10                           ` Glauber Costa [this message]
2009-06-17 17:10                             ` [Qemu-devel] [PATCH 15/15] Fix vga_screen_dump_blank() PPM generation Glauber Costa
2009-06-17 17:12                   ` [Qemu-devel] Re: [PATCH 09/15] BACKPORT: Update irqs on reset and device load Blue Swirl
2009-06-17 17:49                     ` Glauber Costa
2009-06-17 17:57 ` [Qemu-devel] [GIT PULL 00/15] Stable branch update 2009-06-17 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=1245258604-2843-15-git-send-email-glommer@redhat.com \
    --to=glommer@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=markmc@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.