From: Thomas Huth <thuth@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Nikita Ivanov <nivanov@cloudlinux.com>
Subject: [PULL 13/15] Refactoring: refactor TFR() macro to RETRY_ON_EINTR()
Date: Fri, 6 Jan 2023 09:28:51 +0100 [thread overview]
Message-ID: <20230106082853.31787-14-thuth@redhat.com> (raw)
In-Reply-To: <20230106082853.31787-1-thuth@redhat.com>
From: Nikita Ivanov <nivanov@cloudlinux.com>
Rename macro name to more transparent one and refactor
it to expression.
Signed-off-by: Nikita Ivanov <nivanov@cloudlinux.com>
Message-Id: <20221023090422.242617-2-nivanov@cloudlinux.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
include/qemu/osdep.h | 8 +++++++-
chardev/char-fd.c | 2 +-
chardev/char-pipe.c | 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/include/qemu/osdep.h b/include/qemu/osdep.h
index b9c4307779..7d059ad526 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -251,7 +251,13 @@ void QEMU_ERROR("code path is reachable")
#define ESHUTDOWN 4099
#endif
-#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
+#define RETRY_ON_EINTR(expr) \
+ (__extension__ \
+ ({ typeof(expr) __result; \
+ do { \
+ __result = (expr); \
+ } while (__result == -1 && errno == EINTR); \
+ __result; }))
/* 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/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 = -1;
- TFR(fd = qemu_open_old(src, flags, 0666));
+ fd = RETRY_ON_EINTR(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..5ad30bcc59 100644
--- a/chardev/char-pipe.c
+++ b/chardev/char-pipe.c
@@ -131,8 +131,8 @@ 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 = RETRY_ON_EINTR(qemu_open_old(filename_in, O_RDWR | O_BINARY));
+ fd_out = RETRY_ON_EINTR(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 +142,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 = 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/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 = open(dname, O_RDWR));
+ fd = RETRY_ON_EINTR(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 = 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_hdr,
if (ifname[0] != '\0') {
char dname[100];
snprintf(dname, sizeof dname, "/dev/%s", ifname);
- TFR(fd = open(dname, O_RDWR));
+ fd = RETRY_ON_EINTR(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..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 = sizeof(struct virtio_net_hdr);
unsigned int features;
- TFR(fd = open(PATH_NET_TUN, O_RDWR));
+ fd = 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);
- TFR(ip_fd = open("/dev/udp", O_RDWR, 0));
+ ip_fd = 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;
}
- TFR(tap_fd = open("/dev/tap", O_RDWR, 0));
+ tap_fd = 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 = 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 = 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 = open ("/dev/tap", O_RDWR, 0));
+ arp_fd = RETRY_ON_EINTR(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 e28ceb078f..bd85c56a04 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -650,7 +650,7 @@ 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,
+ fd = RETRY_ON_EINTR(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 4858650c3e..5adc69f560 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -272,7 +272,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 = RETRY_ON_EINTR(qemu_open_old("/dev/null", O_RDWR));
if (fd == -1) {
exit(1);
}
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 2fbc3b88f3..f9c8987678 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -203,7 +203,7 @@ void qtest_wait_qemu(QTestState *s)
#ifndef _WIN32
pid_t pid;
- TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
+ pid = RETRY_ON_EINTR(waitpid(s->qemu_pid, &s->wstatus, 0));
assert(pid == s->qemu_pid);
#else
DWORD ret;
--
2.31.1
next prev parent reply other threads:[~2023-01-06 8:57 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-06 8:28 [PULL 00/15] First batch of s390x, qtests and misc fixes in 2023 Thomas Huth
2023-01-06 8:28 ` [PULL 01/15] qemu-iotests/stream-under-throttle: do not shutdown QEMU Thomas Huth
2023-01-06 8:28 ` [PULL 02/15] tests/vm: Update get_default_jobs() to work on non-x86_64 non-KVM hosts Thomas Huth
2023-01-06 8:28 ` [PULL 03/15] MAINTAINERS: Add MIPS-related docs and configs to the MIPS architecture section Thomas Huth
2023-01-06 8:28 ` [PULL 04/15] exec/memory: Expose memory_region_access_valid() Thomas Huth
2023-01-06 8:28 ` [PULL 05/15] hw/s390x/pv: Restrict Protected Virtualization to sysemu Thomas Huth
2023-01-06 8:28 ` [PULL 06/15] target/s390x/tcg/misc_helper: Remove unused "memory.h" include Thomas Huth
2023-01-06 8:28 ` [PULL 07/15] target/s390x/tcg/excp_helper: Restrict system headers to sysemu Thomas Huth
2023-01-06 8:28 ` [PULL 08/15] target/s390x: Restrict sysemu/reset.h to system emulation Thomas Huth
2023-01-06 8:28 ` [PULL 09/15] tests/readconfig: spice doesn't support unix socket on windows yet Thomas Huth
2023-01-06 8:28 ` [PULL 10/15] i386: Deprecate the -no-hpet QEMU command line option Thomas Huth
2023-01-06 8:28 ` [PULL 11/15] docs/interop: Change the vnc-ledstate-Pseudo-encoding doc into .rst Thomas Huth
2023-01-06 8:28 ` [PULL 12/15] Update scripts/meson-buildoptions.sh Thomas Huth
2023-01-06 8:28 ` Thomas Huth [this message]
2023-01-06 8:28 ` [PULL 14/15] error handling: Use RETRY_ON_EINTR() macro where applicable Thomas Huth
2023-01-06 8:28 ` [PULL 15/15] .gitlab-ci.d/windows: Do not run the qtests in the msys2-32bit job Thomas Huth
2023-01-07 14:25 ` [PULL 00/15] First batch of s390x, qtests and misc fixes in 2023 Peter Maydell
2023-01-09 7:50 ` Thomas Huth
2023-01-09 10:06 ` Peter Maydell
-- strict thread matches above, loose matches on Subject: below --
2023-01-09 14:25 [PULL v2 " Thomas Huth
2023-01-09 14:26 ` [PULL 13/15] Refactoring: refactor TFR() macro to RETRY_ON_EINTR() Thomas Huth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230106082853.31787-14-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=nivanov@cloudlinux.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).