Skip to content

Commit

Permalink
Retry if posix_fallocate is interrupted with EINTR (#453)
Browse files Browse the repository at this point in the history
Every now and then Pacemaker reports errors:

  (pcmk__new_client)        debug: New IPC client 3efdbecf-c2d9-44bc-b4a6-9bcd48021ba1 for PID 27492 with uid 0 and gid 0
  (handle_new_connection)   debug: IPC credentials authenticated (/dev/shm/qb-7271-27492-12-hfPbKY/qb)
  (qb_ipcs_shm_connect)     debug: connecting to client [27492]
  (qb_rb_open_2)    debug: shm size:524301; real_size:528384; rb->word_size:132096
  (qb_rb_open_2)    debug: shm size:524301; real_size:528384; rb->word_size:132096
  (qb_sys_mmap_file_open)   error: couldn't allocate file /dev/shm/qb-7271-27492-12-hfPbKY/qb-event-cib_rw-data: Interrupted system call (4)
  (qb_rb_open_2)    error: couldn't create file for mmap
  (qb_ipcs_shm_rb_open)     error: qb_rb_open:/dev/shm/qb-7271-27492-12-hfPbKY/qb-event-cib_rw: Interrupted system call (4)
  (qb_rb_close_helper)      debug: Free'ing ringbuffer: /dev/shm/qb-7271-27492-12-hfPbKY/qb-response-cib_rw-header
  (qb_rb_close_helper)      debug: Free'ing ringbuffer: /dev/shm/qb-7271-27492-12-hfPbKY/qb-request-cib_rw-header
  (qb_ipcs_shm_connect)     error: shm connection FAILED: Interrupted system call (4)
  (handle_new_connection)   error: Error in connection setup (/dev/shm/qb-7271-27492-12-hfPbKY/qb): Interrupted system call (4)

While it probably might be addressed in Pacemaker code, a simple retry
loop in case posix_fallocate(3) returns EINTR seems to be a decent
workaround.

Fixes: #451

Signed-off-by: Jakub Jankowski <[email protected]>
Reviewed-by: Christine Caulfield <[email protected]>
  • Loading branch information
shastah authored Jan 14, 2022
1 parent de5ab30 commit 176eae8
Showing 1 changed file with 19 additions and 6 deletions.
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

0 comments on commit 176eae8

Please sign in to comment.