From patchwork Fri Apr 23 18:18:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "David S. Ahern" X-Patchwork-Id: 94739 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o3NIIolx028743 for ; Fri, 23 Apr 2010 18:18:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751589Ab0DWSSr (ORCPT ); Fri, 23 Apr 2010 14:18:47 -0400 Received: from sj-iport-1.cisco.com ([171.71.176.70]:15087 "EHLO sj-iport-1.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751306Ab0DWSSq (ORCPT ); Fri, 23 Apr 2010 14:18:46 -0400 Authentication-Results: sj-iport-1.cisco.com; dkim=neutral (message not signed) header.i=none X-Files: qemu-cdrom-flush.patch : 2571 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAHOB0UurR7Ht/2dsb2JhbACDFpkWcaQ5iGmRQoJxgS1tBIM3 X-IronPort-AV: E=Sophos;i="4.52,263,1270425600"; d="scan'208";a="319979257" Received: from sj-core-1.cisco.com ([171.71.177.237]) by sj-iport-1.cisco.com with ESMTP; 23 Apr 2010 18:18:46 +0000 Received: from [10.89.10.142] ([10.89.10.142]) by sj-core-1.cisco.com (8.13.8/8.14.3) with ESMTP id o3NIIjwt006226; Fri, 23 Apr 2010 18:18:45 GMT Message-ID: <4BD1E485.2090104@cisco.com> Date: Fri, 23 Apr 2010 12:18:45 -0600 From: "David S. Ahern" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100330 Fedora/3.0.4-1.fc12 Thunderbird/3.0.4 MIME-Version: 1.0 To: Matt Burkhardt CC: kvm@vger.kernel.org Subject: Re: Mount and unmount CD References: <1272035406.2911.16.camel@mlb-dell> In-Reply-To: <1272035406.2911.16.camel@mlb-dell> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 23 Apr 2010 18:19:04 +0000 (UTC) --- qemu/block-raw-posix.c.orig 2010-01-06 22:27:56.000000000 -0700 +++ qemu/block-raw-posix.c 2010-01-06 22:29:51.000000000 -0700 @@ -193,20 +193,40 @@ static int raw_pread_aligned(BlockDriverState *bs, int64_t offset, uint8_t *buf, int count) { BDRVRawState *s = bs->opaque; int ret; ret = fd_open(bs); if (ret < 0) return ret; + /* media changes are only detected at the host layer when + * somethin reopens the cdrom device. Without an event + * notice, we need a heuristic. Try the following which mimics + * what is done for floppy drives. Here we reopen the cdrom + * after 3 seconds of elapsed time - this should be short + * enough to cover a user inserting a new disk and then accessing + * it via the CLI/GUI. + */ + if (bs->type == BDRV_TYPE_CDROM) { + static int64_t last = 0; + int64_t now = qemu_get_clock(rt_clock); + if ((now - last) > 3000) + ret = cdrom_reopen(bs); + else + ret = 0; + last = now; + if (ret < 0) + return ret; + } + if (offset >= 0 && lseek(s->fd, offset, SEEK_SET) == (off_t)-1) { ++(s->lseek_err_cnt); if(s->lseek_err_cnt <= 10) { DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 "] lseek failed : %d = %s\n", s->fd, bs->filename, offset, buf, count, bs->total_sectors, errno, strerror(errno)); } return -1; } --- qemu/hw/ide.c.orig 2010-01-06 22:28:02.000000000 -0700 +++ qemu/hw/ide.c 2010-01-06 22:30:45.000000000 -0700 @@ -1456,20 +1456,28 @@ s->cd_sector_size = sector_size; /* XXX: check if BUSY_STAT should be set */ s->status = READY_STAT | SEEK_STAT | DRQ_STAT | BUSY_STAT; ide_dma_start(s, ide_atapi_cmd_read_dma_cb); } static void ide_atapi_cmd_read(IDEState *s, int lba, int nb_sectors, int sector_size) { + if (s->is_cdrom) { + static int64_t last = 0; + int64_t now = qemu_get_clock(rt_clock); + if ((now - last) > 3000) + (void) cdrom_reopen(s->bs); + last = now; + } + #ifdef DEBUG_IDE_ATAPI printf("read %s: LBA=%d nb_sectors=%d\n", s->atapi_dma ? "dma" : "pio", lba, nb_sectors); #endif if (s->atapi_dma) { ide_atapi_cmd_read_dma(s, lba, nb_sectors, sector_size); } else { ide_atapi_cmd_read_pio(s, lba, nb_sectors, sector_size); } }