From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34239) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wsopl-0003Mx-4h for qemu-devel@nongnu.org; Fri, 06 Jun 2014 03:45:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wsope-0008Op-WA for qemu-devel@nongnu.org; Fri, 06 Jun 2014 03:45:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12912) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wsope-0008Ol-NK for qemu-devel@nongnu.org; Fri, 06 Jun 2014 03:44:58 -0400 Message-ID: <53917173.6060107@redhat.com> Date: Fri, 06 Jun 2014 09:44:51 +0200 From: Paolo Bonzini 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> In-Reply-To: <5390B486.6060800@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: Max Reitz , Stefan Hajnoczi Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, Stefan Hajnoczi 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. 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. Paolo