From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xg9TZ-0005iF-Dt for qemu-devel@nongnu.org; Mon, 20 Oct 2014 05:42:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xg9TS-0001oP-Vm for qemu-devel@nongnu.org; Mon, 20 Oct 2014 05:42:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63266) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xg9TS-0001nj-O0 for qemu-devel@nongnu.org; Mon, 20 Oct 2014 05:41:58 -0400 Date: Mon, 20 Oct 2014 11:41:49 +0200 From: Kevin Wolf Message-ID: <20141020094149.GC3585@noname.redhat.com> References: <54423AC9.2030302@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <54423AC9.2030302@huawei.com> Subject: Re: [Qemu-devel] Close the BlockDriverState when guest eject the media List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Weidong Huang Cc: "qemu-devel@nongnu.org" , stefanha@redhat.com, armbru@redhat.com Am 18.10.2014 um 12:02 hat Weidong Huang geschrieben: > Hi ALL: > > There are two ways to eject the cdrom tray. One is by the eject's qmp commmand(eject_device). > The another one is by the guest(bdrv_eject). They have different results. Yes, they are different things. If a guest opens the tray (using bdrv_eject) and then closes it again, with no user interaction in between, the virtual media must still be in the drive and the guest must be able to access the same image again. Calling bdrv_close() in this case would be a bug. The goal of the monitor command "eject" on the other hand is to remove the medium so that the drive is empty. That a device with a closed tray has to be opened for this is only secondary. > eject_device: close the BlockDriverState(bdrv_close(bs)) > bdrv_eject: don't close the BlockDriverState, > > This is ambiguous. So libvirt can't handle some situations. > > libvirt send eject qmp command ---> qemu send eject request to guest ---> > guest respond to qemu ---> qemu emit tray_open event to libvirt ---> > libvirt will not send change qmp command if media source is null. So > the media is not be replace to the null. What is the problem that libvirt has with the guest opening the tray? I don't think libvirt should even care about that case. Kevin > So close the BlockDriverState in bdrv_eject. Thanks. > > diff --git a/block.c b/block.c > index d3aebeb..0be69de 100644 > --- a/block.c > +++ b/block.c > @@ -5276,6 +5276,10 @@ void bdrv_eject(BlockDriverState *bs, bool eject_flag) > qapi_event_send_device_tray_moved(bdrv_get_device_name(bs), > eject_flag, &error_abort); > } > + > + if (eject_flag) { > + bdrv_close(bs); > + } > } >