From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=42900 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLaLh-0004wb-W5 for qemu-devel@nongnu.org; Mon, 07 Jun 2010 07:18:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLaLc-0001vM-Kq for qemu-devel@nongnu.org; Mon, 07 Jun 2010 07:18:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4840) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLaLc-0001v9-E1 for qemu-devel@nongnu.org; Mon, 07 Jun 2010 07:18:28 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o57BIRVW014271 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 7 Jun 2010 07:18:27 -0400 Message-ID: <4C0CD574.2020404@redhat.com> Date: Mon, 07 Jun 2010 13:18:12 +0200 From: Kevin Wolf MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] monitor: allow device to be ejected if no disk is inserted References: <20100601221219.GB13961@blackpad.lan.raisama.net> In-Reply-To: <20100601221219.GB13961@blackpad.lan.raisama.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Markus Armbruster , Eduardo Habkost , Luiz Capitulino Am 02.06.2010 00:12, schrieb Eduardo Habkost: > Resubmitting a patch that was submitted in December[1]. It was on the staging > tree but somehow it got dropped. I have rebased it to current master branch on > git. > > [1] http://article.gmane.org/gmane.comp.emulators.qemu/59813 > > -------- > > This changes the monitor eject_device() function to not check for > bdrv_is_inserted(). > > Example run where the bug manifests itself: > > (output of 'info block' is stripped to include only the CD-ROM device) > > (qemu) info block > ide1-cd0: type=cdrom removable=1 locked=0 [not inserted] > (qemu) change ide1-cd0 /dev/cdrom host_cdrom > (qemu) info block > ide1-cd0: type=cdrom removable=1 locked=0 file=/dev/cdrom ro=1 drv=host_cdrom encrypted=0 > (qemu) eject ide1-cd0 > (qemu) info block > ide1-cd0: type=cdrom removable=1 locked=0 file=/dev/cdrom ro=1 drv=host_cdrom encrypted=0 > > # at this point, a disk was inserted on the host CD-ROM drive > > (qemu) info block > ide1-cd0: type=cdrom removable=1 locked=0 file=/dev/cdrom ro=1 drv=host_cdrom encrypted=0 > (qemu) eject ide1-cd0 > (qemu) info block > ide1-cd0: type=cdrom removable=1 locked=0 [not inserted] > (qemu) > > The first eject command didn't work because the is_inserted() check > failed. But does it really make a difference? The guest should not see a medium before and it should not see one afterwards. > I have no clue why the code had the is_inserted() check, as it doesn't matter > if there is a disk present at the host drive, when the user wants the virtual > device to be disconnected from the host device. The question is what the semantics of the eject monitor command is supposed to be. I for one would have expected that it means that if there was a medium inserted in the virtual CD-ROM drive, it won't be there afterwards. I wouldn't have expected the connection to the host device to be affected. Actually, what I would have expected is not calling bdrv_close(), but calling bdrv_eject() and possibly doing something with the device state to reflect that. If the VM gets a real CD-ROM passed through, eject for the virtual device should just mean eject for the real device. > The is_inserted() check has another side effect: a memory leak if the "change" > command is used multiple times, as do_change() calls eject_device() before > re-opening the block device, but bdrv_close() is never called. In the context of do_change the desired semantics is probably a different one, I agree. It probably shouldn't call do_eject. Kevin