From nobody Sun Sep 28 16:34:06 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1758282797; cv=none; d=zohomail.com; s=zohoarc; b=LN2QqseDGsK62SsD2xswnAlBe2Dnippu1y3WlO9r17XSuNwxk6Gml+JYFIgq+fMhN4/W0GWpNRr2WryEg9crrcfq2+RXxIJ5bAXDQVMojeD3FGmfZM3tZ80AlqpHkM61oS37AuAUGByzJvVWvQyaa+rw1ga15qJY3ysDq6/QTSI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282797; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nYpEdFXtBLEV86Ix65e1Molyf190v9S0JmjYC86IjG8=; b=ZT5schhBgtku3r5ZaToli0bJTLAMkQFdqqGM+WoQuEnw5x/pk6MiQDVWeegDtXVud+BO+1UKMWfbcYg265zfHIpNyJFrbaodrzS1ac+RohlDfiaAZd88PJGaTD6nsIQwv9RxdUydA40LDjyB+pOe+TSorqEh7Wos666lQJG7Gjc= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758282797128187.48038803725126; Fri, 19 Sep 2025 04:53:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZfD-0002jo-EF; Fri, 19 Sep 2025 07:52:33 -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 1uzZei-0002YP-1a for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:52:01 -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 1uzZec-0000s1-W5 for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:51:58 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-22-HJ1l12WQMhOPvG6CjFpvhw-1; Fri, 19 Sep 2025 07:51:45 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 531A21956089; Fri, 19 Sep 2025 11:51:41 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.187]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 163731955F21; Fri, 19 Sep 2025 11:51:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282709; 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=nYpEdFXtBLEV86Ix65e1Molyf190v9S0JmjYC86IjG8=; b=AKSUZATGtgvVVxRP6K9b1xQ61ZfHCsY8tc2op0hfsXt3pmR2atmz/athC0cP6B0nVJyLxQ woDeqAx2f+zsAo88JPlf1bbo5LxP4u8HO+EsLr42rwroYzWgz53RZ6eSABmQLMVsJoHLig xOtz4QU6w5LKfXijbSQ5W9zTu9HXoVE= X-MC-Unique: HJ1l12WQMhOPvG6CjFpvhw-1 X-Mimecast-MFC-AGG-ID: HJ1l12WQMhOPvG6CjFpvhw_1758282701 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Jagannathan Raman , Zhao Liu , Eric Blake , Stefan Hajnoczi , "Michael S. Tsirkin" , Hanna Reitz , Gustavo Romero , Thanos Makatos , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Darren Kenny , Stefano Garzarella , Kevin Wolf , Fabiano Rosas , qemu-block@nongnu.org, Peter Xu , Laurent Vivier , Jason Wang , Elena Ufimtseva , John Levon , Fam Zheng , Alexander Bulekov , Stefan Weil , Gerd Hoffmann , Coiby Xu , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Qiuhao Li , Michael Roth , Vladimir Sementsov-Ogievskiy , Paolo Bonzini , Bandan Das , Kostiantyn Kostiuk , Hailiang Zhang Subject: [PULL 07/16] treewide: handle result of qio_channel_set_blocking() Date: Fri, 19 Sep 2025 12:50:08 +0100 Message-ID: <20250919115017.1536203-8-berrange@redhat.com> In-Reply-To: <20250919115017.1536203-1-berrange@redhat.com> References: <20250919115017.1536203-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.105, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: 1758282798864116600 From: Vladimir Sementsov-Ogievskiy Currently, we just always pass NULL as errp argument. That doesn't look good. Some realizations of interface may actually report errors. Channel-socket realization actually either ignore or crash on errors, but we are going to straighten it out to always reporting an errp in further commits. So, convert all callers to either handle the error (where environment allows) or explicitly use &error_abort. Take also a chance to change the return value to more convenient bool (keeping also in mind, that underlying realizations may return -1 on failure, not -errno). Suggested-by: Daniel P. Berrang=C3=A9 Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy [DB: fix return type mismatch in TLS/websocket channel impls for qio_channel_set_blocking] Signed-off-by: Daniel P. Berrang=C3=A9 --- block/nbd.c | 4 +++- chardev/char-socket.c | 20 ++++++++++++++++---- hw/remote/proxy.c | 6 +++++- hw/remote/remote-obj.c | 6 +++++- hw/vfio-user/proxy.c | 11 ++++++++--- include/io/channel.h | 6 +++--- io/channel-tls.c | 2 +- io/channel-websock.c | 3 +-- io/channel.c | 4 ++-- nbd/server.c | 4 +++- scsi/qemu-pr-helper.c | 9 ++++++--- tests/unit/io-channel-helpers.c | 5 +++-- tests/unit/test-io-channel-tls.c | 4 ++-- tools/i386/qemu-vmsr-helper.c | 6 ++++-- ui/vnc.c | 2 +- util/vhost-user-server.c | 7 ++++++- 16 files changed, 69 insertions(+), 30 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index d5a2b21c6d..5d231d5c4e 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -351,7 +351,9 @@ int coroutine_fn nbd_co_do_establish_connection(BlockDr= iverState *bs, return ret; } =20 - qio_channel_set_blocking(s->ioc, false, NULL); + if (!qio_channel_set_blocking(s->ioc, false, errp)) { + return -EINVAL; + } qio_channel_set_follow_coroutine_ctx(s->ioc, true); =20 /* successfully connected */ diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 1be078dfc0..cb4ec78ebe 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -530,16 +530,24 @@ static int tcp_chr_sync_read(Chardev *chr, const uint= 8_t *buf, int len) SocketChardev *s =3D SOCKET_CHARDEV(chr); int size; int saved_errno; + Error *local_err =3D NULL; =20 if (s->state !=3D TCP_CHARDEV_STATE_CONNECTED) { return 0; } =20 - qio_channel_set_blocking(s->ioc, true, NULL); + if (!qio_channel_set_blocking(s->ioc, true, &local_err)) { + error_report_err(local_err); + return -1; + } size =3D tcp_chr_recv(chr, (void *) buf, len); saved_errno =3D errno; if (s->state !=3D TCP_CHARDEV_STATE_DISCONNECTED) { - qio_channel_set_blocking(s->ioc, false, NULL); + if (!qio_channel_set_blocking(s->ioc, false, &local_err)) { + error_report_err(local_err); + /* failed to recover non-blocking state */ + tcp_chr_disconnect(chr); + } } if (size =3D=3D 0) { /* connection closed */ @@ -884,18 +892,22 @@ static void tcp_chr_set_client_ioc_name(Chardev *chr, static int tcp_chr_new_client(Chardev *chr, QIOChannelSocket *sioc) { SocketChardev *s =3D SOCKET_CHARDEV(chr); + Error *local_err =3D NULL; =20 if (s->state !=3D TCP_CHARDEV_STATE_CONNECTING) { return -1; } =20 + if (!qio_channel_set_blocking(QIO_CHANNEL(sioc), false, &local_err)) { + error_report_err(local_err); + return -1; + } + s->ioc =3D QIO_CHANNEL(sioc); object_ref(OBJECT(sioc)); s->sioc =3D sioc; object_ref(OBJECT(sioc)); =20 - qio_channel_set_blocking(s->ioc, false, NULL); - if (s->do_nodelay) { qio_channel_set_delay(s->ioc, false); } diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c index b0165aa2a1..18e0f7a064 100644 --- a/hw/remote/proxy.c +++ b/hw/remote/proxy.c @@ -112,8 +112,12 @@ static void pci_proxy_dev_realize(PCIDevice *device, E= rror **errp) return; } =20 + if (!qio_channel_set_blocking(dev->ioc, true, errp)) { + object_unref(dev->ioc); + return; + } + qemu_mutex_init(&dev->io_mutex); - qio_channel_set_blocking(dev->ioc, true, NULL); =20 pci_conf[PCI_LATENCY_TIMER] =3D 0xff; pci_conf[PCI_INTERRUPT_PIN] =3D 0x01; diff --git a/hw/remote/remote-obj.c b/hw/remote/remote-obj.c index 85882902d7..3402068ab9 100644 --- a/hw/remote/remote-obj.c +++ b/hw/remote/remote-obj.c @@ -107,7 +107,11 @@ static void remote_object_machine_done(Notifier *notif= ier, void *data) error_report_err(err); return; } - qio_channel_set_blocking(ioc, false, NULL); + if (!qio_channel_set_blocking(ioc, false, &err)) { + error_report_err(err); + object_unref(OBJECT(ioc)); + return; + } =20 o->dev =3D dev; =20 diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index 2c03d49f97..bbd7ec243d 100644 --- a/hw/vfio-user/proxy.c +++ b/hw/vfio-user/proxy.c @@ -886,10 +886,11 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *a= ddr, Error **errp) sioc =3D qio_channel_socket_new(); ioc =3D QIO_CHANNEL(sioc); if (qio_channel_socket_connect_sync(sioc, addr, errp) < 0) { - object_unref(OBJECT(ioc)); - return NULL; + goto fail; + } + if (!qio_channel_set_blocking(ioc, false, errp)) { + goto fail; } - qio_channel_set_blocking(ioc, false, NULL); =20 proxy =3D g_malloc0(sizeof(VFIOUserProxy)); proxy->sockname =3D g_strdup_printf("unix:%s", sockname); @@ -923,6 +924,10 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *ad= dr, Error **errp) QLIST_INSERT_HEAD(&vfio_user_sockets, proxy, next); =20 return proxy; + +fail: + object_unref(OBJECT(ioc)); + return NULL; } =20 void vfio_user_set_handler(VFIODevice *vbasedev, diff --git a/include/io/channel.h b/include/io/channel.h index c7f64506f7..999a8f5f23 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -531,9 +531,9 @@ int coroutine_mixed_fn qio_channel_write_all(QIOChannel= *ioc, * return QIO_CHANNEL_ERR_BLOCK if they would otherwise * block on I/O */ -int qio_channel_set_blocking(QIOChannel *ioc, - bool enabled, - Error **errp); +bool qio_channel_set_blocking(QIOChannel *ioc, + bool enabled, + Error **errp); =20 /** * qio_channel_set_follow_coroutine_ctx: diff --git a/io/channel-tls.c b/io/channel-tls.c index a8248a9216..7135896f79 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -425,7 +425,7 @@ static int qio_channel_tls_set_blocking(QIOChannel *ioc, { QIOChannelTLS *tioc =3D QIO_CHANNEL_TLS(ioc); =20 - return qio_channel_set_blocking(tioc->master, enabled, errp); + return qio_channel_set_blocking(tioc->master, enabled, errp) ? 0 : -1; } =20 static void qio_channel_tls_set_delay(QIOChannel *ioc, diff --git a/io/channel-websock.c b/io/channel-websock.c index 08ddb274f0..0a8c5c4712 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -1184,8 +1184,7 @@ static int qio_channel_websock_set_blocking(QIOChanne= l *ioc, { QIOChannelWebsock *wioc =3D QIO_CHANNEL_WEBSOCK(ioc); =20 - qio_channel_set_blocking(wioc->master, enabled, errp); - return 0; + return qio_channel_set_blocking(wioc->master, enabled, errp) ? 0 : -1; } =20 static void qio_channel_websock_set_delay(QIOChannel *ioc, diff --git a/io/channel.c b/io/channel.c index ebd9322765..852e684938 100644 --- a/io/channel.c +++ b/io/channel.c @@ -359,12 +359,12 @@ int coroutine_mixed_fn qio_channel_write_all(QIOChann= el *ioc, } =20 =20 -int qio_channel_set_blocking(QIOChannel *ioc, +bool qio_channel_set_blocking(QIOChannel *ioc, bool enabled, Error **errp) { QIOChannelClass *klass =3D QIO_CHANNEL_GET_CLASS(ioc); - return klass->io_set_blocking(ioc, enabled, errp); + return klass->io_set_blocking(ioc, enabled, errp) =3D=3D 0; } =20 =20 diff --git a/nbd/server.c b/nbd/server.c index d242be9811..acec0487a8 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1411,7 +1411,9 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt, Error **errp) ....options sent, ending in NBD_OPT_EXPORT_NAME or NBD_OPT_GO.... */ =20 - qio_channel_set_blocking(client->ioc, false, NULL); + if (!qio_channel_set_blocking(client->ioc, false, errp)) { + return -EINVAL; + } qio_channel_set_follow_coroutine_ctx(client->ioc, true); =20 trace_nbd_negotiate_begin(); diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index b69dd982d6..074b4db472 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -733,8 +733,11 @@ static void coroutine_fn prh_co_entry(void *opaque) uint32_t flags; int r; =20 - qio_channel_set_blocking(QIO_CHANNEL(client->ioc), - false, NULL); + if (!qio_channel_set_blocking(QIO_CHANNEL(client->ioc), + false, &local_err)) { + goto out; + } + qio_channel_set_follow_coroutine_ctx(QIO_CHANNEL(client->ioc), true); =20 /* A very simple negotiation for future extensibility. No features @@ -786,6 +789,7 @@ static void coroutine_fn prh_co_entry(void *opaque) } } =20 +out: if (local_err) { if (verbose =3D=3D 0) { error_free(local_err); @@ -794,7 +798,6 @@ static void coroutine_fn prh_co_entry(void *opaque) } } =20 -out: object_unref(OBJECT(client->ioc)); g_free(client); } diff --git a/tests/unit/io-channel-helpers.c b/tests/unit/io-channel-helper= s.c index c0799c21c2..22b42d14cd 100644 --- a/tests/unit/io-channel-helpers.c +++ b/tests/unit/io-channel-helpers.c @@ -20,6 +20,7 @@ =20 #include "qemu/osdep.h" #include "io-channel-helpers.h" +#include "qapi/error.h" #include "qemu/iov.h" =20 struct QIOChannelTest { @@ -109,8 +110,8 @@ void qio_channel_test_run_threads(QIOChannelTest *test, test->src =3D src; test->dst =3D dst; =20 - qio_channel_set_blocking(test->dst, blocking, NULL); - qio_channel_set_blocking(test->src, blocking, NULL); + qio_channel_set_blocking(test->dst, blocking, &error_abort); + qio_channel_set_blocking(test->src, blocking, &error_abort); =20 reader =3D g_thread_new("reader", test_io_thread_reader, diff --git a/tests/unit/test-io-channel-tls.c b/tests/unit/test-io-channel-= tls.c index e036ac5df4..6f282ad45d 100644 --- a/tests/unit/test-io-channel-tls.c +++ b/tests/unit/test-io-channel-tls.c @@ -184,8 +184,8 @@ static void test_io_channel_tls(const void *opaque) * thread, so we need these non-blocking to avoid deadlock * of ourselves */ - qio_channel_set_blocking(QIO_CHANNEL(clientChanSock), false, NULL); - qio_channel_set_blocking(QIO_CHANNEL(serverChanSock), false, NULL); + qio_channel_set_blocking(QIO_CHANNEL(clientChanSock), false, &error_ab= ort); + qio_channel_set_blocking(QIO_CHANNEL(serverChanSock), false, &error_ab= ort); =20 /* Now the real part of the test, setup the sessions */ clientChanTLS =3D qio_channel_tls_new_client( diff --git a/tools/i386/qemu-vmsr-helper.c b/tools/i386/qemu-vmsr-helper.c index 5f19a48cbd..6c0f4fe870 100644 --- a/tools/i386/qemu-vmsr-helper.c +++ b/tools/i386/qemu-vmsr-helper.c @@ -213,8 +213,10 @@ static void coroutine_fn vh_co_entry(void *opaque) uint64_t vmsr; int r; =20 - qio_channel_set_blocking(QIO_CHANNEL(client->ioc), - false, NULL); + if (!qio_channel_set_blocking(QIO_CHANNEL(client->ioc), + false, &local_err)) { + goto out; + } =20 qio_channel_set_follow_coroutine_ctx(QIO_CHANNEL(client->ioc), true); =20 diff --git a/ui/vnc.c b/ui/vnc.c index 9054fc8125..77c823bf2e 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3337,7 +3337,7 @@ static void vnc_connect(VncDisplay *vd, QIOChannelSoc= ket *sioc, =20 VNC_DEBUG("New client on socket %p\n", vs->sioc); update_displaychangelistener(&vd->dcl, VNC_REFRESH_INTERVAL_BASE); - qio_channel_set_blocking(vs->ioc, false, NULL); + qio_channel_set_blocking(vs->ioc, false, &error_abort); if (vs->ioc_tag) { g_source_remove(vs->ioc_tag); } diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index b19229074a..d805a92394 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -336,6 +336,7 @@ static void vu_accept(QIONetListener *listener, QIOChan= nelSocket *sioc, gpointer opaque) { VuServer *server =3D opaque; + Error *local_err =3D NULL; =20 if (server->sioc) { warn_report("Only one vhost-user client is allowed to " @@ -368,7 +369,11 @@ static void vu_accept(QIONetListener *listener, QIOCha= nnelSocket *sioc, object_ref(OBJECT(server->ioc)); =20 /* TODO vu_message_write() spins if non-blocking! */ - qio_channel_set_blocking(server->ioc, false, NULL); + if (!qio_channel_set_blocking(server->ioc, false, &local_err)) { + error_report_err(local_err); + vu_deinit(&server->vu_dev); + return; + } =20 qio_channel_set_follow_coroutine_ctx(server->ioc, true); =20 --=20 2.50.1