From fe5c4cba737dbeb8ccd5d2c45fec8b72bac72794 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 14 Dec 2011 15:12:36 +0100 Subject: [PATCH 2/2] atapi: implement eject requests RH-Author: Paolo Bonzini Message-id: <1323875557-18796-3-git-send-email-pbonzini@redhat.com> Patchwork-id: 35815 O-Subject: [RHEL 6.3 qemu-kvm PATCH 2/3] atapi: implement eject requests Bugzilla: 739944 RH-Acked-by: Kevin Wolf RH-Acked-by: Markus Armbruster RH-Acked-by: Amit Shah Bugzilla: 739944 Implementing eject requests on IDE involves adding the new callback and reporting the event via GET EVENT STATUS NOTIFICATION. When force-ejecting, unlock the tray. Otherwise you end up with a locked, open tray that you cannot close back. Signed-off-by: Paolo Bonzini Signed-off-by: Kevin Wolf (cherry picked from upstream commit 2df0a3a3085adfde93505bc73c938310b0820c36) --- hw/ide/atapi.c | 11 ++++++++--- hw/ide/core.c | 13 +++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) Signed-off-by: Michal Novotny --- hw/ide/atapi.c | 11 ++++++++--- hw/ide/core.c | 13 +++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c index 6548c8e..e174feb 100644 --- a/hw/ide/atapi.c +++ b/hw/ide/atapi.c @@ -526,9 +526,14 @@ static unsigned int event_status_media(IDEState *s, /* Event notification descriptor */ event_code = MEC_NO_CHANGE; - if (media_status != MS_TRAY_OPEN && s->events.new_media) { - event_code = MEC_NEW_MEDIA; - s->events.new_media = false; + if (media_status != MS_TRAY_OPEN) { + if (s->events.new_media) { + event_code = MEC_NEW_MEDIA; + s->events.new_media = false; + } else if (s->events.eject_request) { + event_code = MEC_EJECT_REQUESTED; + s->events.eject_request = false; + } } buf[4] = event_code; diff --git a/hw/ide/core.c b/hw/ide/core.c index 5c3148f..83efe6e 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -865,6 +865,18 @@ static void ide_cd_change_cb(void *opaque, bool load) */ s->cdrom_changed = 1; s->events.new_media = true; + s->events.eject_request = false; + ide_set_irq(s->bus); +} + +static void ide_cd_eject_request_cb(void *opaque, bool force) +{ + IDEState *s = opaque; + + s->events.eject_request = true; + if (force) { + s->tray_locked = false; + } ide_set_irq(s->bus); } @@ -1819,6 +1831,7 @@ static bool ide_cd_is_medium_locked(void *opaque) static const BlockDevOps ide_cd_block_ops = { .change_media_cb = ide_cd_change_cb, + .eject_request_cb = ide_cd_eject_request_cb, .is_tray_open = ide_cd_is_tray_open, .is_medium_locked = ide_cd_is_medium_locked, }; -- 1.7.7.5