Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry if posix_fallocate is interrupted with EINTR #453

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions lib/unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ qb_sys_mmap_file_open(char *path, const char *file, size_t bytes,
int32_t i;
#endif
char *is_absolute = strchr(file, '/');
#ifdef HAVE_POSIX_FALLOCATE
int32_t fallocate_retry = 5;
#endif

if (is_absolute) {
(void)strlcpy(path, file, PATH_MAX);
Expand Down Expand Up @@ -121,12 +124,22 @@ qb_sys_mmap_file_open(char *path, const char *file, size_t bytes,
}
#endif
#ifdef HAVE_POSIX_FALLOCATE
if ((res = posix_fallocate(fd, 0, bytes)) != 0) {
errno = res;
res = -1 * res;
qb_util_perror(LOG_ERR, "couldn't allocate file %s", path);
goto unlink_exit;
}
/* posix_fallocate(3) can be interrupted by a signal,
so retry few times before giving up */
do {
fallocate_retry--;
res = posix_fallocate(fd, 0, bytes);
if (res == EINTR) {
qb_util_log(LOG_DEBUG, "got EINTR trying to allocate file %s, retrying...", path);
continue;
} else if (res != 0) {
errno = res;
res = -1 * res;
qb_util_perror(LOG_ERR, "couldn't allocate file %s", path);
goto unlink_exit;
}
break;
} while (fallocate_retry > 0);
#else
if (file_flags & O_CREAT) {
long page_size = sysconf(_SC_PAGESIZE);
Expand Down