From patchwork Thu Dec 3 16:33:21 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 40181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AC27BB7BBD for ; Fri, 4 Dec 2009 03:35:47 +1100 (EST) Received: from localhost ([127.0.0.1]:39364 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NGEee-0000JW-SV for incoming@patchwork.ozlabs.org; Thu, 03 Dec 2009 11:35:44 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NGEcW-0007i7-7o for qemu-devel@nongnu.org; Thu, 03 Dec 2009 11:33:32 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NGEcR-0007eY-MI for qemu-devel@nongnu.org; Thu, 03 Dec 2009 11:33:31 -0500 Received: from [199.232.76.173] (port=58399 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NGEcR-0007eM-GR for qemu-devel@nongnu.org; Thu, 03 Dec 2009 11:33:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16513) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NGEcR-0000B8-14 for qemu-devel@nongnu.org; Thu, 03 Dec 2009 11:33:27 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB3GXOQ6029811 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 3 Dec 2009 11:33:24 -0500 Received: from blackpad.lan.raisama.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB3GXMZD011694; Thu, 3 Dec 2009 11:33:23 -0500 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id C62AC17FDE7; Thu, 3 Dec 2009 14:33:21 -0200 (BRST) From: Eduardo Habkost To: Anthony Liguori Date: Thu, 3 Dec 2009 14:33:21 -0200 Message-Id: <1259858001-1273-3-git-send-email-ehabkost@redhat.com> In-Reply-To: <1259858001-1273-1-git-send-email-ehabkost@redhat.com> References: <1259858001-1273-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Naphtali Sprei , qemu-devel@nongnu.org, Luiz Capitulino Subject: [Qemu-devel] [PATCH 2/2] Fix for cdrom un-eject X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Naphtali Sprei When guest un-eject a cdrom, re-insert the cdrom image (re-open the drive's file). Also, related changes for the un-eject: o enter UNIT ATTENTION state only on change/insert media, not upon removal o minor change in packet command abort when in UNIT ATTENTION state (as per spec) o enter UNIT ATTENTION state upon reset (as per spec) o always print the file-name in info block command (if applicable) Relevant Spec: Mt. Fuji Commands for Multimedia Devices Version 7: ftp://ftp.seagate.com/sff/INF-8090.PDF [ehabkost: solved conficts on monitor.c eject_device()] Signed-off-by: Naphtali Sprei Signed-off-by: Eduardo Habkost --- block.c | 24 ++++++++++++++++++++---- block.h | 1 + block_int.h | 1 + hw/ide/core.c | 35 +++++++++++++++++++++++++---------- monitor.c | 1 + 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/block.c b/block.c index 6fdabff..1801569 100644 --- a/block.c +++ b/block.c @@ -463,6 +463,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, ret = drv->bdrv_open(bs, filename, open_flags & ~BDRV_O_RDWR); bs->read_only = 1; } + bs->open_flags = flags; if (ret < 0) { qemu_free(bs->opaque); bs->opaque = NULL; @@ -1155,9 +1156,11 @@ void bdrv_info(Monitor *mon) if (bs->removable) { monitor_printf(mon, " locked=%d", bs->locked); } - if (bs->drv) { + if (bs->filename[0]) { monitor_printf(mon, " file="); monitor_print_filename(mon, bs->filename); + } + if (bs->drv) { if (bs->backing_file[0] != '\0') { monitor_printf(mon, " backing_file="); monitor_print_filename(mon, bs->backing_file); @@ -1907,14 +1910,27 @@ int bdrv_eject(BlockDriverState *bs, int eject_flag) ret = drv->bdrv_eject(bs, eject_flag); } if (ret == -ENOTSUP) { - if (eject_flag) + if (eject_flag) { bdrv_close(bs); - ret = 0; + ret = 0; + } else { /* re-insert media */ + if (bs->filename[0]) { + ret = bdrv_open(bs, bs->filename, bs->open_flags); + } else { + ret = 0; + } + } } - + return ret; } + +void bdrv_forget_fname(BlockDriverState *bs) +{ + bs->filename[0] = '\0'; +} + int bdrv_is_locked(BlockDriverState *bs) { return bs->locked; diff --git a/block.h b/block.h index 2d4f066..8fc10d2 100644 --- a/block.h +++ b/block.h @@ -147,6 +147,7 @@ int bdrv_media_changed(BlockDriverState *bs); int bdrv_is_locked(BlockDriverState *bs); void bdrv_set_locked(BlockDriverState *bs, int locked); int bdrv_eject(BlockDriverState *bs, int eject_flag); +void bdrv_forget_fname(BlockDriverState *bs); 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/block_int.h b/block_int.h index 7ebe926..1ecf7bf 100644 --- a/block_int.h +++ b/block_int.h @@ -137,6 +137,7 @@ struct BlockDriverState { void *opaque; char filename[1024]; + int open_flags; char backing_file[1024]; /* if non zero, the image is a diff of this file image */ char backing_format[16]; /* if non-zero and backing_file exists */ diff --git a/hw/ide/core.c b/hw/ide/core.c index 7b1ff8f..5631898 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -35,6 +35,20 @@ #include + +static int is_pcommand_abort_on_check(uint8_t pcmd) { + int ret = 1; + + if (pcmd == GPCMD_GET_CONFIGURATION || + pcmd == GPCMD_REQUEST_SENSE || + pcmd == GPCMD_INQUIRY) { + ret = 0; + } + return ret; +} + + + static int smart_attributes[][5] = { /* id, flags, val, wrst, thrsh */ { 0x01, 0x03, 0x64, 0x64, 0x06}, /* raw read */ @@ -1206,12 +1220,11 @@ static void ide_atapi_cmd(IDEState *s) } #endif /* If there's a UNIT_ATTENTION condition pending, only - REQUEST_SENSE and INQUIRY commands are allowed to complete. */ + REQUEST_SENSE and INQUIRY commands (and some more) are allowed to complete. */ if (s->sense_key == SENSE_UNIT_ATTENTION && - s->io_buffer[0] != GPCMD_REQUEST_SENSE && - s->io_buffer[0] != GPCMD_INQUIRY) { - ide_atapi_cmd_check_status(s); - return; + is_pcommand_abort_on_check(s->io_buffer[0])) { + ide_atapi_cmd_check_status(s); + return; } switch(s->io_buffer[0]) { case GPCMD_TEST_UNIT_READY: @@ -1676,9 +1689,11 @@ static void cdrom_change_cb(void *opaque) 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; - s->cdrom_changed = 1; + if (nb_sectors > 0) { /* UNIT_ATTENTION only for insertion/change, not removal */ + s->sense_key = SENSE_UNIT_ATTENTION; + s->asc = ASC_MEDIUM_MAY_HAVE_CHANGED; + s->cdrom_changed = 1; + } ide_set_irq(s->bus); } @@ -2530,8 +2545,8 @@ static void ide_reset(IDEState *s) s->lba48 = 0; /* ATAPI specific */ - s->sense_key = 0; - s->asc = 0; + s->sense_key = SENSE_UNIT_ATTENTION; + s->asc = 0x29; /* POWER ON, RESET, OR BUS DEVICE RESET OCCURRED */ s->cdrom_changed = 0; s->packet_transfer_size = 0; s->elementary_transfer_size = 0; diff --git a/monitor.c b/monitor.c index d882c51..6135ead 100644 --- a/monitor.c +++ b/monitor.c @@ -752,6 +752,7 @@ static int eject_device(Monitor *mon, BlockDriverState *bs, int force) } } bdrv_close(bs); + bdrv_forget_fname(bs); /* "manual" eject forgets the file-name */ return 0; }