Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcb38ab6

Browse files
committed
More pg_test_fsync cleanup.
Un-break Windows build (I hope) by making the HAVE_FSYNC_WRITETHROUGHcode match the backend. Fix incorrect program help message. static-izeall functions.
1 parentbc61670 commitcb38ab6

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
structtimevalstart_t,stop_t;
3535

3636

37-
voidhandle_args(intargc,char*argv[]);
38-
voidprepare_buf(void);
39-
voidtest_open(void);
40-
voidtest_non_sync(void);
41-
voidtest_sync(intwrites_per_op);
42-
voidtest_open_syncs(void);
43-
voidtest_open_sync(constchar*msg,intwrites_size);
44-
voidtest_file_descriptor_sync(void);
45-
voidprint_elapse(structtimevalstart_t,structtimevalstop_t);
46-
voiddie(char*str);
37+
staticvoidhandle_args(intargc,char*argv[]);
38+
staticvoidprepare_buf(void);
39+
staticvoidtest_open(void);
40+
staticvoidtest_non_sync(void);
41+
staticvoidtest_sync(intwrites_per_op);
42+
staticvoidtest_open_syncs(void);
43+
staticvoidtest_open_sync(constchar*msg,intwrites_size);
44+
staticvoidtest_file_descriptor_sync(void);
45+
#ifdefHAVE_FSYNC_WRITETHROUGH
46+
staticintpg_fsync_writethrough(intfd);
47+
#endif
48+
staticvoidprint_elapse(structtimevalstart_t,structtimevalstop_t);
49+
staticvoiddie(char*str);
4750

4851

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

75-
void
78+
staticvoid
7679
handle_args(intargc,char*argv[])
7780
{
7881
staticstructoptionlong_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] [-oops-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+
staticvoid
127130
prepare_buf(void)
128131
{
129132
intops;
@@ -135,7 +138,7 @@ prepare_buf(void)
135138
buf= (char*)TYPEALIGN(ALIGNOF_XLOG_BUFFER,full_buf);
136139
}
137140

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

158-
void
161+
staticvoid
159162
test_sync(intwrites_per_op)
160163
{
161164
inttmpfile,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+
staticvoid
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+
staticvoid
393396
test_open_sync(constchar*msg,intwrites_size)
394397
{
395398
inttmpfile,ops,writes;
@@ -424,7 +427,7 @@ test_open_sync(const char *msg, int writes_size)
424427
#endif
425428
}
426429

427-
void
430+
staticvoid
428431
test_file_descriptor_sync(void)
429432
{
430433
inttmpfile,ops;
@@ -496,7 +499,7 @@ test_file_descriptor_sync(void)
496499

497500
}
498501

499-
void
502+
staticvoid
500503
test_non_sync(void)
501504
{
502505
inttmpfile,ops;
@@ -521,10 +524,27 @@ test_non_sync(void)
521524
print_elapse(start_t,stop_t);
522525
}
523526

527+
#ifdefHAVE_FSYNC_WRITETHROUGH
528+
529+
staticint
530+
pg_fsync_writethrough(intfd)
531+
{
532+
#ifdefWIN32
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+
staticvoid
528548
print_elapse(structtimevalstart_t,structtimevalstop_t)
529549
{
530550
doubletotal_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+
staticvoid
538558
die(char*str)
539559
{
540560
fprintf(stderr,"%s\n",str);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp