From 8992ae8f5b60708820f7c1befdabbcbfadaaa07d Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 23 Feb 2023 12:28:29 +0100 Subject: [PATCH] utils: improve ioctl retry --- util/opts/log.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/util/opts/log.c b/util/opts/log.c index eec4d47..6b0dcd7 100644 --- a/util/opts/log.c +++ b/util/opts/log.c @@ -86,21 +86,18 @@ uint64_t get_monotonic_time_us(struct timespec *ts, struct timeval *tv) int ioctl_retried(const char *name, int fd, int request, void *arg) { -#define MAX_RETRIES 4 +#define MAX_RETRIES 10 +#define RETRY_INTERVAL_US 1000 - int retries = 4; - int ret = -1; - - while (retries-- > 0) { - ret = ioctl(fd, request, arg); + for (int try = 0; try <= MAX_RETRIES; try++) { + int ret = ioctl(fd, request, arg); if (errno != EINTR && errno != EAGAIN && errno != ETIMEDOUT) - break; + return ret; + usleep(RETRY_INTERVAL_US); } - if (ret && retries <= 0) { - LOG_PERROR(NULL, "%s: ioctl(%08x, errno=%d) retried %u times; giving up", name, request, errno, MAX_RETRIES); - } - return ret; + LOG_INFO(NULL, "%s: ioctl(%08x, errno=%d) retried %u times", name, request, errno, MAX_RETRIES); + return -1; } char *trim(char *s)