Skip to content

Commit cb38ab6

Browse files
committed
More pg_test_fsync cleanup.
Un-break Windows build (I hope) by making the HAVE_FSYNC_WRITETHROUGH code match the backend. Fix incorrect program help message. static-ize all functions.
1 parent bc61670 commit cb38ab6

File tree

1 file changed

+42
-22
lines changed

1 file changed

+42
-22
lines changed

contrib/pg_test_fsync/pg_test_fsync.c

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ char full_buf[XLOG_SEG_SIZE], *buf, *filename = FSYNC_FILENAME;
3434
struct 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

4952
int
@@ -72,7 +75,7 @@ main(int argc, char *argv[])
7275
return 0;
7376
}
7477

75-
void
78+
static void
7679
handle_args(int argc, char *argv[])
7780
{
7881
static struct option long_options[] = {
@@ -88,7 +91,7 @@ handle_args(int argc, char *argv[])
8891
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ||
8992
strcmp(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");
9295
exit(0);
9396
}
9497
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
@@ -123,7 +126,7 @@ handle_args(int argc, char *argv[])
123126
printf("%d operations per test\n", ops_per_test);
124127
}
125128

126-
void
129+
static void
127130
prepare_buf(void)
128131
{
129132
int ops;
@@ -135,7 +138,7 @@ prepare_buf(void)
135138
buf = (char *) TYPEALIGN(ALIGNOF_XLOG_BUFFER, full_buf);
136139
}
137140

138-
void
141+
static void
139142
test_open(void)
140143
{
141144
int tmpfile;
@@ -155,7 +158,7 @@ test_open(void)
155158
close(tmpfile);
156159
}
157160

158-
void
161+
static void
159162
test_sync(int writes_per_op)
160163
{
161164
int tmpfile, ops, writes;
@@ -291,7 +294,7 @@ test_sync(int writes_per_op)
291294
for (writes = 0; writes < writes_per_op; writes++)
292295
if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
293296
die("write failed");
294-
if (fcntl(tmpfile, F_FULLFSYNC ) != 0)
297+
if (pg_fsync_writethrough(tmpfile) != 0)
295298
die("fsync failed");
296299
if (lseek(tmpfile, 0, SEEK_SET) == -1)
297300
die("seek failed");
@@ -374,7 +377,7 @@ test_sync(int writes_per_op)
374377
}
375378
}
376379

377-
void
380+
static void
378381
test_open_syncs(void)
379382
{
380383
printf("\nCompare open_sync with different write sizes:\n");
@@ -389,7 +392,7 @@ test_open_syncs(void)
389392
}
390393

391394

392-
void
395+
static void
393396
test_open_sync(const char *msg, int writes_size)
394397
{
395398
int 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
428431
test_file_descriptor_sync(void)
429432
{
430433
int tmpfile, ops;
@@ -496,7 +499,7 @@ test_file_descriptor_sync(void)
496499

497500
}
498501

499-
void
502+
static void
500503
test_non_sync(void)
501504
{
502505
int tmpfile, ops;
@@ -521,10 +524,27 @@ test_non_sync(void)
521524
print_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
528548
print_elapse(struct timeval start_t, struct timeval stop_t)
529549
{
530550
double total_time = (stop_t.tv_sec - start_t.tv_sec) +
@@ -534,7 +554,7 @@ print_elapse(struct timeval start_t, struct timeval stop_t)
534554
printf(OPS_FORMAT "\n", per_second);
535555
}
536556

537-
void
557+
static void
538558
die(char *str)
539559
{
540560
fprintf(stderr, "%s\n", str);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy