[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v3] make windows notice media change

From: Filip Navara
Subject: Re: [Qemu-devel] [PATCH v3] make windows notice media change
Date: Wed, 29 Jul 2009 23:04:14 +0200

2009/7/29 Gleb Natapov <address@hidden>:
> On Wed, Jul 29, 2009 at 08:43:29PM +0200, Filip Navara wrote:
>> 2009/7/29 Gleb Natapov <address@hidden>:
>> > On Wed, Jul 29, 2009 at 07:10:29PM +0200, Filip Navara wrote:
>> >> On Wed, Jul 29, 2009 at 6:09 PM, Gleb Natapov<address@hidden> wrote:
>> >> > @@ -3250,6 +3253,8 @@ static int pci_ide_load(QEMUFile* f, void 
>> >> > *opaque, int version_id)
>> >> >     /* per IDE drive data */
>> >> >     for(i = 0; i < 4; i++) {
>> >> >         ide_load(f, &d->ide_if[i]);
>> >> > +        if (version_id == 3)
>> >> > +            qemu_get_8s(f, &d->ide_if[i].cdrom_changed);
>> >> >     }
>> >> >     return 0;
>> >> >  }
>> >>
>> >> I'd prefer passing the version to ide_load and doing the actual load 
>> >> there...
>> >>
>> > Then you'll break ide_load for md ad pmac.
>> You would actually unbreak the PowerMAC code. It should save the
>> cdrom_changed flag the same way as the PC version does.
> Except pmac protocol version is different from pci protocol version.

There's no reason not to jump directly from version 1 to version 3.

>> >> ... but the patch is all wrong and based on wrong assumptions, which is
>> >> much more fundamental problem. Windows cdrom driver is not that stupid
>> >> about the change as you think.
>> > Have you seen the code? How do you know?
>> Yes, I did. It's part of Windows DDK and it has been there at least since NT 
>> 4.
> And you holding all of the detail of this particular code in your head?

No. I read the code 4 years ago, so obviously I was unsure about it
now, so I looked it up. That's why it took me few hours to respond on
the patch.

> Please educate us what QEMU currently does wrong that prevent smart
> Windows code from working? This allegedly smart code polls cdrom like crazy 
> BTW.

I didn't say it is smart, what I said is that it is not as stupid as
you claim it is. I also wanted to know why it does the polling, but I
don't know the answer for that question.

>> >> The cdrom driver really has a timer and polls the IDE controller, but it
>> >> doesn't require the intermediate ASC_MEDIUM_NOT_PRESENT state
>> >> you introduced. It's perfectly ok to return SENSE_UNIT_ATTENTION /
>> > I have
>> >> and Windows will recognize it as medium change.
>> >>
>> >> Something like this should work:
>> >>         if (bdrv_is_inserted(s->bs)) {
>> >>             if (s->cdrom_changed) {
>> >>                 ide_atapi_cmd_error(s, SENSE_UNIT_ATTENTION,
>> >>                                  ASC_MEDIUM_MAY_HAVE_CHANGED);
>> >>                 s->cdrom_changed = 0;
>> >>             } else {
>> >>                 ide_atapi_cmd_ok(s);
>> >>             }
>> >>         } else {
>> >>             ide_atapi_cmd_error(s, SENSE_NOT_READY,
>> >>                                 ASC_MEDIUM_NOT_PRESENT);
>> >>         }
>> >>
>> >> The benefit is that it will not break guests which issue the request only
>> >> once.
>> >>
>> >  10.8.26 TEST UNIT READY Command
>> >  The TEST UNIT READY command provides a means to check if the Device is
>> >  ready. This is not a request for a self-test. If the Device would accept
>> >  an appropriate medium-access command without returning CHECK CONDITION
>> >  status, this command shall return a GOOD status. If the Device cannot
>> >  become operational or is in a state such that an Host Computer action
>> >  (e.g. START/STOP UNIT command with LoEj = 0 & Start = 1) is required to
>> >  make the unit ready, the ATAPI CD-ROM Drive shall return CHECK CONDITION
>> >  status with a sense key of NOT READY.
>> >
>> > No mentioning of returning MEDIUM MAY HAVE CHANGED from UNIT READY
>> > command, so you code it already incorrect. So what should be done in
>> > this case. Here is what spec says and code actually implements:
>> Well, my suggestion is wrong, because I didn't read the QEMU IDE code
>> carefully. It should return GOOD status, which is what ide_atapi_cmd_ok
>> already did. Notice that ide_atapi_cmd_ok doesn't set s->sense_key and
>> s->asc, so the values from cdrom_change_cb should be preserved and
>> Windows driver would still happily received the "MEDIUM MAY HAVE
>> CHANGED" code. So I wonder what really fails?
> Please go and read QEMU IDE code once more. Read spec. Run guest and see
> what it does. What I see from doing all this is that after setting
> sense_key in cdrom_change_cb() Windows issues UNIT READY call which is
> _not_ executed according to the spec

