Received: from eggs.gnu.org ([140.186.70.92]:37017) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QobUt-0000uR-St for qemu-devel@nongnu.org; Wed, 03 Aug 2011 09:28:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QobUs-0005ll-O6 for qemu-devel@nongnu.org; Wed, 03 Aug 2011 09:28:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6942) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QobUs-0005lg-Ct for qemu-devel@nongnu.org; Wed, 03 Aug 2011 09:28:30 -0400 From: Markus Armbruster References: <1311179069-27882-1-git-send-email-armbru@redhat.com> <1311179069-27882-45-git-send-email-armbru@redhat.com> Date: Wed, 03 Aug 2011 15:28:22 +0200 In-Reply-To: (andrzej zaborowski's message of "Wed, 3 Aug 2011 14:05:25 +0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: andrzej zaborowski Cc: kwolf@redhat.com, Peter Maydell , quintela@redhat.com, dbaryshkov@gmail.com, stefano.stabellini@eu.citrix.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, amit.shah@redhat.com andrzej zaborowski writes: > On 3 August 2011 10:12, Markus Armbruster wrote: >> Peter Maydell writes: >> >>> On 1 August 2011 13:33, Markus Armbruster wrote: >>>> andrzej zaborowski writes: >>>>> On 20 July 2011 18:24, Markus Armbruster wrote: >>>>>> We try the drive defined with -drive if=3Dide,index=3D0 (or equivale= nt >>>>>> sugar). =C2=A0We use it only if (dinfo && bdrv_is_inserted(dinfo->bd= rv) && >>>>>> !bdrv_is_removable(dinfo->bdrv)). =C2=A0This is a convoluted way to = test >>>>>> for "drive media can't be removed". >>>>>> >>>>>> The only way to create such a drive with -drive if=3Dide is media=3D= cdrom. >>>>>> And that sets dinfo->media_cd, so just test that. >>>>> >>>>> This is a less generic test and more prone to be broken inadvertently, >>>>> so it seems like a step back. =C2=A0What's the argument against the >>>>> convoluted and explicit test? >>>> >>>> My motivation for changing it was to reduce the uses of BlockDriverSta= te >>>> member removable prior to nuking it from orbit [PATCH 45/55]. >>>> >>>> I consider my change an improvement, because I find "dinfo->media_cd" >>>> clearer than >>>> "bdrv_is_inserted(dinfo->bdrv) && !bdrv_is_removable(dinfo->bdrv)". >>> >>> This seems like an argument for providing a bdrv_supports_eject() >>> or whatever we're actually trying to test for here. I kind of felt >>> the same way as Andrzej when I saw this patch going past but it >>> got lost in my mail folder... >> >> Well, what are you trying to test for here? >> >> Let's start with figuring out what we actually test for right now (may >> not be what you *want* to test for, but it's a start). =C2=A0The test co= de is >> "bdrv_is_inserted(bs) && !bdrv_is_removable(bs)". >> >> bdrv_is_removable() is a confused mess. =C2=A0It is true when an ide-cd, >> scsi-cd or floppy qdev is attached, or when the BlockDriverState was >> created with -drive if=3D{floppy,sd} or -drive >> if=3D{ide,scsi,xen,none},media=3Dcdrom, except when an ide-hd, scsi-hd, >> scsi-generic or virtio-blk qdev is attached. >> >> Since we're about to attach a device here, no other device can be >> attached, and the mess simplifies into "when the BlockDriverState was >> created with -drive if=3D{floppy,sd} or -drive >> if=3D{ide,scsi,xen,none},media=3Dcdrom". >> >> Since we're getting IF_IDE, it further simplifies into "when the >> BlockDriverState was created with -drive if=3Dide,media=3Dcdrom". > > What's wrong with that again? All sounds sensible to me. I'm not claiming otherwise, just double-checking this is what you want. >> Which is >> what my patch tests. > > It's like if you changed the named constants/#defines in a project for > their preprocessed values... Behaviour is preserved but it makes worse > code, and its easier to break too, when someone updates the value of > some constant. Well, you just said you want to check whether the drive was created as CD-ROM. The most direct way to check precisely that is drive->media_cd, and I can't see how that could break. If you can see how, please tell me. If you want to check for something else, please explain what you want. "Keep it the way it was" isn't an explanation. And keeping bdrv_is_removable() mess alive just for this one use would be silly. [...]