From nobody Sat May 18 10:48:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=cloudlinux.com ARC-Seal: i=1; a=rsa-sha256; t=1666589904; cv=none; d=zohomail.com; s=zohoarc; b=NtZYhmwWh1GhUvN21G6zNB+7JT8BantDBhEimmsL/RrIBjf7E9nDPameYXDWT6TaZIeiZ2Tes4X+4pO+t/Y/6eheUzXpgoNdvsnooKqAQvBHVlxF2J1QXO0s+RlQCrVFAwUNXWxrguKAgNluel9SU4c++IcQM6ixb7WJIOzjjo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666589904; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9lVu6m7ds6lIjW35SYKVsoRoC2ayjigTDLfVvXIWLc0=; b=XUSRdurfEkf/9iLgICC0E7oZC59J26UygOq0p2tvG0Q1i7Zcsvg7+Ec8A7O7qT0cb76VmWveQov1jr7PDXteWJIUG06GeD4sjkT8UwWqeKCl9aQgl/dDRhjTsuRDTR7a//6zy4jk7eHTrUImldKIg3dtLPTXPpsSzB29UCUNQKc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666589904785903.5878754055148; Sun, 23 Oct 2022 22:38:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1omlIn-0001Zh-7N for importer@patchew.org; Sun, 23 Oct 2022 20:26:49 -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 1omWuM-0007Ci-Sm for qemu-devel@nongnu.org; Sun, 23 Oct 2022 05:04:38 -0400 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1omWuK-0001Qj-Tq for qemu-devel@nongnu.org; Sun, 23 Oct 2022 05:04:38 -0400 Received: by mail-lj1-x236.google.com with SMTP id j14so9180258ljh.12 for ; Sun, 23 Oct 2022 02:04:36 -0700 (PDT) Received: from fedora.cloudlinux.com ([85.143.112.90]) by smtp.gmail.com with ESMTPSA id c27-20020a056512239b00b0049908e21e26sm3938101lfv.253.2022.10.23.02.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 02:04:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudlinux.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9lVu6m7ds6lIjW35SYKVsoRoC2ayjigTDLfVvXIWLc0=; b=UMljknfqxXZH+1ZnFeaJDQnFto1pQCKZzXc9ycLy/Cg52AJ5o2gGZoMaIS/33XxJah mooneJCcp4IiL+5TuqfHmIe29CzRwFa1xV05QwKVYpD5PjhZxK00JNubOe00vLCA5Dpo ITSY+IuOoWjgp7tl4htERiOTe0HvMUDvKNrXNBSGJJLxcUn3lW2o11AIvSBfxUFyHfug E9/kGGlU6vtCSsDUNZwMEQizEy3iaCB5ABoo+fWIXz5MrtPvk+igFR7L2XfjSs6tcA2r k1ltyJuiuidTwA0ny4dhoMo9SHyXd9mKqrVLwxJjged8w177e8FnwxUiEYpIBf1TIGNE ir0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9lVu6m7ds6lIjW35SYKVsoRoC2ayjigTDLfVvXIWLc0=; b=sfhuZPLJ2sq8lWKNOwx7dLpCUD9XP3svYG65p2tETtCOfayh5CoSCo0KfHA5FJ+RPZ AOHr8vc844YYVAiTvn8LgcDrxdi6bWFrU+SxbRikmyxqG0Xxz+wTMl6lflFron32AKPa bd7m2fCMjCvgW9TELjAbKrYCEx6DniNgXE6ucazwXoN7RaGcyojOJ0rCTHLBAGrH7YYD mS/q9jfeEW73DpL+JpxTwAWz7ZQ92G++2PWySnUliYHTLHAtjyXDyQE/eamc+PyQBTty zhoU1fTokNcDBJeNRwe4auUMUqXrxhEVMbK9fQ4bv1Xhd0S9nO9+54xo0wP3HCdvDFw/ zFzQ== X-Gm-Message-State: ACrzQf0ke3ccJnwbHZqMFFO+MQVFZhqGj/moONewRJP9QjfHLxSRv0Aa fs0sHIJYMoHTGCqnP+aOfFOeXUR3xGe0KA== X-Google-Smtp-Source: AMsMyM7QOZn5FUyX6nRpUTmq4xVS+4N9rgZJsOASA5mZYpP5aG0vq0m2H0Pzz6+wHh8nUOYS8WjVMw== X-Received: by 2002:a2e:8183:0:b0:26e:823d:d51a with SMTP id e3-20020a2e8183000000b0026e823dd51amr9806854ljg.472.1666515874975; Sun, 23 Oct 2022 02:04:34 -0700 (PDT) From: Nikita Ivanov To: qemu-devel@nongnu.org Cc: Nikita Ivanov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Jason Wang , Thomas Huth , Laurent Vivier Subject: [PATCH v4 1/2] Refactoring: refactor TFR() macro to RETRY_ON_EINTR() Date: Sun, 23 Oct 2022 12:04:21 +0300 Message-Id: <20221023090422.242617-2-nivanov@cloudlinux.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221023090422.242617-1-nivanov@cloudlinux.com> References: <20221023090422.242617-1-nivanov@cloudlinux.com> 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=2a00:1450:4864:20::236; envelope-from=nivanov@cloudlinux.com; helo=mail-lj1-x236.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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" X-ZohoMail-DKIM: pass (identity @cloudlinux.com) X-ZM-MESSAGEID: 1666589906883100001 Content-Type: text/plain; charset="utf-8" Rename macro name to more transparent one and refactor it to expression. Signed-off-by: Nikita Ivanov --- chardev/char-fd.c | 2 +- chardev/char-pipe.c | 8 +++++--- include/qemu/osdep.h | 8 +++++++- net/tap-bsd.c | 6 +++--- net/tap-linux.c | 2 +- net/tap-solaris.c | 8 ++++---- net/tap.c | 2 +- os-posix.c | 2 +- tests/qtest/libqtest.c | 2 +- 9 files changed, 24 insertions(+), 16 deletions(-) diff --git a/chardev/char-fd.c b/chardev/char-fd.c index cf78454841..d2c4923359 100644 --- a/chardev/char-fd.c +++ b/chardev/char-fd.c @@ -198,7 +198,7 @@ int qmp_chardev_open_file_source(char *src, int flags, = Error **errp) { int fd =3D -1; =20 - TFR(fd =3D qemu_open_old(src, flags, 0666)); + fd =3D RETRY_ON_EINTR(qemu_open_old(src, flags, 0666)); if (fd =3D=3D -1) { error_setg_file_open(errp, errno, src); } diff --git a/chardev/char-pipe.c b/chardev/char-pipe.c index 66d3b85091..5ad30bcc59 100644 --- a/chardev/char-pipe.c +++ b/chardev/char-pipe.c @@ -131,8 +131,8 @@ static void qemu_chr_open_pipe(Chardev *chr, =20 filename_in =3D g_strdup_printf("%s.in", filename); filename_out =3D g_strdup_printf("%s.out", filename); - TFR(fd_in =3D qemu_open_old(filename_in, O_RDWR | O_BINARY)); - TFR(fd_out =3D qemu_open_old(filename_out, O_RDWR | O_BINARY)); + fd_in =3D RETRY_ON_EINTR(qemu_open_old(filename_in, O_RDWR | O_BINARY)= ); + fd_out =3D RETRY_ON_EINTR(qemu_open_old(filename_out, O_RDWR | O_BINAR= Y)); g_free(filename_in); g_free(filename_out); if (fd_in < 0 || fd_out < 0) { @@ -142,7 +142,9 @@ static void qemu_chr_open_pipe(Chardev *chr, if (fd_out >=3D 0) { close(fd_out); } - TFR(fd_in =3D fd_out =3D qemu_open_old(filename, O_RDWR | O_BINARY= )); + fd_in =3D fd_out =3D RETRY_ON_EINTR( + qemu_open_old(filename, O_RDWR | O_BINARY) + ); if (fd_in < 0) { error_setg_file_open(errp, errno, filename); return; diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index b1c161c035..25c35b9a0e 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -243,7 +243,13 @@ void QEMU_ERROR("code path is reachable") #define ESHUTDOWN 4099 #endif =20 -#define TFR(expr) do { if ((expr) !=3D -1) break; } while (errno =3D=3D EI= NTR) +#define RETRY_ON_EINTR(expr) \ + (__extension__ \ + ({ typeof(expr) __result; \ + do { \ + __result =3D (expr); \ + } while (__result =3D=3D -1 && errno =3D=3D EINTR); \ + __result; })) =20 /* time_t may be either 32 or 64 bits depending on the host OS, and * can be either signed or unsigned, so we can't just hardcode a diff --git a/net/tap-bsd.c b/net/tap-bsd.c index 005ce05c6e..4c98fdd337 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -56,7 +56,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, } else { snprintf(dname, sizeof dname, "/dev/tap%d", i); } - TFR(fd =3D open(dname, O_RDWR)); + fd =3D RETRY_ON_EINTR(open(dname, O_RDWR)); if (fd >=3D 0) { break; } @@ -111,7 +111,7 @@ static int tap_open_clone(char *ifname, int ifname_size= , Error **errp) int fd, s, ret; struct ifreq ifr; =20 - TFR(fd =3D open(PATH_NET_TAP, O_RDWR)); + fd =3D RETRY_ON_EINTR(open(PATH_NET_TAP, O_RDWR)); if (fd < 0) { error_setg_errno(errp, errno, "could not open %s", PATH_NET_TAP); return -1; @@ -159,7 +159,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_h= dr, if (ifname[0] !=3D '\0') { char dname[100]; snprintf(dname, sizeof dname, "/dev/%s", ifname); - TFR(fd =3D open(dname, O_RDWR)); + fd =3D RETRY_ON_EINTR(open(dname, O_RDWR)); if (fd < 0 && errno !=3D ENOENT) { error_setg_errno(errp, errno, "could not open %s", dname); return -1; diff --git a/net/tap-linux.c b/net/tap-linux.c index 304ff45071..f54f308d35 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -45,7 +45,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int len =3D sizeof(struct virtio_net_hdr); unsigned int features; =20 - TFR(fd =3D open(PATH_NET_TUN, O_RDWR)); + fd =3D RETRY_ON_EINTR(open(PATH_NET_TUN, O_RDWR)); if (fd < 0) { error_setg_errno(errp, errno, "could not open %s", PATH_NET_TUN); return -1; diff --git a/net/tap-solaris.c b/net/tap-solaris.c index a44f8805c2..38e15028bf 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -84,13 +84,13 @@ static int tap_alloc(char *dev, size_t dev_size, Error = **errp) if( ip_fd ) close(ip_fd); =20 - TFR(ip_fd =3D open("/dev/udp", O_RDWR, 0)); + ip_fd =3D RETRY_ON_EINTR(open("/dev/udp", O_RDWR, 0)); if (ip_fd < 0) { error_setg(errp, "Can't open /dev/ip (actually /dev/udp)"); return -1; } =20 - TFR(tap_fd =3D open("/dev/tap", O_RDWR, 0)); + tap_fd =3D RETRY_ON_EINTR(open("/dev/tap", O_RDWR, 0)); if (tap_fd < 0) { error_setg(errp, "Can't open /dev/tap"); return -1; @@ -104,7 +104,7 @@ static int tap_alloc(char *dev, size_t dev_size, Error = **errp) if ((ppa =3D ioctl (tap_fd, I_STR, &strioc_ppa)) < 0) error_report("Can't assign new interface"); =20 - TFR(if_fd =3D open("/dev/tap", O_RDWR, 0)); + if_fd =3D RETRY_ON_EINTR(open("/dev/tap", O_RDWR, 0)); if (if_fd < 0) { error_setg(errp, "Can't open /dev/tap (2)"); return -1; @@ -137,7 +137,7 @@ static int tap_alloc(char *dev, size_t dev_size, Error = **errp) if (ioctl (ip_fd, I_PUSH, "arp") < 0) error_report("Can't push ARP module (3)"); /* Open arp_fd */ - TFR(arp_fd =3D open ("/dev/tap", O_RDWR, 0)); + arp_fd =3D RETRY_ON_EINTR(open("/dev/tap", O_RDWR, 0)); if (arp_fd < 0) error_report("Can't open %s", "/dev/tap"); =20 diff --git a/net/tap.c b/net/tap.c index e203d07a12..e090d14203 100644 --- a/net/tap.c +++ b/net/tap.c @@ -651,7 +651,7 @@ static int net_tap_init(const NetdevTapOptions *tap, in= t *vnet_hdr, vnet_hdr_required =3D 0; } =20 - TFR(fd =3D tap_open(ifname, ifname_sz, vnet_hdr, vnet_hdr_required, + fd =3D RETRY_ON_EINTR(tap_open(ifname, ifname_sz, vnet_hdr, vnet_hdr_r= equired, mq_required, errp)); if (fd < 0) { return -1; diff --git a/os-posix.c b/os-posix.c index 321fc4bd13..bb27f67bac 100644 --- a/os-posix.c +++ b/os-posix.c @@ -266,7 +266,7 @@ void os_setup_post(void) error_report("not able to chdir to /: %s", strerror(errno)); exit(1); } - TFR(fd =3D qemu_open_old("/dev/null", O_RDWR)); + fd =3D RETRY_ON_EINTR(qemu_open_old("/dev/null", O_RDWR)); if (fd =3D=3D -1) { exit(1); } diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index b23eb3edc3..90648eb8d1 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -140,7 +140,7 @@ void qtest_kill_qemu(QTestState *s) /* Skip wait if qtest_probe_child already reaped. */ if (pid !=3D -1) { kill(pid, SIGTERM); - TFR(pid =3D waitpid(s->qemu_pid, &s->wstatus, 0)); + pid =3D RETRY_ON_EINTR(waitpid(s->qemu_pid, &s->wstatus, 0)); assert(pid =3D=3D s->qemu_pid); s->qemu_pid =3D -1; } --=20 2.37.3 From nobody Sat May 18 10:48:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=cloudlinux.com ARC-Seal: i=1; a=rsa-sha256; t=1666591215; cv=none; d=zohomail.com; s=zohoarc; b=ljamZrXErkxjNLNhkq5UUIQtAsnHI78oEpi+Y6yblnXVMHKGhkVDNt7ZlqiIir41fL7Z11xgiDBSbBdbg0p93a9i2rwJedl9h5DdsdFzob+gF0xe8VAxIHsGhi6ZkaLxqzvYOFOVIJUuhM9cSyNnq1xWCQiWOjwxS5CPDKYIVRg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666591215; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eRdI2CeCntg4JWFWr7yx+Vx+BbYSV6E3sbpsJk5kRNc=; b=kk8MbyRi9xHD5u5KX5A561Hd0CTrWTkDHy+o/eZAWzTsYwIyHf13OqHUP/JMrb+ZABX4iMEwSREMDLoDjkcwZcKTtXtXkIat2f4/Sw5UF6KCPCaAB2fLjgRbv9dVfRjpM5iEQX/zgp/ym0VymMMjh4PBnSvT6NUuP2G2DgY++Ro= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666591215043461.8063006198495; Sun, 23 Oct 2022 23:00:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1omlKM-0002F6-3G for importer@patchew.org; Sun, 23 Oct 2022 20:28:26 -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 1omWuP-0007D4-5h for qemu-devel@nongnu.org; Sun, 23 Oct 2022 05:04:41 -0400 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1omWuM-0001R7-Qw for qemu-devel@nongnu.org; Sun, 23 Oct 2022 05:04:40 -0400 Received: by mail-lj1-x229.google.com with SMTP id a15so4523440ljb.7 for ; Sun, 23 Oct 2022 02:04:38 -0700 (PDT) Received: from fedora.cloudlinux.com ([85.143.112.90]) by smtp.gmail.com with ESMTPSA id c27-20020a056512239b00b0049908e21e26sm3938101lfv.253.2022.10.23.02.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 02:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudlinux.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eRdI2CeCntg4JWFWr7yx+Vx+BbYSV6E3sbpsJk5kRNc=; b=UTsBVAArw0IHl7hzUPO+Q8QatoJ63RMlHNnEks4y58hXirhL6P8vlnOFf9fi2KeH5p funK2cGGTmuVpXEuIxD+UItjOYf9VvFU7bKsXD+FmaNInuf+agt0v5mUDGwokZqqnaKc yMuSJgkLL6VFPluxBQ3R/wUyML5j1YH2e5cbfC7NG30jhK2pFwmGnY3G72FegIRmlnYQ rrUyR5FMktatqgi0ukodiOdE/WEVAwEHNl57gS6hjYGauxrZIn5+NekPNVtXY2szbNsR J+AWI0gL8e6kOFmPG/ldSonyPku0wXkFvCr3D81BzQW/T+a00AgiUx3n+zvsRjqHSnc+ Tj8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eRdI2CeCntg4JWFWr7yx+Vx+BbYSV6E3sbpsJk5kRNc=; b=EO8xhX+9x2OuWlXmJhA6M86a3X8GCLCjdW1oY6Mqp+9xvfUUBgVJmgZ3c1C02ugKWH 8gVh7DGBYVNa/eQP37ykeVPUkw0eswWLvO/ZDVhAF4xbmZxBAf7gSfYEw0m04FXlSD2a krbwJVTCMvC9nxUyYUpE19JvqY8tXJKsY2og20+HkQ0qUU79l6PmYuMr9ClN/Xqfo5D/ Ukd7c79asBVTXGoOfgMAlR3oS7rvW685UoW6h7Vi/oTkpIEQQVVUbHx1AnG+d6gX7rab vwkU0SeReyq4l+jb0FRWkS3yi+KcKHugIgntecDm48cuiQimr0ENNuwwaQ4gQ+jv0I7Q ZdYA== X-Gm-Message-State: ACrzQf10RzKx8c3vs7mOERmF8923JjPFlgklgbq5VXP71lrO1netH/Gl +8j8wiw0FWY1VyiS/gJAz/DT4GAnWRTwEeup X-Google-Smtp-Source: AMsMyM4wYS7MTyAThJSKrnfuRSB71SkQMkXa1hcPgL1mALGGnT5BTXhTICau/1nv13ZVUbFLzGlk6g== X-Received: by 2002:a2e:a278:0:b0:277:5e1:1091 with SMTP id k24-20020a2ea278000000b0027705e11091mr931762ljm.314.1666515876816; Sun, 23 Oct 2022 02:04:36 -0700 (PDT) From: Nikita Ivanov To: qemu-devel@nongnu.org Cc: Nikita Ivanov , Kevin Wolf , Hanna Reitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Greg Kurz , Christian Schoenebeck , Jason Wang , Michael Roth , Konstantin Kostiuk , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , Laurent Vivier , qemu-block@nongnu.org (open list:raw) Subject: [PATCH v4 2/2] error handling: Use RETRY_ON_EINTR() macro where applicable Date: Sun, 23 Oct 2022 12:04:22 +0300 Message-Id: <20221023090422.242617-3-nivanov@cloudlinux.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221023090422.242617-1-nivanov@cloudlinux.com> References: <20221023090422.242617-1-nivanov@cloudlinux.com> 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=2a00:1450:4864:20::229; envelope-from=nivanov@cloudlinux.com; helo=mail-lj1-x229.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @cloudlinux.com) X-ZM-MESSAGEID: 1666591216501100001 Content-Type: text/plain; charset="utf-8" There is a defined RETRY_ON_EINTR() macro in qemu/osdep.h which handles the same while loop. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/415 Signed-off-by: Nikita Ivanov --- block/file-posix.c | 37 ++++++++++++++++--------------------- chardev/char-pty.c | 4 +--- hw/9pfs/9p-local.c | 8 ++------ net/l2tpv3.c | 17 +++++------------ net/socket.c | 16 +++++++--------- net/tap.c | 8 ++------ qga/commands-posix.c | 4 +--- semihosting/syscalls.c | 4 +--- tests/qtest/libqtest.c | 12 +++++------- tests/vhost-user-bridge.c | 4 +--- util/main-loop.c | 4 +--- util/osdep.c | 4 +--- util/vfio-helpers.c | 12 ++++++------ 13 files changed, 49 insertions(+), 85 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 23acffb9a4..8f7a22e3e4 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1229,9 +1229,7 @@ static int hdev_get_max_segments(int fd, struct stat = *st) ret =3D -errno; goto out; } - do { - ret =3D read(sysfd, buf, sizeof(buf) - 1); - } while (ret =3D=3D -1 && errno =3D=3D EINTR); + ret =3D RETRY_ON_EINTR(read(sysfd, buf, sizeof(buf) - 1)); if (ret < 0) { ret =3D -errno; goto out; @@ -1379,9 +1377,9 @@ static int handle_aiocb_ioctl(void *opaque) RawPosixAIOData *aiocb =3D opaque; int ret; =20 - do { - ret =3D ioctl(aiocb->aio_fildes, aiocb->ioctl.cmd, aiocb->ioctl.bu= f); - } while (ret =3D=3D -1 && errno =3D=3D EINTR); + ret =3D RETRY_ON_EINTR( + ioctl(aiocb->aio_fildes, aiocb->ioctl.cmd, aiocb->ioctl.buf) + ); if (ret =3D=3D -1) { return -errno; } @@ -1463,18 +1461,17 @@ static ssize_t handle_aiocb_rw_vector(RawPosixAIODa= ta *aiocb) { ssize_t len; =20 - do { - if (aiocb->aio_type & QEMU_AIO_WRITE) - len =3D qemu_pwritev(aiocb->aio_fildes, - aiocb->io.iov, - aiocb->io.niov, - aiocb->aio_offset); - else - len =3D qemu_preadv(aiocb->aio_fildes, - aiocb->io.iov, - aiocb->io.niov, - aiocb->aio_offset); - } while (len =3D=3D -1 && errno =3D=3D EINTR); + len =3D RETRY_ON_EINTR( + (aiocb->aio_type & QEMU_AIO_WRITE) ? + qemu_pwritev(aiocb->aio_fildes, + aiocb->io.iov, + aiocb->io.niov, + aiocb->aio_offset) : + qemu_preadv(aiocb->aio_fildes, + aiocb->io.iov, + aiocb->io.niov, + aiocb->aio_offset) + ); =20 if (len =3D=3D -1) { return -errno; @@ -1899,9 +1896,7 @@ static int allocate_first_block(int fd, size_t max_si= ze) buf =3D qemu_memalign(max_align, write_size); memset(buf, 0, write_size); =20 - do { - n =3D pwrite(fd, buf, write_size, 0); - } while (n =3D=3D -1 && errno =3D=3D EINTR); + n =3D RETRY_ON_EINTR(pwrite(fd, buf, write_size, 0)); =20 ret =3D (n =3D=3D -1) ? -errno : 0; =20 diff --git a/chardev/char-pty.c b/chardev/char-pty.c index 53f25c6bbd..92fd33c854 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -93,9 +93,7 @@ static void pty_chr_update_read_handler(Chardev *chr) pfd.fd =3D fioc->fd; pfd.events =3D G_IO_OUT; pfd.revents =3D 0; - do { - rc =3D g_poll(&pfd, 1, 0); - } while (rc =3D=3D -1 && errno =3D=3D EINTR); + rc =3D RETRY_ON_EINTR(g_poll(&pfd, 1, 0)); assert(rc >=3D 0); =20 if (pfd.revents & G_IO_HUP) { diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index d42ce6d8b8..bb3187244f 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -470,9 +470,7 @@ static ssize_t local_readlink(FsContext *fs_ctx, V9fsPa= th *fs_path, if (fd =3D=3D -1) { return -1; } - do { - tsize =3D read(fd, (void *)buf, bufsz); - } while (tsize =3D=3D -1 && errno =3D=3D EINTR); + tsize =3D RETRY_ON_EINTR(read(fd, (void *)buf, bufsz)); close_preserve_errno(fd); } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) || (fs_ctx->export_flags & V9FS_SM_NONE)) { @@ -908,9 +906,7 @@ static int local_symlink(FsContext *fs_ctx, const char = *oldpath, } /* Write the oldpath (target) to the file. */ oldpath_size =3D strlen(oldpath); - do { - write_size =3D write(fd, (void *)oldpath, oldpath_size); - } while (write_size =3D=3D -1 && errno =3D=3D EINTR); + write_size =3D RETRY_ON_EINTR(write(fd, (void *)oldpath, oldpath_s= ize)); close_preserve_errno(fd); =20 if (write_size !=3D oldpath_size) { diff --git a/net/l2tpv3.c b/net/l2tpv3.c index af373e5c30..e0726f5f89 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -240,9 +240,7 @@ static ssize_t net_l2tpv3_receive_dgram_iov(NetClientSt= ate *nc, message.msg_control =3D NULL; message.msg_controllen =3D 0; message.msg_flags =3D 0; - do { - ret =3D sendmsg(s->fd, &message, 0); - } while ((ret =3D=3D -1) && (errno =3D=3D EINTR)); + ret =3D RETRY_ON_EINTR(sendmsg(s->fd, &message, 0)); if (ret > 0) { ret -=3D s->offset; } else if (ret =3D=3D 0) { @@ -285,9 +283,7 @@ static ssize_t net_l2tpv3_receive_dgram(NetClientState = *nc, message.msg_control =3D NULL; message.msg_controllen =3D 0; message.msg_flags =3D 0; - do { - ret =3D sendmsg(s->fd, &message, 0); - } while ((ret =3D=3D -1) && (errno =3D=3D EINTR)); + ret =3D RETRY_ON_EINTR(sendmsg(s->fd, &message, 0)); if (ret > 0) { ret -=3D s->offset; } else if (ret =3D=3D 0) { @@ -434,12 +430,9 @@ static void net_l2tpv3_send(void *opaque) =20 msgvec =3D s->msgvec + s->queue_head; if (target_count > 0) { - do { - count =3D recvmmsg( - s->fd, - msgvec, - target_count, MSG_DONTWAIT, NULL); - } while ((count =3D=3D -1) && (errno =3D=3D EINTR)); + count =3D RETRY_ON_EINTR( + recvmmsg(s->fd, msgvec, target_count, MSG_DONTWAIT, NULL) + ); if (count < 0) { /* Recv error - we still need to flush packets here, * (re)set queue head to current position diff --git a/net/socket.c b/net/socket.c index bfd8596250..00f8a88531 100644 --- a/net/socket.c +++ b/net/socket.c @@ -117,15 +117,13 @@ static ssize_t net_socket_receive_dgram(NetClientStat= e *nc, const uint8_t *buf, NetSocketState *s =3D DO_UPCAST(NetSocketState, nc, nc); ssize_t ret; =20 - do { - if (s->dgram_dst.sin_family !=3D AF_UNIX) { - ret =3D sendto(s->fd, buf, size, 0, - (struct sockaddr *)&s->dgram_dst, - sizeof(s->dgram_dst)); - } else { - ret =3D send(s->fd, buf, size, 0); - } - } while (ret =3D=3D -1 && errno =3D=3D EINTR); + ret =3D RETRY_ON_EINTR( + s->dgram_dst.sin_family !=3D AF_UNIX ? + sendto(s->fd, buf, size, 0, + (struct sockaddr *)&s->dgram_dst, + sizeof(s->dgram_dst)) : + send(s->fd, buf, size, 0) + ); =20 if (ret =3D=3D -1 && errno =3D=3D EAGAIN) { net_socket_write_poll(s, true); diff --git a/net/tap.c b/net/tap.c index e090d14203..4c90f70b7e 100644 --- a/net/tap.c +++ b/net/tap.c @@ -102,9 +102,7 @@ static ssize_t tap_write_packet(TAPState *s, const stru= ct iovec *iov, int iovcnt { ssize_t len; =20 - do { - len =3D writev(s->fd, iov, iovcnt); - } while (len =3D=3D -1 && errno =3D=3D EINTR); + len =3D RETRY_ON_EINTR(writev(s->fd, iov, iovcnt)); =20 if (len =3D=3D -1 && errno =3D=3D EAGAIN) { tap_write_poll(s, true); @@ -577,9 +575,7 @@ static int net_bridge_run_helper(const char *helper, co= nst char *bridge, =20 close(sv[1]); =20 - do { - fd =3D recv_fd(sv[0]); - } while (fd =3D=3D -1 && errno =3D=3D EINTR); + fd =3D RETRY_ON_EINTR(recv_fd(sv[0])); saved_errno =3D errno; =20 close(sv[0]); diff --git a/qga/commands-posix.c b/qga/commands-posix.c index eea819cff0..95753f7c96 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -68,9 +68,7 @@ static void ga_wait_child(pid_t pid, int *status, Error *= *errp) =20 *status =3D 0; =20 - do { - rpid =3D waitpid(pid, status, 0); - } while (rpid =3D=3D -1 && errno =3D=3D EINTR); + rpid =3D RETRY_ON_EINTR(waitpid(pid, status, 0)); =20 if (rpid =3D=3D -1) { error_setg_errno(errp, errno, "failed to wait for child (pid: %d)", diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 508a0ad88c..5893c760c5 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -317,9 +317,7 @@ static void host_read(CPUState *cs, gdb_syscall_complet= e_cb complete, complete(cs, -1, EFAULT); return; } - do { - ret =3D read(gf->hostfd, ptr, len); - } while (ret =3D=3D -1 && errno =3D=3D EINTR); + ret =3D RETRY_ON_EINTR(read(gf->hostfd, ptr, len)); if (ret =3D=3D -1) { complete(cs, -1, errno); unlock_user(ptr, buf, 0); diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 90648eb8d1..5abb29cb9e 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -101,10 +101,10 @@ static int socket_accept(int sock) return -1; } =20 - do { - addrlen =3D sizeof(addr); - ret =3D accept(sock, (struct sockaddr *)&addr, &addrlen); - } while (ret =3D=3D -1 && errno =3D=3D EINTR); + ret =3D RETRY_ON_EINTR(( + addrlen =3D sizeof(addr), + accept(sock, (struct sockaddr *)&addr, &addrlen) + )); if (ret =3D=3D -1) { fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno)); } @@ -574,9 +574,7 @@ int qtest_socket_server(const char *socket_path) addr.sun_family =3D AF_UNIX; snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socket_path); =20 - do { - ret =3D bind(sock, (struct sockaddr *)&addr, sizeof(addr)); - } while (ret =3D=3D -1 && errno =3D=3D EINTR); + ret =3D RETRY_ON_EINTR(bind(sock, (struct sockaddr *)&addr, sizeof(add= r))); g_assert_cmpint(ret, !=3D, -1); ret =3D listen(sock, 1); g_assert_cmpint(ret, !=3D, -1); diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c index fecdf915e7..a5c711b1de 100644 --- a/tests/vhost-user-bridge.c +++ b/tests/vhost-user-bridge.c @@ -331,9 +331,7 @@ vubr_backend_recv_cb(int sock, void *ctx) .msg_iovlen =3D num, .msg_flags =3D MSG_DONTWAIT, }; - do { - ret =3D recvmsg(vubr->backend_udp_sock, &msg, 0); - } while (ret =3D=3D -1 && (errno =3D=3D EINTR)); + ret =3D RETRY_ON_EINTR(recvmsg(vubr->backend_udp_sock, &msg, 0)); =20 if (i =3D=3D 0) { iov_restore_front(elem->in_sg, sg, hdrlen); diff --git a/util/main-loop.c b/util/main-loop.c index f00a25451b..63bd5d123d 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -64,9 +64,7 @@ static void sigfd_handler(void *opaque) ssize_t len; =20 while (1) { - do { - len =3D read(fd, &info, sizeof(info)); - } while (len =3D=3D -1 && errno =3D=3D EINTR); + len =3D RETRY_ON_EINTR(read(fd, &info, sizeof(info))); =20 if (len =3D=3D -1 && errno =3D=3D EAGAIN) { break; diff --git a/util/osdep.c b/util/osdep.c index 746d5f7d71..aa358bd65e 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -244,9 +244,7 @@ static int qemu_lock_fcntl(int fd, int64_t start, int64= _t len, int fl_type) .l_type =3D fl_type, }; qemu_probe_lock_ops(); - do { - ret =3D fcntl(fd, fcntl_op_setlk, &fl); - } while (ret =3D=3D -1 && errno =3D=3D EINTR); + ret =3D RETRY_ON_EINTR(fcntl(fd, fcntl_op_setlk, &fl)); return ret =3D=3D -1 ? -errno : 0; } =20 diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 5ba01177bf..1a9b338cf9 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -240,9 +240,9 @@ static int qemu_vfio_pci_read_config(QEMUVFIOState *s, = void *buf, s->config_region_info.offset, s->config_region_info.size); assert(QEMU_IS_ALIGNED(s->config_region_info.offset + ofs, size)); - do { - ret =3D pread(s->device, buf, size, s->config_region_info.offset += ofs); - } while (ret =3D=3D -1 && errno =3D=3D EINTR); + ret =3D RETRY_ON_EINTR( + pread(s->device, buf, size, s->config_region_info.offset + ofs) + ); return ret =3D=3D size ? 0 : -errno; } =20 @@ -254,9 +254,9 @@ static int qemu_vfio_pci_write_config(QEMUVFIOState *s,= void *buf, int size, int s->config_region_info.offset, s->config_region_info.size); assert(QEMU_IS_ALIGNED(s->config_region_info.offset + ofs, size)); - do { - ret =3D pwrite(s->device, buf, size, s->config_region_info.offset = + ofs); - } while (ret =3D=3D -1 && errno =3D=3D EINTR); + ret =3D RETRY_ON_EINTR( + pwrite(s->device, buf, size, s->config_region_info.offset + ofs) + ); return ret =3D=3D size ? 0 : -errno; } =20 --=20 2.37.3