@@ -34,16 +34,19 @@ char full_buf[XLOG_SEG_SIZE], *buf, *filename = FSYNC_FILENAME;
3434struct timeval start_t ,stop_t ;
3535
3636
37- void handle_args (int argc ,char * argv []);
38- void prepare_buf (void );
39- void test_open (void );
40- void test_non_sync (void );
41- void test_sync (int writes_per_op );
42- void test_open_syncs (void );
43- void test_open_sync (const char * msg ,int writes_size );
44- void test_file_descriptor_sync (void );
45- void print_elapse (struct timeval start_t ,struct timeval stop_t );
46- void die (char * str );
37+ static void handle_args (int argc ,char * argv []);
38+ static void prepare_buf (void );
39+ static void test_open (void );
40+ static void test_non_sync (void );
41+ static void test_sync (int writes_per_op );
42+ static void test_open_syncs (void );
43+ static void test_open_sync (const char * msg ,int writes_size );
44+ static void test_file_descriptor_sync (void );
45+ #ifdef HAVE_FSYNC_WRITETHROUGH
46+ static int pg_fsync_writethrough (int fd );
47+ #endif
48+ static void print_elapse (struct timeval start_t ,struct timeval stop_t );
49+ static void die (char * str );
4750
4851
4952int
@@ -72,7 +75,7 @@ main(int argc, char *argv[])
7275return 0 ;
7376}
7477
75- void
78+ static void
7679handle_args (int argc ,char * argv [])
7780{
7881static struct option long_options []= {
@@ -88,7 +91,7 @@ handle_args(int argc, char *argv[])
8891if (strcmp (argv [1 ],"--help" )== 0 || strcmp (argv [1 ],"-h" )== 0 ||
8992strcmp (argv [1 ],"-?" )== 0 )
9093{
91- fprintf (stderr ,"pg_test_fsync [-f filename] [ops-per-test]\n" );
94+ fprintf (stderr ,"pg_test_fsync [-f filename] [-o ops-per-test]\n" );
9295exit (0 );
9396}
9497if (strcmp (argv [1 ],"--version" )== 0 || strcmp (argv [1 ],"-V" )== 0 )
@@ -123,7 +126,7 @@ handle_args(int argc, char *argv[])
123126printf ("%d operations per test\n" ,ops_per_test );
124127}
125128
126- void
129+ static void
127130prepare_buf (void )
128131{
129132int ops ;
@@ -135,7 +138,7 @@ prepare_buf(void)
135138buf = (char * )TYPEALIGN (ALIGNOF_XLOG_BUFFER ,full_buf );
136139}
137140
138- void
141+ static void
139142test_open (void )
140143{
141144int tmpfile ;
@@ -155,7 +158,7 @@ test_open(void)
155158close (tmpfile );
156159}
157160
158- void
161+ static void
159162test_sync (int writes_per_op )
160163{
161164int tmpfile ,ops ,writes ;
@@ -291,7 +294,7 @@ test_sync(int writes_per_op)
291294for (writes = 0 ;writes < writes_per_op ;writes ++ )
292295if (write (tmpfile ,buf ,WRITE_SIZE )!= WRITE_SIZE )
293296die ("write failed" );
294- if (fcntl (tmpfile , F_FULLFSYNC )!= 0 )
297+ if (pg_fsync_writethrough (tmpfile )!= 0 )
295298die ("fsync failed" );
296299if (lseek (tmpfile ,0 ,SEEK_SET )== -1 )
297300die ("seek failed" );
@@ -374,7 +377,7 @@ test_sync(int writes_per_op)
374377}
375378}
376379
377- void
380+ static void
378381test_open_syncs (void )
379382{
380383printf ("\nCompare open_sync with different write sizes:\n" );
@@ -389,7 +392,7 @@ test_open_syncs(void)
389392}
390393
391394
392- void
395+ static void
393396test_open_sync (const char * msg ,int writes_size )
394397{
395398int tmpfile ,ops ,writes ;
@@ -424,7 +427,7 @@ test_open_sync(const char *msg, int writes_size)
424427#endif
425428}
426429
427- void
430+ static void
428431test_file_descriptor_sync (void )
429432{
430433int tmpfile ,ops ;
@@ -496,7 +499,7 @@ test_file_descriptor_sync(void)
496499
497500}
498501
499- void
502+ static void
500503test_non_sync (void )
501504{
502505int tmpfile ,ops ;
@@ -521,10 +524,27 @@ test_non_sync(void)
521524print_elapse (start_t ,stop_t );
522525}
523526
527+ #ifdef HAVE_FSYNC_WRITETHROUGH
528+
529+ static int
530+ pg_fsync_writethrough (int fd )
531+ {
532+ #ifdef WIN32
533+ return _commit (fd );
534+ #elif defined(F_FULLFSYNC )
535+ return (fcntl (fd ,F_FULLFSYNC ,0 )== -1 ) ?-1 :0 ;
536+ #else
537+ errno = ENOSYS ;
538+ return -1 ;
539+ #endif
540+ }
541+
542+ #endif
543+
524544/*
525545 * print out the writes per second for tests
526546 */
527- void
547+ static void
528548print_elapse (struct timeval start_t ,struct timeval stop_t )
529549{
530550double total_time = (stop_t .tv_sec - start_t .tv_sec )+
@@ -534,7 +554,7 @@ print_elapse(struct timeval start_t, struct timeval stop_t)
534554printf (OPS_FORMAT "\n" ,per_second );
535555}
536556
537- void
557+ static void
538558die (char * str )
539559{
540560fprintf (stderr ,"%s\n" ,str );