From 97511604cefae94982fcf8e7b5ec067d89167978 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@enterprisedb.com>
Date: Sun, 18 Nov 2018 14:23:47 +1300
Subject: [PATCH 3/3] fsync() fault injection.  For testing only!

Touch /tmp/pg_fsync_EIO and /tmp/FileSync_EIO to cause fake failures
for testing.
---
 src/backend/storage/file/fd.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 827a1e2620b..5a545f226e8 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -332,6 +332,12 @@ static int	fsync_parent_path(const char *fname, int elevel);
 int
 pg_fsync(int fd)
 {
+	if (access("/tmp/pg_fsync_EIO", F_OK) == 0)
+	{
+		errno = EIO;
+		return -1;
+	}
+
 	/* #if is to skip the sync_method test if there's no need for it */
 #if defined(HAVE_FSYNC_WRITETHROUGH) && !defined(FSYNC_WRITETHROUGH_IS_FSYNC)
 	if (sync_method == SYNC_METHOD_FSYNC_WRITETHROUGH)
@@ -1993,6 +1999,12 @@ FileSync(File file, uint32 wait_event_info)
 {
 	int			returnCode;
 
+	if (access("/tmp/FileSync_EIO", F_OK) == 0)
+	{
+		errno = EIO;
+		return -1;
+	}
+
 	Assert(FileIsValid(file));
 
 	DO_DB(elog(LOG, "FileSync: %d (%s)",
-- 
2.19.1

