From patchwork Mon Jun 29 03:01:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 489197 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5C58A140271 for ; Mon, 29 Jun 2015 13:02:04 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=uDxTdeGa; dkim-atps=neutral Received: from localhost ([::1]:40417 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9PKc-0006uh-8M for incoming@patchwork.ozlabs.org; Sun, 28 Jun 2015 23:02:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9PKK-0006ch-Ub for qemu-devel@nongnu.org; Sun, 28 Jun 2015 23:01:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z9PKG-0006qS-Tn for qemu-devel@nongnu.org; Sun, 28 Jun 2015 23:01:44 -0400 Received: from mail-qc0-x234.google.com ([2607:f8b0:400d:c01::234]:36106) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9PKG-0006qK-MK; Sun, 28 Jun 2015 23:01:40 -0400 Received: by qczu9 with SMTP id u9so13391400qcz.3; Sun, 28 Jun 2015 20:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :message-id:references:to; bh=TvpkM6bBgtHLJYwZnvqr71eCtx6Mzf93P1DTGWSwyi8=; b=uDxTdeGabYD+SQ5C6LS0YfTDEIYn/vARrEuNaEqxd5e3hGqWQv7g4jNsbodv/PJZ2I aXaQwPQBMWdO0V6QjAbRb8onwvXds0L3EValefYpVRuIZPTqcUhJ2lwOw4shSbvPb53R P4L0w/HNezdNHt+XXxPGmBgwS/imxMFf8fGIGGmGffvG7pGFIeGI2PSf48/J4xMnjqz+ MAsPA5+vxO5Z4kPkKNpAumYCVSWBsQzeOB2DBR3Y/A1RubR6CECxQ/D5STGPBEHLSp1o th0xKIbdPpT+jLx67+ktlnh/s2B3VpNSnNjI7BsiZguL6FNkH7wNdzc6Cf9RDZ21N0LV yC5Q== X-Received: by 10.55.20.166 with SMTP id 38mr27511493qku.12.1435546900251; Sun, 28 Jun 2015 20:01:40 -0700 (PDT) Received: from [192.168.0.7] (d199-74-164-53.col.wideopenwest.com. [74.199.53.164]) by mx.google.com with ESMTPSA id 125sm1821986qhx.44.2015.06.28.20.01.36 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 28 Jun 2015 20:01:39 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1084) From: Programmingkid In-Reply-To: <55909167.8090803@redhat.com> Date: Sun, 28 Jun 2015 23:01:34 -0400 Message-Id: References: <3B3C7431-1003-4AAA-90AF-0E1A154DFBE2@gmail.com> <5589A026.5020800@redhat.com> <455CF92B-58FA-446D-9EB0-42661C23B739@gmail.com> <87pp4kxos3.fsf@blackfin.pond.sub.org> <7B989F99-B95C-4D53-AA2D-29B87634D2BB@gmail.com> <558C22BD.1020404@redhat.com> <558C2852.3050102@redhat.com> <47B5E901-9CCD-4737-A5F2-B790EBEF941A@gmail.com> <02818C70-4409-48F8-8776-0AB917B5A39F@gmail.com> <55909167.8090803@redhat.com> To: Laurent Vivier X-Mailer: Apple Mail (2.1084) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c01::234 Cc: Kevin Wolf , Peter Maydell , Qemu-block , qemu-devel qemu-devel , Markus Armbruster , Paolo Bonzini Subject: Re: [Qemu-devel] [PATCH] block.c: fix real cdrom detection X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Jun 28, 2015, at 8:29 PM, Laurent Vivier wrote: > Hi, > > On 29/06/2015 01:43, Programmingkid wrote: >> >> On Jun 25, 2015, at 2:01 PM, Peter Maydell wrote: >> >>> On 25 June 2015 at 18:56, Programmingkid >>> wrote: >>>> Nice to hear from you again Laurent. The only way a solution in >>>> hdev_open() would work is if it could prevent >>>> find_image_format() from executing. Otherwise find_image_format() >>>> would just quit QEMU with an error. >>> >>> The question you should be asking is "what is Linux doing for raw >>> CDROM devices that is different, such that it works there but >>> doesn't work on OSX?". >>> >>> It would also be helpful to know which is the case that doesn't >>> work. Does QEMU fail in all cases, or only if the cdrom drive is >>> empty, or only if there's a disk in the drive? >> >> QEMU fails if the cdrom is specified "-cdrom /dev/cdrom", and there >> is no cd in the drive. >> >> QEMU also fails with a real cdrom in the drive. >> >>> >>> My initial suspicion is that we need OSX support in raw-posix.c for >>> handling the host CDROM specially -- note that Linux and FreeBSD >>> register a bdrv_host_cdrom with an is_inserted function. >> >> The is_inserted function wouldn't make a difference. > > In fact, if your patch fixes the problem, the is_inserted with no > cdrom should too: > > with your " strcmp("/dev/cdrom", filename) == 0 ", you force the > selection of bdrv_raw (which is what to do). > > without your patch, if "bdrv_is_inserted()" was implemented and no cdrom > in the drive " !bdrv_is_inserted(bs) " should also select bdrv_raw. > > It appears also that bdrv_host_cdrom is not registered in > bdrv_file_init(). I think this is the missing part to have a host cdrom > support on MacOS X. > > Laurent This patch is what I came up with using your idea. It uses the fact that the bdrv_is_inserted() function is called first from find_image_format(). The bdrv_is_inserted() function now points to cdrom_is_inserted(). This new function will return 0 the first time it is called, then 1 after that. So far it works. --- block/raw-posix.c | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index a967464..2d35580 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -2324,6 +2324,23 @@ static int hdev_create(const char *filename, QemuOpts *opts, return ret; } +#ifdef __APPLE__ + +static int cdrom_is_inserted(BlockDriverState *bs) +{ + static int count = 0; + int returnValue = 1; + + if(count == 0) { + returnValue = 0; // get around find_image_format() issue + } + + printf("count = %d for %s, returning %d\n", count, bs->filename, returnValue); + count++; + return returnValue; +} +#endif + static BlockDriver bdrv_host_device = { .format_name = "host_device", .protocol_name = "host_device", @@ -2365,6 +2382,10 @@ static BlockDriver bdrv_host_device = { .bdrv_ioctl = hdev_ioctl, .bdrv_aio_ioctl = hdev_aio_ioctl, #endif + +#ifdef __APPLE__ + .bdrv_is_inserted = cdrom_is_inserted, +#endif }; #ifdef __linux__