From patchwork Wed Apr 27 13:43:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 93051 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C2450B6F12 for ; Wed, 27 Apr 2011 23:41:04 +1000 (EST) Received: from localhost ([::1]:54032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QF4zD-0005Rr-4P for incoming@patchwork.ozlabs.org; Wed, 27 Apr 2011 09:40:59 -0400 Received: from eggs.gnu.org ([140.186.70.92]:51737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QF4z0-0005Rk-PC for qemu-devel@nongnu.org; Wed, 27 Apr 2011 09:40:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QF4yx-0007m8-2X for qemu-devel@nongnu.org; Wed, 27 Apr 2011 09:40:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37056) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QF4yw-0007m4-PB for qemu-devel@nongnu.org; Wed, 27 Apr 2011 09:40:43 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3RDeeN9011456 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 27 Apr 2011 09:40:40 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p3RDeaVS016837; Wed, 27 Apr 2011 09:40:39 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Wed, 27 Apr 2011 15:43:01 +0200 Message-Id: <1303911790-27422-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1303911790-27422-1-git-send-email-kwolf@redhat.com> References: <1303911790-27422-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 02/11] atapi: Add 'medium ready' to 'medium not ready' transition on cd change X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Amit Shah MMC-5 Table F.1 lists errors that can be thrown for the TEST_UNIT_READY command. Going from medium not ready to medium ready states is communicated by throwing an error. This adds the missing 'tray opened' event that we fail to report to guests. After doing this, older Linux guests properly revalidate a disc on the change command. HSM violation errors, which caused Linux guests to do a soft-reset of the link, also go away: ata2.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x6 sr 1:0:0:0: CDB: Test Unit Ready: 00 00 00 00 00 00 ata2.00: cmd a0/00:00:00:00:00/00:00:00:00:00/a0 tag 0 res 01/60:00:00:00:00/00:00:00:00:00/a0 Emask 0x3 (HSM violation) ata2.00: status: { ERR } ata2: soft resetting link ata2.00: configured for MWDMA2 ata2: EH complete Signed-off-by: Amit Shah Acked-by: Jes Sorensen Tested-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/ide/core.c | 20 ++++++++++++++++---- 1 files changed, 16 insertions(+), 4 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index f028ddb..d8c613a 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1248,12 +1248,19 @@ static void ide_atapi_cmd(IDEState *s) ide_atapi_cmd_check_status(s); return; } + if (bdrv_is_inserted(s->bs) && s->cdrom_changed) { + ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT); + + s->cdrom_changed = 0; + s->sense_key = SENSE_UNIT_ATTENTION; + s->asc = ASC_MEDIUM_MAY_HAVE_CHANGED; + return; + } switch(s->io_buffer[0]) { case GPCMD_TEST_UNIT_READY: - if (bdrv_is_inserted(s->bs) && !s->cdrom_changed) { + if (bdrv_is_inserted(s->bs)) { ide_atapi_cmd_ok(s); } else { - s->cdrom_changed = 0; ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT); } @@ -1734,8 +1741,13 @@ static void cdrom_change_cb(void *opaque, int reason) bdrv_get_geometry(s->bs, &nb_sectors); s->nb_sectors = nb_sectors; - s->sense_key = SENSE_UNIT_ATTENTION; - s->asc = ASC_MEDIUM_MAY_HAVE_CHANGED; + /* + * First indicate to the guest that a CD has been removed. That's + * done on the next command the guest sends us. + * + * Then we set SENSE_UNIT_ATTENTION, by which the guest will + * detect a new CD in the drive. See ide_atapi_cmd() for details. + */ s->cdrom_changed = 1; s->events.new_media = true; ide_set_irq(s->bus);