From nobody Tue Feb 10 06:58:14 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651612770; cv=none; d=zohomail.com; s=zohoarc; b=jWgO+x24zFfO8cg0eHauIFxATV63rMe6j0o1DHHeXIg6HxUV9y6OA4X5UhHJMelBIlc9VhEVkxw0TYT5RGKIJu4gaGnkFg/Ml4SIGKlqQ2Pw56bhWwGIQUtLFhrBTz6vCvX5EmHI2u3NagGkQ0Bu72QU3xdF75NS9JOh+TT0ia4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651612770; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vGAsPEx3J2jPmQD3Acyc8kZGSS2G4k65JexyADFPDzg=; b=MAV0TESMdQX5Duwgi7EfUXMB9b7rloPKNzagytmvZU9QI3gw9AY1JUrjIiXkAzyOhd+T6X5g1Ud+neZBveMGHqNQWrNDDCdD6XtTnfYl9DvYKUYtmU10kVhcTP+X6ZkR3ZOZglo6MBxrUENQEoognVYfvGTR50l/wTAtgR8WFHU= 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 1651612770428447.4588774867825; Tue, 3 May 2022 14:19:30 -0700 (PDT) Received: from localhost ([::1]:54782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzvc-0006XI-Vm for importer@patchew.org; Tue, 03 May 2022 17:19:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44056) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyqd-0002jb-2i for qemu-devel@nongnu.org; Tue, 03 May 2022 16:10:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:60861) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyqb-0002Sb-6e for qemu-devel@nongnu.org; Tue, 03 May 2022 16:10:14 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-627-OxjJIOG0OQ6ZQ8FLs4JZiw-1; Tue, 03 May 2022 11:36:36 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 664063CF16FE; Tue, 3 May 2022 13:01:46 +0000 (UTC) Received: from localhost (unknown [10.39.208.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C21E153AD3A; Tue, 3 May 2022 13:01:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651608612; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vGAsPEx3J2jPmQD3Acyc8kZGSS2G4k65JexyADFPDzg=; b=SvK5tZ/G9u5eQUqFE5QmciIbh/A4U8FjHzjFARNwcrtTYScl9Z5fUHIYwBDz3cKGtrhiD/ 3GlUsgzPEqUZEWWgNK1n1mrfHNsCYZDPwfgBgghOO4P4UdaA7FmuARLlBINL8Rl1pKwRca UYtZZP0RtOkXIFEuetOvDZJgsEF3EkA= X-MC-Unique: OxjJIOG0OQ6ZQ8FLs4JZiw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Peter Maydell , Richard Henderson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 14/23] Replace fcntl(O_NONBLOCK) with g_unix_set_fd_nonblocking() Date: Tue, 3 May 2022 17:00:14 +0400 Message-Id: <20220503130023.180544-15-marcandre.lureau@redhat.com> In-Reply-To: <20220503130023.180544-1-marcandre.lureau@redhat.com> References: <20220503130023.180544-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651612772057100001 From: Marc-Andr=C3=A9 Lureau Suggested-by: Daniel P. Berrang=C3=A9 Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Richard Henderson --- net/tap-bsd.c | 4 ++-- net/tap-linux.c | 2 +- net/tap-solaris.c | 2 +- tests/qtest/fuzz/virtio_net_fuzz.c | 2 +- tests/unit/test-iov.c | 4 ++-- util/oslib-posix.c | 16 ++-------------- 6 files changed, 9 insertions(+), 21 deletions(-) diff --git a/net/tap-bsd.c b/net/tap-bsd.c index 7e65bd391f0b..005ce05c6e07 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -98,7 +98,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, return -1; } } - fcntl(fd, F_SETFL, O_NONBLOCK); + g_unix_set_fd_nonblocking(fd, true, NULL); return fd; } =20 @@ -189,7 +189,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_h= dr, goto error; } =20 - fcntl(fd, F_SETFL, O_NONBLOCK); + g_unix_set_fd_nonblocking(fd, true, NULL); return fd; =20 error: diff --git a/net/tap-linux.c b/net/tap-linux.c index 3e24d232e782..304ff45071dd 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -113,7 +113,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_h= dr, return -1; } pstrcpy(ifname, ifname_size, ifr.ifr_name); - fcntl(fd, F_SETFL, O_NONBLOCK); + g_unix_set_fd_nonblocking(fd, true, NULL); return fd; } =20 diff --git a/net/tap-solaris.c b/net/tap-solaris.c index 79919785c9f6..a44f8805c23e 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -198,7 +198,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_h= dr, return -1; } } - fcntl(fd, F_SETFL, O_NONBLOCK); + g_unix_set_fd_nonblocking(fd, true, NULL); return fd; } =20 diff --git a/tests/qtest/fuzz/virtio_net_fuzz.c b/tests/qtest/fuzz/virtio_n= et_fuzz.c index 3df78d9c1c2a..c2c15f07f062 100644 --- a/tests/qtest/fuzz/virtio_net_fuzz.c +++ b/tests/qtest/fuzz/virtio_net_fuzz.c @@ -151,7 +151,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); - fcntl(sockfds[0], F_SETFL, O_NONBLOCK); + g_unix_set_fd_nonblocking(sockfds[0], true, NULL); sockfds_initialized =3D true; g_string_append_printf(cmd_line, " -netdev socket,fd=3D%d,id=3Dhs0 ", sockfds[1]); diff --git a/tests/unit/test-iov.c b/tests/unit/test-iov.c index 0d2ba9ba87d9..93bda00f0e10 100644 --- a/tests/unit/test-iov.c +++ b/tests/unit/test-iov.c @@ -186,7 +186,7 @@ static void test_io(void) =20 close(sv[0]); FD_SET(sv[1], &fds); - fcntl(sv[1], F_SETFL, O_RDWR|O_NONBLOCK); + g_unix_set_fd_nonblocking(sv[1], true, NULL); r =3D g_test_rand_int_range(sz / 2, sz); setsockopt(sv[1], SOL_SOCKET, SO_SNDBUF, &r, sizeof(r)); =20 @@ -220,7 +220,7 @@ static void test_io(void) =20 close(sv[1]); FD_SET(sv[0], &fds); - fcntl(sv[0], F_SETFL, O_RDWR|O_NONBLOCK); + g_unix_set_fd_nonblocking(sv[0], true, NULL); 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/util/oslib-posix.c b/util/oslib-posix.c index 2a6f6248ad03..72f25e599dba 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -226,24 +226,12 @@ void qemu_anon_ram_free(void *ptr, size_t size) =20 void qemu_set_block(int fd) { - int f; - f =3D fcntl(fd, F_GETFL); - assert(f !=3D -1); - f =3D fcntl(fd, F_SETFL, f & ~O_NONBLOCK); - assert(f !=3D -1); + g_unix_set_fd_nonblocking(fd, false, NULL); } =20 int qemu_try_set_nonblock(int fd) { - int f; - f =3D fcntl(fd, F_GETFL); - if (f =3D=3D -1) { - return -errno; - } - if (fcntl(fd, F_SETFL, f | O_NONBLOCK) =3D=3D -1) { - return -errno; - } - return 0; + return g_unix_set_fd_nonblocking(fd, true, NULL) ? 0 : -errno; } =20 void qemu_set_nonblock(int fd) --=20 2.36.0.44.g0f828332d5ac