Move PG_TEMP_FILE* macros to file_utils.h.
authorNathan Bossart <nathan@postgresql.org>
Wed, 6 Sep 2023 00:02:06 +0000 (17:02 -0700)
committerNathan Bossart <nathan@postgresql.org>
Wed, 6 Sep 2023 00:02:06 +0000 (17:02 -0700)
Presently, frontend code that needs to use these macros must either
include storage/fd.h, which declares several frontend-unsafe
functions, or duplicate the macros.  This commit moves these macros
to common/file_utils.h, which is safe for both frontend and backend
code.  Consequently, we can also remove the duplicated macros in
pg_checksums and stop including storage/fd.h in pg_rewind.

Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/ZOP5qoUualu5xl2Z%40paquier.xyz

src/backend/backup/basebackup.c
src/backend/postmaster/postmaster.c
src/backend/storage/file/fileset.c
src/bin/pg_checksums/pg_checksums.c
src/bin/pg_rewind/filemap.c
src/include/common/file_utils.h
src/include/storage/fd.h

index 45be21131c5cb80c40c88fe8e208bad3550234f9..5d66014499af58125a872d50956a332a0eac64fb 100644 (file)
@@ -25,6 +25,7 @@
 #include "commands/defrem.h"
 #include "common/compression.h"
 #include "common/file_perm.h"
+#include "common/file_utils.h"
 #include "lib/stringinfo.h"
 #include "miscadmin.h"
 #include "nodes/pg_list.h"
@@ -37,7 +38,6 @@
 #include "storage/bufpage.h"
 #include "storage/checksum.h"
 #include "storage/dsm_impl.h"
-#include "storage/fd.h"
 #include "storage/ipc.h"
 #include "storage/reinit.h"
 #include "utils/builtins.h"
index d7bfb28ff35b7daddfa275df1bcd3a1fcebd5864..54e9bfb8c487ad00cf9528517e66c3927f5ae3b1 100644 (file)
@@ -94,6 +94,7 @@
 #include "access/xlogrecovery.h"
 #include "catalog/pg_control.h"
 #include "common/file_perm.h"
+#include "common/file_utils.h"
 #include "common/ip.h"
 #include "common/pg_prng.h"
 #include "common/string.h"
index e9951b02694199d4b21efc52a9f474d3b3c7f414..84cae32548e588c68310dda1f6351fd86a9fc62d 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "catalog/pg_tablespace.h"
 #include "commands/tablespace.h"
+#include "common/file_utils.h"
 #include "common/hashfn.h"
 #include "miscadmin.h"
 #include "storage/ipc.h"
index 19eb67e4854f7c1dbad01626a6e3cd0977a5e1ba..9011a19b4ef7323beff5ed462156d5d223134db3 100644 (file)
@@ -52,16 +52,6 @@ typedef enum
    PG_MODE_ENABLE
 } PgChecksumMode;
 
-/*
- * Filename components.
- *
- * XXX: fd.h is not declared here as frontend side code is not able to
- * interact with the backend-side definitions for the various fsync
- * wrappers.
- */
-#define PG_TEMP_FILES_DIR "pgsql_tmp"
-#define PG_TEMP_FILE_PREFIX "pgsql_tmp"
-
 static PgChecksumMode mode = PG_MODE_CHECK;
 
 static const char *progname;
index bd5c598e2008ee007dc1260b3d5cd21f41a48ca9..58280d9abceac8280b8d3875a3012f6a956746b0 100644 (file)
 #include <unistd.h>
 
 #include "catalog/pg_tablespace_d.h"
+#include "common/file_utils.h"
 #include "common/hashfn.h"
 #include "common/string.h"
 #include "datapagemap.h"
 #include "filemap.h"
 #include "pg_rewind.h"
-#include "storage/fd.h"
 
 /*
  * Define a hash table which we can use to store information about the files
index b7efa1226d6ef563741ec725c22479fcf14fd7ce..dd1532bcb063bc5bdb75ed4467b49a372024fc95 100644 (file)
@@ -46,4 +46,8 @@ extern ssize_t pg_pwritev_with_retry(int fd,
 
 extern ssize_t pg_pwrite_zeros(int fd, size_t size, off_t offset);
 
+/* Filename components */
+#define PG_TEMP_FILES_DIR "pgsql_tmp"
+#define PG_TEMP_FILE_PREFIX "pgsql_tmp"
+
 #endif                         /* FILE_UTILS_H */
index 6791a406fc11441857ba8168d2f3e52b9292f35a..aea30c06226bbb29f3bdd4570ad90d21e522ff34 100644 (file)
@@ -195,8 +195,4 @@ extern int  durable_unlink(const char *fname, int elevel);
 extern void SyncDataDirectory(void);
 extern int data_sync_elevel(int elevel);
 
-/* Filename components */
-#define PG_TEMP_FILES_DIR "pgsql_tmp"
-#define PG_TEMP_FILE_PREFIX "pgsql_tmp"
-
 #endif                         /* FD_H */