From nobody Mon Feb 9 23:04:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500263773175693.0048595133907; Sun, 16 Jul 2017 20:56:13 -0700 (PDT) Received: from localhost ([::1]:47767 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWx8l-0006SI-Q3 for importer@patchew.org; Sun, 16 Jul 2017 23:56:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42552) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWx1j-0000uO-Us for qemu-devel@nongnu.org; Sun, 16 Jul 2017 23:48:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dWx1f-0004f8-FB for qemu-devel@nongnu.org; Sun, 16 Jul 2017 23:48:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56592) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dWx1f-0004ev-8u for qemu-devel@nongnu.org; Sun, 16 Jul 2017 23:48:51 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C5657EBD2; Mon, 17 Jul 2017 03:48:50 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-94.pek2.redhat.com [10.72.12.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id C469260F88; Mon, 17 Jul 2017 03:48:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2C5657EBD2 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2C5657EBD2 From: Fam Zheng To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 11:48:21 +0800 Message-Id: <20170717034825.1524-12-famz@redhat.com> In-Reply-To: <20170717034825.1524-1-famz@redhat.com> References: <20170717034825.1524-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 17 Jul 2017 03:48:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 11/15] ssh: support I/O from any AioContext X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini The coroutine may run in a different AioContext, causing the fd handler to busy wait. Fix this by resetting the handler in restart_coroutine, before the coroutine is restarted. Reviewed-by: Stefan Hajnoczi Reviewed-by: Fam Zheng Signed-off-by: Paolo Bonzini Message-Id: <20170629132749.997-12-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/ssh.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index 07a57eb..e8f0404 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -888,13 +888,22 @@ static int ssh_has_zero_init(BlockDriverState *bs) return has_zero_init; } =20 +typedef struct BDRVSSHRestart { + BlockDriverState *bs; + Coroutine *co; +} BDRVSSHRestart; + static void restart_coroutine(void *opaque) { - Coroutine *co =3D opaque; + BDRVSSHRestart *restart =3D opaque; + BlockDriverState *bs =3D restart->bs; + BDRVSSHState *s =3D bs->opaque; + AioContext *ctx =3D bdrv_get_aio_context(bs); =20 - DPRINTF("co=3D%p", co); + DPRINTF("co=3D%p", restart->co); + aio_set_fd_handler(ctx, s->sock, false, NULL, NULL, NULL, NULL); =20 - aio_co_wake(co); + aio_co_wake(restart->co); } =20 /* A non-blocking call returned EAGAIN, so yield, ensuring the @@ -905,7 +914,10 @@ static coroutine_fn void co_yield(BDRVSSHState *s, Blo= ckDriverState *bs) { int r; IOHandler *rd_handler =3D NULL, *wr_handler =3D NULL; - Coroutine *co =3D qemu_coroutine_self(); + BDRVSSHRestart restart =3D { + .bs =3D bs, + .co =3D qemu_coroutine_self() + }; =20 r =3D libssh2_session_block_directions(s->session); =20 @@ -920,11 +932,9 @@ static coroutine_fn void co_yield(BDRVSSHState *s, Blo= ckDriverState *bs) rd_handler, wr_handler); =20 aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock, - false, rd_handler, wr_handler, NULL, co); + false, rd_handler, wr_handler, NULL, &restart); qemu_coroutine_yield(); DPRINTF("s->sock=3D%d - back", s->sock); - aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock, false, - NULL, NULL, NULL, NULL); } =20 /* SFTP has a function `libssh2_sftp_seek64' which seeks to a position --=20 2.9.4