From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WtMHF-0006lG-MB for qemu-devel@nongnu.org; Sat, 07 Jun 2014 15:27:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WtMH9-0003O2-HX for qemu-devel@nongnu.org; Sat, 07 Jun 2014 15:27:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40840) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WtMH9-0003Ny-BS for qemu-devel@nongnu.org; Sat, 07 Jun 2014 15:27:35 -0400 Message-ID: <5393679E.9080900@redhat.com> Date: Sat, 07 Jun 2014 21:27:26 +0200 From: Max Reitz MIME-Version: 1.0 References: <1401561792-13410-1-git-send-email-mreitz@redhat.com> <1401561792-13410-4-git-send-email-mreitz@redhat.com> <20140604123748.GD11073@stefanha-thinkpad.redhat.com> <5390B486.6060800@redhat.com> <53917173.6060107@redhat.com> In-Reply-To: <53917173.6060107@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC 3/5] nbd: Use aio_set_fd_handler2() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , Stefan Hajnoczi Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, Stefan Hajnoczi On 06.06.2014 09:44, Paolo Bonzini wrote: > Il 05/06/2014 20:18, Max Reitz ha scritto: >>> >>> Why is this design cleaner? Because NBD code doesn't have to worry >>> about fd handlers. It uses straightforward coroutine send/recv for >>> socket I/O inside nbd_read_req() and nbd_write_resp(). It's easy to >>> see >>> that only one coroutine receives from the socket and that only one >>> coroutine writes to the socket. >> >> Yes, this sounds better. I'll take a look into it and see how far I can >> get. > > But it doesn't solve any problem, and requires rethinking the > aio_set_fd_handler API. It might clean things up. :-) On the other hand, you are right, it's probably too complicated right now. > I suggest you just refactor all calls to qemu_set_fd_handler2 into a > function like > > qemu_set_fd_handler2(fd, NULL, > nbd_can_read(client) ? nbd_read : NULL, > client->send_coroutine ? > nbd_restart_write : NULL, > opaque); > > and call this function every time the result of nbd_can_read() > changes. Then you can switch to aio_set_fd_handler easily. Seems good, I'll do that. Max