From nobody Wed May 15 09:52:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693325267; cv=none; d=zohomail.com; s=zohoarc; b=RSf0dVe/LbSwWi0q/Xc6y5iQ0pqAgpkGocw4a6mECF6ypTKVwUgsAcfia5TgKq8J+kZ3w2xWBXIon+csZ5FZFepuCBav795K5DE5SzrA+0+Rb6oOpiACEAGuuQFMFK8t8fHjaCp9sfWUzSogqkEsEBpdFSTGVi16TZ+lax7Evos= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693325267; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zuhjGRh7yCVcdFHjq6sVrr2QSG6ibDVXOpmvzu8ZeMk=; b=RykiGqkK+c+akBZ5UrL0tM8MOm/DZNDAa5iQQkek75lNSeLM4fhfFTR7HnTSTAmqYoYsVta94upNx/5dfHnYhGUShK5QYWDvmQBAmFx5zYWCsx+ZGa9Qx1LXMRy5XmyAb5/Xt5RGF9uDqs7tSiCCiO9ueGSTTtE3ypQSEsQEzhM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693325267762519.0847606768613; Tue, 29 Aug 2023 09:07:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb1Ej-00078g-AU; Tue, 29 Aug 2023 12:06:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qb1Eg-000788-Kf for qemu-devel@nongnu.org; Tue, 29 Aug 2023 12:06:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qb1Ee-0002eX-Cs for qemu-devel@nongnu.org; Tue, 29 Aug 2023 12:06:34 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-32-rXf3QvEAMoaAFp7oEQ5CAw-1; Tue, 29 Aug 2023 12:06:29 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4CB6085C70E; Tue, 29 Aug 2023 16:06:28 +0000 (UTC) Received: from localhost (unknown [10.39.195.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id C185D5CC01; Tue, 29 Aug 2023 16:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693325191; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zuhjGRh7yCVcdFHjq6sVrr2QSG6ibDVXOpmvzu8ZeMk=; b=COf+ZVMDDHg+4AmhO8SFda5wQ3gRpt7kFU+ZuraN7W+6GhRNnYY6CssUXO3LLsO2iVdneB 44RA5mrmtaN3mF34wlmIY7V03uIehpxZs2Ab+k9Dr6vE/LiANiXED8cJKQm38+PsFknu+l /ok+gSJOglyXjyNjlaWTv6/5lCZp1KI= X-MC-Unique: rXf3QvEAMoaAFp7oEQ5CAw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Leonardo Bras , eblake@redhat.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , farosas@suse.de, kwolf@redhat.com, Peter Xu , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , Juan Quintela , qemu-block@nongnu.org, Coiby Xu , Fam Zheng , Hanna Reitz , Stefan Hajnoczi Subject: [PATCH v2 1/4] nbd: drop unused nbd_receive_negotiate() aio_context argument Date: Tue, 29 Aug 2023 12:06:19 -0400 Message-ID: <20230829160623.277411-2-stefanha@redhat.com> In-Reply-To: <20230829160623.277411-1-stefanha@redhat.com> References: <20230829160623.277411-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693325269499100016 Content-Type: text/plain; charset="utf-8" aio_context is always NULL, so drop it. Suggested-by: Fabiano Rosas Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/block/nbd.h | 3 +-- nbd/client-connection.c | 3 +-- nbd/client.c | 5 ++--- qemu-nbd.c | 4 ++-- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 4428bcffbb..f672b76173 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -324,8 +324,7 @@ typedef struct NBDExportInfo { char **contexts; } NBDExportInfo; =20 -int nbd_receive_negotiate(AioContext *aio_context, QIOChannel *ioc, - QCryptoTLSCreds *tlscreds, +int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, NBDExportInfo *info, Error **errp); void nbd_free_export_list(NBDExportInfo *info, int count); diff --git a/nbd/client-connection.c b/nbd/client-connection.c index 3d14296c04..aafb3d0fb4 100644 --- a/nbd/client-connection.c +++ b/nbd/client-connection.c @@ -146,8 +146,7 @@ static int nbd_connect(QIOChannelSocket *sioc, SocketAd= dress *addr, return 0; } =20 - ret =3D nbd_receive_negotiate(NULL, QIO_CHANNEL(sioc), tlscreds, - tlshostname, + ret =3D nbd_receive_negotiate(QIO_CHANNEL(sioc), tlscreds, tlshostname, outioc, info, errp); if (ret < 0) { /* diff --git a/nbd/client.c b/nbd/client.c index 479208d5d9..16ec10c8a9 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -1014,8 +1014,7 @@ static int nbd_negotiate_finish_oldstyle(QIOChannel *= ioc, NBDExportInfo *info, * Returns: negative errno: failure talking to server * 0: server is connected */ -int nbd_receive_negotiate(AioContext *aio_context, QIOChannel *ioc, - QCryptoTLSCreds *tlscreds, +int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, NBDExportInfo *info, Error **errp) { @@ -1027,7 +1026,7 @@ int nbd_receive_negotiate(AioContext *aio_context, QI= OChannel *ioc, assert(info->name && strlen(info->name) <=3D NBD_MAX_STRING_SIZE); trace_nbd_receive_negotiate_name(info->name); =20 - result =3D nbd_start_negotiate(aio_context, ioc, tlscreds, hostname, o= utioc, + result =3D nbd_start_negotiate(NULL, ioc, tlscreds, hostname, outioc, info->structured_reply, &zeroes, errp); if (result < 0) { return result; diff --git a/qemu-nbd.c b/qemu-nbd.c index aaccaa3318..b47459f781 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -295,8 +295,8 @@ static void *nbd_client_thread(void *arg) goto out; } =20 - if (nbd_receive_negotiate(NULL, QIO_CHANNEL(sioc), - NULL, NULL, NULL, &info, &local_error) < 0) { + if (nbd_receive_negotiate(QIO_CHANNEL(sioc), NULL, NULL, NULL, + &info, &local_error) < 0) { if (local_error) { error_report_err(local_error); } --=20 2.41.0 From nobody Wed May 15 09:52:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693325267; cv=none; d=zohomail.com; s=zohoarc; b=cS7vZPVx4QQY3hxhJrh/hMn8vExKTwfiCEKvCDA1YtCrEOrhiVqE3QVDAfdgkdObULq6VhpqWh67M/w9cFe9usqvf3utV4oKAbazeZ4nC4lvuTQsz1meuTuuLW8XfN8Q58BKVvgKC18oI4+ayi9NzWihaLrKrv+9hQ5xCggN5Ag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693325267; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f8gQEQZFbJz851gMAxlrbEWVAGA7PIQfI9u3ENDQ7KQ=; b=kQASYrVdnPbt2ehTaix4pdS7UIgcN9pQKgkIXS+/s4fDJEBUh71COTusozuMo8WwCgYOHaE4QSEsLod8YhxJz1VnDCFvke2eyxizzTkVFc2amzAPyAgHvhwtK9InFEIqTn4rL5xlsVrdhi7BNo0xqLHhCH6S4N5P66Kgj9alDqE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16933252677161017.7345769425625; Tue, 29 Aug 2023 09:07:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb1Ey-0007Bm-IP; Tue, 29 Aug 2023 12:06:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qb1Eq-0007Ay-1N for qemu-devel@nongnu.org; Tue, 29 Aug 2023 12:06:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qb1El-0002l8-SH for qemu-devel@nongnu.org; Tue, 29 Aug 2023 12:06:42 -0400 Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-1-g248c82qMvm5YAGn30045w-1; Tue, 29 Aug 2023 12:06:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D42883C147E9; Tue, 29 Aug 2023 16:06:30 +0000 (UTC) Received: from localhost (unknown [10.39.195.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59E6D6B2AC; Tue, 29 Aug 2023 16:06:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693325199; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f8gQEQZFbJz851gMAxlrbEWVAGA7PIQfI9u3ENDQ7KQ=; b=Fx6L7HphV1btTgpwQgCeXuyXf6uekOxUm1qcOYPTWcMtNbaByMbQWHKcGFJQW2Z/20wIzN xoFxWiG1nsFGZt6hCELa51RdbOl9Gr55hiSvnxqqA8jqalbNROLP9V+YBtbbYYmaeLcujR iIU6cr5DqwnStePBTQLQ7gNdE8hjyrI= X-MC-Unique: g248c82qMvm5YAGn30045w-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Leonardo Bras , eblake@redhat.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , farosas@suse.de, kwolf@redhat.com, Peter Xu , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , Juan Quintela , qemu-block@nongnu.org, Coiby Xu , Fam Zheng , Hanna Reitz , Stefan Hajnoczi Subject: [PATCH v2 2/4] nbd: drop unused nbd_start_negotiate() aio_context argument Date: Tue, 29 Aug 2023 12:06:20 -0400 Message-ID: <20230829160623.277411-3-stefanha@redhat.com> In-Reply-To: <20230829160623.277411-1-stefanha@redhat.com> References: <20230829160623.277411-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693325268587100010 Content-Type: text/plain; charset="utf-8" aio_context is always NULL, so drop it. Suggested-by: Fabiano Rosas Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- nbd/client.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 16ec10c8a9..bd7e200136 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -877,8 +877,7 @@ static int nbd_list_meta_contexts(QIOChannel *ioc, * Returns: negative errno: failure talking to server * non-negative: enum NBDMode describing server abilities */ -static int nbd_start_negotiate(AioContext *aio_context, QIOChannel *ioc, - QCryptoTLSCreds *tlscreds, +static int nbd_start_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, bool structured_reply, bool *zeroes, Error **errp) @@ -946,10 +945,6 @@ static int nbd_start_negotiate(AioContext *aio_context= , QIOChannel *ioc, return -EINVAL; } ioc =3D *outioc; - if (aio_context) { - qio_channel_set_blocking(ioc, false, NULL); - qio_channel_attach_aio_context(ioc, aio_context); - } } else { error_setg(errp, "Server does not support STARTTLS"); return -EINVAL; @@ -1026,7 +1021,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLS= Creds *tlscreds, assert(info->name && strlen(info->name) <=3D NBD_MAX_STRING_SIZE); trace_nbd_receive_negotiate_name(info->name); =20 - result =3D nbd_start_negotiate(NULL, ioc, tlscreds, hostname, outioc, + result =3D nbd_start_negotiate(ioc, tlscreds, hostname, outioc, info->structured_reply, &zeroes, errp); if (result < 0) { return result; @@ -1149,7 +1144,7 @@ int nbd_receive_export_list(QIOChannel *ioc, QCryptoT= LSCreds *tlscreds, QIOChannel *sioc =3D NULL; =20 *info =3D NULL; - result =3D nbd_start_negotiate(NULL, ioc, tlscreds, hostname, &sioc, t= rue, + result =3D nbd_start_negotiate(ioc, tlscreds, hostname, &sioc, true, NULL, errp); if (tlscreds && sioc) { ioc =3D sioc; --=20 2.41.0 From nobody Wed May 15 09:52:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693325266; cv=none; d=zohomail.com; s=zohoarc; b=cuRq6QC4ID4glpKIH5KlmA55/BTNJoWqf6/pNIIwA8kjE2Fkq5mVqC+bvIkBhhQTAsRdXZJzYcRCyDFVF3GmUNw16Hi/HzDv2EcN2FKqHBoTVNm6wZTf5DQdRcxvWF9sDGKYJbf0LLdCwRdzGm8feRsW4urKIWgUHaf8xubWQXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693325266; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Rje/ITqNXJ/6Ru0HFlJBMqtFHqIeokN2njMddGzffg8=; b=I3fo81TKgDuq0RYDVvsahJvP2uOK/plZJNBXEHTtyXxuxzVZOf3bFaRtf8AtP3DHdrSFUO1f3K7skTSv748J9IkJgknHFsn1w03RhKHFfxFQNoO9kNe/qAa4E+OIg/bRfXl0gpBzkksB0KwuCal4ttRYjxK6HBIdEWp4mBCi+TU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169332526633483.59772774506962; Tue, 29 Aug 2023 09:07:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb1Em-00079d-Jd; Tue, 29 Aug 2023 12:06:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qb1El-000793-7Y for qemu-devel@nongnu.org; Tue, 29 Aug 2023 12:06:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qb1Ej-0002iy-8S for qemu-devel@nongnu.org; Tue, 29 Aug 2023 12:06:39 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-145-2w300XchNzu5GiC43VQBoQ-1; Tue, 29 Aug 2023 12:06:34 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 09815803E2E; Tue, 29 Aug 2023 16:06:33 +0000 (UTC) Received: from localhost (unknown [10.39.195.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83812492C13; Tue, 29 Aug 2023 16:06:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693325196; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rje/ITqNXJ/6Ru0HFlJBMqtFHqIeokN2njMddGzffg8=; b=e+mEl5vCzNoHbXdNvm6YsumkXp8hpr3CvobyYtd2KkYka9UGLZNIlGoWdmQLKQSX0cRGpZ amwd/bSU64DHrZlCeCIhg+DKNIcdyNkn7U6VYi31VbdIA694/02VoVW8GQsktzQEz3h/fn 9RaSsVnHV2ZAFKuAT16xs2+gVL6geTU= X-MC-Unique: 2w300XchNzu5GiC43VQBoQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Leonardo Bras , eblake@redhat.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , farosas@suse.de, kwolf@redhat.com, Peter Xu , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , Juan Quintela , qemu-block@nongnu.org, Coiby Xu , Fam Zheng , Hanna Reitz , Stefan Hajnoczi Subject: [PATCH v2 3/4] io: check there are no qio_channel_yield() coroutines during ->finalize() Date: Tue, 29 Aug 2023 12:06:21 -0400 Message-ID: <20230829160623.277411-4-stefanha@redhat.com> In-Reply-To: <20230829160623.277411-1-stefanha@redhat.com> References: <20230829160623.277411-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693325267051100001 Callers must clean up their coroutines before calling object_unref(OBJECT(ioc)) to prevent an fd handler leak. Add an assertion to check this. This patch is preparation for the fd handler changes that follow. Signed-off-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Eric Blake --- io/channel.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/io/channel.c b/io/channel.c index 72f0066af5..c415f3fc88 100644 --- a/io/channel.c +++ b/io/channel.c @@ -653,6 +653,10 @@ static void qio_channel_finalize(Object *obj) { QIOChannel *ioc =3D QIO_CHANNEL(obj); =20 + /* Must not have coroutines in qio_channel_yield() */ + assert(!ioc->read_coroutine); + assert(!ioc->write_coroutine); + g_free(ioc->name); =20 #ifdef _WIN32 --=20 2.41.0 From nobody Wed May 15 09:52:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693325266; cv=none; d=zohomail.com; s=zohoarc; b=jw4+rEpWjfsoFhSKJilfQs8qvNUh6CcO0hg48WGTLOz0+7DOZFUm1+Z3iaFbmiFcsDHtgrzkFVfN+cLAFkvgNbFGvspvNNaAUZrtgE3AH2QsxwRPS/tQ4hRig0iDuNNpGnLGRz/q8amSErwtXOCNYBS6F8AV3zfRu02NBFecew4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693325266; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Abcle4ARb0blzurWpZvpu816kCZtgNUdJTUl5lKLdd8=; b=lm4NK8S4pELQzvbn5QZqhe68vwBuJ7XYHccbkGeJ/7VkXycr3JWbu7ugUCFTYZHUOSBRLFalBCzoTd1Mm1L/9U5AqKZ0Nd/+UGoMPmjJWwuHzVkRnIu5vFhki6cHZLuEdH9dY3bHIbMiSbU6h7cKZQEWYhCYoT7ea66Nh5906Jc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693325266343209.36132932791543; Tue, 29 Aug 2023 09:07:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qb1F4-0007Dq-JS; Tue, 29 Aug 2023 12:06:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qb1Eq-0007Az-1m for qemu-devel@nongnu.org; Tue, 29 Aug 2023 12:06:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qb1El-0002kb-Qh for qemu-devel@nongnu.org; Tue, 29 Aug 2023 12:06:43 -0400 Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-497-rNPbv60GMoCqGWJAk4C7Sg-1; Tue, 29 Aug 2023 12:06:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D4F2C280FEE0; Tue, 29 Aug 2023 16:06:35 +0000 (UTC) Received: from localhost (unknown [10.39.195.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA8331121318; Tue, 29 Aug 2023 16:06:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693325198; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Abcle4ARb0blzurWpZvpu816kCZtgNUdJTUl5lKLdd8=; b=OqIxa+FaH/xh5LhTUWaBPdJ6miKNF1tFdScNjukcHYD0Ee15m7Mt4ZFPIn45/lPntM/HP7 YkSKW7NeiRCeKPLRh03aSpXL5gU3xA9EOuJE+woI4/lrKw2yxQfmIH82ubD2cJaQI82KKH cfq8T7Mw/oEa5+KAxbJ0WGAW1n+lBt0= X-MC-Unique: rNPbv60GMoCqGWJAk4C7Sg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Leonardo Bras , eblake@redhat.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , farosas@suse.de, kwolf@redhat.com, Peter Xu , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , Juan Quintela , qemu-block@nongnu.org, Coiby Xu , Fam Zheng , Hanna Reitz , Stefan Hajnoczi Subject: [PATCH v2 4/4] io: follow coroutine AioContext in qio_channel_yield() Date: Tue, 29 Aug 2023 12:06:22 -0400 Message-ID: <20230829160623.277411-5-stefanha@redhat.com> In-Reply-To: <20230829160623.277411-1-stefanha@redhat.com> References: <20230829160623.277411-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693325268422100007 Content-Type: text/plain; charset="utf-8" The ongoing QEMU multi-queue block layer effort makes it possible for multi= ple threads to process I/O in parallel. The nbd block driver is not compatible = with the multi-queue block layer yet because QIOChannel cannot be used easily fr= om coroutines running in multiple threads. This series changes the QIOChannel = API to make that possible. In the current API, calling qio_channel_attach_aio_context() sets the AioContext where qio_channel_yield() installs an fd handler prior to yieldi= ng: qio_channel_attach_aio_context(ioc, my_ctx); ... qio_channel_yield(ioc); // my_ctx is used here ... qio_channel_detach_aio_context(ioc); This API design has limitations: reading and writing must be done in the sa= me AioContext and moving between AioContexts involves a cumbersome sequence of= API calls that is not suitable for doing on a per-request basis. There is no fundamental reason why a QIOChannel needs to run within the same AioContext every time qio_channel_yield() is called. QIOChannel only uses the AioContext while inside qio_channel_yield(). The rest of the time, QIOChannel is independent of any AioContext. In the new API, qio_channel_yield() queries the AioContext from the current coroutine using qemu_coroutine_get_aio_context(). There is no need to explicitly attach/detach AioContexts anymore and qio_channel_attach_aio_context() and qio_channel_detach_aio_context() are g= one. One coroutine can read from the QIOChannel while another coroutine writes f= rom a different AioContext. This API change allows the nbd block driver to use QIOChannel from any thre= ad. It's important to keep in mind that the block driver already synchronizes QIOChannel access and ensures that two coroutines never read simultaneously= or write simultaneously. This patch updates all users of qio_channel_attach_aio_context() to the new API. Most conversions are simple, but vhost-user-server requires a new qemu_coroutine_yield() call to quiesce the vu_client_trip() coroutine when not attached to any AioContext. While the API is has become simpler, there is one wart: QIOChannel has a special case for the iohandler AioContext (used for handlers that must not = run in nested event loops). I didn't find an elegant way preserve that behavior= , so I added a new API called qio_channel_set_follow_coroutine_ctx(ioc, true|fal= se) for opting in to the new AioContext model. By default QIOChannel uses the iohandler AioHandler. Code that formerly called qio_channel_attach_aio_context() now calls qio_channel_set_follow_coroutine_ctx(ioc, true) once after the QIOChannel is created. Signed-off-by: Stefan Hajnoczi Acked-by: Daniel P. Berrang=C3=A9 Reviewed-by: Eric Blake --- include/io/channel-util.h | 23 ++++++ include/io/channel.h | 69 ++++++++---------- include/qemu/vhost-user-server.h | 1 + block/nbd.c | 11 +-- io/channel-command.c | 10 ++- io/channel-file.c | 9 ++- io/channel-null.c | 3 +- io/channel-socket.c | 9 ++- io/channel-tls.c | 6 +- io/channel-util.c | 24 +++++++ io/channel.c | 120 ++++++++++++++++++++++--------- migration/channel-block.c | 3 +- nbd/server.c | 14 +--- scsi/qemu-pr-helper.c | 4 +- util/vhost-user-server.c | 27 +++++-- 15 files changed, 216 insertions(+), 117 deletions(-) diff --git a/include/io/channel-util.h b/include/io/channel-util.h index a5d720d9a0..74ed299fad 100644 --- a/include/io/channel-util.h +++ b/include/io/channel-util.h @@ -49,4 +49,27 @@ QIOChannel *qio_channel_new_fd(int fd, Error **errp); =20 +/** + * qio_channel_yield: + * @read_fd: the file descriptor for the read handler + * @read_ctx: the AioContext for the read handler + * @io_read: the read handler + * @write_fd: the file descriptor for the write handler + * @write_ctx: the AioContext for the write handler + * @io_write: the write handler + * @opaque: the opaque argument to the read and write handler + * + * Set the read and write handlers when @read_ctx and @write_ctx are non-N= ULL, + * respectively. To leave a handler in its current state, pass a NULL + * AioContext. To clear a handler, pass a non-NULL AioContext and a NULL + * handler. + */ +void qio_channel_util_set_aio_fd_handler(int read_fd, + AioContext *read_ctx, + IOHandler *io_read, + int write_fd, + AioContext *write_ctx, + IOHandler *io_write, + void *opaque); + #endif /* QIO_CHANNEL_UTIL_H */ diff --git a/include/io/channel.h b/include/io/channel.h index 229bf36910..5f9dbaab65 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -81,9 +81,11 @@ struct QIOChannel { Object parent; unsigned int features; /* bitmask of QIOChannelFeatures */ char *name; - AioContext *ctx; + AioContext *read_ctx; Coroutine *read_coroutine; + AioContext *write_ctx; Coroutine *write_coroutine; + bool follow_coroutine_ctx; #ifdef _WIN32 HANDLE event; /* For use with GSource on Win32 */ #endif @@ -140,8 +142,9 @@ struct QIOChannelClass { int whence, Error **errp); void (*io_set_aio_fd_handler)(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque); int (*io_flush)(QIOChannel *ioc, @@ -498,6 +501,21 @@ int qio_channel_set_blocking(QIOChannel *ioc, bool enabled, Error **errp); =20 +/** + * qio_channel_set_follow_coroutine_ctx: + * @ioc: the channel object + * @enabled: whether or not to follow the coroutine's AioContext + * + * If @enabled is true, calls to qio_channel_yield() use the current + * coroutine's AioContext. Usually this is desirable. + * + * If @enabled is false, calls to qio_channel_yield() use the global iohan= dler + * AioContext. This is may be used by coroutines that run in the main loop= and + * do not wish to respond to I/O during nested event loops. This is the + * default for compatibility with code that is not aware of AioContexts. + */ +void qio_channel_set_follow_coroutine_ctx(QIOChannel *ioc, bool enabled); + /** * qio_channel_close: * @ioc: the channel object @@ -703,41 +721,6 @@ GSource *qio_channel_add_watch_source(QIOChannel *ioc, GDestroyNotify notify, GMainContext *context); =20 -/** - * qio_channel_attach_aio_context: - * @ioc: the channel object - * @ctx: the #AioContext to set the handlers on - * - * Request that qio_channel_yield() sets I/O handlers on - * the given #AioContext. If @ctx is %NULL, qio_channel_yield() - * uses QEMU's main thread event loop. - * - * You can move a #QIOChannel from one #AioContext to another even if - * I/O handlers are set for a coroutine. However, #QIOChannel provides - * no synchronization between the calls to qio_channel_yield() and - * qio_channel_attach_aio_context(). - * - * Therefore you should first call qio_channel_detach_aio_context() - * to ensure that the coroutine is not entered concurrently. Then, - * while the coroutine has yielded, call qio_channel_attach_aio_context(), - * and then aio_co_schedule() to place the coroutine on the new - * #AioContext. The calls to qio_channel_detach_aio_context() - * and qio_channel_attach_aio_context() should be protected with - * aio_context_acquire() and aio_context_release(). - */ -void qio_channel_attach_aio_context(QIOChannel *ioc, - AioContext *ctx); - -/** - * qio_channel_detach_aio_context: - * @ioc: the channel object - * - * Disable any I/O handlers set by qio_channel_yield(). With the - * help of aio_co_schedule(), this allows moving a coroutine that was - * paused by qio_channel_yield() to another context. - */ -void qio_channel_detach_aio_context(QIOChannel *ioc); - /** * qio_channel_yield: * @ioc: the channel object @@ -785,8 +768,9 @@ void qio_channel_wait(QIOChannel *ioc, /** * qio_channel_set_aio_fd_handler: * @ioc: the channel object - * @ctx: the AioContext to set the handlers on + * @read_ctx: the AioContext to set the read handler on or NULL * @io_read: the read handler + * @write_ctx: the AioContext to set the write handler on or NULL * @io_write: the write handler * @opaque: the opaque value passed to the handler * @@ -794,10 +778,17 @@ void qio_channel_wait(QIOChannel *ioc, * be used by channel implementations to forward the handlers * to another channel (e.g. from #QIOChannelTLS to the * underlying socket). + * + * When @read_ctx is NULL, don't touch the read handler. When @write_ctx is + * NULL, don't touch the write handler. Note that setting the read handler + * clears the write handler, and vice versa, if they share the same AioCon= text. + * Therefore the caller must pass both handlers together when sharing the = same + * AioContext. */ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque); =20 diff --git a/include/qemu/vhost-user-server.h b/include/qemu/vhost-user-ser= ver.h index b1c1cda886..64ad701015 100644 --- a/include/qemu/vhost-user-server.h +++ b/include/qemu/vhost-user-server.h @@ -43,6 +43,7 @@ typedef struct { unsigned int in_flight; /* atomic */ =20 /* Protected by ctx lock */ + bool in_qio_channel_yield; bool wait_idle; VuDev vu_dev; QIOChannel *ioc; /* The I/O channel with the client */ diff --git a/block/nbd.c b/block/nbd.c index 5322e66166..cc48580df7 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -352,7 +352,7 @@ int coroutine_fn nbd_co_do_establish_connection(BlockDr= iverState *bs, } =20 qio_channel_set_blocking(s->ioc, false, NULL); - qio_channel_attach_aio_context(s->ioc, bdrv_get_aio_context(bs)); + qio_channel_set_follow_coroutine_ctx(s->ioc, true); =20 /* successfully connected */ WITH_QEMU_LOCK_GUARD(&s->requests_lock) { @@ -397,7 +397,6 @@ static void coroutine_fn GRAPH_RDLOCK nbd_reconnect_att= empt(BDRVNBDState *s) =20 /* Finalize previous connection if any */ if (s->ioc) { - qio_channel_detach_aio_context(s->ioc); yank_unregister_function(BLOCKDEV_YANK_INSTANCE(s->bs->node_name), nbd_yank, s->bs); object_unref(OBJECT(s->ioc)); @@ -2089,10 +2088,6 @@ static void nbd_attach_aio_context(BlockDriverState = *bs, * the reconnect_delay_timer cannot be active here. */ assert(!s->reconnect_delay_timer); - - if (s->ioc) { - qio_channel_attach_aio_context(s->ioc, new_context); - } } =20 static void nbd_detach_aio_context(BlockDriverState *bs) @@ -2101,10 +2096,6 @@ static void nbd_detach_aio_context(BlockDriverState = *bs) =20 assert(!s->open_timer); assert(!s->reconnect_delay_timer); - - if (s->ioc) { - qio_channel_detach_aio_context(s->ioc); - } } =20 static BlockDriver bdrv_nbd =3D { diff --git a/io/channel-command.c b/io/channel-command.c index 7ed726c802..6d5f64e146 100644 --- a/io/channel-command.c +++ b/io/channel-command.c @@ -20,6 +20,7 @@ =20 #include "qemu/osdep.h" #include "io/channel-command.h" +#include "io/channel-util.h" #include "io/channel-watch.h" #include "qapi/error.h" #include "qemu/module.h" @@ -331,14 +332,17 @@ static int qio_channel_command_close(QIOChannel *ioc, =20 =20 static void qio_channel_command_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque) { QIOChannelCommand *cioc =3D QIO_CHANNEL_COMMAND(ioc); - aio_set_fd_handler(ctx, cioc->readfd, io_read, NULL, NULL, NULL, opaqu= e); - aio_set_fd_handler(ctx, cioc->writefd, NULL, io_write, NULL, NULL, opa= que); + + qio_channel_util_set_aio_fd_handler(cioc->readfd, read_ctx, io_read, + cioc->writefd, write_ctx, io_write, + opaque); } =20 =20 diff --git a/io/channel-file.c b/io/channel-file.c index 8b5821f452..4a12c61886 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -20,6 +20,7 @@ =20 #include "qemu/osdep.h" #include "io/channel-file.h" +#include "io/channel-util.h" #include "io/channel-watch.h" #include "qapi/error.h" #include "qemu/module.h" @@ -192,13 +193,17 @@ static int qio_channel_file_close(QIOChannel *ioc, =20 =20 static void qio_channel_file_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque) { QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); - aio_set_fd_handler(ctx, fioc->fd, io_read, io_write, NULL, NULL, opaqu= e); + + qio_channel_util_set_aio_fd_handler(fioc->fd, read_ctx, io_read, + fioc->fd, write_ctx, io_write, + opaque); } =20 static GSource *qio_channel_file_create_watch(QIOChannel *ioc, diff --git a/io/channel-null.c b/io/channel-null.c index 4fafdb770d..ef99586348 100644 --- a/io/channel-null.c +++ b/io/channel-null.c @@ -128,8 +128,9 @@ qio_channel_null_close(QIOChannel *ioc, =20 static void qio_channel_null_set_aio_fd_handler(QIOChannel *ioc G_GNUC_UNUSED, - AioContext *ctx G_GNUC_UNUSED, + AioContext *read_ctx G_GNUC_UNUSED, IOHandler *io_read G_GNUC_UNUSED, + AioContext *write_ctx G_GNUC_UNUSED, IOHandler *io_write G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { diff --git a/io/channel-socket.c b/io/channel-socket.c index d99945ebec..02ffb51e99 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -22,6 +22,7 @@ #include "qapi/qapi-visit-sockets.h" #include "qemu/module.h" #include "io/channel-socket.h" +#include "io/channel-util.h" #include "io/channel-watch.h" #include "trace.h" #include "qapi/clone-visitor.h" @@ -893,13 +894,17 @@ qio_channel_socket_shutdown(QIOChannel *ioc, } =20 static void qio_channel_socket_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque) { QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); - aio_set_fd_handler(ctx, sioc->fd, io_read, io_write, NULL, NULL, opaqu= e); + + qio_channel_util_set_aio_fd_handler(sioc->fd, read_ctx, io_read, + sioc->fd, write_ctx, io_write, + opaque); } =20 static GSource *qio_channel_socket_create_watch(QIOChannel *ioc, diff --git a/io/channel-tls.c b/io/channel-tls.c index 847d5297c3..58fe1aceee 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -388,14 +388,16 @@ static int qio_channel_tls_close(QIOChannel *ioc, } =20 static void qio_channel_tls_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque) { QIOChannelTLS *tioc =3D QIO_CHANNEL_TLS(ioc); =20 - qio_channel_set_aio_fd_handler(tioc->master, ctx, io_read, io_write, o= paque); + qio_channel_set_aio_fd_handler(tioc->master, read_ctx, io_read, + write_ctx, io_write, opaque); } =20 typedef struct QIOChannelTLSSource QIOChannelTLSSource; diff --git a/io/channel-util.c b/io/channel-util.c index 848a7a43d6..4b340d46d7 100644 --- a/io/channel-util.c +++ b/io/channel-util.c @@ -36,3 +36,27 @@ QIOChannel *qio_channel_new_fd(int fd, } return ioc; } + + +void qio_channel_util_set_aio_fd_handler(int read_fd, + AioContext *read_ctx, + IOHandler *io_read, + int write_fd, + AioContext *write_ctx, + IOHandler *io_write, + void *opaque) +{ + if (read_fd =3D=3D write_fd && read_ctx =3D=3D write_ctx) { + aio_set_fd_handler(read_ctx, read_fd, io_read, io_write, + NULL, NULL, opaque); + } else { + if (read_ctx) { + aio_set_fd_handler(read_ctx, read_fd, io_read, NULL, + NULL, NULL, opaque); + } + if (write_ctx) { + aio_set_fd_handler(write_ctx, write_fd, NULL, io_write, + NULL, NULL, opaque); + } + } +} diff --git a/io/channel.c b/io/channel.c index c415f3fc88..b190d593d3 100644 --- a/io/channel.c +++ b/io/channel.c @@ -365,6 +365,12 @@ int qio_channel_set_blocking(QIOChannel *ioc, } =20 =20 +void qio_channel_set_follow_coroutine_ctx(QIOChannel *ioc, bool enabled) +{ + ioc->follow_coroutine_ctx =3D enabled; +} + + int qio_channel_close(QIOChannel *ioc, Error **errp) { @@ -388,14 +394,16 @@ GSource *qio_channel_create_watch(QIOChannel *ioc, =20 =20 void qio_channel_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque) { QIOChannelClass *klass =3D QIO_CHANNEL_GET_CLASS(ioc); =20 - klass->io_set_aio_fd_handler(ioc, ctx, io_read, io_write, opaque); + klass->io_set_aio_fd_handler(ioc, read_ctx, io_read, write_ctx, io_wri= te, + opaque); } =20 guint qio_channel_add_watch_full(QIOChannel *ioc, @@ -542,56 +550,101 @@ static void qio_channel_restart_write(void *opaque) aio_co_wake(co); } =20 -static void qio_channel_set_aio_fd_handlers(QIOChannel *ioc) +static void coroutine_fn +qio_channel_set_fd_handlers(QIOChannel *ioc, GIOCondition condition) { - IOHandler *rd_handler =3D NULL, *wr_handler =3D NULL; + AioContext *ctx =3D ioc->follow_coroutine_ctx ? + qemu_coroutine_get_aio_context(qemu_coroutine_self()) : + iohandler_get_aio_context(); + AioContext *read_ctx =3D NULL; + IOHandler *io_read =3D NULL; + AioContext *write_ctx =3D NULL; + IOHandler *io_write =3D NULL; + + if (condition =3D=3D G_IO_IN) { + ioc->read_coroutine =3D qemu_coroutine_self(); + ioc->read_ctx =3D ctx; + read_ctx =3D ctx; + io_read =3D qio_channel_restart_read; + + /* + * Thread safety: if the other coroutine is set and its AioContext + * match ours, then there is mutual exclusion between read and wri= te + * because they share a single thread and it's safe to set both re= ad + * and write fd handlers here. If the AioContext does not match ou= rs, + * then both threads may run in parallel but there is no shared st= ate + * to worry about. + */ + if (ioc->write_coroutine && ioc->write_ctx =3D=3D ctx) { + write_ctx =3D ctx; + io_write =3D qio_channel_restart_write; + } + } else if (condition =3D=3D G_IO_OUT) { + ioc->write_coroutine =3D qemu_coroutine_self(); + ioc->write_ctx =3D ctx; + write_ctx =3D ctx; + io_write =3D qio_channel_restart_write; + if (ioc->read_coroutine && ioc->read_ctx =3D=3D ctx) { + read_ctx =3D ctx; + io_read =3D qio_channel_restart_read; + } + } else { + abort(); + } + + qio_channel_set_aio_fd_handler(ioc, read_ctx, io_read, + write_ctx, io_write, ioc); +} + +static void coroutine_fn +qio_channel_clear_fd_handlers(QIOChannel *ioc, GIOCondition condition) +{ + AioContext *read_ctx =3D NULL; + IOHandler *io_read =3D NULL; + AioContext *write_ctx =3D NULL; + IOHandler *io_write =3D NULL; AioContext *ctx; =20 - if (ioc->read_coroutine) { - rd_handler =3D qio_channel_restart_read; + if (condition =3D=3D G_IO_IN) { + ctx =3D ioc->read_ctx; + read_ctx =3D ctx; + io_read =3D NULL; + if (ioc->write_coroutine && ioc->write_ctx =3D=3D ctx) { + write_ctx =3D ctx; + io_write =3D qio_channel_restart_write; + } + } else if (condition =3D=3D G_IO_OUT) { + ctx =3D ioc->write_ctx; + write_ctx =3D ctx; + io_write =3D NULL; + if (ioc->read_coroutine && ioc->read_ctx =3D=3D ctx) { + read_ctx =3D ctx; + io_read =3D qio_channel_restart_read; + } + } else { + abort(); } - if (ioc->write_coroutine) { - wr_handler =3D qio_channel_restart_write; - } - - ctx =3D ioc->ctx ? ioc->ctx : iohandler_get_aio_context(); - qio_channel_set_aio_fd_handler(ioc, ctx, rd_handler, wr_handler, ioc); -} - -void qio_channel_attach_aio_context(QIOChannel *ioc, - AioContext *ctx) -{ - assert(!ioc->read_coroutine); - assert(!ioc->write_coroutine); - ioc->ctx =3D ctx; -} =20 -void qio_channel_detach_aio_context(QIOChannel *ioc) -{ - ioc->read_coroutine =3D NULL; - ioc->write_coroutine =3D NULL; - qio_channel_set_aio_fd_handlers(ioc); - ioc->ctx =3D NULL; + qio_channel_set_aio_fd_handler(ioc, read_ctx, io_read, + write_ctx, io_write, ioc); } =20 void coroutine_fn qio_channel_yield(QIOChannel *ioc, GIOCondition condition) { - AioContext *ioc_ctx =3D ioc->ctx ?: qemu_get_aio_context(); + AioContext *ioc_ctx; =20 assert(qemu_in_coroutine()); - assert(in_aio_context_home_thread(ioc_ctx)); + ioc_ctx =3D qemu_coroutine_get_aio_context(qemu_coroutine_self()); =20 if (condition =3D=3D G_IO_IN) { assert(!ioc->read_coroutine); - ioc->read_coroutine =3D qemu_coroutine_self(); } else if (condition =3D=3D G_IO_OUT) { assert(!ioc->write_coroutine); - ioc->write_coroutine =3D qemu_coroutine_self(); } else { abort(); } - qio_channel_set_aio_fd_handlers(ioc); + qio_channel_set_fd_handlers(ioc, condition); qemu_coroutine_yield(); assert(in_aio_context_home_thread(ioc_ctx)); =20 @@ -599,11 +652,10 @@ void coroutine_fn qio_channel_yield(QIOChannel *ioc, * through the aio_fd_handlers. */ if (condition =3D=3D G_IO_IN) { assert(ioc->read_coroutine =3D=3D NULL); - qio_channel_set_aio_fd_handlers(ioc); } else if (condition =3D=3D G_IO_OUT) { assert(ioc->write_coroutine =3D=3D NULL); - qio_channel_set_aio_fd_handlers(ioc); } + qio_channel_clear_fd_handlers(ioc, condition); } =20 void qio_channel_wake_read(QIOChannel *ioc) diff --git a/migration/channel-block.c b/migration/channel-block.c index b7374363c3..fff8d87094 100644 --- a/migration/channel-block.c +++ b/migration/channel-block.c @@ -158,8 +158,9 @@ qio_channel_block_close(QIOChannel *ioc, =20 static void qio_channel_block_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque) { diff --git a/nbd/server.c b/nbd/server.c index 8486b64b15..b5f93a20c9 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1333,6 +1333,7 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt, Error **errp) */ =20 qio_channel_set_blocking(client->ioc, false, NULL); + qio_channel_set_follow_coroutine_ctx(client->ioc, true); =20 trace_nbd_negotiate_begin(); memcpy(buf, "NBDMAGIC", 8); @@ -1352,11 +1353,6 @@ static coroutine_fn int nbd_negotiate(NBDClient *cli= ent, Error **errp) return ret; } =20 - /* Attach the channel to the same AioContext as the export */ - if (client->exp && client->exp->common.ctx) { - qio_channel_attach_aio_context(client->ioc, client->exp->common.ct= x); - } - assert(!client->optlen); trace_nbd_negotiate_success(); =20 @@ -1465,7 +1461,6 @@ void nbd_client_put(NBDClient *client) */ assert(client->closing); =20 - qio_channel_detach_aio_context(client->ioc); object_unref(OBJECT(client->sioc)); object_unref(OBJECT(client->ioc)); if (client->tlscreds) { @@ -1544,8 +1539,6 @@ static void blk_aio_attached(AioContext *ctx, void *o= paque) exp->common.ctx =3D ctx; =20 QTAILQ_FOREACH(client, &exp->clients, next) { - qio_channel_attach_aio_context(client->ioc, ctx); - assert(client->nb_requests =3D=3D 0); assert(client->recv_coroutine =3D=3D NULL); assert(client->send_coroutine =3D=3D NULL); @@ -1555,14 +1548,9 @@ static void blk_aio_attached(AioContext *ctx, void *= opaque) static void blk_aio_detach(void *opaque) { NBDExport *exp =3D opaque; - NBDClient *client; =20 trace_nbd_blk_aio_detach(exp->name, exp->common.ctx); =20 - QTAILQ_FOREACH(client, &exp->clients, next) { - qio_channel_detach_aio_context(client->ioc); - } - exp->common.ctx =3D NULL; } =20 diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index ae44a816e1..c6c6347e9b 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -735,8 +735,7 @@ static void coroutine_fn prh_co_entry(void *opaque) =20 qio_channel_set_blocking(QIO_CHANNEL(client->ioc), false, NULL); - qio_channel_attach_aio_context(QIO_CHANNEL(client->ioc), - qemu_get_aio_context()); + qio_channel_set_follow_coroutine_ctx(QIO_CHANNEL(client->ioc), true); =20 /* A very simple negotiation for future extensibility. No features * are defined so write 0. @@ -796,7 +795,6 @@ static void coroutine_fn prh_co_entry(void *opaque) } =20 out: - qio_channel_detach_aio_context(QIO_CHANNEL(client->ioc)); object_unref(OBJECT(client->ioc)); g_free(client); } diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index cd17fb5326..b4b6bf30a2 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -127,7 +127,14 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserM= sg *vmsg) if (rc < 0) { if (rc =3D=3D QIO_CHANNEL_ERR_BLOCK) { assert(local_err =3D=3D NULL); - qio_channel_yield(ioc, G_IO_IN); + if (server->ctx) { + server->in_qio_channel_yield =3D true; + qio_channel_yield(ioc, G_IO_IN); + server->in_qio_channel_yield =3D false; + } else { + /* Wait until attached to an AioContext again */ + qemu_coroutine_yield(); + } continue; } else { error_report_err(local_err); @@ -278,7 +285,7 @@ set_watch(VuDev *vu_dev, int fd, int vu_evt, vu_fd_watch->fd =3D fd; vu_fd_watch->cb =3D cb; qemu_socket_set_nonblock(fd); - aio_set_fd_handler(server->ioc->ctx, fd, kick_handler, + aio_set_fd_handler(server->ctx, fd, kick_handler, NULL, NULL, NULL, vu_fd_watch); vu_fd_watch->vu_dev =3D vu_dev; vu_fd_watch->pvt =3D pvt; @@ -299,7 +306,7 @@ static void remove_watch(VuDev *vu_dev, int fd) if (!vu_fd_watch) { return; } - aio_set_fd_handler(server->ioc->ctx, fd, NULL, NULL, NULL, NULL, NULL); + aio_set_fd_handler(server->ctx, fd, NULL, NULL, NULL, NULL, NULL); =20 QTAILQ_REMOVE(&server->vu_fd_watches, vu_fd_watch, next); g_free(vu_fd_watch); @@ -344,6 +351,8 @@ static void vu_accept(QIONetListener *listener, QIOChan= nelSocket *sioc, /* TODO vu_message_write() spins if non-blocking! */ qio_channel_set_blocking(server->ioc, false, NULL); =20 + qio_channel_set_follow_coroutine_ctx(server->ioc, true); + server->co_trip =3D qemu_coroutine_create(vu_client_trip, server); =20 aio_context_acquire(server->ctx); @@ -399,13 +408,12 @@ void vhost_user_server_attach_aio_context(VuServer *s= erver, AioContext *ctx) return; } =20 - qio_channel_attach_aio_context(server->ioc, ctx); - QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { aio_set_fd_handler(ctx, vu_fd_watch->fd, kick_handler, NULL, NULL, NULL, vu_fd_watch); } =20 + assert(!server->in_qio_channel_yield); aio_co_schedule(ctx, server->co_trip); } =20 @@ -419,11 +427,16 @@ void vhost_user_server_detach_aio_context(VuServer *s= erver) aio_set_fd_handler(server->ctx, vu_fd_watch->fd, NULL, NULL, NULL, NULL, vu_fd_watch); } - - qio_channel_detach_aio_context(server->ioc); } =20 server->ctx =3D NULL; + + if (server->ioc) { + if (server->in_qio_channel_yield) { + /* Stop receiving the next vhost-user message */ + qio_channel_wake_read(server->ioc); + } + } } =20 bool vhost_user_server_start(VuServer *server, --=20 2.41.0