From patchwork Thu Oct 24 04:56:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dietmar Maurer X-Patchwork-Id: 1182628 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=proxmox.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46zFNB3HXnz9sPc for ; Thu, 24 Oct 2019 15:57:12 +1100 (AEDT) Received: from localhost ([::1]:60004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNVBM-00077K-Ic for incoming@patchwork.ozlabs.org; Thu, 24 Oct 2019 00:57:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51211) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNVAi-00076o-Md for qemu-devel@nongnu.org; Thu, 24 Oct 2019 00:56:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNVAh-0002N1-8l for qemu-devel@nongnu.org; Thu, 24 Oct 2019 00:56:28 -0400 Received: from 212-186-127-178.static.upcbusiness.at ([212.186.127.178]:39081 helo=rtest1.maurer-it.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1iNVAg-0002Go-Uw for qemu-devel@nongnu.org; Thu, 24 Oct 2019 00:56:27 -0400 Received: by rtest1.maurer-it.com (Postfix, from userid 0) id 0516E500AE8; Thu, 24 Oct 2019 06:56:16 +0200 (CEST) From: Dietmar Maurer To: qemu-devel@nongnu.org Subject: [PATCH v4] yield_until_fd_readable: make it work with any AioContect Date: Thu, 24 Oct 2019 06:56:10 +0200 Message-Id: <20191024045610.9071-1-dietmar@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.186.127.178 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dietmar Maurer , stefanha@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Simply use qemu_get_current_aio_context(). Signed-off-by: Dietmar Maurer --- Changelog for v4: - avoid unsafe cast and keep fd_coroutine_enter() Changelog for v3: - use (IOHandler *) instead of ((void (*)(void *)) - coding style: fix max line length Changelog for v2: - use correct read handler in aio_set_fd_handler (instead of write handler) util/qemu-coroutine-io.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/util/qemu-coroutine-io.c b/util/qemu-coroutine-io.c index 44a8969a69..5b80bb416f 100644 --- a/util/qemu-coroutine-io.c +++ b/util/qemu-coroutine-io.c @@ -67,6 +67,7 @@ qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool do_send) } typedef struct { + AioContext *ctx; Coroutine *co; int fd; } FDYieldUntilData; @@ -74,7 +75,7 @@ typedef struct { static void fd_coroutine_enter(void *opaque) { FDYieldUntilData *data = opaque; - qemu_set_fd_handler(data->fd, NULL, NULL, NULL); + aio_set_fd_handler(data->ctx, data->fd, false, NULL, NULL, NULL, NULL); qemu_coroutine_enter(data->co); } @@ -83,8 +84,10 @@ void coroutine_fn yield_until_fd_readable(int fd) FDYieldUntilData data; assert(qemu_in_coroutine()); + data.ctx = qemu_get_current_aio_context(); data.co = qemu_coroutine_self(); data.fd = fd; - qemu_set_fd_handler(fd, fd_coroutine_enter, NULL, &data); + aio_set_fd_handler( + data.ctx, fd, false, fd_coroutine_enter, NULL, NULL, &data); qemu_coroutine_yield(); }