@@ -31,16 +31,16 @@ static WALKeyCacheRec *tde_wal_key_last_rec = NULL;
31
31
32
32
static WALKeyCacheRec * pg_tde_add_wal_key_to_cache (WalEncryptionKey * cached_key , XLogRecPtr start_lsn );
33
33
static WalEncryptionKey * pg_tde_decrypt_wal_key (TDEPrincipalKey * principal_key , WalKeyFileEntry * entry );
34
- static void pg_tde_initialize_wal_key_file_entry (WalKeyFileEntry * entry , const TDEPrincipalKey * principal_key , const RelFileLocator * rlocator , const WalEncryptionKey * rel_key_data );
34
+ static void pg_tde_initialize_wal_key_file_entry (WalKeyFileEntry * entry , const TDEPrincipalKey * principal_key , const WalEncryptionKey * rel_key_data );
35
35
static int pg_tde_open_wal_key_file_basic (const char * filename , int flags , bool ignore_missing );
36
36
static int pg_tde_open_wal_key_file_read (const char * filename , bool ignore_missing , off_t * curr_pos );
37
37
static int pg_tde_open_wal_key_file_write (const char * filename , const TDESignedPrincipalKeyInfo * signed_key_info , bool truncate , off_t * curr_pos );
38
38
static bool pg_tde_read_one_wal_key_file_entry (int fd , WalKeyFileEntry * entry , off_t * offset );
39
- static void pg_tde_read_one_wal_key_file_entry2 (int fd , int32 key_index , WalKeyFileEntry * entry , Oid databaseId );
39
+ static void pg_tde_read_one_wal_key_file_entry2 (int fd , int32 key_index , WalKeyFileEntry * entry );
40
40
static void pg_tde_wal_key_file_header_read (const char * filename , int fd , WalKeyFileHeader * fheader , off_t * bytes_read );
41
41
static int pg_tde_wal_key_file_header_write (const char * filename , int fd , const TDESignedPrincipalKeyInfo * signed_key_info , off_t * bytes_written );
42
42
static void pg_tde_write_one_wal_key_file_entry (int fd , const WalKeyFileEntry * entry , off_t * offset , const char * db_map_path );
43
- static void pg_tde_write_wal_key_file_entry (const RelFileLocator * rlocator , const WalEncryptionKey * rel_key_data , TDEPrincipalKey * principal_key );
43
+ static void pg_tde_write_wal_key_file_entry (const WalEncryptionKey * rel_key_data , TDEPrincipalKey * principal_key );
44
44
45
45
static char *
46
46
get_wal_key_file_path (void )
@@ -129,15 +129,13 @@ pg_tde_wal_last_key_set_lsn(XLogRecPtr lsn)
129
129
* with the actual lsn by the first WAL write.
130
130
*/
131
131
void
132
- pg_tde_create_wal_key (WalEncryptionKey * rel_key_data ,
133
- const RelFileLocator * newrlocator ,
134
- TDEMapEntryType entry_type )
132
+ pg_tde_create_wal_key (WalEncryptionKey * rel_key_data , TDEMapEntryType entry_type )
135
133
{
136
134
TDEPrincipalKey * principal_key ;
137
135
138
136
LWLockAcquire (tde_lwlock_enc_keys (), LW_EXCLUSIVE );
139
137
140
- principal_key = GetPrincipalKey (newrlocator -> dbOid , LW_EXCLUSIVE );
138
+ principal_key = GetPrincipalKey (GLOBAL_DATA_TDE_OID , LW_EXCLUSIVE );
141
139
if (principal_key == NULL )
142
140
{
143
141
ereport (ERROR ,
@@ -160,7 +158,7 @@ pg_tde_create_wal_key(WalEncryptionKey *rel_key_data,
160
158
errmsg ("could not generate IV for WAL encryption key: %s" ,
161
159
ERR_error_string (ERR_get_error (), NULL )));
162
160
163
- pg_tde_write_wal_key_file_entry (newrlocator , rel_key_data , principal_key );
161
+ pg_tde_write_wal_key_file_entry (rel_key_data , principal_key );
164
162
165
163
#ifdef FRONTEND
166
164
free (principal_key );
@@ -186,7 +184,6 @@ pg_tde_get_wal_cache_keys(void)
186
184
WalEncryptionKey *
187
185
pg_tde_read_last_wal_key (void )
188
186
{
189
- RelFileLocator rlocator = GLOBAL_SPACE_RLOCATOR (XLOG_TDE_OID );
190
187
off_t read_pos = 0 ;
191
188
LWLock * lock_pk = tde_lwlock_enc_keys ();
192
189
TDEPrincipalKey * principal_key ;
@@ -197,7 +194,7 @@ pg_tde_read_last_wal_key(void)
197
194
off_t fsize ;
198
195
199
196
LWLockAcquire (lock_pk , LW_EXCLUSIVE );
200
- principal_key = GetPrincipalKey (rlocator . dbOid , LW_EXCLUSIVE );
197
+ principal_key = GetPrincipalKey (GLOBAL_DATA_TDE_OID , LW_EXCLUSIVE );
201
198
if (principal_key == NULL )
202
199
{
203
200
LWLockRelease (lock_pk );
@@ -219,7 +216,7 @@ pg_tde_read_last_wal_key(void)
219
216
}
220
217
221
218
file_idx = ((fsize - sizeof (WalKeyFileHeader )) / sizeof (WalKeyFileEntry )) - 1 ;
222
- pg_tde_read_one_wal_key_file_entry2 (fd , file_idx , & entry , rlocator . dbOid );
219
+ pg_tde_read_one_wal_key_file_entry2 (fd , file_idx , & entry );
223
220
224
221
rel_key_data = pg_tde_decrypt_wal_key (principal_key , & entry );
225
222
#ifdef FRONTEND
@@ -235,7 +232,6 @@ pg_tde_read_last_wal_key(void)
235
232
WALKeyCacheRec *
236
233
pg_tde_fetch_wal_keys (XLogRecPtr start_lsn )
237
234
{
238
- RelFileLocator rlocator = GLOBAL_SPACE_RLOCATOR (XLOG_TDE_OID );
239
235
off_t read_pos = 0 ;
240
236
LWLock * lock_pk = tde_lwlock_enc_keys ();
241
237
TDEPrincipalKey * principal_key ;
@@ -244,7 +240,7 @@ pg_tde_fetch_wal_keys(XLogRecPtr start_lsn)
244
240
WALKeyCacheRec * return_wal_rec = NULL ;
245
241
246
242
LWLockAcquire (lock_pk , LW_SHARED );
247
- principal_key = GetPrincipalKey (rlocator . dbOid , LW_SHARED );
243
+ principal_key = GetPrincipalKey (GLOBAL_DATA_TDE_OID , LW_SHARED );
248
244
if (principal_key == NULL )
249
245
{
250
246
LWLockRelease (lock_pk );
@@ -283,7 +279,7 @@ pg_tde_fetch_wal_keys(XLogRecPtr start_lsn)
283
279
{
284
280
WalKeyFileEntry entry ;
285
281
286
- pg_tde_read_one_wal_key_file_entry2 (fd , file_idx , & entry , rlocator . dbOid );
282
+ pg_tde_read_one_wal_key_file_entry2 (fd , file_idx , & entry );
287
283
288
284
/*
289
285
* Skip new (just created but not updated by write) and invalid keys
@@ -496,8 +492,7 @@ pg_tde_read_one_wal_key_file_entry(int fd,
496
492
static void
497
493
pg_tde_read_one_wal_key_file_entry2 (int fd ,
498
494
int32 key_index ,
499
- WalKeyFileEntry * entry ,
500
- Oid databaseId )
495
+ WalKeyFileEntry * entry )
501
496
{
502
497
off_t read_pos ;
503
498
@@ -512,17 +507,14 @@ pg_tde_read_one_wal_key_file_entry2(int fd,
512
507
}
513
508
514
509
static void
515
- pg_tde_write_wal_key_file_entry (const RelFileLocator * rlocator ,
516
- const WalEncryptionKey * rel_key_data ,
510
+ pg_tde_write_wal_key_file_entry (const WalEncryptionKey * rel_key_data ,
517
511
TDEPrincipalKey * principal_key )
518
512
{
519
513
int fd ;
520
514
off_t curr_pos = 0 ;
521
515
WalKeyFileEntry write_entry ;
522
516
TDESignedPrincipalKeyInfo signed_key_Info ;
523
517
524
- Assert (rlocator );
525
-
526
518
pg_tde_sign_principal_key_info (& signed_key_Info , principal_key );
527
519
528
520
/* Open and validate file for basic correctness. */
@@ -552,7 +544,7 @@ pg_tde_write_wal_key_file_entry(const RelFileLocator *rlocator,
552
544
}
553
545
554
546
/* Initialize WAL key file entry and encrypt key */
555
- pg_tde_initialize_wal_key_file_entry (& write_entry , principal_key , rlocator , rel_key_data );
547
+ pg_tde_initialize_wal_key_file_entry (& write_entry , principal_key , rel_key_data );
556
548
557
549
/* Write the given entry at curr_pos; i.e. the free entry. */
558
550
pg_tde_write_one_wal_key_file_entry (fd , & write_entry , & curr_pos , get_wal_key_file_path ());
@@ -610,11 +602,8 @@ pg_tde_write_one_wal_key_file_entry(int fd,
610
602
static void
611
603
pg_tde_initialize_wal_key_file_entry (WalKeyFileEntry * entry ,
612
604
const TDEPrincipalKey * principal_key ,
613
- const RelFileLocator * rlocator ,
614
605
const WalEncryptionKey * rel_key_data )
615
606
{
616
- entry -> spcOid = rlocator -> spcOid ;
617
- entry -> relNumber = rlocator -> relNumber ;
618
607
entry -> type = rel_key_data -> type ;
619
608
entry -> enc_key = * rel_key_data ;
620
609
@@ -663,7 +652,6 @@ pg_tde_perform_rotate_server_key(TDEPrincipalKey *principal_key,
663
652
WalEncryptionKey * key ;
664
653
WalKeyFileEntry read_map_entry ;
665
654
WalKeyFileEntry write_map_entry ;
666
- RelFileLocator rloc = GLOBAL_SPACE_RLOCATOR (XLOG_TDE_OID );
667
655
668
656
if (!pg_tde_read_one_wal_key_file_entry (old_fd , & read_map_entry , & old_curr_pos ))
669
657
break ;
@@ -673,7 +661,7 @@ pg_tde_perform_rotate_server_key(TDEPrincipalKey *principal_key,
673
661
674
662
/* Decrypt and re-encrypt key */
675
663
key = pg_tde_decrypt_wal_key (principal_key , & read_map_entry );
676
- pg_tde_initialize_wal_key_file_entry (& write_map_entry , new_principal_key , & rloc , key );
664
+ pg_tde_initialize_wal_key_file_entry (& write_map_entry , new_principal_key , key );
677
665
678
666
pg_tde_write_one_wal_key_file_entry (new_fd , & write_map_entry , & new_curr_pos , tmp_path );
679
667
0 commit comments