5656static bool
5757build_path (char * dst , size_t dstlen , const char * relpath )
5858{
59- if (cluster_shared_data_dir == NULL || cluster_shared_data_dir [0 ] == '\0' )
60- {
59+ if (cluster_shared_data_dir == NULL || cluster_shared_data_dir [0 ] == '\0' ) {
6160 if (dstlen > 0 )
6261 dst [0 ] = '\0' ;
6362 return false;
@@ -101,7 +100,7 @@ ClusterCfValidity
101100cluster_cf_classify_buffer (const char * buf , size_t len , uint64 expected_sysid )
102101{
103102 ControlFileData cf ;
104- pg_crc32c crc ;
103+ pg_crc32c crc ;
105104
106105 if (buf == NULL || len < sizeof (ControlFileData ))
107106 return CLUSTER_CF_INVALID_SHORT ;
@@ -115,8 +114,7 @@ cluster_cf_classify_buffer(const char *buf, size_t len, uint64 expected_sysid)
115114 return CLUSTER_CF_INVALID_CRC ;
116115
117116 /* Foreign byte order: version is a nonzero multiple of 65536. */
118- if (cf .pg_control_version % 65536 == 0 &&
119- cf .pg_control_version / 65536 != 0 )
117+ if (cf .pg_control_version % 65536 == 0 && cf .pg_control_version / 65536 != 0 )
120118 return CLUSTER_CF_INVALID_BYTE_ORDER ;
121119
122120 if (expected_sysid != 0 && cf .system_identifier != expected_sysid )
@@ -134,8 +132,7 @@ cluster_cf_classify_buffer(const char *buf, size_t len, uint64 expected_sysid)
134132 * corrupt primary (spec §3.9 T3). Otherwise fail-closed.
135133 */
136134ClusterCfReadSource
137- cluster_cf_decide_source (ClusterCfValidity primary , ClusterCfValidity bak ,
138- bool bak_strict_ok )
135+ cluster_cf_decide_source (ClusterCfValidity primary , ClusterCfValidity bak , bool bak_strict_ok )
139136{
140137 if (primary == CLUSTER_CF_VALID )
141138 return CLUSTER_CF_SOURCE_PRIMARY ;
@@ -174,8 +171,8 @@ cluster_cf_bak_strict_ok(const ControlFileData *bak, uint64 expected_sysid,
174171static ClusterCfValidity
175172read_image (const char * path , char * image )
176173{
177- int fd ;
178- int r ;
174+ int fd ;
175+ int r ;
179176
180177 if (path == NULL )
181178 return CLUSTER_CF_INVALID_SHORT ;
@@ -187,7 +184,7 @@ read_image(const char *path, char *image)
187184 r = read (fd , image , sizeof (ControlFileData ));
188185 CloseTransientFile (fd );
189186
190- if (r != (int ) sizeof (ControlFileData ))
187+ if (r != (int )sizeof (ControlFileData ))
191188 return CLUSTER_CF_INVALID_SHORT ;
192189
193190 return cluster_cf_classify_buffer (image , sizeof (ControlFileData ), 0 );
@@ -203,16 +200,15 @@ read_image(const char *path, char *image)
203200bool
204201cluster_cf_authority_read (ControlFileData * out )
205202{
206- char primary_img [sizeof (ControlFileData )];
207- char bak_img [sizeof (ControlFileData )];
203+ char primary_img [sizeof (ControlFileData )];
204+ char bak_img [sizeof (ControlFileData )];
208205 ClusterCfValidity pv ;
209206 ClusterCfValidity bv ;
210- bool bak_strict_ok ;
207+ bool bak_strict_ok ;
211208 ClusterCfReadSource src ;
212209
213210 pv = read_image (cluster_cf_shared_path (), primary_img );
214- if (pv == CLUSTER_CF_VALID )
215- {
211+ if (pv == CLUSTER_CF_VALID ) {
216212 memcpy (out , primary_img , sizeof (ControlFileData ));
217213 return true;
218214 }
@@ -230,29 +226,26 @@ cluster_cf_authority_read(ControlFileData *out)
230226 * is skipped here (0); the symlink/migrate gates already reject a foreign
231227 * authority at startup (§3.2 M3).
232228 */
233- if (bv == CLUSTER_CF_VALID )
234- {
229+ if (bv == CLUSTER_CF_VALID ) {
235230 ControlFileData bak_cf ;
236231
237232 memcpy (& bak_cf , bak_img , sizeof (ControlFileData ));
238- bak_strict_ok = cluster_cf_bak_strict_ok (& bak_cf , 0 ,
239- cluster_cf_bak_checkpoint_recoverable (& bak_cf ));
240- }
241- else
233+ bak_strict_ok
234+ = cluster_cf_bak_strict_ok (& bak_cf , 0 , cluster_cf_bak_checkpoint_recoverable (& bak_cf ));
235+ } else
242236 bak_strict_ok = false;
243237
244238 src = cluster_cf_decide_source (pv , bv , bak_strict_ok );
245- switch (src )
246- {
247- case CLUSTER_CF_SOURCE_PRIMARY :
248- memcpy (out , primary_img , sizeof (ControlFileData ));
249- return true;
250- case CLUSTER_CF_SOURCE_BAK :
251- cluster_cf_counter_inc (CLUSTER_CF_BAK_FALLBACK );
252- memcpy (out , bak_img , sizeof (ControlFileData ));
253- return true;
254- case CLUSTER_CF_SOURCE_FAILCLOSED :
255- break ;
239+ switch (src ) {
240+ case CLUSTER_CF_SOURCE_PRIMARY :
241+ memcpy (out , primary_img , sizeof (ControlFileData ));
242+ return true;
243+ case CLUSTER_CF_SOURCE_BAK :
244+ cluster_cf_counter_inc (CLUSTER_CF_BAK_FALLBACK );
245+ memcpy (out , bak_img , sizeof (ControlFileData ));
246+ return true;
247+ case CLUSTER_CF_SOURCE_FAILCLOSED :
248+ break ;
256249 }
257250 return false;
258251}
@@ -265,39 +258,28 @@ cluster_cf_authority_read(ControlFileData *out)
265258static void
266259write_durable (const char * tmp , const char * final , const char * buf )
267260{
268- int fd ;
261+ int fd ;
269262
270263 fd = OpenTransientFile (tmp , O_RDWR | O_CREAT | O_TRUNC | PG_BINARY );
271264 if (fd < 0 )
272- ereport (PANIC ,
273- (errcode_for_file_access (),
274- errmsg ("could not open file \"%s\": %m" , tmp )));
265+ ereport (PANIC , (errcode_for_file_access (), errmsg ("could not open file \"%s\": %m" , tmp )));
275266
276267 errno = 0 ;
277- if (write (fd , buf , PG_CONTROL_FILE_SIZE ) != PG_CONTROL_FILE_SIZE )
278- {
268+ if (write (fd , buf , PG_CONTROL_FILE_SIZE ) != PG_CONTROL_FILE_SIZE ) {
279269 if (errno == 0 )
280270 errno = ENOSPC ;
281- ereport (PANIC ,
282- (errcode_for_file_access (),
283- errmsg ("could not write file \"%s\": %m" , tmp )));
271+ ereport (PANIC , (errcode_for_file_access (), errmsg ("could not write file \"%s\": %m" , tmp )));
284272 }
285273
286274 if (pg_fsync (fd ) != 0 )
287- ereport (PANIC ,
288- (errcode_for_file_access (),
289- errmsg ("could not fsync file \"%s\": %m" , tmp )));
275+ ereport (PANIC , (errcode_for_file_access (), errmsg ("could not fsync file \"%s\": %m" , tmp )));
290276
291277 if (CloseTransientFile (fd ) != 0 )
292- ereport (PANIC ,
293- (errcode_for_file_access (),
294- errmsg ("could not close file \"%s\": %m" , tmp )));
278+ ereport (PANIC , (errcode_for_file_access (), errmsg ("could not close file \"%s\": %m" , tmp )));
295279
296280 if (durable_rename (tmp , final , PANIC ) != 0 )
297- ereport (PANIC ,
298- (errcode_for_file_access (),
299- errmsg ("could not rename file \"%s\" to \"%s\": %m" ,
300- tmp , final )));
281+ ereport (PANIC , (errcode_for_file_access (),
282+ errmsg ("could not rename file \"%s\" to \"%s\": %m" , tmp , final )));
301283}
302284
303285/*
@@ -308,18 +290,18 @@ write_durable(const char *tmp, const char *final, const char *buf)
308290static void
309291roll_primary_to_bak (const char * primary , const char * bak , const char * baktmp )
310292{
311- char buf [PG_CONTROL_FILE_SIZE ];
312- int fd ;
313- int r ;
293+ char buf [PG_CONTROL_FILE_SIZE ];
294+ int fd ;
295+ int r ;
314296
315297 fd = OpenTransientFile (primary , O_RDONLY | PG_BINARY );
316298 if (fd < 0 )
317- return ; /* first write: no prior primary to preserve */
299+ return ; /* first write: no prior primary to preserve */
318300
319301 r = read (fd , buf , PG_CONTROL_FILE_SIZE );
320302 CloseTransientFile (fd );
321303 if (r != PG_CONTROL_FILE_SIZE )
322- return ; /* short/odd primary: don't manufacture a .bak */
304+ return ; /* short/odd primary: don't manufacture a .bak */
323305
324306 write_durable (baktmp , bak , buf );
325307}
@@ -332,24 +314,23 @@ roll_primary_to_bak(const char *primary, const char *bak, const char *baktmp)
332314void
333315cluster_cf_authority_write (const ControlFileData * cf )
334316{
335- char buffer [PG_CONTROL_FILE_SIZE ];
336- char primary [MAXPGPATH ];
337- char bak [MAXPGPATH ];
338- char tmp [MAXPGPATH ];
339- char baktmp [MAXPGPATH ];
317+ char buffer [PG_CONTROL_FILE_SIZE ];
318+ char primary [MAXPGPATH ];
319+ char bak [MAXPGPATH ];
320+ char tmp [MAXPGPATH ];
321+ char baktmp [MAXPGPATH ];
340322 ControlFileData local ;
341323
342- if (!build_path (primary , sizeof (primary ), CLUSTER_CF_REL_PATH ) ||
343- !build_path (bak , sizeof (bak ), CLUSTER_CF_BAK_REL_PATH ) ||
344- !build_path (tmp , sizeof (tmp ), CLUSTER_CF_TMP_REL_PATH ) ||
345- !build_path (baktmp , sizeof (baktmp ), CLUSTER_CF_BAK_TMP_REL_PATH ))
346- ereport (PANIC ,
347- (errmsg ("cluster shared_data_dir is not configured" )));
324+ if (!build_path (primary , sizeof (primary ), CLUSTER_CF_REL_PATH )
325+ || !build_path (bak , sizeof (bak ), CLUSTER_CF_BAK_REL_PATH )
326+ || !build_path (tmp , sizeof (tmp ), CLUSTER_CF_TMP_REL_PATH )
327+ || !build_path (baktmp , sizeof (baktmp ), CLUSTER_CF_BAK_TMP_REL_PATH ))
328+ ereport (PANIC , (errmsg ("cluster shared_data_dir is not configured" )));
348329
349330 /* Recompute CRC over a private copy (cf is const). */
350331 memcpy (& local , cf , sizeof (local ));
351332 INIT_CRC32C (local .crc );
352- COMP_CRC32C (local .crc , (char * ) & local , offsetof(ControlFileData , crc ));
333+ COMP_CRC32C (local .crc , (char * )& local , offsetof(ControlFileData , crc ));
353334 FIN_CRC32C (local .crc );
354335
355336 /* Zero-pad to the full on-disk size, as update_controlfile does. */
0 commit comments