From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4878C25B08 for ; Wed, 17 Aug 2022 14:10:30 +0000 (UTC) Received: from localhost ([::1]:55812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOJkb-00045r-N8 for qemu-devel@archiver.kernel.org; Wed, 17 Aug 2022 10:10:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOJgx-00010S-7l for qemu-devel@nongnu.org; Wed, 17 Aug 2022 10:06:43 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]:42777) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oOJgq-00084G-PS for qemu-devel@nongnu.org; Wed, 17 Aug 2022 10:06:42 -0400 Received: by mail-ej1-x62a.google.com with SMTP id j8so24710583ejx.9 for ; Wed, 17 Aug 2022 07:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudlinux.com; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=2xLnLd6C0qS6Ki38TFfnOnzrAhs49/XEKvPETvaJGgQ=; b=Xu7/TM1OZX2/RgvuXPergJtIYzAJG30ApYU900QM+ZZ8Tutptu6lv2rVSQKgALcc3A bWyaWzXV3lmi4uzqMswvpYa5n9gdsOHWTKWwEULe9NMgqQtA2zIucuLit4Zse9j+ax6z unQk0OcxJXwz7CnoRkvJHwRmvKu1QYyiq4Vp79P/YajR8h+JO7GhPaV4iY8xvGB4e6GH R6IcS4igQ1cLSL934rPSM9vikOYkYeJ1yczA2OJwX53IbM01sbZtwFGOqjo/iY4hd+Fh R1tpMExLdcnfrWp2o5YNn+/wcFPKL2akLeGTAr1vLPilVorYLIWXSb4QQt/TRyQHGBtS 1fzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=2xLnLd6C0qS6Ki38TFfnOnzrAhs49/XEKvPETvaJGgQ=; b=3I+yf5hRqjYXRi70QHkTe//Yc+5FXr5rYR5bmr3pRn+gM68RS1Hih8mz++Pep9IqQo VIcf0XmUudotZ1GJ4PMMwEJ22NzEIbh/fHN65cMe2bjSBB5FFKk9Nxno3Ck7Y1KPL1LN KuqMAnqnbmFN0KOwSv5HhbluFIv2EtlA6N9LzWqDq6KnktUldMwr9dhAH7rpvmEWya7z TTt+fnnVQL6h0i50Tp0KIAuWIVcfkduyV+g5dqeOhzavp/IErVWZWxh3mJovg682kKBg UJwNVxLOOmgWibY7qjtPYbspfoOzfuQwf3WiMM12RinaZ01/oKIjBGCgQqDfIcVP3r0G Lj+A== X-Gm-Message-State: ACgBeo3vc7ap6qQ+io1N1XTXc1sRQkTmbQku6JVyjJO4vGNWhqV8RQo6 iJc7J0tNZZMuM/1engvZtqo120sSrLcQ6+4DrGukC9QFZg3CTA== X-Google-Smtp-Source: AA6agR60D6bz4F1SJC0xqtcw3XkOe/+nZUbHmQ38So02enp9bdFk9e/w7dLn9hEsX/pmMkw5wBIrc+VzejhTvFsDcVI= X-Received: by 2002:a17:906:9bc4:b0:730:9edc:40b2 with SMTP id de4-20020a1709069bc400b007309edc40b2mr16641970ejc.155.1660745193973; Wed, 17 Aug 2022 07:06:33 -0700 (PDT) MIME-Version: 1.0 References: <877d3jupln.fsf@pond.sub.org> <3206015.kY3CcG7ZbH@silver> <7218690.D19hzYb2mh@silver> <87mtcen7bz.fsf@pond.sub.org> In-Reply-To: From: Nikita Ivanov Date: Wed, 17 Aug 2022 17:06:23 +0300 Message-ID: Subject: Re: [PATCH] error handling: Use TFR() macro where applicable To: qemu-devel@nongnu.org Cc: Markus Armbruster , Christian Schoenebeck , Peter Maydell , =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= , Greg Kurz , Jason Wang , Michael Roth , Konstantin Kostiuk , Paolo Bonzini Content-Type: multipart/alternative; boundary="00000000000059844205e6705fa3" Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=nivanov@cloudlinux.com; helo=mail-ej1-x62a.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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --00000000000059844205e6705fa3 Content-Type: text/plain; charset="UTF-8" Hi! Are there any updates? I have not received any comments since the last email. On Mon, Aug 8, 2022 at 9:03 PM Nikita Ivanov wrote: > And summing up the discussion about TEMP_FAILURE_RETRY() usage examples, > I've come up with a new patch for TFR() to TEMP_FAILURE_RETRY() > refactoring. I've decided to stick to expression realisation. > > From 94217dfacf12b3211cfab6e19d750e57d679e851 Mon Sep 17 00:00:00 2001 > From: Nikita Ivanov > Date: Mon, 8 Aug 2022 20:43:45 +0300 > Subject: [PATCH] Refactoring: rename TFR() to TEMP_FAILURE_RETRY() > > glibc's unistd.h header provides the same macro with the > subtle difference in type casting. Adjust macro name to the > common standard and define conditionally. > > Signed-off-by: Nikita Ivanov > --- > block/file-posix.c | 14 +++++++------- > chardev/char-fd.c | 2 +- > chardev/char-pipe.c | 12 +++++++++--- > chardev/char-pty.c | 2 +- > hw/9pfs/9p-local.c | 6 ++++-- > include/qemu/osdep.h | 11 +++++++++-- > net/l2tpv3.c | 8 +++++--- > net/socket.c | 4 ++-- > net/tap-bsd.c | 6 +++--- > net/tap-linux.c | 2 +- > net/tap-solaris.c | 8 ++++---- > net/tap.c | 10 ++++++---- > os-posix.c | 2 +- > qga/commands-posix.c | 2 +- > semihosting/syscalls.c | 2 +- > tests/qtest/libqtest.c | 10 +++++----- > tests/vhost-user-bridge.c | 4 +++- > util/main-loop.c | 2 +- > util/osdep.c | 2 +- > util/vfio-helpers.c | 8 ++++---- > 20 files changed, 69 insertions(+), 48 deletions(-) > > diff --git a/block/file-posix.c b/block/file-posix.c > index 0786cb76f9..28ce649ab9 100644 > --- a/block/file-posix.c > +++ b/block/file-posix.c > @@ -1238,8 +1238,8 @@ static int hdev_get_max_segments(int fd, struct stat > *st) > ret = -errno; > goto out; > } > - TFR( > - ret = read(sysfd, buf, sizeof(buf) - 1) > + ret = TEMP_FAILURE_RETRY( > + read(sysfd, buf, sizeof(buf) - 1) > ); > if (ret < 0) { > ret = -errno; > @@ -1388,8 +1388,8 @@ static int handle_aiocb_ioctl(void *opaque) > RawPosixAIOData *aiocb = opaque; > int ret; > > - TFR( > - ret = ioctl(aiocb->aio_fildes, aiocb->ioctl.cmd, aiocb->ioctl.buf) > + ret = TEMP_FAILURE_RETRY( > + ioctl(aiocb->aio_fildes, aiocb->ioctl.cmd, aiocb->ioctl.buf) > ); > if (ret == -1) { > return -errno; > @@ -1472,8 +1472,8 @@ static ssize_t > handle_aiocb_rw_vector(RawPosixAIOData *aiocb) > { > ssize_t len; > > - TFR( > - len = (aiocb->aio_type & QEMU_AIO_WRITE) ? > + len = TEMP_FAILURE_RETRY( > + (aiocb->aio_type & QEMU_AIO_WRITE) ? > qemu_pwritev(aiocb->aio_fildes, > aiocb->io.iov, > aiocb->io.niov, > @@ -1907,7 +1907,7 @@ static int allocate_first_block(int fd, size_t > max_size) > buf = qemu_memalign(max_align, write_size); > memset(buf, 0, write_size); > > - TFR(n = pwrite(fd, buf, write_size, 0)); > + n = TEMP_FAILURE_RETRY(pwrite(fd, buf, write_size, 0)); > > ret = (n == -1) ? -errno : 0; > > diff --git a/chardev/char-fd.c b/chardev/char-fd.c > index cf78454841..1250a63236 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 = -1; > > - TFR(fd = qemu_open_old(src, flags, 0666)); > + fd = TEMP_FAILURE_RETRY(qemu_open_old(src, flags, 0666)); > if (fd == -1) { > error_setg_file_open(errp, errno, src); > } > diff --git a/chardev/char-pipe.c b/chardev/char-pipe.c > index 66d3b85091..a59a055c87 100644 > --- a/chardev/char-pipe.c > +++ b/chardev/char-pipe.c > @@ -131,8 +131,12 @@ static void qemu_chr_open_pipe(Chardev *chr, > > filename_in = g_strdup_printf("%s.in", filename); > filename_out = g_strdup_printf("%s.out", filename); > - TFR(fd_in = qemu_open_old(filename_in, O_RDWR | O_BINARY)); > - TFR(fd_out = qemu_open_old(filename_out, O_RDWR | O_BINARY)); > + fd_in = TEMP_FAILURE_RETRY( > + qemu_open_old(filename_in, O_RDWR | O_BINARY) > + ); > + fd_out = TEMP_FAILURE_RETRY( > + qemu_open_old(filename_out, O_RDWR | O_BINARY) > + ); > g_free(filename_in); > g_free(filename_out); > if (fd_in < 0 || fd_out < 0) { > @@ -142,7 +146,9 @@ static void qemu_chr_open_pipe(Chardev *chr, > if (fd_out >= 0) { > close(fd_out); > } > - TFR(fd_in = fd_out = qemu_open_old(filename, O_RDWR | O_BINARY)); > + fd_in = fd_out = TEMP_FAILURE_RETRY( > + qemu_open_old(filename, O_RDWR | O_BINARY) > + ); > if (fd_in < 0) { > error_setg_file_open(errp, errno, filename); > return; > diff --git a/chardev/char-pty.c b/chardev/char-pty.c > index b2f490bacf..913a98250b 100644 > --- a/chardev/char-pty.c > +++ b/chardev/char-pty.c > @@ -93,7 +93,7 @@ static void pty_chr_update_read_handler(Chardev *chr) > pfd.fd = fioc->fd; > pfd.events = G_IO_OUT; > pfd.revents = 0; > - TFR(rc = g_poll(&pfd, 1, 0)); > + rc = TEMP_FAILURE_RETRY(g_poll(&pfd, 1, 0)); > assert(rc >= 0); > > if (pfd.revents & G_IO_HUP) { > diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c > index c90ab947ba..6a3b4fac4a 100644 > --- a/hw/9pfs/9p-local.c > +++ b/hw/9pfs/9p-local.c > @@ -470,7 +470,7 @@ static ssize_t local_readlink(FsContext *fs_ctx, > V9fsPath *fs_path, > if (fd == -1) { > return -1; > } > - TFR(tsize = read(fd, (void *)buf, bufsz)); > + tsize = TEMP_FAILURE_RETRY(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)) { > @@ -906,7 +906,9 @@ static int local_symlink(FsContext *fs_ctx, const char > *oldpath, > } > /* Write the oldpath (target) to the file. */ > oldpath_size = strlen(oldpath); > - TFR(write_size = write(fd, (void *)oldpath, oldpath_size)); > + write_size = TEMP_FAILURE_RETRY( > + write(fd, (void *)oldpath, oldpath_size) > + ); > close_preserve_errno(fd); > > if (write_size != oldpath_size) { > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h > index b1c161c035..6cd0de8e38 100644 > --- a/include/qemu/osdep.h > +++ b/include/qemu/osdep.h > @@ -242,8 +242,15 @@ void QEMU_ERROR("code path is reachable") > #if !defined(ESHUTDOWN) > #define ESHUTDOWN 4099 > #endif > - > -#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR) > +#if !defined(TEMP_FAILURE_RETRY) > +#define TEMP_FAILURE_RETRY(expr) \ > + (__extension__ \ > + ({ long int __result; \ > + do { \ > + __result = (long int) (expression); \ > + } while (__result == -1L && errno == EINTR); \ > + __result; })) > +#endif > > /* 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/l2tpv3.c b/net/l2tpv3.c > index adfdbdb84c..cbde9332fe 100644 > --- a/net/l2tpv3.c > +++ b/net/l2tpv3.c > @@ -240,7 +240,7 @@ static ssize_t > net_l2tpv3_receive_dgram_iov(NetClientState *nc, > message.msg_control = NULL; > message.msg_controllen = 0; > message.msg_flags = 0; > - TFR(ret = sendmsg(s->fd, &message, 0)); > + ret = TEMP_FAILURE_RETRY(sendmsg(s->fd, &message, 0)); > if (ret > 0) { > ret -= s->offset; > } else if (ret == 0) { > @@ -283,7 +283,7 @@ static ssize_t net_l2tpv3_receive_dgram(NetClientState > *nc, > message.msg_control = NULL; > message.msg_controllen = 0; > message.msg_flags = 0; > - TFR(ret = sendmsg(s->fd, &message, 0)); > + ret = TEMP_FAILURE_RETRY(sendmsg(s->fd, &message, 0)); > if (ret > 0) { > ret -= s->offset; > } else if (ret == 0) { > @@ -430,7 +430,9 @@ static void net_l2tpv3_send(void *opaque) > > msgvec = s->msgvec + s->queue_head; > if (target_count > 0) { > - TFR(count = recvmmsg(s->fd, msgvec, target_count, MSG_DONTWAIT, > NULL)); > + count = TEMP_FAILURE_RETRY( > + 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 a3397660c2..cfb893b183 100644 > --- a/net/socket.c > +++ b/net/socket.c > @@ -117,8 +117,8 @@ static ssize_t net_socket_receive_dgram(NetClientState > *nc, const uint8_t *buf, > NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc); > ssize_t ret; > > - TFR( > - ret = s->dgram_dst.sin_family != AF_UNIX ? > + ret = TEMP_FAILURE_RETRY( > + s->dgram_dst.sin_family != AF_UNIX ? > sendto(s->fd, buf, size, 0, > (struct sockaddr *)&s->dgram_dst, > sizeof(s->dgram_dst)) : > diff --git a/net/tap-bsd.c b/net/tap-bsd.c > index 005ce05c6e..720090244e 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 = open(dname, O_RDWR)); > + fd = TEMP_FAILURE_RETRY(open(dname, O_RDWR)); > if (fd >= 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; > > - TFR(fd = open(PATH_NET_TAP, O_RDWR)); > + fd = TEMP_FAILURE_RETRY(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_hdr, > if (ifname[0] != '\0') { > char dname[100]; > snprintf(dname, sizeof dname, "/dev/%s", ifname); > - TFR(fd = open(dname, O_RDWR)); > + fd = TEMP_FAILURE_RETRY(open(dname, O_RDWR)); > if (fd < 0 && errno != 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..bf3ce44329 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 = sizeof(struct virtio_net_hdr); > unsigned int features; > > - TFR(fd = open(PATH_NET_TUN, O_RDWR)); > + fd = TEMP_FAILURE_RETRY(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..73e0e9f196 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); > > - TFR(ip_fd = open("/dev/udp", O_RDWR, 0)); > + ip_fd = TEMP_FAILURE_RETRY(open("/dev/udp", O_RDWR, 0)); > if (ip_fd < 0) { > error_setg(errp, "Can't open /dev/ip (actually /dev/udp)"); > return -1; > } > > - TFR(tap_fd = open("/dev/tap", O_RDWR, 0)); > + tap_fd = TEMP_FAILURE_RETRY(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 = ioctl (tap_fd, I_STR, &strioc_ppa)) < 0) > error_report("Can't assign new interface"); > > - TFR(if_fd = open("/dev/tap", O_RDWR, 0)); > + if_fd = TEMP_FAILURE_RETRY(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 = open ("/dev/tap", O_RDWR, 0)); > + arp_fd = TEMP_FAILURE_RETRY(open("/dev/tap", O_RDWR, 0)); > if (arp_fd < 0) > error_report("Can't open %s", "/dev/tap"); > > diff --git a/net/tap.c b/net/tap.c > index b047eca8b5..dfd220a184 100644 > --- a/net/tap.c > +++ b/net/tap.c > @@ -102,7 +102,7 @@ static ssize_t tap_write_packet(TAPState *s, const > struct iovec *iov, int iovcnt > { > ssize_t len; > > - TFR(len = writev(s->fd, iov, iovcnt)); > + len = TEMP_FAILURE_RETRY(writev(s->fd, iov, iovcnt)); > > if (len == -1 && errno == EAGAIN) { > tap_write_poll(s, true); > @@ -575,7 +575,7 @@ static int net_bridge_run_helper(const char *helper, > const char *bridge, > > close(sv[1]); > > - TFR(fd = recv_fd(sv[0])); > + fd = TEMP_FAILURE_RETRY(recv_fd(sv[0])); > saved_errno = errno; > > close(sv[0]); > @@ -647,8 +647,10 @@ static int net_tap_init(const NetdevTapOptions *tap, > int *vnet_hdr, > vnet_hdr_required = 0; > } > > - TFR(fd = tap_open(ifname, ifname_sz, vnet_hdr, vnet_hdr_required, > - mq_required, errp)); > + fd = TEMP_FAILURE_RETRY( > + tap_open(ifname, ifname_sz, vnet_hdr, vnet_hdr_required, > + mq_required, errp) > + ); > if (fd < 0) { > return -1; > } > diff --git a/os-posix.c b/os-posix.c > index 321fc4bd13..59cac65585 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 = qemu_open_old("/dev/null", O_RDWR)); > + fd = TEMP_FAILURE_RETRY(qemu_open_old("/dev/null", O_RDWR)); > if (fd == -1) { > exit(1); > } > diff --git a/qga/commands-posix.c b/qga/commands-posix.c > index 90f83aa9b6..feb0fab807 100644 > --- a/qga/commands-posix.c > +++ b/qga/commands-posix.c > @@ -68,7 +68,7 @@ static void ga_wait_child(pid_t pid, int *status, Error > **errp) > > *status = 0; > > - TFR(rpid = waitpid(pid, status, 0)); > + rpid = TEMP_FAILURE_RETRY(waitpid(pid, status, 0)); > > if (rpid == -1) { > error_setg_errno(errp, errno, "failed to wait for child (pid: > %d)", > diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c > index 025c08147a..0cbef7d22b 100644 > --- a/semihosting/syscalls.c > +++ b/semihosting/syscalls.c > @@ -317,7 +317,7 @@ static void host_read(CPUState *cs, > gdb_syscall_complete_cb complete, > complete(cs, -1, EFAULT); > return; > } > - TFR(ret = read(gf->hostfd, ptr, len)); > + ret = TEMP_FAILURE_RETRY(read(gf->hostfd, ptr, len)); > if (ret == -1) { > complete(cs, -1, errno); > unlock_user(ptr, buf, 0); > diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c > index d4022966b3..4a12824dc4 100644 > --- a/tests/qtest/libqtest.c > +++ b/tests/qtest/libqtest.c > @@ -102,8 +102,8 @@ static int socket_accept(int sock) > } > > addrlen = sizeof(addr); > - TFR( > - ret = accept(sock, (struct sockaddr *)&addr, &addrlen) > + ret = TEMP_FAILURE_RETRY( > + accept(sock, (struct sockaddr *)&addr, &addrlen) > ); > if (ret == -1) { > fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno)); > @@ -140,7 +140,7 @@ void qtest_kill_qemu(QTestState *s) > /* Skip wait if qtest_probe_child already reaped. */ > if (pid != -1) { > kill(pid, SIGTERM); > - TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0)); > + pid = TEMP_FAILURE_RETRY(waitpid(s->qemu_pid, &s->wstatus, 0)); > assert(pid == s->qemu_pid); > s->qemu_pid = -1; > } > @@ -578,8 +578,8 @@ int qtest_socket_server(const char *socket_path) > addr.sun_family = AF_UNIX; > snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socket_path); > > - TFR( > - ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr)) > + ret = TEMP_FAILURE_RETRY( > + bind(sock, (struct sockaddr *)&addr, sizeof(addr)) > ); > g_assert_cmpint(ret, !=, -1); > ret = listen(sock, 1); > diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c > index 4d8f933ed5..624a211f3d 100644 > --- a/tests/vhost-user-bridge.c > +++ b/tests/vhost-user-bridge.c > @@ -331,7 +331,9 @@ vubr_backend_recv_cb(int sock, void *ctx) > .msg_iovlen = num, > .msg_flags = MSG_DONTWAIT, > }; > - TFR(ret = recvmsg(vubr->backend_udp_sock, &msg, 0)); > + ret = TEMP_FAILURE_RETRY( > + recvmsg(vubr->backend_udp_sock, &msg, 0) > + ); > > if (i == 0) { > iov_restore_front(elem->in_sg, sg, hdrlen); > diff --git a/util/main-loop.c b/util/main-loop.c > index 58e14db2d4..5f65f928bd 100644 > --- a/util/main-loop.c > +++ b/util/main-loop.c > @@ -64,7 +64,7 @@ static void sigfd_handler(void *opaque) > ssize_t len; > > while (1) { > - TFR(len = read(fd, &info, sizeof(info))); > + len = TEMP_FAILURE_RETRY(read(fd, &info, sizeof(info))); > > if (len == -1 && errno == EAGAIN) { > break; > diff --git a/util/osdep.c b/util/osdep.c > index d35c473ac7..2c287e75e7 100644 > --- a/util/osdep.c > +++ b/util/osdep.c > @@ -244,7 +244,7 @@ static int qemu_lock_fcntl(int fd, int64_t start, > int64_t len, int fl_type) > .l_type = fl_type, > }; > qemu_probe_lock_ops(); > - TFR(ret = fcntl(fd, fcntl_op_setlk, &fl)); > + ret = TEMP_FAILURE_RETRY(fcntl(fd, fcntl_op_setlk, &fl)); > return ret == -1 ? -errno : 0; > } > > diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c > index c878be1c5f..e1422666eb 100644 > --- a/util/vfio-helpers.c > +++ b/util/vfio-helpers.c > @@ -240,8 +240,8 @@ 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)); > - TFR( > - ret = pread(s->device, buf, size, s->config_region_info.offset + > ofs) > + ret = TEMP_FAILURE_RETRY( > + pread(s->device, buf, size, s->config_region_info.offset + ofs) > ); > return ret == size ? 0 : -errno; > } > @@ -254,8 +254,8 @@ 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)); > - TFR( > - ret = pwrite(s->device, buf, size, s->config_region_info.offset + > ofs) > + ret = TEMP_FAILURE_RETRY( > + pwrite(s->device, buf, size, s->config_region_info.offset + ofs) > ); > return ret == size ? 0 : -errno; > } > -- > 2.37.1 > > > On Mon, Aug 8, 2022 at 9:00 PM Nikita Ivanov > wrote: > >> Hi! >> During our discussion, I found that I've missed a couple of places where >> TFR() macro could be applied. Here is an updated first patch: >> >> From 8a68f50aac4a8549f416b9350cf339cf0501a712 Mon Sep 17 00:00:00 2001 >> From: Nikita Ivanov >> Date: Wed, 3 Aug 2022 12:54:00 +0300 >> Subject: [PATCH] error handling: Use TFR() macro where applicable >> >> There is a defined TFR() 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 | 39 ++++++++++++++++++--------------------- >> chardev/char-pty.c | 4 +--- >> hw/9pfs/9p-local.c | 8 ++------ >> net/l2tpv3.c | 15 +++------------ >> net/socket.c | 16 +++++++--------- >> net/tap.c | 8 ++------ >> qga/commands-posix.c | 4 +--- >> semihosting/syscalls.c | 4 +--- >> tests/qtest/libqtest.c | 14 +++++++------- >> tests/vhost-user-bridge.c | 4 +--- >> util/main-loop.c | 4 +--- >> util/osdep.c | 4 +--- >> util/vfio-helpers.c | 12 ++++++------ >> 13 files changed, 51 insertions(+), 85 deletions(-) >> >> diff --git a/block/file-posix.c b/block/file-posix.c >> index 48cd096624..0786cb76f9 100644 >> --- a/block/file-posix.c >> +++ b/block/file-posix.c >> @@ -1238,9 +1238,9 @@ static int hdev_get_max_segments(int fd, struct >> stat *st) >> ret = -errno; >> goto out; >> } >> - do { >> - ret = read(sysfd, buf, sizeof(buf) - 1); >> - } while (ret == -1 && errno == EINTR); >> + TFR( >> + ret = read(sysfd, buf, sizeof(buf) - 1) >> + ); >> if (ret < 0) { >> ret = -errno; >> goto out; >> @@ -1388,9 +1388,9 @@ static int handle_aiocb_ioctl(void *opaque) >> RawPosixAIOData *aiocb = opaque; >> int ret; >> >> - do { >> - ret = ioctl(aiocb->aio_fildes, aiocb->ioctl.cmd, >> aiocb->ioctl.buf); >> - } while (ret == -1 && errno == EINTR); >> + TFR( >> + ret = ioctl(aiocb->aio_fildes, aiocb->ioctl.cmd, >> aiocb->ioctl.buf) >> + ); >> if (ret == -1) { >> return -errno; >> } >> @@ -1472,18 +1472,17 @@ static ssize_t >> handle_aiocb_rw_vector(RawPosixAIOData *aiocb) >> { >> ssize_t len; >> >> - do { >> - if (aiocb->aio_type & QEMU_AIO_WRITE) >> - len = qemu_pwritev(aiocb->aio_fildes, >> - aiocb->io.iov, >> - aiocb->io.niov, >> - aiocb->aio_offset); >> - else >> - len = qemu_preadv(aiocb->aio_fildes, >> - aiocb->io.iov, >> - aiocb->io.niov, >> - aiocb->aio_offset); >> - } while (len == -1 && errno == EINTR); >> + TFR( >> + len = (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) >> + ); >> >> if (len == -1) { >> return -errno; >> @@ -1908,9 +1907,7 @@ static int allocate_first_block(int fd, size_t >> max_size) >> buf = qemu_memalign(max_align, write_size); >> memset(buf, 0, write_size); >> >> - do { >> - n = pwrite(fd, buf, write_size, 0); >> - } while (n == -1 && errno == EINTR); >> + TFR(n = pwrite(fd, buf, write_size, 0)); >> >> ret = (n == -1) ? -errno : 0; >> >> diff --git a/chardev/char-pty.c b/chardev/char-pty.c >> index 53f25c6bbd..b2f490bacf 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 = fioc->fd; >> pfd.events = G_IO_OUT; >> pfd.revents = 0; >> - do { >> - rc = g_poll(&pfd, 1, 0); >> - } while (rc == -1 && errno == EINTR); >> + TFR(rc = g_poll(&pfd, 1, 0)); >> assert(rc >= 0); >> >> if (pfd.revents & G_IO_HUP) { >> diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c >> index d42ce6d8b8..c90ab947ba 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, >> V9fsPath *fs_path, >> if (fd == -1) { >> return -1; >> } >> - do { >> - tsize = read(fd, (void *)buf, bufsz); >> - } while (tsize == -1 && errno == EINTR); >> + TFR(tsize = 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 = strlen(oldpath); >> - do { >> - write_size = write(fd, (void *)oldpath, oldpath_size); >> - } while (write_size == -1 && errno == EINTR); >> + TFR(write_size = write(fd, (void *)oldpath, oldpath_size)); >> close_preserve_errno(fd); >> >> if (write_size != oldpath_size) { >> diff --git a/net/l2tpv3.c b/net/l2tpv3.c >> index af373e5c30..adfdbdb84c 100644 >> --- a/net/l2tpv3.c >> +++ b/net/l2tpv3.c >> @@ -240,9 +240,7 @@ static ssize_t >> net_l2tpv3_receive_dgram_iov(NetClientState *nc, >> message.msg_control = NULL; >> message.msg_controllen = 0; >> message.msg_flags = 0; >> - do { >> - ret = sendmsg(s->fd, &message, 0); >> - } while ((ret == -1) && (errno == EINTR)); >> + TFR(ret = sendmsg(s->fd, &message, 0)); >> if (ret > 0) { >> ret -= s->offset; >> } else if (ret == 0) { >> @@ -285,9 +283,7 @@ static ssize_t >> net_l2tpv3_receive_dgram(NetClientState *nc, >> message.msg_control = NULL; >> message.msg_controllen = 0; >> message.msg_flags = 0; >> - do { >> - ret = sendmsg(s->fd, &message, 0); >> - } while ((ret == -1) && (errno == EINTR)); >> + TFR(ret = sendmsg(s->fd, &message, 0)); >> if (ret > 0) { >> ret -= s->offset; >> } else if (ret == 0) { >> @@ -434,12 +430,7 @@ static void net_l2tpv3_send(void *opaque) >> >> msgvec = s->msgvec + s->queue_head; >> if (target_count > 0) { >> - do { >> - count = recvmmsg( >> - s->fd, >> - msgvec, >> - target_count, MSG_DONTWAIT, NULL); >> - } while ((count == -1) && (errno == EINTR)); >> + TFR(count = 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..a3397660c2 100644 >> --- a/net/socket.c >> +++ b/net/socket.c >> @@ -117,15 +117,13 @@ static ssize_t >> net_socket_receive_dgram(NetClientState *nc, const uint8_t *buf, >> NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc); >> ssize_t ret; >> >> - do { >> - if (s->dgram_dst.sin_family != AF_UNIX) { >> - ret = sendto(s->fd, buf, size, 0, >> - (struct sockaddr *)&s->dgram_dst, >> - sizeof(s->dgram_dst)); >> - } else { >> - ret = send(s->fd, buf, size, 0); >> - } >> - } while (ret == -1 && errno == EINTR); >> + TFR( >> + ret = s->dgram_dst.sin_family != AF_UNIX ? >> + sendto(s->fd, buf, size, 0, >> + (struct sockaddr *)&s->dgram_dst, >> + sizeof(s->dgram_dst)) : >> + send(s->fd, buf, size, 0) >> + ); >> >> if (ret == -1 && errno == EAGAIN) { >> net_socket_write_poll(s, true); >> diff --git a/net/tap.c b/net/tap.c >> index b3ddfd4a74..b047eca8b5 100644 >> --- a/net/tap.c >> +++ b/net/tap.c >> @@ -102,9 +102,7 @@ static ssize_t tap_write_packet(TAPState *s, const >> struct iovec *iov, int iovcnt >> { >> ssize_t len; >> >> - do { >> - len = writev(s->fd, iov, iovcnt); >> - } while (len == -1 && errno == EINTR); >> + TFR(len = writev(s->fd, iov, iovcnt)); >> >> if (len == -1 && errno == EAGAIN) { >> tap_write_poll(s, true); >> @@ -577,9 +575,7 @@ static int net_bridge_run_helper(const char *helper, >> const char *bridge, >> >> close(sv[1]); >> >> - do { >> - fd = recv_fd(sv[0]); >> - } while (fd == -1 && errno == EINTR); >> + TFR(fd = recv_fd(sv[0])); >> saved_errno = errno; >> >> close(sv[0]); >> diff --git a/qga/commands-posix.c b/qga/commands-posix.c >> index 954efed01b..90f83aa9b6 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) >> >> *status = 0; >> >> - do { >> - rpid = waitpid(pid, status, 0); >> - } while (rpid == -1 && errno == EINTR); >> + TFR(rpid = waitpid(pid, status, 0)); >> >> if (rpid == -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..025c08147a 100644 >> --- a/semihosting/syscalls.c >> +++ b/semihosting/syscalls.c >> @@ -317,9 +317,7 @@ static void host_read(CPUState *cs, >> gdb_syscall_complete_cb complete, >> complete(cs, -1, EFAULT); >> return; >> } >> - do { >> - ret = read(gf->hostfd, ptr, len); >> - } while (ret == -1 && errno == EINTR); >> + TFR(ret = read(gf->hostfd, ptr, len)); >> if (ret == -1) { >> complete(cs, -1, errno); >> unlock_user(ptr, buf, 0); >> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c >> index 8c159eacf5..d4022966b3 100644 >> --- a/tests/qtest/libqtest.c >> +++ b/tests/qtest/libqtest.c >> @@ -101,10 +101,10 @@ static int socket_accept(int sock) >> return -1; >> } >> >> - do { >> - addrlen = sizeof(addr); >> - ret = accept(sock, (struct sockaddr *)&addr, &addrlen); >> - } while (ret == -1 && errno == EINTR); >> + addrlen = sizeof(addr); >> + TFR( >> + ret = accept(sock, (struct sockaddr *)&addr, &addrlen) >> + ); >> if (ret == -1) { >> fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno)); >> } >> @@ -578,9 +578,9 @@ int qtest_socket_server(const char *socket_path) >> addr.sun_family = AF_UNIX; >> snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socket_path); >> >> - do { >> - ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr)); >> - } while (ret == -1 && errno == EINTR); >> + TFR( >> + ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr)) >> + ); >> g_assert_cmpint(ret, !=, -1); >> ret = listen(sock, 1); >> g_assert_cmpint(ret, !=, -1); >> diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c >> index 9b1dab2f28..4d8f933ed5 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 = num, >> .msg_flags = MSG_DONTWAIT, >> }; >> - do { >> - ret = recvmsg(vubr->backend_udp_sock, &msg, 0); >> - } while (ret == -1 && (errno == EINTR)); >> + TFR(ret = recvmsg(vubr->backend_udp_sock, &msg, 0)); >> >> if (i == 0) { >> iov_restore_front(elem->in_sg, sg, hdrlen); >> diff --git a/util/main-loop.c b/util/main-loop.c >> index f00a25451b..58e14db2d4 100644 >> --- a/util/main-loop.c >> +++ b/util/main-loop.c >> @@ -64,9 +64,7 @@ static void sigfd_handler(void *opaque) >> ssize_t len; >> >> while (1) { >> - do { >> - len = read(fd, &info, sizeof(info)); >> - } while (len == -1 && errno == EINTR); >> + TFR(len = read(fd, &info, sizeof(info))); >> >> if (len == -1 && errno == EAGAIN) { >> break; >> diff --git a/util/osdep.c b/util/osdep.c >> index 60fcbbaebe..d35c473ac7 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 = fl_type, >> }; >> qemu_probe_lock_ops(); >> - do { >> - ret = fcntl(fd, fcntl_op_setlk, &fl); >> - } while (ret == -1 && errno == EINTR); >> + TFR(ret = fcntl(fd, fcntl_op_setlk, &fl)); >> return ret == -1 ? -errno : 0; >> } >> >> diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c >> index 5ba01177bf..c878be1c5f 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 = pread(s->device, buf, size, s->config_region_info.offset + >> ofs); >> - } while (ret == -1 && errno == EINTR); >> + TFR( >> + ret = pread(s->device, buf, size, s->config_region_info.offset + >> ofs) >> + ); >> return ret == size ? 0 : -errno; >> } >> >> @@ -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 = pwrite(s->device, buf, size, s->config_region_info.offset >> + ofs); >> - } while (ret == -1 && errno == EINTR); >> + TFR( >> + ret = pwrite(s->device, buf, size, s->config_region_info.offset >> + ofs) >> + ); >> return ret == size ? 0 : -errno; >> } >> >> -- >> 2.37.1 >> >> >> On Mon, Aug 8, 2022 at 5:22 PM Markus Armbruster >> wrote: >> >>> Christian Schoenebeck writes: >>> >>> > On Montag, 8. August 2022 14:52:28 CEST Christian Schoenebeck wrote: >>> >> On Montag, 8. August 2022 10:05:56 CEST Markus Armbruster wrote: >>> >> > Nikita Ivanov writes: >>> >> > > Summing up the discussion above, I suggest the following patch >>> for TFR() >>> >> > > macro refactoring. (The patch is sequential to the first one I >>> >> > > introduced >>> >> > > in the start of the discussion). >>> >> > > >>> >> > >>From 6318bee052900aa93bba6620b53c7cb2290e5001 Mon Sep 17 00:00:00 >>> 2001 >>> >> > >> >>> >> > > From: Nikita Ivanov >>> >> > > Date: Mon, 8 Aug 2022 09:30:34 +0300 >>> >> > > Subject: [PATCH] Refactoring: rename TFR() to TEMP_FAILURE_RETRY() >>> >> > > >>> >> > > glibc's unistd.h header provides the same macro with the >>> >> > > subtle difference in type casting. Adjust macro name to the >>> >> > > common standard and define conditionally. >>> >> > > >>> >> > > Signed-off-by: Nikita Ivanov >>> >>> [...] >>> >>> >> > > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h >>> >> > > index b1c161c035..55f2927d8b 100644 >>> >> > > --- a/include/qemu/osdep.h >>> >> > > +++ b/include/qemu/osdep.h >>> >> > > @@ -242,8 +242,10 @@ void QEMU_ERROR("code path is reachable") >>> >> > > >>> >> > > #if !defined(ESHUTDOWN) >>> >> > > #define ESHUTDOWN 4099 >>> >> > > #endif >>> >> > > >>> >> > > - >>> >> > > -#define TFR(expr) do { if ((expr) != -1) break; } while (errno == >>> >> > > EINTR) >>> >> > > +#if !defined(TEMP_FAILURE_RETRY) >>> >> > > +#define TEMP_FAILURE_RETRY(expr) \ >>> >> > > + do { if ((expr) != -1) break; } while (errno == EINTR) >>> >>> To avoid / reduce confusion: this macro expands into a statement, and ... >>> >>> >> > > +#endif >>> >> > >>> >> > GLibc's version is >>> >> > >>> >> > # define TEMP_FAILURE_RETRY(expression) \ >>> >> > (__extension__ >>> \ >>> >> > ({ long int __result; >>> \ >>> >> > do __result = (long int) (expression); >>> \ >>> >> > while (__result == -1L && errno == EINTR); >>> \ >>> >> > __result; })) >>> >>> ... this one expands into an expression. It uses GCC's "a compound >>> statement enclosed in parentheses may appear as an expression" extension. >>> >>> >> > >>> >> > The difference isn't just "type casting", it's also statement >>> >> > vs. expression. >>> >> > >>> >> > Is it a good idea to have the macro expand into a statement on some >>> >> > hosts, and into an expression on others? Sure, CI should catch any >>> uses >>> >> > as expression, but delaying compile errors to CI wastes developer >>> time. >>> >> >>> >> For consistency and simplicity, I would define exactly one version (no >>> >> ifdefs) of the macro with a different macro name than glibc's >>> >> TEMP_FAILURE_RETRY(), and use that QEMU specific macro name in QEMU >>> code >>> >> everywhere. >>> >>> TFR()? Can't resist closing the circle... >>> >>> >> As for statement vs. expression: The only advantage of the statement >>> version >>> >> is if you'd need __result as an rvalue, which is not needed ATM, >>> right? So >>> >> I would go for the expression version (with cast) for now. >>> >>> The expression-like macro is nicer where the return value matters. >>> Example (stolen from "The GNU C Library Reference Manual"): >>> >>> nbytes = TEMP_FAILURE_RETRY (write (desc, buffer, count)); >>> >>> With the statement-like macro, you have to write >>> >>> TEMP_FAILURE_RETRY (nbytes = write (desc, buffer, count)); >>> >>> >> The glibc history does not reveal why they chose the statement >>> version. >>> >>> The expression version, actually. >>> >>> >> Best regards, >>> >> Christian Schoenebeck >>> > >>> > Sorry: s/rvalue/lvalue/ i.e. if you need the memory address of result >>> or if >>> > you need to take the result value of the last iteration in >>> 'expression' into >>> > account. >>> >>> >> >> -- >> Best Regards, >> *Nikita Ivanov* | C developer >> *Telephone:* +79140870696 >> *Telephone:* +79015053149 >> > > > -- > Best Regards, > *Nikita Ivanov* | C developer > *Telephone:* +79140870696 > *Telephone:* +79015053149 > -- Best Regards, *Nikita Ivanov* | C developer *Telephone:* +79140870696 *Telephone:* +79015053149 --00000000000059844205e6705fa3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi! Are there any updates? I have not received any comment= s since the last email.

