From nobody Sat Sep 6 14:41:20 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1756892773; cv=none; d=zohomail.com; s=zohoarc; b=JUNfyUXmDuLjhM2nSInTI0rtPoHNEEEyJ65aEcSkhHtwPoFA+b33Q/4EP3Neuwlc0aSk0IiH8SSvtyvStIwkCUzQM3CUKZ63rUVfRKRwIUQ9yxjsvhheDbcb1TcQr2DjdD/SAKqgQt3H+y1gUjKcYKca9DxcPTnpkxnBZZPm45g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756892773; h=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=LdOEsfMv9+PXz13uCV6qZQY+vLOFE3HhoDVvWVSOAWc=; b=GopauK8t/7hjk2am4Aw2EYeWKHvgM1OyJoqQFZ70wW99TtfxCqQ9fML+tH4Q0uyKjm1ZBOvMxDgTBc92eoFJx3MvwEww1x7YDZN1ZxvpB9wlFqKlameaYuKSWoEqIML82AiZez7x2HDzaYfu7VA37dO0jKJldcFME18CxIijZkU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756892773368886.7035412844164; Wed, 3 Sep 2025 02:46:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utk2Y-00068l-UL; Wed, 03 Sep 2025 05:44: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 1utk2R-00063v-5y; Wed, 03 Sep 2025 05:44:23 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utk2N-0007uR-S3; Wed, 03 Sep 2025 05:44:22 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 15CD08067A; Wed, 03 Sep 2025 12:44:16 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id EicMoq3GhCg0-u946eTFc; Wed, 03 Sep 2025 12:44:15 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1756892655; bh=LdOEsfMv9+PXz13uCV6qZQY+vLOFE3HhoDVvWVSOAWc=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=unZJsqTOEcaT/Mj/DvUYDNcx4ceuEqoxa3/t8/9xjMXVQIBW5R2D+Y9f4umew1CMr 20/BHKBocmmNhct5E37yYT87thyxaisNp76f+F2MJzGm2aIk/cE3VdxsgUQ8zbwiVn 6nb55Wkmzi+Boz6tcCJQPJJEfWMo2hX5ET5RjLXs= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: berrange@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, peterx@redhat.com, vsementsov@yandex-team.ru Subject: [PATCH 01/10] io/channel: document how qio_channel_readv_full() handles fds Date: Wed, 3 Sep 2025 12:44:01 +0300 Message-ID: <20250903094411.1029449-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250903094411.1029449-1-vsementsov@yandex-team.ru> References: <20250903094411.1029449-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1756892774883116600 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- include/io/channel.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/io/channel.h b/include/io/channel.h index 234e5db70d..b848d50b99 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -117,6 +117,12 @@ struct QIOChannelClass { size_t nfds, int flags, Error **errp); + + /* + * The io_readv handler must guarantee that all + * incoming fds are set BLOCKING and CLOEXEC (if + * available). + */ ssize_t (*io_readv)(QIOChannel *ioc, const struct iovec *iov, size_t niov, @@ -124,6 +130,7 @@ struct QIOChannelClass { size_t *nfds, int flags, Error **errp); + int (*io_close)(QIOChannel *ioc, Error **errp); GSource * (*io_create_watch)(QIOChannel *ioc, @@ -234,6 +241,9 @@ 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. + * qio_channel_readv_full() guarantees that all + * incoming fds are set BLOCKING 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.48.1 From nobody Sat Sep 6 14:41:20 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1756892852; cv=none; d=zohomail.com; s=zohoarc; b=aqE30lkQaSnNn5oSDCOHXNDlvxa9Zm5fm8bBcy9AjJMIxm12Nsd6qlV51TjQOxut++cjiroZQ6PStts7DnVu9OVVz1WS3/g31x+co39cLM6NZ2xRYPRhYnRO34ADhY9r6sJv4NKA/zTFEjbm3LaJNJqt2oqNZ12H/cLTYo/MT8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756892852; h=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=sIRk+lbn/qhf6egokX5jBbKKnrraNB0E4tHLMcdfjyg=; b=Dea+Gy4WME9jExUREN4fJmnanJTY8JNLCPR6UGj0KdHb7S/zxI1SYzFFSKdqEPzg32wfKPpxTyy+czH179NxKxCEPiJ0bl6eQ+buzs+XzYO6luMaVGQpt4PzpF09nhJTSd+Dsoq62HTE4jJBwok+GUhCBzT8qufmr7FGrgV/T0g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756892852483386.2263595237822; Wed, 3 Sep 2025 02:47:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utk2Z-000692-4x; Wed, 03 Sep 2025 05:44: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 1utk2R-00063u-5S; Wed, 03 Sep 2025 05:44:23 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utk2N-0007uU-P9; Wed, 03 Sep 2025 05:44:22 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id AD7BC806F5; Wed, 03 Sep 2025 12:44:16 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id EicMoq3GhCg0-frm9E0oN; Wed, 03 Sep 2025 12:44:16 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1756892656; bh=sIRk+lbn/qhf6egokX5jBbKKnrraNB0E4tHLMcdfjyg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=nT4yCZVsRkiA7SMnpQ56wBrm1Cnlh9icDq5jMTo2DwmW1o9yKBbOhcS9bg6vG4/Bk iMD150zYxISfZOK8mqEsAkrIckHEafoa/fjBkEA2+MpCFPh0glsHwsLCprFmzIMsjX uVqjqnoGFQZd37dMXpuimLO0mBUclILoPxN1TRow= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: berrange@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, peterx@redhat.com, vsementsov@yandex-team.ru, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Subject: [PATCH 02/10] char-socket: rework tcp_chr_recv() Date: Wed, 3 Sep 2025 12:44:02 +0300 Message-ID: <20250903094411.1029449-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250903094411.1029449-1-vsementsov@yandex-team.ru> References: <20250903094411.1029449-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1756892853962124100 Content-Type: text/plain; charset="utf-8" First, qio_channel_readv_full() already guarantees BLOCKING and CLOEXEC states for incoming descriptors, no reason call extra ioctls. Second, current implementation calls _set_block() and _set_cloexec() again on old descriptors on failure path - we fix this too. Finally, handling errors exactly after qio_channel_readv_full() call looks more readable. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- chardev/char-socket.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 1e8313915b..5b9b19ba8b 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -293,6 +293,18 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf, s= ize_t len) 0, &err); } =20 + if (ret =3D=3D QIO_CHANNEL_ERR_BLOCK) { + errno =3D EAGAIN; + return -1; + } else if (ret =3D=3D -1) { + trace_chr_socket_recv_err(chr, chr->label, error_get_pretty(err)); + error_free(err); + errno =3D EIO; + return -1; + } + + assert(ret >=3D 0); + if (msgfds_num) { /* close and clean read_msgfds */ for (i =3D 0; i < s->read_msgfds_num; i++) { @@ -307,30 +319,7 @@ 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; - } else if (ret =3D=3D -1) { - trace_chr_socket_recv_err(chr, chr->label, error_get_pretty(err)); - error_free(err); - errno =3D EIO; - } else if (ret =3D=3D 0) { - trace_chr_socket_recv_eof(chr, chr->label); - } + trace_chr_socket_recv_eof(chr, chr->label); =20 return ret; } --=20 2.48.1 From nobody Sat Sep 6 14:41:20 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1756892677; cv=none; d=zohomail.com; s=zohoarc; b=H5xS9FQkfkZTE2htMvxF6Apmo0rwmqbt8RpQ2nPb8RIwnvuSvO9W3CniD6S2e5/XOZe1gAyIEY5gWnafNh7mVKY9Waqn/SVDtLJ56gRDqllbI63VtPlN1OJ+CJcc+gfG9P/8TWYbQ9i7SaZZlC6Wv4iE6acBTpK0T7Kn/QS+Mr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756892677; h=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=hUj5xMUecTx8X16HPNS7q8D78Nrs6/uPNPUtPM98KSc=; b=ndlcBIVQHgh5S5dHeCv5IhbEIfIo57HX25G/Zblaeos2WYZSJSR/N6exkb8yXln53L0ryhkhgOWoLlggNLfABjMkFU7lhuCAqspkRd2pSLoJJ0kI4olplDK9CaWuxA30plGyP6DyEyo0yhwc5hPtlmUI5ElVfApIQl0oP2iTFDo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756892677818655.4928936216808; Wed, 3 Sep 2025 02:44:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utk2S-00063r-7X; Wed, 03 Sep 2025 05:44:24 -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 1utk2Q-00063L-27; Wed, 03 Sep 2025 05:44:22 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utk2N-0007ua-PR; Wed, 03 Sep 2025 05:44:21 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 77E458073C; Wed, 03 Sep 2025 12:44:17 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id EicMoq3GhCg0-vSakBBTS; Wed, 03 Sep 2025 12:44:17 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1756892657; bh=hUj5xMUecTx8X16HPNS7q8D78Nrs6/uPNPUtPM98KSc=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=No93VDNRuH1ywvNHUdJYxMFFfitrRLvSwI0D+/3y1LU6Q3sZjwSZtvFpkM8jlMvNi jE8NLieu2qzHE1rGuv8Nc/B4A7+1eWxcGSRqs9Uo9V6RtPPSgvtO/gvADXfz/1oiMC E+l+vZyByCbHnYjY8WpJd+nytw58JN3B03cuw2eU= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: berrange@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, peterx@redhat.com, vsementsov@yandex-team.ru, Paolo Bonzini , Stefan Weil Subject: [PATCH 03/10] util: add qemu_set_blocking() function Date: Wed, 3 Sep 2025 12:44:03 +0300 Message-ID: <20250903094411.1029449-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250903094411.1029449-1-vsementsov@yandex-team.ru> References: <20250903094411.1029449-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1756892681381124100 Content-Type: text/plain; charset="utf-8" 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 g_unix_set_fd_nonblocking() and several wrappers without bool parameter: - qemu_scoket_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(), the best one - qemu_socket_set_block(), which simply ignores an error, the worst case And all three lack errp argument, so we have to handle it after the call. So let's introduce a new socket-layer wrapper, and use it consistently in following commits. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- include/qemu/osdep.h | 1 + util/oslib-posix.c | 12 ++++++++++++ util/oslib-win32.c | 18 ++++++++++++++++++ 3 files changed, 31 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..e473938195 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -250,6 +250,18 @@ void qemu_anon_ram_free(void *ptr, size_t size) #endif } =20 +bool qemu_set_blocking(int fd, bool block, Error **errp) +{ + if (!g_unix_set_fd_nonblocking(fd, !block, NULL)) { + error_setg_errno(errp, errno, + "Can't set file descriptor %d %s", fd, + block ? "blocking" : "non-blocking"); + 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.48.1 From nobody Sat Sep 6 14:41:20 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1756892698; cv=none; d=zohomail.com; s=zohoarc; b=HxwkxbISQtucYTBTtnajLUgx0bk+9YBHRVPm1vcGhqoj+NYrxXWmLpP///XIfRquu/IMyvC26o0z67dciv4Ws9oca++UO7eqAYaUUR1dDBBMM/Jm+2Oy3duCfBTACKIm1FVKXFW3gNA1M+RkafoxW9JUhl6bwAgNw1ZQk1OGVR4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756892698; h=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=zit6+aTBTIBl1ZuWWFJYHmrdrb/Nql11nAAi/gn7+/o=; b=YUdXZY+oxPsopvpMD5twV69HheLNgm8+0KKDXD2IUDIesjCT+lykfsd0e7OzGZZMicmaIcnMTPem9W34k/5Ed5kmdFkpFYMgjEJZint44bNq3p+DJgR/uyK6RRmeEdAPtYCAmI8JU16G3e60wpT+2Eu872gF1ZC20Llzc9oGkZI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756892697981675.8630530314356; Wed, 3 Sep 2025 02:44:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utk2k-0006Kv-2c; Wed, 03 Sep 2025 05:44:42 -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 1utk2R-000646-Qb; Wed, 03 Sep 2025 05:44:24 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utk2O-0007ul-Oa; Wed, 03 Sep 2025 05:44:23 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 63FF180782; Wed, 03 Sep 2025 12:44:18 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id EicMoq3GhCg0-Z2a9dZNQ; Wed, 03 Sep 2025 12:44:17 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1756892657; bh=zit6+aTBTIBl1ZuWWFJYHmrdrb/Nql11nAAi/gn7+/o=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Pv0JZpdIcROZWPy1vZnhejYEU/WI1ZBqWwbtwuE+zUO3tXfDng6utzVW0a2ATVhNW XYAOo9yHKEA9Vo5i2ki55VbR/fFND2Dc4lNIr2v9Jmby5ALBnMFkqatschXQyu//xq ae0C7OOB/gnugZEpCAVCBckBqVXVmZ5WmGl3bQC0= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: berrange@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, peterx@redhat.com, vsementsov@yandex-team.ru, "Michael S. Tsirkin" , Stefano Garzarella , Jason Wang , Michael Roth , Kostiantyn Kostiuk , Paolo Bonzini , Stefan Weil , Coiby Xu Subject: [PATCH 04/10] util: drop qemu_socket_set_nonblock() Date: Wed, 3 Sep 2025 12:44:04 +0300 Message-ID: <20250903094411.1029449-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250903094411.1029449-1-vsementsov@yandex-team.ru> References: <20250903094411.1029449-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1756892701017124100 Content-Type: text/plain; charset="utf-8" Use common qemu_set_blocking() instead. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- contrib/ivshmem-server/ivshmem-server.c | 5 ++++- 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 | 5 ++++- tests/unit/test-crypto-tlssession.c | 8 ++++---- util/oslib-posix.c | 7 ------- util/oslib-win32.c | 5 ----- util/vhost-user-server.c | 4 ++-- 14 files changed, 62 insertions(+), 37 deletions(-) diff --git a/contrib/ivshmem-server/ivshmem-server.c b/contrib/ivshmem-serv= er/ivshmem-server.c index 2f3c7320a6..9ccd436ee4 100644 --- a/contrib/ivshmem-server/ivshmem-server.c +++ b/contrib/ivshmem-server/ivshmem-server.c @@ -146,7 +146,10 @@ ivshmem_server_handle_new_conn(IvshmemServer *server) return -1; } =20 - qemu_socket_set_nonblock(newfd); + if (!qemu_set_blocking(newfd, false, NULL)) { + close(newfd); + return -1; + } IVSHMEM_SERVER_DEBUG(server, "accept()=3D%d\n", newfd); =20 /* allocate new structure for this peer */ 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 3b7ca924ff..e77602a22e 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -820,11 +820,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..ddf8ebdc5e 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("errer: %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..1b7e283f24 100644 --- a/tests/unit/socket-helpers.c +++ b/tests/unit/socket-helpers.c @@ -88,7 +88,10 @@ static int socket_can_bind_connect(const char *hostname,= int family) goto cleanup; } =20 - qemu_socket_set_nonblock(cfd); + if (!qemu_set_blocking(cfd, false, NULL)) { + goto cleanup; + } + 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 e473938195..dc23b33210 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -272,13 +272,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 b19229074a..8dcd32dc65 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -78,7 +78,7 @@ static void vmsg_unblock_fds(VhostUserMsg *vmsg) } =20 for (i =3D 0; i < vmsg->fd_num; i++) { - qemu_socket_set_nonblock(vmsg->fds[i]); + qemu_set_blocking(vmsg->fds[i], false, &error_abort); } } =20 @@ -303,7 +303,7 @@ 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); + 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.48.1 From nobody Sat Sep 6 14:41:20 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1756892784; cv=none; d=zohomail.com; s=zohoarc; b=nLq6lzevyW4obRctgxsFxJBGQDS/tWfMiBcJyLWS0fwYJrZoftuAiygeZ7yK53WQXR2R6ymn9d3AE8sbyfyoJL1gCYAl/5y4A6FbW96Qx774JunsDOK+wJMbuymbNk78D8avaNYjeCGJdy21sJ08uNWJ65BpV29fEnufaikYnhY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756892784; h=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=cPcTm0Onlv9tB/dQmFTsQTZnBRIN/zxkFFBerI9L9ZY=; b=UYtXot9vKelfZqu2OESqi3Kj/1oXC41+zWWZ3I7GSFLOanRpkHfBxwHC3bya1zcevWoXl8O10/TGNEJg06RSu3LmOkQORYD35p8DfeY1geXheTfn3a2CXv5c7RsZDEVggROqZbjZdI+seqrfvxFU+mN/3pwxwCxAxSC8xcuw8Gc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756892784733723.2809567492274; Wed, 3 Sep 2025 02:46:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utk2v-0006MJ-Ec; Wed, 03 Sep 2025 05:44:56 -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 1utk2R-000641-OV; Wed, 03 Sep 2025 05:44:24 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utk2O-0007uq-TA; Wed, 03 Sep 2025 05:44:23 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 218AD80783; Wed, 03 Sep 2025 12:44:19 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id EicMoq3GhCg0-JNEI174m; Wed, 03 Sep 2025 12:44:18 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1756892658; bh=cPcTm0Onlv9tB/dQmFTsQTZnBRIN/zxkFFBerI9L9ZY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=WafOWKhSIam7wqgBtEoMqREtp9GqziURAExMc14aohpxP4VzACEKlTyiq+Zq1w/kT WxWytBB85LeB+pN29by/nzRf06oeQxA0sGzLMDB1K32q2sm3lzhVpdN75i9uyWIkIC b10KPRlTif38fovzYblsA7ZtKLwNr3rgDZG1RO9Y= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: berrange@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, peterx@redhat.com, vsementsov@yandex-team.ru, Jason Wang , Paolo Bonzini , Stefan Weil Subject: [PATCH 05/10] util: drop qemu_socket_try_set_nonblock() Date: Wed, 3 Sep 2025 12:44:05 +0300 Message-ID: <20250903094411.1029449-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250903094411.1029449-1-vsementsov@yandex-team.ru> References: <20250903094411.1029449-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1756892784954116600 Content-Type: text/plain; charset="utf-8" Now we can use qemu_set_blocking() in these cases. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- 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 dc23b33210..51f16d57ff 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -267,10 +267,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.48.1 From nobody Sat Sep 6 14:41:20 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1756892845; cv=none; d=zohomail.com; s=zohoarc; b=ccuNnGQ39R0WqyICKNLoKLaP8DNssWie51RXHw+ON6iygMjvr0TJRPxFQKDY5WKeePFpwKaUtrTfHYf0z1faEg5hBAt3N+druoO25a+wast3a4uFxM4GqS8RUx/GlwBm9tVMKqn6oBaMMGdbIb2yQaGS6c3Utlg1K/9s3Z5BID8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756892845; h=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=fkLGyCbDw3KY+wvM5vQPHxrSIbDb3U7juq+tFywxqw8=; b=ChsEYsR4yxJtSG7S+Z/Ml/1nsEQj0rNr4ctJVRQo47iIc38reTuzD3mWdR630lN7kQTAz8VhZrv1c9XslxORakkYJv9R31HGzReDd2y8A08A/JLOEn/Aj7PgneXF5+viITjL/T5fVxXazU8DcF8gHOyNwgwJMDyRG4+xHaujAB0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756892845837682.8831520233311; Wed, 3 Sep 2025 02:47:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utk2Z-000699-NQ; Wed, 03 Sep 2025 05:44: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 1utk2S-00064z-FI; Wed, 03 Sep 2025 05:44:24 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utk2Q-0007v4-Cn; Wed, 03 Sep 2025 05:44:24 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id BF0A98078F; Wed, 03 Sep 2025 12:44:19 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id EicMoq3GhCg0-lPCqMY01; Wed, 03 Sep 2025 12:44:19 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1756892659; bh=fkLGyCbDw3KY+wvM5vQPHxrSIbDb3U7juq+tFywxqw8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=JA4nSTMGJJsYSqM6i2/e159fuyGuraJUhdh8ORBisls/ZDxHiR2nuzVidrgGvyn9H SgZMzrLmZEdXeBZ/8XtcsFjJjdv1QjyedG7honDK9Jb2Y9h/hE/Z4fMC/EJO6EiobN KjgVPVAO2j30q/yQ5eByaU6X5ASQJ5ppKlEAm0rw= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: berrange@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, peterx@redhat.com, vsementsov@yandex-team.ru, Paolo Bonzini , Stefan Weil Subject: [PATCH 06/10] util: drop qemu_socket_set_block() Date: Wed, 3 Sep 2025 12:44:06 +0300 Message-ID: <20250903094411.1029449-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250903094411.1029449-1-vsementsov@yandex-team.ru> References: <20250903094411.1029449-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1756892847900124100 Content-Type: text/plain; charset="utf-8" Now we can use qemu_set_blocking() and stop ignore errors in these case. Just crash on error for now, as we'll rework it in following commits. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- include/qemu/sockets.h | 1 - io/channel-socket.c | 3 ++- util/oslib-posix.c | 6 ------ util/oslib-win32.c | 7 ------- 4 files changed, 2 insertions(+), 15 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/io/channel-socket.c b/io/channel-socket.c index e77602a22e..4f7e86f72f 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -498,7 +498,8 @@ static void qio_channel_socket_copy_fds(struct msghdr *= msg, } =20 /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ - qemu_socket_set_block(fd); + /* TODO: don't crash on error, just handle it! */ + qemu_set_blocking(fd, true, &error_abort); =20 #ifndef MSG_CMSG_CLOEXEC qemu_set_cloexec(fd); diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 51f16d57ff..8891d82db0 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -262,12 +262,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.48.1 From nobody Sat Sep 6 14:41:20 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1756892753; cv=none; d=zohomail.com; s=zohoarc; b=jl1bQqYJk4c7Yr0o3UcuWvh6KT/lbfEyMlnqUNXBOwTDTyATKIKmNC+4d82kVz00h5nl2LobgxGJM0NNKKknDO2qgFos1OdlMkHqkp8JcsB2qAZenEYySgHIlIGeWzSmEPem1QPyp1PWEQXVHLnVHTHb9eWioOiAflpEpONLnLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756892753; h=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=irwXYky4BmEjlrsjMDSVpln+Q+lnheCMLPQaCIlhUzM=; b=BUEU0gcvoCv28e/jfvoho3YePvAKvgIxV0+ZQxfDU8u4Vpcb3L1F8watTUpg+btILp5LcpMAEm8PeRPhkAuyqDd73GQskbbCfeIGHkZCoIf2tdyqjSRC0SvHKc/eToDV00bIEVh37WLIEqx5WI1vOh5rtvQvXnc8kvX/5ydW410= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756892753248589.93035956317; Wed, 3 Sep 2025 02:45:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utk2c-0006AK-KN; Wed, 03 Sep 2025 05:44: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 1utk2U-00066L-DQ; Wed, 03 Sep 2025 05:44:27 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utk2R-0007vZ-KU; Wed, 03 Sep 2025 05:44:26 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id B5CE9807AC; Wed, 03 Sep 2025 12:44:21 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id EicMoq3GhCg0-hpyxFrqc; Wed, 03 Sep 2025 12:44:21 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1756892661; bh=irwXYky4BmEjlrsjMDSVpln+Q+lnheCMLPQaCIlhUzM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=w5B7JgqwY6g/+pvIDeKt0/rQr/lBLcYiMQVObewhQUk1zSswFrN7V4w4EfjS8P8+V 0pOjn+bYXzD5dbVcLSyHlmx1/7qzl08gazY0TvLMgJBLMzTriUZ1RXMyosYxEzIgbm H5vzGKEkntj4kYYO4XkYI5dY59P+YSPFtk7oUs+s= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: berrange@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, peterx@redhat.com, vsementsov@yandex-team.ru, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Gerd Hoffmann , "Michael S. Tsirkin" , Gustavo Romero , Stefano Garzarella , Jason Wang , Michael Roth , Kostiantyn Kostiuk , Alexander Bulekov , Bandan Das , Stefan Hajnoczi , Fabiano Rosas , Darren Kenny , Qiuhao Li , Laurent Vivier Subject: [PATCH 07/10] use qemu_set_blocking instead of g_unix_set_fd_nonblocking Date: Wed, 3 Sep 2025 12:44:07 +0300 Message-ID: <20250903094411.1029449-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250903094411.1029449-1-vsementsov@yandex-team.ru> References: <20250903094411.1029449-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1756892755571116600 Content-Type: text/plain; charset="utf-8" Instead of open-coded g_unix_set_fd_nonblocking() calls, use QEMU wrapper qemu_socket_set_nonblock(). Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- 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 | 4 +++- hw/misc/ivshmem-pci.c | 8 +++++++- 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 | 8 +++++++- 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 | 3 +-- tests/unit/test-iov.c | 5 +++-- ui/input-linux.c | 3 +-- util/event_notifier-posix.c | 5 +++-- util/main-loop.c | 6 +++++- 21 files changed, 69 insertions(+), 54 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..29f298bbcb 100644 --- a/hw/misc/ivshmem-flat.c +++ b/hw/misc/ivshmem-flat.c @@ -12,6 +12,7 @@ #include "qemu/units.h" #include "qemu/error-report.h" #include "qemu/module.h" +#include "qemu/sockets.h" #include "qapi/error.h" #include "hw/irq.h" #include "hw/qdev-properties-system.h" @@ -154,7 +155,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, NULL); 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..b7da89fe3a 100644 --- a/hw/misc/ivshmem-pci.c +++ b/hw/misc/ivshmem-pci.c @@ -21,6 +21,7 @@ #include "qemu/units.h" #include "qapi/error.h" #include "qemu/cutils.h" +#include "qemu/sockets.h" #include "hw/pci/pci.h" #include "hw/qdev-properties.h" #include "hw/qdev-properties-system.h" @@ -540,7 +541,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..2e444e59b5 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..786f339c13 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -34,6 +34,7 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/cutils.h" +#include "qemu/sockets.h" =20 #define PATH_NET_TUN "/dev/net/tun" =20 @@ -124,7 +125,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, NULL)) { + close(fd); + return -1; + } + return fd; } =20 diff --git a/net/tap-solaris.c b/net/tap-solaris.c index 51b7830bef..02709590c1 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 NULL)) { + 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 75cb3e44b2..ba70bf997c 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -472,8 +472,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..8c05e0d528 100644 --- a/util/event_notifier-posix.c +++ b/util/event_notifier-posix.c @@ -14,6 +14,7 @@ #include "qemu/cutils.h" #include "qemu/event_notifier.h" #include "qemu/main-loop.h" +#include "qemu/sockets.h" =20 #ifdef CONFIG_EVENTFD #include @@ -52,11 +53,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, NULL)) { ret =3D -errno; goto fail; } - if (!g_unix_set_fd_nonblocking(fds[1], true, NULL)) { + if (!qemu_set_blocking(fds[1], false, NULL)) { ret =3D -errno; goto fail; } diff --git a/util/main-loop.c b/util/main-loop.c index 51aeb2432e..6885be688c 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -34,6 +34,7 @@ #include "block/thread-pool.h" #include "qemu/error-report.h" #include "qemu/queue.h" +#include "qemu/sockets.h" #include "qom/object.h" =20 #ifndef _WIN32 @@ -114,7 +115,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.48.1 From nobody Sat Sep 6 14:41:20 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1756892852; cv=none; d=zohomail.com; s=zohoarc; b=SOLu21WDJ5O/Q2ZvhqzGaqyu+U+LBwjAmP1Hh8RER4sPy/XOp10zY5zszHcqBBF2MVQjJBWz5oxnPsFWUcT026retEvYlXZMH/a4HsbxKQNTrdr5eucv37qj9FCi4bfH27MJV7CVFsFDrrjHMtl9i1EDmnZ3uGZQKMalIXbAi9I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756892852; h=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=cxz7Rx52Pf9R/0jZg6IJzKm0KNpYmtuSsQhLIkTbvH0=; b=Fql1/PfupR7AdGwVivbV79IRt/apPJMD50WZbP5Jkmf33ubt4iZxp0swPNOjP3oUoHerywlOwRYo1yNCfVxgfsZ3cUuT24sWMS5aCQL7z9etvWCVkcj96mHIJaEkNvhv5bLHKjZdUjel7qPtyJOWuL12vb0fojTiSGrb73w0FQI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756892852411871.1011298481351; Wed, 3 Sep 2025 02:47:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utk2Z-00069B-RV; Wed, 03 Sep 2025 05:44: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 1utk2U-000664-5t; Wed, 03 Sep 2025 05:44:26 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utk2S-0007vp-CM; Wed, 03 Sep 2025 05:44:25 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 9A5C6807BA; Wed, 03 Sep 2025 12:44:22 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id EicMoq3GhCg0-YKtgi2yn; Wed, 03 Sep 2025 12:44:22 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1756892662; bh=cxz7Rx52Pf9R/0jZg6IJzKm0KNpYmtuSsQhLIkTbvH0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=KrEBzLb2iZbbeHCBq1kOgvxsAnIc6Pwuq/aImZWpIpum2za7aDey3Z4/l74GVE5Bg ebERmwAItE93ols4nuRiF2x+fQqlfDwMzAKM4tNpQLEKcGu7kI0kumNs4unGy9XYKf l9UxlpcoX1Y+LsI3sWIEMAHkxY5+zPXRTDFXUkSQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: berrange@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, peterx@redhat.com, vsementsov@yandex-team.ru, Paolo Bonzini Subject: [PATCH 08/10] oslib-posix: add qemu_fds_set_blocking() helper Date: Wed, 3 Sep 2025 12:44:08 +0300 Message-ID: <20250903094411.1029449-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250903094411.1029449-1-vsementsov@yandex-team.ru> References: <20250903094411.1029449-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1756892853969124100 Content-Type: text/plain; charset="utf-8" And use it in io/channel-socket.c. This simplifies the following commit, which will move this functionality from io/channel-socket.c to the callers. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- include/qemu/osdep.h | 7 +++++++ io/channel-socket.c | 24 +++++++++++++----------- util/oslib-posix.c | 12 ++++++++++++ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 1b38cb7e45..dde98d588c 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -689,6 +689,13 @@ ssize_t qemu_write_full(int fd, const void *buf, size_= t count) void qemu_set_cloexec(int fd); bool qemu_set_blocking(int fd, bool block, Error **errp); =20 +/* + * qemu_fds_set_blockinging: + * Call qemu_socket_set_block() on several fds. + * When @nfds =3D 0, does nothing, @fds is not touched. + */ +bool qemu_fds_set_blockinging(int *fds, int nfds, bool block, Error **errp= ); + /* Return a dynamically allocated directory path that is appropriate for s= toring * local state. * diff --git a/io/channel-socket.c b/io/channel-socket.c index 4f7e86f72f..96098b5bcc 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -472,8 +472,11 @@ 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; +#ifndef MSG_CMSG_CLOEXEC + int i; +#endif =20 if (cmsg->cmsg_len < CMSG_LEN(sizeof(int)) || cmsg->cmsg_level !=3D SOL_SOCKET || @@ -491,20 +494,19 @@ static void qio_channel_socket_copy_fds(struct msghdr= *msg, *fds =3D g_renew(int, *fds, *nfds + gotfds); memcpy(*fds + *nfds, CMSG_DATA(cmsg), fd_size); =20 + /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ + /* TODO: don't crash on error, just handle it! */ + qemu_fds_set_blockinging(*fds + *nfds, gotfds, true, &error_abort); + +#ifndef MSG_CMSG_CLOEXEC for (i =3D 0; i < gotfds; i++) { int fd =3D (*fds)[*nfds + i]; - if (fd < 0) { - continue; + if (fd >=3D 0) { + qemu_set_cloexec(fd); } - - /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ - /* TODO: don't crash on error, just handle it! */ - qemu_set_blocking(fd, true, &error_abort); - -#ifndef MSG_CMSG_CLOEXEC - qemu_set_cloexec(fd); -#endif } +#endif + *nfds +=3D gotfds; } } diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 8891d82db0..8589ff21ec 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -262,6 +262,18 @@ bool qemu_set_blocking(int fd, bool block, Error **err= p) return true; } =20 +bool qemu_fds_set_blockinging(int *fds, int nfds, bool block, Error **errp) +{ + int i; + for (i =3D 0; i < nfds; i++) { + if (fds[i] >=3D 0 && !qemu_set_blocking(fds[i], block, errp)) { + return false; + } + } + + return true; +} + int socket_set_fast_reuse(int fd) { int val =3D 1, ret; --=20 2.48.1 From nobody Sat Sep 6 14:41:20 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1756892823; cv=none; d=zohomail.com; s=zohoarc; b=dA7K9e+Ku2ZsmKfBxtqi2PzIwLK4qeRT4Mb0+3yiRM/MSMet6Rb9O5shorgtgqsdLXjWyMnZMDbIG/QBks0jMNsLira00xgwss9Hhb6pMtrVtW01QySCdn5FdHLTw9dg3lrI/cZk8+AGkI4/xNvnDgtzdgx69q2dAkocBv4z+AM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756892823; h=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=mSgHIaR12/SBVJgL9Jw+GVpLjwNw4STFZ/H1sTGYY8U=; b=hdLQYzVXOaQsWztjynQvrvVcWPd8wbl2uhndoFj1UVn4JgZMdraDgXXbg/IZ82eoBTKiSlkgxh0lkTQZcAUAgrl64ozAtac7e54S8walg5dsxPvMjN8rNLjRvieNAmTbH0oUlSXvp1rEt+n3BZoX7AnsjbChhBlNvAXuIBmA7uM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756892823805725.9579295266462; Wed, 3 Sep 2025 02:47:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utk2e-0006BR-Qc; Wed, 03 Sep 2025 05:44: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 1utk2V-00067E-QD; Wed, 03 Sep 2025 05:44:27 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utk2T-0007wr-LR; Wed, 03 Sep 2025 05:44:27 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 0DEBF80798; Wed, 03 Sep 2025 12:44:24 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id EicMoq3GhCg0-KpIGMhKy; Wed, 03 Sep 2025 12:44:23 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1756892663; bh=mSgHIaR12/SBVJgL9Jw+GVpLjwNw4STFZ/H1sTGYY8U=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=e4Q6bPGO1FgzQWGbqzy0FzhzvFesapaiNUW9R2P44eryxw9/a5TFSc4kqT7mf3SAp S9atTzPi/BtNOyBdCHi2Exi+L6Vc+qe5d6Nee428vNE7gAcA8wtXYbi3kOu2ms/nMh fgJFKOzLaAhTtduP+WVNWDKTxjeqGoPYiq65zixU= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: berrange@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, peterx@redhat.com, vsementsov@yandex-team.ru, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Elena Ufimtseva , Jagannathan Raman , John Levon , Thanos Makatos , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , "Michael S. Tsirkin" , Stefano Garzarella , Fabiano Rosas , Fam Zheng , Stefan Berger , Laurent Vivier , Coiby Xu Subject: [PATCH 09/10] qio_channel_readv_full(): move setting fd blocking to callers Date: Wed, 3 Sep 2025 12:44:09 +0300 Message-ID: <20250903094411.1029449-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250903094411.1029449-1-vsementsov@yandex-team.ru> References: <20250903094411.1029449-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1756892826300124100 Content-Type: text/plain; charset="utf-8" In future we'll need a way to pass non-blocking sockets through migration channel (backed by unix-socket for local migration). In this case setting fd blocking in qio_channel_readv_full() and than setting it non-blocking again in migration state loading code is not quit good: 1. For CPR scenario it's just wrong, because we pass fds when source is still running. Making fd blocking when it is still being used on source will break things. [Still, most probably we don't no have CPR-supporting states which operates with non-blocking sockets] 2. It's just ineffective to call the ioctl twice for nothing. So, we'll need a way to avoid call to qemu_socket_set_block() in qio_channel_readv_full(). Still let's go further, and simply keep in qio_channel_readv_full() blocking status of fd as is, and let's the caller to care about it. It's good at least for symmetry of the API: qemu_channel_writev_full() doesn't modify the fd, let's qio_channel_readv_full() not doing so too. So, this commit moves qemu_socket_set_block() calls from qio_channel_readv_full() to callers, mostly with help of qemu_fds_set_blocking() function. Let's look through all the users of qio_channel_readv_full(): 1. Some callers just pass NULLs as fds / nfds, nothing to do here: - qio_channel_readv() - qio_channel_read() - migration_channel_read_peek() 2. Some final users of the API, to be updated: Add call to qemu_fds_set_blocking(): - qemu_fill_buffer() in migration/qemu-file.c - test_io_channel_unix_fd_pass() in test-io-channel-socket.c - vu_message_read() in vhost-user-server.c - tcp_chr_recv() in chardev/char-socket.c - vfio_user_recv_one() in vfio-user/proxy.c Uses only one fd, so add call to qemu_socket_set_block(): - prh_read() in qemu-pr-helper.c - tpm_emu_ctrl_thread() in qtest/tpm-emu.c 3. An API wrapper, which has own users: qio_channel_readv_full_all_eof(), called from: - multifd_recv_thread() (migration/multifd.c)- with NULLs - qio_channel_readv_full_all() - wrapper, called from: - qio_channel_readv_all() - wrapper, with NULLs - backend_read() (virtio/vhost-user.c): use only one fd, add call to qemu_socket_set_block() - qio_channel_readv_all_eof() - wrapper, with NULLs - mpqemu_read(), static (in hw/remote/mpqemu-link.c), called from: - mpqemu_msg_recv(): add call to qemu_fds_set_blocking() Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- chardev/char-socket.c | 8 ++++++++ hw/remote/mpqemu-link.c | 3 +++ hw/vfio-user/proxy.c | 4 ++++ hw/virtio/vhost-user.c | 5 +++++ include/io/channel.h | 12 +++++++----- io/channel-socket.c | 4 ---- migration/qemu-file.c | 6 ++++++ scsi/qemu-pr-helper.c | 4 ++++ tests/qtest/tpm-emu.c | 1 + tests/unit/test-io-channel-socket.c | 1 + util/vhost-user-server.c | 5 +++++ 11 files changed, 44 insertions(+), 9 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 5b9b19ba8b..89d199b426 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -305,6 +305,14 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf, s= ize_t len) =20 assert(ret >=3D 0); =20 + if (!qemu_fds_set_blockinging(msgfds, msgfds_num, true, NULL)) { + for (i =3D 0; i < msgfds_num; i++) { + close(msgfds[i]); + } + errno =3D EINVAL; + return -1; + } + if (msgfds_num) { /* close and clean read_msgfds */ for (i =3D 0; i < s->read_msgfds_num; i++) { diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c index 49885a1db6..d5716ff92f 100644 --- a/hw/remote/mpqemu-link.c +++ b/hw/remote/mpqemu-link.c @@ -162,6 +162,9 @@ copy_fds: goto fail; } if (nfds) { + if (!qemu_fds_set_blockinging(fds, nfds, true, errp)) { + goto fail; + } memcpy(msg->fds, fds, nfds * sizeof(int)); } =20 diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index 2275d3fe39..55efa7fd77 100644 --- a/hw/vfio-user/proxy.c +++ b/hw/vfio-user/proxy.c @@ -300,6 +300,10 @@ static int vfio_user_recv_one(VFIOUserProxy *proxy, Er= ror **errp) trace_vfio_user_recv_hdr(proxy->sockname, hdr.id, hdr.command, hdr.siz= e, hdr.flags); =20 + if (!qemu_fds_set_blockinging(fdp, numfds, true, errp)) { + goto err; + } + /* * For replies, find the matching pending request. * For requests, reap incoming FDs. diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 36c9c2e04d..badd9d7851 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1801,6 +1801,11 @@ static gboolean backend_read(QIOChannel *ioc, GIOCon= dition condition, goto err; } =20 + if (fd && !qemu_set_blocking(fd[0], true, &local_err)) { + error_report_err(local_err); + goto err; + } + if (hdr.size > VHOST_USER_PAYLOAD_SIZE) { error_report("Failed to read msg header." " Size %d exceeds the maximum %zu.", hdr.size, diff --git a/include/io/channel.h b/include/io/channel.h index b848d50b99..40823c1728 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -119,9 +119,10 @@ struct QIOChannelClass { Error **errp); =20 /* - * The io_readv handler must guarantee that all - * incoming fds are set BLOCKING and CLOEXEC (if - * available). + * The io_readv handler must set all incoming fds + * CLOEXEC, and must NOT modify fds in any other + * way (for example, must not change its BLOCKING + * status) */ ssize_t (*io_readv)(QIOChannel *ioc, const struct iovec *iov, @@ -242,8 +243,9 @@ 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. * qio_channel_readv_full() guarantees that all - * incoming fds are set BLOCKING and CLOEXEC (if - * available). + * incoming fds are set CLOEXEC (if available). + * qio_channel_readv_full() doesn't modify BLOCKING + * state of fds. * * It is an error to pass a non-NULL @fds parameter * unless qio_channel_has_feature() returns a true diff --git a/io/channel-socket.c b/io/channel-socket.c index 96098b5bcc..b87a1f3e38 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -494,10 +494,6 @@ static void qio_channel_socket_copy_fds(struct msghdr = *msg, *fds =3D g_renew(int, *fds, *nfds + gotfds); memcpy(*fds + *nfds, CMSG_DATA(cmsg), fd_size); =20 - /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ - /* TODO: don't crash on error, just handle it! */ - qemu_fds_set_blockinging(*fds + *nfds, gotfds, true, &error_abort); - #ifndef MSG_CMSG_CLOEXEC for (i =3D 0; i < gotfds; i++) { int fd =3D (*fds)[*nfds + i]; diff --git a/migration/qemu-file.c b/migration/qemu-file.c index b6ac190034..b1d042e298 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -361,6 +361,12 @@ static ssize_t coroutine_mixed_fn qemu_fill_buffer(QEM= UFile *f) qemu_file_set_error_obj(f, len, local_error); } =20 + /* + * NOTE: don't worry about error_abort, it will be removed + * in the next commit + */ + qemu_fds_set_blockinging(fds, nfd, true, &error_abort); + for (int i =3D 0; i < nfd; i++) { FdEntry *fde =3D g_new0(FdEntry, 1); fde->fd =3D fds[i]; diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index b69dd982d6..8ca817f187 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -620,6 +620,10 @@ static int coroutine_fn prh_read(PRHelperClient *clien= t, void *buf, int sz, goto err; } =20 + if (!qemu_fds_set_blockinging(fds, nfds, true, errp)) { + goto err; + } + /* Stash one file descriptor per request. */ if (nfds) { bool too_many =3D false; diff --git a/tests/qtest/tpm-emu.c b/tests/qtest/tpm-emu.c index 9e4c2005d0..6ef30ac6b8 100644 --- a/tests/qtest/tpm-emu.c +++ b/tests/qtest/tpm-emu.c @@ -119,6 +119,7 @@ void *tpm_emu_ctrl_thread(void *data) cmd =3D be32_to_cpu(cmd); g_assert_cmpint(cmd, =3D=3D, CMD_SET_DATAFD); g_assert_cmpint(nfd, =3D=3D, 1); + qemu_set_blocking(*pfd, true, &error_abort); s->tpm_ioc =3D QIO_CHANNEL(qio_channel_socket_new_fd(*pfd, &error_= abort)); g_free(pfd); =20 diff --git a/tests/unit/test-io-channel-socket.c b/tests/unit/test-io-chann= el-socket.c index dc7be96e9c..815ee1d812 100644 --- a/tests/unit/test-io-channel-socket.c +++ b/tests/unit/test-io-channel-socket.c @@ -464,6 +464,7 @@ static void test_io_channel_unix_fd_pass(void) &error_abort); =20 g_assert(nfdrecv =3D=3D G_N_ELEMENTS(fdsend)); + qemu_fds_set_blockinging(fdrecv, nfdrecv, true, &error_abort); /* Each recvd FD should be different from sent FD */ for (i =3D 0; i < nfdrecv; i++) { g_assert_cmpint(fdrecv[i], !=3D, testfd); diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 8dcd32dc65..a2ae318ea3 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -161,6 +161,11 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserM= sg *vmsg) g_free(fds); goto fail; } + if (!qemu_fds_set_blockinging(fds, nfds, true, &local_err)) { + error_report_err(local_err); + g_free(fds); + goto fail; + } memcpy(vmsg->fds + vmsg->fd_num, fds, nfds * sizeof(vmsg->fds[= 0])); vmsg->fd_num +=3D nfds; g_free(fds); --=20 2.48.1 From nobody Sat Sep 6 14:41:20 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1756892792; cv=none; d=zohomail.com; s=zohoarc; b=a4SxleU34ztLvYto/DcYoVwlMcDWdcAnoi8dgW4dM4HK+vCyaFtAbasGPoQXXHgOhJ6+nI8WUeDCcMdeNkYNseXwNPoHXYZNTQzhaKSyPk9qaPqLTr3m0JA/SU7mJe0yVxWCw4JCseuvaqXxqyx4OrgagMHEDpHw8+3G4kQHpmo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756892792; h=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=rpWIJmcNN5lupFdb4weg79+iSwld3z32WBQckX84HH0=; b=EONIjzXHtadhqQI8s6FFZWLM2YWa3+7S37JFBIw9vOvfbisCeXBCWMS5H16G7SbWTGn35iKJMHCkEGMwmxF8FIorpU2kQc4vXJVWzxOwRlxJsYoNnoCeVjqN/yRtPzpD4oAcgf5wT/TDT67gWuykSrsS5Q0tkLS4OIpw542sUgQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756892792902458.0494272237802; Wed, 3 Sep 2025 02:46:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utk2Z-000698-In; Wed, 03 Sep 2025 05:44: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 1utk2V-00067F-Qr; Wed, 03 Sep 2025 05:44:27 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1utk2U-0007ww-AG; Wed, 03 Sep 2025 05:44:27 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 9DDE78078F; Wed, 03 Sep 2025 12:44:24 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id EicMoq3GhCg0-pbBdHC6g; Wed, 03 Sep 2025 12:44:24 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1756892664; bh=rpWIJmcNN5lupFdb4weg79+iSwld3z32WBQckX84HH0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=W1qer5mvyh2vyNqBPyb1fFDrnv4Y+ZmQijVPWbsovY3Fgd8MW9QZ048xPrZCnUFI0 /FGwDF8c/zbttm6PNASFLLloTLw5lXcEdZMbdodxcfxD30qwS9qgSgafWctlwkneNq 3eCGs72DrRo7qjB++5xhTSkiyvxvwjh95AusmGnI= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: berrange@redhat.com Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, peterx@redhat.com, vsementsov@yandex-team.ru, Fabiano Rosas Subject: [PATCH 10/10] migration/qemu-file: don't make incoming fds blocking again Date: Wed, 3 Sep 2025 12:44:10 +0300 Message-ID: <20250903094411.1029449-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250903094411.1029449-1-vsementsov@yandex-team.ru> References: <20250903094411.1029449-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1756892795261116600 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- migration/qemu-file.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index b1d042e298..b6ac190034 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -361,12 +361,6 @@ static ssize_t coroutine_mixed_fn qemu_fill_buffer(QEM= UFile *f) qemu_file_set_error_obj(f, len, local_error); } =20 - /* - * NOTE: don't worry about error_abort, it will be removed - * in the next commit - */ - qemu_fds_set_blockinging(fds, nfd, true, &error_abort); - for (int i =3D 0; i < nfd; i++) { FdEntry *fde =3D g_new0(FdEntry, 1); fde->fd =3D fds[i]; --=20 2.48.1