From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:53169) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoEla-0001cu-71 for qemu-devel@nongnu.org; Mon, 09 Jul 2012 10:16:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SoElT-00086S-T3 for qemu-devel@nongnu.org; Mon, 09 Jul 2012 10:16:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27022) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoElT-000863-Lo for qemu-devel@nongnu.org; Mon, 09 Jul 2012 10:16:39 -0400 From: Kevin Wolf Date: Mon, 9 Jul 2012 16:16:09 +0200 Message-Id: <1341843388-5663-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1341843388-5663-1-git-send-email-kwolf@redhat.com> References: <1341843388-5663-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 06/25] sheepdog: use coroutine based socket functions in coroutine context List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: MORITA Kazutaka This removes blocking network I/Os in coroutine context. Signed-off-by: MORITA Kazutaka Signed-off-by: Kevin Wolf --- block/sheepdog.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 0b49c6d..5dc1d7a 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -541,11 +541,18 @@ static coroutine_fn int send_co_req(int sockfd, SheepdogReq *hdr, void *data, return ret; } +static coroutine_fn int do_co_req(int sockfd, SheepdogReq *hdr, void *data, + unsigned int *wlen, unsigned int *rlen); + static int do_req(int sockfd, SheepdogReq *hdr, void *data, unsigned int *wlen, unsigned int *rlen) { int ret; + if (qemu_in_coroutine()) { + return do_co_req(sockfd, hdr, data, wlen, rlen); + } + socket_set_block(sockfd); ret = send_req(sockfd, hdr, data, wlen); if (ret < 0) { @@ -1642,7 +1649,6 @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, int ret; if (bs->growable && sector_num + nb_sectors > bs->total_sectors) { - /* TODO: shouldn't block here */ ret = sd_truncate(bs, (sector_num + nb_sectors) * SECTOR_SIZE); if (ret < 0) { return ret; @@ -1710,7 +1716,7 @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) hdr.opcode = SD_OP_FLUSH_VDI; hdr.oid = vid_to_vdi_oid(inode->vdi_id); - ret = do_co_req(s->flush_fd, (SheepdogReq *)&hdr, NULL, &wlen, &rlen); + ret = do_req(s->flush_fd, (SheepdogReq *)&hdr, NULL, &wlen, &rlen); if (ret) { error_report("failed to send a request to the sheep"); return ret; -- 1.7.6.5