On Mon, Aug 8, 2022 at 9:03 PM Nikita Ivanov <nivanov@cloudlinux.com> wrote= :
And summing up the discussion about TEMP_FAILURE_RETRY() usage examples,= I've come up with a new patch for TFR() to TEMP_FAILURE_RETRY() refact= oring. I've decided to stick to expression realisation.

From 942= 17dfacf12b3211cfab6e19d750e57d679e851 Mon Sep 17 00:00:00 2001
From: Nik= ita Ivanov <= nivanov@cloudlinux.com>
Date: Mon, 8 Aug 2022 20:43:45 +0300
S= ubject: [PATCH] Refactoring: rename TFR() to TEMP_FAILURE_RETRY()

gl= ibc's unistd.h header provides the same macro with the
subtle differ= ence in type casting. Adjust macro name to the
common standard and defin= e conditionally.

Signed-off-by: Nikita Ivanov <nivanov@cloudlinux.com>---
=C2=A0block/file-posix.c =C2=A0 =C2=A0 =C2=A0 =C2=A0| 14 +++++++---= ----
=C2=A0chardev/char-fd.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A02 +-=C2=A0chardev/char-pipe.c =C2=A0 =C2=A0 =C2=A0 | 12 +++++++++---
=C2=A0= chardev/char-pty.c =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A02 +-
=C2=A0hw/9pfs= /9p-local.c =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A06 ++++--
=C2=A0include/qe= mu/osdep.h =C2=A0 =C2=A0 =C2=A0| 11 +++++++++--
=C2=A0net/l2tpv3.c =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A08 +++++---
=C2=A0ne= t/socket.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A04 ++--=C2=A0net/tap-bsd.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A06 += ++---
=C2=A0net/tap-linux.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A02= +-
=C2=A0net/tap-solaris.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A08 ++++--= --
=C2=A0net/tap.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 | 10 ++++++----
=C2=A0os-posix.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0| =C2=A02 +-
=C2=A0qga/commands-posix.c =C2=A0 =C2= =A0 =C2=A0| =C2=A02 +-
=C2=A0semihosting/syscalls.c =C2=A0 =C2=A0| =C2= =A02 +-
=C2=A0tests/qtest/libqtest.c =C2=A0 =C2=A0| 10 +++++-----
=C2= =A0tests/vhost-user-bridge.c | =C2=A04 +++-
=C2=A0util/main-loop.c =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A02 +-
=C2=A0util/osdep.c =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A02 +-
=C2=A0util/vfio-he= lpers.c =C2=A0 =C2=A0 =C2=A0 | =C2=A08 ++++----
=C2=A020 files changed, = 69 insertions(+), 48 deletions(-)

