diff mbox

[3/5] block: Don't call bdrv_eject() if the tray state didn't change

Message ID 1329506504-29152-4-git-send-email-lcapitulino@redhat.com
State New
Headers show

Commit Message

Luiz Capitulino Feb. 17, 2012, 7:21 p.m. UTC
It's not needed. Besides we can then assume that bdrv_eject() is
only called when there's a tray state change, which is useful to
the DEVICE_TRAY_MOVED event (going to be added in a future
commit).

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hw/ide/atapi.c |    7 +++++--
 hw/scsi-disk.c |    7 +++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

Comments

Markus Armbruster Feb. 20, 2012, 8:16 a.m. UTC | #1
Luiz Capitulino <lcapitulino@redhat.com> writes:

> It's not needed. Besides we can then assume that bdrv_eject() is
> only called when there's a tray state change, which is useful to
> the DEVICE_TRAY_MOVED event (going to be added in a future
> commit).

We can assume that only after the next patch "ide: drop
ide_tray_state_post_load()", actually.  I'd swap the two.  Doubtful
whether it's worth a respin, though.
diff mbox

Patch

diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 0adb27b..5919cf5 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -883,8 +883,11 @@  static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
             ide_atapi_cmd_error(s, sense, ASC_MEDIA_REMOVAL_PREVENTED);
             return;
         }
-        bdrv_eject(s->bs, !start);
-        s->tray_open = !start;
+
+        if (s->tray_open != !start) {
+            bdrv_eject(s->bs, !start);
+            s->tray_open = !start;
+        }
     }
 
     ide_atapi_cmd_ok(s);
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index a5d2fd1..091ecdc 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1050,8 +1050,11 @@  static int scsi_disk_emulate_start_stop(SCSIDiskReq *r)
                                  : SENSE_CODE(NOT_READY_REMOVAL_PREVENTED));
             return -1;
         }
-        bdrv_eject(s->qdev.conf.bs, !start);
-        s->tray_open = !start;
+
+        if (s->tray_open != !start) {
+            bdrv_eject(s->qdev.conf.bs, !start);
+            s->tray_open = !start;
+        }
     }
     return 0;
 }