public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: "David S. Ahern" <daahern@cisco.com>
To: Matt Burkhardt <mlb@imparisystems.com>
Cc: kvm@vger.kernel.org
Subject: Re: Mount and unmount CD
Date: Fri, 23 Apr 2010 12:18:45 -0600	[thread overview]
Message-ID: <4BD1E485.2090104@cisco.com> (raw)
In-Reply-To: <1272035406.2911.16.camel@mlb-dell>

[-- Attachment #1: Type: text/plain, Size: 986 bytes --]

I saw this with RHEL5.3. I ended up hacking qemu to re_open the CD every
so often. See attached.

David


On 04/23/2010 09:10 AM, Matt Burkhardt wrote:
> I'm having a problem with a virtual machine running under RHEL 5.4
> 64-bit.  I take out the CD / insert a new and the main machine sees the
> new cd and makes it available.  However, the virtual machines still see
> the old CD.  I've tried mounting the new CD, but it just keeps mounting
> what it "thinks" is in there - the old one.
> 
> Any ideas?
> 
> 
> Matt Burkhardt
> Impari Systems, Inc.
> 
> mlb@imparisystems.com
> http://www.imparisystems.com 
> http://www.linkedin.com/in/mlburkhardt 
> http://www.twitter.com/matthewboh
> 502 Fairview Avenue
> Frederick, MD  21701
> work (301) 682-7901
> cell   (301) 802-3235
> 
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

[-- Attachment #2: qemu-cdrom-flush.patch --]
[-- Type: text/plain, Size: 2571 bytes --]

--- 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);
     }
 }

  reply	other threads:[~2010-04-23 18:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-23 15:10 Mount and unmount CD Matt Burkhardt
2010-04-23 18:18 ` David S. Ahern [this message]
2010-04-23 18:52   ` David S. Ahern
     [not found]     ` <1272209538.8137.7.camel@mlb-dell>
2010-04-25 15:45       ` Mount and unmount CD Bug reporting David S. Ahern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BD1E485.2090104@cisco.com \
    --to=daahern@cisco.com \
    --cc=kvm@vger.kernel.org \
    --cc=mlb@imparisystems.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox