From patchwork Wed Aug 3 13:07:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 108260 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 86E15B71E3 for ; Thu, 4 Aug 2011 01:06:16 +1000 (EST) Received: from localhost ([::1]:45510 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QobCD-00026Q-Sd for incoming@patchwork.ozlabs.org; Wed, 03 Aug 2011 09:09:13 -0400 Received: from eggs.gnu.org ([140.186.70.92]:47403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QobBb-0000In-Ia for qemu-devel@nongnu.org; Wed, 03 Aug 2011 09:08:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QobBV-0001A7-MF for qemu-devel@nongnu.org; Wed, 03 Aug 2011 09:08:35 -0400 Received: from oxygen.pond.sub.org ([78.46.104.156]:52262) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QobBV-00019B-Dr for qemu-devel@nongnu.org; Wed, 03 Aug 2011 09:08:29 -0400 Received: from blackfin.pond.sub.org (p5B32D904.dip.t-dialin.net [91.50.217.4]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 3F9A6A2C93; Wed, 3 Aug 2011 15:08:27 +0200 (CEST) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 165D560053; Wed, 3 Aug 2011 15:08:25 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 3 Aug 2011 15:07:52 +0200 Message-Id: <1312376904-16115-14-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1312376904-16115-1-git-send-email-armbru@redhat.com> References: <1312376904-16115-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 78.46.104.156 Cc: kwolf@redhat.com, quintela@redhat.com, stefano.stabellini@eu.citrix.com, lcapitulino@redhat.com, hare@suse.de, amit.shah@redhat.com, hch@lst.de Subject: [Qemu-devel] [PATCH v2 13/45] block: Revert entanglement of bdrv_is_inserted() with tray status 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 Commit 4be9762a changed bdrv_is_inserted() to fail when the tray is open. Unfortunately, there are two different kinds of users, with conflicting needs. 1. Device models using bdrv_eject(), currently ide-cd and scsi-cd. They expect bdrv_is_inserted() to reflect the tray status. Commit 4be9762a makes them happy. 2. Code that wants to know whether a BlockDriverState has media, such as find_image_format(), bdrv_flush_all(). Commit 4be9762a makes them unhappy. In particular, it breaks flush on VM stop for media ejected by the guest. Revert the change to bdrv_is_inserted(). Check the tray status in the device models instead. Note on IDE: Since only ATAPI devices have a tray, and they don't accept ATA commands since the recent commit "ide: Reject ATA commands specific to drive kinds", checking in atapi.c suffices. Signed-off-by: Markus Armbruster --- block.c | 7 +++---- hw/ide/atapi.c | 15 ++++++++------- hw/scsi-disk.c | 10 ++++++++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/block.c b/block.c index 17933c8..257aec8 100644 --- a/block.c +++ b/block.c @@ -2986,13 +2986,12 @@ static int coroutine_fn bdrv_co_flush_em(BlockDriverState *bs) int bdrv_is_inserted(BlockDriverState *bs) { BlockDriver *drv = bs->drv; - int ret; + if (!drv) return 0; if (!drv->bdrv_is_inserted) - return !bs->tray_open; - ret = drv->bdrv_is_inserted(bs); - return ret; + return 1; + return drv->bdrv_is_inserted(bs); } /** diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c index 96f7c31..08e1a7a 100644 --- a/hw/ide/atapi.c +++ b/hw/ide/atapi.c @@ -73,7 +73,7 @@ static void lba_to_msf(uint8_t *buf, int lba) static inline int media_present(IDEState *s) { - return (s->nb_sectors > 0); + return !s->tray_open && s->nb_sectors > 0; } /* XXX: DVDs that could fit on a CD will be reported as a CD */ @@ -1066,20 +1066,21 @@ static const struct { [ 0x03 ] = { cmd_request_sense, ALLOW_UA }, [ 0x12 ] = { cmd_inquiry, ALLOW_UA }, [ 0x1a ] = { cmd_mode_sense, /* (6) */ 0 }, - [ 0x1b ] = { cmd_start_stop_unit, 0 }, + [ 0x1b ] = { cmd_start_stop_unit, 0 }, /* [1] */ [ 0x1e ] = { cmd_prevent_allow_medium_removal, 0 }, [ 0x25 ] = { cmd_read_cdvd_capacity, CHECK_READY }, - [ 0x28 ] = { cmd_read, /* (10) */ 0 }, + [ 0x28 ] = { cmd_read, /* (10) */ CHECK_READY }, [ 0x2b ] = { cmd_seek, CHECK_READY }, [ 0x43 ] = { cmd_read_toc_pma_atip, CHECK_READY }, [ 0x46 ] = { cmd_get_configuration, ALLOW_UA }, [ 0x4a ] = { cmd_get_event_status_notification, ALLOW_UA }, [ 0x5a ] = { cmd_mode_sense, /* (10) */ 0 }, - [ 0xa8 ] = { cmd_read, /* (12) */ 0 }, - [ 0xad ] = { cmd_read_dvd_structure, 0 }, + [ 0xa8 ] = { cmd_read, /* (12) */ CHECK_READY }, + [ 0xad ] = { cmd_read_dvd_structure, CHECK_READY }, [ 0xbb ] = { cmd_set_speed, 0 }, [ 0xbd ] = { cmd_mechanism_status, 0 }, - [ 0xbe ] = { cmd_read_cd, 0 }, + [ 0xbe ] = { cmd_read_cd, CHECK_READY }, + /* [1] handler detects and reports not ready condition itself */ }; void ide_atapi_cmd(IDEState *s) @@ -1115,7 +1116,7 @@ void ide_atapi_cmd(IDEState *s) * GET_EVENT_STATUS_NOTIFICATION to detect such tray open/close * states rely on this behavior. */ - if (bdrv_is_inserted(s->bs) && s->cdrom_changed) { + if (!s->tray_open && bdrv_is_inserted(s->bs) && s->cdrom_changed) { ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT); s->cdrom_changed = 0; diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 2d5e157..db72b86 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -186,6 +186,9 @@ static void scsi_read_data(SCSIRequest *req) if (n > SCSI_DMA_BUF_SIZE / 512) n = SCSI_DMA_BUF_SIZE / 512; + if (s->tray_open) { + scsi_read_complete(r, -ENOMEDIUM); + } r->iov.iov_len = n * 512; qemu_iovec_init_external(&r->qiov, &r->iov, 1); r->req.aiocb = bdrv_aio_readv(s->bs, r->sector, &r->qiov, n, @@ -284,6 +287,9 @@ static void scsi_write_data(SCSIRequest *req) n = r->iov.iov_len / 512; if (n) { + if (s->tray_open) { + scsi_write_complete(r, -ENOMEDIUM); + } qemu_iovec_init_external(&r->qiov, &r->iov, 1); r->req.aiocb = bdrv_aio_writev(s->bs, r->sector, &r->qiov, n, scsi_write_complete, r); @@ -844,7 +850,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf) switch (req->cmd.buf[0]) { case TEST_UNIT_READY: - if (!bdrv_is_inserted(s->bs)) + if (s->tray_open || !bdrv_is_inserted(s->bs)) goto not_ready; break; case REQUEST_SENSE: @@ -987,7 +993,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf) return buflen; not_ready: - if (!bdrv_is_inserted(s->bs)) { + if (s->tray_open || !bdrv_is_inserted(s->bs)) { scsi_command_complete(r, CHECK_CONDITION, SENSE_CODE(NO_MEDIUM)); } else { scsi_command_complete(r, CHECK_CONDITION, SENSE_CODE(LUN_NOT_READY));