1
1
/*
2
- * test_fsync .c
2
+ * pg_test_fsync .c
3
3
* tests all supported fsync() methods
4
4
*/
5
5
6
6
#include "postgres.h"
7
7
8
+ #include <fcntl.h>
9
+ #include <sys/stat.h>
10
+ #include <sys/time.h>
11
+ #include <time.h>
12
+ #include <unistd.h>
13
+
8
14
#include "getopt_long.h"
9
15
#include "access/xlog_internal.h"
10
16
#include "access/xlog.h"
11
17
#include "access/xlogdefs.h"
12
18
13
- #include <sys/types.h>
14
- #include <sys/stat.h>
15
- #include <fcntl.h>
16
- #include <stdio.h>
17
- #include <stdlib.h>
18
- #include <time.h>
19
- #include <sys/time.h>
20
- #include <unistd.h>
21
- #include <string.h>
22
-
23
19
24
- /*
20
+ /*
25
21
* put the temp files in the local directory
26
- * unless the user specifies otherwise
22
+ * unless the user specifies otherwise
27
23
*/
28
- #define FSYNC_FILENAME "./test_fsync .out"
24
+ #define FSYNC_FILENAME "./pg_test_fsync .out"
29
25
30
26
#define WRITE_SIZE (8 * 1024) /* 8k */
31
27
54
50
main (int argc , char * argv [])
55
51
{
56
52
handle_args (argc , argv );
57
-
53
+
58
54
prepare_buf ();
59
55
60
56
test_open ();
61
-
57
+
62
58
/* Test using 1 8k write */
63
59
test_sync (1 );
64
60
65
61
/* Test using 2 8k writes */
66
62
test_sync (2 );
67
-
63
+
68
64
test_open_syncs ();
69
65
70
66
test_file_descriptor_sync ();
71
-
67
+
72
68
test_non_sync ();
73
-
69
+
74
70
unlink (filename );
75
71
76
72
return 0 ;
@@ -92,12 +88,12 @@ handle_args(int argc, char *argv[])
92
88
if (strcmp (argv [1 ], "--help" ) == 0 || strcmp (argv [1 ], "-h" ) == 0 ||
93
89
strcmp (argv [1 ], "-?" ) == 0 )
94
90
{
95
- fprintf (stderr , "test_fsync [-f filename] [ops-per-test]\n" );
91
+ fprintf (stderr , "pg_test_fsync [-f filename] [ops-per-test]\n" );
96
92
exit (0 );
97
93
}
98
94
if (strcmp (argv [1 ], "--version" ) == 0 || strcmp (argv [1 ], "-V" ) == 0 )
99
95
{
100
- fprintf (stderr ,"test_fsync " PG_VERSION "\n" );
96
+ fprintf (stderr ,"pg_test_fsync " PG_VERSION "\n" );
101
97
exit (0 );
102
98
}
103
99
}
@@ -114,11 +110,11 @@ handle_args(int argc, char *argv[])
114
110
case 'o' :
115
111
ops_per_test = atoi (optarg );
116
112
break ;
117
-
113
+
118
114
default :
119
115
fprintf (stderr ,
120
116
"Try \"%s --help\" for more information.\n" ,
121
- "test_fsync " );
117
+ "pg_test_fsync " );
122
118
exit (1 );
123
119
break ;
124
120
}
@@ -144,8 +140,8 @@ test_open(void)
144
140
{
145
141
int tmpfile ;
146
142
147
- /*
148
- * test if we can open the target file
143
+ /*
144
+ * test if we can open the target file
149
145
*/
150
146
if ((tmpfile = open (filename , O_RDWR | O_CREAT , S_IRUSR | S_IWUSR )) == -1 )
151
147
die ("Cannot open output file." );
@@ -164,7 +160,7 @@ test_sync(int writes_per_op)
164
160
{
165
161
int tmpfile , ops , writes ;
166
162
bool fs_warning = false;
167
-
163
+
168
164
if (writes_per_op == 1 )
169
165
printf ("\nCompare file sync methods using one 8k write:\n" );
170
166
else
@@ -279,10 +275,10 @@ test_sync(int writes_per_op)
279
275
gettimeofday (& stop_t , NULL );
280
276
close (tmpfile );
281
277
print_elapse (start_t , stop_t );
282
-
278
+
283
279
/*
284
280
* If fsync_writethrough is available, test as well
285
- */
281
+ */
286
282
#ifdef HAVE_FSYNC_WRITETHROUGH
287
283
printf (LABEL_FORMAT , "fsync_writethrough" );
288
284
fflush (stdout );
@@ -422,7 +418,7 @@ test_open_sync(const char *msg, int writes_size)
422
418
close (tmpfile );
423
419
print_elapse (start_t , stop_t );
424
420
}
425
-
421
+
426
422
#else
427
423
printf (NA_FORMAT , "open_sync" , "n/a\n" );
428
424
#endif
@@ -444,8 +440,8 @@ test_file_descriptor_sync(void)
444
440
printf ("(If the times are similar, fsync() can sync data written\n" );
445
441
printf ("on a different descriptor.)\n" );
446
442
447
- /*
448
- * first write, fsync and close, which is the
443
+ /*
444
+ * first write, fsync and close, which is the
449
445
* normal behavior without multiple descriptors
450
446
*/
451
447
printf (LABEL_FORMAT , "write, fsync, close" );
@@ -477,8 +473,8 @@ test_file_descriptor_sync(void)
477
473
* This simulates processes fsyncing each other's
478
474
* writes.
479
475
*/
480
- printf (LABEL_FORMAT , "write, close, fsync" );
481
- fflush (stdout );
476
+ printf (LABEL_FORMAT , "write, close, fsync" );
477
+ fflush (stdout );
482
478
483
479
gettimeofday (& start_t , NULL );
484
480
for (ops = 0 ; ops < ops_per_test ; ops ++ )
@@ -525,7 +521,7 @@ test_non_sync(void)
525
521
print_elapse (start_t , stop_t );
526
522
}
527
523
528
- /*
524
+ /*
529
525
* print out the writes per second for tests
530
526
*/
531
527
void
0 commit comments