0001-Tolerate-EINVAL-when-calling-fsync-on-a-directory.patch

application/octet-stream

Filename: 0001-Tolerate-EINVAL-when-calling-fsync-on-a-directory.patch
Type: application/octet-stream
Part: 0
Message: Re: BUG #15636: PostgreSQL 11.1 pg_basebackup backup to a CIFS destination throws fsync error at end of backup

Patch

Format: format-patch
Series: patch 0001
Subject: Tolerate EINVAL when calling fsync() on a directory.
File+
src/backend/storage/file/fd.c 1 1
src/common/file_utils.c 1 1
From e9700a6ae0ec88016d2ee9380faa160427224605 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@enterprisedb.com>
Date: Fri, 15 Feb 2019 16:54:00 +1300
Subject: [PATCH] Tolerate EINVAL when calling fsync() on a directory.

Previously, we tolerated EBADF as a way for OSes to indicated that they
don't support fsync() on a directory.  Tolerate EINVAL too, because that
is what happens on older versions of CIFS.

This isn't intended to support running PostgreSQL on CIFS, but is useful
for some of the tools in bin.

Bug #15636.

Reported-by: John Klann
Discussion: https://postgr.es/m/15636-d380890dafd78fc6@postgresql.org
---
 src/backend/storage/file/fd.c | 2 +-
 src/common/file_utils.c       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 213de7698a..5136d04d46 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -3360,7 +3360,7 @@ fsync_fname_ext(const char *fname, bool isdir, bool ignore_perm, int elevel)
 	 * Some OSes don't allow us to fsync directories at all, so we can ignore
 	 * those errors. Anything else needs to be logged.
 	 */
-	if (returncode != 0 && !(isdir && errno == EBADF))
+	if (returncode != 0 && !(isdir && (errno == EBADF || errno == EINVAL)))
 	{
 		int			save_errno;
 
diff --git a/src/common/file_utils.c b/src/common/file_utils.c
index 4bcb9c1e05..c25713d0e5 100644
--- a/src/common/file_utils.c
+++ b/src/common/file_utils.c
@@ -299,7 +299,7 @@ fsync_fname(const char *fname, bool isdir, const char *progname)
 	 * Some OSes don't allow us to fsync directories at all, so we can ignore
 	 * those errors. Anything else needs to be reported.
 	 */
-	if (returncode != 0 && !(isdir && errno == EBADF))
+	if (returncode != 0 && !(isdir && (errno == EBADF || errno == EINVAL)))
 	{
 		fprintf(stderr, _("%s: could not fsync file \"%s\": %s\n"),
 				progname, fname, strerror(errno));
-- 
2.20.1