Backport "Expose fsync_fname as a public API".
authorRobert Haas <rhaas@postgresql.org>
Mon, 4 May 2015 16:52:29 +0000 (12:52 -0400)
committerRobert Haas <rhaas@postgresql.org>
Mon, 4 May 2015 16:59:51 +0000 (12:59 -0400)
Backport commit b0a48e996bd7ff336ea26344d3d97ad32b22a61a back to 9.0
to allow back-patching another fix that uses fsync_fname.

src/backend/storage/file/copydir.c
src/backend/storage/file/fd.c
src/include/storage/fd.h

index fe44180c937065ab4bc93b5a77c1359b29f818a5..7299d78ed449670b7ba9b292d37a971d9b39fd67 100644 (file)
@@ -38,7 +38,6 @@
 
 
 static void copy_file(char *fromfile, char *tofile);
-static void fsync_fname(char *fname, bool isdir);
 
 
 /*
@@ -214,59 +213,3 @@ copy_file(char *fromfile, char *tofile)
 
    pfree(buffer);
 }
-
-
-/*
- * fsync a file
- *
- * Try to fsync directories but ignore errors that indicate the OS
- * just doesn't allow/require fsyncing directories.
- */
-static void
-fsync_fname(char *fname, bool isdir)
-{
-   int         fd;
-   int         returncode;
-
-   /*
-    * Some OSs require directories to be opened read-only whereas other
-    * systems don't allow us to fsync files opened read-only; so we need both
-    * cases here
-    */
-   if (!isdir)
-       fd = BasicOpenFile(fname,
-                          O_RDWR | PG_BINARY,
-                          S_IRUSR | S_IWUSR);
-   else
-       fd = BasicOpenFile(fname,
-                          O_RDONLY | PG_BINARY,
-                          S_IRUSR | S_IWUSR);
-
-   /*
-    * Some OSs don't allow us to open directories at all (Windows returns
-    * EACCES)
-    */
-   if (fd < 0 && isdir && (errno == EISDIR || errno == EACCES))
-       return;
-
-   else if (fd < 0)
-       ereport(ERROR,
-               (errcode_for_file_access(),
-                errmsg("could not open file \"%s\": %m", fname)));
-
-   returncode = pg_fsync(fd);
-
-   /* Some OSs don't allow us to fsync directories at all */
-   if (returncode != 0 && isdir && errno == EBADF)
-   {
-       close(fd);
-       return;
-   }
-
-   if (returncode != 0)
-       ereport(ERROR,
-               (errcode_for_file_access(),
-                errmsg("could not fsync file \"%s\": %m", fname)));
-
-   close(fd);
-}
index 4364340845f0dcbf9863c548ddfd13d6729a835a..ba80f70e08365993bec333a72b6e1de3c9f5236e 100644 (file)
@@ -1948,3 +1948,59 @@ RemovePgTempFilesInDir(const char *tmpdirname)
 
    FreeDir(temp_dir);
 }
+
+
+/*
+ * fsync a file
+ *
+ * Try to fsync directories but ignore errors that indicate the OS
+ * just doesn't allow/require fsyncing directories.
+ */
+void
+fsync_fname(char *fname, bool isdir)
+{
+   int         fd;
+   int         returncode;
+
+   /*
+    * Some OSs require directories to be opened read-only whereas other
+    * systems don't allow us to fsync files opened read-only; so we need both
+    * cases here
+    */
+   if (!isdir)
+       fd = BasicOpenFile(fname,
+                          O_RDWR | PG_BINARY,
+                          S_IRUSR | S_IWUSR);
+   else
+       fd = BasicOpenFile(fname,
+                          O_RDONLY | PG_BINARY,
+                          S_IRUSR | S_IWUSR);
+
+   /*
+    * Some OSs don't allow us to open directories at all (Windows returns
+    * EACCES)
+    */
+   if (fd < 0 && isdir && (errno == EISDIR || errno == EACCES))
+       return;
+
+   else if (fd < 0)
+       ereport(ERROR,
+               (errcode_for_file_access(),
+                errmsg("could not open file \"%s\": %m", fname)));
+
+   returncode = pg_fsync(fd);
+
+   /* Some OSs don't allow us to fsync directories at all */
+   if (returncode != 0 && isdir && errno == EBADF)
+   {
+       close(fd);
+       return;
+   }
+
+   if (returncode != 0)
+       ereport(ERROR,
+               (errcode_for_file_access(),
+                errmsg("could not fsync file \"%s\": %m", fname)));
+
+   close(fd);
+}
index 5798ee385651938ca2a7c49867931c12436aa3cf..014e0f866792257fe8f9d48f9fac0381074e56d4 100644 (file)
@@ -99,6 +99,7 @@ extern int    pg_fsync_no_writethrough(int fd);
 extern int pg_fsync_writethrough(int fd);
 extern int pg_fdatasync(int fd);
 extern int pg_flush_data(int fd, off_t offset, off_t amount);
+extern void fsync_fname(char *fname, bool isdir);
 
 /* Filename components for OpenTemporaryFile */
 #define PG_TEMP_FILES_DIR "pgsql_tmp"