Skip to content

Commit

Permalink
Rename internal functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dAdAbird committed Jul 23, 2024
1 parent d896070 commit 38efd43
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ src/keyring/keyring_curl.o \
src/keyring/keyring_file.o \
src/keyring/keyring_vault.o \
src/keyring/keyring_api.o \
src/catalog/tde_global_catalog.o \
src/catalog/tde_global_space.o \
src/catalog/tde_keyring.o \
src/catalog/tde_principal_key.o \
src/common/pg_tde_shmem.o \
Expand Down
2 changes: 1 addition & 1 deletion expected/vault_v2_test.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CREATE EXTENSION pg_tde;
\getenv root_token ROOT_TOKEN
SELECT pg_tde_add_database_key_provider_vault_v2('vault-v2',:'root_token','http://127.0.0.1:8200','secret',NULL);
pg_tde_add_database_key_provider_vault_v2
----------------------------------
-------------------------------------------
1
(1 row)

Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pg_tde_sources = files(

'src/smgr/pg_tde_smgr.c',

'src/catalog/tde_global_catalog.c',
'src/catalog/tde_global_space.c',
'src/catalog/tde_keyring.c',
'src/catalog/tde_principal_key.c',
'src/common/pg_tde_shmem.c',
Expand Down
6 changes: 3 additions & 3 deletions src/access/pg_tde_xlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "access/pg_tde_xlog.h"
#include "encryption/enc_tde.h"
#ifdef PERCONA_FORK
#include "catalog/tde_global_catalog.h"
#include "catalog/tde_global_space.h"

static char *TDEXLogEncryptBuf = NULL;

Expand Down Expand Up @@ -240,7 +240,7 @@ TDEXLogWriteEncryptedPages(int fd, const void *buf, size_t count, off_t offset)
size_t data_size = 0;
XLogPageHeader curr_page_hdr = &EncryptCurrentPageHrd;
XLogPageHeader enc_buf_page;
RelKeyData *key = GetGlCatInternalKey(XLOG_TDE_OID);
RelKeyData *key = TDEGetGlobalInternalKey(XLOG_TDE_OID);
off_t enc_off;
size_t page_size = XLOG_BLCKSZ - offset % XLOG_BLCKSZ;
uint32 iv_ctr = 0;
Expand Down Expand Up @@ -327,7 +327,7 @@ tdeheap_xlog_seg_read(int fd, void *buf, size_t count, off_t offset)
char iv_prefix[16] = {0,};
size_t data_size = 0;
XLogPageHeader curr_page_hdr = &DecryptCurrentPageHrd;
RelKeyData *key = GetGlCatInternalKey(XLOG_TDE_OID);
RelKeyData *key = TDEGetGlobalInternalKey(XLOG_TDE_OID);
size_t page_size = XLOG_BLCKSZ - offset % XLOG_BLCKSZ;
off_t dec_off;
uint32 iv_ctr = 0;
Expand Down
24 changes: 13 additions & 11 deletions src/catalog/tde_global_catalog.c → src/catalog/tde_global_space.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*-------------------------------------------------------------------------
*
* tde_global_catalog.c
* tde_global_space.c
* Global catalog key management
*
*
* IDENTIFICATION
* src/catalog/tde_global_catalog.c
* src/catalog/tde_global_space.c
*
*-------------------------------------------------------------------------
*/
Expand All @@ -21,7 +21,7 @@
#include "utils/memutils.h"

#include "access/pg_tde_tdemap.h"
#include "catalog/tde_global_catalog.h"
#include "catalog/tde_global_space.h"
#include "catalog/tde_keyring.h"
#include "catalog/tde_principal_key.h"

Expand Down Expand Up @@ -49,25 +49,24 @@ typedef enum
*/
static RelKeyData * internal_keys_cache = NULL;

static void init_gl_catalog_keys(void);
static void init_keys(void);
static void init_default_keyring(void);
static TDEPrincipalKey * create_principal_key(const char *key_name,
GenericKeyring * keyring, Oid dbOid,
Oid spcOid);
static void cache_internal_key(RelKeyData * ikey, InternalKeyType type);

void
TDEGlCatKeyInit(void)
TDEInitGlobalKeys(void)
{
char db_map_path[MAXPGPATH] = {0};

init_default_keyring();

pg_tde_set_db_file_paths(&GLOBAL_SPACE_RLOCATOR(XLOG_TDE_OID),
db_map_path, NULL);
if (access(db_map_path, F_OK) == -1)
{
init_gl_catalog_keys();
init_default_keyring();
init_keys();
}
else
{
Expand Down Expand Up @@ -100,7 +99,7 @@ cache_internal_key(RelKeyData * ikey, InternalKeyType type)


RelKeyData *
GetGlCatInternalKey(Oid obj_id)
TDEGetGlobalInternalKey(Oid obj_id)
{
InternalKeyType ktype;

Expand Down Expand Up @@ -146,10 +145,13 @@ init_default_keyring(void)
}

/*
* Keys are created during the cluster start only, so no locks needed here.
* Create and store global space keys (principal and internal) and cache the
* internal key.
*
* This function has to be run during the cluster start only, so no locks here.
*/
static void
init_gl_catalog_keys(void)
init_keys(void)
{
InternalKey int_key;
RelKeyData *rel_key_data;
Expand Down
2 changes: 1 addition & 1 deletion src/catalog/tde_keyring.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "access/xlog.h"
#include "access/xloginsert.h"
#include "access/pg_tde_xlog.h"
#include "catalog/tde_global_catalog.h"
#include "catalog/tde_global_space.h"
#include "catalog/tde_keyring.h"
#include "catalog/tde_principal_key.h"
#include "access/skey.h"
Expand Down
2 changes: 1 addition & 1 deletion src/catalog/tde_principal_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "access/pg_tde_tdemap.h"
#ifdef PERCONA_FORK
#include "catalog/tde_global_catalog.h"
#include "catalog/tde_global_space.h"
#endif

typedef struct TdePrincipalKeySharedState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*-------------------------------------------------------------------------
*
* tde_global_catalog.h
* tde_global_space.h
* Global catalog key management
*
* src/include/catalog/tde_global_catalog.h
* src/include/catalog/tde_global_space.h
*
*-------------------------------------------------------------------------
*/
Expand All @@ -16,10 +16,10 @@
#include "access/pg_tde_tdemap.h"
#include "catalog/tde_principal_key.h"

/*
* Needed for glogbal data (WAL etc) keys identification in caches and storage.
* We take IDs the oid type operators, so there is no overlap with the "real"
* catalog object possible.
/*
* Needed for global data (WAL etc) keys identification in caches and storage.
* We take Oids of the sql operators, so there is no overlap with the "real"
* catalog objects possible.
*/
#define GLOBAL_DATA_TDE_OID 607 /* Global objects fake "db" */
#define XLOG_TDE_OID 608
Expand All @@ -30,8 +30,7 @@
_obj_oid \
}

extern void TDEGlCatKeyInit(void);
extern void TDEInitGlobalKeys(void);
extern RelKeyData * TDEGetGlobalInternalKey(Oid obj_id);

extern RelKeyData *GetGlCatInternalKey(Oid obj_id);

#endif /*TDE_GLOBAL_CATALOG_H*/
#endif /* TDE_GLOBAL_CATALOG_H */
4 changes: 2 additions & 2 deletions src/pg_tde.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "pg_tde_defs.h"
#include "smgr/pg_tde_smgr.h"
#ifdef PERCONA_FORK
#include "catalog/tde_global_catalog.h"
#include "catalog/tde_global_space.h"
#endif

#define MAX_ON_INSTALLS 5
Expand Down Expand Up @@ -87,7 +87,7 @@ tde_shmem_startup(void)
AesInit();

#ifdef PERCONA_FORK
TDEGlCatKeyInit();
TDEInitGlobalKeys();

TDEXLogShmemInit();
TDEXLogSmgrInit();
Expand Down

0 comments on commit 38efd43

Please sign in to comment.