From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhHcE-000725-DF for qemu-devel@nongnu.org; Mon, 05 May 2014 08:03:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WhHc1-00074K-Lo for qemu-devel@nongnu.org; Mon, 05 May 2014 08:03:26 -0400 Received: from mail-we0-x22d.google.com ([2a00:1450:400c:c03::22d]:34121) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhHc1-00073p-FB for qemu-devel@nongnu.org; Mon, 05 May 2014 08:03:13 -0400 Received: by mail-we0-f173.google.com with SMTP id u57so846197wes.4 for ; Mon, 05 May 2014 05:03:12 -0700 (PDT) Date: Mon, 5 May 2014 14:03:09 +0200 From: Stefan Hajnoczi Message-ID: <20140505120309.GB16173@stefanha-thinkpad.redhat.com> References: <1398956086-20171-1-git-send-email-stefanha@redhat.com> <1398956086-20171-19-git-send-email-stefanha@redhat.com> <20140504101745.GG1124@T430.nay.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140504101745.GG1124@T430.nay.redhat.com> Subject: Re: [Qemu-devel] [PATCH 18/22] vmdk: implement .bdrv_detach/attach_aio_context() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: Kevin Wolf , "Shergill, Gurinder" , qemu-devel@nongnu.org, Stefan Hajnoczi , Paolo Bonzini , "Vinod, Chegu" On Sun, May 04, 2014 at 06:17:45PM +0800, Fam Zheng wrote: > On Thu, 05/01 16:54, Stefan Hajnoczi wrote: > > @@ -2118,6 +2139,8 @@ static BlockDriver bdrv_vmdk = { > > .bdrv_has_zero_init = vmdk_has_zero_init, > > .bdrv_get_specific_info = vmdk_get_specific_info, > > .bdrv_refresh_limits = vmdk_refresh_limits, > > + .bdrv_detach_aio_context = vmdk_detach_aio_context, > > + .bdrv_attach_aio_context = vmdk_attach_aio_context, > > > > .create_options = vmdk_create_options, > > }; > > -- > > I'm wondering why we need to separate detach and attach as two functions, and > also add bdrv_set_aio_context in block.c, instead of a single > .bdrv_set_aio_context member which is called in bdrv_set_aio_context()? The > latter seems less code. I can see it working either way, but here is why I chose to keep them separate: The detach/attach happens in two phases: 1. Parents are detached before child nodes - just in case the parent still needs the child in order to detach. 2. The new AioContext is acquired and then children are attached before their parent nodes - that way the parent knows it can already use its children during attach. Acquiring the new AioContext for the minimum amount of time (attach only) seems like a good idea. Remember the AioContext may be responsible for other I/O devices too so we should minimize the scope of acquire/release. Doing it all in a single .bdrv_set_aio_context() forces detach to happen while the new AioContext is held. Another reason why separate detach/attach is nice is that it allows block drivers to avoid code duplication. .bdrv_open() calls attach() and .bdrv_close() calls detach(). A single .bdrv_set_aio_context() function would need extra code to deal with the open (currently not attached) and close (don't attach to a new context) scenarios. Stefan