From patchwork Thu Nov 26 13:09:25 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naphtali Sprei X-Patchwork-Id: 39509 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 5AC9F1007D1 for ; Fri, 27 Nov 2009 00:12:22 +1100 (EST) Received: from localhost ([127.0.0.1]:46096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDe8x-0005Ju-1v for incoming@patchwork.ozlabs.org; Thu, 26 Nov 2009 08:12:19 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDe6P-0004WT-7b for qemu-devel@nongnu.org; Thu, 26 Nov 2009 08:09:41 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDe6K-0004UV-EQ for qemu-devel@nongnu.org; Thu, 26 Nov 2009 08:09:40 -0500 Received: from [199.232.76.173] (port=45243 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDe6K-0004UQ-6o for qemu-devel@nongnu.org; Thu, 26 Nov 2009 08:09:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16316) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDe6I-00056i-U6 for qemu-devel@nongnu.org; Thu, 26 Nov 2009 08:09:35 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAQD9SlW023902 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 26 Nov 2009 08:09:28 -0500 Received: from [10.35.0.60] (dhcp-0-60.tlv.redhat.com [10.35.0.60]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAQD9P0H031733 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 26 Nov 2009 08:09:27 -0500 Message-ID: <4B0E7E05.4070402@redhat.com> Date: Thu, 26 Nov 2009 15:09:25 +0200 From: Naphtali Sprei User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: qemu-devel@nongnu.org X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH] 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 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 Signed-off-by: Naphtali Sprei --- 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 3286ba2..69c50f8 100644 --- a/monitor.c +++ b/monitor.c @@ -567,6 +567,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; }