Received: from eggs.gnu.org ([2001:4830:134:3::10]:54604) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9dvh-0006SA-Nj for qemu-devel@nongnu.org; Mon, 29 Jun 2015 14:37:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z9dvg-0002os-JC for qemu-devel@nongnu.org; Mon, 29 Jun 2015 14:37:17 -0400 Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: multipart/alternative; boundary=Apple-Mail-4--118189133 From: Programmingkid In-Reply-To: Date: Mon, 29 Jun 2015 14:37:07 -0400 Message-Id: <36A983F7-2A97-4130-9179-FA614ACEBAA0@gmail.com> References: Subject: Re: [Qemu-devel] [PATCH] raw-posix.c: cd_is_inserted() implementation for Mac OS X List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Kevin Wolf , qemu-devel qemu-devel , Qemu-block --Apple-Mail-4--118189133 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On Jun 29, 2015, at 2:16 PM, Peter Maydell wrote: > On 29 June 2015 at 19:04, Programmingkid = wrote: >>=20 >> On Jun 29, 2015, at 1:11 PM, Peter Maydell wrote: >>=20 >>> On 29 June 2015 at 17:54, Programmingkid = wrote: >>>> @@ -2365,6 +2384,10 @@ static BlockDriver bdrv_host_device =3D { >>>> .bdrv_ioctl =3D hdev_ioctl, >>>> .bdrv_aio_ioctl =3D hdev_aio_ioctl, >>>> #endif >>>> + >>>> +#ifdef __APPLE__ >>>> + .bdrv_is_inserted =3D cdrom_is_inserted, >>>> +#endif >>>=20 >>> Why isn't this handled by having a bdrv_host_cdrom, >>> like Linux and FreeBSD do for their CDROM support? >>=20 >> That would involve a lot of unnecessary work and modifications. This >> small change is all that is needed. >=20 > Yes, but it's obviously wrong, because this: >=20 > + if (count =3D=3D 0) { > + count++; > + returnValue =3D 0; /* get around find_image_format() issue */ > + } >=20 > makes no sense at all -- this means that we'll always report "drive > empty" the first time this function is called. We should always > report the correct answer, regardless of who's calling us. >=20 > If you find yourself writing this kind of weird workaround, it > generally suggests that the change is a "this happens to make it > work" patch, not the correct fix for the problem. We need clean > fixes in QEMU, because if we allow "happens to make it work" > patches to pile up then the whole system becomes unmaintainable. > Yes, this often means that the amount of work required to > fix a bug is more than a handful of lines. That doesn't mean > that the work is unnecessary. >=20 > (For instance, what happens if somebody changes some other > part of QEMU so that it happens that find_image_format() is not > the first thing to call this function?) >=20 > We know the correct way to support host cdrom drives, because > we're already doing that on Linux. We should consistently > support host cdrom drives the same way for all hosts. I have really tried to find out what was wrong. It is a asynchronous, multi-threaded mess. Trying to follow where QEMU messes up=20 was hard. The closest I came to was to a function called=20 bdrv_co_io_em(). It was returning a value of -22.=20 If some change does happen to make this patch to=20 not work anymore, I can easily fix it.=20= --Apple-Mail-4--118189133 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
On 29 June 2015 at 19:04, Programmingkid <programmingkidx@gmail.com>= ; wrote:

On Jun 29, 2015, at 1:11 PM, Peter Maydell = wrote:

On 29 June 2015 at 17:54, Programmingkid <programmingkidx@gmail.com>= ; wrote:
@@ = -2365,6 +2384,10 @@ static BlockDriver bdrv_host_device =3D = {
=    .bdrv_ioctl =         =3D = hdev_ioctl,
=    .bdrv_aio_ioctl     =3D = hdev_aio_ioctl,
#endif
+
+#ifdef = __APPLE__
+ =    .bdrv_is_inserted   =3D = cdrom_is_inserted,
+#endif

Why isn't this handled by having = a bdrv_host_cdrom,
like Linux and FreeBSD do for = their CDROM support?

That would = involve a lot of unnecessary work and modifications. = This
small change is all that = is needed.

Yes, but it's obviously wrong, because = this:

+    if (count =3D=3D 0) {
+ =        count++;
+ =        returnValue =3D 0; /* get = around find_image_format() issue */
+ =    }

makes no sense at all -- this means that = we'll always report "drive
empty" the first time this function is = called. We should always
report the correct answer, regardless of = who's calling us.

If you find yourself writing this kind of weird = workaround, it
generally suggests that the change is a "this happens = to make it
work" patch, not the correct fix for the problem. We need = clean
fixes in QEMU, because if we allow "happens to make it = work"
patches to pile up then the whole system becomes = unmaintainable.
Yes, this often means that the amount of work = required to
fix a bug is more than a handful of lines. That doesn't = mean
that the work is unnecessary.

(For instance, what happens = if somebody changes some other
part of QEMU so that it happens that = find_image_format() is not
the first thing to call this = function?)

We know the correct way to support host cdrom drives, = because
we're already doing that on Linux. We should = consistently
support host cdrom drives the same way for all = hosts.

I have really tried to find = out what was wrong. It is a asynchronous,
multi-threaded mess. = Trying to follow where QEMU messes up 
was hard. The = closest I came to was to a function called