From 4eda0a64705763854225a29703b606692af50e77 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Fri, 7 Aug 2015 15:10:56 +0200 Subject: [PATCH] Don't include low level locking code from frontend code. Some frontend code like e.g. pg_xlogdump or pg_resetxlog, has to use backend headers. Unfortunately until now that code includes most of the locking code. It's generally not nice to expose such low level details, but de6fd1c898 made that a hard problem. We fall back to defining 'inline' away if the compiler doesn't support it - that can cause linker errors like on buildfarm animal pademelon if a inline function references backend only code. To fix that problem separate definitions from lock.h that are required from frontend code into lockdefs.h and use it in the relevant places. I've only removed the minimal amount of necessary definitions for now - it might turn out that we want more for other reasons. To avoid such details being exposed again put some checks against being included from frontend code into atomics.h, lock.h, lwlock.h and s_lock.h. It's otherwise fairly easy to indirectly include these headers. Discussion: 20150806070902.GE12214@awork2.anarazel.de --- src/backend/utils/hash/hashfn.c | 1 + src/include/access/genam.h | 2 +- src/include/access/hash.h | 2 +- src/include/access/tuptoaster.h | 2 +- src/include/catalog/objectaddress.h | 2 +- src/include/port/atomics.h | 4 +++ src/include/storage/lock.h | 43 +++------------------- src/include/storage/lockdefs.h | 56 +++++++++++++++++++++++++++++ src/include/storage/lwlock.h | 4 +++ src/include/storage/procarray.h | 1 + src/include/storage/s_lock.h | 4 +++ src/include/storage/standby.h | 2 +- 12 files changed, 80 insertions(+), 43 deletions(-) create mode 100644 src/include/storage/lockdefs.h diff --git a/src/backend/utils/hash/hashfn.c b/src/backend/utils/hash/hashfn.c index 260d8806db..bdd438d4ca 100644 --- a/src/backend/utils/hash/hashfn.c +++ b/src/backend/utils/hash/hashfn.c @@ -22,6 +22,7 @@ #include "postgres.h" #include "access/hash.h" +#include "utils/hsearch.h" /* diff --git a/src/include/access/genam.h b/src/include/access/genam.h index d86590ac11..d9d05a08ff 100644 --- a/src/include/access/genam.h +++ b/src/include/access/genam.h @@ -17,7 +17,7 @@ #include "access/sdir.h" #include "access/skey.h" #include "nodes/tidbitmap.h" -#include "storage/lock.h" +#include "storage/lockdefs.h" #include "utils/relcache.h" #include "utils/snapshot.h" diff --git a/src/include/access/hash.h b/src/include/access/hash.h index 93cc8afceb..97cb859fa5 100644 --- a/src/include/access/hash.h +++ b/src/include/access/hash.h @@ -24,7 +24,7 @@ #include "fmgr.h" #include "lib/stringinfo.h" #include "storage/bufmgr.h" -#include "storage/lock.h" +#include "storage/lockdefs.h" #include "utils/relcache.h" /* diff --git a/src/include/access/tuptoaster.h b/src/include/access/tuptoaster.h index 7d18535771..77f637e90d 100644 --- a/src/include/access/tuptoaster.h +++ b/src/include/access/tuptoaster.h @@ -14,8 +14,8 @@ #define TUPTOASTER_H #include "access/htup_details.h" +#include "storage/lockdefs.h" #include "utils/relcache.h" -#include "storage/lock.h" /* * This enables de-toasting of index entries. Needed until VACUUM is diff --git a/src/include/catalog/objectaddress.h b/src/include/catalog/objectaddress.h index 37808c03c6..0fc16ed717 100644 --- a/src/include/catalog/objectaddress.h +++ b/src/include/catalog/objectaddress.h @@ -14,7 +14,7 @@ #define OBJECTADDRESS_H #include "nodes/pg_list.h" -#include "storage/lock.h" +#include "storage/lockdefs.h" #include "utils/acl.h" #include "utils/relcache.h" diff --git a/src/include/port/atomics.h b/src/include/port/atomics.h index bb87945088..65cfa3f824 100644 --- a/src/include/port/atomics.h +++ b/src/include/port/atomics.h @@ -37,6 +37,10 @@ #ifndef ATOMICS_H #define ATOMICS_H +#ifdef FRONTEND +#error "atomics.h may not be included from frontend code" +#endif + #define INSIDE_ATOMICS_H #include diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h index 96fe3a66ab..a9cd08c527 100644 --- a/src/include/storage/lock.h +++ b/src/include/storage/lock.h @@ -14,6 +14,11 @@ #ifndef LOCK_H_ #define LOCK_H_ +#ifdef FRONTEND +#error "lock.h may not be included from frontend code" +#endif + +#include "storage/lockdefs.h" #include "storage/backendid.h" #include "storage/lwlock.h" #include "storage/shmem.h" @@ -77,15 +82,6 @@ typedef struct ((vxid).backendId = (proc).backendId, \ (vxid).localTransactionId = (proc).lxid) - -/* - * LOCKMODE is an integer (1..N) indicating a lock type. LOCKMASK is a bit - * mask indicating a set of held or requested lock types (the bit 1<