On Thu, Mar 31, 2011 at 10:53 AM, Amit Shah <amit.s...@redhat.com> wrote:
>> = Amit =
>>
>> Found that 2.6.38 and later guest kernels fail to report media change.
>
> It's not 2.6.38 and later; it's somewhere around the time libata was
> introduced and CDROM emulation went from ide to scsi in the kernel.
> All current kernels (2.6.32 onwards) have this behaviour.
>
> Also, this looks like it's due to multiple emulation bugs in QEMU:
>
> - Command 46 (GET_CONFIGURATION) handles only specific cases.  The
>  ones that aren't handled are the ones invoked by the guest kernel.
>
> - Command 0 (TEST_UNIT_READY) replies with an error message if there's
>  no medium instead of sending a reply with the no medium message.
>  This causes the guest to do a soft-reset (invoking the HSM violation
>  error message).
>
> - Command 4a (GET_EVENT_STATUS_NOTIFICATION) is not implemented by us
>  at all.
>
> All these commands are marked as mandatory to be implemented by devices.
>
> The commit Gleb pointed to in another message in this thread may have
> something to do with media change not getting propogated as well:
>
>
>    case GPCMD_TEST_UNIT_READY:
>        if (bdrv_is_inserted(s->bs) && !s->cdrom_changed) {
>            ide_atapi_cmd_ok(s);
>        } else {
>            s->cdrom_changed = 0;
>            ide_atapi_cmd_error(s, SENSE_NOT_READY,
>                                ASC_MEDIUM_NOT_PRESENT);
>        }
>        break;
>
> Here, if cdrom got changed, we return an error message to the guest
> instead of sending a UNIT_READY with UNIT_ATTENTION message.  So the
> guest does its soft-reset thing, due to which the guest never then
> notices the UNIT_ATTENTION pending message, causing the guest to think
> it's still the same media in the device.

Linux 2.6.32 sr_media_change() expects the ASC_MEDIUM_NOT_PRESENT error:

        retval = sr_test_unit_ready(cd->device, sshdr);
        if (retval || (scsi_sense_valid(sshdr) &&
                       /* 0x3a is medium not present */
                       sshdr->asc == 0x3a)) {
                /* Media not present or unable to test, unit probably not
                 * ready. This usually means there is no disc in the drive.
                 * Mark as changed, and we will figure it out later once
                 * the drive is available again.
                 */
                cd->device->changed = 1;

Next time sr_media_change() is called and TUR returns success it
notices the medium has been changed.  This code path is invoked from
cdrom_open(), i.e. every time hald/udisks polls the CD-ROM device.

My understanding is that this mechanism works under QEMU today.  Can
you help me understand what I'm missing?

>>  The new in-kernel media change polling framework issues ATAPI
>> commands which are not implemented in hw/ide/core.c.
>
> The in-kernel media change polling has nothing to do with our
> emulation or the commands, btw.

Yes it does, it the in-kernel polling relies on
GET_EVENT_STATUS_NOTIFICATION which was previously not critical (TUR
was used instead as mentioned above).

Stefan

Reply via email to