Skip to content

Commit 387483e

Browse files
committed
Tolerate ENOSYS failure from sync_file_range().
One unintended consequence of commit 9ccdd7f was that Windows WSL users started getting a panic whenever we tried to initiate data flushing with sync_file_range(), because WSL does not implement that system call. Previously, they got a stream of periodic warnings, which was also undesirable but at least ignorable. Prevent the panic by handling ENOSYS specially and skipping the panic promotion with data_sync_elevel(). Also suppress future attempts after the first such failure so that the pre-existing problem of noisy warnings is improved. Back-patch to 9.6 (older branches were not affected in this way by 9ccdd7f). Author: Thomas Munro and James Sewell Tested-by: James Sewell Reported-by: Bruce Klein Discussion: https://postgr.es/m/CA+mCpegfOUph2U4ZADtQT16dfbkjjYNJL1bSTWErsazaFjQW9A@mail.gmail.com
1 parent 58947fb commit 387483e

File tree

1 file changed

+20
-1
lines changed
  • src/backend/storage/file

1 file changed

+20
-1
lines changed

src/backend/storage/file/fd.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ pg_flush_data(int fd, off_t offset, off_t nbytes)
423423
#if defined(HAVE_SYNC_FILE_RANGE)
424424
{
425425
int rc;
426+
static bool not_implemented_by_kernel = false;
427+
428+
if (not_implemented_by_kernel)
429+
return;
426430

427431
/*
428432
* sync_file_range(SYNC_FILE_RANGE_WRITE), currently linux specific,
@@ -437,7 +441,22 @@ pg_flush_data(int fd, off_t offset, off_t nbytes)
437441
SYNC_FILE_RANGE_WRITE);
438442
if (rc != 0)
439443
{
440-
ereport(data_sync_elevel(WARNING),
444+
int elevel;
445+
446+
/*
447+
* For systems that don't have an implementation of
448+
* sync_file_range() such as Windows WSL, generate only one
449+
* warning and then suppress all further attempts by this process.
450+
*/
451+
if (errno == ENOSYS)
452+
{
453+
elevel = WARNING;
454+
not_implemented_by_kernel = true;
455+
}
456+
else
457+
elevel = data_sync_elevel(WARNING);
458+
459+
ereport(elevel,
441460
(errcode_for_file_access(),
442461
errmsg("could not flush dirty data: %m")));
443462
}

0 commit comments

Comments
 (0)