@ -970,17 +970,12 @@ EndPrepare(GlobalTransaction gxact)
/*
/*
* Create the 2 PC state file .
* Create the 2 PC state file .
*
* Note : because we use BasicOpenFile ( ) , we are responsible for ensuring
* the FD gets closed in any error exit path . Once we get into the
* critical section , though , it doesn ' t matter since any failure causes
* PANIC anyway .
*/
*/
TwoPhaseFilePath ( path , xid ) ;
TwoPhaseFilePath ( path , xid ) ;
fd = BasicOpen File( path ,
fd = OpenTransientFile ( path ,
O_CREAT | O_EXCL | O_WRONLY | PG_BINARY ,
O_CREAT | O_EXCL | O_WRONLY | PG_BINARY ,
S_IRUSR | S_IWUSR ) ;
S_IRUSR | S_IWUSR ) ;
if ( fd < 0 )
if ( fd < 0 )
ereport ( ERROR ,
ereport ( ERROR ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
@ -995,7 +990,7 @@ EndPrepare(GlobalTransaction gxact)
COMP_CRC32 ( statefile_crc , record - > data , record - > len ) ;
COMP_CRC32 ( statefile_crc , record - > data , record - > len ) ;
if ( ( write ( fd , record - > data , record - > len ) ) ! = record - > len )
if ( ( write ( fd , record - > data , record - > len ) ) ! = record - > len )
{
{
clos e( fd ) ;
CloseTransientFil e( fd ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
errmsg ( " could not write two-phase state file: %m " ) ) ) ;
errmsg ( " could not write two-phase state file: %m " ) ) ) ;
@ -1012,7 +1007,7 @@ EndPrepare(GlobalTransaction gxact)
if ( ( write ( fd , & bogus_crc , sizeof ( pg_crc32 ) ) ) ! = sizeof ( pg_crc32 ) )
if ( ( write ( fd , & bogus_crc , sizeof ( pg_crc32 ) ) ) ! = sizeof ( pg_crc32 ) )
{
{
clos e( fd ) ;
CloseTransientFil e( fd ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
errmsg ( " could not write two-phase state file: %m " ) ) ) ;
errmsg ( " could not write two-phase state file: %m " ) ) ) ;
@ -1021,7 +1016,7 @@ EndPrepare(GlobalTransaction gxact)
/* Back up to prepare for rewriting the CRC */
/* Back up to prepare for rewriting the CRC */
if ( lseek ( fd , - ( ( off_t ) sizeof ( pg_crc32 ) ) , SEEK_CUR ) < 0 )
if ( lseek ( fd , - ( ( off_t ) sizeof ( pg_crc32 ) ) , SEEK_CUR ) < 0 )
{
{
clos e( fd ) ;
CloseTransientFil e( fd ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
errmsg ( " could not seek in two-phase state file: %m " ) ) ) ;
errmsg ( " could not seek in two-phase state file: %m " ) ) ) ;
@ -1061,13 +1056,13 @@ EndPrepare(GlobalTransaction gxact)
/* write correct CRC and close file */
/* write correct CRC and close file */
if ( ( write ( fd , & statefile_crc , sizeof ( pg_crc32 ) ) ) ! = sizeof ( pg_crc32 ) )
if ( ( write ( fd , & statefile_crc , sizeof ( pg_crc32 ) ) ) ! = sizeof ( pg_crc32 ) )
{
{
clos e( fd ) ;
CloseTransientFil e( fd ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
errmsg ( " could not write two-phase state file: %m " ) ) ) ;
errmsg ( " could not write two-phase state file: %m " ) ) ) ;
}
}
if ( clos e( fd ) ! = 0 )
if ( CloseTransientFil e( fd ) ! = 0 )
ereport ( ERROR ,
ereport ( ERROR ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
errmsg ( " could not close two-phase state file: %m " ) ) ) ;
errmsg ( " could not close two-phase state file: %m " ) ) ) ;
@ -1144,7 +1139,7 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
TwoPhaseFilePath ( path , xid ) ;
TwoPhaseFilePath ( path , xid ) ;
fd = BasicOpen File( path , O_RDONLY | PG_BINARY , 0 ) ;
fd = OpenTransient File( path , O_RDONLY | PG_BINARY , 0 ) ;
if ( fd < 0 )
if ( fd < 0 )
{
{
if ( give_warnings )
if ( give_warnings )
@ -1163,7 +1158,7 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
*/
*/
if ( fstat ( fd , & stat ) )
if ( fstat ( fd , & stat ) )
{
{
clos e( fd ) ;
CloseTransientFil e( fd ) ;
if ( give_warnings )
if ( give_warnings )
ereport ( WARNING ,
ereport ( WARNING ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
@ -1177,14 +1172,14 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
sizeof ( pg_crc32 ) ) | |
sizeof ( pg_crc32 ) ) | |
stat . st_size > MaxAllocSize )
stat . st_size > MaxAllocSize )
{
{
clos e( fd ) ;
CloseTransientFil e( fd ) ;
return NULL ;
return NULL ;
}
}
crc_offset = stat . st_size - sizeof ( pg_crc32 ) ;
crc_offset = stat . st_size - sizeof ( pg_crc32 ) ;
if ( crc_offset ! = MAXALIGN ( crc_offset ) )
if ( crc_offset ! = MAXALIGN ( crc_offset ) )
{
{
clos e( fd ) ;
CloseTransientFil e( fd ) ;
return NULL ;
return NULL ;
}
}
@ -1195,7 +1190,7 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
if ( read ( fd , buf , stat . st_size ) ! = stat . st_size )
if ( read ( fd , buf , stat . st_size ) ! = stat . st_size )
{
{
clos e( fd ) ;
CloseTransientFil e( fd ) ;
if ( give_warnings )
if ( give_warnings )
ereport ( WARNING ,
ereport ( WARNING ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
@ -1205,7 +1200,7 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
return NULL ;
return NULL ;
}
}
clos e( fd ) ;
CloseTransientFil e( fd ) ;
hdr = ( TwoPhaseFileHeader * ) buf ;
hdr = ( TwoPhaseFileHeader * ) buf ;
if ( hdr - > magic ! = TWOPHASE_MAGIC | | hdr - > total_len ! = stat . st_size )
if ( hdr - > magic ! = TWOPHASE_MAGIC | | hdr - > total_len ! = stat . st_size )
@ -1469,9 +1464,9 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
TwoPhaseFilePath ( path , xid ) ;
TwoPhaseFilePath ( path , xid ) ;
fd = BasicOpen File( path ,
fd = OpenTransient File( path ,
O_CREAT | O_TRUNC | O_WRONLY | PG_BINARY ,
O_CREAT | O_TRUNC | O_WRONLY | PG_BINARY ,
S_IRUSR | S_IWUSR ) ;
S_IRUSR | S_IWUSR ) ;
if ( fd < 0 )
if ( fd < 0 )
ereport ( ERROR ,
ereport ( ERROR ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
@ -1481,14 +1476,14 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
/* Write content and CRC */
/* Write content and CRC */
if ( write ( fd , content , len ) ! = len )
if ( write ( fd , content , len ) ! = len )
{
{
clos e( fd ) ;
CloseTransientFil e( fd ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
errmsg ( " could not write two-phase state file: %m " ) ) ) ;
errmsg ( " could not write two-phase state file: %m " ) ) ) ;
}
}
if ( write ( fd , & statefile_crc , sizeof ( pg_crc32 ) ) ! = sizeof ( pg_crc32 ) )
if ( write ( fd , & statefile_crc , sizeof ( pg_crc32 ) ) ! = sizeof ( pg_crc32 ) )
{
{
clos e( fd ) ;
CloseTransientFil e( fd ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
errmsg ( " could not write two-phase state file: %m " ) ) ) ;
errmsg ( " could not write two-phase state file: %m " ) ) ) ;
@ -1500,13 +1495,13 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
*/
*/
if ( pg_fsync ( fd ) ! = 0 )
if ( pg_fsync ( fd ) ! = 0 )
{
{
clos e( fd ) ;
CloseTransientFil e( fd ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
errmsg ( " could not fsync two-phase state file: %m " ) ) ) ;
errmsg ( " could not fsync two-phase state file: %m " ) ) ) ;
}
}
if ( clos e( fd ) ! = 0 )
if ( CloseTransientFil e( fd ) ! = 0 )
ereport ( ERROR ,
ereport ( ERROR ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
errmsg ( " could not close two-phase state file: %m " ) ) ) ;
errmsg ( " could not close two-phase state file: %m " ) ) ) ;
@ -1577,7 +1572,7 @@ CheckPointTwoPhase(XLogRecPtr redo_horizon)
TwoPhaseFilePath ( path , xid ) ;
TwoPhaseFilePath ( path , xid ) ;
fd = BasicOpen File( path , O_RDWR | PG_BINARY , 0 ) ;
fd = OpenTransient File( path , O_RDWR | PG_BINARY , 0 ) ;
if ( fd < 0 )
if ( fd < 0 )
{
{
if ( errno = = ENOENT )
if ( errno = = ENOENT )
@ -1596,14 +1591,14 @@ CheckPointTwoPhase(XLogRecPtr redo_horizon)
if ( pg_fsync ( fd ) ! = 0 )
if ( pg_fsync ( fd ) ! = 0 )
{
{
clos e( fd ) ;
CloseTransientFil e( fd ) ;
ereport ( ERROR ,
ereport ( ERROR ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
errmsg ( " could not fsync two-phase state file \" %s \" : %m " ,
errmsg ( " could not fsync two-phase state file \" %s \" : %m " ,
path ) ) ) ;
path ) ) ) ;
}
}
if ( clos e( fd ) ! = 0 )
if ( CloseTransientFil e( fd ) ! = 0 )
ereport ( ERROR ,
ereport ( ERROR ,
( errcode_for_file_access ( ) ,
( errcode_for_file_access ( ) ,
errmsg ( " could not close two-phase state file \" %s \" : %m " ,
errmsg ( " could not close two-phase state file \" %s \" : %m " ,