The code is spread across several drivers and the IDE one is not part of the DDK
examples. From what I can see the there is no code for handling
SENSE_UNIT_ATTENTION which didn't result from a command explicitly
sent to the ATAPI drive, so what you see is the periodic timer which issues the

Even if this wasn't according to the IDE spec. the code seems to be able to
recover from error and read the sense data stored in sense_key and asc state
anyway. ide_atapi_cmd_check_status doesn't clear them. I will check it
once I get my Windows installation ready.

> , but ide_atapi_cmd_check_status()
> is executed instead. After that windows correctly calls REQUEST SENSE

The REQUEST SENSE is probably the one resulting from the issued
TEST UNIT READY command in the cdrom driver, this is usual behavior
of the scsiport driver (which is responsible for all the SCSI requests in

> At this point condition is cleared.

In GPCMD_REQUEST_SENSE handler, right?

Hmm, now it makes me wonder if the REQUEST SENSE was really
the one resulting from the TEST UNIT READY request in cdrom
driver or if it got lost somewhere.

> Then Windows calls UNIT READY once again and at this point
> ide_atapi_cmd_ok() is called without sense_key set.

This one must be from the next timer expiration, the TEST UNIT
READY command is never reissued for the single expiration.

Thanks for the explanation. I will try to reproduce it and see if I can
make any SENSE out of it.

>> >  10.6 Unit Attention Condition
>> >  If an Host Computer issues a command other than INQUIRY or REQUEST SENSE
>> >  while a unit attention condition exists for that Host, the ATAPI CD-ROM
>> >  Drive shall not perform the command and shall report CHECK CONDITION
>> >  status unless a higher priority status as defined by the ATAPI CD-ROM
>> >  Drive is also pending (e.g. BUSY).

Actually the Windows behavior is compliant with this. It issues
different command
from INQUIRY / REQUEST SENSE and is supposed to deal with the failure.

>> > Cool. So Windows calls REQUEST SENSE after seeing CHECK CONDITION. Gets
>> > MEDIUM MAY HAVE CHANGED calls TEST UNIT once again see that media is
>> > present and thinks that CDROM gone crazy.
>> >
>> > If you claim that my fix is incorrect (it may very well be) please
>> > provide working tested solution compliant to spec.
>> I'm no IDE expert, but your change is workaround that may break
>> well-behaved guests
>> because the TEST_UNIT_READY code will intentionally return wrong result and 
>> the
>> guest has no reason to retry the query. The fact that Windows driver
>> has a timer and
>> eventually re-queries the status is something one shouldn't depend on.
> With that I agree. My log message clearly states that this is a
> workaround since QEMU code look correct to me (also not ATAPI expert).
> And I agree with your concern too. It easily fixed by running a short
> timer that will reinject SENSE UNIT ATTENTION interrupt after returning
> NOT PRESENT status if there is a need, but for now I didn't wanted to
> complicate the logic.

I believe the logic can actually be simplified, if we can find the root cause
of the problem.

>> If I knew how to patch it properly I would have done, but I don't. I'm
>> more than willing
>> to explain how Windows behaves, but I can't any patches at the moment
>> since I have
>> no Windows virtual machine ready for testing.
> You can look at DDK code at tell us were QEMU device emulation is wrong.
> After this patch will be applied of cause. Just claiming things without
> even looking at spec doesn't help.

I did look at the DDK code and I read the spec. It's not like my claims were
not backed with some actual reading, my suggested fix was. I'm glad you
provided me with the information that could be used for me better
understanding the problem. Hopefully I can come up with some patch or
further information within few days.

Best regards,
Filip Navara

reply via email to

[Prev in Thread] Current Thread [Next in Thread]