From nobody Sun Sep 28 15:29:05 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=1758282783; cv=none; d=zohomail.com; s=zohoarc; b=YRE1lF7kzXgjKugjISLx4y9VMSif7SBtS2oRmmyF8p30iTT3tKWnBeIlJ4DqDX8hworyJgF2MnfwRQ4Asi1nnOioLh5p+z/K9z0kubcAZSSyNT0+GnEGcQp3i3nKscuAOZyc8j+AS26mijlMrDBAmdX1exapnno+xlO7TDXDhiY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282783; 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=1X8ssnAp9dmrYFTp2QEuf2wTnDfkKp7l5Plm26RpJHg=; b=QHQ+H+1+NjVfXLJ5jvyNuLQnINLZOf2bS5XFw0ZYJlscCZ5fQzTbENSq/hEpr4aN1Jdmx4SnIBCXhtL9hX0JvR0dY2IeCUS+z60IPA6vCRJdZ5QM8DhKG8AVxgf7oi9iP+h8ahO/UJQJBI/6B4MgQpOrAsZyGsWPHmR6kBwqE4w= 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 1758282783919831.4553780226752; Fri, 19 Sep 2025 04:53:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZdq-0001hg-44; Fri, 19 Sep 2025 07:51:06 -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 1uzZdn-0001gA-Q5 for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:51:03 -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 1uzZdd-0000lm-VO for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:51:03 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-HJvOr-v0MMSLyNVrwFHglw-1; Fri, 19 Sep 2025 07:50:44 -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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7CBA31800343; Fri, 19 Sep 2025 11:50:40 +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 BF64A1955F21; Fri, 19 Sep 2025 11:50:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282648; 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=1X8ssnAp9dmrYFTp2QEuf2wTnDfkKp7l5Plm26RpJHg=; b=MILCgH47HHkCnvA1AgIG4cWik7CT9jmABaHyAt0SJhSi25Jr4a5QwEajm/0YuZFBI21790 Ehz2K7CA0a1M9fyYDNBHvvf5TFge5LP6vxfI6ioSiOqnCIOi5tFkDURNMR7jNmcSHGIuhj +5OpGlJEYJhvXoSWzCYXt31rwDr7nLE= X-MC-Unique: HJvOr-v0MMSLyNVrwFHglw-1 X-Mimecast-MFC-AGG-ID: HJvOr-v0MMSLyNVrwFHglw_1758282641 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 , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mauro Matteo Cascella Subject: [PULL 01/16] MAINTAINERS: list qemu-security@nongnu.org as security contact Date: Fri, 19 Sep 2025 12:50:02 +0100 Message-ID: <20250919115017.1536203-2-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.129.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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, T_SPF_HELO_TEMPERROR=0.01, T_SPF_TEMPERROR=0.01 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: 1758282785966116600 The qemu-security@nongnu.org list is considered the authoritative contact for reporting QEMU security issues. Remove the Red Hat security team address in favour of QEMU's list, to ensure that upstream gets first contact. There is a representative of the Red Hat security team as a member of qemu-security@nongnu.org whom requests CVE assignments on behalf of QEMU when needed. Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Mauro Matteo Cascella Signed-off-by: Daniel P. Berrang=C3=A9 --- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index bd417e96f7..70eb0241d3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -85,7 +85,7 @@ Responsible Disclosure, Reporting Security Issues ------------------------------------------------- W: https://wiki.qemu.org/SecurityProcess M: Michael S. Tsirkin -L: secalert@redhat.com +L: qemu-security@nongnu.org =20 Trivial patches --------------- --=20 2.50.1 From nobody Sun Sep 28 15:29:05 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=1758282918; cv=none; d=zohomail.com; s=zohoarc; b=WGkLrU7gWe3uARTq2W/7NENpYzQIyeCrtmeE4a5TivFjHFCu20tRyM5skZMdcEUfSTyTcCa+dKON/CFLqZlkgFF8yDPoNYiKl3i+9b31aAQrm3lU2KtpsVnmXnu/3xeSJ+LNIBL8O4BZtDiwNfjOQrNIb/JLrihdJxu47wi9lwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282918; 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=PdRoEwCHMx+zjgwRt6dMBJqTTFrggUWD628P7VP28VY=; b=F2ZxooP6PPFrgxBOMwuVdvciLECpu3/IKNKvmA3lj+JPhPsRSSaNq8MxLEkZwgFkDlGRYy38yvzPs2WAfQ8tti+c5TAbB9NeAaCyl7/G7NeuQY4ctskSgEmdw3bZg9/we1WmUktAQzUNDsDj+nsry3J6KWpYRnD38O8cI7JgUJQ= 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 1758282918330671.8407800357585; Fri, 19 Sep 2025 04:55:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZds-0001ly-Ed; Fri, 19 Sep 2025 07:51:08 -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 1uzZdr-0001l2-5F for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:51:07 -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 1uzZdi-0000mT-ET for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:51:05 -0400 Received: from mx-prod-mc-05.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-313-FF262A2ENbOqTtDaVXgaPg-1; Fri, 19 Sep 2025 07:50:52 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 39B5819560A1; Fri, 19 Sep 2025 11:50:50 +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 DF2A01953944; Fri, 19 Sep 2025 11:50:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282656; 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=PdRoEwCHMx+zjgwRt6dMBJqTTFrggUWD628P7VP28VY=; b=YiXyl5LK1tOfFqE9IVloRk+rF0Yb3JdJjFKe33N91qQzEO/NZKnDbBVe5KgmfUsLEe+NdR 8MnPDTRBT6vZqI3ussv8lu9nvESLBOEsid6lz5yeRQRlLHOIBj0LwUuibCLi0z+wcB1Q1c YtKQu+ligb6EBhmrTwbWhGO1aSgJyiE= X-MC-Unique: FF262A2ENbOqTtDaVXgaPg-1 X-Mimecast-MFC-AGG-ID: FF262A2ENbOqTtDaVXgaPg_1758282650 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 02/16] migration/qemu-file: don't make incoming fds blocking again Date: Fri, 19 Sep 2025 12:50:03 +0100 Message-ID: <20250919115017.1536203-3-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.129.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_H4=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=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: 1758282919532116600 From: Vladimir Sementsov-Ogievskiy In migration we want to pass fd "as is", not changing its blocking status. The only current user of these fds is CPR state (through VMSTATE_FD), which of-course doesn't want to modify fds on target when source is still running and use these fds. Suggested-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Xu Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Daniel P. Berrang=C3=A9 --- include/io/channel.h | 1 + io/channel-socket.c | 13 +++++++++---- migration/qemu-file.c | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/io/channel.h b/include/io/channel.h index 234e5db70d..12266256a8 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -36,6 +36,7 @@ OBJECT_DECLARE_TYPE(QIOChannel, QIOChannelClass, =20 #define QIO_CHANNEL_READ_FLAG_MSG_PEEK 0x1 #define QIO_CHANNEL_READ_FLAG_RELAXED_EOF 0x2 +#define QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING 0x4 =20 typedef enum QIOChannelFeature QIOChannelFeature; =20 diff --git a/io/channel-socket.c b/io/channel-socket.c index 3b7ca924ff..21f8f2e0c5 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -464,7 +464,8 @@ static void qio_channel_socket_finalize(Object *obj) =20 #ifndef WIN32 static void qio_channel_socket_copy_fds(struct msghdr *msg, - int **fds, size_t *nfds) + int **fds, size_t *nfds, + bool preserve_blocking) { struct cmsghdr *cmsg; =20 @@ -497,8 +498,10 @@ static void qio_channel_socket_copy_fds(struct msghdr = *msg, continue; } =20 - /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ - qemu_socket_set_block(fd); + if (!preserve_blocking) { + /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ + qemu_socket_set_block(fd); + } =20 #ifndef MSG_CMSG_CLOEXEC qemu_set_cloexec(fd); @@ -556,7 +559,9 @@ static ssize_t qio_channel_socket_readv(QIOChannel *ioc, } =20 if (fds && nfds) { - qio_channel_socket_copy_fds(&msg, fds, nfds); + qio_channel_socket_copy_fds( + &msg, fds, nfds, + flags & QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING); } =20 return ret; diff --git a/migration/qemu-file.c b/migration/qemu-file.c index b6ac190034..d5c6e7ec61 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -340,7 +340,8 @@ static ssize_t coroutine_mixed_fn qemu_fill_buffer(QEMU= File *f) =20 do { struct iovec iov =3D { f->buf + pending, IO_BUF_SIZE - pending }; - len =3D qio_channel_readv_full(f->ioc, &iov, 1, pfds, pnfd, 0, + len =3D qio_channel_readv_full(f->ioc, &iov, 1, pfds, pnfd, + QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLO= CKING, &local_error); if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { if (qemu_in_coroutine()) { --=20 2.50.1 From nobody Sun Sep 28 15:29:05 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=1758282781; cv=none; d=zohomail.com; s=zohoarc; b=SynzIEItvHJn8gylIMgv8WlERUUifSt+JzX4Zd4Pa7qodxHwzEafoAMtWXA91dEurZ4yHOtBNt+Qe7xNk4hALwYlnm48mzKYIlCzJggxVy3pPSyswC5yxGrmFhK9Lgtd9Hfac2qXJ9W21W9qZZb+u3qtSnNjeymMKr9vTEVv6iY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282781; 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=kVgOQG1mOqMMrShBgYl6HdG7O1jge5gMd4Y6e+CPNqA=; b=POOPUFD0qbqBwloahnLHWO66WQwGeGMxZ5g3n6op71W9UQvH0gz7UmKPXis2wN/N42ps+mnW1Q5TH8yfnIsyb1bzvU5MichJuxfjtQjFahVPLtXauGCCYIilrZn6gKoQ41nHds7KsFdnF+JjnEEn7CNuT4dK8B+GbGxZEq7KbUQ= 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 1758282781035703.6607998295216; Fri, 19 Sep 2025 04:53:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZe3-0002EF-IV; Fri, 19 Sep 2025 07:51:19 -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 1uzZe2-00027z-8N for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:51:18 -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 1uzZdw-0000oD-TP for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:51:17 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-33-mJWvmZtmPq-bINoxBXqtxw-1; Fri, 19 Sep 2025 07:51:03 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 90D59180035C; Fri, 19 Sep 2025 11:51:00 +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 9E1781955F21; Fri, 19 Sep 2025 11:50:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282668; 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=kVgOQG1mOqMMrShBgYl6HdG7O1jge5gMd4Y6e+CPNqA=; b=eOSq/Wn+meKdjJdobgJyw9GPdX08GuFfp3JMvOwCZXMnjyptRi21v5nbjEw8DDw0bHZRQy alW6Mx3APs8i3sZjiZLbeKVlbVhFmabwfYN7/5WLCJA7Qjfc5FlJr075YrI7vXcLr9N87f fENpMnSihD9z3bDr8N7EdzXTTUMrfTo= X-MC-Unique: mJWvmZtmPq-bINoxBXqtxw-1 X-Mimecast-MFC-AGG-ID: mJWvmZtmPq-bINoxBXqtxw_1758282661 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 03/16] io/channel: document how qio_channel_readv_full() handles fds Date: Fri, 19 Sep 2025 12:50:04 +0100 Message-ID: <20250919115017.1536203-4-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.129.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_H4=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, T_SPF_TEMPERROR=0.01 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: 1758282781841116600 From: Vladimir Sementsov-Ogievskiy The only realization, which may have incoming fds is qio_channel_socket_readv() (in io/channel-socket.c). qio_channel_socket_readv() do call (through qio_channel_socket_copy_fds()) qemu_socket_set_block() and qemu_set_cloexec() for each fd. Also, qio_channel_socket_copy_fds() is called at the end of qio_channel_socket_readv(), on success path. Acked-by: Peter Xu Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Daniel P. Berrang=C3=A9 --- include/io/channel.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/io/channel.h b/include/io/channel.h index 12266256a8..c7f64506f7 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -118,6 +118,15 @@ struct QIOChannelClass { size_t nfds, int flags, Error **errp); + + /* + * The io_readv handler must guarantee that all + * incoming fds are set BLOCKING (unless + * QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING flag is set) and + * CLOEXEC (if available). + * @fds and @nfds are set only on success path, and untouched + * in case of errors. + */ ssize_t (*io_readv)(QIOChannel *ioc, const struct iovec *iov, size_t niov, @@ -125,6 +134,7 @@ struct QIOChannelClass { size_t *nfds, int flags, Error **errp); + int (*io_close)(QIOChannel *ioc, Error **errp); GSource * (*io_create_watch)(QIOChannel *ioc, @@ -235,6 +245,13 @@ void qio_channel_set_name(QIOChannel *ioc, * was allocated. It is the callers responsibility * to call close() on each file descriptor and to * call g_free() on the array pointer in @fds. + * @fds allocated and set (and @nfds is set too) + * _only_ on success path. These parameters are + * untouched in case of errors. + * qio_channel_readv_full() guarantees that all + * incoming fds are set BLOCKING (unless + * QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING flag + * is set) and CLOEXEC (if available). * * It is an error to pass a non-NULL @fds parameter * unless qio_channel_has_feature() returns a true --=20 2.50.1 From nobody Sun Sep 28 15:29:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1758282781; cv=none; d=zohomail.com; s=zohoarc; b=Ce1I0s3s07lr3dRZt+ZVp9CbRocM4ztDl7h+e7LsGBDf2JD0J3FD2P8QzNMsKAqkQ6uc21fKwDdFdsdCIfTLEJECq0P/3Pa9YnAqofHmDEQwZxpj/InAdlVpndU0q56ag14j1jUHx9vXGCva00rI+TuMAtlfGIDSWpA8T7AmNDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282781; 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:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=3q3laFhjxPJKlhMhuHPLwdXmfd33rpdgudU2nn8b1RY=; b=GPDDuWcZ/4zk5XUf10hpB3FeZuFG6XZ7O8BMi2wcQKlVCy+BhqZ2EzQH1DqjO7xwYT7OAiUfhl3OPBigVFz+gESyn+mYpTMkKvcDklug1KF5VrggKe+Z/R8lIfRSXH1DNiF9NeZswAEThlIccj/mFQvzdp9zPnMI7gAAlx1HfVc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1758282781221973.7692850967687; Fri, 19 Sep 2025 04:53:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZeK-0002PL-Hl; Fri, 19 Sep 2025 07:51:36 -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 1uzZeH-0002Mw-AZ for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:51: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 1uzZe8-0000on-0W for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:51:32 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-414-_0SSnr8BMIKkpk8nr-R7Rw-1; Fri, 19 Sep 2025 07:51:13 -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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 098501800451; Fri, 19 Sep 2025 11:51:11 +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 15B2E1955F21; Fri, 19 Sep 2025 11:51:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282677; 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=3q3laFhjxPJKlhMhuHPLwdXmfd33rpdgudU2nn8b1RY=; b=QEkqh1grHhoHatC8qsRkXYeHHzSOfG4Nw+axNt+kV542wuqGD2kkkzsjhTZn4PbaBcPWFg Nrq9X746RXlMWSkTxeZnHkrMK9SGfSb3P3KmzlsekRz3/j99C3oHsQ7sh5rBiPZ5camSmC lNiN9JfA0/byqMeONa9NPVH70wkXMns= X-MC-Unique: _0SSnr8BMIKkpk8nr-R7Rw-1 X-Mimecast-MFC-AGG-ID: _0SSnr8BMIKkpk8nr-R7Rw_1758282671 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 04/16] char-socket: tcp_chr_recv(): drop extra _set_(block, cloexec) Date: Fri, 19 Sep 2025 12:50:05 +0100 Message-ID: <20250919115017.1536203-5-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_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: , Reply-to: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758282781835116601 From: Vladimir Sementsov-Ogievskiy qio_channel_readv_full() guarantees BLOCKING and CLOEXEC states for incoming descriptors, no reason to call extra ioctls. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Daniel P. Berrang=C3=A9 --- chardev/char-socket.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 1e8313915b..b1ce5d01c7 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -307,20 +307,6 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf, s= ize_t len) s->read_msgfds_num =3D msgfds_num; } =20 - for (i =3D 0; i < s->read_msgfds_num; i++) { - int fd =3D s->read_msgfds[i]; - if (fd < 0) { - continue; - } - - /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ - qemu_socket_set_block(fd); - -#ifndef MSG_CMSG_CLOEXEC - qemu_set_cloexec(fd); -#endif - } - if (ret =3D=3D QIO_CHANNEL_ERR_BLOCK) { errno =3D EAGAIN; ret =3D -1; --=20 2.50.1 From nobody Sun Sep 28 15:29:05 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=1758282779; cv=none; d=zohomail.com; s=zohoarc; b=V9VDQCGrQF0rtWaX0lYTZy65BOwyq/C4rwHqsaG6qRfNBomqv/AkDuNNaHDaLZ6gZEs5lYbpgwfypcic3W5MP5QsD/RaWN0hoaqKdwtWXTtrr7kgF/REbrrmVaTBrb1mul8n0/7C6HoL3sIfHlS8puQVszx6/dI0kIgJ9Si8q7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282779; 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=aYbFxVq+Dg/2d/l2nCPF94mEkoEMfK/UjL78kqcQAuE=; b=KN16d0F8jcPpkGrr6BiLIK4Nj8VGjMaTpYi86MFK0YOLN1XZpGF6rIGFMk+OLH04ddJQgYyq++WWF70UhkpZmrebPaF7HX8I23Tp5mSXQ3UFL5rs1tYTwen/hu5reICL09zVb7aRm8dNETvgQtP/TnzfU4upigm9VqEJN5lMmWc= 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 1758282779110792.0380653261652; Fri, 19 Sep 2025 04:52:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZed-0002VQ-8c; Fri, 19 Sep 2025 07:51:55 -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 1uzZeL-0002Q4-KP for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:51:37 -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 1uzZeF-0000pY-HG for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:51:37 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-230-trPstYJBPsC7fQ_q4uRgsw-1; Fri, 19 Sep 2025 07:51:23 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D93F618004D4; Fri, 19 Sep 2025 11:51:20 +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 690951955F21; Fri, 19 Sep 2025 11:51:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282687; 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=aYbFxVq+Dg/2d/l2nCPF94mEkoEMfK/UjL78kqcQAuE=; b=NCNZbcwTbPR11lRbz+HQjr9VCmvs/zNi0sskQ11pfxWtS81Llto6S4n15ctNOleWepXGG5 4XzjV4dY2ImEwowx/kNbb/hBtqPRYAM2KqQhB6ozvRUlOA37zrFJkgxokyFAvlJrGrDrEG slQbsAL7Y9B5eiT9ufXG9/lrl2uZ4Kc= X-MC-Unique: trPstYJBPsC7fQ_q4uRgsw-1 X-Mimecast-MFC-AGG-ID: trPstYJBPsC7fQ_q4uRgsw_1758282681 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 05/16] char-socket: tcp_chr_recv(): add comment Date: Fri, 19 Sep 2025 12:50:06 +0100 Message-ID: <20250919115017.1536203-6-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: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=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=no 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: 1758282780567116600 From: Vladimir Sementsov-Ogievskiy Add comment, to stress that the order of operation (first drop old fds, second check read status) is intended. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Daniel P. Berrang=C3=A9 --- chardev/char-socket.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index b1ce5d01c7..1be078dfc0 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -294,7 +294,12 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf, s= ize_t len) } =20 if (msgfds_num) { - /* close and clean read_msgfds */ + /* + * Close and clean previous read_msgfds, they are obsolete at + * this point, regardless result of new call to + * qio_channel_readv_full(). + */ + for (i =3D 0; i < s->read_msgfds_num; i++) { close(s->read_msgfds[i]); } --=20 2.50.1 From nobody Sun Sep 28 15:29:05 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=1758282786; cv=none; d=zohomail.com; s=zohoarc; b=kmdrJUASgn8h2ZYmvwg3PMiP18QLJZzPprg207mSKORS+WVCCJxwgvPqw68jUcz0jEIKs5vY+0WmLH2tc1j6QfEAaD+9qnK2XOfp9RPb9h4DNFpa2TwCsgzOkiac5K/O1iiJO7As9nwqOkR8uTCKofRQvBLIbswvLNfkNYtGrNU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282786; 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=lse4TUK4YsNm2dA0AOzJMTi63TonEkTeeFzhtxCHbUk=; b=L+ti9jaW9CMGd8mpAgVfcdlKUvm8iPi9EEYOo9GGAsrhCY3nAdcaoVtj9ZNt0eOrzLi2XL6kfJ9UMnom69quJMMJOVmUI4DfFkGen28uN7BBXN/Y0h4173Xa4gHN8RL9hhUVD1cUHTeIg2GumaObdazJxx8rTIr7N0E/8ktwI9s= 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 1758282786881354.5248307309414; Fri, 19 Sep 2025 04:53:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZf9-0002gd-0L; Fri, 19 Sep 2025 07:52:31 -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 1uzZeY-0002UQ-0L for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:51:52 -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 1uzZeQ-0000qc-Oy for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:51:49 -0400 Received: from mx-prod-mc-03.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-658-L4vFGNtOMFCbfO8N1CjhEQ-1; Fri, 19 Sep 2025 07:51:34 -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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 957F119560B7; Fri, 19 Sep 2025 11:51:31 +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 6BECE1955F21; Fri, 19 Sep 2025 11:51:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282697; 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=lse4TUK4YsNm2dA0AOzJMTi63TonEkTeeFzhtxCHbUk=; b=ZPiACS2ahJr80kjVZnrM7Pc6SB2AizNOtcxXiK9zdV/274J0pKgiEwJj13FmT2RJhQHDFG NMALxKDb1p8s0NN+yk9+rW4qiQICJMsrLIjbCqfsB7S4XRfmabysKpDES+nW0ZcAH91W6F awjMVAVIA6LdBSSfB63wndEUq8N5V6M= X-MC-Unique: L4vFGNtOMFCbfO8N1CjhEQ-1 X-Mimecast-MFC-AGG-ID: L4vFGNtOMFCbfO8N1CjhEQ_1758282691 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 06/16] util: add qemu_set_blocking() function Date: Fri, 19 Sep 2025 12:50:07 +0100 Message-ID: <20250919115017.1536203-7-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: 1758282787957116600 From: Vladimir Sementsov-Ogievskiy In generic code we have qio_channel_set_blocking(), which takes bool parameter, and qemu_file_set_blocking(), which as well takes bool parameter. At lower fd-layer we have a mess of functions: - enough direct calls to Unix-specific g_unix_set_fd_nonblocking() (of course, all calls are out of Windows-compatible code), which is glib specific with GError, which we can't use, and have to handle error-reporting by hand after the call. and several platform-agnostic qemu_* helpers: - qemu_socket_set_nonblock(), which asserts success for posix (still, in most cases we can handle the error in better way) and ignores error for win32 realization - qemu_socket_try_set_nonblock(), providing and error, but not errp, so we have to handle it after the call - qemu_socket_set_block(), which simply ignores an error Note, that *_socket_* word in original API, which we are going to substitute was intended, because Windows support these operations only for sockets. What leads to solution of dropping it again? 1. Having a QEMU-native wrapper with errp parameter for g_unix_set_fd_nonblocking() for non-socket fds worth doing, at least to unify error handling. 2. So, if try to keep _socket_ vs _file_ words, we'll have two actually duplicated functions for Linux, which actually will be executed successfully on any (good enough) fds, and nothing prevent using them improperly except for the name. That doesn't look good. 3. Naming helped us in the world where we crash on errors or ignore them. Now, with errp parameter, callers are intended to proper error checking. And for places where we really OK with crash-on-error semantics (like tests), we have an explicit &error_abort. So, this commit starts a series, which will effectively revert commit ff5927baa7ffb9 "util: rename qemu_*block() socket functions" (which in turn was reverting f9e8cacc5557e43 "oslib-posix: rename socket_set_nonblock() to qemu_set_nonblock()", so that's a long story). Now we don't simply rename, instead we provide the new API and update all the callers. This commit only introduces a new fd-layer wrapper. Next commits will replace old API calls with it, and finally remove old API. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/osdep.h | 1 + util/oslib-posix.c | 15 +++++++++++++++ util/oslib-win32.c | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index be3460b32f..1b38cb7e45 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -687,6 +687,7 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t= count) G_GNUC_WARN_UNUSED_RESULT; =20 void qemu_set_cloexec(int fd); +bool qemu_set_blocking(int fd, bool block, Error **errp); =20 /* Return a dynamically allocated directory path that is appropriate for s= toring * local state. diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 4ff577e5de..c737701075 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -250,6 +250,21 @@ void qemu_anon_ram_free(void *ptr, size_t size) #endif } =20 +bool qemu_set_blocking(int fd, bool block, Error **errp) +{ + g_autoptr(GError) err =3D NULL; + + if (!g_unix_set_fd_nonblocking(fd, !block, &err)) { + error_setg_errno(errp, errno, + "Can't set file descriptor %d %s: %s", fd, + block ? "blocking" : "non-blocking", + err->message); + return false; + } + + return true; +} + void qemu_socket_set_block(int fd) { g_unix_set_fd_nonblocking(fd, false, NULL); diff --git a/util/oslib-win32.c b/util/oslib-win32.c index b7351634ec..03044f5b59 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -177,6 +177,24 @@ static int socket_error(void) } } =20 +bool qemu_set_blocking(int fd, bool block, Error **errp) +{ + unsigned long opt =3D block ? 0 : 1; + + if (block) { + qemu_socket_unselect(fd, NULL); + } + + if (ioctlsocket(fd, FIONBIO, &opt) !=3D NO_ERROR) { + error_setg_errno(errp, socket_error(), + "Can't set file descriptor %d %s", fd, + block ? "blocking" : "non-blocking"); + return false; + } + + return true; +} + void qemu_socket_set_block(int fd) { unsigned long opt =3D 0; --=20 2.50.1 From nobody Sun Sep 28 15:29:05 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 From nobody Sun Sep 28 15:29:05 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=1758282953; cv=none; d=zohomail.com; s=zohoarc; b=BA99XPgSmpmEXaOWpWGigdW+EqU2qWTRIQr/nZxD66e2MT+bjqXuczlxlOf1DuJslCLp2COEbJcCc09BLK0J9SpUX5jy5Cbmr+uff+jRvxF2gf00/Xj75jgNm4TjuiLLzYflexwwgSGAaoLBBEZ71U6LLdQjLPU5UUrYR5POioI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282953; 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=B0mk2+5odIxLDvJ8M3BZaxRVZ+iWKW+dUIpWQQsle4E=; b=imRFhlqF27/ahx44ADBdoUEcQEbR8kKVkObKxoDhegnnKbvqJgATv2VpHBTfgX93YCFxyL4VnS/ajT6wSQ0GEdE/euV/VgeTJk3P99FUq5V1RRxMEGZVQeA2ei52k7RzJe4MhifM7gh/4TgXeFj8OVWCk9C20nvon/pqczoVgNg= 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 1758282953429499.8101277772179; Fri, 19 Sep 2025 04:55:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZfQ-0002xo-Pu; Fri, 19 Sep 2025 07:52:44 -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 1uzZen-0002cT-Pf for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:52:09 -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 1uzZel-0000sp-5z for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:52:05 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-311-UuI39O5qO6yFgKM27TwZnQ-1; Fri, 19 Sep 2025 07:51:54 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BEA451800288; Fri, 19 Sep 2025 11:51:51 +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 C76351955F21; Fri, 19 Sep 2025 11:51:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282717; 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=B0mk2+5odIxLDvJ8M3BZaxRVZ+iWKW+dUIpWQQsle4E=; b=Yz9L9SvuWPsJkRFRSW0T3BLxcYlFAD/J+F4PjYi03xB4eq1xQuzvnTYP+b7hKdctLDsIGh 7VrZ6k3+1apz1ftoTc9AVIl9qFIf5PrIj2v4vpKdopJTOEy5tVakUSZmfhjrTB1QKVLsQg wdwC7DSE/jNd7WcRkNCTN+uoSWOitrE= X-MC-Unique: UuI39O5qO6yFgKM27TwZnQ-1 X-Mimecast-MFC-AGG-ID: UuI39O5qO6yFgKM27TwZnQ_1758282712 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 08/16] migration: qemu_file_set_blocking(): add errp parameter Date: Fri, 19 Sep 2025 12:50:09 +0100 Message-ID: <20250919115017.1536203-9-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.129.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_H4=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: 1758282955826116600 From: Vladimir Sementsov-Ogievskiy qemu_file_set_blocking() is a wrapper on qio_channel_set_blocking(), so let's passthrough the errp. Note the migration should not be using &error_abort in these calls, however, this is done to expedite the API conversion. The original code would have eventually ended up calling either qemu_socket_set_nonblock which would asset on Linux, or g_unix_set_fd_nonblocking which would propagate errors. We never saw asserts in practice, and conceptually they should not happen, but ideally this code will be later adapted to remove use of &error_abort. Acked-by: Peter Xu Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Daniel P. Berrang=C3=A9 --- migration/colo.c | 5 ++++- migration/migration.c | 8 +++++--- migration/postcopy-ram.c | 2 +- migration/qemu-file.c | 4 ++-- migration/qemu-file.h | 2 +- migration/savevm.c | 4 ++-- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/migration/colo.c b/migration/colo.c index e0f713c837..cf4d71d9ed 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -859,7 +859,10 @@ static void *colo_process_incoming_thread(void *opaque) * coroutine, and here we are in the COLO incoming thread, so it is ok= to * set the fd back to blocked. */ - qemu_file_set_blocking(mis->from_src_file, true); + if (!qemu_file_set_blocking(mis->from_src_file, true, &local_err)) { + error_report_err(local_err); + goto out; + } =20 colo_incoming_start_dirty_log(); =20 diff --git a/migration/migration.c b/migration/migration.c index 10c216d25d..e1ac4d73c2 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -951,7 +951,7 @@ static void migration_incoming_setup(QEMUFile *f) =20 assert(!mis->from_src_file); mis->from_src_file =3D f; - qemu_file_set_blocking(f, false); + qemu_file_set_blocking(f, false, &error_abort); } =20 void migration_incoming_process(void) @@ -971,7 +971,7 @@ static bool postcopy_try_recover(void) /* This should be set already in migration_incoming_setup() */ assert(mis->from_src_file); /* Postcopy has standalone thread to do vm load */ - qemu_file_set_blocking(mis->from_src_file, true); + qemu_file_set_blocking(mis->from_src_file, true, &error_abort); =20 /* Re-configure the return path */ mis->to_src_file =3D qemu_file_get_return_path(mis->from_src_file); @@ -4002,7 +4002,9 @@ void migration_connect(MigrationState *s, Error *erro= r_in) } =20 migration_rate_set(rate_limit); - qemu_file_set_blocking(s->to_dst_file, true); + if (!qemu_file_set_blocking(s->to_dst_file, true, &local_err)) { + goto fail; + } =20 /* * Open the return path. For postcopy, it is used exclusively. For diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 45af9a361e..0172172343 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1909,7 +1909,7 @@ void postcopy_preempt_new_channel(MigrationIncomingSt= ate *mis, QEMUFile *file) * The new loading channel has its own threads, so it needs to be * blocked too. It's by default true, just be explicit. */ - qemu_file_set_blocking(file, true); + qemu_file_set_blocking(file, true, &error_abort); mis->postcopy_qemufile_dst =3D file; qemu_sem_post(&mis->postcopy_qemufile_dst_done); trace_postcopy_preempt_new_channel(); diff --git a/migration/qemu-file.c b/migration/qemu-file.c index d5c6e7ec61..0f4280df21 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -888,9 +888,9 @@ void qemu_put_counted_string(QEMUFile *f, const char *s= tr) * both directions, and thus changing the blocking on the main * QEMUFile can also affect the return path. */ -void qemu_file_set_blocking(QEMUFile *f, bool block) +bool qemu_file_set_blocking(QEMUFile *f, bool block, Error **errp) { - qio_channel_set_blocking(f->ioc, block, NULL); + return qio_channel_set_blocking(f->ioc, block, errp); } =20 /* diff --git a/migration/qemu-file.h b/migration/qemu-file.h index f5b9f430e0..c13c967167 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -71,7 +71,7 @@ void qemu_file_set_error(QEMUFile *f, int ret); int qemu_file_shutdown(QEMUFile *f); QEMUFile *qemu_file_get_return_path(QEMUFile *f); int qemu_fflush(QEMUFile *f); -void qemu_file_set_blocking(QEMUFile *f, bool block); +bool qemu_file_set_blocking(QEMUFile *f, bool block, Error **errp); int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size); void qemu_set_offset(QEMUFile *f, off_t off, int whence); off_t qemu_get_offset(QEMUFile *f); diff --git a/migration/savevm.c b/migration/savevm.c index fabbeb296a..abe0547f9b 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2095,7 +2095,7 @@ static void *postcopy_ram_listen_thread(void *opaque) * Because we're a thread and not a coroutine we can't yield * in qemu_file, and thus we must be blocking now. */ - qemu_file_set_blocking(f, true); + qemu_file_set_blocking(f, true, &error_fatal); =20 /* TODO: sanity check that only postcopiable data will be loaded here = */ load_res =3D qemu_loadvm_state_main(f, mis); @@ -2108,7 +2108,7 @@ static void *postcopy_ram_listen_thread(void *opaque) f =3D mis->from_src_file; =20 /* And non-blocking again so we don't block in any cleanup */ - qemu_file_set_blocking(f, false); + qemu_file_set_blocking(f, false, &error_fatal); =20 trace_postcopy_ram_listen_thread_exit(); if (load_res < 0) { --=20 2.50.1 From nobody Sun Sep 28 15:29:05 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=1758282828; cv=none; d=zohomail.com; s=zohoarc; b=n2JONJ4Da29bo1IvPZwR6PWwFvaszgFjygidDJ63CFOeRHcAQ16LsoOutso7/HR6ICVpUrwlc0i/FqqiEhW56qQePdGIedpEP2hibHMUnMDB6i/dTxVsubLguCmfISAHz83SDmG0dPWeyQuLVXkCbmm89WR6WuQYfRGJ7kNLvQs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282828; 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=ATlsXS8BZZhkrb06fgwiQpKpule5hVLhnbHVKaTdUx4=; b=jiFT1AQGUM42hDPBof2mOlJa/pgBtA5bCv8y6h3HvJDE6Y3PTC85h+i/UkjWBDVBmI9CvVMT+5f4q70h27y75rTP2UJY0HSpi2JEwLehMSOhflGXt4S4zU/ODFA5eAjZiEjxVGNt1zcd7NtIClGiBCKOWbIhieECi2vn1qk2BDo= 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 1758282828593993.5589294417096; Fri, 19 Sep 2025 04:53:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZfU-00035Y-KV; Fri, 19 Sep 2025 07:52:48 -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 1uzZf2-0002jm-NN for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:52:22 -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 1uzZew-0000tz-NA for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:52:19 -0400 Received: from mx-prod-mc-04.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-173-_5Y_3oHGMSKUlyQjfTyZoQ-1; Fri, 19 Sep 2025 07:52:04 -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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1FF3119560B0; Fri, 19 Sep 2025 11:52:02 +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 2F7B51955F21; Fri, 19 Sep 2025 11:51:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282727; 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=ATlsXS8BZZhkrb06fgwiQpKpule5hVLhnbHVKaTdUx4=; b=KFursU0I8dpyDeRC7AWoGYjJ6EQbmF4C5JYfXmPO9p5l6oi1DP8x1cYWXYBZ2LKCvt8gvJ hopkH2klgdzqHzUgkOlZH66qhpzvN/gWKDX/DIvFjAWvugpijSa9ycAncIFfNDbiFyXf4r JBmnip7QnGl/hTYgI4ZlOpj9I7zS/WQ= X-MC-Unique: _5Y_3oHGMSKUlyQjfTyZoQ-1 X-Mimecast-MFC-AGG-ID: _5Y_3oHGMSKUlyQjfTyZoQ_1758282722 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 09/16] util: drop qemu_socket_set_nonblock() Date: Fri, 19 Sep 2025 12:50:10 +0100 Message-ID: <20250919115017.1536203-10-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.129.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_H4=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: 1758282830806116600 From: Vladimir Sementsov-Ogievskiy Use common qemu_set_blocking() instead. Note that pre-patch the behavior of Win32 and Linux realizations are inconsistent: we ignore failure for Win32, and assert success for Linux. How do we convert the callers? 1. Most of callers call qemu_socket_set_nonblock() on a freshly created socket fd, in conditions when we may simply report an error. Seems correct switching to error handling both for Windows (pre-patch error is ignored) and Linux (pre-patch we assert success). Anyway, we normally don't expect errors in these cases. Still in tests let's use &error_abort for simplicity. What are exclusions? 2. hw/virtio/vhost-user.c - we are inside #ifdef CONFIG_LINUX, so no damage in switching to error handling from assertion. 3. io/channel-socket.c: here we convert both old calls to qemu_socket_set_nonblock() and qemu_socket_set_block() to one new call. Pre-patch we assert success for Linux in qemu_socket_set_nonblock(), and ignore all other errors here. So, for Windows switch is a bit dangerous: we may get new errors or crashes(when error_abort is passed) in cases where we have silently ignored the error before (was it correct in all such cases, if they were?) Still, there is no other way to stricter API than take this risk. 4. util/vhost-user-server - compiled only for Linux (see util/meson.build), so we are safe, switching from assertion to &error_abort. Note: In qga/channel-posix.c we use g_warning(), where g_printerr() would actually be a better choice. Still let's for now follow common style of qga, where g_warning() is commonly used to print such messages, and no call to g_printerr(). Converting everything to use g_printerr() should better be another series. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Daniel P. Berrang=C3=A9 --- contrib/ivshmem-server/ivshmem-server.c | 9 ++++++++- hw/hyperv/syndbg.c | 4 +++- hw/virtio/vhost-user.c | 5 ++++- include/qemu/sockets.h | 1 - io/channel-socket.c | 7 +++---- net/dgram.c | 16 +++++++++++++--- net/l2tpv3.c | 5 +++-- net/socket.c | 20 ++++++++++++++++---- qga/channel-posix.c | 7 ++++++- tests/unit/socket-helpers.c | 4 +++- tests/unit/test-crypto-tlssession.c | 8 ++++---- util/oslib-posix.c | 7 ------- util/oslib-win32.c | 5 ----- util/vhost-user-server.c | 6 ++++-- 14 files changed, 67 insertions(+), 37 deletions(-) diff --git a/contrib/ivshmem-server/ivshmem-server.c b/contrib/ivshmem-serv= er/ivshmem-server.c index 2f3c7320a6..13cb828174 100644 --- a/contrib/ivshmem-server/ivshmem-server.c +++ b/contrib/ivshmem-server/ivshmem-server.c @@ -6,6 +6,7 @@ * top-level directory. */ #include "qemu/osdep.h" +#include "qapi/error.h" #include "qemu/host-utils.h" #include "qemu/sockets.h" =20 @@ -135,6 +136,7 @@ ivshmem_server_handle_new_conn(IvshmemServer *server) socklen_t unaddr_len; int newfd; unsigned i; + Error *local_err =3D NULL; =20 /* accept the incoming connection */ unaddr_len =3D sizeof(unaddr); @@ -146,9 +148,14 @@ ivshmem_server_handle_new_conn(IvshmemServer *server) return -1; } =20 - qemu_socket_set_nonblock(newfd); IVSHMEM_SERVER_DEBUG(server, "accept()=3D%d\n", newfd); =20 + if (!qemu_set_blocking(newfd, false, &local_err)) { + error_report_err(local_err); + close(newfd); + return -1; + } + /* allocate new structure for this peer */ peer =3D g_malloc0(sizeof(*peer)); peer->sock_fd =3D newfd; diff --git a/hw/hyperv/syndbg.c b/hw/hyperv/syndbg.c index ac7e15f6f1..bcdfdf6af7 100644 --- a/hw/hyperv/syndbg.c +++ b/hw/hyperv/syndbg.c @@ -338,7 +338,9 @@ static void hv_syndbg_realize(DeviceState *dev, Error *= *errp) return; } =20 - qemu_socket_set_nonblock(syndbg->socket); + if (!qemu_set_blocking(syndbg->socket, false, errp)) { + return; + } =20 syndbg->servaddr.sin_port =3D htons(syndbg->host_port); syndbg->servaddr.sin_family =3D AF_INET; diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 1e1d6b0d6e..36c9c2e04d 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -2039,7 +2039,10 @@ static int vhost_user_postcopy_advise(struct vhost_d= ev *dev, Error **errp) error_setg(errp, "%s: Failed to get ufd", __func__); return -EIO; } - qemu_socket_set_nonblock(ufd); + if (!qemu_set_blocking(ufd, false, errp)) { + close(ufd); + return -EINVAL; + } =20 /* register ufd with userfault thread */ u->postcopy_fd.fd =3D ufd; diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index c562690d89..6477f90b9e 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -48,7 +48,6 @@ int socket_set_cork(int fd, int v); int socket_set_nodelay(int fd); void qemu_socket_set_block(int fd); int qemu_socket_try_set_nonblock(int fd); -void qemu_socket_set_nonblock(int fd); int socket_set_fast_reuse(int fd); =20 #ifdef WIN32 diff --git a/io/channel-socket.c b/io/channel-socket.c index 21f8f2e0c5..f7e3cb9742 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -825,11 +825,10 @@ qio_channel_socket_set_blocking(QIOChannel *ioc, { QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); =20 - if (enabled) { - qemu_socket_set_block(sioc->fd); - } else { - qemu_socket_set_nonblock(sioc->fd); + if (!qemu_set_blocking(sioc->fd, enabled, errp)) { + return -1; } + return 0; } =20 diff --git a/net/dgram.c b/net/dgram.c index 48f653bceb..fb9ded30df 100644 --- a/net/dgram.c +++ b/net/dgram.c @@ -226,7 +226,10 @@ static int net_dgram_mcast_create(struct sockaddr_in *= mcastaddr, } } =20 - qemu_socket_set_nonblock(fd); + if (!qemu_set_blocking(fd, false, errp)) { + goto fail; + } + return fd; fail: if (fd >=3D 0) { @@ -504,7 +507,11 @@ int net_init_dgram(const Netdev *netdev, const char *n= ame, close(fd); return -1; } - qemu_socket_set_nonblock(fd); + + if (!qemu_set_blocking(fd, false, errp)) { + close(fd); + return -1; + } =20 dest_len =3D sizeof(raddr_in); dest_addr =3D g_malloc(dest_len); @@ -551,7 +558,10 @@ int net_init_dgram(const Netdev *netdev, const char *n= ame, close(fd); return -1; } - qemu_socket_set_nonblock(fd); + if (!qemu_set_blocking(fd, false, errp)) { + close(fd); + return -1; + } =20 dest_len =3D sizeof(raddr_un); dest_addr =3D g_malloc(dest_len); diff --git a/net/l2tpv3.c b/net/l2tpv3.c index b5547cb917..cdfc641aa6 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -648,6 +648,9 @@ int net_init_l2tpv3(const Netdev *netdev, error_setg(errp, "could not bind socket err=3D%i", errno); goto outerr; } + if (!qemu_set_blocking(fd, false, errp)) { + goto outerr; + } =20 freeaddrinfo(result); =20 @@ -709,8 +712,6 @@ int net_init_l2tpv3(const Netdev *netdev, s->vec =3D g_new(struct iovec, MAX_L2TPV3_IOVCNT); s->header_buf =3D g_malloc(s->header_size); =20 - qemu_socket_set_nonblock(fd); - s->fd =3D fd; s->counter =3D 0; =20 diff --git a/net/socket.c b/net/socket.c index 784dda686f..db25e3d9ae 100644 --- a/net/socket.c +++ b/net/socket.c @@ -295,7 +295,10 @@ static int net_socket_mcast_create(struct sockaddr_in = *mcastaddr, } } =20 - qemu_socket_set_nonblock(fd); + if (!qemu_set_blocking(fd, false, errp)) { + goto fail; + } + return fd; fail: if (fd >=3D 0) @@ -508,7 +511,10 @@ static int net_socket_listen_init(NetClientState *peer, error_setg_errno(errp, errno, "can't create stream socket"); return -1; } - qemu_socket_set_nonblock(fd); + if (!qemu_set_blocking(fd, false, errp)) { + close(fd); + return -1; + } =20 socket_set_fast_reuse(fd); =20 @@ -556,7 +562,10 @@ static int net_socket_connect_init(NetClientState *pee= r, error_setg_errno(errp, errno, "can't create stream socket"); return -1; } - qemu_socket_set_nonblock(fd); + if (!qemu_set_blocking(fd, false, errp)) { + close(fd); + return -1; + } =20 connected =3D 0; for(;;) { @@ -671,7 +680,10 @@ static int net_socket_udp_init(NetClientState *peer, close(fd); return -1; } - qemu_socket_set_nonblock(fd); + if (!qemu_set_blocking(fd, false, errp)) { + close(fd); + return -1; + } =20 s =3D net_socket_fd_init_dgram(peer, model, name, fd, 0, NULL, errp); if (!s) { diff --git a/qga/channel-posix.c b/qga/channel-posix.c index 465d688ecb..9ccc8b7bd1 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -28,6 +28,7 @@ static gboolean ga_channel_listen_accept(GIOChannel *chan= nel, GAChannel *c =3D data; int ret, client_fd; bool accepted =3D false; + Error *err =3D NULL; =20 g_assert(channel !=3D NULL); =20 @@ -36,7 +37,11 @@ static gboolean ga_channel_listen_accept(GIOChannel *cha= nnel, g_warning("error converting fd to gsocket: %s", strerror(errno)); goto out; } - qemu_socket_set_nonblock(client_fd); + if (!qemu_set_blocking(client_fd, false, &err)) { + g_warning("%s", error_get_pretty(err)); + error_free(err); + goto out; + } ret =3D ga_channel_client_add(c, client_fd); if (ret) { g_warning("error setting up connection"); diff --git a/tests/unit/socket-helpers.c b/tests/unit/socket-helpers.c index 37db24f72a..46d2ff101c 100644 --- a/tests/unit/socket-helpers.c +++ b/tests/unit/socket-helpers.c @@ -19,6 +19,7 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/error.h" #include "qemu/sockets.h" #include "socket-helpers.h" =20 @@ -88,7 +89,8 @@ static int socket_can_bind_connect(const char *hostname, = int family) goto cleanup; } =20 - qemu_socket_set_nonblock(cfd); + qemu_set_blocking(cfd, false, &error_abort); + if (connect(cfd, (struct sockaddr *)&ss, sslen) < 0) { if (errno =3D=3D EINPROGRESS) { check_soerr =3D true; diff --git a/tests/unit/test-crypto-tlssession.c b/tests/unit/test-crypto-t= lssession.c index 554054e934..61311cbe6e 100644 --- a/tests/unit/test-crypto-tlssession.c +++ b/tests/unit/test-crypto-tlssession.c @@ -112,8 +112,8 @@ static void test_crypto_tls_session_psk(void) * thread, so we need these non-blocking to avoid deadlock * of ourselves */ - qemu_socket_set_nonblock(channel[0]); - qemu_socket_set_nonblock(channel[1]); + qemu_set_blocking(channel[0], false, &error_abort); + qemu_set_blocking(channel[1], false, &error_abort); =20 clientCreds =3D test_tls_creds_psk_create( QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT, @@ -264,8 +264,8 @@ static void test_crypto_tls_session_x509(const void *op= aque) * thread, so we need these non-blocking to avoid deadlock * of ourselves */ - qemu_socket_set_nonblock(channel[0]); - qemu_socket_set_nonblock(channel[1]); + qemu_set_blocking(channel[0], false, &error_abort); + qemu_set_blocking(channel[1], false, &error_abort); =20 #define CLIENT_CERT_DIR "tests/test-crypto-tlssession-client/" #define SERVER_CERT_DIR "tests/test-crypto-tlssession-server/" diff --git a/util/oslib-posix.c b/util/oslib-posix.c index c737701075..599993d40d 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -275,13 +275,6 @@ int qemu_socket_try_set_nonblock(int fd) return g_unix_set_fd_nonblocking(fd, true, NULL) ? 0 : -errno; } =20 -void qemu_socket_set_nonblock(int fd) -{ - int f; - f =3D qemu_socket_try_set_nonblock(fd); - assert(f =3D=3D 0); -} - int socket_set_fast_reuse(int fd) { int val =3D 1, ret; diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 03044f5b59..1566eb57e7 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -211,11 +211,6 @@ int qemu_socket_try_set_nonblock(int fd) return 0; } =20 -void qemu_socket_set_nonblock(int fd) -{ - (void)qemu_socket_try_set_nonblock(fd); -} - int socket_set_fast_reuse(int fd) { /* Enabling the reuse of an endpoint that was used by a socket still in diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index d805a92394..04c72a92aa 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -78,7 +78,8 @@ static void vmsg_unblock_fds(VhostUserMsg *vmsg) } =20 for (i =3D 0; i < vmsg->fd_num; i++) { - qemu_socket_set_nonblock(vmsg->fds[i]); + /* TODO: handle error more gracefully than aborting */ + qemu_set_blocking(vmsg->fds[i], false, &error_abort); } } =20 @@ -303,7 +304,8 @@ set_watch(VuDev *vu_dev, int fd, int vu_evt, =20 vu_fd_watch->fd =3D fd; vu_fd_watch->cb =3D cb; - qemu_socket_set_nonblock(fd); + /* TODO: handle error more gracefully than aborting */ + qemu_set_blocking(fd, false, &error_abort); aio_set_fd_handler(server->ctx, fd, kick_handler, NULL, NULL, NULL, vu_fd_watch); vu_fd_watch->vu_dev =3D vu_dev; --=20 2.50.1 From nobody Sun Sep 28 15:29:05 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=1758282844; cv=none; d=zohomail.com; s=zohoarc; b=W1VRi8uW18V00ur37JtBTo4WvBVg4X4/Wl+iKo6KETq1Ijz3A+jYcQvIiWLWRlPiIezp1QnBrX9SJHminqbDohGHzYO0/hcCaSpkNXzJnw+ltMTr+RL8iMBrIc9Qg1LCNa4Q9v1HdGMDr1UqtdD/SeZeVVx1AW0hTYKf0/N+d3Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282844; 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=Da93fHKvg30zR+PExOLc2FmPdm1BxYGR/cY3/h+WITU=; b=RXZSclgQe7RWsqYsuAxMPrq5hgWMW8h5vds4Ip41HihkkWAs0KwFdI8pdnCIzDsWxUe8rhj6STy9c92OEzNs/gwAyOSnEf4Vgv1A8H3WlYG/rT47FOZohm1sCwZwMRe/1cjW++hUv8bwIWGP8lFEiuBLFG8TNiUw1T4efolafCU= 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 1758282844355533.1097106045686; Fri, 19 Sep 2025 04:54:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZfY-0003EA-4u; Fri, 19 Sep 2025 07:52: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 1uzZfI-0002s1-5v for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:52:37 -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 1uzZf5-0000v9-84 for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:52:35 -0400 Received: from mx-prod-mc-05.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-505-RBOvo2cIN7mM1qlIaGxnJA-1; Fri, 19 Sep 2025 07:52:14 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8B1E81956096; Fri, 19 Sep 2025 11:52:12 +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 83E021955F2D; Fri, 19 Sep 2025 11:52:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282738; 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=Da93fHKvg30zR+PExOLc2FmPdm1BxYGR/cY3/h+WITU=; b=DwVaNClErTgZ8s2pxPu8TPikOnS6BSHv35bGDMI7ZARWaKiL2z5hRykKuIjejjEVpQcoBP KV46JKSr+rGNFqOjzkXIYBdpm6+pinjTHSlROx7qLBOfQBJ7fHZ45Rj7aMAm/1vFfWF3XZ 2gYLuH/5ZmsNHCwRpatQ/J6ybpA+O7Y= X-MC-Unique: RBOvo2cIN7mM1qlIaGxnJA-1 X-Mimecast-MFC-AGG-ID: RBOvo2cIN7mM1qlIaGxnJA_1758282732 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 10/16] util: drop qemu_socket_try_set_nonblock() Date: Fri, 19 Sep 2025 12:50:11 +0100 Message-ID: <20250919115017.1536203-11-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.129.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_MSPIKE_H4=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: 1758282847227116600 From: Vladimir Sementsov-Ogievskiy Now we can use qemu_set_blocking() in these cases. Reviewed-by: Peter Xu Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/sockets.h | 1 - net/dgram.c | 12 +++--------- net/socket.c | 7 ++----- net/stream.c | 9 +++------ net/stream_data.c | 10 ++++------ util/oslib-posix.c | 4 ---- util/oslib-win32.c | 9 --------- 7 files changed, 12 insertions(+), 40 deletions(-) diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index 6477f90b9e..9512fec514 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -47,7 +47,6 @@ ssize_t qemu_send_full(int s, const void *buf, size_t cou= nt) int socket_set_cork(int fd, int v); int socket_set_nodelay(int fd); void qemu_socket_set_block(int fd); -int qemu_socket_try_set_nonblock(int fd); int socket_set_fast_reuse(int fd); =20 #ifdef WIN32 diff --git a/net/dgram.c b/net/dgram.c index fb9ded30df..baa126d514 100644 --- a/net/dgram.c +++ b/net/dgram.c @@ -287,7 +287,7 @@ static int net_dgram_mcast_init(NetClientState *peer, Error **errp) { NetDgramState *s; - int fd, ret; + int fd; struct sockaddr_in *saddr; =20 if (remote->type !=3D SOCKET_ADDRESS_TYPE_INET) { @@ -335,11 +335,8 @@ static int net_dgram_mcast_init(NetClientState *peer, g_free(saddr); return -1; } - ret =3D qemu_socket_try_set_nonblock(fd); - if (ret < 0) { + if (!qemu_set_blocking(fd, false, errp)) { g_free(saddr); - error_setg_errno(errp, -ret, "%s: Can't use file descripto= r %d", - name, fd); return -1; } =20 @@ -572,10 +569,7 @@ int net_init_dgram(const Netdev *netdev, const char *n= ame, if (fd =3D=3D -1) { return -1; } - ret =3D qemu_socket_try_set_nonblock(fd); - if (ret < 0) { - error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d= ", - name, fd); + if (!qemu_set_blocking(fd, false, errp)) { return -1; } dest_addr =3D NULL; diff --git a/net/socket.c b/net/socket.c index db25e3d9ae..1ad03fc9d4 100644 --- a/net/socket.c +++ b/net/socket.c @@ -718,7 +718,7 @@ int net_init_socket(const Netdev *netdev, const char *n= ame, } =20 if (sock->fd) { - int fd, ret, so_type; + int fd, so_type; =20 fd =3D monitor_fd_param(monitor_cur(), sock->fd, errp); if (fd =3D=3D -1) { @@ -728,10 +728,7 @@ int net_init_socket(const Netdev *netdev, const char *= name, if (so_type < 0) { return -1; } - ret =3D qemu_socket_try_set_nonblock(fd); - if (ret < 0) { - error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d= ", - name, fd); + if (!qemu_set_blocking(fd, false, errp)) { return -1; } switch (so_type) { diff --git a/net/stream.c b/net/stream.c index d893f02cab..94f823a2a7 100644 --- a/net/stream.c +++ b/net/stream.c @@ -138,7 +138,6 @@ static void net_stream_server_listening(QIOTask *task, = gpointer opaque) NetStreamData *d =3D opaque; QIOChannelSocket *listen_sioc =3D QIO_CHANNEL_SOCKET(d->listen_ioc); SocketAddress *addr; - int ret; Error *err =3D NULL; =20 if (qio_task_propagate_error(task, &err)) { @@ -149,13 +148,11 @@ static void net_stream_server_listening(QIOTask *task= , gpointer opaque) =20 addr =3D qio_channel_socket_get_local_address(listen_sioc, NULL); g_assert(addr !=3D NULL); - ret =3D qemu_socket_try_set_nonblock(listen_sioc->fd); - if (addr->type =3D=3D SOCKET_ADDRESS_TYPE_FD && ret < 0) { - qemu_set_info_str(&d->nc, "can't use file descriptor %s (errno %d)= ", - addr->u.fd.str, -ret); + if (!qemu_set_blocking(listen_sioc->fd, false, &err)) { + qemu_set_info_str(&d->nc, "error: %s", error_get_pretty(err)); + error_free(err); return; } - g_assert(ret =3D=3D 0); qapi_free_SocketAddress(addr); =20 d->nc.link_down =3D true; diff --git a/net/stream_data.c b/net/stream_data.c index 5af27e0d1d..03740e9f73 100644 --- a/net/stream_data.c +++ b/net/stream_data.c @@ -12,6 +12,7 @@ #include "net/net.h" #include "io/channel.h" #include "io/net-listener.h" +#include "qemu/sockets.h" =20 #include "stream_data.h" =20 @@ -154,7 +155,6 @@ int net_stream_data_client_connected(QIOTask *task, Net= StreamData *d) { QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(d->ioc); SocketAddress *addr; - int ret; Error *err =3D NULL; =20 if (qio_task_propagate_error(task, &err)) { @@ -166,14 +166,12 @@ int net_stream_data_client_connected(QIOTask *task, N= etStreamData *d) addr =3D qio_channel_socket_get_remote_address(sioc, NULL); g_assert(addr !=3D NULL); =20 - ret =3D qemu_socket_try_set_nonblock(sioc->fd); - if (addr->type =3D=3D SOCKET_ADDRESS_TYPE_FD && ret < 0) { - qemu_set_info_str(&d->nc, "can't use file descriptor %s (errno %d)= ", - addr->u.fd.str, -ret); + if (!qemu_set_blocking(sioc->fd, false, &err)) { + qemu_set_info_str(&d->nc, "error: %s", error_get_pretty(err)); + error_free(err); qapi_free_SocketAddress(addr); goto error; } - g_assert(ret =3D=3D 0); qapi_free_SocketAddress(addr); =20 net_socket_rs_init(&d->rs, net_stream_data_rs_finalize, false); diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 599993d40d..7654febfa5 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -270,10 +270,6 @@ void qemu_socket_set_block(int fd) g_unix_set_fd_nonblocking(fd, false, NULL); } =20 -int qemu_socket_try_set_nonblock(int fd) -{ - return g_unix_set_fd_nonblocking(fd, true, NULL) ? 0 : -errno; -} =20 int socket_set_fast_reuse(int fd) { diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 1566eb57e7..bf5d478c5c 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -202,15 +202,6 @@ void qemu_socket_set_block(int fd) ioctlsocket(fd, FIONBIO, &opt); } =20 -int qemu_socket_try_set_nonblock(int fd) -{ - unsigned long opt =3D 1; - if (ioctlsocket(fd, FIONBIO, &opt) !=3D NO_ERROR) { - return -socket_error(); - } - return 0; -} - int socket_set_fast_reuse(int fd) { /* Enabling the reuse of an endpoint that was used by a socket still in --=20 2.50.1 From nobody Sun Sep 28 15:29:05 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=1758283048; cv=none; d=zohomail.com; s=zohoarc; b=cVqX2wFBj5bt96y066h60CArifjQVI4L2BF7m5rEIer2uNnjJz10EbMZPvLHtEApAGah/qkR7YUAE8PmNHhpuw1zC4J2gZylhJLm3gnoui7ywJyMM05ft33/wEacaQeLk2Ml5klrpiTHb9Au9pVkTQxSIiTQh4go/1mTRtZ+Ci8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758283048; 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=JHLoJxwljpLeo0arktfCDo5fN3hVTtZXV5S/bRj7zZo=; b=PgD4F+/FWlK7fgVe4uwe0zLHvVAcnLsSLkOuTMUOfhCYw5KOxdFeWumLL2MGsoZ/XZXxWg4mHjg4sYJntj5XJOFOsmdL+LQ0UMQ9//NbTo0ptUuQ03zQZ5rOlID6o0vuCdcV5izu7T0U/ffw9hobT4pJzgUG2V7jXeVmFAcnkLI= 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 1758283048881938.7894922440996; Fri, 19 Sep 2025 04:57:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZfW-00038E-Gg; Fri, 19 Sep 2025 07:52:50 -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 1uzZfP-0002yV-2A for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:52:44 -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 1uzZfG-0000wG-CP for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:52:42 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-D6NsE1Q6M0m18XQDPzxITA-1; Fri, 19 Sep 2025 07:52:24 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E983D180028E; Fri, 19 Sep 2025 11:52:21 +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 EDA111955F2D; Fri, 19 Sep 2025 11:52:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282747; 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=JHLoJxwljpLeo0arktfCDo5fN3hVTtZXV5S/bRj7zZo=; b=TMNXltkZTi4jpPJvbITlJuvlAZRW4h0V38lUT5d4P4P0zLMvGEvsbreUwMP5f4XicUhJWr Tt5GUmQNkcR0yaFwBeVEtZxO6KcUqsIXvEHxKzwuqFuGYhe5LBU4+gODfUN3RH76EpO7gF Md3G4DtNAgwHfj6lsCwpg8jgTS1j82w= X-MC-Unique: D6NsE1Q6M0m18XQDPzxITA-1 X-Mimecast-MFC-AGG-ID: D6NsE1Q6M0m18XQDPzxITA_1758282742 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 11/16] io/channel-socket: rework qio_channel_socket_copy_fds() Date: Fri, 19 Sep 2025 12:50:12 +0100 Message-ID: <20250919115017.1536203-12-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_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 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: 1758283050864116600 From: Vladimir Sementsov-Ogievskiy We want to switch from qemu_socket_set_block() to newer qemu_set_blocking(), which provides return status of operation, to handle errors. Still, we want to keep qio_channel_socket_readv() interface clean, as currently it allocate @fds only on success. So, in case of error, we should close all incoming fds and keep user's @fds untouched or zero. Let's make separate functions qio_channel_handle_fds() and qio_channel_cleanup_fds(), to achieve what we want. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Daniel P. Berrang=C3=A9 --- include/io/channel.h | 8 +++--- io/channel-socket.c | 67 +++++++++++++++++++++++++++++++++----------- 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/include/io/channel.h b/include/io/channel.h index 999a8f5f23..0f25ae0069 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -124,8 +124,8 @@ struct QIOChannelClass { * incoming fds are set BLOCKING (unless * QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING flag is set) and * CLOEXEC (if available). - * @fds and @nfds are set only on success path, and untouched - * in case of errors. + * @fds and @nfds are set only on success path. Still, setting + * @fds and @nfds to zero is acceptable on failure path. */ ssize_t (*io_readv)(QIOChannel *ioc, const struct iovec *iov, @@ -246,8 +246,8 @@ void qio_channel_set_name(QIOChannel *ioc, * to call close() on each file descriptor and to * call g_free() on the array pointer in @fds. * @fds allocated and set (and @nfds is set too) - * _only_ on success path. These parameters are - * untouched in case of errors. + * _only_ on success path. Still, @fds and @nfds + * may be set to zero on failure path. * qio_channel_readv_full() guarantees that all * incoming fds are set BLOCKING (unless * QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING flag diff --git a/io/channel-socket.c b/io/channel-socket.c index f7e3cb9742..e53d9ac76f 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -464,8 +464,7 @@ static void qio_channel_socket_finalize(Object *obj) =20 #ifndef WIN32 static void qio_channel_socket_copy_fds(struct msghdr *msg, - int **fds, size_t *nfds, - bool preserve_blocking) + int **fds, size_t *nfds) { struct cmsghdr *cmsg; =20 @@ -473,7 +472,7 @@ static void qio_channel_socket_copy_fds(struct msghdr *= msg, *fds =3D NULL; =20 for (cmsg =3D CMSG_FIRSTHDR(msg); cmsg; cmsg =3D CMSG_NXTHDR(msg, cmsg= )) { - int fd_size, i; + int fd_size; int gotfds; =20 if (cmsg->cmsg_len < CMSG_LEN(sizeof(int)) || @@ -491,24 +490,53 @@ static void qio_channel_socket_copy_fds(struct msghdr= *msg, gotfds =3D fd_size / sizeof(int); *fds =3D g_renew(int, *fds, *nfds + gotfds); memcpy(*fds + *nfds, CMSG_DATA(cmsg), fd_size); + *nfds +=3D gotfds; + } +} =20 - for (i =3D 0; i < gotfds; i++) { - int fd =3D (*fds)[*nfds + i]; - if (fd < 0) { - continue; - } +static bool qio_channel_handle_fds(int *fds, size_t nfds, + bool preserve_blocking, Error **errp) +{ + int *end =3D fds + nfds, *fd; + +#ifdef MSG_CMSG_CLOEXEC + if (preserve_blocking) { + /* Nothing to do */ + return true; + } +#endif =20 - if (!preserve_blocking) { - /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ - qemu_socket_set_block(fd); + for (fd =3D fds; fd !=3D end; fd++) { + if (*fd < 0) { + continue; + } + + if (!preserve_blocking) { + /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ + if (!qemu_set_blocking(*fd, true, errp)) { + return false; } + } =20 #ifndef MSG_CMSG_CLOEXEC - qemu_set_cloexec(fd); + qemu_set_cloexec(*fd); #endif + } + + return true; +} + +static void qio_channel_cleanup_fds(int **fds, size_t *nfds) +{ + for (size_t i =3D 0; i < *nfds; i++) { + if ((*fds)[i] < 0) { + continue; } - *nfds +=3D gotfds; + close((*fds)[i]); } + + g_clear_pointer(fds, g_free); + *nfds =3D 0; } =20 =20 @@ -559,9 +587,16 @@ static ssize_t qio_channel_socket_readv(QIOChannel *io= c, } =20 if (fds && nfds) { - qio_channel_socket_copy_fds( - &msg, fds, nfds, - flags & QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING); + bool preserve_blocking =3D + flags & QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING; + + qio_channel_socket_copy_fds(&msg, fds, nfds); + + if (!qio_channel_handle_fds(*fds, *nfds, + preserve_blocking, errp)) { + qio_channel_cleanup_fds(fds, nfds); + return -1; + } } =20 return ret; --=20 2.50.1 From nobody Sun Sep 28 15:29:05 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=1758282930; cv=none; d=zohomail.com; s=zohoarc; b=LzWJjgNwfOwbBcV45fT5E7OupZzt1Ljx0JM4hsgBCUdqthDRKH/8GtudC2F7ywStFG5Wrnz3gwwoIz70WpW38T3tlSP7VPOczcSBgipsDm3mN7aA4A2+BpVPCNJ1SVM+K3E1UkILDo7QuD9oVs6ZxyV0ielCbOIIX+HVSXXMPOA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282930; 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=WCT7bDDV91OpCNXWZKEsJb4IXa/ws5YGQiPt6N3/OcM=; b=hT6TJg1x2bKFMLslucCnHHXellH5a2+wcG2Fr5H5va9CfV38rwN+9dkb1XtkR32bDaBUqMTvtOWhmBq68piXN7vTAA50PunyoeOhxoq5knik9RV+ecDm/m3A0Bo4GVgcOgJfzCp8ajyjMj3H+TR1GvBzeZLclm749EBYvUvuUCA= 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 1758282930427708.6978836084297; Fri, 19 Sep 2025 04:55:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZfl-0003bB-19; Fri, 19 Sep 2025 07:53:06 -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 1uzZfa-0003Oo-MA for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:52:55 -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 1uzZfN-0000yI-T8 for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:52:54 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-676-o8TG-49lPXmnPonB4m1wKg-1; Fri, 19 Sep 2025 07:52:35 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2CEF9180057E; Fri, 19 Sep 2025 11:52:33 +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 7F5201955F2D; Fri, 19 Sep 2025 11:52:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282758; 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=WCT7bDDV91OpCNXWZKEsJb4IXa/ws5YGQiPt6N3/OcM=; b=gkHigi4LfbXN9R2qdx+gOfZoK9LXX7S7WdWTLEWI5Cg+FFA0LuSxZL0xU8O+LTyByuK3C3 MwLMsO+zuhm/1kCeHi8UJ1g/96EkuUlx/vu7k+xSis/inF4Plt5lqIGaAUaLJt4oDeZ2I8 jyL1TfPhZ8eUhX7K5ardN/UQngngZtI= X-MC-Unique: o8TG-49lPXmnPonB4m1wKg-1 X-Mimecast-MFC-AGG-ID: o8TG-49lPXmnPonB4m1wKg_1758282753 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 12/16] util: drop qemu_socket_set_block() Date: Fri, 19 Sep 2025 12:50:13 +0100 Message-ID: <20250919115017.1536203-13-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_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: 1758282931710116600 From: Vladimir Sementsov-Ogievskiy Now it's unused. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/sockets.h | 1 - util/oslib-posix.c | 6 ------ util/oslib-win32.c | 7 ------- 3 files changed, 14 deletions(-) diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index 9512fec514..be351d85f7 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -46,7 +46,6 @@ ssize_t qemu_send_full(int s, const void *buf, size_t cou= nt) G_GNUC_WARN_UNUSED_RESULT; int socket_set_cork(int fd, int v); int socket_set_nodelay(int fd); -void qemu_socket_set_block(int fd); int socket_set_fast_reuse(int fd); =20 #ifdef WIN32 diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 7654febfa5..14cf94ac03 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -265,12 +265,6 @@ bool qemu_set_blocking(int fd, bool block, Error **err= p) return true; } =20 -void qemu_socket_set_block(int fd) -{ - g_unix_set_fd_nonblocking(fd, false, NULL); -} - - int socket_set_fast_reuse(int fd) { int val =3D 1, ret; diff --git a/util/oslib-win32.c b/util/oslib-win32.c index bf5d478c5c..b9ce2f96ee 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -195,13 +195,6 @@ bool qemu_set_blocking(int fd, bool block, Error **err= p) return true; } =20 -void qemu_socket_set_block(int fd) -{ - unsigned long opt =3D 0; - qemu_socket_unselect(fd, NULL); - ioctlsocket(fd, FIONBIO, &opt); -} - int socket_set_fast_reuse(int fd) { /* Enabling the reuse of an endpoint that was used by a socket still in --=20 2.50.1 From nobody Sun Sep 28 15:29:05 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=1758282849; cv=none; d=zohomail.com; s=zohoarc; b=Akh3PdaFiQl4DA+FXZHMsPMqEbUlSYD/COkNL+1XL+i48aeiy4nOTKnHCox/3TObzC9GPvUkRF47y54dwbqzzEaeu4HdjwJdG15cnYC7SGFn2vOUkc44/QlY2RZO7nqSIcCHDLTiEHYJvEmdGFHrozbU+nsqIey7Dhgcte3XKfw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282849; 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=uAEwYloVz8dVmJ2LRVxd5DvNOyTmbZrHLJJqiBnNkWU=; b=H7/7L67YszP3yfgaO8TWmHrNlOdj+8toh4A3Eg6EdkyoYtfqEAsmb6jR7Btpkdy5tmWBYJDUOigcMPSH2jZ5OHH9rThl+uSSf7cPwHfiukreIFLjtd8ktln0w37j4LWYdg8ZvAp2Z8KC/VtyJiKNMufI1gLuCGOclIJSNDk2Jjo= 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 1758282849544143.03969478261536; Fri, 19 Sep 2025 04:54:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZgF-00046A-7G; Fri, 19 Sep 2025 07:53:35 -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 1uzZfe-0003aG-Oo for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:52:58 -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 1uzZfX-0000zd-0w for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:52:57 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-346-C4svYDpEO5ehwUlUZemauw-1; Fri, 19 Sep 2025 07:52:44 -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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7D74A1800359; Fri, 19 Sep 2025 11:52:42 +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 8EE941955F21; Fri, 19 Sep 2025 11:52:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282766; 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=uAEwYloVz8dVmJ2LRVxd5DvNOyTmbZrHLJJqiBnNkWU=; b=e7iHPEjGu1Bi2kYXKNiriLegQIwOAVmhC+pAoBDUWgx8UL1VlfIuEK/9PVvKCHJHo1FO7O QCIUhqgfNiQRc9ChF8XEWqwFTNgDUhPxkOGmrPh0CJaF+SRVWGOOHO0rYWh6ecTiiUjiVJ MVyfYLodMKx6WFWg0CWTbAOt5JC6i6s= X-MC-Unique: C4svYDpEO5ehwUlUZemauw-1 X-Mimecast-MFC-AGG-ID: C4svYDpEO5ehwUlUZemauw_1758282762 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 13/16] treewide: use qemu_set_blocking instead of g_unix_set_fd_nonblocking Date: Fri, 19 Sep 2025 12:50:14 +0100 Message-ID: <20250919115017.1536203-14-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_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 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: 1758282850995116600 From: Vladimir Sementsov-Ogievskiy Instead of open-coded g_unix_set_fd_nonblocking() calls, use QEMU wrapper qemu_set_blocking(). Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy [DB: fix missing closing ) in tap-bsd.c, remove now unused GError var] Signed-off-by: Daniel P. Berrang=C3=A9 --- chardev/char-fd.c | 4 ++-- chardev/char-pty.c | 3 +-- chardev/char-serial.c | 3 +-- chardev/char-stdio.c | 3 +-- hw/input/virtio-input-host.c | 3 +-- hw/misc/ivshmem-flat.c | 3 ++- hw/misc/ivshmem-pci.c | 7 ++++++- hw/virtio/vhost-vsock.c | 8 ++------ io/channel-command.c | 9 ++++++--- io/channel-file.c | 3 +-- net/tap-bsd.c | 12 ++++++++++-- net/tap-linux.c | 7 ++++++- net/tap-solaris.c | 7 ++++++- net/tap.c | 21 ++++++--------------- qga/commands-posix.c | 3 +-- tests/qtest/fuzz/virtio_net_fuzz.c | 2 +- tests/qtest/vhost-user-test.c | 4 +--- tests/unit/test-iov.c | 5 +++-- ui/input-linux.c | 3 +-- util/event_notifier-posix.c | 7 +++++-- util/main-loop.c | 5 ++++- 21 files changed, 67 insertions(+), 55 deletions(-) diff --git a/chardev/char-fd.c b/chardev/char-fd.c index 6f03adf872..739dc68c36 100644 --- a/chardev/char-fd.c +++ b/chardev/char-fd.c @@ -212,8 +212,8 @@ void qemu_chr_open_fd(Chardev *chr, FDChardev *s =3D FD_CHARDEV(chr); g_autofree char *name =3D NULL; =20 - if (fd_out >=3D 0 && !g_unix_set_fd_nonblocking(fd_out, true, NULL)) { - assert(!"Failed to set FD nonblocking"); + if (fd_out >=3D 0) { + qemu_set_blocking(fd_out, false, &error_abort); } =20 if (fd_out =3D=3D fd_in && fd_in >=3D 0) { diff --git a/chardev/char-pty.c b/chardev/char-pty.c index 674e9b3f14..fe6bfb043d 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -349,8 +349,7 @@ static void char_pty_open(Chardev *chr, } =20 close(slave_fd); - if (!g_unix_set_fd_nonblocking(master_fd, true, NULL)) { - error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + if (!qemu_set_blocking(master_fd, false, errp)) { return; } =20 diff --git a/chardev/char-serial.c b/chardev/char-serial.c index 0a68b4b4e0..1ff31dcde3 100644 --- a/chardev/char-serial.c +++ b/chardev/char-serial.c @@ -271,8 +271,7 @@ static void qmp_chardev_open_serial(Chardev *chr, if (fd < 0) { return; } - if (!g_unix_set_fd_nonblocking(fd, true, NULL)) { - error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + if (!qemu_set_blocking(fd, false, errp)) { return; } tty_serial_init(fd, 115200, 'N', 8, 1); diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c index 48db8d2f30..193727e807 100644 --- a/chardev/char-stdio.c +++ b/chardev/char-stdio.c @@ -107,8 +107,7 @@ static void qemu_chr_open_stdio(Chardev *chr, old_fd0_flags =3D fcntl(0, F_GETFL); old_fd1_flags =3D fcntl(1, F_GETFL); tcgetattr(0, &oldtty); - if (!g_unix_set_fd_nonblocking(0, true, NULL)) { - error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + if (!qemu_set_blocking(0, false, errp)) { return; } atexit(term_exit); diff --git a/hw/input/virtio-input-host.c b/hw/input/virtio-input-host.c index bbfee9d3b9..9f62532559 100644 --- a/hw/input/virtio-input-host.c +++ b/hw/input/virtio-input-host.c @@ -114,8 +114,7 @@ static void virtio_input_host_realize(DeviceState *dev,= Error **errp) error_setg_file_open(errp, errno, vih->evdev); return; } - if (!g_unix_set_fd_nonblocking(vih->fd, true, NULL)) { - error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + if (!qemu_set_blocking(vih->fd, false, errp)) { goto err_close; } =20 diff --git a/hw/misc/ivshmem-flat.c b/hw/misc/ivshmem-flat.c index fe4be6be17..e83e6c6ee9 100644 --- a/hw/misc/ivshmem-flat.c +++ b/hw/misc/ivshmem-flat.c @@ -154,7 +154,8 @@ static void ivshmem_flat_add_vector(IvshmemFTState *s, = IvshmemPeer *peer, * peer. */ peer->vector[peer->vector_counter].id =3D peer->vector_counter; - g_unix_set_fd_nonblocking(vector_fd, true, NULL); + /* WARNING: qemu_socket_set_nonblock() return code ignored */ + qemu_set_blocking(vector_fd, false, &error_warn); event_notifier_init_fd(&peer->vector[peer->vector_counter].event_notif= ier, vector_fd); =20 diff --git a/hw/misc/ivshmem-pci.c b/hw/misc/ivshmem-pci.c index d47ae739d6..2748db9286 100644 --- a/hw/misc/ivshmem-pci.c +++ b/hw/misc/ivshmem-pci.c @@ -540,7 +540,12 @@ static void process_msg_connect(IVShmemState *s, uint1= 6_t posn, int fd, =20 IVSHMEM_DPRINTF("eventfds[%d][%d] =3D %d\n", posn, vector, fd); event_notifier_init_fd(&peer->eventfds[vector], fd); - g_unix_set_fd_nonblocking(fd, true, NULL); /* msix/irqfd poll non bloc= k */ + + /* msix/irqfd poll non block */ + if (!qemu_set_blocking(fd, false, errp)) { + close(fd); + return; + } =20 if (posn =3D=3D s->vm_id) { setup_interrupt(s, vector, errp); diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c index 6e4088831f..107d88babe 100644 --- a/hw/virtio/vhost-vsock.c +++ b/hw/virtio/vhost-vsock.c @@ -147,9 +147,7 @@ static void vhost_vsock_device_realize(DeviceState *dev= , Error **errp) return; } =20 - if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { - error_setg_errno(errp, errno, - "vhost-vsock: unable to set non-blocking mode= "); + if (!qemu_set_blocking(vhostfd, false, errp)) { return; } } else { @@ -160,9 +158,7 @@ static void vhost_vsock_device_realize(DeviceState *dev= , Error **errp) return; } =20 - if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { - error_setg_errno(errp, errno, - "Failed to set FD nonblocking"); + if (!qemu_set_blocking(vhostfd, false, errp)) { return; } } diff --git a/io/channel-command.c b/io/channel-command.c index 8966dd3a2b..8ae9a026b3 100644 --- a/io/channel-command.c +++ b/io/channel-command.c @@ -277,9 +277,12 @@ static int qio_channel_command_set_blocking(QIOChannel= *ioc, cioc->blocking =3D enabled; #else =20 - if ((cioc->writefd >=3D 0 && !g_unix_set_fd_nonblocking(cioc->writefd,= !enabled, NULL)) || - (cioc->readfd >=3D 0 && !g_unix_set_fd_nonblocking(cioc->readfd, != enabled, NULL))) { - error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + if (cioc->writefd >=3D 0 && + !qemu_set_blocking(cioc->writefd, enabled, errp)) { + return -1; + } + if (cioc->readfd >=3D 0 && + !qemu_set_blocking(cioc->readfd, enabled, errp)) { return -1; } #endif diff --git a/io/channel-file.c b/io/channel-file.c index ca3f180cc2..5cef75a67c 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -223,8 +223,7 @@ static int qio_channel_file_set_blocking(QIOChannel *io= c, #else QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); =20 - if (!g_unix_set_fd_nonblocking(fioc->fd, !enabled, NULL)) { - error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + if (!qemu_set_blocking(fioc->fd, enabled, errp)) { return -1; } return 0; diff --git a/net/tap-bsd.c b/net/tap-bsd.c index b4c84441ba..3f98d0ea82 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -98,7 +98,12 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hd= r, return -1; } } - g_unix_set_fd_nonblocking(fd, true, NULL); + + if (!qemu_set_blocking(fd, false, errp)) { + close(fd); + return -1; + } + return fd; } =20 @@ -189,7 +194,10 @@ int tap_open(char *ifname, int ifname_size, int *vnet_= hdr, goto error; } =20 - g_unix_set_fd_nonblocking(fd, true, NULL); + if (!qemu_set_blocking(fd, false, errp)) { + goto error; + } + return fd; =20 error: diff --git a/net/tap-linux.c b/net/tap-linux.c index 22ec2f45d2..e832810665 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -124,7 +124,12 @@ int tap_open(char *ifname, int ifname_size, int *vnet_= hdr, return -1; } pstrcpy(ifname, ifname_size, ifr.ifr_name); - g_unix_set_fd_nonblocking(fd, true, NULL); + + if (!qemu_set_blocking(fd, false, errp)) { + close(fd); + return -1; + } + return fd; } =20 diff --git a/net/tap-solaris.c b/net/tap-solaris.c index 51b7830bef..af2ebb16f5 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -198,7 +198,12 @@ int tap_open(char *ifname, int ifname_size, int *vnet_= hdr, return -1; } } - g_unix_set_fd_nonblocking(fd, true, NULL); + + if (!qemu_set_blocking(fd, false, errp)) { + close(fd); + return -1; + } + return fd; } =20 diff --git a/net/tap.c b/net/tap.c index f7df702f97..f37133e301 100644 --- a/net/tap.c +++ b/net/tap.c @@ -627,8 +627,7 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, return -1; } =20 - if (!g_unix_set_fd_nonblocking(fd, true, NULL)) { - error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + if (!qemu_set_blocking(fd, false, errp)) { return -1; } vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); @@ -729,9 +728,7 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, error_propagate(errp, err); goto failed; } - if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { - error_setg_errno(errp, errno, "%s: Can't use file descript= or %d", - name, fd); + if (!qemu_set_blocking(vhostfd, false, errp)) { goto failed; } } else { @@ -741,8 +738,7 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, "tap: open vhost char device failed"); goto failed; } - if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { - error_setg_errno(errp, errno, "Failed to set FD nonblockin= g"); + if (!qemu_set_blocking(vhostfd, false, errp)) { goto failed; } } @@ -839,9 +835,7 @@ int net_init_tap(const Netdev *netdev, const char *name, return -1; } =20 - if (!g_unix_set_fd_nonblocking(fd, true, NULL)) { - error_setg_errno(errp, errno, "%s: Can't use file descriptor %= d", - name, fd); + if (!qemu_set_blocking(fd, false, errp)) { close(fd); return -1; } @@ -895,10 +889,8 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, goto free_fail; } =20 - if (!g_unix_set_fd_nonblocking(fd, true, NULL)) { + if (!qemu_set_blocking(fd, false, errp)) { ret =3D -1; - error_setg_errno(errp, errno, "%s: Can't use file descript= or %d", - name, fd); goto free_fail; } =20 @@ -951,8 +943,7 @@ free_fail: return -1; } =20 - if (!g_unix_set_fd_nonblocking(fd, true, NULL)) { - error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + if (!qemu_set_blocking(fd, false, errp)) { return -1; } vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 12bc086d79..5070f27d75 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -503,9 +503,8 @@ int64_t qmp_guest_file_open(const char *path, const cha= r *mode, /* set fd non-blocking to avoid common use cases (like reading from a * named pipe) from hanging the agent */ - if (!g_unix_set_fd_nonblocking(fileno(fh), true, NULL)) { + if (!qemu_set_blocking(fileno(fh), false, errp)) { fclose(fh); - error_setg_errno(errp, errno, "Failed to set FD nonblocking"); return -1; } =20 diff --git a/tests/qtest/fuzz/virtio_net_fuzz.c b/tests/qtest/fuzz/virtio_n= et_fuzz.c index e239875e3b..e9b13d3e4f 100644 --- a/tests/qtest/fuzz/virtio_net_fuzz.c +++ b/tests/qtest/fuzz/virtio_net_fuzz.c @@ -132,7 +132,7 @@ static void *virtio_net_test_setup_socket(GString *cmd_= line, void *arg) { int ret =3D socketpair(PF_UNIX, SOCK_STREAM, 0, sockfds); g_assert_cmpint(ret, !=3D, -1); - g_unix_set_fd_nonblocking(sockfds[0], true, NULL); + qemu_set_blocking(sockfds[0], false, &error_abort); sockfds_initialized =3D true; g_string_append_printf(cmd_line, " -netdev socket,fd=3D%d,id=3Dhs0 ", sockfds[1]); diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index 56472ca709..6ec4ec2d5a 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -330,7 +330,6 @@ static int chr_can_read(void *opaque) =20 static void chr_read(void *opaque, const uint8_t *buf, int size) { - g_autoptr(GError) err =3D NULL; TestServer *s =3D opaque; CharBackend *chr =3D &s->chr; VhostUserMsg msg; @@ -471,8 +470,7 @@ static void chr_read(void *opaque, const uint8_t *buf, = int size) * The receive function forces it to be blocking, * so revert it back to non-blocking. */ - g_unix_set_fd_nonblocking(fd, true, &err); - g_assert_no_error(err); + qemu_set_blocking(fd, false, &error_abort); break; =20 case VHOST_USER_SET_LOG_BASE: diff --git a/tests/unit/test-iov.c b/tests/unit/test-iov.c index 75bc3be005..63e2b1583c 100644 --- a/tests/unit/test-iov.c +++ b/tests/unit/test-iov.c @@ -1,4 +1,5 @@ #include "qemu/osdep.h" +#include "qapi/error.h" #include "qemu/iov.h" #include "qemu/sockets.h" =20 @@ -186,7 +187,7 @@ static void test_io(void) =20 close(sv[0]); FD_SET(sv[1], &fds); - g_unix_set_fd_nonblocking(sv[1], true, NULL); + qemu_set_blocking(sv[1], false, &error_abort); r =3D g_test_rand_int_range(sz / 2, sz); setsockopt(sv[1], SOL_SOCKET, SO_SNDBUF, &r, sizeof(r)); =20 @@ -222,7 +223,7 @@ static void test_io(void) =20 close(sv[1]); FD_SET(sv[0], &fds); - g_unix_set_fd_nonblocking(sv[0], true, NULL); + qemu_set_blocking(sv[0], false, &error_abort); r =3D g_test_rand_int_range(sz / 2, sz); setsockopt(sv[0], SOL_SOCKET, SO_RCVBUF, &r, sizeof(r)); usleep(500000); diff --git a/ui/input-linux.c b/ui/input-linux.c index 92e1a1aa64..44d0c15a9b 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -316,8 +316,7 @@ static void input_linux_complete(UserCreatable *uc, Err= or **errp) error_setg_file_open(errp, errno, il->evdev); return; } - if (!g_unix_set_fd_nonblocking(il->fd, true, NULL)) { - error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + if (!qemu_set_blocking(il->fd, false, errp)) { return; } =20 diff --git a/util/event_notifier-posix.c b/util/event_notifier-posix.c index 76420c5b56..83fdbb96bb 100644 --- a/util/event_notifier-posix.c +++ b/util/event_notifier-posix.c @@ -11,6 +11,7 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/error.h" #include "qemu/cutils.h" #include "qemu/event_notifier.h" #include "qemu/main-loop.h" @@ -36,6 +37,7 @@ int event_notifier_init(EventNotifier *e, int active) { int fds[2]; int ret; + Error *local_err =3D NULL; =20 #ifdef CONFIG_EVENTFD ret =3D eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); @@ -52,11 +54,11 @@ int event_notifier_init(EventNotifier *e, int active) if (!g_unix_open_pipe(fds, FD_CLOEXEC, NULL)) { return -errno; } - if (!g_unix_set_fd_nonblocking(fds[0], true, NULL)) { + if (!qemu_set_blocking(fds[0], false, &local_err)) { ret =3D -errno; goto fail; } - if (!g_unix_set_fd_nonblocking(fds[1], true, NULL)) { + if (!qemu_set_blocking(fds[1], false, &local_err)) { ret =3D -errno; goto fail; } @@ -70,6 +72,7 @@ int event_notifier_init(EventNotifier *e, int active) return 0; =20 fail: + error_report_err(local_err); close(fds[0]); close(fds[1]); return ret; diff --git a/util/main-loop.c b/util/main-loop.c index 51aeb2432e..b8ddda8f5e 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -114,7 +114,10 @@ static int qemu_signal_init(Error **errp) return -errno; } =20 - g_unix_set_fd_nonblocking(sigfd, true, NULL); + if (!qemu_set_blocking(sigfd, false, errp)) { + close(sigfd); + return -EINVAL; + } =20 qemu_set_fd_handler(sigfd, sigfd_handler, NULL, (void *)(intptr_t)sigf= d); =20 --=20 2.50.1 From nobody Sun Sep 28 15:29:05 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=1758282934; cv=none; d=zohomail.com; s=zohoarc; b=msjAH0QmV1F0veZLEcaLFsbS7QvgmcT8zbOb9XSnhSQj00rHvbBWCfqstfhOLkpJApvDHrEbkJAE6bENp8FyNee7b9fRZ2gAoEQXqlflJkUrApOCbxebLrnVf1UeUVqD+GWGGpOu2i2piMq/LAiCaz9ziB0VMCJWdHg4EUra9DM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282934; 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=XvMIDTfhkqExxjxXfh4Y8++3SmI4tPG6/nea+iq54aw=; b=exaK1xD8dEdwG4lIva5WrIMj9+Bmd/XSNA7gWNP+iJdGurL1c06QsXn4FbU6fKbS4yxTSGJWJXldH4VrlruBQlmHTthfQYCyEJvmadNW4Kr1Hf7eRgYjDfeDoWUZ/3F6GlQQaVxiIZzA8ze5EKG+fOesrbD5FBKssO0OGrVY9s8= 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 1758282934988504.6548933882608; Fri, 19 Sep 2025 04:55:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZgA-00046G-85; Fri, 19 Sep 2025 07:53:30 -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 1uzZfq-0003l4-Et for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:53:17 -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 1uzZfi-00010Y-5I for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:53:09 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-85-CUaULWqdO1mMvd0XplFWUA-1; Fri, 19 Sep 2025 07:52:55 -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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C5B9218002CA; Fri, 19 Sep 2025 11:52:52 +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 E19871955F21; Fri, 19 Sep 2025 11:52:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282776; 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=XvMIDTfhkqExxjxXfh4Y8++3SmI4tPG6/nea+iq54aw=; b=akhFatovUQVBV7r2PcLXk3m4bKt4/zZRVNFqmPolVRtktYaKPhXsoRNHRXSV4FeNNeFI+9 gLBOZgj1M8XLiZz4choP8F5JLmAdR9iFzTkB2F3Qbr0AJjQTVvlDvQIJpr5KJQrETCCqjM RVV+6jpMrQz6sSqNQk2ZvfhYKet7Rg8= X-MC-Unique: CUaULWqdO1mMvd0XplFWUA-1 X-Mimecast-MFC-AGG-ID: CUaULWqdO1mMvd0XplFWUA_1758282772 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 14/16] chardev: qemu_chr_open_fd(): add errp Date: Fri, 19 Sep 2025 12:50:15 +0100 Message-ID: <20250919115017.1536203-15-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.129.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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01 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: 1758282935454116600 From: Vladimir Sementsov-Ogievskiy Every caller already support errp, let's go further. Suggested-by: Daniel P. Berrang=C3=A9 Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Daniel P. Berrang=C3=A9 --- chardev/char-fd.c | 12 ++++++++---- chardev/char-file.c | 6 +++++- chardev/char-pipe.c | 9 ++++++++- chardev/char-serial.c | 5 ++++- chardev/char-stdio.c | 7 +++++-- include/chardev/char-fd.h | 2 +- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/chardev/char-fd.c b/chardev/char-fd.c index 739dc68c36..4ee286f323 100644 --- a/chardev/char-fd.c +++ b/chardev/char-fd.c @@ -206,14 +206,16 @@ int qmp_chardev_open_file_source(char *src, int flags= , Error **errp) } =20 /* open a character device to a unix fd */ -void qemu_chr_open_fd(Chardev *chr, - int fd_in, int fd_out) +bool qemu_chr_open_fd(Chardev *chr, + int fd_in, int fd_out, Error **errp) { FDChardev *s =3D FD_CHARDEV(chr); g_autofree char *name =3D NULL; =20 if (fd_out >=3D 0) { - qemu_set_blocking(fd_out, false, &error_abort); + if (!qemu_set_blocking(fd_out, false, errp)) { + return false; + } } =20 if (fd_out =3D=3D fd_in && fd_in >=3D 0) { @@ -221,7 +223,7 @@ void qemu_chr_open_fd(Chardev *chr, name =3D g_strdup_printf("chardev-file-%s", chr->label); qio_channel_set_name(QIO_CHANNEL(s->ioc_in), name); s->ioc_out =3D QIO_CHANNEL(object_ref(s->ioc_in)); - return; + return true; } =20 if (fd_in >=3D 0) { @@ -236,6 +238,8 @@ void qemu_chr_open_fd(Chardev *chr, name =3D g_strdup_printf("chardev-file-out-%s", chr->label); qio_channel_set_name(QIO_CHANNEL(s->ioc_out), name); } + + return true; } =20 static void char_fd_class_init(ObjectClass *oc, const void *data) diff --git a/chardev/char-file.c b/chardev/char-file.c index a9e8c5e0d7..89e9cb849c 100644 --- a/chardev/char-file.c +++ b/chardev/char-file.c @@ -92,7 +92,11 @@ static void qmp_chardev_open_file(Chardev *chr, } } =20 - qemu_chr_open_fd(chr, in, out); + if (!qemu_chr_open_fd(chr, in, out, errp)) { + qemu_close(out); + qemu_close(in); + return; + } #endif } =20 diff --git a/chardev/char-pipe.c b/chardev/char-pipe.c index 3d1b0ce2d2..e9f3bb8290 100644 --- a/chardev/char-pipe.c +++ b/chardev/char-pipe.c @@ -150,7 +150,14 @@ static void qemu_chr_open_pipe(Chardev *chr, return; } } - qemu_chr_open_fd(chr, fd_in, fd_out); + + if (!qemu_chr_open_fd(chr, fd_in, fd_out, errp)) { + close(fd_in); + if (fd_out !=3D fd_in) { + close(fd_out); + } + return; + } } =20 #endif /* !_WIN32 */ diff --git a/chardev/char-serial.c b/chardev/char-serial.c index 1ff31dcde3..c622d758db 100644 --- a/chardev/char-serial.c +++ b/chardev/char-serial.c @@ -276,7 +276,10 @@ static void qmp_chardev_open_serial(Chardev *chr, } tty_serial_init(fd, 115200, 'N', 8, 1); =20 - qemu_chr_open_fd(chr, fd, fd); + if (!qemu_chr_open_fd(chr, fd, fd, errp)) { + close(fd); + return; + } } #endif /* __linux__ || __sun__ */ =20 diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c index 193727e807..2568164a10 100644 --- a/chardev/char-stdio.c +++ b/chardev/char-stdio.c @@ -110,14 +110,17 @@ static void qemu_chr_open_stdio(Chardev *chr, if (!qemu_set_blocking(0, false, errp)) { return; } + + if (!qemu_chr_open_fd(chr, 0, 1, errp)) { + return; + } + atexit(term_exit); =20 memset(&act, 0, sizeof(act)); act.sa_handler =3D term_stdio_handler; sigaction(SIGCONT, &act, NULL); =20 - qemu_chr_open_fd(chr, 0, 1); - stdio_allow_signal =3D !opts->has_signal || opts->signal; qemu_chr_set_echo_stdio(chr, false); } diff --git a/include/chardev/char-fd.h b/include/chardev/char-fd.h index 9de0e440de..6fe43062ca 100644 --- a/include/chardev/char-fd.h +++ b/include/chardev/char-fd.h @@ -41,7 +41,7 @@ typedef struct FDChardev FDChardev; DECLARE_INSTANCE_CHECKER(FDChardev, FD_CHARDEV, TYPE_CHARDEV_FD) =20 -void qemu_chr_open_fd(Chardev *chr, int fd_in, int fd_out); +bool qemu_chr_open_fd(Chardev *chr, int fd_in, int fd_out, Error **errp); int qmp_chardev_open_file_source(char *src, int flags, Error **errp); =20 #endif /* CHAR_FD_H */ --=20 2.50.1 From nobody Sun Sep 28 15:29: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=1758282934; cv=none; d=zohomail.com; s=zohoarc; b=SFDlvgJKad588FYrTxbhDvo7peT8mSEZ1qXWNS9uXrWtOOOyBCaynzhHLeXXTFU/2usQ0VG6v97vmuHot74Q7Aivb1RakKkfQWMyB8VhaH3g2YnuJNTt7xulLi9sKv9xDHZTPSfjBFrhnLxLwKkZVc14sVUrCDEZatQKcp2lXt0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282934; 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=tmONteAmIKfsTtmIPKxh9UZI8OuT5Rgmz4ekHvmX4zU=; b=hnPNxqe2F7YVet6XkUYoPXQexTWZ5c5mv3B49OAwLn9fiYPL5o6LgPPPlqude1Iuyvb8WIwG4lEaUnmnMBhr+ndA7HhU9ua9roIztsw8ypjyL/olsgKCIG415ZEcAc1kYHAkL+B8dfGbvZxGcTcvZLzjaP5ahZsC8cIWkd/Pn/4= 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 175828293430646.61260342024309; Fri, 19 Sep 2025 04:55:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZgg-0005BZ-Ua; Fri, 19 Sep 2025 07:54:03 -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 1uzZg5-0003zM-0Y for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:53:28 -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 1uzZfq-00014e-UX for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:53:16 -0400 Received: from mx-prod-mc-04.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-189-lQ4fwf1ZNZ6_S15GVzWtng-1; Fri, 19 Sep 2025 07:53:04 -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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E3F0619560B2; Fri, 19 Sep 2025 11:53:01 +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 47F741955F21; Fri, 19 Sep 2025 11:52:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282787; 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=tmONteAmIKfsTtmIPKxh9UZI8OuT5Rgmz4ekHvmX4zU=; b=D9IMYdy3yeffYGxZ+UEKR6jZRmUBjqPI58HisLRkvpKXkXyHiBJ475bITczvm7t9NIOoPY HyT3xtrYBWWJHBuUDgod+pLntNI07xT7T1iZ9v2gaMnYkvIIMBiubYRyjlA39mf+2KkuoD k6FSsqeK3VdSiTQf/8PDxJOv19qdhGw= X-MC-Unique: lQ4fwf1ZNZ6_S15GVzWtng-1 X-Mimecast-MFC-AGG-ID: lQ4fwf1ZNZ6_S15GVzWtng_1758282782 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 15/16] chardev: close an fd on failure path Date: Fri, 19 Sep 2025 12:50:16 +0100 Message-ID: <20250919115017.1536203-16-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.129.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_H4=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: 1758282935481116600 From: Vladimir Sementsov-Ogievskiy There are at least two failure paths, where we forget to close an fd. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Daniel P. Berrang=C3=A9 --- chardev/char-pty.c | 1 + chardev/char-serial.c | 1 + 2 files changed, 2 insertions(+) diff --git a/chardev/char-pty.c b/chardev/char-pty.c index fe6bfb043d..b066f01412 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -350,6 +350,7 @@ static void char_pty_open(Chardev *chr, =20 close(slave_fd); if (!qemu_set_blocking(master_fd, false, errp)) { + close(master_fd); return; } =20 diff --git a/chardev/char-serial.c b/chardev/char-serial.c index c622d758db..4c6ca713eb 100644 --- a/chardev/char-serial.c +++ b/chardev/char-serial.c @@ -272,6 +272,7 @@ static void qmp_chardev_open_serial(Chardev *chr, return; } if (!qemu_set_blocking(fd, false, errp)) { + close(fd); return; } tty_serial_init(fd, 115200, 'N', 8, 1); --=20 2.50.1 From nobody Sun Sep 28 15:29: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=1758282915; cv=none; d=zohomail.com; s=zohoarc; b=KXk19V0nwy3fvgV5LOxvwmfvPy45CDbtVgL8wfSYfAKtUyNcOt3WZ39d5Jy60dCuvHjbSOO4rpqI/5EGbBcsO8W/FD3wHi5bHeG7obCNWUYqGB0EwbxwxFDj19fLwCCfURaFeq403ZwyM2NHB0AUD1vq+pc2glRvl82pw3s/pps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758282915; 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=l/nPgGoxBal0yhdLm799HPkz/9tEha6vwLh4qn0x4io=; b=PauUbnFIyYh0TU7/DIM48gkf+lWTQH1OAtRVn0acCh9PmDSYAWf0uXYtthFrFaecJ5cFYXk7YNwk61Jq3E+klw3a4QFZCVwQzUWTfhh1vVbg9DcdaEa1XZmAwyPoV6O0zvGRaMPPCGlXGHNMhBhHJFD5moBENtcfb1qOrKUX8zU= 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 175828291512334.37487098461963; Fri, 19 Sep 2025 04:55:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uzZgL-0004db-C0; Fri, 19 Sep 2025 07:53:41 -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 1uzZgI-0004RS-GV for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:53:38 -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 1uzZg4-00019z-QS for qemu-devel@nongnu.org; Fri, 19 Sep 2025 07:53:33 -0400 Received: from mx-prod-mc-02.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-411-_QGoYI_lP0u-9i_WIN13rw-1; Fri, 19 Sep 2025 07:53:14 -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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ECDE3195608A; Fri, 19 Sep 2025 11:53:11 +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 6E0E11955F21; Fri, 19 Sep 2025 11:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758282797; 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=l/nPgGoxBal0yhdLm799HPkz/9tEha6vwLh4qn0x4io=; b=ISD6ySah1p3G13D17ZpYEfvgmTEXUaeNyN1RYgLRxd1fXHP81LC0FZjyV6upc1jfdMeTiB wDPSjldfyZwGklGSfwa4wrpxAECczUexNzVMCTLdNfTXRnLYaEFC7COF1+tXlwsB+Var6J HDohvWjEQBBVxH3nRIWNslVN9itVkIQ= X-MC-Unique: _QGoYI_lP0u-9i_WIN13rw-1 X-Mimecast-MFC-AGG-ID: _QGoYI_lP0u-9i_WIN13rw_1758282792 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 16/16] util/vhost-user-server: vu_message_read(): improve error handling Date: Fri, 19 Sep 2025 12:50:17 +0100 Message-ID: <20250919115017.1536203-17-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.129.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_H4=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, T_SPF_TEMPERROR=0.01 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: 1758282917261116600 From: Vladimir Sementsov-Ogievskiy 1. Drop extra error_report_err(NULL), it will just crash, if we get here. 2. Get and report error of qemu_set_blocking(), instead of aborting. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Daniel P. Berrang=C3=A9 --- util/vhost-user-server.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 04c72a92aa..1dbe409f82 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -62,7 +62,7 @@ static void vmsg_close_fds(VhostUserMsg *vmsg) } } =20 -static void vmsg_unblock_fds(VhostUserMsg *vmsg) +static bool vmsg_unblock_fds(VhostUserMsg *vmsg, Error **errp) { int i; =20 @@ -74,13 +74,16 @@ static void vmsg_unblock_fds(VhostUserMsg *vmsg) */ if (vmsg->request =3D=3D VHOST_USER_ADD_MEM_REG || vmsg->request =3D=3D VHOST_USER_SET_MEM_TABLE) { - return; + return true; } =20 for (i =3D 0; i < vmsg->fd_num; i++) { - /* TODO: handle error more gracefully than aborting */ - qemu_set_blocking(vmsg->fds[i], false, &error_abort); + if (!qemu_set_blocking(vmsg->fds[i], false, errp)) { + return false; + } } + + return true; } =20 static void panic_cb(VuDev *vu_dev, const char *buf) @@ -123,7 +126,6 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMs= g *vmsg) =20 vmsg->fd_num =3D 0; if (!ioc) { - error_report_err(local_err); goto fail; } =20 @@ -177,7 +179,10 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserM= sg *vmsg) } while (read_bytes !=3D VHOST_USER_HDR_SIZE); =20 /* qio_channel_readv_full will make socket fds blocking, unblock them = */ - vmsg_unblock_fds(vmsg); + if (!vmsg_unblock_fds(vmsg, &local_err)) { + error_report_err(local_err); + goto fail; + } if (vmsg->size > sizeof(vmsg->payload)) { error_report("Error: too big message request: %d, " "size: vmsg->size: %u, " --=20 2.50.1