diff --git a/block/file-posix.c b/= block/file-posix.c
index 0786cb76f9..28ce649ab9 100644
--- a/block/fi= le-posix.c
+++ b/block/file-posix.c
@@ -1238,8 +1238,8 @@ static int = hdev_get_max_segments(int fd, struct stat *st)
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0ret =3D -errno;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto out;=C2=A0 =C2=A0 =C2=A0}
- =C2=A0 =C2=A0TFR(
- =C2=A0 =C2=A0 =C2=A0 =C2= =A0ret =3D read(sysfd, buf, sizeof(buf) - 1)
+ =C2=A0 =C2=A0ret =3D TEMP= _FAILURE_RETRY(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0read(sysfd, buf, sizeof(buf= ) - 1)
=C2=A0 =C2=A0 =C2=A0);
=C2=A0 =C2=A0 =C2=A0if (ret < 0) {=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D -errno;
@@ -1388,8 +1388,8 @= @ static int handle_aiocb_ioctl(void *opaque)
=C2=A0 =C2=A0 =C2=A0RawPos= ixAIOData *aiocb =3D opaque;
=C2=A0 =C2=A0 =C2=A0int ret;
=C2=A0
-= =C2=A0 =C2=A0TFR(
- =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D ioctl(aiocb->= aio_fildes, aiocb->ioctl.cmd, aiocb->ioctl.buf)
+ =C2=A0 =C2=A0ret= =3D TEMP_FAILURE_RETRY(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0ioctl(aiocb->ai= o_fildes, aiocb->ioctl.cmd, aiocb->ioctl.buf)
=C2=A0 =C2=A0 =C2=A0= );
=C2=A0 =C2=A0 =C2=A0if (ret =3D=3D -1) {
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0return -errno;
@@ -1472,8 +1472,8 @@ static ssize_t handle_aio= cb_rw_vector(RawPosixAIOData *aiocb)
=C2=A0{
=C2=A0 =C2=A0 =C2=A0ssiz= e_t len;
=C2=A0
- =C2=A0 =C2=A0TFR(
- =C2=A0 =C2=A0 =C2=A0 =C2=A0l= en =3D (aiocb->aio_type & QEMU_AIO_WRITE) ?
+ =C2=A0 =C2=A0len = =3D TEMP_FAILURE_RETRY(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0(aiocb->aio_type= & QEMU_AIO_WRITE) ?
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0qemu_pwritev(aiocb->aio_fildes,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 aiocb->i= o.iov,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 aiocb->io.niov,
@@ -1907,7 +1907,7= @@ static int allocate_first_block(int fd, size_t max_size)
=C2=A0 =C2= =A0 =C2=A0buf =3D qemu_memalign(max_align, write_size);
=C2=A0 =C2=A0 = =C2=A0memset(buf, 0, write_size);
=C2=A0
- =C2=A0 =C2=A0TFR(n =3D pwr= ite(fd, buf, write_size, 0));
+ =C2=A0 =C2=A0n =3D TEMP_FAILURE_RETRY(pw= rite(fd, buf, write_size, 0));
=C2=A0
=C2=A0 =C2=A0 =C2=A0ret =3D (n = =3D=3D -1) ? -errno : 0;
=C2=A0
diff --git a/chardev/char-fd.c b/char= dev/char-fd.c
index cf78454841..1250a63236 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)
=C2=A0{
=C2=A0 =C2= =A0 =C2=A0int fd =3D -1;
=C2=A0
- =C2=A0 =C2=A0TFR(fd =3D qemu_open_o= ld(src, flags, 0666));
+ =C2=A0 =C2=A0fd =3D TEMP_FAILURE_RETRY(qemu_ope= n_old(src, flags, 0666));
=C2=A0 =C2=A0 =C2=A0if (fd =3D=3D -1) {
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0error_setg_file_open(errp, errno, src);
= =C2=A0 =C2=A0 =C2=A0}
diff --git a/chardev/char-pipe.c b/chardev/char-pi= pe.c
index 66d3b85091..a59a055c87 100644
--- a/chardev/char-pipe.c+++ b/chardev/char-pipe.c
@@ -131,8 +131,12 @@ static void qemu_chr_ope= n_pipe(Chardev *chr,
=C2=A0
=C2=A0 =C2=A0 =C2=A0filename_in =3D g_str= dup_printf("%s.in",= filename);
=C2=A0 =C2=A0 =C2=A0filename_out =3D g_strdup_printf("%= s.out", filename);
- =C2=A0 =C2=A0TFR(fd_in =3D qemu_open_old(filen= ame_in, O_RDWR | O_BINARY));
- =C2=A0 =C2=A0TFR(fd_out =3D qemu_open_old= (filename_out, O_RDWR | O_BINARY));
+ =C2=A0 =C2=A0fd_in =3D TEMP_FAILUR= E_RETRY(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_open_old(filename_in, O_RDWR = | O_BINARY)
+ =C2=A0 =C2=A0);
+ =C2=A0 =C2=A0fd_out =3D TEMP_FAILURE_= RETRY(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_open_old(filename_out, O_RDWR |= O_BINARY)
+ =C2=A0 =C2=A0);
=C2=A0 =C2=A0 =C2=A0g_free(filename_in);=
=C2=A0 =C2=A0 =C2=A0g_free(filename_out);
=C2=A0 =C2=A0 =C2=A0if (fd= _in < 0 || fd_out < 0) {
@@ -142,7 +146,9 @@ static void qemu_chr_= open_pipe(Chardev *chr,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (fd_out >= ;=3D 0) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0close(fd_out);=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
- =C2=A0 =C2=A0 =C2=A0 =C2=A0TFR= (fd_in =3D fd_out =3D qemu_open_old(filename, O_RDWR | O_BINARY));
+ =C2= =A0 =C2=A0 =C2=A0 =C2=A0fd_in =3D fd_out =3D TEMP_FAILURE_RETRY(
+ =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_open_old(filename, O_RDWR | O_BI= NARY)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0if (fd_in < 0) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0e= rror_setg_file_open(errp, errno, filename);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0return;
diff --git a/chardev/char-pty.c b/chardev/ch= ar-pty.c
index b2f490bacf..913a98250b 100644
--- a/chardev/char-pty.c=
+++ b/chardev/char-pty.c
@@ -93,7 +93,7 @@ static void pty_chr_updat= e_read_handler(Chardev *chr)
=C2=A0 =C2=A0 =C2=A0pfd.fd =3D fioc->fd;=
=C2=A0 =C2=A0 =C2=A0pfd.events =3D G_IO_OUT;
=C2=A0 =C2=A0 =C2=A0pfd= .revents =3D 0;
- =C2=A0 =C2=A0TFR(rc =3D g_poll(&pfd, 1, 0));
+ = =C2=A0 =C2=A0rc =3D TEMP_FAILURE_RETRY(g_poll(&pfd, 1, 0));
=C2=A0 = =C2=A0 =C2=A0assert(rc >=3D 0);
=C2=A0
=C2=A0 =C2=A0 =C2=A0if (pfd= .revents & G_IO_HUP) {
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-= local.c
index c90ab947ba..6a3b4fac4a 100644
--- a/hw/9pfs/9p-local.c<= br>+++ b/hw/9pfs/9p-local.c
@@ -470,7 +470,7 @@ static ssize_t local_rea= dlink(FsContext *fs_ctx, V9fsPath *fs_path,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0if (fd =3D=3D -1) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0return -1;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
- =C2=A0 =C2=A0 =C2= =A0 =C2=A0TFR(tsize =3D read(fd, (void *)buf, bufsz));
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0tsize =3D TEMP_FAILURE_RETRY(read(fd, (void *)buf, bufsz));=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0close_preserve_errno(fd);
=C2=A0 =C2= =A0 =C2=A0} else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (fs_ctx->exp= ort_flags & V9FS_SM_NONE)) {
@@ -906,7 +906,9 @@ static int local_sy= mlink(FsContext *fs_ctx, const char *oldpath,
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Write the oldpath (targ= et) to the file. */
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0oldpath_size =3D s= trlen(oldpath);
- =C2=A0 =C2=A0 =C2=A0 =C2=A0TFR(write_size =3D write(fd= , (void *)oldpath, oldpath_size));
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0write_si= ze =3D TEMP_FAILURE_RETRY(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0wr= ite(fd, (void *)oldpath, oldpath_size)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0);=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0close_preserve_errno(fd);
=C2=A0
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (write_size !=3D oldpath_size) {
di= ff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index b1c161c035.= .6cd0de8e38 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osde= p.h
@@ -242,8 +242,15 @@ void QEMU_ERROR("code path is reachable&qu= ot;)
=C2=A0#if !defined(ESHUTDOWN)
=C2=A0#define ESHUTDOWN 4099
= =C2=A0#endif
-
-#define TFR(expr) do { if ((expr) !=3D -1) break; } w= hile (errno =3D=3D EINTR)
+#if !defined(TEMP_FAILURE_RETRY)
+#define = TEMP_FAILURE_RETRY(expr) \
+ =C2=A0 =C2=A0(__extension__ =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0\
+ =C2=A0 = =C2=A0 =C2=A0 =C2=A0({ long int __result; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 \=
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 do { =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 \
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0__result =3D (long int) (expressio= n); =C2=A0 =C2=A0 =C2=A0 =C2=A0 \
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }= while (__result =3D=3D -1L && errno =3D=3D EINTR); =C2=A0 =C2=A0 \=
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 __result; }))
+#endif
=C2=A0=
=C2=A0/* time_t may be either 32 or 64 bits depending on the host OS, a= nd
=C2=A0 * can be either signed or unsigned, so we can't just hardc= ode a
diff --git a/net/l2tpv3.c b/net/l2tpv3.c
index adfdbdb84c..cbde= 9332fe 100644
--- a/net/l2tpv3.c
+++ b/net/l2tpv3.c
@@ -240,7 +240= ,7 @@ static ssize_t net_l2tpv3_receive_dgram_iov(NetClientState *nc,
= =C2=A0 =C2=A0 =C2=A0message.msg_control =3D NULL;
=C2=A0 =C2=A0 =C2=A0me= ssage.msg_controllen =3D 0;
=C2=A0 =C2=A0 =C2=A0message.msg_flags =3D 0;=
- =C2=A0 =C2=A0TFR(ret =3D sendmsg(s->fd, &message, 0));
+ = =C2=A0 =C2=A0ret =3D TEMP_FAILURE_RETRY(sendmsg(s->fd, &message, 0))= ;
=C2=A0 =C2=A0 =C2=A0if (ret > 0) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0ret -=3D s->offset;
=C2=A0 =C2=A0 =C2=A0} else if (ret =3D=3D 0= ) {
@@ -283,7 +283,7 @@ static ssize_t net_l2tpv3_receive_dgram(NetClien= tState *nc,
=C2=A0 =C2=A0 =C2=A0message.msg_control =3D NULL;
=C2=A0 = =C2=A0 =C2=A0message.msg_controllen =3D 0;
=C2=A0 =C2=A0 =C2=A0message.m= sg_flags =3D 0;
- =C2=A0 =C2=A0TFR(ret =3D sendmsg(s->fd, &messag= e, 0));
+ =C2=A0 =C2=A0ret =3D TEMP_FAILURE_RETRY(sendmsg(s->fd, &= ;message, 0));
=C2=A0 =C2=A0 =C2=A0if (ret > 0) {
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0ret -=3D s->offset;
=C2=A0 =C2=A0 =C2=A0} else if= (ret =3D=3D 0) {
@@ -430,7 +430,9 @@ static void net_l2tpv3_send(void *= opaque)
=C2=A0
=C2=A0 =C2=A0 =C2=A0msgvec =3D s->msgvec + s->qu= eue_head;
=C2=A0 =C2=A0 =C2=A0if (target_count > 0) {
- =C2=A0 =C2= =A0 =C2=A0 =C2=A0TFR(count =3D recvmmsg(s->fd, msgvec, target_count, MSG= _DONTWAIT, NULL));
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0count =3D TEMP_FAILURE_R= ETRY(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0recvmmsg(s->fd, msgv= ec, target_count, MSG_DONTWAIT, NULL)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0);=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (count < 0) {
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Recv error - we still need to flush packe= ts here,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 * (re)set queu= e head to current position
diff --git a/net/socket.c b/net/socket.c
i= ndex a3397660c2..cfb893b183 100644
--- a/net/socket.c
+++ b/net/socke= t.c
@@ -117,8 +117,8 @@ static ssize_t net_socket_receive_dgram(NetClien= tState *nc, const uint8_t *buf,
=C2=A0 =C2=A0 =C2=A0NetSocketState *s = =3D DO_UPCAST(NetSocketState, nc, nc);
=C2=A0 =C2=A0 =C2=A0ssize_t ret;<= br>=C2=A0
- =C2=A0 =C2=A0TFR(
- =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D s-= >dgram_dst.sin_family !=3D AF_UNIX ?
+ =C2=A0 =C2=A0ret =3D TEMP_FAIL= URE_RETRY(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0s->dgram_dst.sin_family !=3D = AF_UNIX ?
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sendto(s->f= d, buf, size, 0,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 (struct sockaddr *)&s->dgram_dst,
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 sizeo= f(s->dgram_dst)) :
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
inde= x 005ce05c6e..720090244e 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd= .c
@@ -56,7 +56,7 @@ int tap_open(char *ifname, int ifname_size, int *vn= et_hdr,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} else {
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0snprintf(dname, sizeof dname, "/dev/tap= %d", i);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
- =C2=A0 =C2=A0 =C2= =A0 =C2=A0TFR(fd =3D open(dname, O_RDWR));
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0= fd =3D TEMP_FAILURE_RETRY(open(dname, O_RDWR));
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0if (fd >=3D 0) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0break;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
@@ -111,7 +111,7 @@ = static int tap_open_clone(char *ifname, int ifname_size, Error **errp)
= =C2=A0 =C2=A0 =C2=A0int fd, s, ret;
=C2=A0 =C2=A0 =C2=A0struct ifreq ifr= ;
=C2=A0
- =C2=A0 =C2=A0TFR(fd =3D open(PATH_NET_TAP, O_RDWR));
+ = =C2=A0 =C2=A0fd =3D TEMP_FAILURE_RETRY(open(PATH_NET_TAP, O_RDWR));
=C2= =A0 =C2=A0 =C2=A0if (fd < 0) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0erro= r_setg_errno(errp, errno, "could not open %s", PATH_NET_TAP);
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -1;
@@ -159,7 +159,7 @@ int tap= _open(char *ifname, int ifname_size, int *vnet_hdr,
=C2=A0 =C2=A0 =C2=A0= if (ifname[0] !=3D '\0') {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0cha= r dname[100];
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0snprintf(dname, sizeof d= name, "/dev/%s", ifname);
- =C2=A0 =C2=A0 =C2=A0 =C2=A0TFR(fd = =3D open(dname, O_RDWR));
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0fd =3D TEMP_FAILU= RE_RETRY(open(dname, O_RDWR));
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (fd = < 0 && errno !=3D ENOENT) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0error_setg_errno(errp, errno, "could not open %s"= ;, dname);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -1;diff --git a/net/tap-linux.c b/net/tap-linux.c
index 304ff45071..bf3ce4= 4329 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,
=C2= =A0 =C2=A0 =C2=A0int len =3D sizeof(struct virtio_net_hdr);
=C2=A0 =C2= =A0 =C2=A0unsigned int features;
=C2=A0
- =C2=A0 =C2=A0TFR(fd =3D ope= n(PATH_NET_TUN, O_RDWR));
+ =C2=A0 =C2=A0fd =3D TEMP_FAILURE_RETRY(open(= PATH_NET_TUN, O_RDWR));
=C2=A0 =C2=A0 =C2=A0if (fd < 0) {
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0error_setg_errno(errp, errno, "could not op= en %s", PATH_NET_TUN);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -1;=
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index a44f8805c2.= .73e0e9f196 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)
=C2=A0 =C2=A0 =C2=A0if( ip_fd )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = close(ip_fd);
=C2=A0
- =C2=A0 =C2=A0TFR(ip_fd =3D open("/dev/udp= ", O_RDWR, 0));
+ =C2=A0 =C2=A0ip_fd =3D TEMP_FAILURE_RETRY(open(&q= uot;/dev/udp", O_RDWR, 0));
=C2=A0 =C2=A0 =C2=A0if (ip_fd < 0) {=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0error_setg(errp, "Can't open= /dev/ip (actually /dev/udp)");
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0r= eturn -1;
=C2=A0 =C2=A0 =C2=A0}
=C2=A0
- =C2=A0 =C2=A0TFR(tap_fd = =3D open("/dev/tap", O_RDWR, 0));
+ =C2=A0 =C2=A0tap_fd =3D TE= MP_FAILURE_RETRY(open("/dev/tap", O_RDWR, 0));
=C2=A0 =C2=A0 = =C2=A0if (tap_fd < 0) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0error_setg(= errp, "Can't open /dev/tap");
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0return -1;
@@ -104,7 +104,7 @@ static int tap_alloc(char *dev, siz= e_t dev_size, Error **errp)
=C2=A0 =C2=A0 =C2=A0if ((ppa =3D ioctl (tap_= fd, I_STR, &strioc_ppa)) < 0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0e= rror_report("Can't assign new interface");
=C2=A0
- =C2= =A0 =C2=A0TFR(if_fd =3D open("/dev/tap", O_RDWR, 0));
+ =C2=A0= =C2=A0if_fd =3D TEMP_FAILURE_RETRY(open("/dev/tap", O_RDWR, 0));=
=C2=A0 =C2=A0 =C2=A0if (if_fd < 0) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0error_setg(errp, "Can't open /dev/tap (2)");
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0return -1;
@@ -137,7 +137,7 @@ static int tap= _alloc(char *dev, size_t dev_size, Error **errp)
=C2=A0 =C2=A0 =C2=A0if = (ioctl (ip_fd, I_PUSH, "arp") < 0)
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0error_report("Can't push ARP module (3)");
=C2= =A0 =C2=A0 =C2=A0/* Open arp_fd */
- =C2=A0 =C2=A0TFR(arp_fd =3D open (&= quot;/dev/tap", O_RDWR, 0));
+ =C2=A0 =C2=A0arp_fd =3D TEMP_FAILURE= _RETRY(open("/dev/tap", O_RDWR, 0));
=C2=A0 =C2=A0 =C2=A0if (a= rp_fd < 0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0error_report("Can&#= 39;t open %s", "/dev/tap");
=C2=A0
diff --git a/net/ta= p.c b/net/tap.c
index b047eca8b5..dfd220a184 100644
--- a/net/tap.c+++ b/net/tap.c
@@ -102,7 +102,7 @@ static ssize_t tap_write_packet(TA= PState *s, const struct iovec *iov, int iovcnt
=C2=A0{
=C2=A0 =C2=A0 = =C2=A0ssize_t len;
=C2=A0
- =C2=A0 =C2=A0TFR(len =3D writev(s->fd,= iov, iovcnt));
+ =C2=A0 =C2=A0len =3D TEMP_FAILURE_RETRY(writev(s->f= d, iov, iovcnt));
=C2=A0
=C2=A0 =C2=A0 =C2=A0if (len =3D=3D -1 &&= amp; errno =3D=3D EAGAIN) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tap_write_= poll(s, true);
@@ -575,7 +575,7 @@ static int net_bridge_run_helper(cons= t char *helper, const char *bridge,
=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0close(sv[1]);
=C2=A0
- =C2=A0 =C2=A0 =C2=A0 =C2=A0TFR(fd = =3D recv_fd(sv[0]));
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0fd =3D TEMP_FAILURE_RE= TRY(recv_fd(sv[0]));
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0saved_errno =3D e= rrno;
=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0close(sv[0]);
@@ -6= 47,8 +647,10 @@ static int net_tap_init(const NetdevTapOptions *tap, int *v= net_hdr,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0vnet_hdr_required =3D 0;
= =C2=A0 =C2=A0 =C2=A0}
=C2=A0
- =C2=A0 =C2=A0TFR(fd =3D tap_open(ifnam= e, ifname_sz, vnet_hdr, vnet_hdr_required,
- =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0mq_required, errp));
+ = =C2=A0 =C2=A0fd =3D TEMP_FAILURE_RETRY(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0tap= _open(ifname, ifname_sz, vnet_hdr, vnet_hdr_required,
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0mq_required, = errp)
+ =C2=A0 =C2=A0);
=C2=A0 =C2=A0 =C2=A0if (fd < 0) {
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -1;
=C2=A0 =C2=A0 =C2=A0}
diff = --git a/os-posix.c b/os-posix.c
index 321fc4bd13..59cac65585 100644
-= -- a/os-posix.c
+++ b/os-posix.c
@@ -266,7 +266,7 @@ void os_setup_po= st(void)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0error_report(&q= uot;not able to chdir to /: %s", strerror(errno));
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0exit(1);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0}
- =C2=A0 =C2=A0 =C2=A0 =C2=A0TFR(fd =3D qemu_open_old("/dev= /null", O_RDWR));
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0fd =3D TEMP_FAILURE_= RETRY(qemu_open_old("/dev/null", O_RDWR));
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0if (fd =3D=3D -1) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0exit(1);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
diff --git = a/qga/commands-posix.c b/qga/commands-posix.c
index 90f83aa9b6..feb0fab8= 07 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@= -68,7 +68,7 @@ static void ga_wait_child(pid_t pid, int *status, Error **e= rrp)
=C2=A0
=C2=A0 =C2=A0 =C2=A0*status =3D 0;
=C2=A0
- =C2=A0 = =C2=A0TFR(rpid =3D waitpid(pid, status, 0));
+ =C2=A0 =C2=A0rpid =3D TEM= P_FAILURE_RETRY(waitpid(pid, status, 0));
=C2=A0
=C2=A0 =C2=A0 =C2=A0= if (rpid =3D=3D -1) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0error_setg_errno= (errp, errno, "failed to wait for child (pid: %d)",
diff --git= a/semihosting/syscalls.c b/semihosting/syscalls.c
index 025c08147a..0cb= ef7d22b 100644
--- a/semihosting/syscalls.c
+++ b/semihosting/syscall= s.c
@@ -317,7 +317,7 @@ static void host_read(CPUState *cs, gdb_syscall_= complete_cb complete,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0complete(cs, -1,= EFAULT);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
=C2=A0 =C2=A0 =C2= =A0}
- =C2=A0 =C2=A0TFR(ret =3D read(gf->hostfd, ptr, len));
+ =C2= =A0 =C2=A0ret =3D TEMP_FAILURE_RETRY(read(gf->hostfd, ptr, len));
=C2= =A0 =C2=A0 =C2=A0if (ret =3D=3D -1) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= complete(cs, -1, errno);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unlock_user(p= tr, buf, 0);
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.= c
index d4022966b3..4a12824dc4 100644
--- a/tests/qtest/libqtest.c+++ b/tests/qtest/libqtest.c
@@ -102,8 +102,8 @@ static int socket_acce= pt(int sock)
=C2=A0 =C2=A0 =C2=A0}
=C2=A0
=C2=A0 =C2=A0 =C2=A0addr= len =3D sizeof(addr);
- =C2=A0 =C2=A0TFR(
- =C2=A0 =C2=A0 =C2=A0 =C2= =A0ret =3D accept(sock, (struct sockaddr *)&addr, &addrlen)
+ = =C2=A0 =C2=A0ret =3D TEMP_FAILURE_RETRY(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0ac= cept(sock, (struct sockaddr *)&addr, &addrlen)
=C2=A0 =C2=A0 =C2= =A0);
=C2=A0 =C2=A0 =C2=A0if (ret =3D=3D -1) {
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0fprintf(stderr, "%s failed: %s\n", __func__, strerro= r(errno));
@@ -140,7 +140,7 @@ void qtest_kill_qemu(QTestState *s)
= =C2=A0 =C2=A0 =C2=A0/* Skip wait if qtest_probe_child already reaped. =C2= =A0*/
=C2=A0 =C2=A0 =C2=A0if (pid !=3D -1) {
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0kill(pid, SIGTERM);
- =C2=A0 =C2=A0 =C2=A0 =C2=A0TFR(pid =3D w= aitpid(s->qemu_pid, &s->wstatus, 0));
+ =C2=A0 =C2=A0 =C2=A0 = =C2=A0pid =3D TEMP_FAILURE_RETRY(waitpid(s->qemu_pid, &s->wstatus= , 0));
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0assert(pid =3D=3D s->qemu_pi= d);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0s->qemu_pid =3D -1;
=C2=A0 = =C2=A0 =C2=A0}
@@ -578,8 +578,8 @@ int qtest_socket_server(const char *s= ocket_path)
=C2=A0 =C2=A0 =C2=A0addr.sun_family =3D AF_UNIX;
=C2=A0 = =C2=A0 =C2=A0snprintf(addr.sun_path, sizeof(addr.sun_path), "%s",= socket_path);
=C2=A0
- =C2=A0 =C2=A0TFR(
- =C2=A0 =C2=A0 =C2=A0 = =C2=A0ret =3D bind(sock, (struct sockaddr *)&addr, sizeof(addr))
+ = =C2=A0 =C2=A0ret =3D TEMP_FAILURE_RETRY(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0bi= nd(sock, (struct sockaddr *)&addr, sizeof(addr))
=C2=A0 =C2=A0 =C2= =A0);
=C2=A0 =C2=A0 =C2=A0g_assert_cmpint(ret, !=3D, -1);
=C2=A0 =C2= =A0 =C2=A0ret =3D listen(sock, 1);
diff --git a/tests/vhost-user-bridge.= c b/tests/vhost-user-bridge.c
index 4d8f933ed5..624a211f3d 100644
---= a/tests/vhost-user-bridge.c
+++ b/tests/vhost-user-bridge.c
@@ -331,= 7 +331,9 @@ vubr_backend_recv_cb(int sock, void *ctx)
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0.msg_iovlen =3D num,
=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0.msg_flags =3D MSG_DONTWAIT,
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0};
- =C2=A0 =C2=A0 =C2=A0 =C2=A0TFR(ret =3D recvmsg(= vubr->backend_udp_sock, &msg, 0));
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0r= et =3D TEMP_FAILURE_RETRY(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0recvmsg(vubr->backend_udp_sock, &msg, 0)
+ =C2=A0 = =C2=A0 =C2=A0 =C2=A0);
=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (i= =3D=3D 0) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0iov_restore= _front(elem->in_sg, sg, hdrlen);
diff --git a/util/main-loop.c b/util= /main-loop.c
index 58e14db2d4..5f65f928bd 100644
--- a/util/main-loop= .c
+++ b/util/main-loop.c
@@ -64,7 +64,7 @@ static void sigfd_handler= (void *opaque)
=C2=A0 =C2=A0 =C2=A0ssize_t len;
=C2=A0
=C2=A0 =C2= =A0 =C2=A0while (1) {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0TFR(len =3D read(fd, = &info, sizeof(info)));
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0len =3D TEMP_FAI= LURE_RETRY(read(fd, &info, sizeof(info)));
=C2=A0
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0if (len =3D=3D -1 && errno =3D=3D EAGAIN) {
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break;
diff --git a/util= /osdep.c b/util/osdep.c
index d35c473ac7..2c287e75e7 100644
--- a/uti= l/osdep.c
+++ b/util/osdep.c
@@ -244,7 +244,7 @@ static int qemu_lock= _fcntl(int fd, int64_t start, int64_t len, int fl_type)
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0.l_type =C2=A0 =3D fl_type,
=C2=A0 =C2=A0 =C2=A0};=C2=A0 =C2=A0 =C2=A0qemu_probe_lock_ops();
- =C2=A0 =C2=A0TFR(ret =3D = fcntl(fd, fcntl_op_setlk, &fl));
+ =C2=A0 =C2=A0ret =3D TEMP_FAILURE= _RETRY(fcntl(fd, fcntl_op_setlk, &fl));
=C2=A0 =C2=A0 =C2=A0return r= et =3D=3D -1 ? -errno : 0;
=C2=A0}
=C2=A0
diff --git a/util/vfio-h= elpers.c b/util/vfio-helpers.c
index c878be1c5f..e1422666eb 100644
--= - a/util/vfio-helpers.c
+++ b/util/vfio-helpers.c
@@ -240,8 +240,8 @@= static int qemu_vfio_pci_read_config(QEMUVFIOState *s, void *buf,
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0s->config_region_= info.offset,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0s-= >config_region_info.size);
=C2=A0 =C2=A0 =C2=A0assert(QEMU_IS_ALIGNED= (s->config_region_info.offset + ofs, size));
- =C2=A0 =C2=A0TFR(
-= =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D pread(s->device, buf, size, s->co= nfig_region_info.offset + ofs)
+ =C2=A0 =C2=A0ret =3D TEMP_FAILURE_RETRY= (
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0pread(s->device, buf, size, s->conf= ig_region_info.offset + ofs)
=C2=A0 =C2=A0 =C2=A0);
=C2=A0 =C2=A0 =C2= =A0return ret =3D=3D size ? 0 : -errno;
=C2=A0}
@@ -254,8 +254,8 @@ s= tatic int qemu_vfio_pci_write_config(QEMUVFIOState *s, void *buf, int size,= int
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 s->co= nfig_region_info.offset,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 s->config_region_info.size);
=C2=A0 =C2=A0 =C2=A0assert= (QEMU_IS_ALIGNED(s->config_region_info.offset + ofs, size));
- =C2=A0= =C2=A0TFR(
- =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D pwrite(s->device, bu= f, size, s->config_region_info.offset + ofs)
+ =C2=A0 =C2=A0ret =3D T= EMP_FAILURE_RETRY(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0pwrite(s->device, buf= , size, s->config_region_info.offset + ofs)
=C2=A0 =C2=A0 =C2=A0);=C2=A0 =C2=A0 =C2=A0return ret =3D=3D size ? 0 : -errno;
=C2=A0}
-- =
2.37.1


On Mon, Aug 8, 2022 at 9:00 PM Nikita Ivanov <nivanov@cloudlinux.com= > wrote:
=
Hi!
During our discussion, I found that I've missed= a couple of places where TFR() macro could be applied. Here is an updated = first patch:

From 8a68f50aac4a8549f416b9350cf339cf0501a712 Mon Sep 1= 7 00:00:00 2001
From: Nikita Ivanov <nivanov@cloudlinux.com>
Date: Wed, 3 = Aug 2022 12:54:00 +0300
Subject: [PATCH] error handling: Use TFR() macro= where applicable

There is a defined TFR() macro in qemu/osdep.h whi= ch
handles the same while loop.
Resolves: https://gitlab.com/qem= u-project/qemu/-/issues/415

Signed-off-by: Nikita Ivanov <nivanov@cloudlinux= .com>
---
=C2=A0block/file-posix.c =C2=A0 =C2=A0 =C2=A0 =C2=A0= | 39 ++++++++++++++++++---------------------
=C2=A0chardev/char-pty.c = =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A04 +---
=C2=A0hw/9pfs/9p-local.c =C2= =A0 =C2=A0 =C2=A0 =C2=A0| =C2=A08 ++------
=C2=A0net/l2tpv3.c =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 15 +++------------
=C2=A0net/soc= ket.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 16 +++++++---------=
=C2=A0net/tap.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= | =C2=A08 ++------
=C2=A0qga/commands-posix.c =C2=A0 =C2=A0 =C2=A0| =C2= =A04 +---
=C2=A0semihosting/syscalls.c =C2=A0 =C2=A0| =C2=A04 +---
= =C2=A0tests/qtest/libqtest.c =C2=A0 =C2=A0| 14 +++++++-------
=C2=A0test= s/vhost-user-bridge.c | =C2=A04 +---
=C2=A0util/main-loop.c =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0| =C2=A04 +---
=C2=A0util/osdep.c =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A04 +---
=C2=A0util/vfio-helpers= .c =C2=A0 =C2=A0 =C2=A0 | 12 ++++++------
=C2=A013 files changed, 51 ins= ertions(+), 85 deletions(-)

diff --git a/block/file-posix.c b/block/= file-posix.c
index 48cd096624..0786cb76f9 100644
--- a/block/file-pos= ix.c
+++ b/block/file-posix.c
@@ -1238,9 +1238,9 @@ static int hdev_g= et_max_segments(int fd, struct stat *st)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0ret =3D -errno;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto out;
=C2=A0= =C2=A0 =C2=A0}
- =C2=A0 =C2=A0do {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0ret = =3D read(sysfd, buf, sizeof(buf) - 1);
- =C2=A0 =C2=A0} while (ret =3D= =3D -1 && errno =3D=3D EINTR);
+ =C2=A0 =C2=A0TFR(
+ =C2=A0 = =C2=A0 =C2=A0 =C2=A0ret =3D read(sysfd, buf, sizeof(buf) - 1)
+ =C2=A0 = =C2=A0);
=C2=A0 =C2=A0 =C2=A0if (ret < 0) {
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0ret =3D -errno;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto out;=
@@ -1388,9 +1388,9 @@ static int handle_aiocb_ioctl(void *opaque)
= =C2=A0 =C2=A0 =C2=A0RawPosixAIOData *aiocb =3D opaque;
=C2=A0 =C2=A0 =C2= =A0int ret;
=C2=A0
- =C2=A0 =C2=A0do {
- =C2=A0 =C2=A0 =C2=A0 =C2= =A0ret =3D ioctl(aiocb->aio_fildes, aiocb->ioctl.cmd, aiocb->ioctl= .buf);
- =C2=A0 =C2=A0} while (ret =3D=3D -1 && errno =3D=3D EIN= TR);
+ =C2=A0 =C2=A0TFR(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D ioctl(a= iocb->aio_fildes, aiocb->ioctl.cmd, aiocb->ioctl.buf)
+ =C2=A0 = =C2=A0);
=C2=A0 =C2=A0 =C2=A0if (ret =3D=3D -1) {
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0return -errno;
=C2=A0 =C2=A0 =C2=A0}
@@ -1472,18 +14= 72,17 @@ static ssize_t handle_aiocb_rw_vector(RawPosixAIOData *aiocb)
= =C2=A0{
=C2=A0 =C2=A0 =C2=A0ssize_t len;
=C2=A0
- =C2=A0 =C2=A0do = {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0if (aiocb->aio_type & QEMU_AIO_WRI= TE)
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0len =3D qemu_pwritev(aioc= b->aio_fildes,
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 aiocb->io.iov,
-= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 aiocb->io.niov,
- =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 aiocb->aio_offset);
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 else<= br>- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0len =3D qemu_preadv(aiocb->= ;aio_fildes,
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0aiocb->io.iov,
- =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0aiocb->io.niov,
- =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0aiocb->aio_offset);
- =C2=A0 =C2=A0} while (len =3D=3D -1 &= & errno =3D=3D EINTR);
+ =C2=A0 =C2=A0TFR(
+ =C2=A0 =C2=A0 =C2=A0= =C2=A0len =3D (aiocb->aio_type & QEMU_AIO_WRITE) ?
+ =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_pwritev(aiocb->aio_fildes,
+ =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 aiocb->io.iov,
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 aiocb->io.niov,
= + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 aiocb->aio_offset) :
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0qemu_preadv(aiocb->aio_fildes,
+ =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0aiocb-= >io.iov,
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0aiocb->io.niov,
+ =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ai= ocb->aio_offset)
+ =C2=A0 =C2=A0);
=C2=A0
=C2=A0 =C2=A0 =C2=A0i= f (len =3D=3D -1) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -errno;
= @@ -1908,9 +1907,7 @@ static int allocate_first_block(int fd, size_t max_si= ze)
=C2=A0 =C2=A0 =C2=A0buf =3D qemu_memalign(max_align, write_size);=C2=A0 =C2=A0 =C2=A0memset(buf, 0, write_size);
=C2=A0
- =C2=A0 =C2= =A0do {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0n =3D pwrite(fd, buf, write_size, 0= );
- =C2=A0 =C2=A0} while (n =3D=3D -1 && errno =3D=3D EINTR);+ =C2=A0 =C2=A0TFR(n =3D pwrite(fd, buf, write_size, 0));
=C2=A0
= =C2=A0 =C2=A0 =C2=A0ret =3D (n =3D=3D -1) ? -errno : 0;
=C2=A0
diff -= -git a/chardev/char-pty.c b/chardev/char-pty.c
index 53f25c6bbd..b2f490b= acf 100644
--- a/chardev/char-pty.c
+++ b/chardev/char-pty.c
@@ -9= 3,9 +93,7 @@ static void pty_chr_update_read_handler(Chardev *chr)
=C2= =A0 =C2=A0 =C2=A0pfd.fd =3D fioc->fd;
=C2=A0 =C2=A0 =C2=A0pfd.events = =3D G_IO_OUT;
=C2=A0 =C2=A0 =C2=A0pfd.revents =3D 0;
- =C2=A0 =C2=A0d= o {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0rc =3D g_poll(&pfd, 1, 0);
- =C2= =A0 =C2=A0} while (rc =3D=3D -1 && errno =3D=3D EINTR);
+ =C2=A0= =C2=A0TFR(rc =3D g_poll(&pfd, 1, 0));
=C2=A0 =C2=A0 =C2=A0assert(rc= >=3D 0);
=C2=A0
=C2=A0 =C2=A0 =C2=A0if (pfd.revents & G_IO_HU= P) {
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index d42ce= 6d8b8..c90ab947ba 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-lo= cal.c
@@ -470,9 +470,7 @@ static ssize_t local_readlink(FsContext *fs_ct= x, V9fsPath *fs_path,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (fd =3D=3D -1= ) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -1;
=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0}
- =C2=A0 =C2=A0 =C2=A0 =C2=A0do {
- =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tsize =3D read(fd, (void *)buf, bufsz= );
- =C2=A0 =C2=A0 =C2=A0 =C2=A0} while (tsize =3D=3D -1 && errn= o =3D=3D EINTR);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0TFR(tsize =3D read(fd, (vo= id *)buf, bufsz));
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0close_preserve_errn= o(fd);
=C2=A0 =C2=A0 =C2=A0} else if ((fs_ctx->export_flags & V9F= S_SM_PASSTHROUGH) ||
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (fs_ctx->export_flags & V9FS_SM_NONE)) {
@@ -908,9 +906,7 = @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Wr= ite the oldpath (target) to the file. */
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0oldpath_size =3D strlen(oldpath);
- =C2=A0 =C2=A0 =C2=A0 =C2=A0do {- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0write_size =3D write(fd, (void= *)oldpath, oldpath_size);
- =C2=A0 =C2=A0 =C2=A0 =C2=A0} while (write_s= ize =3D=3D -1 && errno =3D=3D EINTR);
+ =C2=A0 =C2=A0 =C2=A0 =C2= =A0TFR(write_size =3D write(fd, (void *)oldpath, oldpath_size));
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0close_preserve_errno(fd);
=C2=A0
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0if (write_size !=3D oldpath_size) {
diff --gi= t a/net/l2tpv3.c b/net/l2tpv3.c
index af373e5c30..adfdbdb84c 100644
-= -- a/net/l2tpv3.c
+++ b/net/l2tpv3.c
@@ -240,9 +240,7 @@ static ssize= _t net_l2tpv3_receive_dgram_iov(NetClientState *nc,
=C2=A0 =C2=A0 =C2=A0= message.msg_control =3D NULL;
=C2=A0 =C2=A0 =C2=A0message.msg_controllen= =3D 0;
=C2=A0 =C2=A0 =C2=A0message.msg_flags =3D 0;
- =C2=A0 =C2=A0d= o {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D sendmsg(s->fd, &message,= 0);
- =C2=A0 =C2=A0} while ((ret =3D=3D -1) && (errno =3D=3D EI= NTR));
+ =C2=A0 =C2=A0TFR(ret =3D sendmsg(s->fd, &message, 0));=C2=A0 =C2=A0 =C2=A0if (ret > 0) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0ret -=3D s->offset;
=C2=A0 =C2=A0 =C2=A0} else if (ret =3D=3D 0) {=
@@ -285,9 +283,7 @@ static ssize_t net_l2tpv3_receive_dgram(NetClientSt= ate *nc,
=C2=A0 =C2=A0 =C2=A0message.msg_control =3D NULL;
=C2=A0 =C2= =A0 =C2=A0message.msg_controllen =3D 0;
=C2=A0 =C2=A0 =C2=A0message.msg_= flags =3D 0;
- =C2=A0 =C2=A0do {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D= sendmsg(s->fd, &message, 0);
- =C2=A0 =C2=A0} while ((ret =3D=3D= -1) && (errno =3D=3D EINTR));
+ =C2=A0 =C2=A0TFR(ret =3D sendms= g(s->fd, &message, 0));
=C2=A0 =C2=A0 =C2=A0if (ret > 0) {
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret -=3D s->offset;
=C2=A0 =C2=A0 = =C2=A0} else if (ret =3D=3D 0) {
@@ -434,12 +430,7 @@ static void net_l2= tpv3_send(void *opaque)
=C2=A0
=C2=A0 =C2=A0 =C2=A0msgvec =3D s->m= sgvec + s->queue_head;
=C2=A0 =C2=A0 =C2=A0if (target_count > 0) {=
- =C2=A0 =C2=A0 =C2=A0 =C2=A0do {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0count =3D recvmmsg(
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0s->fd,
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0msgvec,
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0target_count, MSG_DONTWAIT, NULL);
- =C2=A0 =C2=A0 =C2=A0 =C2=A0} = while ((count =3D=3D -1) && (errno =3D=3D EINTR));
+ =C2=A0 =C2= =A0 =C2=A0 =C2=A0TFR(count =3D recvmmsg(s->fd, msgvec, target_count, MSG= _DONTWAIT, NULL));
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (count < 0) {=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Recv error - we stil= l need to flush packets here,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 * (re)set queue head to current position
diff --git a/net/socket.= c b/net/socket.c
index bfd8596250..a3397660c2 100644
--- a/net/socket= .c
+++ b/net/socket.c
@@ -117,15 +117,13 @@ static ssize_t net_socket= _receive_dgram(NetClientState *nc, const uint8_t *buf,
=C2=A0 =C2=A0 =C2= =A0NetSocketState *s =3D DO_UPCAST(NetSocketState, nc, nc);
=C2=A0 =C2= =A0 =C2=A0ssize_t ret;
=C2=A0
- =C2=A0 =C2=A0do {
- =C2=A0 =C2=A0 = =C2=A0 =C2=A0if (s->dgram_dst.sin_family !=3D AF_UNIX) {
- =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D sendto(s->fd, buf, size, 0,
- = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (struct sockaddr *)&s->dgram_dst,
- =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 sizeof(s= ->dgram_dst));
- =C2=A0 =C2=A0 =C2=A0 =C2=A0} else {
- =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D send(s->fd, buf, size, 0);
- = =C2=A0 =C2=A0 =C2=A0 =C2=A0}
- =C2=A0 =C2=A0} while (ret =3D=3D -1 &= & errno =3D=3D EINTR);
+ =C2=A0 =C2=A0TFR(
+ =C2=A0 =C2=A0 =C2=A0= =C2=A0ret =3D s->dgram_dst.sin_family !=3D AF_UNIX ?
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0sendto(s->fd, buf, size, 0,
+ =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (struct sockadd= r *)&s->dgram_dst,
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 sizeof(s->dgram_dst)) :
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0send(s->fd, buf, size, 0)
+ =C2=A0 =C2=A0)= ;
=C2=A0
=C2=A0 =C2=A0 =C2=A0if (ret =3D=3D -1 && errno =3D= =3D EAGAIN) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0net_socket_write_poll(s,= true);
diff --git a/net/tap.c b/net/tap.c
index b3ddfd4a74..b047eca8= b5 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -102,9 +102,7 @@ stat= ic ssize_t tap_write_packet(TAPState *s, const struct iovec *iov, int iovcn= t
=C2=A0{
=C2=A0 =C2=A0 =C2=A0ssize_t len;
=C2=A0
- =C2=A0 =C2= =A0do {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0len =3D writev(s->fd, iov, iovcn= t);
- =C2=A0 =C2=A0} while (len =3D=3D -1 && errno =3D=3D EINTR)= ;
+ =C2=A0 =C2=A0TFR(len =3D writev(s->fd, iov, iovcnt));
=C2=A0=C2=A0 =C2=A0 =C2=A0if (len =3D=3D -1 && errno =3D=3D EAGAIN) {=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tap_write_poll(s, true);
@@ -577,9 += 575,7 @@ static int net_bridge_run_helper(const char *helper, const char *b= ridge,
=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0close(sv[1]);
=C2= =A0
- =C2=A0 =C2=A0 =C2=A0 =C2=A0do {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0fd =3D recv_fd(sv[0]);
- =C2=A0 =C2=A0 =C2=A0 =C2=A0} while= (fd =3D=3D -1 && errno =3D=3D EINTR);
+ =C2=A0 =C2=A0 =C2=A0 = =C2=A0TFR(fd =3D recv_fd(sv[0]));
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0save= d_errno =3D errno;
=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0close(sv[= 0]);
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 9= 54efed01b..90f83aa9b6 100644
--- a/qga/commands-posix.c
+++ b/qga/com= mands-posix.c
@@ -68,9 +68,7 @@ static void ga_wait_child(pid_t pid, int= *status, Error **errp)
=C2=A0
=C2=A0 =C2=A0 =C2=A0*status =3D 0;
= =C2=A0
- =C2=A0 =C2=A0do {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0rpid =3D wait= pid(pid, status, 0);
- =C2=A0 =C2=A0} while (rpid =3D=3D -1 && e= rrno =3D=3D EINTR);
+ =C2=A0 =C2=A0TFR(rpid =3D waitpid(pid, status, 0))= ;
=C2=A0
=C2=A0 =C2=A0 =C2=A0if (rpid =3D=3D -1) {
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0error_setg_errno(errp, errno, "failed to wait for = child (pid: %d)",
diff --git a/semihosting/syscalls.c b/semihosting= /syscalls.c
index 508a0ad88c..025c08147a 100644
--- a/semihosting/sys= calls.c
+++ b/semihosting/syscalls.c
@@ -317,9 +317,7 @@ static void = host_read(CPUState *cs, gdb_syscall_complete_cb complete,
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0complete(cs, -1, EFAULT);
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0return;
=C2=A0 =C2=A0 =C2=A0}
- =C2=A0 =C2=A0do {
- =C2= =A0 =C2=A0 =C2=A0 =C2=A0ret =3D read(gf->hostfd, ptr, len);
- =C2=A0 = =C2=A0} while (ret =3D=3D -1 && errno =3D=3D EINTR);
+ =C2=A0 = =C2=A0TFR(ret =3D read(gf->hostfd, ptr, len));
=C2=A0 =C2=A0 =C2=A0if= (ret =3D=3D -1) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0complete(cs, -1, er= rno);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unlock_user(ptr, buf, 0);
dif= f --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 8c159eac= f5..d4022966b3 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/= libqtest.c
@@ -101,10 +101,10 @@ static int socket_accept(int sock)
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -1;
=C2=A0 =C2=A0 =C2=A0}
= =C2=A0
- =C2=A0 =C2=A0do {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0addrlen =3D s= izeof(addr);
- =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D accept(sock, (struct s= ockaddr *)&addr, &addrlen);
- =C2=A0 =C2=A0} while (ret =3D=3D -= 1 && errno =3D=3D EINTR);
+ =C2=A0 =C2=A0addrlen =3D sizeof(addr= );
+ =C2=A0 =C2=A0TFR(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D accept(so= ck, (struct sockaddr *)&addr, &addrlen)
+ =C2=A0 =C2=A0);
=C2= =A0 =C2=A0 =C2=A0if (ret =3D=3D -1) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno));=C2=A0 =C2=A0 =C2=A0}
@@ -578,9 +578,9 @@ int qtest_socket_server(const= char *socket_path)
=C2=A0 =C2=A0 =C2=A0addr.sun_family =3D AF_UNIX;
= =C2=A0 =C2=A0 =C2=A0snprintf(addr.sun_path, sizeof(addr.sun_path), "%s= ", socket_path);
=C2=A0
- =C2=A0 =C2=A0do {
- =C2=A0 =C2=A0 = =C2=A0 =C2=A0ret =3D bind(sock, (struct sockaddr *)&addr, sizeof(addr))= ;
- =C2=A0 =C2=A0} while (ret =3D=3D -1 && errno =3D=3D EINTR);<= br>+ =C2=A0 =C2=A0TFR(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D bind(sock, (= struct sockaddr *)&addr, sizeof(addr))
+ =C2=A0 =C2=A0);
=C2=A0 = =C2=A0 =C2=A0g_assert_cmpint(ret, !=3D, -1);
=C2=A0 =C2=A0 =C2=A0ret =3D= listen(sock, 1);
=C2=A0 =C2=A0 =C2=A0g_assert_cmpint(ret, !=3D, -1);diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
inde= x 9b1dab2f28..4d8f933ed5 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)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0.msg_io= vlen =3D num,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0.msg_flags= =3D MSG_DONTWAIT,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0};
- =C2=A0 =C2= =A0 =C2=A0 =C2=A0do {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D= recvmsg(vubr->backend_udp_sock, &msg, 0);
- =C2=A0 =C2=A0 =C2=A0= =C2=A0} while (ret =3D=3D -1 && (errno =3D=3D EINTR));
+ =C2=A0= =C2=A0 =C2=A0 =C2=A0TFR(ret =3D recvmsg(vubr->backend_udp_sock, &ms= g, 0));
=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (i =3D=3D 0) {=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0iov_restore_front(elem->= ;in_sg, sg, hdrlen);
diff --git a/util/main-loop.c b/util/main-loop.cindex f00a25451b..58e14db2d4 100644
--- a/util/main-loop.c
+++ b/uti= l/main-loop.c
@@ -64,9 +64,7 @@ static void sigfd_handler(void *opaque)<= br>=C2=A0 =C2=A0 =C2=A0ssize_t len;
=C2=A0
=C2=A0 =C2=A0 =C2=A0while = (1) {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0do {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0len =3D read(fd, &info, sizeof(info));
- =C2=A0 =C2=A0= =C2=A0 =C2=A0} while (len =3D=3D -1 && errno =3D=3D EINTR);
+ = =C2=A0 =C2=A0 =C2=A0 =C2=A0TFR(len =3D read(fd, &info, sizeof(info)));<= br>=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (len =3D=3D -1 &&= errno =3D=3D EAGAIN) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= break;
diff --git a/util/osdep.c b/util/osdep.c
index 60fcbbaebe..d35= c473ac7 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -244,9 +24= 4,7 @@ static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int f= l_type)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0.l_type =C2=A0 =3D fl_type,=C2=A0 =C2=A0 =C2=A0};
=C2=A0 =C2=A0 =C2=A0qemu_probe_lock_ops();
- = =C2=A0 =C2=A0do {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D fcntl(fd, fcntl_o= p_setlk, &fl);
- =C2=A0 =C2=A0} while (ret =3D=3D -1 && errn= o =3D=3D EINTR);
+ =C2=A0 =C2=A0TFR(ret =3D fcntl(fd, fcntl_op_setlk, &a= mp;fl));
=C2=A0 =C2=A0 =C2=A0return ret =3D=3D -1 ? -errno : 0;
=C2= =A0}
=C2=A0
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.cindex 5ba01177bf..c878be1c5f 100644
--- a/util/vfio-helpers.c
+++ b/= util/vfio-helpers.c
@@ -240,9 +240,9 @@ static int qemu_vfio_pci_read_co= nfig(QEMUVFIOState *s, void *buf,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0s->config_region_info.offset,
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0s->config_region_info.size);=C2=A0 =C2=A0 =C2=A0assert(QEMU_IS_ALIGNED(s->config_region_info.offset= + ofs, size));
- =C2=A0 =C2=A0do {
- =C2=A0 =C2=A0 =C2=A0 =C2=A0ret = =3D pread(s->device, buf, size, s->config_region_info.offset + ofs);<= br>- =C2=A0 =C2=A0} while (ret =3D=3D -1 && errno =3D=3D EINTR);+ =C2=A0 =C2=A0TFR(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D pread(s->de= vice, buf, size, s->config_region_info.offset + ofs)
+ =C2=A0 =C2=A0)= ;
=C2=A0 =C2=A0 =C2=A0return ret =3D=3D size ? 0 : -errno;
=C2=A0}=C2=A0
@@ -254,9 +254,9 @@ static int qemu_vfio_pci_write_config(QEMUVF= IOState *s, void *buf, int size, int
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 s->config_region_info.offset,
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 s->config_region_info.size= );
=C2=A0 =C2=A0 =C2=A0assert(QEMU_IS_ALIGNED(s->config_region_info.o= ffset + ofs, size));
- =C2=A0 =C2=A0do {
- =C2=A0 =C2=A0 =C2=A0 =C2= =A0ret =3D pwrite(s->device, buf, size, s->config_region_info.offset = + ofs);
- =C2=A0 =C2=A0} while (ret =3D=3D -1 && errno =3D=3D EI= NTR);
+ =C2=A0 =C2=A0TFR(
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D pwrite= (s->device, buf, size, s->config_region_info.offset + ofs)
+ =C2= =A0 =C2=A0);
=C2=A0 =C2=A0 =C2=A0return ret =3D=3D size ? 0 : -errno;=C2=A0}
=C2=A0
--
2.37.1


On Mon, Aug 8, 2022 at 5:22 PM M= arkus Armbruster <armbru@redhat.com> wrote:
Christian Schoenebeck <qemu_oss@crudebyte.com> writes:

> On Montag, 8. August 2022 14:52:28 CEST Christian Schoenebeck wrote: >> On Montag, 8. August 2022 10:05:56 CEST Markus Armbruster wrote: >> > Nikita Ivanov <nivanov@cloudlinux.com> writes:
>> > > Summing up the discussion above, I suggest the following= patch for TFR()
>> > > macro refactoring. (The patch is sequential to the first= one I
>> > > introduced
>> > > in the start of the discussion).
>> > >
>> > >>From 6318bee052900aa93bba6620b53c7cb2290e5001 Mon Sep= 17 00:00:00 2001
>> > >>
>> > > From: Nikita Ivanov <nivanov@cloudlinux.com>
>> > > Date: Mon, 8 Aug 2022 09:30:34 +0300
>> > > Subject: [PATCH] Refactoring: rename TFR() to TEMP_FAILU= RE_RETRY()
>> > >
>> > > glibc's unistd.h header provides the same macro with= the
>> > > subtle difference in type casting. Adjust macro name to = the
>> > > common standard and define conditionally.
>> > >
>> > > Signed-off-by: Nikita Ivanov <nivanov@cloudlinux.com>

[...]

>> > > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h=
>> > > index b1c161c035..55f2927d8b 100644
>> > > --- a/include/qemu/osdep.h
>> > > +++ b/include/qemu/osdep.h
>> > > @@ -242,8 +242,10 @@ void QEMU_ERROR("code path is = reachable")
>> > >
>> > >=C2=A0 #if !defined(ESHUTDOWN)
>> > >=C2=A0 #define ESHUTDOWN 4099
>> > >=C2=A0 #endif
>> > >
>> > > -
>> > > -#define TFR(expr) do { if ((expr) !=3D -1) break; } whi= le (errno =3D=3D
>> > > EINTR)
>> > > +#if !defined(TEMP_FAILURE_RETRY)
>> > > +#define TEMP_FAILURE_RETRY(expr) \
>> > > +=C2=A0 =C2=A0 do { if ((expr) !=3D -1) break; } while (= errno =3D=3D EINTR)

To avoid / reduce confusion: this macro expands into a statement, and ...
>> > > +#endif
>> >
>> > GLibc's version is
>> >
>> >=C2=A0 =C2=A0 # define TEMP_FAILURE_RETRY(expression) \
>> >=C2=A0 =C2=A0 =C2=A0 (__extension__=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 \
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 ({ long int __result;=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0\
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0do __result =3D (long= int) (expression);=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0\
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0while (__result =3D= =3D -1L && errno =3D=3D EINTR);=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0\
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0__result; }))

... this one expands into an expression.=C2=A0 It uses GCC's "a co= mpound
statement enclosed in parentheses may appear as an expression" extensi= on.

>> >
>> > The difference isn't just "type casting", it= 9;s also statement
>> > vs. expression.
>> >
>> > Is it a good idea to have the macro expand into a statement o= n some
>> > hosts, and into an expression on others?=C2=A0 Sure, CI shoul= d catch any uses
>> > as expression, but delaying compile errors to CI wastes devel= oper time.
>>
>> For consistency and simplicity, I would define exactly one version= (no
>> ifdefs) of the macro with a different macro name than glibc's<= br> >> TEMP_FAILURE_RETRY(), and use that QEMU specific macro name in QEM= U code
>> everywhere.

TFR()?=C2=A0 Can't resist closing the circle...

>> As for statement vs. expression: The only advantage of the stateme= nt version
>> is if you'd need __result as an rvalue, which is not needed AT= M, right? So
>> I would go for the expression version (with cast) for now.

The expression-like macro is nicer where the return value matters.
Example (stolen from "The GNU C Library Reference Manual"):

=C2=A0 =C2=A0 nbytes =3D TEMP_FAILURE_RETRY (write (desc, buffer, count));<= br>
With the statement-like macro, you have to write

=C2=A0 =C2=A0 TEMP_FAILURE_RETRY (nbytes =3D write (desc, buffer, count));<= br>
>> The glibc history does not reveal why they chose the statement ver= sion.

The expression version, actually.

>> Best regards,
>> Christian Schoenebeck
>
> Sorry: s/rvalue/lvalue/ i.e. if you need the memory address of result = or if
> you need to take the result value of the last iteration in 'expres= sion' into
> account.



--
Best Regards,
Nikita Ivanov | C developer
Telephone: +79140870696
Telephone:= =C2=A0+79015053149


--
Best Regards,
Nikita Ivanov | C developer
Telephone: +79140870696
Telephone:= =C2=A0+79015053149


--
Best Regards,
Nikita Iva= nov | C developer
Telephone: +79140870696
Telephone:=C2=A0+79015053149
--00000000000059844205e6705fa3--